Skip to content

Commit

Permalink
[feature|optimize|build] Support configure whether the group is expan…
Browse files Browse the repository at this point in the history
…ded or not (#13); optimize SettingsItem.kt; update dependencies
  • Loading branch information
SkyD666 committed Apr 25, 2024
1 parent 78d4fe1 commit d4b9078
Show file tree
Hide file tree
Showing 13 changed files with 186 additions and 23 deletions.
14 changes: 7 additions & 7 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ android {
minSdk = 24
targetSdk = 34
versionCode = 14
versionName = "1.1-beta14"
versionName = "1.1-beta15"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"

Expand Down Expand Up @@ -105,7 +105,7 @@ android {
buildConfig = true
}
composeOptions {
kotlinCompilerExtensionVersion = "1.5.11"
kotlinCompilerExtensionVersion = "1.5.12"
}
packaging {
resources.excludes += mutableSetOf(
Expand Down Expand Up @@ -139,25 +139,25 @@ tasks.withType(KotlinCompile::class.java).configureEach {

dependencies {

implementation("androidx.core:core-ktx:1.12.0")
implementation("androidx.core:core-ktx:1.13.0")
implementation("androidx.appcompat:appcompat:1.6.1")
implementation("androidx.constraintlayout:constraintlayout:2.1.4")
implementation("androidx.navigation:navigation-fragment-ktx:2.7.7")
implementation("androidx.navigation:navigation-ui-ktx:2.7.7")
implementation("androidx.navigation:navigation-compose:2.7.7")
implementation("androidx.lifecycle:lifecycle-runtime-compose:2.7.0")
implementation("androidx.compose.ui:ui:1.6.5")
implementation("androidx.compose.material:material:1.6.5")
implementation("androidx.compose.ui:ui:1.6.6")
implementation("androidx.compose.material:material:1.6.6")
implementation("androidx.compose.material3:material3:1.3.0-alpha05")
implementation("androidx.compose.material3:material3-window-size-class:1.2.1")
implementation("androidx.compose.material:material-icons-extended:1.6.5")
implementation("androidx.compose.material:material-icons-extended:1.6.6")
implementation("com.materialkolor:material-kolor:1.4.4")
implementation("androidx.room:room-runtime:2.6.1")
implementation("androidx.room:room-ktx:2.6.1")
implementation("androidx.room:room-paging:2.6.1")
ksp("androidx.room:room-compiler:2.6.1")
implementation("androidx.work:work-runtime-ktx:2.9.0")
implementation("androidx.datastore:datastore-preferences:1.0.0")
implementation("androidx.datastore:datastore-preferences:1.1.0")
implementation("androidx.swiperefreshlayout:swiperefreshlayout:1.1.0")
implementation("androidx.core:core-splashscreen:1.0.1")
implementation("androidx.media3:media3-exoplayer:1.3.1")
Expand Down
4 changes: 3 additions & 1 deletion app/src/main/java/com/skyd/anivu/ext/PreferenceExt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@ import com.skyd.anivu.model.preference.IgnoreUpdateVersionPreference
import com.skyd.anivu.model.preference.Settings
import com.skyd.anivu.model.preference.appearance.DarkModePreference
import com.skyd.anivu.model.preference.appearance.ThemePreference
import com.skyd.anivu.model.preference.appearance.feed.FeedGroupExpandPreference
import com.skyd.anivu.model.preference.behavior.article.ArticleSwipeLeftActionPreference
import com.skyd.anivu.model.preference.behavior.article.ArticleTapActionPreference
import com.skyd.anivu.model.preference.behavior.article.DeduplicateTitleInDescPreference

fun Preferences.toSettings(): Settings {
return Settings(
// Theme
// Appearance
theme = ThemePreference.fromPreferences(this),
darkMode = DarkModePreference.fromPreferences(this),
feedGroupExpand = FeedGroupExpandPreference.fromPreferences(this),

// Update
ignoreUpdateVersion = IgnoreUpdateVersionPreference.fromPreferences(this),
Expand Down
19 changes: 15 additions & 4 deletions app/src/main/java/com/skyd/anivu/model/bean/GroupBean.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,26 @@ data class GroupBean(
@ColumnInfo(name = NAME_COLUMN)
val name: String,
) : BaseBean, Parcelable {
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other !is GroupBean) return false
return groupId == other.groupId
}

override fun hashCode(): Int {
return groupId.hashCode()
}

companion object {
const val DEFAULT_GROUP_ID = "default"

const val NAME_COLUMN = "name"
const val GROUP_ID_COLUMN = "groupId"

val defaultGroup = GroupBean(
groupId = DEFAULT_GROUP_ID,
name = appContext.getString(R.string.default_feed_group)
)
val defaultGroup
get() = GroupBean(
groupId = DEFAULT_GROUP_ID,
name = appContext.getString(R.string.default_feed_group)
)
}
}
8 changes: 6 additions & 2 deletions app/src/main/java/com/skyd/anivu/model/preference/Settings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,25 @@ import com.skyd.anivu.ext.dataStore
import com.skyd.anivu.ext.toSettings
import com.skyd.anivu.model.preference.appearance.DarkModePreference
import com.skyd.anivu.model.preference.appearance.ThemePreference
import com.skyd.anivu.model.preference.appearance.feed.FeedGroupExpandPreference
import com.skyd.anivu.model.preference.behavior.article.ArticleSwipeLeftActionPreference
import com.skyd.anivu.model.preference.behavior.article.ArticleTapActionPreference
import com.skyd.anivu.model.preference.behavior.article.DeduplicateTitleInDescPreference
import com.skyd.anivu.ui.local.LocalArticleSwipeLeftAction
import com.skyd.anivu.ui.local.LocalArticleTapAction
import com.skyd.anivu.ui.local.LocalDarkMode
import com.skyd.anivu.ui.local.LocalDeduplicateTitleInDesc
import com.skyd.anivu.ui.local.LocalFeedGroupExpand
import com.skyd.anivu.ui.local.LocalIgnoreUpdateVersion
import com.skyd.anivu.ui.local.LocalTheme
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.map

data class Settings(
// Theme
// Appearance
val theme: String = ThemePreference.default,
val darkMode: Int = DarkModePreference.default,
val feedGroupExpand: Boolean = FeedGroupExpandPreference.default,
// Update
val ignoreUpdateVersion: Long = IgnoreUpdateVersionPreference.default,
// Behavior
Expand All @@ -43,9 +46,10 @@ fun SettingsProvider(
.collectAsState(initial = Settings(), context = Dispatchers.Default)

CompositionLocalProvider(
// Theme
// Appearance
LocalTheme provides settings.theme,
LocalDarkMode provides settings.darkMode,
LocalFeedGroupExpand provides settings.feedGroupExpand,
// Update
LocalIgnoreUpdateVersion provides settings.ignoreUpdateVersion,
// Behavior
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.skyd.anivu.model.preference.appearance.feed

import android.content.Context
import androidx.datastore.preferences.core.Preferences
import androidx.datastore.preferences.core.booleanPreferencesKey
import com.skyd.anivu.base.BasePreference
import com.skyd.anivu.ext.dataStore
import com.skyd.anivu.ext.put
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch

object FeedGroupExpandPreference : BasePreference<Boolean> {
private const val FEED_GROUP_EXPAND = "feedGroupExpand"
override val default = true

val key = booleanPreferencesKey(FEED_GROUP_EXPAND)

fun put(context: Context, scope: CoroutineScope, value: Boolean) {
scope.launch(Dispatchers.IO) {
context.dataStore.put(key, value)
}
}

override fun fromPreferences(preferences: Preferences): Boolean = preferences[key] ?: default
}
8 changes: 4 additions & 4 deletions app/src/main/java/com/skyd/anivu/ui/component/SettingsItem.kt
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ fun BannerItem(content: @Composable () -> Unit) {
Spacer(modifier = Modifier.height(16.dp))
CompositionLocalProvider(
LocalContentColor provides (LocalContentColor.current alwaysLight true),
LocalVerticalPadding provides 12.dp
LocalVerticalPadding provides 21.dp
) {
Box(
modifier = Modifier
Expand Down Expand Up @@ -354,7 +354,7 @@ fun BaseSettingsItem(
combinedClickable(onLongClick = onLongClick) { onClick() }
} else this
}
.padding(LocalVerticalPadding.current),
.padding(horizontal = 16.dp),
verticalAlignment = Alignment.CenterVertically
) {
if (icon != null) {
Expand All @@ -379,7 +379,7 @@ fun BaseSettingsItem(
Column(
modifier = Modifier
.weight(1f)
.padding(horizontal = 10.dp)
.padding(horizontal = 10.dp, vertical = LocalVerticalPadding.current)
) {
Text(
text = text,
Expand All @@ -389,7 +389,7 @@ fun BaseSettingsItem(
)
dropdownMenu?.invoke()
if (description != null) {
Box(modifier = Modifier.padding(top = 5.dp)) {
Box(modifier = Modifier.padding(top = 4.dp)) {
description.invoke()
}
}
Expand Down
10 changes: 6 additions & 4 deletions app/src/main/java/com/skyd/anivu/ui/fragment/feed/FeedScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.focus.FocusDirection
import androidx.compose.ui.focus.FocusRequester
import androidx.compose.ui.focus.focusProperties
import androidx.compose.ui.focus.focusRequester
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.input.nestedscroll.nestedScroll
Expand Down Expand Up @@ -81,6 +80,7 @@ import com.skyd.anivu.ui.component.lazyverticalgrid.adapter.LazyGridAdapter
import com.skyd.anivu.ui.component.lazyverticalgrid.adapter.proxy.Feed1Proxy
import com.skyd.anivu.ui.component.lazyverticalgrid.adapter.proxy.Group1Proxy
import com.skyd.anivu.ui.fragment.search.SearchFragment
import com.skyd.anivu.ui.local.LocalFeedGroupExpand
import com.skyd.anivu.ui.local.LocalNavController
import com.skyd.anivu.ui.local.LocalWindowSizeClass
import kotlinx.coroutines.android.awaitFrame
Expand Down Expand Up @@ -170,7 +170,7 @@ fun FeedScreen(viewModel: FeedViewModel = hiltViewModel()) {
is GroupListState.Success -> {
FeedList(
result = groupListState.dataList,
contentPadding = innerPadding + PaddingValues(bottom = fabHeight),
contentPadding = innerPadding + PaddingValues(bottom = fabHeight + 16.dp),
onRemoveFeed = { feed -> dispatch(FeedIntent.RemoveFeed(feed.url)) },
onEditFeed = { feed ->
openEditDialog = feed
Expand Down Expand Up @@ -405,6 +405,7 @@ private fun EditFeedDialog(
AniVuIconButton(
onClick = openCreateGroupDialog,
imageVector = Icons.Default.Add,
contentDescription = stringResource(id = R.string.feed_screen_add_group),
)
}

Expand Down Expand Up @@ -474,12 +475,13 @@ private fun FeedList(
onMoveToGroup: (from: GroupBean, to: GroupBean) -> Unit,
openCreateGroupDialog: () -> Unit,
) {
val feedGroupExpand = LocalFeedGroupExpand.current
val groups = rememberSaveable(result) { result.filterIsInstance<GroupBean>() }
val feedVisible = rememberSaveable(saver = snapshotStateMapSaver()) {
mutableStateMapOf(
GroupBean.DEFAULT_GROUP_ID to false,
GroupBean.DEFAULT_GROUP_ID to feedGroupExpand,
*(groups
.map { it.groupId to false }
.map { it.groupId to feedGroupExpand }
.toTypedArray())
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ import android.content.Context
import android.os.Bundle
import android.util.TypedValue
import androidx.lifecycle.lifecycleScope
import androidx.preference.Preference
import androidx.preference.PreferenceCategory
import androidx.preference.PreferenceScreen
import androidx.preference.SwitchPreferenceCompat
import com.google.android.material.color.DynamicColors
import com.skyd.anivu.R
import com.skyd.anivu.base.BasePreferenceFragmentCompat
import com.skyd.anivu.ext.dataStore
import com.skyd.anivu.ext.findMainNavController
import com.skyd.anivu.ext.getOrDefault
import com.skyd.anivu.ext.inDarkMode
import com.skyd.anivu.model.preference.appearance.DarkModePreference
Expand Down Expand Up @@ -90,6 +92,22 @@ class AppearanceFragment : BasePreferenceFragmentCompat() {
themeCategory.addPreference(this)
}
}

val styleCategory = PreferenceCategory(this).apply {
key = "styleCategory"
title = getString(R.string.appearance_fragment_style_category)
screen.addPreference(this)
}

Preference(this).apply {
key = "feedScreenStyle"
title = getString(R.string.feed_style_screen_name)
setOnPreferenceClickListener {
findMainNavController().navigate(R.id.action_to_feed_style_fragment)
true
}
styleCategory.addPreference(this)
}
}

private fun getColorPalettes(): List<ColorPalettesPreference.ColorPalette> {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package com.skyd.anivu.ui.fragment.settings.appearance.feed

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Expand
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.runtime.Composable
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Modifier
import androidx.compose.ui.input.nestedscroll.nestedScroll
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import com.skyd.anivu.R
import com.skyd.anivu.base.BaseComposeFragment
import com.skyd.anivu.model.preference.appearance.feed.FeedGroupExpandPreference
import com.skyd.anivu.ui.component.AniVuTopBar
import com.skyd.anivu.ui.component.AniVuTopBarStyle
import com.skyd.anivu.ui.component.CategorySettingsItem
import com.skyd.anivu.ui.component.SwitchSettingsItem
import com.skyd.anivu.ui.local.LocalFeedGroupExpand
import dagger.hilt.android.AndroidEntryPoint


@AndroidEntryPoint
class FeedAppearanceFragment : BaseComposeFragment() {
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View = setContentBase { FeedStyleScreen() }
}

@Composable
fun FeedStyleScreen() {
val scrollBehavior = TopAppBarDefaults.exitUntilCollapsedScrollBehavior()
val context = LocalContext.current
val scope = rememberCoroutineScope()

Scaffold(
topBar = {
AniVuTopBar(
style = AniVuTopBarStyle.Large,
scrollBehavior = scrollBehavior,
title = { Text(text = stringResource(R.string.feed_style_screen_name)) },
)
}
) { paddingValues ->
LazyColumn(
modifier = Modifier
.fillMaxSize()
.nestedScroll(scrollBehavior.nestedScrollConnection),
contentPadding = paddingValues,
) {
item {
CategorySettingsItem(text = stringResource(id = R.string.feed_style_screen_group_list_category))
}
item {
val feedGroupExpand = LocalFeedGroupExpand.current
SwitchSettingsItem(
imageVector = Icons.Default.Expand,
text = stringResource(id = R.string.feed_style_screen_feed_group_expand),
checked = feedGroupExpand,
onCheckedChange = {
FeedGroupExpandPreference.put(
context = context,
scope = scope,
value = it,
)
}
)
}
}
}
}
4 changes: 3 additions & 1 deletion app/src/main/java/com/skyd/anivu/ui/local/LocalValue.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import androidx.navigation.NavHostController
import com.skyd.anivu.model.preference.IgnoreUpdateVersionPreference
import com.skyd.anivu.model.preference.appearance.DarkModePreference
import com.skyd.anivu.model.preference.appearance.ThemePreference
import com.skyd.anivu.model.preference.appearance.feed.FeedGroupExpandPreference
import com.skyd.anivu.model.preference.behavior.article.ArticleSwipeLeftActionPreference
import com.skyd.anivu.model.preference.behavior.article.ArticleTapActionPreference
import com.skyd.anivu.model.preference.behavior.article.DeduplicateTitleInDescPreference
Expand All @@ -18,9 +19,10 @@ val LocalWindowSizeClass = compositionLocalOf<WindowSizeClass> {
error("LocalWindowSizeClass not initialized!")
}

// Theme
// Appearance
val LocalTheme = compositionLocalOf { ThemePreference.default }
val LocalDarkMode = compositionLocalOf { DarkModePreference.default }
val LocalFeedGroupExpand = compositionLocalOf { FeedGroupExpandPreference.default }

// Update
val LocalIgnoreUpdateVersion = compositionLocalOf { IgnoreUpdateVersionPreference.default }
Expand Down
Loading

0 comments on commit d4b9078

Please sign in to comment.