Skip to content

Commit

Permalink
Bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
acristescu committed Sep 8, 2023
1 parent 34c8dd1 commit 925fc66
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 74 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class MainActivity : AppCompatActivity(), MainContract.View {

private lateinit var binding: ActivityMainBinding

private lateinit var requestPermissionLauncher: ActivityResultLauncher<String>
private var requestPermissionLauncher: ActivityResultLauncher<String>? = null

private val presenter: MainPresenter by lazy { MainPresenter(this, get(), get(), get(), get()) }

Expand Down Expand Up @@ -162,14 +162,19 @@ class MainActivity : AppCompatActivity(), MainContract.View {
}
}

override fun onDestroy() {
super.onDestroy()
requestPermissionLauncher = null
}

override fun askForNotificationsPermission(delayed: Boolean) {
CoroutineScope(Dispatchers.Main).launch {
if(delayed) {
delay(5000)
}
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)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
27 changes: 0 additions & 27 deletions app/src/main/res/layout/row_item_settings_dialog_theme.xml

This file was deleted.

0 comments on commit 925fc66

Please sign in to comment.