diff --git a/app/src/main/java/org/futo/circles/feature/settings/SettingsDataSource.kt b/app/src/main/java/org/futo/circles/feature/settings/SettingsDataSource.kt index 0ff97506a62bfc0dda8bd72c9de4f56c29733fab..f09b610ea3b47e2a3e128f03febfaa57e62f1f7a 100644 --- a/app/src/main/java/org/futo/circles/feature/settings/SettingsDataSource.kt +++ b/app/src/main/java/org/futo/circles/feature/settings/SettingsDataSource.kt @@ -29,20 +29,6 @@ class SettingsDataSource @Inject constructor( val startReAuthEventLiveData = authConfirmationProvider.startReAuthEventLiveData val profileLiveData = session.userService().getUserLive(session.myUserId) - val loadingLiveData = MutableLiveData<LoadingData>() - private val loadingData = LoadingData(total = 0) - - suspend fun logOut() = createResult { - loadingLiveData.postValue( - loadingData.apply { - messageId = R.string.log_out - isLoading = true - } - ) - session.signOutService().signOut(true) - loadingLiveData.postValue(loadingData.apply { isLoading = false }) - } - suspend fun deactivateAccount(): Response<Unit> = createResult { session.accountService().deactivateAccount(false, authConfirmationProvider) } diff --git a/app/src/main/java/org/futo/circles/feature/settings/SettingsFragment.kt b/app/src/main/java/org/futo/circles/feature/settings/SettingsFragment.kt index f01f0ce7f17d8cf9cf628fb01e76d39a06fa47fb..7b686aec87c9920427c556737049cca941a4449f 100644 --- a/app/src/main/java/org/futo/circles/feature/settings/SettingsFragment.kt +++ b/app/src/main/java/org/futo/circles/feature/settings/SettingsFragment.kt @@ -14,6 +14,8 @@ import dagger.hilt.android.AndroidEntryPoint import org.futo.circles.BuildConfig import org.futo.circles.MainActivity import org.futo.circles.R +import org.futo.circles.auth.model.LogOut +import org.futo.circles.auth.model.SwitchUser import org.futo.circles.core.extensions.loadProfileIcon import org.futo.circles.core.extensions.notEmptyDisplayName import org.futo.circles.core.extensions.observeData @@ -28,8 +30,6 @@ import org.futo.circles.databinding.FragmentSettingsBinding import org.futo.circles.feature.home.SystemNoticesCountSharedViewModel import org.futo.circles.feature.settings.active_sessions.verify.qr.QrScannerActivity import org.futo.circles.model.DeactivateAccount -import org.futo.circles.model.LogOut -import org.futo.circles.model.SwitchUser import org.matrix.android.sdk.api.session.user.model.User @AndroidEntryPoint diff --git a/app/src/main/java/org/futo/circles/feature/settings/SettingsViewModel.kt b/app/src/main/java/org/futo/circles/feature/settings/SettingsViewModel.kt index 76e7e7d4ada143f9f47a3c44dd8bb4d4e1485121..9c1864c3215bfc01d42f995d02582c770947d471 100644 --- a/app/src/main/java/org/futo/circles/feature/settings/SettingsViewModel.kt +++ b/app/src/main/java/org/futo/circles/feature/settings/SettingsViewModel.kt @@ -2,19 +2,22 @@ package org.futo.circles.feature.settings import androidx.lifecycle.ViewModel import dagger.hilt.android.lifecycle.HiltViewModel +import org.futo.circles.auth.feature.log_in.log_out.LogoutDataSource import org.futo.circles.core.SingleEventLiveData import org.futo.circles.core.extensions.Response import org.futo.circles.core.extensions.createResult import org.futo.circles.core.extensions.launchBg import org.futo.circles.core.provider.MatrixSessionProvider import javax.inject.Inject + @HiltViewModel class SettingsViewModel @Inject constructor( - private val settingsDataSource: SettingsDataSource + private val settingsDataSource: SettingsDataSource, + private val logoutDataSource: LogoutDataSource ) : ViewModel() { val profileLiveData = settingsDataSource.profileLiveData - val loadingLiveData = settingsDataSource.loadingLiveData + val loadingLiveData = logoutDataSource.loadingLiveData val passPhraseLoadingLiveData = settingsDataSource.passPhraseLoadingLiveData val startReAuthEventLiveData = settingsDataSource.startReAuthEventLiveData val logOutLiveData = SingleEventLiveData<Response<Unit?>>() @@ -25,7 +28,7 @@ class SettingsViewModel @Inject constructor( val clearCacheLiveData = SingleEventLiveData<Unit>() fun logOut() { - launchBg { logOutLiveData.postValue(settingsDataSource.logOut()) } + launchBg { logOutLiveData.postValue(logoutDataSource.logOut()) } } fun deactivateAccount() { diff --git a/app/src/main/java/org/futo/circles/model/ConfirmationType.kt b/app/src/main/java/org/futo/circles/model/ConfirmationType.kt index 559d1fbb9eee85a2891c6bd7bc40abee3edb502d..6e8ff2f3920878f2ca25666d3812e9e2f80d37e2 100644 --- a/app/src/main/java/org/futo/circles/model/ConfirmationType.kt +++ b/app/src/main/java/org/futo/circles/model/ConfirmationType.kt @@ -10,18 +10,6 @@ data class DeactivateAccount( override val positiveButtonRes: Int = R.string.deactivate ) : ConfirmationType(titleRes, messageRes, positiveButtonRes) -data class SwitchUser( - override val titleRes: Int = R.string.switch_user, - override val messageRes: Int = R.string.switch_user_message, - override val positiveButtonRes: Int = R.string.switch_str -) : ConfirmationType(titleRes, messageRes, positiveButtonRes) - -data class LogOut( - override val titleRes: Int = R.string.log_out, - override val messageRes: Int = R.string.log_out_message, - override val positiveButtonRes: Int = R.string.log_out -) : ConfirmationType(titleRes, messageRes, positiveButtonRes) - data class IgnoreUser( override val titleRes: Int = R.string.ignore, override val messageRes: Int = R.string.ignore_user_message, diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 771da29345efe07f8a8a3ea1b4dbc03d45fab35d..4cc7fe016826e71855a4074abcb1cce3f3cc99b1 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -52,7 +52,6 @@ <string name="private_circles">Private Circles</string> <string name="log_out">Log out</string> <string name="others">Others</string> - <string name="log_out_message">Are you sure you want to log out?</string> <string name="session_is_not_created">Session is not created</string> <string name="following_format">Following %d</string> <string name="followed_by_format">Followed by %d</string> @@ -206,8 +205,6 @@ <string name="add_link">Add link</string> <string name="state_events">State events</string> <string name="switch_user">Switch User</string> - <string name="switch_str">Switch</string> - <string name="switch_user_message">Are you sure you want to switch user?</string> <string name="search_people">Search people</string> <string name="circle_type">Circle type</string> <string name="public_type">Public</string> diff --git a/auth/src/main/java/org/futo/circles/auth/model/ConfirmationType.kt b/auth/src/main/java/org/futo/circles/auth/model/ConfirmationType.kt index b4abc65e8172c6bfdbb5b419d8a1228cd90e2e94..78ae193122b1345c9f1f6b65581f342b282726af 100644 --- a/auth/src/main/java/org/futo/circles/auth/model/ConfirmationType.kt +++ b/auth/src/main/java/org/futo/circles/auth/model/ConfirmationType.kt @@ -7,4 +7,16 @@ data class RemoveUser( override val titleRes: Int = R.string.remove_user, override val messageRes: Int = R.string.remove_user_message, override val positiveButtonRes: Int = R.string.remove +) : ConfirmationType(titleRes, messageRes, positiveButtonRes) + +data class SwitchUser( + override val titleRes: Int = R.string.switch_user, + override val messageRes: Int = R.string.switch_user_message, + override val positiveButtonRes: Int = R.string.switch_str +) : ConfirmationType(titleRes, messageRes, positiveButtonRes) + +data class LogOut( + override val titleRes: Int = R.string.log_out, + override val messageRes: Int = R.string.log_out_message, + override val positiveButtonRes: Int = R.string.log_out ) : ConfirmationType(titleRes, messageRes, positiveButtonRes) \ No newline at end of file diff --git a/auth/src/main/res/values/strings.xml b/auth/src/main/res/values/strings.xml index 192e8bba0147148715864c3e63a5edeb20b528c0..f2c03307d9bbc76a7ccf5c2913c99e697fb1f428 100644 --- a/auth/src/main/res/values/strings.xml +++ b/auth/src/main/res/values/strings.xml @@ -99,6 +99,11 @@ <string name="item_not_owned">Item is not owned</string> <string name="developer_error">Developer error</string> <string name="purchase_failed_format">Purchase failed with code %d</string> + <string name="log_out">Log out</string> + <string name="log_out_message">Are you sure you want to log out?</string> + <string name="switch_user">Switch User</string> + <string name="switch_user_message">Are you sure you want to switch user?</string> + <string name="switch_str">Switch</string> <plurals name="days"> <item quantity="one">%1$d day</item>