From 24c22a72e643e9054402e0c71b3be52b51ef6d86 Mon Sep 17 00:00:00 2001 From: davidoskky Date: Sun, 21 Aug 2022 19:52:53 +0200 Subject: [PATCH] Send a message regarding connectivity loss/retrieval on all activities --- .../android/AddSourceActivity.kt | 13 +++++++++++++ .../readerforselfossv2/android/LoginActivity.kt | 14 ++++++++++++++ .../readerforselfossv2/android/SourcesActivity.kt | 13 +++++++++++++ .../android/fragments/ArticleFragment.kt | 13 +++++++++++++ 4 files changed, 53 insertions(+) diff --git a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/AddSourceActivity.kt b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/AddSourceActivity.kt index 0edd1c2..f4d79df 100644 --- a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/AddSourceActivity.kt +++ b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/AddSourceActivity.kt @@ -6,11 +6,13 @@ import android.view.View import android.widget.* import androidx.appcompat.app.AppCompatActivity import androidx.constraintlayout.widget.ConstraintLayout +import androidx.lifecycle.lifecycleScope import bou.amine.apps.readerforselfossv2.android.databinding.ActivityAddSourceBinding import bou.amine.apps.readerforselfossv2.android.themes.AppColors import bou.amine.apps.readerforselfossv2.android.themes.Toppings import bou.amine.apps.readerforselfossv2.android.utils.Config import bou.amine.apps.readerforselfossv2.android.utils.isBaseUrlValid +import bou.amine.apps.readerforselfossv2.android.viewmodel.AppViewModel import bou.amine.apps.readerforselfossv2.repository.Repository import com.ftinc.scoop.Scoop import kotlinx.coroutines.CoroutineScope @@ -30,6 +32,7 @@ class AddSourceActivity : AppCompatActivity(), DIAware { override val di by closestDI() private val repository : Repository by instance() + private val viewModel : AppViewModel by instance() override fun onCreate(savedInstanceState: Bundle?) { appColors = AppColors(this@AddSourceActivity) @@ -76,6 +79,16 @@ class AddSourceActivity : AppCompatActivity(), DIAware { binding.sourceUri.text.toString() ) } + + lifecycleScope.launch { + viewModel.toastMessageProvider.collect { toastMessage -> + Toast.makeText( + this@AddSourceActivity, + toastMessage, + Toast.LENGTH_SHORT + ).show() + } + } } override fun onResume() { diff --git a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/LoginActivity.kt b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/LoginActivity.kt index 544325f..6c75f57 100644 --- a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/LoginActivity.kt +++ b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/LoginActivity.kt @@ -10,11 +10,14 @@ import android.view.MenuItem import android.view.View import android.view.inputmethod.EditorInfo import android.widget.TextView +import android.widget.Toast import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AppCompatActivity +import androidx.lifecycle.lifecycleScope import bou.amine.apps.readerforselfossv2.android.databinding.ActivityLoginBinding import bou.amine.apps.readerforselfossv2.android.themes.AppColors import bou.amine.apps.readerforselfossv2.android.utils.isBaseUrlValid +import bou.amine.apps.readerforselfossv2.android.viewmodel.AppViewModel import bou.amine.apps.readerforselfossv2.repository.Repository import com.mikepenz.aboutlibraries.LibsBuilder import com.russhwolf.settings.Settings @@ -38,6 +41,7 @@ class LoginActivity() : AppCompatActivity(), DIAware { override val di by closestDI() private val repository : Repository by instance() + private val viewModel : AppViewModel by instance() override fun onCreate(savedInstanceState: Bundle?) { appColors = AppColors(this@LoginActivity) @@ -57,6 +61,16 @@ class LoginActivity() : AppCompatActivity(), DIAware { } handleActions() + + lifecycleScope.launch { + viewModel.toastMessageProvider.collect { toastMessage -> + Toast.makeText( + this@LoginActivity, + toastMessage, + Toast.LENGTH_SHORT + ).show() + } + } } private fun handleActions() { diff --git a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/SourcesActivity.kt b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/SourcesActivity.kt index 10988e9..2761ae6 100644 --- a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/SourcesActivity.kt +++ b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/SourcesActivity.kt @@ -5,11 +5,13 @@ import android.content.res.ColorStateList import android.os.Bundle import android.widget.Toast import androidx.appcompat.app.AppCompatActivity +import androidx.lifecycle.lifecycleScope import androidx.recyclerview.widget.LinearLayoutManager import bou.amine.apps.readerforselfossv2.android.adapters.SourcesListAdapter import bou.amine.apps.readerforselfossv2.android.databinding.ActivitySourcesBinding import bou.amine.apps.readerforselfossv2.android.themes.AppColors import bou.amine.apps.readerforselfossv2.android.themes.Toppings +import bou.amine.apps.readerforselfossv2.android.viewmodel.AppViewModel import bou.amine.apps.readerforselfossv2.repository.Repository import bou.amine.apps.readerforselfossv2.rest.SelfossModel import com.ftinc.scoop.Scoop @@ -27,6 +29,7 @@ class SourcesActivity : AppCompatActivity(), DIAware { override val di by closestDI() private val repository : Repository by instance() + private val viewModel : AppViewModel by instance() override fun onCreate(savedInstanceState: Bundle?) { appColors = AppColors(this@SourcesActivity) @@ -47,6 +50,16 @@ class SourcesActivity : AppCompatActivity(), DIAware { binding.fab.rippleColor = appColors.colorAccentDark binding.fab.backgroundTintList = ColorStateList.valueOf(appColors.colorAccent) + + lifecycleScope.launch { + viewModel.toastMessageProvider.collect { toastMessage -> + Toast.makeText( + this@SourcesActivity, + toastMessage, + Toast.LENGTH_SHORT + ).show() + } + } } override fun onStop() { diff --git a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/fragments/ArticleFragment.kt b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/fragments/ArticleFragment.kt index abc8f2c..74d5d03 100644 --- a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/fragments/ArticleFragment.kt +++ b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/fragments/ArticleFragment.kt @@ -19,6 +19,7 @@ import androidx.browser.customtabs.CustomTabsIntent import androidx.core.content.res.ResourcesCompat import androidx.core.widget.NestedScrollView import androidx.fragment.app.Fragment +import androidx.lifecycle.lifecycleScope import androidx.room.Room import bou.amine.apps.readerforselfossv2.android.ImageActivity import bou.amine.apps.readerforselfossv2.android.R @@ -35,6 +36,7 @@ import bou.amine.apps.readerforselfossv2.android.utils.* import bou.amine.apps.readerforselfossv2.android.utils.customtabs.CustomTabActivityHelper import bou.amine.apps.readerforselfossv2.android.utils.glide.getBitmapInputStream import bou.amine.apps.readerforselfossv2.android.utils.glide.loadMaybeBasicAuth +import bou.amine.apps.readerforselfossv2.android.viewmodel.AppViewModel import bou.amine.apps.readerforselfossv2.repository.Repository import bou.amine.apps.readerforselfossv2.rest.SelfossModel import bou.amine.apps.readerforselfossv2.utils.isEmptyOrNullOrNullString @@ -79,6 +81,7 @@ class ArticleFragment : Fragment(), DIAware { override val di : DI by closestDI() private val repository: Repository by instance() + private val viewModel : AppViewModel by instance() private var settings = Settings() @@ -108,6 +111,16 @@ class ArticleFragment : Fragment(), DIAware { requireContext(), AppDatabase::class.java, "selfoss-database" ).addMigrations(MIGRATION_1_2).addMigrations(MIGRATION_2_3).addMigrations(MIGRATION_3_4).build() + + lifecycleScope.launch { + viewModel.toastMessageProvider.collect { toastMessage -> + Toast.makeText( + context, + toastMessage, + Toast.LENGTH_SHORT + ).show() + } + } } override fun onCreateView(