Skip to content

Commit

Permalink
[feature] Support #65
Browse files Browse the repository at this point in the history
  • Loading branch information
SkyD666 committed Dec 27, 2024
1 parent 2574590 commit 02a7174
Show file tree
Hide file tree
Showing 21 changed files with 330 additions and 188 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-beta17"
versionName = "2.1-rc01"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"

Expand Down
2 changes: 2 additions & 0 deletions app/src/main/java/com/skyd/anivu/ext/PreferenceExt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import com.skyd.anivu.model.preference.appearance.article.ShowArticlePullRefresh
import com.skyd.anivu.model.preference.appearance.article.ShowArticleTopBarRefreshPreference
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.FeedNumberBadgePreference
import com.skyd.anivu.model.preference.appearance.feed.FeedTopBarTonalElevationPreference
import com.skyd.anivu.model.preference.appearance.media.MediaShowThumbnailPreference
import com.skyd.anivu.model.preference.appearance.read.ReadContentTonalElevationPreference
Expand Down Expand Up @@ -87,6 +88,7 @@ fun Preferences.toSettings(): Settings {
readTextSize = ReadTextSizePreference.fromPreferences(this),
readContentTonalElevation = ReadContentTonalElevationPreference.fromPreferences(this),
readTopBarTonalElevation = ReadTopBarTonalElevationPreference.fromPreferences(this),
feedNumberBadge = FeedNumberBadgePreference.fromPreferences(this),

// Update
ignoreUpdateVersion = IgnoreUpdateVersionPreference.fromPreferences(this),
Expand Down
19 changes: 9 additions & 10 deletions app/src/main/java/com/skyd/anivu/model/db/dao/FeedDao.kt
Original file line number Diff line number Diff line change
Expand Up @@ -139,17 +139,16 @@ interface FeedDao {
fun getFeedPagingSource(): PagingSource<Int, FeedBean>

@Transaction
@Query("SELECT * FROM $FEED_TABLE_NAME WHERE ${FeedBean.URL_COLUMN} = :feedUrl")
suspend fun getFeed(feedUrl: String): FeedBean
@Query("SELECT * FROM $FEED_VIEW_NAME WHERE ${FeedBean.URL_COLUMN} = :feedUrl")
suspend fun getFeed(feedUrl: String): FeedViewBean

@Transaction
@Query(
"""
SELECT * FROM $FEED_VIEW_NAME
WHERE ${FeedBean.GROUP_ID_COLUMN} IN (:groupIds)
"""
)
suspend fun getFeedsIn(groupIds: List<String>): List<FeedViewBean>
@Query("SELECT * FROM $FEED_VIEW_NAME WHERE ${FeedBean.URL_COLUMN} IN (:feedUrls)")
suspend fun getFeedsIn(feedUrls: List<String>): List<FeedViewBean>

@Transaction
@Query("SELECT * FROM $FEED_VIEW_NAME WHERE ${FeedBean.GROUP_ID_COLUMN} IN (:groupIds)")
suspend fun getFeedsInGroup(groupIds: List<String>): List<FeedViewBean>

@Transaction
@Query(
Expand All @@ -159,7 +158,7 @@ interface FeedDao {
${FeedBean.GROUP_ID_COLUMN} NOT IN (:groupIds)
"""
)
suspend fun getFeedsNotIn(groupIds: List<String>): List<FeedViewBean>
suspend fun getFeedsNotInGroup(groupIds: List<String>): List<FeedViewBean>

@Transaction
@Query(
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/skyd/anivu/model/db/dao/GroupDao.kt
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ interface GroupDao {
removeGroupIdFromList(groupId)
innerRemoveGroup(groupId)
return EntryPointAccessors.fromApplication(appContext, GroupDaoEntryPoint::class.java).run {
feedDao.getFeedsIn(listOf(groupId)).forEach {
feedDao.getFeedsInGroup(listOf(groupId)).forEach {
it.feed.customIcon?.let { icon -> tryDeleteFeedIconFile(icon) }
}
feedDao.removeFeedByGroupId(groupId)
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/java/com/skyd/anivu/model/preference/Settings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import com.skyd.anivu.model.preference.appearance.article.ShowArticlePullRefresh
import com.skyd.anivu.model.preference.appearance.article.ShowArticleTopBarRefreshPreference
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.FeedNumberBadgePreference
import com.skyd.anivu.model.preference.appearance.feed.FeedTopBarTonalElevationPreference
import com.skyd.anivu.model.preference.appearance.media.MediaShowThumbnailPreference
import com.skyd.anivu.model.preference.appearance.read.ReadContentTonalElevationPreference
Expand Down Expand Up @@ -84,6 +85,7 @@ import com.skyd.anivu.ui.local.LocalDateStyle
import com.skyd.anivu.ui.local.LocalDeduplicateTitleInDesc
import com.skyd.anivu.ui.local.LocalFeedDefaultGroupExpand
import com.skyd.anivu.ui.local.LocalFeedListTonalElevation
import com.skyd.anivu.ui.local.LocalFeedNumberBadge
import com.skyd.anivu.ui.local.LocalFeedTopBarTonalElevation
import com.skyd.anivu.ui.local.LocalHardwareDecode
import com.skyd.anivu.ui.local.LocalHideEmptyDefault
Expand Down Expand Up @@ -152,6 +154,7 @@ data class Settings(
val readTextSize: Float = ReadTextSizePreference.default,
val readContentTonalElevation: Float = ReadContentTonalElevationPreference.default,
val readTopBarTonalElevation: Float = ReadTopBarTonalElevationPreference.default,
val feedNumberBadge: Int = FeedNumberBadgePreference.default,
// Update
val ignoreUpdateVersion: Long = IgnoreUpdateVersionPreference.default,
// Behavior
Expand Down Expand Up @@ -229,6 +232,7 @@ fun SettingsProvider(
LocalReadTextSize provides settings.readTextSize,
LocalReadContentTonalElevation provides settings.readContentTonalElevation,
LocalReadTopBarTonalElevation provides settings.readTopBarTonalElevation,
LocalFeedNumberBadge provides settings.feedNumberBadge,
// Update
LocalIgnoreUpdateVersion provides settings.ignoreUpdateVersion,
// Behavior
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.skyd.anivu.model.preference.appearance.feed

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

object FeedNumberBadgePreference : BasePreference<Int> {
private const val FEED_NUMBER_BADGE = "feedNumberBadge"

const val UNREAD = 1
const val ALL = 1 shl 1
const val UNREAD_ALL = UNREAD + ALL
val values = arrayOf(UNREAD, ALL, UNREAD_ALL)

override val default = ALL

val key = intPreferencesKey(FEED_NUMBER_BADGE)

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

override fun fromPreferences(preferences: Preferences): Int = preferences[key] ?: default

fun toDisplayName(
context: Context,
value: Int = context.dataStore.getOrDefault(this),
): String = when (value) {
UNREAD -> context.getString(R.string.feed_number_badge_unread)
ALL -> context.getString(R.string.feed_number_badge_all)
UNREAD_ALL -> context.getString(R.string.feed_number_badge_unread_all)
else -> context.getString(R.string.unknown)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class ArticleRepository @Inject constructor(
requests += async {
val articleBeanList = runCatching {
rssHelper.queryRssXml(
feed = feedDao.getFeed(feedUrl),
feed = feedDao.getFeed(feedUrl).feed,
latestLink = articleDao.queryLatestByFeedUrl(feedUrl)?.link,
)?.also { feedWithArticle ->
feedDao.updateFeed(feedWithArticle.feed)
Expand Down
Loading

0 comments on commit 02a7174

Please sign in to comment.