mirror of
https://github.com/bbara04/Purefin.git
synced 2026-07-24 03:36:51 +00:00
feat: implement logout functionality and settings provider
This commit is contained in:
@@ -16,6 +16,7 @@ interface UserSessionRepository {
|
||||
|
||||
val isLoggedIn: Flow<Boolean>
|
||||
suspend fun setLoggedIn(isLoggedIn: Boolean)
|
||||
suspend fun logout()
|
||||
|
||||
val isOfflineMode: Flow<Boolean>
|
||||
}
|
||||
}
|
||||
|
||||
@@ -288,7 +288,7 @@ class AppViewModel @Inject constructor(
|
||||
|
||||
fun logout() {
|
||||
viewModelScope.launch {
|
||||
userSessionRepository.setLoggedIn(false)
|
||||
userSessionRepository.logout()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
package hu.bbara.purefin.core.feature.settings
|
||||
|
||||
import hu.bbara.purefin.core.data.UserSessionRepository
|
||||
import hu.bbara.purefin.core.settings.SettingGroup
|
||||
import hu.bbara.purefin.core.settings.SettingsGroupProvider
|
||||
import hu.bbara.purefin.core.settings.VoidSetting
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.flowOf
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
@Singleton
|
||||
class LogoutSettingsProvider @Inject constructor(
|
||||
private val userSessionRepository: UserSessionRepository
|
||||
) : SettingsGroupProvider {
|
||||
|
||||
override val settingGroups: Flow<List<SettingGroup>> = flowOf(
|
||||
listOf(
|
||||
SettingGroup(
|
||||
title = "Account",
|
||||
options = listOf(
|
||||
VoidSetting(
|
||||
key = LOGOUT_KEY,
|
||||
title = "Log out",
|
||||
onClick = { userSessionRepository.logout() }
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
private companion object {
|
||||
const val LOGOUT_KEY = "logout"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package hu.bbara.purefin.core.settings
|
||||
|
||||
import dagger.Binds
|
||||
import dagger.Module
|
||||
import dagger.hilt.InstallIn
|
||||
import dagger.hilt.components.SingletonComponent
|
||||
import dagger.multibindings.IntoSet
|
||||
import hu.bbara.purefin.core.feature.settings.LogoutSettingsProvider
|
||||
import hu.bbara.purefin.core.feature.update.AppUpdateController
|
||||
|
||||
@Module
|
||||
@InstallIn(SingletonComponent::class)
|
||||
abstract class SettingsGroupProviderModule {
|
||||
|
||||
@Binds
|
||||
@IntoSet
|
||||
abstract fun bindAppUpdateSettingsProvider(impl: AppUpdateController): SettingsGroupProvider
|
||||
|
||||
@Binds
|
||||
@IntoSet
|
||||
abstract fun bindLogoutSettingsProvider(impl: LogoutSettingsProvider): SettingsGroupProvider
|
||||
}
|
||||
@@ -4,11 +4,8 @@ import dagger.Binds
|
||||
import dagger.Module
|
||||
import dagger.hilt.InstallIn
|
||||
import dagger.hilt.components.SingletonComponent
|
||||
import dagger.multibindings.IntoSet
|
||||
import hu.bbara.purefin.core.feature.update.AppUpdateController
|
||||
import hu.bbara.purefin.core.feature.update.AppUpdateInstaller
|
||||
import hu.bbara.purefin.core.feature.update.AppVersionProvider
|
||||
import hu.bbara.purefin.core.settings.SettingsGroupProvider
|
||||
|
||||
@Module
|
||||
@InstallIn(SingletonComponent::class)
|
||||
@@ -19,8 +16,4 @@ abstract class AppUpdateModule {
|
||||
|
||||
@Binds
|
||||
abstract fun bindAppVersionProvider(impl: AndroidAppVersionProvider): AppVersionProvider
|
||||
|
||||
@Binds
|
||||
@IntoSet
|
||||
abstract fun bindAppUpdateSettingsProvider(impl: AppUpdateController): SettingsGroupProvider
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user