From 26de99403237fbbee83485fc5294eb5fa2eec490 Mon Sep 17 00:00:00 2001 From: tibbi Date: Thu, 18 Aug 2016 21:48:38 +0200 Subject: [PATCH] create a helper extension for toasts --- .../applauncher/adapters/RecyclerAdapter.kt | 6 +++--- .../com/simplemobiletools/applauncher/extensions/context.kt | 6 +++++- .../com/simplemobiletools/applauncher/extensions/view.kt | 2 -- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/applauncher/adapters/RecyclerAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/applauncher/adapters/RecyclerAdapter.kt index 38bffcf..280f07e 100644 --- a/app/src/main/kotlin/com/simplemobiletools/applauncher/adapters/RecyclerAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/applauncher/adapters/RecyclerAdapter.kt @@ -6,7 +6,6 @@ import android.support.v7.app.AppCompatActivity import android.support.v7.view.ActionMode import android.support.v7.widget.RecyclerView import android.view.* -import android.widget.Toast import com.bignerdranch.android.multiselector.ModalMultiSelectorCallback import com.bignerdranch.android.multiselector.MultiSelector import com.bignerdranch.android.multiselector.SwappingHolder @@ -14,6 +13,7 @@ import com.simplemobiletools.applauncher.R import com.simplemobiletools.applauncher.databases.DbHelper import com.simplemobiletools.applauncher.extensions.hide import com.simplemobiletools.applauncher.extensions.show +import com.simplemobiletools.applauncher.extensions.toast import com.simplemobiletools.applauncher.models.AppLauncher import kotlinx.android.synthetic.main.app_launcher_dialog_item.view.* import kotlinx.android.synthetic.main.edit_launcher.view.* @@ -93,10 +93,10 @@ class RecyclerAdapter(val act: Activity, val launchers: List, val i finishActionMode() alertDialog.dismiss() } else { - Toast.makeText(act, act.resources.getString(R.string.unknown_error), Toast.LENGTH_SHORT).show() + act.toast(R.string.unknown_error) } } else { - Toast.makeText(act, act.resources.getString(R.string.enter_launcher_name), Toast.LENGTH_SHORT).show() + act.toast(R.string.enter_launcher_name) } } } diff --git a/app/src/main/kotlin/com/simplemobiletools/applauncher/extensions/context.kt b/app/src/main/kotlin/com/simplemobiletools/applauncher/extensions/context.kt index f836973..3b86b22 100644 --- a/app/src/main/kotlin/com/simplemobiletools/applauncher/extensions/context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/applauncher/extensions/context.kt @@ -1,6 +1,10 @@ package com.simplemobiletools.applauncher.extensions +import android.content.Context import android.content.Intent import android.net.Uri +import android.widget.Toast -fun viewIntent(url: String): Intent = Intent(Intent.ACTION_VIEW, Uri.parse(url)) +fun Context.viewIntent(url: String): Intent = Intent(Intent.ACTION_VIEW, Uri.parse(url)) + +fun Context.toast(msgId: Int, duration: Int = Toast.LENGTH_SHORT) = Toast.makeText(this, resources.getString(msgId), duration).show() diff --git a/app/src/main/kotlin/com/simplemobiletools/applauncher/extensions/view.kt b/app/src/main/kotlin/com/simplemobiletools/applauncher/extensions/view.kt index a959a9a..cee54b4 100644 --- a/app/src/main/kotlin/com/simplemobiletools/applauncher/extensions/view.kt +++ b/app/src/main/kotlin/com/simplemobiletools/applauncher/extensions/view.kt @@ -2,8 +2,6 @@ package com.simplemobiletools.applauncher.extensions import android.view.View -val View.isVisible: Boolean get() = visibility == View.VISIBLE - fun View.hide() { visibility = View.INVISIBLE }