Skip to content

Commit ddf5d1d

Browse files
committed
Add error details on import screens
1 parent e81c978 commit ddf5d1d

File tree

25 files changed

+146
-42
lines changed

25 files changed

+146
-42
lines changed

core/designsystem/src/main/java/com/twofasapp/designsystem/dialog/Dialog.kt

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package com.twofasapp.designsystem.dialog
22

33
import androidx.compose.foundation.layout.Arrangement
44
import androidx.compose.foundation.layout.Column
5-
import androidx.compose.foundation.layout.ColumnScope
65
import androidx.compose.foundation.layout.PaddingValues
76
import androidx.compose.foundation.layout.Row
87
import androidx.compose.foundation.layout.Spacer
@@ -55,6 +54,7 @@ fun BaseDialog(
5554
negativeEnabled: Boolean = true,
5655
shape: Shape = TwTheme.shape.dialog,
5756
containerColor: Color = TwTheme.color.surface,
57+
contentScrollable: Boolean = true,
5858
properties: DialogProperties = DialogProperties(),
5959
content: @Composable () -> Unit = {},
6060
) {
@@ -87,14 +87,24 @@ fun BaseDialog(
8787
}
8888

8989
if (body != null || bodyAnnotated != null) {
90-
Body(
91-
text = body,
92-
textAnnotated = bodyAnnotated,
93-
onBodyClick = onBodyClick,
94-
)
95-
}
90+
if (contentScrollable) {
91+
Column(
92+
modifier = Modifier
93+
.verticalScroll(rememberScrollState())
94+
.weight(weight = 1f, fill = false),
95+
) {
96+
Body(text = body, textAnnotated = bodyAnnotated, onBodyClick = onBodyClick)
97+
98+
content()
99+
}
100+
} else {
101+
Body(text = body, textAnnotated = bodyAnnotated, onBodyClick = onBodyClick)
96102

97-
content()
103+
content()
104+
}
105+
} else {
106+
content()
107+
}
98108

