Loading commons/src/main/kotlin/com/simplemobiletools/commons/extensions/Activity.kt +16 −4 Original line number Diff line number Diff line Loading @@ -41,24 +41,36 @@ import java.util.* fun Activity.toast(id: Int, length: Int = Toast.LENGTH_SHORT) { if (isOnMainThread()) { Toast.makeText(this, id, length).show() showToast(this, id, length) } else { runOnUiThread { Toast.makeText(this, id, length).show() showToast(this, id, length) } } } fun Activity.toast(msg: String, length: Int = Toast.LENGTH_SHORT) { if (isOnMainThread()) { Toast.makeText(this, msg, length).show() showToast(this, msg, length) } else { runOnUiThread { Toast.makeText(this, msg, length).show() showToast(this, msg, length) } } } private fun showToast(activity: Activity, messageId: Int, length: Int) { if (!activity.isActivityDestroyed()) { Toast.makeText(activity, messageId, length).show() } } private fun showToast(activity: Activity, message: String, length: Int) { if (!activity.isActivityDestroyed()) { Toast.makeText(activity, message, length).show() } } fun Activity.showErrorToast(msg: String, length: Int = Toast.LENGTH_LONG) { toast(String.format(getString(R.string.an_error_occurred), msg), length) } Loading Loading
commons/src/main/kotlin/com/simplemobiletools/commons/extensions/Activity.kt +16 −4 Original line number Diff line number Diff line Loading @@ -41,24 +41,36 @@ import java.util.* fun Activity.toast(id: Int, length: Int = Toast.LENGTH_SHORT) { if (isOnMainThread()) { Toast.makeText(this, id, length).show() showToast(this, id, length) } else { runOnUiThread { Toast.makeText(this, id, length).show() showToast(this, id, length) } } } fun Activity.toast(msg: String, length: Int = Toast.LENGTH_SHORT) { if (isOnMainThread()) { Toast.makeText(this, msg, length).show() showToast(this, msg, length) } else { runOnUiThread { Toast.makeText(this, msg, length).show() showToast(this, msg, length) } } } private fun showToast(activity: Activity, messageId: Int, length: Int) { if (!activity.isActivityDestroyed()) { Toast.makeText(activity, messageId, length).show() } } private fun showToast(activity: Activity, message: String, length: Int) { if (!activity.isActivityDestroyed()) { Toast.makeText(activity, message, length).show() } } fun Activity.showErrorToast(msg: String, length: Int = Toast.LENGTH_LONG) { toast(String.format(getString(R.string.an_error_occurred), msg), length) } Loading