Skip to content

Commit

Permalink
[feature|optimize|fix] Support configure the tonal elevation of some …
Browse files Browse the repository at this point in the history
…components of Feed (#55), Article, and Search screens; optimize the layout of Article screen and search screen (#53); fix the wrong article deduplication issue (#54)
  • Loading branch information
SkyD666 committed Jun 5, 2024
1 parent 6e59f4d commit 7e0a2c2
Show file tree
Hide file tree
Showing 37 changed files with 1,504 additions and 317 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ android {
applicationId = "com.skyd.anivu"
minSdk = 24
targetSdk = 34
versionCode = 17
versionName = "1.1-beta45"
versionCode = 18
versionName = "1.1-beta46"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"

Expand Down
6 changes: 1 addition & 5 deletions app/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,4 @@ public static final ** CREATOR;
-dontwarn com.arthenica.smartexception.java.Exceptions

# MPV
-keep,allowoptimization class is.xyz.mpv.MPVLib { public protected *; }

-dontwarn org.xmlpull.v1.**
-keep class org.xmlpull.** { *; }
-keepclassmembers class org.xmlpull.** { *; }
-keep,allowoptimization class is.xyz.mpv.MPVLib { public protected *; }
4 changes: 4 additions & 0 deletions app/src/main/java/com/skyd/anivu/ext/PaddingValuesExt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import androidx.compose.foundation.layout.calculateEndPadding
import androidx.compose.foundation.layout.calculateStartPadding
import androidx.compose.runtime.Composable
import androidx.compose.ui.platform.LocalLayoutDirection
import androidx.compose.ui.unit.Dp

@Composable
operator fun PaddingValues.plus(other: PaddingValues): PaddingValues = PaddingValues(
Expand All @@ -15,3 +16,6 @@ operator fun PaddingValues.plus(other: PaddingValues): PaddingValues = PaddingVa
end = calculateEndPadding(LocalLayoutDirection.current) +
other.calculateEndPadding(LocalLayoutDirection.current)
)

@Composable
operator fun PaddingValues.plus(other: Dp): PaddingValues = this + PaddingValues(other)
14 changes: 14 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 @@ -8,7 +8,14 @@ import com.skyd.anivu.model.preference.appearance.DateStylePreference
import com.skyd.anivu.model.preference.appearance.NavigationBarLabelPreference
import com.skyd.anivu.model.preference.appearance.TextFieldStylePreference
import com.skyd.anivu.model.preference.appearance.ThemePreference
import com.skyd.anivu.model.preference.appearance.article.ArticleItemTonalElevationPreference
import com.skyd.anivu.model.preference.appearance.article.ArticleListTonalElevationPreference
import com.skyd.anivu.model.preference.appearance.article.ArticleTopBarTonalElevationPreference
import com.skyd.anivu.model.preference.appearance.feed.FeedGroupExpandPreference
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.search.SearchListTonalElevationPreference
import com.skyd.anivu.model.preference.appearance.search.SearchTopBarTonalElevationPreference
import com.skyd.anivu.model.preference.behavior.PickImageMethodPreference
import com.skyd.anivu.model.preference.behavior.article.ArticleSwipeLeftActionPreference
import com.skyd.anivu.model.preference.behavior.article.ArticleTapActionPreference
Expand All @@ -32,6 +39,13 @@ fun Preferences.toSettings(): Settings {
textFieldStyle = TextFieldStylePreference.fromPreferences(this),
dateStyle = DateStylePreference.fromPreferences(this),
navigationBarLabel = NavigationBarLabelPreference.fromPreferences(this),
feedListTonalElevation = FeedListTonalElevationPreference.fromPreferences(this),
feedTopBarTonalElevation = FeedTopBarTonalElevationPreference.fromPreferences(this),
articleListTonalElevation = ArticleListTonalElevationPreference.fromPreferences(this),
articleTopBarTonalElevation = ArticleTopBarTonalElevationPreference.fromPreferences(this),
articleItemTonalElevation = ArticleItemTonalElevationPreference.fromPreferences(this),
searchListTonalElevation = SearchListTonalElevationPreference.fromPreferences(this),
searchTopBarTonalElevation = SearchTopBarTonalElevationPreference.fromPreferences(this),

// Update
ignoreUpdateVersion = IgnoreUpdateVersionPreference.fromPreferences(this),
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/java/com/skyd/anivu/model/bean/ArticleBean.kt
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ data class ArticleBean(
val image: String? = null,
@ColumnInfo(name = LINK_COLUMN)
var link: String? = null,
@ColumnInfo(name = GUID_COLUMN)
var guid: String? = null,
@ColumnInfo(name = UPDATE_AT_COLUMN)
var updateAt: Long? = null,
@ColumnInfo(name = IS_READ_COLUMN)
Expand All @@ -66,6 +68,7 @@ data class ArticleBean(
const val CONTENT_COLUMN = "content"
const val IMAGE_COLUMN = "image"
const val LINK_COLUMN = "link"
const val GUID_COLUMN = "guid"
const val UPDATE_AT_COLUMN = "updateAt"
const val IS_READ_COLUMN = "isRead"
const val IS_FAVORITE_COLUMN = "isFavorite"
Expand Down
5 changes: 3 additions & 2 deletions app/src/main/java/com/skyd/anivu/model/db/AppDatabase.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import com.skyd.anivu.model.db.migration.Migration2To3
import com.skyd.anivu.model.db.migration.Migration3To4
import com.skyd.anivu.model.db.migration.Migration4To5
import com.skyd.anivu.model.db.migration.Migration5To6
import com.skyd.anivu.model.db.migration.Migration6To7

const val APP_DATA_BASE_FILE_NAME = "app.db"

Expand All @@ -41,7 +42,7 @@ const val APP_DATA_BASE_FILE_NAME = "app.db"
GroupBean::class,
],
views = [FeedViewBean::class],
version = 6,
version = 7,
)
@TypeConverters(
value = []
Expand All @@ -61,7 +62,7 @@ abstract class AppDatabase : RoomDatabase() {

private val migrations = arrayOf(
Migration1To2(), Migration2To3(), Migration3To4(), Migration4To5(),
Migration5To6()
Migration5To6(), Migration6To7()
)

fun getInstance(context: Context): AppDatabase {
Expand Down
44 changes: 34 additions & 10 deletions app/src/main/java/com/skyd/anivu/model/db/dao/ArticleDao.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,25 @@ interface ArticleDao {
val enclosureDao: EnclosureDao
}

// null always compares false in '='
@Query(
"""
SELECT * from $ARTICLE_TABLE_NAME
WHERE ${ArticleBean.LINK_COLUMN} = :link
AND ${ArticleBean.FEED_URL_COLUMN} = :feedUrl
WHERE ${ArticleBean.GUID_COLUMN} = :guid AND
${ArticleBean.FEED_URL_COLUMN} = :feedUrl
"""
)
suspend fun queryArticleByGuid(
guid: String?,
feedUrl: String,
): ArticleBean?

// null always compares false in '='
@Query(
"""
SELECT * from $ARTICLE_TABLE_NAME
WHERE ${ArticleBean.LINK_COLUMN} = :link AND
${ArticleBean.FEED_URL_COLUMN} = :feedUrl
"""
)
suspend fun queryArticleByLink(
Expand All @@ -56,16 +70,26 @@ interface ArticleDao {
val hiltEntryPoint =
EntryPointAccessors.fromApplication(appContext, ArticleDaoEntryPoint::class.java)
articleWithEnclosureList.forEach {
// 可能会出现link、feedUrl都一样,但是uuid不一样的情况
var newArticle = queryArticleByLink(
link = it.article.link,
feedUrl = it.article.feedUrl,
)
// Duplicate article by guid or link
val guid = it.article.guid
val link = it.article.link
var newArticle: ArticleBean? = null
if (guid != null) {
newArticle = queryArticleByGuid(
guid = guid,
feedUrl = it.article.feedUrl,
)
} else if (link != null) {
newArticle = queryArticleByLink(
link = link,
feedUrl = it.article.feedUrl,
)
}
if (newArticle == null) {
innerUpdateArticle(it.article)
newArticle = it.article
} else {
// 除了uuid,其他的字段都更新
// Update all fields except articleId
newArticle = it.article.copy(articleId = newArticle.articleId)
innerUpdateArticle(newArticle)
}
Expand Down Expand Up @@ -143,7 +167,7 @@ interface ArticleDao {
@Query(
"""
UPDATE $ARTICLE_TABLE_NAME SET ${ArticleBean.IS_FAVORITE_COLUMN} = :favorite
WHERE ${ArticleBean.ARTICLE_ID_COLUMN} LIKE :articleId
WHERE ${ArticleBean.ARTICLE_ID_COLUMN} = :articleId
"""
)
fun favoriteArticle(articleId: String, favorite: Boolean)
Expand All @@ -152,7 +176,7 @@ interface ArticleDao {
@Query(
"""
UPDATE $ARTICLE_TABLE_NAME SET ${ArticleBean.IS_READ_COLUMN} = :read
WHERE ${ArticleBean.ARTICLE_ID_COLUMN} LIKE :articleId
WHERE ${ArticleBean.ARTICLE_ID_COLUMN} = :articleId
"""
)
fun readArticle(articleId: String, read: Boolean)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.skyd.anivu.model.db.migration

import androidx.room.migration.Migration
import androidx.sqlite.db.SupportSQLiteDatabase
import com.skyd.anivu.model.bean.ARTICLE_TABLE_NAME
import com.skyd.anivu.model.bean.ArticleBean

class Migration6To7 : Migration(6, 7) {
override fun migrate(db: SupportSQLiteDatabase) {
db.execSQL("ALTER TABLE $ARTICLE_TABLE_NAME ADD ${ArticleBean.GUID_COLUMN} TEXT")
}
}
28 changes: 28 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 @@ -13,7 +13,14 @@ import com.skyd.anivu.model.preference.appearance.DateStylePreference
import com.skyd.anivu.model.preference.appearance.NavigationBarLabelPreference
import com.skyd.anivu.model.preference.appearance.TextFieldStylePreference
import com.skyd.anivu.model.preference.appearance.ThemePreference
import com.skyd.anivu.model.preference.appearance.article.ArticleItemTonalElevationPreference
import com.skyd.anivu.model.preference.appearance.article.ArticleListTonalElevationPreference
import com.skyd.anivu.model.preference.appearance.article.ArticleTopBarTonalElevationPreference
import com.skyd.anivu.model.preference.appearance.feed.FeedGroupExpandPreference
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.search.SearchListTonalElevationPreference
import com.skyd.anivu.model.preference.appearance.search.SearchTopBarTonalElevationPreference
import com.skyd.anivu.model.preference.behavior.PickImageMethodPreference
import com.skyd.anivu.model.preference.behavior.article.ArticleSwipeLeftActionPreference
import com.skyd.anivu.model.preference.behavior.article.ArticleTapActionPreference
Expand All @@ -27,14 +34,19 @@ import com.skyd.anivu.model.preference.player.HardwareDecodePreference
import com.skyd.anivu.model.preference.player.PlayerDoubleTapPreference
import com.skyd.anivu.model.preference.player.PlayerShow85sButtonPreference
import com.skyd.anivu.model.preference.player.PlayerShowScreenshotButtonPreference
import com.skyd.anivu.ui.local.LocalArticleItemTonalElevation
import com.skyd.anivu.ui.local.LocalArticleListTonalElevation
import com.skyd.anivu.ui.local.LocalArticleSwipeLeftAction
import com.skyd.anivu.ui.local.LocalArticleTapAction
import com.skyd.anivu.ui.local.LocalArticleTopBarTonalElevation
import com.skyd.anivu.ui.local.LocalAutoDeleteArticleBefore
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.LocalFeedListTonalElevation
import com.skyd.anivu.ui.local.LocalFeedTopBarTonalElevation
import com.skyd.anivu.ui.local.LocalHardwareDecode
import com.skyd.anivu.ui.local.LocalHideEmptyDefault
import com.skyd.anivu.ui.local.LocalIgnoreUpdateVersion
Expand All @@ -44,6 +56,8 @@ import com.skyd.anivu.ui.local.LocalPickImageMethod
import com.skyd.anivu.ui.local.LocalPlayerDoubleTap
import com.skyd.anivu.ui.local.LocalPlayerShow85sButton
import com.skyd.anivu.ui.local.LocalPlayerShowScreenshotButton
import com.skyd.anivu.ui.local.LocalSearchListTonalElevation
import com.skyd.anivu.ui.local.LocalSearchTopBarTonalElevation
import com.skyd.anivu.ui.local.LocalTextFieldStyle
import com.skyd.anivu.ui.local.LocalTheme
import com.skyd.anivu.ui.local.LocalUseAutoDelete
Expand All @@ -58,6 +72,13 @@ data class Settings(
val textFieldStyle: String = TextFieldStylePreference.default,
val dateStyle: String = DateStylePreference.default,
val navigationBarLabel: String = NavigationBarLabelPreference.default,
val feedListTonalElevation: Float = FeedListTonalElevationPreference.default,
val feedTopBarTonalElevation: Float = FeedTopBarTonalElevationPreference.default,
val articleListTonalElevation: Float = ArticleListTonalElevationPreference.default,
val articleTopBarTonalElevation: Float = ArticleTopBarTonalElevationPreference.default,
val articleItemTonalElevation: Float = ArticleItemTonalElevationPreference.default,
val searchListTonalElevation: Float = SearchListTonalElevationPreference.default,
val searchTopBarTonalElevation: Float = SearchTopBarTonalElevationPreference.default,
// Update
val ignoreUpdateVersion: Long = IgnoreUpdateVersionPreference.default,
// Behavior
Expand Down Expand Up @@ -94,6 +115,13 @@ fun SettingsProvider(
LocalTextFieldStyle provides settings.textFieldStyle,
LocalDateStyle provides settings.dateStyle,
LocalNavigationBarLabel provides settings.navigationBarLabel,
LocalFeedListTonalElevation provides settings.feedListTonalElevation,
LocalFeedTopBarTonalElevation provides settings.feedTopBarTonalElevation,
LocalArticleListTonalElevation provides settings.articleListTonalElevation,
LocalArticleTopBarTonalElevation provides settings.articleTopBarTonalElevation,
LocalArticleItemTonalElevation provides settings.articleItemTonalElevation,
LocalSearchListTonalElevation provides settings.searchListTonalElevation,
LocalSearchTopBarTonalElevation provides settings.searchTopBarTonalElevation,
// 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.article

import android.content.Context
import androidx.datastore.preferences.core.Preferences
import androidx.datastore.preferences.core.floatPreferencesKey
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 ArticleItemTonalElevationPreference : BasePreference<Float> {
private const val ARTICLE_ITEM_TONAL_ELEVATION = "articleItemTonalElevation"
override val default = -2f

val key = floatPreferencesKey(ARTICLE_ITEM_TONAL_ELEVATION)

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

override fun fromPreferences(preferences: Preferences): Float = preferences[key] ?: default
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.skyd.anivu.model.preference.appearance.article

import android.content.Context
import androidx.datastore.preferences.core.Preferences
import androidx.datastore.preferences.core.floatPreferencesKey
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 ArticleListTonalElevationPreference : BasePreference<Float> {
private const val ARTICLE_LIST_TONAL_ELEVATION = "articleListTonalElevation"
override val default = 2f

val key = floatPreferencesKey(ARTICLE_LIST_TONAL_ELEVATION)

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

override fun fromPreferences(preferences: Preferences): Float = preferences[key] ?: default
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.skyd.anivu.model.preference.appearance.article

import android.content.Context
import androidx.datastore.preferences.core.Preferences
import androidx.datastore.preferences.core.floatPreferencesKey
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 ArticleTopBarTonalElevationPreference : BasePreference<Float> {
private const val ARTICLE_TOP_BAR_TONAL_ELEVATION = "articleTopBarTonalElevation"
override val default = 2f

val key = floatPreferencesKey(ARTICLE_TOP_BAR_TONAL_ELEVATION)

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

override fun fromPreferences(preferences: Preferences): Float = preferences[key] ?: default
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.skyd.anivu.model.preference.appearance.feed

import android.content.Context
import androidx.datastore.preferences.core.Preferences
import androidx.datastore.preferences.core.floatPreferencesKey
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 FeedListTonalElevationPreference : BasePreference<Float> {
private const val FEED_LIST_TONAL_ELEVATION = "feedListTonalElevation"
override val default = 0f

val key = floatPreferencesKey(FEED_LIST_TONAL_ELEVATION)

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

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

object TonalElevationPreferenceUtil {
fun toDisplay(value: Float): String {
return "%.2fdp".format(value)
}
}
Loading

0 comments on commit 7e0a2c2

Please sign in to comment.