Skip to content
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

Moving to a new preferences library. #1451

Merged
merged 5 commits into from Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/build.gradle.kts
Expand Up @@ -109,7 +109,7 @@ android {

dependencies {
implementation("androidx.appcompat:appcompat:1.6.1")
implementation("com.github.alorma:compose-settings-ui-m3:1.0.3")
implementation("me.zhanghai.compose.preference:library:1.0.0")

implementation("com.squareup.okhttp3:logging-interceptor:5.0.0-alpha.12")

Expand Down
13 changes: 10 additions & 3 deletions app/src/main/java/com/jerboa/Utils.kt
Expand Up @@ -26,6 +26,7 @@ import androidx.activity.result.ActivityResultCallback
import androidx.activity.result.ActivityResultLauncher
import androidx.activity.result.contract.ActivityResultContract
import androidx.annotation.RequiresApi
import androidx.annotation.StringRes
import androidx.appcompat.app.AppCompatDelegate
import androidx.browser.customtabs.CustomTabsIntent
import androidx.compose.foundation.lazy.LazyListState
Expand Down Expand Up @@ -734,15 +735,19 @@ fun Context.findActivity(): Activity? =
else -> null
}

enum class ThemeMode(val mode: Int) {
enum class ThemeMode(
@StringRes val resId: Int,
) {
System(R.string.look_and_feel_theme_system),
SystemBlack(R.string.look_and_feel_theme_system_black),
Light(R.string.look_and_feel_theme_light),
Dark(R.string.look_and_feel_theme_dark),
Black(R.string.look_and_feel_theme_black),
}

enum class ThemeColor(val mode: Int) {
enum class ThemeColor(
@StringRes val resId: Int,
) {
Dynamic(R.string.look_and_feel_theme_color_dynamic),
Beach(R.string.look_and_feel_theme_color_beach),
Blue(R.string.look_and_feel_theme_color_blue),
Expand All @@ -755,7 +760,9 @@ enum class ThemeColor(val mode: Int) {
Dracula(R.string.look_and_feel_theme_color_dracula),
}

enum class PostViewMode(val mode: Int) {
enum class PostViewMode(
@StringRes val resId: Int,
) {
/**
* The full size post view card. For image posts, this expands them to their full height. For
* link posts, the thumbnail is shown to the right of the title.
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/jerboa/datatypes/Others.kt
Expand Up @@ -64,13 +64,13 @@ val SortType.data: SortData
SortType.TopAll -> SortData(R.string.sorttype_topall, R.string.dialogs_top_all, Icons.Outlined.BarChart)
SortType.MostComments -> SortData(
R.string.sorttype_mostcomments,
R.string.sorttype_mostcomments,
R.string.sorttype_mostcomments_long,
Icons.Outlined.FormatListNumbered,
)

SortType.NewComments -> SortData(
R.string.sorttype_newcomments,
R.string.sorttype_newcomments,
R.string.sorttype_newcomments_long,
Icons.Outlined.NewReleases,
)

Expand Down
@@ -1,8 +1,11 @@
package com.jerboa.feat

import androidx.annotation.StringRes
import com.jerboa.R

enum class PostNavigationGestureMode(val mode: Int) {
enum class PostNavigationGestureMode(
@StringRes val resId: Int,
) {
/**
* Disable all navigation gestures within posts.
*/
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/java/com/jerboa/feat/SwipeToAction.kt
@@ -1,5 +1,6 @@
package com.jerboa.feat

import androidx.annotation.StringRes
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.outlined.Comment
import androidx.compose.material.icons.outlined.Bookmark
Expand Down Expand Up @@ -71,7 +72,7 @@ data class ActionColor(
enum class SwipeToActionPreset(
val leftActions: List<SwipeToActionType>,
val rightActions: List<SwipeToActionType>,
val resId: Int,
@StringRes val resId: Int,
) {
Disabled(emptyList(), emptyList(), R.string.swipe_action_preset_disabled),
TwoSides(
Expand Down
Expand Up @@ -297,7 +297,7 @@ fun CommunityMoreDropdown(
children = {
PostViewMode.entries.map {
DropdownMenuItem(
text = { Text(text = stringResource(it.mode)) },
text = { Text(text = stringResource(it.resId)) },
onClick = {
onDismissRequest()
onClickPostViewMode(it)
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/jerboa/ui/components/home/Home.kt
Expand Up @@ -217,7 +217,7 @@ fun HomeMoreDropdown(
children = {
PostViewMode.entries.map {
DropdownMenuItem(
text = { Text(text = stringResource(it.mode)) },
text = { Text(text = stringResource(it.resId)) },
onClick = {
onDismissRequest()
onClickPostViewMode(it)
Expand Down
Expand Up @@ -4,7 +4,6 @@ package com.jerboa.ui.components.settings

import android.util.Log
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.outlined.Info
Expand All @@ -19,14 +18,14 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import com.alorma.compose.settings.ui.SettingsMenuLink
import com.jerboa.R
import com.jerboa.db.entity.isAnon
import com.jerboa.model.AccountViewModel
import com.jerboa.ui.components.common.JerboaSnackbarHost
import com.jerboa.ui.components.common.SimpleTopAppBar
import com.jerboa.ui.components.common.getCurrentAccount
import com.jerboa.ui.theme.SETTINGS_MENU_LINK_HEIGHT
import me.zhanghai.compose.preference.Preference
import me.zhanghai.compose.preference.ProvidePreferenceTheme

@Composable
fun SettingsActivity(
Expand All @@ -48,48 +47,48 @@ fun SettingsActivity(
},
content = { padding ->
Column(modifier = Modifier.padding(padding)) {
SettingsMenuLink(
modifier = Modifier.height(SETTINGS_MENU_LINK_HEIGHT),
title = { Text(stringResource(R.string.settings_activity_look_and_feel)) },
icon = {
Icon(
imageVector = Icons.Outlined.Palette,
contentDescription = null,
)
},
onClick = onClickLookAndFeel,
)
if (!account.isAnon()) {
SettingsMenuLink(
modifier = Modifier.height(SETTINGS_MENU_LINK_HEIGHT),
title = {
Text(
stringResource(
R.string.settings_activity_account_settings,
account.name,
),
ProvidePreferenceTheme {
Preference(
title = { Text(stringResource(R.string.settings_activity_look_and_feel)) },
icon = {
Icon(
imageVector = Icons.Outlined.Palette,
contentDescription = null,
)
},
onClick = onClickLookAndFeel,
)

if (!account.isAnon()) {
Preference(
title = {
Text(
stringResource(
R.string.settings_activity_account_settings,
account.name,
),
)
},
icon = {
Icon(
imageVector = Icons.Outlined.ManageAccounts,
contentDescription = null,
)
},
onClick = onClickAccountSettings,
)
}
Preference(
title = { Text(stringResource(R.string.settings_activity_about)) },
icon = {
Icon(
imageVector = Icons.Outlined.ManageAccounts,
imageVector = Icons.Outlined.Info,
contentDescription = null,
)
},
onClick = onClickAccountSettings,
onClick = onClickAbout,
)
}
SettingsMenuLink(
modifier = Modifier.height(SETTINGS_MENU_LINK_HEIGHT),
title = { Text(stringResource(R.string.settings_activity_about)) },
icon = {
Icon(
imageVector = Icons.Outlined.Info,
contentDescription = null,
)
},
onClick = onClickAbout,
)
}
},
)
Expand Down