-
Notifications
You must be signed in to change notification settings - Fork 0
feat: Modal disconnect from account details #181
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
737108f
feat: Add ic_circle_information_outlined drawable
baillyjamy 5ab5b99
chore: Add disconnectCriticalButton string resource
baillyjamy 9092df2
chore: Add disconnectAccountPartiallySecured string resources
baillyjamy 383dd80
chore: Add disconnectAccountAdd2faButton string resource
baillyjamy dfc84ce
chore: Add removeAccountWarningTitle and removeAccountWarningDescript…
baillyjamy 33d4377
chore: Add removeAccountButton string resource
baillyjamy 6b23498
feat: Add disconnect account dialog flow
baillyjamy 6389baf
Merge remote-tracking branch 'origin/main' into feat-modal-disconnect
baillyjamy 86276d4
Merge remote-tracking branch 'origin/feat-security-status' into feat-…
baillyjamy a593e00
feat: Remove account without user
baillyjamy 15b3433
Merge remote-tracking branch 'origin/main' into feat-modal-disconnect
baillyjamy fc733f3
feat: Move Dialog package
baillyjamy 26ba080
feat: Use viewmodel in disconnect dialog
baillyjamy da9978a
refactor: Rename DisconnectViewModel to DisconnectDialogViewModel
baillyjamy 16fd8e1
fix: Remove useless dialog property
baillyjamy 7f4c6a6
fix: Remove useless @Serializable
baillyjamy bdf7c0a
Merge remote-tracking branch 'origin/main' into feat-modal-disconnect
baillyjamy c5361ba
fix: Apply copilote suggestions
baillyjamy e0fa9b0
fix: Remove useless accountRemovedChannel
baillyjamy 84c5821
chore: Remove useless Channel
tevincent File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
app/src/main/kotlin/com/infomaniak/auth/ui/dialog/disconnect/DisconnectConfirmDialog.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| /* | ||
| * Infomaniak Authenticator - Android | ||
| * Copyright (C) 2026 Infomaniak Network SA | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU General Public License as published by | ||
| * the Free Software Foundation, either version 3 of the License, or | ||
| * (at your option) any later version. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU General Public License | ||
| * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| */ | ||
| package com.infomaniak.auth.ui.dialog.disconnect | ||
|
|
||
| import android.annotation.SuppressLint | ||
| import androidx.compose.material3.AlertDialog | ||
| import androidx.compose.material3.ButtonDefaults | ||
| import androidx.compose.material3.Icon | ||
| import androidx.compose.material3.MaterialTheme | ||
| import androidx.compose.material3.Scaffold | ||
| import androidx.compose.material3.Text | ||
| import androidx.compose.material3.TextButton | ||
| import androidx.compose.runtime.Composable | ||
| import androidx.compose.runtime.LaunchedEffect | ||
| import androidx.compose.ui.res.painterResource | ||
| import androidx.compose.ui.res.stringResource | ||
| import androidx.compose.ui.text.style.TextAlign | ||
| import androidx.hilt.lifecycle.viewmodel.compose.hiltViewModel | ||
| import com.infomaniak.auth.R | ||
| import com.infomaniak.auth.ui.screen.accountdetails.DisconnectConfiguration | ||
| import com.infomaniak.auth.ui.theme.AuthenticatorTheme | ||
| import com.infomaniak.core.ui.compose.preview.PreviewSmallWindow | ||
|
|
||
| @Composable | ||
| fun DisconnectConfirmDialog( | ||
| accountId: Long, | ||
| configuration: DisconnectConfiguration, | ||
| onAccountDisconnected: () -> Unit, | ||
| onDismissRequest: () -> Unit, | ||
| viewModel: DisconnectDialogViewModel = hiltViewModel() | ||
| ) { | ||
| LaunchedEffect(Unit) { | ||
| viewModel.fetchAccountDetails(accountId) | ||
| } | ||
|
|
||
| AlertDialog( | ||
| icon = { | ||
| Icon( | ||
| painter = painterResource(R.drawable.triangle_alert), | ||
| contentDescription = null | ||
| ) | ||
| }, | ||
| onDismissRequest = onDismissRequest, | ||
| title = { | ||
| Text( | ||
| text = stringResource(configuration.confirmationTitleResId), | ||
| textAlign = TextAlign.Center | ||
| ) | ||
| }, | ||
| text = { | ||
| Text(text = stringResource(configuration.confirmationDescriptionResId)) | ||
| }, | ||
| confirmButton = { | ||
| TextButton( | ||
| onClick = { | ||
| viewModel.removeAccount(onAccountRemoved = onAccountDisconnected) | ||
| }, | ||
| colors = ButtonDefaults.textButtonColors( | ||
| contentColor = MaterialTheme.colorScheme.error, | ||
| ) | ||
| ) { | ||
| Text(stringResource(configuration.criticalButtonStringResId)) | ||
| } | ||
| } | ||
| ) | ||
| } | ||
|
|
||
| @SuppressLint("UnusedMaterial3ScaffoldPaddingParameter") | ||
| @PreviewSmallWindow | ||
| @Composable | ||
| private fun DisconnectWarningDialogPreview() { | ||
| AuthenticatorTheme { | ||
| Scaffold { _ -> | ||
| DisconnectConfirmDialog( | ||
| accountId = 1L, | ||
| configuration = DisconnectConfiguration.DisconnectSecuredAccount, | ||
| onAccountDisconnected = {}, | ||
| onDismissRequest = {}, | ||
| ) | ||
| } | ||
| } | ||
| } |
76 changes: 76 additions & 0 deletions
76
app/src/main/kotlin/com/infomaniak/auth/ui/dialog/disconnect/DisconnectDialogViewModel.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| /* | ||
| * Infomaniak Authenticator - Android | ||
| * Copyright (C) 2026 Infomaniak Network SA | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU General Public License as published by | ||
| * the Free Software Foundation, either version 3 of the License, or | ||
| * (at your option) any later version. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU General Public License | ||
| * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| */ | ||
| package com.infomaniak.auth.ui.dialog.disconnect | ||
|
|
||
| import androidx.lifecycle.ViewModel | ||
| import androidx.lifecycle.viewModelScope | ||
| import com.infomaniak.auth.lib.AuthenticatorFacade | ||
| import com.infomaniak.auth.utils.AccountUtils | ||
| import dagger.hilt.android.lifecycle.HiltViewModel | ||
| import kotlinx.coroutines.Dispatchers | ||
| import kotlinx.coroutines.ExperimentalCoroutinesApi | ||
| import kotlinx.coroutines.channels.BufferOverflow | ||
| import kotlinx.coroutines.flow.MutableSharedFlow | ||
| import kotlinx.coroutines.flow.SharingStarted | ||
| import kotlinx.coroutines.flow.combine | ||
| import kotlinx.coroutines.flow.first | ||
| import kotlinx.coroutines.flow.flatMapLatest | ||
| import kotlinx.coroutines.flow.stateIn | ||
| import kotlinx.coroutines.launch | ||
| import javax.inject.Inject | ||
|
|
||
| @OptIn(ExperimentalCoroutinesApi::class) | ||
| @HiltViewModel | ||
| class DisconnectDialogViewModel @Inject constructor( | ||
| private val accountUtils: AccountUtils, | ||
| private val authenticatorFacade: AuthenticatorFacade, | ||
| ) : ViewModel() { | ||
| private val accountIdFlow = MutableSharedFlow<Long>(replay = 1, onBufferOverflow = BufferOverflow.DROP_OLDEST) | ||
|
|
||
| val userAccessToken = accountIdFlow | ||
| .flatMapLatest { id -> | ||
| combine( | ||
| accountUtils.users, | ||
| authenticatorFacade.accounts | ||
| ) { users, accounts -> | ||
| val user = users.find { it.id.toLong() == id } | ||
| val account = accounts.find { it.id == id } | ||
|
|
||
| if (account != null) user?.apiToken?.accessToken else null | ||
| } | ||
| } | ||
| .stateIn( | ||
| scope = viewModelScope, | ||
| started = SharingStarted.Eagerly, | ||
| initialValue = null | ||
| ) | ||
|
|
||
| fun fetchAccountDetails(accountId: Long) { | ||
| accountIdFlow.tryEmit(accountId) | ||
| } | ||
|
|
||
| fun removeAccount(onAccountRemoved: () -> Unit) { | ||
| viewModelScope.launch(Dispatchers.IO) { | ||
| accountIdFlow.first().let { accountId -> | ||
| accountUtils.removeUser(accountId.toInt()) | ||
| authenticatorFacade.removeAccount(token = null, id = accountId) | ||
| onAccountRemoved() | ||
| } | ||
| } | ||
| } | ||
| } | ||
125 changes: 125 additions & 0 deletions
125
app/src/main/kotlin/com/infomaniak/auth/ui/dialog/disconnect/DisconnectWarningDialog.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,125 @@ | ||
| /* | ||
| * Infomaniak Authenticator - Android | ||
| * Copyright (C) 2026 Infomaniak Network SA | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU General Public License as published by | ||
| * the Free Software Foundation, either version 3 of the License, or | ||
| * (at your option) any later version. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU General Public License | ||
| * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| */ | ||
| package com.infomaniak.auth.ui.dialog.disconnect | ||
|
|
||
| import android.annotation.SuppressLint | ||
| import androidx.compose.material3.AlertDialog | ||
| import androidx.compose.material3.ButtonDefaults | ||
| import androidx.compose.material3.Icon | ||
| import androidx.compose.material3.MaterialTheme | ||
| import androidx.compose.material3.Scaffold | ||
| import androidx.compose.material3.Text | ||
| import androidx.compose.material3.TextButton | ||
| import androidx.compose.runtime.Composable | ||
| import androidx.compose.runtime.LaunchedEffect | ||
| import androidx.compose.runtime.getValue | ||
| import androidx.compose.ui.platform.LocalContext | ||
| import androidx.compose.ui.res.painterResource | ||
| import androidx.compose.ui.res.stringResource | ||
| import androidx.compose.ui.text.style.TextAlign | ||
| import androidx.hilt.lifecycle.viewmodel.compose.hiltViewModel | ||
| import androidx.lifecycle.compose.collectAsStateWithLifecycle | ||
| import com.infomaniak.auth.R | ||
| import com.infomaniak.auth.lib.models.UrlConstants | ||
| import com.infomaniak.auth.ui.screen.accountdetails.DisconnectConfiguration | ||
| import com.infomaniak.auth.ui.theme.AuthenticatorTheme | ||
| import com.infomaniak.core.network.ApiEnvironment | ||
| import com.infomaniak.core.ui.compose.preview.PreviewSmallWindow | ||
| import com.infomaniak.core.webview.ui.WebViewActivity | ||
|
|
||
| @Composable | ||
| fun DisconnectWarningDialog( | ||
| accountId: Long, | ||
| configuration: DisconnectConfiguration, | ||
| onDismissRequest: () -> Unit, | ||
| onConfirmButton: () -> Unit, | ||
| viewModel: DisconnectDialogViewModel = hiltViewModel() | ||
| ) { | ||
| val context = LocalContext.current | ||
| val host = ApiEnvironment.current.host | ||
|
|
||
| val userAccessToken by viewModel.userAccessToken.collectAsStateWithLifecycle() | ||
|
|
||
| LaunchedEffect(Unit) { | ||
| viewModel.fetchAccountDetails(accountId) | ||
| } | ||
|
|
||
| AlertDialog( | ||
| icon = { | ||
| Icon( | ||
| painter = painterResource(R.drawable.ic_circle_information_outlined), | ||
| contentDescription = null | ||
| ) | ||
| }, | ||
| onDismissRequest = onDismissRequest, | ||
| title = { | ||
| Text( | ||
| text = stringResource(configuration.warningTitleResId), | ||
| textAlign = TextAlign.Center | ||
| ) | ||
| }, | ||
| text = { | ||
| Text(text = stringResource(configuration.warningDescriptionResId)) | ||
| }, | ||
| confirmButton = { | ||
| TextButton( | ||
| onClick = onConfirmButton, | ||
| colors = ButtonDefaults.textButtonColors( | ||
| contentColor = MaterialTheme.colorScheme.error, | ||
| ) | ||
| ) { | ||
| Text(stringResource(configuration.criticalButtonStringResId)) | ||
| } | ||
| }, | ||
| dismissButton = { | ||
| if (userAccessToken != null) { | ||
| TextButton( | ||
| onClick = { | ||
| onDismissRequest() | ||
| WebViewActivity.startActivity( | ||
| context = context, | ||
| url = UrlConstants.autologUrl( | ||
| host = host, | ||
| UrlConstants.managerUrl(host, configuration.dismissHelpUrl) | ||
| ), | ||
| headers = mapOf("Authorization" to "Bearer $userAccessToken"), | ||
| ) | ||
| } | ||
| ) { | ||
| Text(stringResource(configuration.neutralButtonStringResId)) | ||
| } | ||
| } | ||
| } | ||
| ) | ||
| } | ||
|
|
||
| @SuppressLint("UnusedMaterial3ScaffoldPaddingParameter") | ||
| @PreviewSmallWindow | ||
| @Composable | ||
| private fun DisconnectWarningDialogPreview() { | ||
| AuthenticatorTheme { | ||
| Scaffold { _ -> | ||
| DisconnectWarningDialog( | ||
| accountId = 1L, | ||
| configuration = DisconnectConfiguration.DisconnectSecuredAccount, | ||
| onDismissRequest = {}, | ||
| onConfirmButton = {} | ||
| ) | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.