Skip to content

Commit f205d1a

Browse files
committed
[feature] Support #84
1 parent bf65961 commit f205d1a

File tree

23 files changed

+301
-40
lines changed

23 files changed

+301
-40
lines changed

app/build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ android {
2121
applicationId = "com.skyd.anivu"
2222
minSdk = 24
2323
targetSdk = 35
24-
versionCode = 25
25-
versionName = "3.1-alpha01"
24+
versionCode = 26
25+
versionName = "3.1-alpha02"
2626

2727
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
2828

app/src/main/java/com/skyd/anivu/ext/PreferenceExt.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import com.skyd.anivu.model.preference.appearance.feed.FeedDefaultGroupExpandPre
1919
import com.skyd.anivu.model.preference.appearance.feed.FeedListTonalElevationPreference
2020
import com.skyd.anivu.model.preference.appearance.feed.FeedNumberBadgePreference
2121
import com.skyd.anivu.model.preference.appearance.feed.FeedTopBarTonalElevationPreference
22+
import com.skyd.anivu.model.preference.appearance.feed.HideMutedFeedPreference
2223
import com.skyd.anivu.model.preference.appearance.media.MediaFileFilterPreference
2324
import com.skyd.anivu.model.preference.appearance.media.MediaShowGroupTabPreference
2425
import com.skyd.anivu.model.preference.appearance.media.MediaShowThumbnailPreference
@@ -92,6 +93,7 @@ fun Preferences.toSettings(): Settings {
9293
readContentTonalElevation = ReadContentTonalElevationPreference.fromPreferences(this),
9394
readTopBarTonalElevation = ReadTopBarTonalElevationPreference.fromPreferences(this),
9495
feedNumberBadge = FeedNumberBadgePreference.fromPreferences(this),
96+
hideMutedFeed = HideMutedFeedPreference.fromPreferences(this),
9597

9698
// Update
9799
ignoreUpdateVersion = IgnoreUpdateVersionPreference.fromPreferences(this),

app/src/main/java/com/skyd/anivu/model/bean/feed/FeedBean.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ data class FeedBean(
3838
val sortXmlArticlesOnUpdate: Boolean = false,
3939
@ColumnInfo(name = REQUEST_HEADERS_COLUMN)
4040
val requestHeaders: RequestHeaders? = null,
41+
@ColumnInfo(name = MUTE_COLUMN)
42+
val mute: Boolean = false,
43+
@ColumnInfo(name = PREVIOUS_FEED_URL_COLUMN)
44+
val previousFeedUrl: String? = null,
45+
@ColumnInfo(name = NEXT_FEED_URL_COLUMN)
46+
val nextFeedUrl: String? = null,
4147
) : BaseBean, Parcelable {
4248
companion object {
4349
const val URL_COLUMN = "url"
@@ -51,6 +57,9 @@ data class FeedBean(
5157
const val CUSTOM_ICON_COLUMN = "customIcon"
5258
const val SORT_XML_ARTICLES_ON_UPDATE_COLUMN = "sortXmlArticlesOnUpdate"
5359
const val REQUEST_HEADERS_COLUMN = "requestHeaders"
60+
const val MUTE_COLUMN = "mute"
61+
const val PREVIOUS_FEED_URL_COLUMN = "previousFeedUrl"
62+
const val NEXT_FEED_URL_COLUMN = "nextFeedUrl"
5463

5564
fun FeedBean.isDefaultGroup(): Boolean =
5665
this.groupId == null || this.groupId == GroupVo.DEFAULT_GROUP_ID

app/src/main/java/com/skyd/anivu/model/db/AppDatabase.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import com.skyd.anivu.model.db.migration.Migration12To13
3535
import com.skyd.anivu.model.db.migration.Migration13To14
3636
import com.skyd.anivu.model.db.migration.Migration14To15
3737
import com.skyd.anivu.model.db.migration.Migration15To16
38+
import com.skyd.anivu.model.db.migration.Migration16To17
3839
import com.skyd.anivu.model.db.migration.Migration1To2
3940
import com.skyd.anivu.model.db.migration.Migration2To3
4041
import com.skyd.anivu.model.db.migration.Migration3To4
@@ -62,7 +63,7 @@ const val APP_DATA_BASE_FILE_NAME = "app.db"
6263
RssMediaBean::class,
6364
],
6465
views = [FeedViewBean::class],
65-
version = 16,
66+
version = 17,
6667
)
6768
@TypeConverters(
6869
value = [CategoriesConverter::class, RequestHeadersConverter::class]
@@ -87,7 +88,7 @@ abstract class AppDatabase : RoomDatabase() {
8788
Migration1To2(), Migration2To3(), Migration3To4(), Migration4To5(),
8889
Migration5To6(), Migration6To7(), Migration7To8(), Migration8To9(),
8990
Migration9To10(), Migration10To11(), Migration11To12(), Migration12To13(),
90-
Migration13To14(), Migration14To15(), Migration15To16(),
91+
Migration13To14(), Migration14To15(), Migration15To16(), Migration16To17(),
9192
)
9293

9394
fun getInstance(context: Context): AppDatabase {

app/src/main/java/com/skyd/anivu/model/db/dao/FeedDao.kt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,10 @@ interface FeedDao {
160160
)
161161
suspend fun getFeedsNotInGroup(groupIds: List<String>): List<FeedViewBean>
162162

163+
@Transaction
164+
@Query("SELECT * FROM $FEED_VIEW_NAME WHERE ${FeedBean.GROUP_ID_COLUMN} IS NULL")
165+
fun getFeedsInDefaultGroup(): Flow<List<FeedViewBean>>
166+
163167
@Transaction
164168
@Query(
165169
"""
@@ -182,11 +186,30 @@ interface FeedDao {
182186
@Query("SELECT ${FeedBean.URL_COLUMN} FROM $FEED_TABLE_NAME")
183187
fun getAllFeedUrl(): List<String>
184188

189+
@Transaction
190+
@Query("SELECT ${FeedBean.URL_COLUMN} FROM $FEED_TABLE_NAME WHERE ${FeedBean.MUTE_COLUMN} = 0")
191+
fun getAllUnmutedFeedUrl(): List<String>
192+
185193
@Transaction
186194
@Query("SELECT COUNT(*) FROM $FEED_TABLE_NAME WHERE ${FeedBean.URL_COLUMN} LIKE :url")
187195
fun containsByUrl(url: String): Int
188196

189197
@Transaction
190198
@Query("SELECT COUNT(*) FROM $FEED_TABLE_NAME WHERE ${FeedBean.CUSTOM_ICON_COLUMN} LIKE :customIcon")
191199
fun containsByCustomIcon(customIcon: String): Int
200+
201+
@Transaction
202+
@Query(
203+
"UPDATE $FEED_TABLE_NAME SET ${FeedBean.MUTE_COLUMN} = :mute " +
204+
"WHERE ${FeedBean.URL_COLUMN} = :feedUrl"
205+
)
206+
suspend fun muteFeed(feedUrl: String, mute: Boolean): Int
207+
208+
@Transaction
209+
@Query(
210+
"UPDATE $FEED_TABLE_NAME SET ${FeedBean.MUTE_COLUMN} = :mute " +
211+
"WHERE ${FeedBean.GROUP_ID_COLUMN} IS NULL AND :groupId IS NULL " +
212+
"OR ${FeedBean.GROUP_ID_COLUMN} = :groupId"
213+
)
214+
suspend fun muteFeedsInGroup(groupId: String?, mute: Boolean): Int
192215
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.skyd.anivu.model.db.migration
2+
3+
import androidx.room.migration.Migration
4+
import androidx.sqlite.db.SupportSQLiteDatabase
5+
import com.skyd.anivu.model.bean.feed.FEED_TABLE_NAME
6+
import com.skyd.anivu.model.bean.feed.FeedBean
7+
8+
class Migration16To17 : Migration(16, 17) {
9+
override fun migrate(db: SupportSQLiteDatabase) {
10+
db.execSQL("ALTER TABLE `$FEED_TABLE_NAME` ADD ${FeedBean.MUTE_COLUMN} INTEGER NOT NULL DEFAULT 0")
11+
db.execSQL("ALTER TABLE `$FEED_TABLE_NAME` ADD ${FeedBean.PREVIOUS_FEED_URL_COLUMN} TEXT")
12+
db.execSQL("ALTER TABLE `$FEED_TABLE_NAME` ADD ${FeedBean.NEXT_FEED_URL_COLUMN} TEXT")
13+
}
14+
}

app/src/main/java/com/skyd/anivu/model/preference/Settings.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import com.skyd.anivu.model.preference.appearance.feed.FeedDefaultGroupExpandPre
2424
import com.skyd.anivu.model.preference.appearance.feed.FeedListTonalElevationPreference
2525
import com.skyd.anivu.model.preference.appearance.feed.FeedNumberBadgePreference
2626
import com.skyd.anivu.model.preference.appearance.feed.FeedTopBarTonalElevationPreference
27+
import com.skyd.anivu.model.preference.appearance.feed.HideMutedFeedPreference
2728
import com.skyd.anivu.model.preference.appearance.media.MediaFileFilterPreference
2829
import com.skyd.anivu.model.preference.appearance.media.MediaShowGroupTabPreference
2930
import com.skyd.anivu.model.preference.appearance.media.MediaShowThumbnailPreference
@@ -91,6 +92,7 @@ import com.skyd.anivu.ui.local.LocalFeedNumberBadge
9192
import com.skyd.anivu.ui.local.LocalFeedTopBarTonalElevation
9293
import com.skyd.anivu.ui.local.LocalHardwareDecode
9394
import com.skyd.anivu.ui.local.LocalHideEmptyDefault
95+
import com.skyd.anivu.ui.local.LocalHideMutedFeed
9496
import com.skyd.anivu.ui.local.LocalIgnoreUpdateVersion
9597
import com.skyd.anivu.ui.local.LocalMediaFileFilter
9698
import com.skyd.anivu.ui.local.LocalMediaLibLocation
@@ -160,6 +162,7 @@ data class Settings(
160162
val readContentTonalElevation: Float = ReadContentTonalElevationPreference.default,
161163
val readTopBarTonalElevation: Float = ReadTopBarTonalElevationPreference.default,
162164
val feedNumberBadge: Int = FeedNumberBadgePreference.default,
165+
val hideMutedFeed: Boolean = HideMutedFeedPreference.default,
163166
// Update
164167
val ignoreUpdateVersion: Long = IgnoreUpdateVersionPreference.default,
165168
// Behavior
@@ -240,6 +243,7 @@ fun SettingsProvider(
240243
LocalReadContentTonalElevation provides settings.readContentTonalElevation,
241244
LocalReadTopBarTonalElevation provides settings.readTopBarTonalElevation,
242245
LocalFeedNumberBadge provides settings.feedNumberBadge,
246+
LocalHideMutedFeed provides settings.hideMutedFeed,
243247
// Update
244248
LocalIgnoreUpdateVersion provides settings.ignoreUpdateVersion,
245249
// Behavior
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.skyd.anivu.model.preference.appearance.feed
2+
3+
import android.content.Context
4+
import androidx.datastore.preferences.core.Preferences
5+
import androidx.datastore.preferences.core.booleanPreferencesKey
6+
import com.skyd.anivu.base.BasePreference
7+
import com.skyd.anivu.ext.dataStore
8+
import com.skyd.anivu.ext.put
9+
import kotlinx.coroutines.CoroutineScope
10+
import kotlinx.coroutines.Dispatchers
11+
import kotlinx.coroutines.launch
12+
13+
object HideMutedFeedPreference : BasePreference<Boolean> {
14+
private const val HIDE_MUTED_FEED = "hideMutedFeed"
15+
override val default = true
16+
17+
val key = booleanPreferencesKey(HIDE_MUTED_FEED)
18+
19+
fun put(context: Context, scope: CoroutineScope, value: Boolean) {
20+
scope.launch(Dispatchers.IO) {
21+
context.dataStore.put(key, value)
22+
}
23+
}
24+
25+
override fun fromPreferences(preferences: Preferences): Boolean = preferences[key] ?: default
26+
}

app/src/main/java/com/skyd/anivu/model/repository/feed/FeedRepository.kt

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@ import com.skyd.anivu.model.db.dao.ArticleDao
1616
import com.skyd.anivu.model.db.dao.FeedDao
1717
import com.skyd.anivu.model.db.dao.GroupDao
1818
import com.skyd.anivu.model.preference.appearance.feed.FeedDefaultGroupExpandPreference
19+
import com.skyd.anivu.model.preference.appearance.feed.HideMutedFeedPreference
1920
import com.skyd.anivu.model.repository.RssHelper
2021
import kotlinx.coroutines.Dispatchers
2122
import kotlinx.coroutines.flow.Flow
2223
import kotlinx.coroutines.flow.combine
24+
import kotlinx.coroutines.flow.distinctUntilChanged
2325
import kotlinx.coroutines.flow.flow
2426
import kotlinx.coroutines.flow.flowOf
2527
import kotlinx.coroutines.flow.flowOn
@@ -37,16 +39,17 @@ class FeedRepository @Inject constructor(
3739
) : BaseRepository() {
3840
fun requestGroupAnyList(): Flow<List<Any>> = combine(
3941
groupDao.getGroupWithFeeds(),
40-
groupDao.getGroupIds(),
41-
) { groupList, groupIds ->
42-
groupList to feedDao.getFeedsNotInGroup(groupIds)
43-
}.map { (groupList, defaultFeeds) ->
42+
feedDao.getFeedsInDefaultGroup(),
43+
appContext.dataStore.data.map {
44+
it[HideMutedFeedPreference.key] ?: HideMutedFeedPreference.default
45+
}.distinctUntilChanged()
46+
) { groupList, defaultFeeds, hideMute ->
4447
mutableListOf<Any>().apply {
4548
add(GroupVo.DefaultGroup)
46-
addAll(defaultFeeds)
49+
addAll(defaultFeeds.run { if (hideMute) filter { !it.feed.mute } else this })
4750
reorderGroupRepository.sortGroupWithFeed(groupList).forEach { group ->
4851
add(group.group.toVo())
49-
addAll(group.feeds)
52+
addAll(group.feeds.run { if (hideMute) filter { !it.feed.mute } else this })
5053
}
5154
}
5255
}.flowOn(Dispatchers.IO)
@@ -229,6 +232,15 @@ class FeedRepository @Inject constructor(
229232
fun readAllInFeed(feedUrl: String): Flow<Int> = flow {
230233
emit(articleDao.readAllInFeed(feedUrl))
231234
}.flowOn(Dispatchers.IO)
235+
236+
fun muteFeed(feedUrl: String, mute: Boolean): Flow<Int> = flow {
237+
emit(feedDao.muteFeed(feedUrl, mute))
238+
}.flowOn(Dispatchers.IO)
239+
240+
fun muteFeedsInGroup(groupId: String?, mute: Boolean): Flow<Int> = flow {
241+
val realGroupId = if (groupId == GroupVo.DefaultGroup.groupId) null else groupId
242+
emit(feedDao.muteFeedsInGroup(realGroupId, mute))
243+
}.flowOn(Dispatchers.IO)
232244
}
233245

234246
fun tryDeleteFeedIconFile(path: String?) {

app/src/main/java/com/skyd/anivu/model/worker/rsssync/RssSyncWorker.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class RssSyncWorker(context: Context, parameters: WorkerParameters) :
2929
override suspend fun doWork(): Result {
3030
var hasError = false
3131
hiltEntryPoint.articleRepo
32-
.refreshArticleList(hiltEntryPoint.feedDao.getAllFeedUrl())
32+
.refreshArticleList(hiltEntryPoint.feedDao.getAllUnmutedFeedUrl())
3333
.catch {
3434
hasError = true
3535
it.printStackTrace()

0 commit comments

Comments
 (0)