refactor: remove :unit:choosefont dialogs (#63)

* remove :unit:choosefont module and all its dialogs

* update usages in ConfigureContentViewScreen
This commit is contained in:
akesi seli 2024-11-02 08:52:58 +01:00 committed by GitHub
parent 75e39eeae8
commit a8921b46da
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 80 additions and 325 deletions

View File

@ -81,7 +81,6 @@ Here is a list of the main unit modules and their purpose:
- `:unit:ban` contains the modal bottom sheet used to ban a user from a community
- `:unit:chat` contains the chat conversation screen
- `:unit:choosecolor` contains the dialogs and bottom sheets used for theme/color selection
- `:unit:choosefont` contains the bottom sheets used for font selection
- `:unit:communitydetail` contains the community detail screen
- `:unit:communityinfo` contains the community info bottom sheet accessible from community detail
- `:unit:configureswipeactions` contains the screen and bottom sheets to configure swipe actions

View File

@ -66,7 +66,6 @@ kotlin {
implementation(projects.unit.accountsettings)
implementation(projects.unit.manageban)
implementation(projects.unit.choosecolor)
implementation(projects.unit.choosefont)
implementation(projects.unit.configureswipeactions)
implementation(projects.unit.configurenavbar)
implementation(projects.unit.configurecontentview)

View File

@ -247,7 +247,6 @@
"$(SRCROOT)/../unit/ban/build/fat-framework/debug",
"$(SRCROOT)/../unit/chat/build/fat-framework/debug",
"$(SRCROOT)/../unit/choosecolor/build/fat-framework/debug",
"$(SRCROOT)/../unit/choosefont/build/fat-framework/debug",
"$(SRCROOT)/../unit/communitydetail/build/fat-framework/debug",
"$(SRCROOT)/../unit/communityinfo/build/fat-framework/debug",
"$(SRCROOT)/../unit/configurecontentview/build/fat-framework/debug",
@ -385,7 +384,6 @@
"$(SRCROOT)/../unit/ban/build/fat-framework/release",
"$(SRCROOT)/../unit/chat/build/fat-framework/release",
"$(SRCROOT)/../unit/choosecolor/build/fat-framework/release",
"$(SRCROOT)/../unit/choosefont/build/fat-framework/release",
"$(SRCROOT)/../unit/communitydetail/build/fat-framework/release",
"$(SRCROOT)/../unit/communityinfo/build/fat-framework/release",
"$(SRCROOT)/../unit/configurecontentview/build/fat-framework/release",

View File

@ -57,7 +57,6 @@ include(":unit:accountsettings")
include(":unit:ban")
include(":unit:chat")
include(":unit:choosecolor")
include(":unit:choosefont")
include(":unit:communitydetail")
include(":unit:communityinfo")
include(":unit:configurecontentview")

View File

@ -1,64 +0,0 @@
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
plugins {
alias(libs.plugins.kotlin.multiplatform)
alias(libs.plugins.android.library)
alias(libs.plugins.jetbrains.compose)
alias(libs.plugins.compose.compiler)
alias(libs.plugins.detekt)
}
@OptIn(org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi::class)
kotlin {
applyDefaultHierarchyTemplate()
androidTarget {
compilerOptions {
jvmTarget.set(JvmTarget.JVM_1_8)
}
}
listOf(
iosX64(),
iosArm64(),
iosSimulatorArm64(),
).forEach {
it.binaries.framework {
baseName = "unit.choosefont"
isStatic = true
}
}
sourceSets {
val commonMain by getting {
dependencies {
implementation(compose.runtime)
implementation(compose.foundation)
implementation(compose.material)
implementation(compose.material3)
implementation(compose.materialIconsExtended)
implementation(libs.voyager.navigator)
implementation(projects.core.appearance)
implementation(projects.core.commonui.components)
implementation(projects.core.l10n)
implementation(projects.core.navigation)
implementation(projects.core.notifications)
implementation(projects.core.resources)
implementation(projects.core.utils)
}
}
val commonTest by getting {
dependencies {
implementation(kotlin("test"))
}
}
}
}
android {
namespace = "com.livefast.eattrash.raccoonforlemmy.unit.choosefont"
compileSdk = libs.versions.android.targetSdk.get().toInt()
defaultConfig {
minSdk = libs.versions.android.minSdk.get().toInt()
}
}

View File

@ -1,8 +0,0 @@
<?xml version="1.0" ?>
<SmellBaseline>
<ManuallySuppressedIssues></ManuallySuppressedIssues>
<CurrentIssues>
<ID>LongMethod:FontFamilyBottomSheet.kt$FontFamilyBottomSheet$@Composable override fun Content()</ID>
<ID>LongMethod:FontScaleBottomSheet.kt$FontScaleBottomSheet$@Composable override fun Content()</ID>
</CurrentIssues>
</SmellBaseline>

View File

@ -1,107 +0,0 @@
package com.livefast.eattrash.raccoonforlemmy.unit.choosefont
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.font.FontFamily
import cafe.adriel.voyager.core.screen.Screen
import com.livefast.eattrash.raccoonforlemmy.core.appearance.data.UiFontFamily
import com.livefast.eattrash.raccoonforlemmy.core.appearance.data.toInt
import com.livefast.eattrash.raccoonforlemmy.core.appearance.data.toReadableName
import com.livefast.eattrash.raccoonforlemmy.core.appearance.data.toUiFontFamily
import com.livefast.eattrash.raccoonforlemmy.core.appearance.theme.Spacing
import com.livefast.eattrash.raccoonforlemmy.core.commonui.components.BottomSheetHeader
import com.livefast.eattrash.raccoonforlemmy.core.l10n.messages.LocalStrings
import com.livefast.eattrash.raccoonforlemmy.core.navigation.di.getNavigationCoordinator
import com.livefast.eattrash.raccoonforlemmy.core.notifications.NotificationCenterEvent
import com.livefast.eattrash.raccoonforlemmy.core.notifications.di.getNotificationCenter
import com.livefast.eattrash.raccoonforlemmy.core.resources.di.getCoreResources
import com.livefast.eattrash.raccoonforlemmy.core.utils.compose.onClick
private val defaultChoices: List<Int> =
listOf(
UiFontFamily.Poppins,
UiFontFamily.NotoSans,
UiFontFamily.CharisSIL,
UiFontFamily.Default,
).map { it.toInt() }
class FontFamilyBottomSheet(
private val values: List<Int> = defaultChoices,
private val content: Boolean = false,
) : Screen {
@Composable
override fun Content() {
val navigationCoordinator = remember { getNavigationCoordinator() }
val notificationCenter = remember { getNotificationCenter() }
val coreResources = remember { getCoreResources() }
Column(
modifier =
Modifier
.padding(
top = Spacing.s,
start = Spacing.s,
end = Spacing.s,
bottom = Spacing.m,
),
verticalArrangement = Arrangement.spacedBy(Spacing.s),
) {
BottomSheetHeader(LocalStrings.current.settingsUiFontFamily)
Column(
modifier = Modifier.fillMaxWidth().verticalScroll(rememberScrollState()),
verticalArrangement = Arrangement.spacedBy(Spacing.xxs),
) {
for (value in values) {
val family = value.toUiFontFamily()
Row(
modifier =
Modifier
.padding(
horizontal = Spacing.s,
vertical = Spacing.s,
)
.fillMaxWidth()
.onClick(
onClick = {
val event =
if (content) {
NotificationCenterEvent.ChangeContentFontFamily(family)
} else {
NotificationCenterEvent.ChangeFontFamily(family)
}
notificationCenter.send(event)
navigationCoordinator.hideBottomSheet()
},
),
) {
val fontFamily =
when (family) {
UiFontFamily.NotoSans -> coreResources.notoSans
UiFontFamily.CharisSIL -> coreResources.charisSil
UiFontFamily.Poppins -> coreResources.poppins
else -> FontFamily.Default
}
Text(
text = family.toReadableName(),
style =
MaterialTheme.typography.bodyLarge.copy(
fontFamily = fontFamily,
),
color = MaterialTheme.colorScheme.onBackground,
)
}
}
}
}
}
}

View File

@ -1,123 +0,0 @@
package com.livefast.eattrash.raccoonforlemmy.unit.choosefont
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import cafe.adriel.voyager.core.screen.Screen
import com.livefast.eattrash.raccoonforlemmy.core.appearance.data.FontScale
import com.livefast.eattrash.raccoonforlemmy.core.appearance.data.scaleFactor
import com.livefast.eattrash.raccoonforlemmy.core.appearance.data.toFontScale
import com.livefast.eattrash.raccoonforlemmy.core.appearance.data.toReadableName
import com.livefast.eattrash.raccoonforlemmy.core.appearance.repository.ContentFontClass
import com.livefast.eattrash.raccoonforlemmy.core.appearance.theme.Spacing
import com.livefast.eattrash.raccoonforlemmy.core.commonui.components.BottomSheetHeader
import com.livefast.eattrash.raccoonforlemmy.core.l10n.messages.LocalStrings
import com.livefast.eattrash.raccoonforlemmy.core.navigation.di.getNavigationCoordinator
import com.livefast.eattrash.raccoonforlemmy.core.notifications.NotificationCenterEvent
import com.livefast.eattrash.raccoonforlemmy.core.notifications.di.getNotificationCenter
import com.livefast.eattrash.raccoonforlemmy.core.utils.compose.onClick
private val defaultChoices: List<Float> =
listOf(
FontScale.Largest,
FontScale.Larger,
FontScale.Large,
FontScale.Normal,
FontScale.Small,
FontScale.Smaller,
FontScale.Smallest,
).map { it.scaleFactor }
class FontScaleBottomSheet(
private val values: List<Float> = defaultChoices,
private val contentClass: ContentFontClass? = null,
) : Screen {
@Composable
override fun Content() {
val navigationCoordinator = remember { getNavigationCoordinator() }
val notificationCenter = remember { getNotificationCenter() }
Column(
modifier =
Modifier
.padding(
top = Spacing.s,
start = Spacing.s,
end = Spacing.s,
bottom = Spacing.m,
),
verticalArrangement = Arrangement.spacedBy(Spacing.s),
) {
val title =
when (contentClass) {
ContentFontClass.Title -> LocalStrings.current.settingsTitleFontScale
ContentFontClass.Body -> LocalStrings.current.settingsContentFontScale
ContentFontClass.Comment -> LocalStrings.current.settingsCommentFontScale
ContentFontClass.AncillaryText -> LocalStrings.current.settingsAncillaryFontScale
else -> LocalStrings.current.settingsUiFontScale
}
BottomSheetHeader(title)
Text(
modifier =
Modifier.padding(
start = Spacing.s,
top = Spacing.s,
end = Spacing.s,
),
text = title,
style = MaterialTheme.typography.titleMedium,
color = MaterialTheme.colorScheme.onBackground,
)
Column(
modifier = Modifier.fillMaxWidth().verticalScroll(rememberScrollState()),
verticalArrangement = Arrangement.spacedBy(Spacing.xxs),
) {
for (value in values) {
val fontScale = value.toFontScale()
Row(
modifier =
Modifier
.padding(
horizontal = Spacing.s,
vertical = Spacing.s,
)
.fillMaxWidth()
.onClick(
onClick = {
notificationCenter.send(
if (contentClass != null) {
NotificationCenterEvent.ChangeContentFontSize(
value = value,
contentClass = contentClass,
)
} else {
NotificationCenterEvent.ChangeUiFontSize(value)
},
)
navigationCoordinator.hideBottomSheet()
},
),
) {
val originalFontSize = MaterialTheme.typography.bodyLarge.fontSize
Text(
text = fontScale.toReadableName(),
style =
MaterialTheme.typography.bodyLarge.copy(
fontSize = originalFontSize * value,
),
color = MaterialTheme.colorScheme.onBackground,
)
}
}
}
}
}
}

View File

@ -55,8 +55,6 @@ kotlin {
implementation(projects.domain.identity)
implementation(projects.domain.lemmy.data)
implementation(projects.domain.lemmy.repository)
implementation(projects.unit.choosefont)
}
}
val commonTest by getting {
@ -69,8 +67,14 @@ kotlin {
android {
namespace = "com.livefast.eattrash.raccoonforlemmy.unit.configurecontentview"
compileSdk = libs.versions.android.targetSdk.get().toInt()
compileSdk =
libs.versions.android.targetSdk
.get()
.toInt()
defaultConfig {
minSdk = libs.versions.android.minSdk.get().toInt()
minSdk =
libs.versions.android.minSdk
.get()
.toInt()
}
}

View File

@ -34,10 +34,15 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.input.nestedscroll.nestedScroll
import cafe.adriel.voyager.core.screen.Screen
import cafe.adriel.voyager.koin.getScreenModel
import com.livefast.eattrash.raccoonforlemmy.core.appearance.data.FontScale
import com.livefast.eattrash.raccoonforlemmy.core.appearance.data.PostLayout
import com.livefast.eattrash.raccoonforlemmy.core.appearance.data.UiFontFamily
import com.livefast.eattrash.raccoonforlemmy.core.appearance.data.VoteFormat
import com.livefast.eattrash.raccoonforlemmy.core.appearance.data.scaleFactor
import com.livefast.eattrash.raccoonforlemmy.core.appearance.data.toFontScale
import com.livefast.eattrash.raccoonforlemmy.core.appearance.data.toInt
import com.livefast.eattrash.raccoonforlemmy.core.appearance.data.toReadableName
import com.livefast.eattrash.raccoonforlemmy.core.appearance.data.toUiFontFamily
import com.livefast.eattrash.raccoonforlemmy.core.appearance.repository.ContentFontClass
import com.livefast.eattrash.raccoonforlemmy.core.appearance.theme.Spacing
import com.livefast.eattrash.raccoonforlemmy.core.commonui.lemmyui.SettingsHeader
@ -52,8 +57,6 @@ import com.livefast.eattrash.raccoonforlemmy.core.l10n.messages.LocalStrings
import com.livefast.eattrash.raccoonforlemmy.core.navigation.di.getNavigationCoordinator
import com.livefast.eattrash.raccoonforlemmy.core.notifications.NotificationCenterEvent
import com.livefast.eattrash.raccoonforlemmy.core.notifications.di.getNotificationCenter
import com.livefast.eattrash.raccoonforlemmy.unit.choosefont.FontFamilyBottomSheet
import com.livefast.eattrash.raccoonforlemmy.unit.choosefont.FontScaleBottomSheet
class ConfigureContentViewScreen : Screen {
@OptIn(ExperimentalMaterial3Api::class)
@ -68,6 +71,8 @@ class ConfigureContentViewScreen : Screen {
val scrollState = rememberScrollState()
var voteFormatBottomSheetOpened by remember { mutableStateOf(false) }
var postLayoutBottomSheetOpened by remember { mutableStateOf(false) }
var fontFamilyBottomSheetOpened by remember { mutableStateOf(false) }
var fontScaleClassBottomSheet by remember { mutableStateOf<ContentFontClass?>(null) }
Scaffold(
modifier =
@ -122,8 +127,7 @@ class ConfigureContentViewScreen : Screen {
title = LocalStrings.current.settingsContentFontFamily,
value = uiState.contentFontFamily.toReadableName(),
onTap = {
val sheet = FontFamilyBottomSheet(content = true)
navigationCoordinator.showBottomSheet(sheet)
fontFamilyBottomSheetOpened = true
},
)
@ -135,8 +139,7 @@ class ConfigureContentViewScreen : Screen {
.toFontScale()
.toReadableName(),
onTap = {
val sheet = FontScaleBottomSheet(contentClass = ContentFontClass.Title)
navigationCoordinator.showBottomSheet(sheet)
fontScaleClassBottomSheet = ContentFontClass.Title
},
)
SettingsRow(
@ -146,8 +149,7 @@ class ConfigureContentViewScreen : Screen {
.toFontScale()
.toReadableName(),
onTap = {
val sheet = FontScaleBottomSheet(contentClass = ContentFontClass.Body)
navigationCoordinator.showBottomSheet(sheet)
fontScaleClassBottomSheet = ContentFontClass.Body
},
)
SettingsRow(
@ -157,9 +159,7 @@ class ConfigureContentViewScreen : Screen {
.toFontScale()
.toReadableName(),
onTap = {
val sheet =
FontScaleBottomSheet(contentClass = ContentFontClass.Comment)
navigationCoordinator.showBottomSheet(sheet)
fontScaleClassBottomSheet = ContentFontClass.Comment
},
)
SettingsRow(
@ -169,9 +169,7 @@ class ConfigureContentViewScreen : Screen {
.toFontScale()
.toReadableName(),
onTap = {
val sheet =
FontScaleBottomSheet(contentClass = ContentFontClass.AncillaryText)
navigationCoordinator.showBottomSheet(sheet)
fontScaleClassBottomSheet = ContentFontClass.AncillaryText
},
)
@ -347,5 +345,65 @@ class ConfigureContentViewScreen : Screen {
},
)
}
if (fontFamilyBottomSheetOpened) {
val items =
listOf(
UiFontFamily.Poppins,
UiFontFamily.NotoSans,
UiFontFamily.CharisSIL,
UiFontFamily.Default,
).map { it.toInt() }
CustomModalBottomSheet(
title = LocalStrings.current.settingsUiFontFamily,
items =
items.map { fontFamily ->
CustomModalBottomSheetItem(
label = fontFamily.toUiFontFamily().toReadableName(),
)
},
onSelected = { index ->
fontFamilyBottomSheetOpened = false
if (index != null) {
notificationCenter.send(
NotificationCenterEvent.ChangeContentFontFamily(items[index].toUiFontFamily()),
)
}
},
)
}
fontScaleClassBottomSheet?.also { contentClass ->
val items =
listOf(
FontScale.Largest,
FontScale.Larger,
FontScale.Large,
FontScale.Normal,
FontScale.Small,
FontScale.Smaller,
FontScale.Smallest,
).map { it.scaleFactor }
CustomModalBottomSheet(
title = LocalStrings.current.settingsUiFontScale,
items =
items.map { font ->
CustomModalBottomSheetItem(
label = font.toFontScale().toReadableName(),
)
},
onSelected = { index ->
fontScaleClassBottomSheet = null
if (index != null) {
notificationCenter.send(
NotificationCenterEvent.ChangeContentFontSize(
value = items[index],
contentClass = contentClass,
),
)
}
},
)
}
}
}