From 925fc66ced7d343b2104835e10487650a31c1bb0 Mon Sep 17 00:00:00 2001 From: Alexandru Cristescu Date: Fri, 8 Sep 2023 12:16:58 +0100 Subject: [PATCH] Bugfixes --- .../repositories/UserSessionRepository.kt | 85 +++++++++---------- .../onlinego/ui/screens/main/MainActivity.kt | 9 +- .../onlinego/utils/WhatsNewUtils.kt | 2 + .../layout/row_item_settings_dialog_theme.xml | 27 ------ 4 files changed, 49 insertions(+), 74 deletions(-) delete mode 100644 app/src/main/res/layout/row_item_settings_dialog_theme.xml diff --git a/app/src/main/java/io/zenandroid/onlinego/data/repositories/UserSessionRepository.kt b/app/src/main/java/io/zenandroid/onlinego/data/repositories/UserSessionRepository.kt index 246e4255..aa88cb51 100644 --- a/app/src/main/java/io/zenandroid/onlinego/data/repositories/UserSessionRepository.kt +++ b/app/src/main/java/io/zenandroid/onlinego/data/repositories/UserSessionRepository.kt @@ -16,53 +16,48 @@ import okhttp3.HttpUrl.Companion.toHttpUrlOrNull import org.koin.core.context.GlobalContext.get class UserSessionRepository { - // Note: Can't use constructor injection here because it will create a dependency loop and - // Koin will throw a fit (at runtime) - private val socketService: OGSWebSocketService by get().inject() - private val restService: OGSRestService by get().inject() + // Note: Can't use constructor injection here because it will create a dependency loop and + // Koin will throw a fit (at runtime) + private val socketService: OGSWebSocketService by get().inject() + private val restService: OGSRestService by get().inject() - var uiConfig: UIConfig? = null - private set + var uiConfig: UIConfig? = null + private set - val userId: Long? - get() = uiConfig?.user?.id + val userId: Long? + get() = uiConfig?.user?.id // get() = 126739L - val cookieJar = PersistentCookieJar(SetCookieCache(), SharedPrefsCookiePersistor(OnlineGoApplication.instance)) - - init { - uiConfig = PersistenceManager.getUIConfig() - userId?.toString()?.let(FirebaseCrashlytics.getInstance()::setUserId) - } - - fun storeUIConfig(uiConfig: UIConfig) { - this.uiConfig = uiConfig - socketService.resendAuth() - FirebaseCrashlytics.getInstance().setUserId(uiConfig.user?.id.toString()) - PersistenceManager.storeUIConfig(uiConfig) - } - - fun requiresUIConfigRefresh(): Boolean { - if(uiConfig?.user_jwt == null) { - return true - } - - return false - } - - fun isLoggedIn() = - (uiConfig != null) && - cookieJar.loadForRequest(BuildConfig.BASE_URL.toHttpUrlOrNull()!!) - .any { it.name == "sessionid" } - - fun logOut() { - FirebaseCrashlytics.getInstance().sendUnsentReports() - uiConfig = null - (OnlineGoApplication.instance.getSystemService(ACTIVITY_SERVICE) as ActivityManager).clearApplicationUserData() - } - - suspend fun deleteAccount(password: String) { - restService.deleteMyAccount(password) - } - + val cookieJar = + PersistentCookieJar(SetCookieCache(), SharedPrefsCookiePersistor(OnlineGoApplication.instance)) + + init { + uiConfig = PersistenceManager.getUIConfig() + userId?.toString()?.let(FirebaseCrashlytics.getInstance()::setUserId) + } + + fun storeUIConfig(uiConfig: UIConfig) { + this.uiConfig = uiConfig + socketService.resendAuth() + FirebaseCrashlytics.getInstance().setUserId(uiConfig.user?.id.toString()) + PersistenceManager.storeUIConfig(uiConfig) + } + + fun requiresUIConfigRefresh(): Boolean = + uiConfig?.user_jwt == null + + fun isLoggedIn() = + (uiConfig != null) && + cookieJar.loadForRequest(BuildConfig.BASE_URL.toHttpUrlOrNull()!!) + .any { it.name == "sessionid" } + + fun logOut() { + FirebaseCrashlytics.getInstance().sendUnsentReports() + uiConfig = null + (OnlineGoApplication.instance.getSystemService(ACTIVITY_SERVICE) as ActivityManager).clearApplicationUserData() + } + + suspend fun deleteAccount(password: String) { + restService.deleteMyAccount(password) + } } \ No newline at end of file diff --git a/app/src/main/java/io/zenandroid/onlinego/ui/screens/main/MainActivity.kt b/app/src/main/java/io/zenandroid/onlinego/ui/screens/main/MainActivity.kt index e0845f34..5d524f4c 100644 --- a/app/src/main/java/io/zenandroid/onlinego/ui/screens/main/MainActivity.kt +++ b/app/src/main/java/io/zenandroid/onlinego/ui/screens/main/MainActivity.kt @@ -59,7 +59,7 @@ class MainActivity : AppCompatActivity(), MainContract.View { private lateinit var binding: ActivityMainBinding - private lateinit var requestPermissionLauncher: ActivityResultLauncher + private var requestPermissionLauncher: ActivityResultLauncher? = null private val presenter: MainPresenter by lazy { MainPresenter(this, get(), get(), get(), get()) } @@ -162,6 +162,11 @@ class MainActivity : AppCompatActivity(), MainContract.View { } } + override fun onDestroy() { + super.onDestroy() + requestPermissionLauncher = null + } + override fun askForNotificationsPermission(delayed: Boolean) { CoroutineScope(Dispatchers.Main).launch { if(delayed) { @@ -169,7 +174,7 @@ class MainActivity : AppCompatActivity(), MainContract.View { } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { if (ContextCompat.checkSelfPermission(applicationContext, Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED) { - requestPermissionLauncher.launch(Manifest.permission.POST_NOTIFICATIONS) + requestPermissionLauncher?.launch(Manifest.permission.POST_NOTIFICATIONS) } } } diff --git a/app/src/main/java/io/zenandroid/onlinego/utils/WhatsNewUtils.kt b/app/src/main/java/io/zenandroid/onlinego/utils/WhatsNewUtils.kt index c772f5a1..af2672cf 100644 --- a/app/src/main/java/io/zenandroid/onlinego/utils/WhatsNewUtils.kt +++ b/app/src/main/java/io/zenandroid/onlinego/utils/WhatsNewUtils.kt @@ -36,6 +36,8 @@ private val annotatedCurrentText = AnnotatedString.Builder().run { append("\n") append("· New Settings screen!") append("\n") + append("· Added ability to delete account. Careful with it, it cannot be undone!") + append("\n") append("· Lots of bugfixes") pop() diff --git a/app/src/main/res/layout/row_item_settings_dialog_theme.xml b/app/src/main/res/layout/row_item_settings_dialog_theme.xml deleted file mode 100644 index a5e7282e..00000000 --- a/app/src/main/res/layout/row_item_settings_dialog_theme.xml +++ /dev/null @@ -1,27 +0,0 @@ - - - - - - - - - \ No newline at end of file