Skip to content

Commit 59f4c06

Browse files
committed
feat(debug-settings): add secret debug settings screen
1 parent 997b72d commit 59f4c06

File tree

23 files changed

+944
-23
lines changed

23 files changed

+944
-23
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
plugins {
2+
id(ThunderbirdPlugins.Library.androidCompose)
3+
}
4+
5+
android {
6+
namespace = "net.thunderbird.feature.debugSettings"
7+
buildFeatures {
8+
buildConfig = true
9+
}
10+
}
11+
12+
dependencies {
13+
implementation(projects.core.ui.compose.designsystem)
14+
implementation(projects.core.ui.compose.navigation)
15+
implementation(projects.core.common)
16+
implementation(projects.core.outcome)
17+
implementation(projects.feature.mail.account.api)
18+
implementation(projects.feature.notification.api)
19+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package net.thunderbird.feature.debugSettings
2+
3+
import androidx.compose.foundation.layout.Box
4+
import androidx.compose.foundation.layout.padding
5+
import androidx.compose.runtime.Composable
6+
import androidx.compose.ui.Modifier
7+
import androidx.compose.ui.tooling.preview.PreviewLightDark
8+
import app.k9mail.core.ui.compose.designsystem.PreviewWithThemesLightDark
9+
import app.k9mail.core.ui.compose.designsystem.atom.text.TextBodyLarge
10+
import app.k9mail.core.ui.compose.theme2.MainTheme
11+
12+
@PreviewLightDark
13+
@Composable
14+
private fun DebugSectionPreview() {
15+
PreviewWithThemesLightDark {
16+
Box(modifier = Modifier.padding(MainTheme.spacings.triple)) {
17+
DebugSection(
18+
title = "Debug section",
19+
) {
20+
TextBodyLarge("Content")
21+
}
22+
}
23+
}
24+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package net.thunderbird.feature.debugSettings
2+
3+
import androidx.compose.foundation.layout.fillMaxSize
4+
import androidx.compose.runtime.Composable
5+
import androidx.compose.ui.Modifier
6+
import androidx.compose.ui.tooling.preview.PreviewLightDark
7+
import app.k9mail.core.ui.compose.common.koin.koinPreview
8+
import app.k9mail.core.ui.compose.designsystem.PreviewWithThemesLightDark
9+
import kotlinx.coroutines.flow.Flow
10+
import kotlinx.coroutines.flow.flowOf
11+
import net.thunderbird.core.outcome.Outcome
12+
import net.thunderbird.feature.debugSettings.notification.DebugNotificationSectionViewModel
13+
import net.thunderbird.feature.mail.account.api.AccountManager
14+
import net.thunderbird.feature.mail.account.api.BaseAccount
15+
import net.thunderbird.feature.notification.api.command.NotificationCommand.CommandOutcome.Failure
16+
import net.thunderbird.feature.notification.api.command.NotificationCommand.CommandOutcome.Success
17+
import net.thunderbird.feature.notification.api.content.Notification
18+
import net.thunderbird.feature.notification.api.sender.NotificationSender
19+
20+
@PreviewLightDark
21+
@Composable
22+
private fun SecretDebugSettingsScreenPreview() {
23+
koinPreview {
24+
single<DebugNotificationSectionViewModel> {
25+
DebugNotificationSectionViewModel(
26+
accountManager = object : AccountManager<BaseAccount> {
27+
override fun getAccounts(): List<BaseAccount> = listOf()
28+
override fun getAccountsFlow(): Flow<List<BaseAccount>> = flowOf(listOf())
29+
override fun getAccount(accountUuid: String): BaseAccount? = null
30+
override fun getAccountFlow(accountUuid: String): Flow<BaseAccount?> = flowOf(null)
31+
override fun moveAccount(
32+
account: BaseAccount,
33+
newPosition: Int,
34+
) = Unit
35+
36+
override fun saveAccount(account: BaseAccount) = Unit
37+
},
38+
notificationSender = object : NotificationSender {
39+
override fun send(
40+
notification: Notification,
41+
): Flow<Outcome<Success<Notification>, Failure<Notification>>> =
42+
error("not implementd")
43+
},
44+
)
45+
}
46+
} WithContent {
47+
PreviewWithThemesLightDark {
48+
SecretDebugSettingsScreen(
49+
onNavigateBack = { },
50+
modifier = Modifier.fillMaxSize(),
51+
)
52+
}
53+
}
54+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package net.thunderbird.feature.debugSettings.inject
2+
3+
import net.thunderbird.feature.debugSettings.navigation.DefaultSecretDebugSettingsNavigation
4+
import net.thunderbird.feature.debugSettings.navigation.SecretDebugSettingsNavigation
5+
import net.thunderbird.feature.debugSettings.notification.DebugNotificationSectionViewModel
6+
import org.koin.core.module.dsl.viewModel
7+
import org.koin.dsl.module
8+
9+
val featureDebugSettingsModule = module {
10+
single<SecretDebugSettingsNavigation> { DefaultSecretDebugSettingsNavigation() }
11+
viewModel {
12+
DebugNotificationSectionViewModel(
13+
accountManager = get(),
14+
notificationSender = get(),
15+
)
16+
}
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
package net.thunderbird.feature.debugSettings.notification
2+
3+
import androidx.compose.foundation.layout.padding
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.Modifier
10+
import androidx.compose.ui.tooling.preview.PreviewLightDark
11+
import app.k9mail.core.ui.compose.designsystem.PreviewWithThemeLightDark
12+
import app.k9mail.core.ui.compose.theme2.MainTheme
13+
import kotlin.uuid.ExperimentalUuidApi
14+
import kotlin.uuid.Uuid
15+
import kotlinx.collections.immutable.toPersistentList
16+
import net.thunderbird.feature.mail.account.api.BaseAccount
17+
import net.thunderbird.feature.notification.api.content.MailNotification
18+
19+
@OptIn(ExperimentalUuidApi::class)
20+
@PreviewLightDark
21+
@Composable
22+
private fun DebugNotificationSectionPreview() {
23+
PreviewWithThemeLightDark {
24+
val accounts = remember {
25+
List(size = 10) {
26+
object : BaseAccount {
27+
override val uuid: String = Uuid.random().toString()
28+
override val name: String? = "Account $it"
29+
override val email: String = "account-$it@mail.com"
30+
}
31+
}.toPersistentList()
32+
}
33+
var state by remember {
34+
mutableStateOf(
35+
DebugNotificationSectionContract.State(
36+
accounts = accounts,
37+
selectedAccount = accounts.first(),
38+
),
39+
)
40+
}
41+
DebugNotificationSection(
42+
state = state,
43+
modifier = Modifier.padding(MainTheme.spacings.triple),
44+
onAccountSelect = { state = state.copy(selectedAccount = it) },
45+
)
46+
}
47+
}
48+
49+
@OptIn(ExperimentalUuidApi::class)
50+
@PreviewLightDark
51+
@Composable
52+
private fun PreviewSingleMailNotification() {
53+
PreviewWithThemeLightDark {
54+
val accounts = remember {
55+
List(size = 10) {
56+
object : BaseAccount {
57+
override val uuid: String = Uuid.random().toString()
58+
override val name: String? = "Account $it"
59+
override val email: String = "account-$it@mail.com"
60+
}
61+
}.toPersistentList()
62+
}
63+
var state by remember {
64+
mutableStateOf(
65+
DebugNotificationSectionContract.State(
66+
accounts = accounts,
67+
selectedAccount = accounts.first(),
68+
selectedSystemNotificationType = MailNotification.NewMail.SingleMail::class,
69+
),
70+
)
71+
}
72+
DebugNotificationSection(
73+
state = state,
74+
modifier = Modifier.padding(MainTheme.spacings.triple),
75+
onAccountSelect = { state = state.copy(selectedAccount = it) },
76+
)
77+
}
78+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package net.thunderbird.feature.debugSettings
2+
3+
import androidx.compose.foundation.layout.Column
4+
import androidx.compose.foundation.layout.padding
5+
import androidx.compose.runtime.Composable
6+
import androidx.compose.ui.Modifier
7+
import app.k9mail.core.ui.compose.designsystem.atom.divider.HorizontalDivider
8+
import app.k9mail.core.ui.compose.designsystem.atom.text.TextTitleLarge
9+
import app.k9mail.core.ui.compose.designsystem.atom.text.TextTitleMedium
10+
import app.k9mail.core.ui.compose.theme2.MainTheme
11+
12+
@Composable
13+
internal fun DebugSection(
14+
title: String,
15+
modifier: Modifier = Modifier,
16+
content: @Composable () -> Unit,
17+
) {
18+
DebugSection(
19+
title = { TextTitleLarge(title) },
20+
modifier = modifier,
21+
content = content,
22+
)
23+
}
24+
25+
@Composable
26+
internal fun DebugSubSection(
27+
title: String,
28+
modifier: Modifier = Modifier,
29+
content: @Composable () -> Unit,
30+
) {
31+
DebugSection(
32+
title = { TextTitleMedium(title) },
33+
modifier = modifier,
34+
content = content,
35+
)
36+
}
37+
38+
@Composable
39+
internal fun DebugSection(
40+
title: @Composable () -> Unit,
41+
modifier: Modifier = Modifier,
42+
content: @Composable () -> Unit,
43+
) {
44+
Column(modifier = modifier) {
45+
title()
46+
HorizontalDivider(modifier = Modifier.padding(vertical = MainTheme.spacings.double))
47+
content()
48+
}
49+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package net.thunderbird.feature.debugSettings
2+
3+
import androidx.compose.foundation.layout.Column
4+
import androidx.compose.foundation.layout.padding
5+
import androidx.compose.foundation.rememberScrollState
6+
import androidx.compose.foundation.verticalScroll
7+
import androidx.compose.runtime.Composable
8+
import androidx.compose.ui.Modifier
9+
import app.k9mail.core.ui.compose.designsystem.atom.button.ButtonIcon
10+
import app.k9mail.core.ui.compose.designsystem.atom.icon.Icons
11+
import app.k9mail.core.ui.compose.designsystem.organism.TopAppBar
12+
import app.k9mail.core.ui.compose.designsystem.template.Scaffold
13+
import app.k9mail.core.ui.compose.theme2.MainTheme
14+
import net.thunderbird.feature.debugSettings.notification.DebugNotificationSection
15+
16+
@Composable
17+
fun SecretDebugSettingsScreen(
18+
onNavigateBack: () -> Unit,
19+
modifier: Modifier = Modifier,
20+
) {
21+
Scaffold(
22+
topBar = {
23+
TopAppBar(
24+
title = "Secret Debug Settings Screen",
25+
navigationIcon = {
26+
ButtonIcon(
27+
onClick = onNavigateBack,
28+
imageVector = Icons.Outlined.ArrowBack,
29+
)
30+
},
31+
)
32+
},
33+
modifier = modifier,
34+
) { paddingValues ->
35+
Column(
36+
modifier = Modifier
37+
.padding(paddingValues)
38+
.verticalScroll(rememberScrollState())
39+
.padding(MainTheme.spacings.double),
40+
) {
41+
DebugNotificationSection()
42+
}
43+
}
44+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package net.thunderbird.feature.debugSettings.navigation
2+
3+
import androidx.compose.foundation.layout.fillMaxSize
4+
import androidx.compose.ui.Modifier
5+
import androidx.navigation.NavGraphBuilder
6+
import app.k9mail.core.ui.compose.navigation.Navigation
7+
import app.k9mail.core.ui.compose.navigation.deepLinkComposable
8+
import net.thunderbird.feature.debugSettings.BuildConfig
9+
import net.thunderbird.feature.debugSettings.SecretDebugSettingsScreen
10+
import net.thunderbird.feature.debugSettings.navigation.SecretDebugSettingsRoute.Notification
11+
12+
interface SecretDebugSettingsNavigation : Navigation<SecretDebugSettingsRoute>
13+
14+
internal class DefaultSecretDebugSettingsNavigation : SecretDebugSettingsNavigation {
15+
override fun registerRoutes(
16+
navGraphBuilder: NavGraphBuilder,
17+
onBack: () -> Unit,
18+
onFinish: (SecretDebugSettingsRoute) -> Unit,
19+
) {
20+
if (BuildConfig.DEBUG) {
21+
with(navGraphBuilder) {
22+
deepLinkComposable<Notification>(Notification.basePath) {
23+
SecretDebugSettingsScreen(
24+
onNavigateBack = onBack,
25+
modifier = Modifier.fillMaxSize(),
26+
)
27+
}
28+
}
29+
}
30+
}
31+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package net.thunderbird.feature.debugSettings.navigation
2+
3+
import app.k9mail.core.ui.compose.navigation.Route
4+
import kotlinx.serialization.Serializable
5+
6+
sealed interface SecretDebugSettingsRoute : Route {
7+
@Serializable
8+
data object Notification : SecretDebugSettingsRoute {
9+
override val basePath: String = "$SECRET_DEBUG_SETTINGS/notification"
10+
11+
override fun route(): String = basePath
12+
}
13+
14+
companion object {
15+
const val SECRET_DEBUG_SETTINGS = "app://secret_debug_settings"
16+
}
17+
}

0 commit comments

Comments
 (0)