-
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[feature|optimize|build] Support configure whether the group is expan…
…ded or not (#13); optimize SettingsItem.kt; update dependencies
- Loading branch information
Showing
13 changed files
with
186 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
...rc/main/java/com/skyd/anivu/model/preference/appearance/feed/FeedGroupExpandPreference.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
app/src/main/java/com/skyd/anivu/ui/fragment/settings/appearance/feed/FeedStyleFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
) | ||
} | ||
) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.