Skip to content

Commit

Permalink
[feature|fix|refactor] Support record each group's expanded state (#35)…
Browse files Browse the repository at this point in the history
…; fix the issue of notifications failing to display when downloading; check post notification permission before downloading; refactor the download manager code; remove LazyVerticalGrid adapter code
  • Loading branch information
SkyD666 committed Sep 8, 2024
1 parent 21318f3 commit 91dc781
Show file tree
Hide file tree
Showing 38 changed files with 557 additions and 703 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ android {
minSdk = 24
targetSdk = 35
versionCode = 24
versionName = "2.1-alpha31"
versionName = "2.1-beta01"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"

Expand Down
23 changes: 0 additions & 23 deletions app/src/main/java/com/skyd/anivu/di/DownloadModule.kt

This file was deleted.

8 changes: 8 additions & 0 deletions app/src/main/java/com/skyd/anivu/ext/FlowExt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,16 @@ import kotlinx.coroutines.flow.FlowCollector
import kotlinx.coroutines.flow.buffer
import kotlinx.coroutines.flow.catch
import kotlinx.coroutines.flow.channelFlow
import kotlinx.coroutines.flow.debounce
import kotlinx.coroutines.flow.drop
import kotlinx.coroutines.flow.emitAll
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.flow.flowOn
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.merge
import kotlinx.coroutines.flow.produceIn
import kotlinx.coroutines.flow.take
import kotlinx.coroutines.launch
import java.util.concurrent.atomic.AtomicBoolean

Expand Down Expand Up @@ -82,3 +86,7 @@ fun <T> Flow<T>.collectIn(
): Job = lifecycleOwner.lifecycleScope.launch {
flowWithLifecycle(lifecycleOwner.lifecycle, minActiveState).collect(action)
}

fun <T> Flow<T>.debounceWithoutFirst(timeoutMillis: Long) = merge(
take(1), drop(1).debounce(timeoutMillis)
)
4 changes: 2 additions & 2 deletions app/src/main/java/com/skyd/anivu/ext/PreferenceExt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import com.skyd.anivu.model.preference.appearance.article.ArticleListTonalElevat
import com.skyd.anivu.model.preference.appearance.article.ArticleTopBarTonalElevationPreference
import com.skyd.anivu.model.preference.appearance.article.ShowArticlePullRefreshPreference
import com.skyd.anivu.model.preference.appearance.article.ShowArticleTopBarRefreshPreference
import com.skyd.anivu.model.preference.appearance.feed.FeedGroupExpandPreference
import com.skyd.anivu.model.preference.appearance.feed.FeedDefaultGroupExpandPreference
import com.skyd.anivu.model.preference.appearance.feed.FeedListTonalElevationPreference
import com.skyd.anivu.model.preference.appearance.feed.FeedTopBarTonalElevationPreference
import com.skyd.anivu.model.preference.appearance.media.MediaShowThumbnailPreference
Expand Down Expand Up @@ -61,7 +61,7 @@ fun Preferences.toSettings(): Settings {
// Appearance
theme = ThemePreference.fromPreferences(this),
darkMode = DarkModePreference.fromPreferences(this),
feedGroupExpand = FeedGroupExpandPreference.fromPreferences(this),
feedDefaultGroupExpand = FeedDefaultGroupExpandPreference.fromPreferences(this),
textFieldStyle = TextFieldStylePreference.fromPreferences(this),
dateStyle = DateStylePreference.fromPreferences(this),
navigationBarLabel = NavigationBarLabelPreference.fromPreferences(this),
Expand Down
6 changes: 4 additions & 2 deletions app/src/main/java/com/skyd/anivu/model/bean/GroupVo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import com.skyd.anivu.appContext
import com.skyd.anivu.base.BaseBean
import com.skyd.anivu.ext.dataStore
import com.skyd.anivu.ext.getOrDefault
import com.skyd.anivu.model.preference.appearance.feed.FeedGroupExpandPreference
import com.skyd.anivu.model.preference.appearance.feed.FeedDefaultGroupExpandPreference
import kotlinx.parcelize.Parcelize
import kotlinx.serialization.Serializable

Expand All @@ -25,11 +25,13 @@ open class GroupVo(
GroupVo(
DEFAULT_GROUP_ID,
appContext.getString(R.string.default_feed_group),
appContext.dataStore.getOrDefault(FeedGroupExpandPreference),
appContext.dataStore.getOrDefault(FeedDefaultGroupExpandPreference),
) {
private fun readResolve(): Any = DefaultGroup
override val name: String
get() = appContext.getString(R.string.default_feed_group)
override val isExpanded: Boolean
get() = appContext.dataStore.getOrDefault(FeedDefaultGroupExpandPreference)
}

companion object {
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/java/com/skyd/anivu/model/db/dao/GroupDao.kt
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,13 @@ interface GroupDao {
}
}

@Transaction
@Query(
"UPDATE `$GROUP_TABLE_NAME` SET ${GroupBean.IS_EXPANDED_COLUMN} = :expanded " +
"WHERE ${GroupBean.GROUP_ID_COLUMN} = :groupId"
)
suspend fun changeGroupExpanded(groupId: String, expanded: Boolean): Int

@Transaction
@Query("SELECT * FROM `$GROUP_TABLE_NAME`")
fun getGroupWithFeeds(): Flow<List<GroupWithFeedBean>>
Expand Down
8 changes: 4 additions & 4 deletions app/src/main/java/com/skyd/anivu/model/preference/Settings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import com.skyd.anivu.model.preference.appearance.article.ArticleListTonalElevat
import com.skyd.anivu.model.preference.appearance.article.ArticleTopBarTonalElevationPreference
import com.skyd.anivu.model.preference.appearance.article.ShowArticlePullRefreshPreference
import com.skyd.anivu.model.preference.appearance.article.ShowArticleTopBarRefreshPreference
import com.skyd.anivu.model.preference.appearance.feed.FeedGroupExpandPreference
import com.skyd.anivu.model.preference.appearance.feed.FeedDefaultGroupExpandPreference
import com.skyd.anivu.model.preference.appearance.feed.FeedListTonalElevationPreference
import com.skyd.anivu.model.preference.appearance.feed.FeedTopBarTonalElevationPreference
import com.skyd.anivu.model.preference.appearance.media.MediaShowThumbnailPreference
Expand Down Expand Up @@ -72,7 +72,7 @@ import com.skyd.anivu.ui.local.LocalAutoDeleteArticleFrequency
import com.skyd.anivu.ui.local.LocalDarkMode
import com.skyd.anivu.ui.local.LocalDateStyle
import com.skyd.anivu.ui.local.LocalDeduplicateTitleInDesc
import com.skyd.anivu.ui.local.LocalFeedGroupExpand
import com.skyd.anivu.ui.local.LocalFeedDefaultGroupExpand
import com.skyd.anivu.ui.local.LocalFeedListTonalElevation
import com.skyd.anivu.ui.local.LocalFeedTopBarTonalElevation
import com.skyd.anivu.ui.local.LocalHardwareDecode
Expand Down Expand Up @@ -120,7 +120,7 @@ data class Settings(
// Appearance
val theme: String = ThemePreference.default,
val darkMode: Int = DarkModePreference.default,
val feedGroupExpand: Boolean = FeedGroupExpandPreference.default,
val feedDefaultGroupExpand: Boolean = FeedDefaultGroupExpandPreference.default,
val textFieldStyle: String = TextFieldStylePreference.default,
val dateStyle: String = DateStylePreference.default,
val navigationBarLabel: String = NavigationBarLabelPreference.default,
Expand Down Expand Up @@ -191,7 +191,7 @@ fun SettingsProvider(
// Appearance
LocalTheme provides settings.theme,
LocalDarkMode provides settings.darkMode,
LocalFeedGroupExpand provides settings.feedGroupExpand,
LocalFeedDefaultGroupExpand provides settings.feedDefaultGroupExpand,
LocalTextFieldStyle provides settings.textFieldStyle,
LocalDateStyle provides settings.dateStyle,
LocalNavigationBarLabel provides settings.navigationBarLabel,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch

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

val key = booleanPreferencesKey(FEED_GROUP_EXPAND)
val key = booleanPreferencesKey(FEED_DEFAULT_GROUP_EXPAND)

fun put(context: Context, scope: CoroutineScope, value: Boolean) {
scope.launch(Dispatchers.IO) {
Expand Down
Loading

0 comments on commit 91dc781

Please sign in to comment.