99109
if (showActions) {
100110
Actions(
@@ -136,7 +146,7 @@ private fun Title(
136146
}
137147

138148
@Composable
139-
private fun ColumnScope.Body(
149+
private fun Body(
140150
text: String?,
141151
textAnnotated: AnnotatedString?,
142152
onBodyClick: ((Int) -> Unit)? = null,
@@ -149,8 +159,6 @@ private fun ColumnScope.Body(
149159
modifier = Modifier
150160
.padding(horizontal = DialogPadding)
151161
.padding(TitlePadding)
152-
.verticalScroll(rememberScrollState())
153-
154162
)
155163
} else if (textAnnotated != null) {
156164
ClickableText(
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package com.twofasapp.designsystem.dialog
2+
3+
import androidx.compose.foundation.layout.Box
4+
import androidx.compose.runtime.Composable
5+
import androidx.compose.runtime.getValue
6+
import androidx.compose.runtime.mutableStateOf
7+
import androidx.compose.runtime.remember
8+
import androidx.compose.runtime.setValue
9+
import androidx.compose.ui.Alignment
10+
import androidx.compose.ui.Modifier
11+
import androidx.compose.ui.platform.LocalContext
12+
import com.twofasapp.designsystem.common.TwTextButton
13+
import com.twofasapp.designsystem.ktx.copyToClipboard
14+
15+
@Composable
16+
fun StackTraceDetails(
17+
modifier: Modifier = Modifier,
18+
title: String,
19+
content: String?,
20+
) {
21+
val context = LocalContext.current
22+
var showDialog by remember { mutableStateOf(false) }
23+
24+
if (content == null) return
25+
26+
Box(
27+
modifier = modifier,
28+
contentAlignment = Alignment.Center,
29+
) {
30+
TwTextButton(
31+
text = title,
32+
modifier = Modifier,
33+
onClick = { showDialog = true }
34+
)
35+
}
36+
37+
if (showDialog) {
38+
InfoDialog(
39+
onDismissRequest = { showDialog = false },
40+
title = "Error details",
41+
positive = "Ok",
42+
negative = "Copy",
43+
onNegative = { context.copyToClipboard(content) },
44+
body = content,
45+
)
46+
}
47+
}
48+
49+
fun Throwable.formatErrorDetails(): String {
50+
return buildString {
51+
append("Fatal Exception: ${this@formatErrorDetails.javaClass.name}")
52+
append("\n")
53+
append("\n")
54+
append(stackTrace.joinToString("\n"))
55+
}
56+
}

core/locale/src/main/java/com/twofasapp/locale/Strings.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ class Strings(c: Context) {
111111
val externalImportResultTokensMsg = c.getString(R.string.tokens__google_auth_import_subtitle_end)
112112
val externalImportResultErrorMsg = c.getString(R.string.externalimport__read_error)
113113
val externalImportSuccessToast = c.getString(R.string.backup__import_completed_successfuly)
114+
val showErrorDetails = c.getString(R.string.settings__show_error_details)
114115

115116
val trashTitle = c.getString(R.string.settings__trash)
116117
val trashEmpty = c.getString(R.string.settings__trash_is_empty)

core/locale/src/main/res/values-de-rDE/strings.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
Project: 2FAS App
55
Locale: de-DE, German (Germany)
66
Exported by: rafakob
7-
Exported at: Mon, 13 Jan 2025 14:09:32 -0800
7+
Exported at: Tue, 14 Jan 2025 04:37:30 -0800
88
-->
99
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
1010
<!-- InfoPlist.strings
@@ -854,4 +854,5 @@
854854
<string name="widget__no_selected_services">Gedrückt halten und Service auswählen, um das Widget zu aktivieren...</string>
855855
<string name="widget__reveal_tokens_long_message">Decke deine 2FAS-Token für 60 Sekunden auf</string>
856856
<string name="widget__reveal_tokens_short_message">Aufdecken für 60 Sekunden</string>
857+
<string name="settings__show_error_details">Show error details</string>
857858
</resources>

core/locale/src/main/res/values-el-rGR/strings.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
Project: 2FAS App
55
Locale: el-GR, Greek (Greece)
66
Exported by: rafakob
7-
Exported at: Mon, 13 Jan 2025 14:09:32 -0800
7+
Exported at: Tue, 14 Jan 2025 04:37:31 -0800
88
-->
99
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
1010
<!-- InfoPlist.strings
@@ -854,4 +854,5 @@
854854
<string name="widget__no_selected_services">Κρατήστε πατημένο και επιλέξτε service για να ενεργοποιήσετε το widget...</string>
855855
<string name="widget__reveal_tokens_long_message">Αποκαλύψτε τις μάρκες 2FAS για 60 δευτερόλεπτα</string>
856856
<string name="widget__reveal_tokens_short_message">Αποκάλυψη για 60 δευτερόλεπτα</string>
857+
<string name="settings__show_error_details">Show error details</string>
857858
</resources>

core/locale/src/main/res/values-es-rES/strings.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
Project: 2FAS App
55
Locale: es-ES, Spanish (Spain)
66
Exported by: rafakob
7-
Exported at: Mon, 13 Jan 2025 14:09:32 -0800
7+
Exported at: Tue, 14 Jan 2025 04:37:30 -0800
88
-->
99
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
1010
<!-- InfoPlist.strings
@@ -854,4 +854,5 @@
854854
<string name="widget__no_selected_services">Mantén pulsado y selecciona servicio para activar el widget...</string>
855855
<string name="widget__reveal_tokens_long_message">Revela tus fichas 2FAS durante 60 segundos</string>
856856
<string name="widget__reveal_tokens_short_message">Revela durante 60 segundos</string>
857+
<string name="settings__show_error_details">Show error details</string>
857858
</resources>

core/locale/src/main/res/values-fr-rFR/strings.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
Project: 2FAS App
55
Locale: fr-FR, French (France)
66
Exported by: rafakob
7-
Exported at: Mon, 13 Jan 2025 14:09:32 -0800
7+
Exported at: Tue, 14 Jan 2025 04:37:30 -0800
88
-->
99
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
1010
<!-- InfoPlist.strings
@@ -854,4 +854,5 @@
854854
<string name="widget__no_selected_services">Maintenir et sélectionner le service pour activer le widget...</string>
855855
<string name="widget__reveal_tokens_long_message">Révéler les jetons 2FAS pendant 60 secondes</string>
856856
<string name="widget__reveal_tokens_short_message">Révéler pendant 60 secondes</string>
857+
<string name="settings__show_error_details">Show error details</string>
857858
</resources>

core/locale/src/main/res/values-it-rIT/strings.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
Project: 2FAS App
55
Locale: it-IT, Italian (Italy)
66
Exported by: rafakob
7-
Exported at: Mon, 13 Jan 2025 14:09:32 -0800
7+
Exported at: Tue, 14 Jan 2025 04:37:31 -0800
88
-->
99
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
1010
<!-- InfoPlist.strings
@@ -854,4 +854,5 @@
854854
<string name="widget__no_selected_services">Tieni premuto e seleziona un servizio per attivare il widget...</string>
855855
<string name="widget__reveal_tokens_long_message">Mostra il tuo token 2FAS per 60 secondi</string>
856856
<string name="widget__reveal_tokens_short_message">Mostra per 60 secondi</string>
857+
<string name="settings__show_error_details">Show error details</string>
857858
</resources>

core/locale/src/main/res/values-ja-rJP/strings.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
Project: 2FAS App
55
Locale: ja-JP, Japanese (Japan)
66
Exported by: rafakob
7-
Exported at: Mon, 13 Jan 2025 14:09:32 -0800
7+
Exported at: Tue, 14 Jan 2025 04:37:31 -0800
88
-->
99
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
1010
<!-- InfoPlist.strings
@@ -848,4 +848,5 @@
848848
<string name="widget__no_selected_services">ウィジェットを有効化するには、サービスを長押しして選択してください...</string>
849849
<string name="widget__reveal_tokens_long_message">2FASのトークンを60秒間表示</string>
850850
<string name="widget__reveal_tokens_short_message">60秒間表示</string>
851+
<string name="settings__show_error_details">Show error details</string>
851852
</resources>

core/locale/src/main/res/values-nl-rNL/strings.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
Project: 2FAS App
55
Locale: nl-NL, Dutch (Netherlands)
66
Exported by: rafakob
7-
Exported at: Mon, 13 Jan 2025 14:09:32 -0800
7+
Exported at: Tue, 14 Jan 2025 04:37:31 -0800
88
-->
99
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
1010
<!-- InfoPlist.strings
@@ -854,4 +854,5 @@
854854
<string name="widget__no_selected_services">Houd de service ingedrukt en selecteer deze om de widget te activeren...</string>
855855
<string name="widget__reveal_tokens_long_message">Uw 2FAS tokens voor 60 seconden onthullen</string>
856856
<string name="widget__reveal_tokens_short_message">60 seconden onthullen</string>
857+
<string name="settings__show_error_details">Show error details</string>
857858
</resources>

core/locale/src/main/res/values-pl-rPL/strings.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
Project: 2FAS App
55
Locale: pl-PL, Polish (Poland)
66
Exported by: rafakob
7-
Exported at: Mon, 13 Jan 2025 14:09:32 -0800
7+
Exported at: Tue, 14 Jan 2025 04:37:31 -0800
88
-->
99
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
1010
<!-- InfoPlist.strings
@@ -860,4 +860,5 @@
860860
<string name="widget__no_selected_services">Przytrzymaj i wybierz serwis, aby aktywować widget...</string>
861861
<string name="widget__reveal_tokens_long_message">Odsłoń swoje tokeny 2FAS na 60 sekund</string>
862862
<string name="widget__reveal_tokens_short_message">Odsłoń na 60 sekund</string>
863+
<string name="settings__show_error_details">Show error details</string>
863864
</resources>

core/locale/src/main/res/values-pt-rBR/strings.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
Project: 2FAS App
55
Locale: pt-BR, Brazilian Portuguese
66
Exported by: rafakob
7-
Exported at: Mon, 13 Jan 2025 14:09:32 -0800
7+
Exported at: Tue, 14 Jan 2025 04:37:31 -0800
88
-->
99
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
1010
<!-- InfoPlist.strings
@@ -854,4 +854,5 @@
854854
<string name="widget__no_selected_services">Mantenha pressionado e selecione o serviço para ativar o widget...</string>
855855
<string name="widget__reveal_tokens_long_message">Revele seus tokens 2FAS por 60 segundos</string>
856856
<string name="widget__reveal_tokens_short_message">Revele por 60 segundos</string>
857+
<string name="settings__show_error_details">Show error details</string>
857858
</resources>

core/locale/src/main/res/values-pt-rPT/strings.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
Project: 2FAS App
55
Locale: pt-PT, Portuguese (Portugal)
66
Exported by: rafakob
7-
Exported at: Mon, 13 Jan 2025 14:09:32 -0800
7+
Exported at: Tue, 14 Jan 2025 04:37:31 -0800
88
-->
99
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
1010
<!-- InfoPlist.strings
@@ -854,4 +854,5 @@
854854
<string name="widget__no_selected_services">Mantenha premido e selecione serviço para ativar o widget...</string>
855855
<string name="widget__reveal_tokens_long_message">Revele as suas fichas 2FAS durante 60 segundos</string>
856856
<string name="widget__reveal_tokens_short_message">Revelar durante 60 segundos</string>
857+
<string name="settings__show_error_details">Show error details</string>
857858
</resources>

core/locale/src/main/res/values-tr-rTR/strings.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
Project: 2FAS App
55
Locale: tr-TR, Turkish (Turkey)
66
Exported by: rafakob
7-
Exported at: Mon, 13 Jan 2025 14:09:32 -0800
7+
Exported at: Tue, 14 Jan 2025 04:37:31 -0800
88
-->
99
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
1010
<!-- InfoPlist.strings
@@ -854,4 +854,5 @@
854854
<string name="widget__no_selected_services">Widget\'ı etkinleştirmek için basılı tutun ve servisi seçin...</string>
855855
<string name="widget__reveal_tokens_long_message">2FAS jetonları 60 saniye boyunca gösterin</string>
856856
<string name="widget__reveal_tokens_short_message">60 saniye boyunca göster</string>
857+
<string name="settings__show_error_details">Show error details</string>
857858
</resources>

core/locale/src/main/res/values-uk-rUA/strings.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
Project: 2FAS App
55
Locale: uk-UA, Ukrainian (Ukraine)
66
Exported by: rafakob
7-
Exported at: Mon, 13 Jan 2025 14:09:32 -0800
7+
Exported at: Tue, 14 Jan 2025 04:37:31 -0800
88
-->
99
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
1010
<!-- InfoPlist.strings
@@ -860,4 +860,5 @@
860860
<string name="widget__no_selected_services">Утримуйте та оберіть послугу, щоб активувати віджет...</string>
861861
<string name="widget__reveal_tokens_long_message">Розкрийте свої токени 2FAS на 60 секунд</string>
862862
<string name="widget__reveal_tokens_short_message">Розкрийте на 60 секунд</string>
863+
<string name="settings__show_error_details">Show error details</string>
863864
</resources>

core/locale/src/main/res/values-zh/strings.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
Project: 2FAS App
55
Locale: zh-Hans, Simplified Chinese
66
Exported by: rafakob
7-
Exported at: Mon, 13 Jan 2025 14:09:32 -0800
7+
Exported at: Tue, 14 Jan 2025 04:37:31 -0800
88
-->
99
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
1010
<!-- InfoPlist.strings
@@ -848,4 +848,5 @@
848848
<string name="widget__no_selected_services">请按住并选择服务以激活小部件...</string>
849849
<string name="widget__reveal_tokens_long_message">显示您的 2FAS 令牌 60 秒</string>
850850
<string name="widget__reveal_tokens_short_message">显示 60 秒</string>
851+
<string name="settings__show_error_details">Show error details</string>
851852
</resources>

core/locale/src/main/res/values/strings.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
Project: 2FAS App
55
Locale: en, English
66
Exported by: rafakob
7-
Exported at: Mon, 13 Jan 2025 14:09:31 -0800
7+
Exported at: Tue, 14 Jan 2025 04:37:30 -0800
88
-->
99
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
1010
<!-- InfoPlist.strings
@@ -854,4 +854,5 @@
854854
<string name="widget__no_selected_services">Hold and select service to activate widget...</string>
855855
<string name="widget__reveal_tokens_long_message">Reveal your 2FAS tokens for 60 seconds</string>
856856
<string name="widget__reveal_tokens_short_message">Reveal for 60 seconds</string>
857+
<string name="settings__show_error_details">Show error details</string>
857858
</resources>

feature/backup/src/main/java/com/twofasapp/feature/backup/ui/import/BackupImportScreen.kt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import com.twofasapp.designsystem.common.TwTextButton
3434
import com.twofasapp.designsystem.common.TwTopAppBar
3535
import com.twofasapp.designsystem.dialog.InfoDialog
3636
import com.twofasapp.designsystem.dialog.PasswordDialog
37+
import com.twofasapp.designsystem.dialog.StackTraceDetails
3738
import com.twofasapp.designsystem.ktx.strings
3839
import com.twofasapp.designsystem.ktx.toastShort
3940
import org.koin.androidx.compose.koinViewModel
@@ -190,7 +191,13 @@ private fun ScreenContent(
190191
)
191192
}
192193

193-
is ScreenState.ErrorInvalidFile -> Unit
194+
is ScreenState.ErrorInvalidFile -> {
195+
StackTraceDetails(
196+
title = strings.showErrorDetails,
197+
content = uiState.screenState.reason,
198+
)
199+
}
200+
194201
is ScreenState.ErrorInvalidFileSize -> Unit
195202
}
196203

feature/backup/src/main/java/com/twofasapp/feature/backup/ui/import/BackupImportUiState.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ internal data class BackupImportUiState(
1414
internal sealed interface ScreenState {
1515
data class BackupRead(val servicesToImport: Int) : ScreenState
1616
data object BackupReadEncrypted : ScreenState
17-
data object ErrorInvalidFile : ScreenState
17+
data class ErrorInvalidFile(val reason: String?) : ScreenState
1818
data object ErrorInvalidFileSize : ScreenState
1919
}
2020

feature/backup/src/main/java/com/twofasapp/feature/backup/ui/import/BackupImportViewModel.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import com.twofasapp.data.services.domain.BackupContent
1313
import com.twofasapp.data.services.exceptions.DecryptWrongPassword
1414
import com.twofasapp.data.services.exceptions.FileTooBigException
1515
import com.twofasapp.data.session.SessionRepository
16+
import com.twofasapp.designsystem.dialog.formatErrorDetails
1617
import kotlinx.coroutines.flow.MutableStateFlow
1718
import kotlinx.coroutines.flow.update
1819

@@ -66,7 +67,7 @@ internal class BackupImportViewModel(
6667
.onFailure { e ->
6768
when (e) {
6869
is FileTooBigException -> uiState.update { it.copy(screenState = ScreenState.ErrorInvalidFileSize) }
69-
else -> uiState.update { it.copy(screenState = ScreenState.ErrorInvalidFile) }
70+
else -> uiState.update { it.copy(screenState = ScreenState.ErrorInvalidFile(reason = e.formatErrorDetails())) }
7071
}
7172
}
7273
}

0 commit comments

Comments
 (0)