Skip to content

Commit

Permalink
[feature|optimize] Support hide empty Default feed group; relative ti…
Browse files Browse the repository at this point in the history
…me to "3 weeks ago"
  • Loading branch information
SkyD666 committed Apr 28, 2024
1 parent 9fb0b11 commit 72ce2e4
Show file tree
Hide file tree
Showing 15 changed files with 124 additions and 35 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ android {
minSdk = 24
targetSdk = 34
versionCode = 16
versionName = "1.1-beta17"
versionName = "1.1-beta18"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"

Expand Down
1 change: 1 addition & 0 deletions app/src/main/java/com/skyd/anivu/config/Const.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ object Const {
const val NIGHT_SCREEN_URL = "https://github.com/SkyD666/NightScreen"

const val BASE_URL = "https://github.com/SkyD666/"
const val FAVICON_FETCH_URL = "https://besticon-demo.herokuapp.com/allicons.json"

val TEMP_TORRENT_DIR = File(appContext.cacheDir.path, "Torrent").apply {
if (!exists()) mkdirs()
Expand Down
11 changes: 10 additions & 1 deletion app/src/main/java/com/skyd/anivu/ext/DateExt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,16 @@ fun Date.toDateTimeString(
locale: Locale = Locale.getDefault()
): String {
return if (context.dataStore.getOrDefault(DateStylePreference) == DateStylePreference.RELATIVE) {
DateUtils.getRelativeTimeSpanString(this.time, System.currentTimeMillis(), 0).toString()
val current = System.currentTimeMillis()
val delta = current - this.time
DateUtils.getRelativeTimeSpanString(
this.time,
current,
// "DateUtils.WEEK_IN_MILLIS <= .. <= DateUtils.WEEK_IN_MILLIS * 4" is 1~3 weeks ago
if (delta in DateUtils.WEEK_IN_MILLIS..DateUtils.WEEK_IN_MILLIS * 4) {
DateUtils.WEEK_IN_MILLIS
} else 0
).toString()
} else {
SimpleDateFormat
.getDateTimeInstance(dateStyle, timeStyle, locale)
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 @@ -11,6 +11,7 @@ import com.skyd.anivu.model.preference.appearance.feed.FeedGroupExpandPreference
import com.skyd.anivu.model.preference.behavior.article.ArticleSwipeLeftActionPreference
import com.skyd.anivu.model.preference.behavior.article.ArticleTapActionPreference
import com.skyd.anivu.model.preference.behavior.article.DeduplicateTitleInDescPreference
import com.skyd.anivu.model.preference.behavior.feed.HideEmptyDefaultPreference

fun Preferences.toSettings(): Settings {
return Settings(
Expand All @@ -28,5 +29,6 @@ fun Preferences.toSettings(): Settings {
deduplicateTitleInDesc = DeduplicateTitleInDescPreference.fromPreferences(this),
articleTapAction = ArticleTapActionPreference.fromPreferences(this),
articleSwipeLeftAction = ArticleSwipeLeftActionPreference.fromPreferences(this),
hideEmptyDefault = HideEmptyDefaultPreference.fromPreferences(this),
)
}
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 @@ -16,12 +16,14 @@ import com.skyd.anivu.model.preference.appearance.feed.FeedGroupExpandPreference
import com.skyd.anivu.model.preference.behavior.article.ArticleSwipeLeftActionPreference
import com.skyd.anivu.model.preference.behavior.article.ArticleTapActionPreference
import com.skyd.anivu.model.preference.behavior.article.DeduplicateTitleInDescPreference
import com.skyd.anivu.model.preference.behavior.feed.HideEmptyDefaultPreference
import com.skyd.anivu.ui.local.LocalArticleSwipeLeftAction
import com.skyd.anivu.ui.local.LocalArticleTapAction
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.LocalHideEmptyDefault
import com.skyd.anivu.ui.local.LocalIgnoreUpdateVersion
import com.skyd.anivu.ui.local.LocalTextFieldStyle
import com.skyd.anivu.ui.local.LocalTheme
Expand All @@ -41,6 +43,7 @@ data class Settings(
val deduplicateTitleInDesc: Boolean = DeduplicateTitleInDescPreference.default,
val articleTapAction: String = ArticleTapActionPreference.default,
val articleSwipeLeftAction: String = ArticleSwipeLeftActionPreference.default,
val hideEmptyDefault: Boolean = HideEmptyDefaultPreference.default,
)

@Composable
Expand All @@ -64,6 +67,7 @@ fun SettingsProvider(
LocalDeduplicateTitleInDesc provides settings.deduplicateTitleInDesc,
LocalArticleTapAction provides settings.articleTapAction,
LocalArticleSwipeLeftAction provides settings.articleSwipeLeftAction,
LocalHideEmptyDefault provides settings.hideEmptyDefault,
) {
content()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.skyd.anivu.model.preference.behavior.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 HideEmptyDefaultPreference : BasePreference<Boolean> {
private const val HIDE_EMPTY_DEFAULT = "hideEmptyDefault"
override val default = true

val key = booleanPreferencesKey(HIDE_EMPTY_DEFAULT)

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
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.skyd.anivu.model.repository

import android.util.Log
import androidx.compose.ui.util.fastMaxBy
import com.rometools.rome.feed.synd.SyndEntry
import com.rometools.rome.io.SyndFeedInput
import com.rometools.rome.io.XmlReader
Expand Down Expand Up @@ -114,7 +115,7 @@ class RssHelper @Inject constructor(
return runCatching {
retrofit.create(HttpService::class.java)
.requestFavicon(url)
.icons?.firstOrNull { it.width != null && it.width >= 20 }?.url
.icons?.fastMaxBy { it.width ?: 0 }?.url
}.onFailure { it.printStackTrace() }.getOrNull()
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.skyd.anivu.model.service

import com.skyd.anivu.config.Const
import com.skyd.anivu.model.bean.FaviconBean
import okhttp3.ResponseBody
import retrofit2.Call
Expand All @@ -11,6 +12,6 @@ interface HttpService {
@GET
fun requestGetResponseBody(@Url url: String): Call<ResponseBody>

@GET("https://besticon-demo.herokuapp.com/allicons.json")
@GET(Const.FAVICON_FETCH_URL)
suspend fun requestFavicon(@Query("url") url: String): FaviconBean
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,19 @@ import com.skyd.anivu.ui.component.lazyverticalgrid.adapter.LazyGridAdapter

class DefaultGroup1Proxy(
private val group1Proxy: Group1Proxy,
private val hide: (index: Int) -> Boolean,
) : LazyGridAdapter.Proxy<GroupBean.DefaultGroup>() {
@Composable
override fun Draw(index: Int, data: GroupBean.DefaultGroup) {
Group1Item(
data = data,
initExpand = group1Proxy.isExpand,
onExpandChange = group1Proxy.onExpandChange,
onShowAllArticles = group1Proxy.onShowAllArticles,
onDelete = group1Proxy.onDelete,
onFeedsMoveTo = group1Proxy.onMoveFeedsTo,
)
if (!hide(index)) {
Group1Item(
data = data,
initExpand = group1Proxy.isExpand,
onExpandChange = group1Proxy.onExpandChange,
onShowAllArticles = group1Proxy.onShowAllArticles,
onDelete = group1Proxy.onDelete,
onFeedsMoveTo = group1Proxy.onMoveFeedsTo,
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@ fun Feed1Item(
.padding(horizontal = 16.dp, vertical = 12.dp)
) {
Row(verticalAlignment = Alignment.CenterVertically) {
FeedIcon(modifier = Modifier.padding(3.dp), data = feed, size = 23.dp)
FeedIcon(modifier = Modifier.padding(3.dp), data = feed, size = 24.dp)
val title = rememberSaveable(feed.title, feed.nickname) {
feed.nickname.orEmpty().ifBlank { feed.title?.readable().orEmpty() }
}
Spacer(modifier = Modifier.width(10.dp))
Spacer(modifier = Modifier.width(8.dp))
Text(
modifier = Modifier.weight(1f),
text = title,
Expand Down
37 changes: 23 additions & 14 deletions app/src/main/java/com/skyd/anivu/ui/fragment/feed/FeedScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ import com.skyd.anivu.ui.component.lazyverticalgrid.adapter.proxy.Group1Proxy
import com.skyd.anivu.ui.fragment.article.ArticleFragment
import com.skyd.anivu.ui.fragment.search.SearchFragment
import com.skyd.anivu.ui.local.LocalFeedGroupExpand
import com.skyd.anivu.ui.local.LocalHideEmptyDefault
import com.skyd.anivu.ui.local.LocalNavController
import com.skyd.anivu.ui.local.LocalTextFieldStyle
import com.skyd.anivu.ui.local.LocalWindowSizeClass
Expand Down Expand Up @@ -200,19 +201,19 @@ fun FeedScreen(viewModel: FeedViewModel = hiltViewModel()) {
contentPadding = innerPadding + PaddingValues(bottom = fabHeight + 16.dp),
onRemoveFeed = { feed -> dispatch(FeedIntent.RemoveFeed(feed.url)) },
onShowAllArticles = { group ->
navController.navigate(R.id.action_to_article_fragment, Bundle().apply {
putStringArrayList(
ArticleFragment.FEED_URLS_KEY,
ArrayList(
(uiState.groupListState as? GroupListState.Success)
?.dataList
?.filterIsInstance(FeedViewBean::class.java)
?.filter { it.feed.groupId == group.groupId || group.isDefaultGroup() && it.feed.isDefaultGroup() }
?.map { it.feed.url }
.orEmpty()
val feedUrls = (uiState.groupListState as? GroupListState.Success)
?.dataList
?.filterIsInstance(FeedViewBean::class.java)
?.filter { it.feed.groupId == group.groupId || group.isDefaultGroup() && it.feed.isDefaultGroup() }
?.map { it.feed.url }
.orEmpty()
if (feedUrls.isNotEmpty()) {
navController.navigate(R.id.action_to_article_fragment, Bundle().apply {
putStringArrayList(
ArticleFragment.FEED_URLS_KEY, ArrayList(feedUrls)
)
)
})
})
}
},
onEditFeed = { feed ->
openEditDialog = feed
Expand Down Expand Up @@ -524,6 +525,7 @@ private fun FeedList(
onMoveToGroup: (from: GroupBean, to: GroupBean) -> Unit,
openCreateGroupDialog: () -> Unit,
) {
val hideEmptyDefault = LocalHideEmptyDefault.current
val feedGroupExpand = LocalFeedGroupExpand.current
val groups = rememberSaveable(result) { result.filterIsInstance<GroupBean>() }
val feedVisible = rememberSaveable(saver = snapshotStateMapSaver()) {
Expand All @@ -549,7 +551,11 @@ private fun FeedList(
}
var openSelectGroupDialog by rememberSaveable { mutableStateOf<GroupBean?>(null) }
var selectGroupDialogCurrentGroup by rememberSaveable { mutableStateOf<GroupBean?>(null) }
val adapter = remember {

val shouldHideEmptyDefault: (index: Int) -> Boolean = remember(hideEmptyDefault, result) {
{ hideEmptyDefault && result.getOrNull(it + 1) !is FeedViewBean }
}
val adapter = remember(shouldHideEmptyDefault) {
val group1Proxy = Group1Proxy(
isExpand = { feedVisible[it.groupId] ?: false },
onExpandChange = { data, expand -> feedVisible[data.groupId] = expand },
Expand All @@ -562,7 +568,10 @@ private fun FeedList(
)
LazyGridAdapter(
mutableListOf(
DefaultGroup1Proxy(group1Proxy),
DefaultGroup1Proxy(
group1Proxy = group1Proxy,
hide = shouldHideEmptyDefault,
),
group1Proxy,
Feed1Proxy(
visible = { feedVisible[it] ?: false },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.outlined.Article
import androidx.compose.material.icons.outlined.Done
import androidx.compose.material.icons.outlined.SwipeLeft
import androidx.compose.material.icons.outlined.VisibilityOff
import androidx.compose.material3.DropdownMenu
import androidx.compose.material3.DropdownMenuItem
import androidx.compose.material3.Icon
Expand All @@ -33,6 +34,7 @@ import com.skyd.anivu.base.BaseComposeFragment
import com.skyd.anivu.model.preference.behavior.article.ArticleSwipeLeftActionPreference
import com.skyd.anivu.model.preference.behavior.article.ArticleTapActionPreference
import com.skyd.anivu.model.preference.behavior.article.DeduplicateTitleInDescPreference
import com.skyd.anivu.model.preference.behavior.feed.HideEmptyDefaultPreference
import com.skyd.anivu.ui.component.AniVuTopBar
import com.skyd.anivu.ui.component.AniVuTopBarStyle
import com.skyd.anivu.ui.component.BaseSettingsItem
Expand All @@ -41,6 +43,7 @@ import com.skyd.anivu.ui.component.SwitchSettingsItem
import com.skyd.anivu.ui.local.LocalArticleSwipeLeftAction
import com.skyd.anivu.ui.local.LocalArticleTapAction
import com.skyd.anivu.ui.local.LocalDeduplicateTitleInDesc
import com.skyd.anivu.ui.local.LocalHideEmptyDefault
import dagger.hilt.android.AndroidEntryPoint


Expand Down Expand Up @@ -76,6 +79,24 @@ fun BehaviorScreen() {
.nestedScroll(scrollBehavior.nestedScrollConnection),
contentPadding = paddingValues,
) {
item {
CategorySettingsItem(text = stringResource(id = R.string.behavior_screen_feed_screen_category))
}
item {
SwitchSettingsItem(
imageVector = Icons.Outlined.VisibilityOff,
text = stringResource(id = R.string.behavior_screen_feed_screen_hide_empty_default),
description = stringResource(id = R.string.behavior_screen_feed_screen_hide_empty_default_description),
checked = LocalHideEmptyDefault.current,
onCheckedChange = {
HideEmptyDefaultPreference.put(
context = context,
scope = scope,
value = it,
)
}
)
}
item {
CategorySettingsItem(text = stringResource(id = R.string.behavior_screen_article_screen_category))
}
Expand Down
4 changes: 3 additions & 1 deletion app/src/main/java/com/skyd/anivu/ui/local/LocalValue.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import com.skyd.anivu.model.preference.appearance.feed.FeedGroupExpandPreference
import com.skyd.anivu.model.preference.behavior.article.ArticleSwipeLeftActionPreference
import com.skyd.anivu.model.preference.behavior.article.ArticleTapActionPreference
import com.skyd.anivu.model.preference.behavior.article.DeduplicateTitleInDescPreference
import com.skyd.anivu.model.preference.behavior.feed.HideEmptyDefaultPreference

val LocalNavController = compositionLocalOf<NavHostController> {
error("LocalNavController not initialized!")
Expand All @@ -34,4 +35,5 @@ val LocalIgnoreUpdateVersion = compositionLocalOf { IgnoreUpdateVersionPreferenc
// Behavior
val LocalDeduplicateTitleInDesc = compositionLocalOf { DeduplicateTitleInDescPreference.default }
val LocalArticleTapAction = compositionLocalOf { ArticleTapActionPreference.default }
val LocalArticleSwipeLeftAction = compositionLocalOf { ArticleSwipeLeftActionPreference.default }
val LocalArticleSwipeLeftAction = compositionLocalOf { ArticleSwipeLeftActionPreference.default }
val LocalHideEmptyDefault = compositionLocalOf { HideEmptyDefaultPreference.default }
13 changes: 10 additions & 3 deletions app/src/main/res/values-zh-rCN/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
<string name="data_fragment_clear_cache_warning">确定要删除这些缓存吗?</string>
<string name="clear">清除</string>
<string name="rss_config_fragment_name">RSS</string>
<string name="rss_config_fragment_description">配置 RSS </string>
<string name="rss_config_fragment_description">配置 RSS 同步、解析规则等</string>
<string name="rss_config_fragment_parse_link_tag_as_enclosure">解析 Link 为附件</string>
<string name="rss_config_fragment_parse_link_tag_as_enclosure_description">解析 Link 标签,若符合磁力链或 Torrent 格式,则显示为附件</string>
<string name="rss_config_fragment_parse_category">解析</string>
Expand Down Expand Up @@ -128,7 +128,7 @@
<string name="player_config_fragment_name">播放器</string>
<string name="player_config_fragment_behavior_category">行为</string>
<string name="player_config_fragment_double_tap">双击</string>
<string name="player_config_fragment_description">配置播放器行为等</string>
<string name="player_config_fragment_description">配置播放器行为、外观等</string>
<string name="player_config_fragment_double_tap_description">配置双击行为</string>
<string name="appearance_fragment_name">外观和样式</string>
<string name="appearance_fragment_theme_category">主题</string>
Expand Down Expand Up @@ -160,7 +160,7 @@
<string name="update_check_failed">检查更新失败:%s</string>
<string name="article_screen_read">详情</string>
<string name="behavior_screen_name">行为</string>
<string name="behavior_screen_description">配置对操作的响应行为</string>
<string name="behavior_screen_description">配置订阅、文章列表行为等</string>
<string name="behavior_screen_article_screen_category">文章列表</string>
<string name="behavior_screen_article_screen_deduplicate_title_in_desc">标题去重</string>
<string name="behavior_screen_article_screen_deduplicate_title_in_desc_description">删除描述文本中与标题相同的子字符串</string>
Expand Down Expand Up @@ -188,6 +188,13 @@
<string name="feed_screen_all_articles">所有文章</string>
<string name="download_fragment_add_download">新建下载</string>
<string name="download_fragment_add_download_hint">磁力链 / 种子链接</string>
<string name="download_fragment_unsupported_link">不支持的链接</string>
<string name="date_style_relative">相对日期</string>
<string name="date_style_full">完整日期</string>
<string name="appearance_fragment_date_style">日期样式</string>
<string name="behavior_screen_feed_screen_category">订阅列表</string>
<string name="behavior_screen_feed_screen_hide_empty_default">隐藏空默认分组</string>
<string name="behavior_screen_feed_screen_hide_empty_default_description">当默认分组为空时,隐藏它</string>
<plurals name="rss_sync_frequency_minute">
<item quantity="other">每 %d 分钟</item>
</plurals>
Expand Down
Loading

0 comments on commit 72ce2e4

Please sign in to comment.