From 8b2be5c55c92387dd2283f24f77a098622182afc Mon Sep 17 00:00:00 2001 From: aminecmi Date: Fri, 26 Aug 2022 23:21:13 +0200 Subject: [PATCH] Refreshing settings. --- .../apps/readerforselfossv2/android/HomeActivity.kt | 11 ++++++++++- .../android/settings/SettingsActivity.kt | 7 +++++++ .../readerforselfossv2/repository/RepositoryImpl.kt | 1 - 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/HomeActivity.kt b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/HomeActivity.kt index b70c25f..3e8f487 100644 --- a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/HomeActivity.kt +++ b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/HomeActivity.kt @@ -66,8 +66,10 @@ import org.kodein.di.instance import java.util.concurrent.TimeUnit import kotlin.concurrent.thread + class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener, DIAware { + private val SETTINGS_ACTIVITY: Int = 101111 private val DRAWER_ID_TAGS = 100101L private val DRAWER_ID_HIDDEN_TAGS = 101100L private val DRAWER_ID_SOURCES = 100110L @@ -378,7 +380,7 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener, DIAwar iconRes = R.drawable.ic_settings_black_24dp isIconTinted = true onDrawerItemClickListener = { _, _, _ -> - startActivity(Intent(this@HomeActivity, SettingsActivity::class.java)) + startActivityForResult(Intent(this@HomeActivity, SettingsActivity::class.java), SETTINGS_ACTIVITY) false } }) @@ -1028,5 +1030,12 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener, DIAwar WorkManager.getInstance(baseContext).enqueueUniquePeriodicWork("selfoss-loading", ExistingPeriodicWorkPolicy.KEEP, backgroundWork) } } + + override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { + super.onActivityResult(requestCode, resultCode, data) + if (requestCode == SETTINGS_ACTIVITY) { + appSettingsService.refreshUserSettings() + } + } } diff --git a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/settings/SettingsActivity.kt b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/settings/SettingsActivity.kt index 4e4893a..f39c198 100644 --- a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/settings/SettingsActivity.kt +++ b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/settings/SettingsActivity.kt @@ -216,4 +216,11 @@ class SettingsActivity : AppCompatActivity(), setPreferencesFromResource(R.xml.pref_experimental, rootKey) } } + + override fun onOptionsItemSelected(item: MenuItem): Boolean { + when (item.itemId) { + android.R.id.home -> super.onBackPressed() + } + return super.onOptionsItemSelected(item) + } } \ No newline at end of file diff --git a/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/repository/RepositoryImpl.kt b/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/repository/RepositoryImpl.kt index 0ef29b1..0b915ed 100644 --- a/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/repository/RepositoryImpl.kt +++ b/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/repository/RepositoryImpl.kt @@ -362,7 +362,6 @@ class Repository(private val api: SelfossApi, private val appSettingsService: Ap appSettingsService.updateApiVersion(fetchedVersion.getApiMajorVersion()) } } - dateUtils = DateUtils(apiMajorVersion) } fun isNetworkAvailable() = isConnectionAvailable.value && !offlineOverride