Skip to content

Commit

Permalink
[feature] Support to configure whether to show video thumbnails
Browse files Browse the repository at this point in the history
  • Loading branch information
SkyD666 committed Aug 30, 2024
1 parent d9c99ba commit 0e35333
Show file tree
Hide file tree
Showing 12 changed files with 128 additions and 9 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 = 22
versionName = "2.1-alpha25"
versionName = "2.1-alpha26"

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.ShowArticleTopBarRefre
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.media.MediaShowThumbnailPreference
import com.skyd.anivu.model.preference.appearance.search.SearchItemMinWidthPreference
import com.skyd.anivu.model.preference.appearance.search.SearchListTonalElevationPreference
import com.skyd.anivu.model.preference.appearance.search.SearchTopBarTonalElevationPreference
Expand Down Expand Up @@ -73,6 +74,7 @@ fun Preferences.toSettings(): Settings {
showArticlePullRefresh = ShowArticlePullRefreshPreference.fromPreferences(this),
articleItemMinWidth = ArticleItemMinWidthPreference.fromPreferences(this),
searchItemMinWidth = SearchItemMinWidthPreference.fromPreferences(this),
mediaShowThumbnail = MediaShowThumbnailPreference.fromPreferences(this),

// Update
ignoreUpdateVersion = IgnoreUpdateVersionPreference.fromPreferences(this),
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.ShowArticleTopBarRefre
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.media.MediaShowThumbnailPreference
import com.skyd.anivu.model.preference.appearance.search.SearchItemMinWidthPreference
import com.skyd.anivu.model.preference.appearance.search.SearchListTonalElevationPreference
import com.skyd.anivu.model.preference.appearance.search.SearchTopBarTonalElevationPreference
Expand Down Expand Up @@ -76,6 +77,7 @@ import com.skyd.anivu.ui.local.LocalHardwareDecode
import com.skyd.anivu.ui.local.LocalHideEmptyDefault
import com.skyd.anivu.ui.local.LocalIgnoreUpdateVersion
import com.skyd.anivu.ui.local.LocalMediaLibLocation
import com.skyd.anivu.ui.local.LocalMediaShowThumbnail
import com.skyd.anivu.ui.local.LocalNavigationBarLabel
import com.skyd.anivu.ui.local.LocalOpmlExportDir
import com.skyd.anivu.ui.local.LocalParseLinkTagAsEnclosure
Expand Down Expand Up @@ -129,6 +131,7 @@ data class Settings(
val showArticlePullRefresh: Boolean = ShowArticlePullRefreshPreference.default,
val articleItemMinWidth: Float = ArticleItemMinWidthPreference.default,
val searchItemMinWidth: Float = SearchItemMinWidthPreference.default,
val mediaShowThumbnail: Boolean = MediaShowThumbnailPreference.default,
// Update
val ignoreUpdateVersion: Long = IgnoreUpdateVersionPreference.default,
// Behavior
Expand Down Expand Up @@ -197,6 +200,7 @@ fun SettingsProvider(
LocalShowArticlePullRefresh provides settings.showArticlePullRefresh,
LocalArticleItemMinWidth provides settings.articleItemMinWidth,
LocalSearchItemMinWidth provides settings.searchItemMinWidth,
LocalMediaShowThumbnail provides settings.mediaShowThumbnail,
// 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.media

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 MediaShowThumbnailPreference : BasePreference<Boolean> {
private const val MEDIA_SHOW_THUMBNAIL = "mediaShowThumbnail"
override val default = true

val key = booleanPreferencesKey(MEDIA_SHOW_THUMBNAIL)

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
}
3 changes: 3 additions & 0 deletions app/src/main/java/com/skyd/anivu/ui/activity/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ import com.skyd.anivu.ui.screen.settings.appearance.article.ARTICLE_STYLE_SCREEN
import com.skyd.anivu.ui.screen.settings.appearance.article.ArticleStyleScreen
import com.skyd.anivu.ui.screen.settings.appearance.feed.FEED_STYLE_SCREEN_ROUTE
import com.skyd.anivu.ui.screen.settings.appearance.feed.FeedStyleScreen
import com.skyd.anivu.ui.screen.settings.appearance.media.MEDIA_STYLE_SCREEN_ROUTE
import com.skyd.anivu.ui.screen.settings.appearance.media.MediaStyleScreen
import com.skyd.anivu.ui.screen.settings.appearance.search.SEARCH_STYLE_SCREEN_ROUTE
import com.skyd.anivu.ui.screen.settings.appearance.search.SearchStyleScreen
import com.skyd.anivu.ui.screen.settings.behavior.BEHAVIOR_SCREEN_ROUTE
Expand Down Expand Up @@ -234,6 +236,7 @@ private fun MainNavHost() {
composable(route = APPEARANCE_SCREEN_ROUTE) { AppearanceScreen() }
composable(route = ARTICLE_STYLE_SCREEN_ROUTE) { ArticleStyleScreen() }
composable(route = FEED_STYLE_SCREEN_ROUTE) { FeedStyleScreen() }
composable(route = MEDIA_STYLE_SCREEN_ROUTE) { MediaStyleScreen() }
composable(route = REORDER_GROUP_SCREEN_ROUTE) { ReorderGroupScreen() }
composable(route = SEARCH_STYLE_SCREEN_ROUTE) { SearchStyleScreen() }
composable(route = BEHAVIOR_SCREEN_ROUTE) { BehaviorScreen() }
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/java/com/skyd/anivu/ui/local/LocalValue.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import com.skyd.anivu.model.preference.appearance.article.ShowArticleTopBarRefre
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.media.MediaShowThumbnailPreference
import com.skyd.anivu.model.preference.appearance.search.SearchItemMinWidthPreference
import com.skyd.anivu.model.preference.appearance.search.SearchListTonalElevationPreference
import com.skyd.anivu.model.preference.appearance.search.SearchTopBarTonalElevationPreference
Expand Down Expand Up @@ -87,6 +88,7 @@ val LocalShowArticleTopBarRefresh =
val LocalShowArticlePullRefresh = compositionLocalOf { ShowArticlePullRefreshPreference.default }
val LocalArticleItemMinWidth = compositionLocalOf { ArticleItemMinWidthPreference.default }
val LocalSearchItemMinWidth = compositionLocalOf { SearchItemMinWidthPreference.default }
val LocalMediaShowThumbnail = compositionLocalOf { MediaShowThumbnailPreference.default }

// Update
val LocalIgnoreUpdateVersion = compositionLocalOf { IgnoreUpdateVersionPreference.default }
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/skyd/anivu/ui/mpv/MPVView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ class MPVView(context: Context, attrs: AttributeSet?) : SurfaceView(context, att
// pseudo-track to allow disabling audio/subs
list.add(Track(-1, context.getString(R.string.track_off)))
}
val count = MPVLib.getPropertyInt("track-list/count")!!
val count = MPVLib.getPropertyInt("track-list/count") ?: 0
// Note that because events are async, properties might disappear at any moment
// so use ?: continue instead of !!
for (i in 0 until count) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,9 @@ import androidx.compose.ui.unit.TextUnitType
import androidx.compose.ui.unit.dp
import androidx.lifecycle.compose.LocalLifecycleOwner
import coil.EventListener
import coil.decode.VideoFrameDecoder
import coil.request.CachePolicy
import coil.request.ErrorResult
import coil.request.ImageRequest
import coil.request.videoFramePercent
import com.skyd.anivu.R
import com.skyd.anivu.ext.fileSize
import com.skyd.anivu.ext.openWith
Expand All @@ -54,6 +52,7 @@ import com.skyd.anivu.ext.toUri
import com.skyd.anivu.model.bean.VideoBean
import com.skyd.anivu.ui.component.AniVuImage
import com.skyd.anivu.ui.component.rememberAniVuImageLoader
import com.skyd.anivu.ui.local.LocalMediaShowThumbnail
import java.util.Locale

@Composable
Expand Down Expand Up @@ -116,7 +115,7 @@ fun Media1Item(
contentDescription = null
)
}
if (data.isMedia) {
if (data.isMedia && LocalMediaShowThumbnail.current) {
if (showThumbnail) {
val lifecycleOwner = LocalLifecycleOwner.current
AniVuImage(
Expand All @@ -127,7 +126,6 @@ fun Media1Item(
.diskCachePolicy(CachePolicy.ENABLED)
.memoryCachePolicy(CachePolicy.ENABLED)
.data(data.file.path)
.videoFramePercent(0.5)
.crossfade(true)
.build()
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,16 @@ import com.skyd.anivu.ui.component.BaseSettingsItem
import com.skyd.anivu.ui.component.CategorySettingsItem
import com.skyd.anivu.ui.component.CheckableListMenu
import com.skyd.anivu.ui.component.SwitchSettingsItem
import com.skyd.anivu.ui.screen.settings.appearance.article.ARTICLE_STYLE_SCREEN_ROUTE
import com.skyd.anivu.ui.screen.settings.appearance.feed.FEED_STYLE_SCREEN_ROUTE
import com.skyd.anivu.ui.screen.settings.appearance.search.SEARCH_STYLE_SCREEN_ROUTE
import com.skyd.anivu.ui.local.LocalDarkMode
import com.skyd.anivu.ui.local.LocalDateStyle
import com.skyd.anivu.ui.local.LocalNavController
import com.skyd.anivu.ui.local.LocalNavigationBarLabel
import com.skyd.anivu.ui.local.LocalTextFieldStyle
import com.skyd.anivu.ui.local.LocalTheme
import com.skyd.anivu.ui.screen.settings.appearance.article.ARTICLE_STYLE_SCREEN_ROUTE
import com.skyd.anivu.ui.screen.settings.appearance.feed.FEED_STYLE_SCREEN_ROUTE
import com.skyd.anivu.ui.screen.settings.appearance.media.MEDIA_STYLE_SCREEN_ROUTE
import com.skyd.anivu.ui.screen.settings.appearance.search.SEARCH_STYLE_SCREEN_ROUTE
import com.skyd.anivu.ui.theme.extractColors


Expand Down Expand Up @@ -233,6 +234,14 @@ fun AppearanceScreen() {
onClick = { navController.navigate(SEARCH_STYLE_SCREEN_ROUTE) },
)
}
item {
BaseSettingsItem(
icon = null,
text = stringResource(id = R.string.media_style_screen_name),
description = null,
onClick = { navController.navigate(MEDIA_STYLE_SCREEN_ROUTE) },
)
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package com.skyd.anivu.ui.screen.settings.appearance.media

import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.outlined.HideImage
import androidx.compose.material.icons.outlined.Image
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.runtime.Composable
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Modifier
import androidx.compose.ui.input.nestedscroll.nestedScroll
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import com.skyd.anivu.R
import com.skyd.anivu.model.preference.appearance.media.MediaShowThumbnailPreference
import com.skyd.anivu.ui.component.AniVuTopBar
import com.skyd.anivu.ui.component.AniVuTopBarStyle
import com.skyd.anivu.ui.component.CategorySettingsItem
import com.skyd.anivu.ui.component.SwitchSettingsItem
import com.skyd.anivu.ui.local.LocalMediaShowThumbnail


const val MEDIA_STYLE_SCREEN_ROUTE = "mediaStyleScreen"

@Composable
fun MediaStyleScreen() {
val scrollBehavior = TopAppBarDefaults.exitUntilCollapsedScrollBehavior()
val context = LocalContext.current
val scope = rememberCoroutineScope()

Scaffold(
topBar = {
AniVuTopBar(
style = AniVuTopBarStyle.Large,
scrollBehavior = scrollBehavior,
title = { Text(text = stringResource(R.string.media_style_screen_name)) },
)
}
) { paddingValues ->
LazyColumn(
modifier = Modifier
.fillMaxSize()
.nestedScroll(scrollBehavior.nestedScrollConnection),
contentPadding = paddingValues,
) {
item {
CategorySettingsItem(text = stringResource(id = R.string.media_style_screen_media_list_category))
}
item {
val mediaShowThumbnail = LocalMediaShowThumbnail.current
SwitchSettingsItem(
imageVector = if (mediaShowThumbnail) Icons.Outlined.Image else Icons.Outlined.HideImage,
text = stringResource(id = R.string.media_style_screen_media_list_show_thumbnail),
checked = mediaShowThumbnail,
onCheckedChange = {
MediaShowThumbnailPreference.put(
context = context,
scope = scope,
value = it,
)
}
)
}
}
}
}
3 changes: 3 additions & 0 deletions app/src/main/res/values-zh-rCN/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,9 @@
<string name="data_screen_clear_play_history_warning">确定删除播放历史?</string>
<string name="data_screen_clear_play_history_success">已删除 %d 项</string>
<string name="folder">文件夹</string>
<string name="media_style_screen_name">媒体页面</string>
<string name="media_style_screen_media_list_category">媒体列表</string>
<string name="media_style_screen_media_list_show_thumbnail">显示预览图</string>
<plurals name="feed_screen_read_all_result">
<item quantity="other">已读 %d 项</item>
</plurals>
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,9 @@
<string name="data_screen_clear_play_history_warning">Sure to delete playback history?</string>
<string name="data_screen_clear_play_history_success">Deleted %d items</string>
<string name="folder">Folder</string>
<string name="media_style_screen_name">Media screen</string>
<string name="media_style_screen_media_list_category">Media list</string>
<string name="media_style_screen_media_list_show_thumbnail">Show thumbnails</string>
<plurals name="feed_screen_read_all_result">
<item quantity="one">Read %d item</item>
<item quantity="other">Read %d items</item>
Expand Down

0 comments on commit 0e35333

Please sign in to comment.