forked from github/wulkanowy-mirror
Fix not attached fragment (#337)
* Add condition for error dialog * Add safe call of forEach in LuckyNumberWidgetProvider
This commit is contained in:
parent
a191f03cdf
commit
103ab95c80
@ -2,6 +2,7 @@ package io.github.wulkanowy.ui.base
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import android.widget.Toast
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.appcompat.app.AppCompatDelegate
|
||||
import androidx.fragment.app.Fragment
|
||||
@ -25,7 +26,7 @@ abstract class BaseActivity : AppCompatActivity(), BaseView, HasSupportFragmentI
|
||||
@Inject
|
||||
lateinit var themeManager: ThemeManager
|
||||
|
||||
protected lateinit var messageContainer: View
|
||||
protected var messageContainer: View? = null
|
||||
|
||||
public override fun onCreate(savedInstanceState: Bundle?) {
|
||||
AndroidInjection.inject(this)
|
||||
@ -36,13 +37,18 @@ abstract class BaseActivity : AppCompatActivity(), BaseView, HasSupportFragmentI
|
||||
}
|
||||
|
||||
override fun showError(text: String, error: Throwable) {
|
||||
Snackbar.make(messageContainer, text, LENGTH_LONG).setAction(R.string.all_details) {
|
||||
if (messageContainer != null) {
|
||||
Snackbar.make(messageContainer!!, text, LENGTH_LONG)
|
||||
.setAction(R.string.all_details) {
|
||||
ErrorDialog.newInstance(error).show(supportFragmentManager, error.toString())
|
||||
}.show()
|
||||
}
|
||||
.show()
|
||||
} else showMessage(text)
|
||||
}
|
||||
|
||||
override fun showMessage(text: String) {
|
||||
Snackbar.make(messageContainer, text, LENGTH_LONG).show()
|
||||
if (messageContainer != null) Snackbar.make(messageContainer!!, text, LENGTH_LONG).show()
|
||||
else Toast.makeText(this, text, Toast.LENGTH_LONG).show()
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
|
@ -2,6 +2,7 @@ package io.github.wulkanowy.ui.base
|
||||
|
||||
import android.view.View
|
||||
import com.google.android.material.snackbar.Snackbar
|
||||
import com.google.android.material.snackbar.Snackbar.LENGTH_LONG
|
||||
import dagger.android.support.DaggerFragment
|
||||
import io.github.wulkanowy.R
|
||||
|
||||
@ -10,16 +11,22 @@ abstract class BaseFragment : DaggerFragment(), BaseView {
|
||||
protected var messageContainer: View? = null
|
||||
|
||||
override fun showError(text: String, error: Throwable) {
|
||||
if (messageContainer == null) (activity as? BaseActivity)?.showError(text, error)
|
||||
else messageContainer?.also {
|
||||
Snackbar.make(it, text, Snackbar.LENGTH_LONG).setAction(R.string.all_details) {
|
||||
ErrorDialog.newInstance(error).show(childFragmentManager, error.toString())
|
||||
}.show()
|
||||
if (messageContainer != null) {
|
||||
Snackbar.make(messageContainer!!, text, LENGTH_LONG)
|
||||
.setAction(R.string.all_details) {
|
||||
if (isAdded) ErrorDialog.newInstance(error).show(childFragmentManager, error.toString())
|
||||
}
|
||||
.show()
|
||||
} else {
|
||||
(activity as? BaseActivity)?.showError(text, error)
|
||||
}
|
||||
}
|
||||
|
||||
override fun showMessage(text: String) {
|
||||
if (messageContainer == null) (activity as? BaseActivity)?.showMessage(text)
|
||||
else messageContainer?.also { Snackbar.make(it, text, Snackbar.LENGTH_LONG).show() }
|
||||
if (messageContainer != null) {
|
||||
Snackbar.make(messageContainer!!, text, LENGTH_LONG).show()
|
||||
} else {
|
||||
(activity as? BaseActivity)?.showMessage(text)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -68,7 +68,7 @@ class LuckyNumberWidgetProvider : BroadcastReceiver() {
|
||||
}
|
||||
|
||||
private fun onUpdate(context: Context, intent: Intent) {
|
||||
intent.getIntArrayExtra(EXTRA_APPWIDGET_IDS).forEach { appWidgetId ->
|
||||
intent.getIntArrayExtra(EXTRA_APPWIDGET_IDS)?.forEach { appWidgetId ->
|
||||
RemoteViews(context.packageName, R.layout.widget_luckynumber).apply {
|
||||
setTextViewText(R.id.luckyNumberWidgetNumber,
|
||||
getLuckyNumber(sharedPref.getLong(getStudentWidgetKey(appWidgetId), 0), appWidgetId)?.luckyNumber?.toString() ?: "#"
|
||||
|
Loading…
x
Reference in New Issue
Block a user