diff --git a/app/src/main/java/com/huanchengfly/tieba/post/ui/page/forum/threadlist/ForumThreadListViewModel.kt b/app/src/main/java/com/huanchengfly/tieba/post/ui/page/forum/threadlist/ForumThreadListViewModel.kt index b9dbe4c9..3fcad583 100644 --- a/app/src/main/java/com/huanchengfly/tieba/post/ui/page/forum/threadlist/ForumThreadListViewModel.kt +++ b/app/src/main/java/com/huanchengfly/tieba/post/ui/page/forum/threadlist/ForumThreadListViewModel.kt @@ -1,6 +1,7 @@ package com.huanchengfly.tieba.post.ui.page.forum.threadlist import androidx.compose.runtime.Stable +import com.huanchengfly.tieba.post.App import com.huanchengfly.tieba.post.api.TiebaApi import com.huanchengfly.tieba.post.api.models.AgreeBean import com.huanchengfly.tieba.post.api.models.protos.ThreadInfo @@ -18,6 +19,7 @@ import com.huanchengfly.tieba.post.arch.UiIntent import com.huanchengfly.tieba.post.arch.UiState import com.huanchengfly.tieba.post.arch.wrapImmutable import com.huanchengfly.tieba.post.repository.FrsPageRepository +import com.huanchengfly.tieba.post.utils.appPreferences import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.FlowPreview import kotlinx.coroutines.flow.Flow @@ -102,7 +104,7 @@ private class ForumThreadListPartialChangeProducer(val type: ForumThreadListType val userList = response.data_.user_list val threadList = response.data_.thread_list.map { threadInfo -> threadInfo.copy(author = userList.find { it.id == threadInfo.authorId }) - } + }.filter { !App.INSTANCE.appPreferences.blockVideo || it.videoInfo == null } ForumThreadListPartialChange.FirstLoad.Success( threadList.wrapImmutable(), response.data_.thread_id_list, diff --git a/app/src/main/java/com/huanchengfly/tieba/post/ui/page/main/explore/personalized/PersonalizedPage.kt b/app/src/main/java/com/huanchengfly/tieba/post/ui/page/main/explore/personalized/PersonalizedPage.kt index fa20882c..2e7dcaec 100644 --- a/app/src/main/java/com/huanchengfly/tieba/post/ui/page/main/explore/personalized/PersonalizedPage.kt +++ b/app/src/main/java/com/huanchengfly/tieba/post/ui/page/main/explore/personalized/PersonalizedPage.kt @@ -226,7 +226,7 @@ fun PersonalizedPage( @Composable private fun FeedList( dataProvider: () -> List>, - personalizedDataProvider: () -> List>, + personalizedDataProvider: () -> List?>, refreshPositionProvider: () -> Int, hiddenThreadIdsProvider: () -> List, onItemClick: (ThreadInfo) -> Unit, @@ -278,7 +278,7 @@ private fun FeedList( if (personalized != null) { Dislike( - personalized = threadPersonalizedData[index], + personalized = personalized, onDislike = { clickTime, reasons -> onDislike(item.get(), clickTime, reasons) } diff --git a/app/src/main/java/com/huanchengfly/tieba/post/ui/page/main/explore/personalized/PersonalizedViewModel.kt b/app/src/main/java/com/huanchengfly/tieba/post/ui/page/main/explore/personalized/PersonalizedViewModel.kt index 1dddcae6..ab69549b 100644 --- a/app/src/main/java/com/huanchengfly/tieba/post/ui/page/main/explore/personalized/PersonalizedViewModel.kt +++ b/app/src/main/java/com/huanchengfly/tieba/post/ui/page/main/explore/personalized/PersonalizedViewModel.kt @@ -1,6 +1,7 @@ package com.huanchengfly.tieba.post.ui.page.main.explore.personalized import androidx.compose.runtime.Stable +import com.huanchengfly.tieba.post.App import com.huanchengfly.tieba.post.api.TiebaApi import com.huanchengfly.tieba.post.api.models.AgreeBean import com.huanchengfly.tieba.post.api.models.CommonResponse @@ -19,6 +20,7 @@ import com.huanchengfly.tieba.post.arch.UiIntent import com.huanchengfly.tieba.post.arch.UiState import com.huanchengfly.tieba.post.arch.wrapImmutable import com.huanchengfly.tieba.post.models.DislikeBean +import com.huanchengfly.tieba.post.utils.appPreferences import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.FlowPreview import kotlinx.coroutines.flow.Flow @@ -28,6 +30,7 @@ import kotlinx.coroutines.flow.flatMapConcat import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.merge import kotlinx.coroutines.flow.onStart +import okhttp3.internal.toImmutableList import javax.inject.Inject @Stable @@ -62,11 +65,17 @@ class PersonalizedViewModel @Inject constructor() : private fun produceRefreshPartialChange(): Flow = TiebaApi.getInstance().personalizedProtoFlow(1, 1) - .map { + .map { response -> + val data = response.toData().filter { + !App.INSTANCE.appPreferences.blockVideo || it.get { videoInfo } == null + } + val threadPersonalizedData = data.map { thread -> + response.data_?.thread_personalized?.firstOrNull { thread.get { id } == it.tid } + ?.wrapImmutable() + } PersonalizedPartialChange.Refresh.Success( - data = it.toData(), - threadPersonalizedData = (it.data_?.thread_personalized - ?: emptyList()).wrapImmutable(), + data = data, + threadPersonalizedData = threadPersonalizedData.toImmutableList(), ) } .onStart { emit(PersonalizedPartialChange.Refresh.Start) } @@ -74,12 +83,18 @@ class PersonalizedViewModel @Inject constructor() : private fun PersonalizedUiIntent.LoadMore.producePartialChange(): Flow = TiebaApi.getInstance().personalizedProtoFlow(2, page) - .map { + .map { response -> + val data = response.toData().filter { + !App.INSTANCE.appPreferences.blockVideo || it.get { videoInfo } == null + } + val threadPersonalizedData = data.map { thread -> + response.data_?.thread_personalized?.firstOrNull { thread.get { id } == it.tid } + ?.wrapImmutable() + } PersonalizedPartialChange.LoadMore.Success( currentPage = page, - data = it.toData(), - threadPersonalizedData = (it.data_?.thread_personalized - ?: emptyList()).wrapImmutable(), + data = data, + threadPersonalizedData = threadPersonalizedData.toImmutableList(), ) } .onStart { emit(PersonalizedPartialChange.LoadMore.Start) } @@ -261,7 +276,7 @@ sealed interface PersonalizedPartialChange : PartialChange data class Success( val data: List>, - val threadPersonalizedData: List>, + val threadPersonalizedData: List?>, ) : Refresh() data class Failure( @@ -287,7 +302,7 @@ sealed interface PersonalizedPartialChange : PartialChange data class Success( val currentPage: Int, val data: List>, - val threadPersonalizedData: List>, + val threadPersonalizedData: List?>, ) : LoadMore() data class Failure( @@ -302,7 +317,7 @@ data class PersonalizedUiState( val isLoadingMore: Boolean = false, val currentPage: Int = 1, val data: List> = emptyList(), - val threadPersonalizedData: List> = emptyList(), + val threadPersonalizedData: List?> = emptyList(), val hiddenThreadIds: List = emptyList(), val refreshPosition: Int = 0, ): UiState diff --git a/app/src/main/java/com/huanchengfly/tieba/post/ui/page/settings/habit/HabitSettingsPage.kt b/app/src/main/java/com/huanchengfly/tieba/post/ui/page/settings/habit/HabitSettingsPage.kt index 9ad1a41d..0ba43d04 100644 --- a/app/src/main/java/com/huanchengfly/tieba/post/ui/page/settings/habit/HabitSettingsPage.kt +++ b/app/src/main/java/com/huanchengfly/tieba/post/ui/page/settings/habit/HabitSettingsPage.kt @@ -4,7 +4,14 @@ import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.padding import androidx.compose.material.ExperimentalMaterialApi import androidx.compose.material.icons.Icons -import androidx.compose.material.icons.outlined.* +import androidx.compose.material.icons.outlined.CalendarViewDay +import androidx.compose.material.icons.outlined.ExitToApp +import androidx.compose.material.icons.outlined.Extension +import androidx.compose.material.icons.outlined.PhotoSizeSelectActual +import androidx.compose.material.icons.outlined.SecurityUpdateWarning +import androidx.compose.material.icons.outlined.StarOutline +import androidx.compose.material.icons.outlined.Verified +import androidx.compose.material.icons.rounded.VideocamOff import androidx.compose.runtime.Composable import androidx.compose.ui.ExperimentalComposeUiApi import androidx.compose.ui.Modifier @@ -23,7 +30,11 @@ import com.huanchengfly.tieba.post.ui.common.prefs.widgets.ListPref import com.huanchengfly.tieba.post.ui.common.prefs.widgets.SwitchPref import com.huanchengfly.tieba.post.ui.common.prefs.widgets.TextPref import com.huanchengfly.tieba.post.ui.page.settings.LeadingIcon -import com.huanchengfly.tieba.post.ui.widgets.compose.* +import com.huanchengfly.tieba.post.ui.widgets.compose.AvatarIcon +import com.huanchengfly.tieba.post.ui.widgets.compose.BackNavigationIcon +import com.huanchengfly.tieba.post.ui.widgets.compose.MyScaffold +import com.huanchengfly.tieba.post.ui.widgets.compose.Sizes +import com.huanchengfly.tieba.post.ui.widgets.compose.TitleCentredToolbar import com.ramcosta.composedestinations.annotation.Destination import com.ramcosta.composedestinations.navigation.DestinationsNavigator @@ -92,6 +103,22 @@ fun HabitSettingsPage( }, ) } + prefsItem { + SwitchPref( + key = "blockVideo", + title = stringResource(id = R.string.settings_block_video), + defaultChecked = false, + leadingIcon = { + LeadingIcon { + AvatarIcon( + icon = Icons.Rounded.VideocamOff, + size = Sizes.Small, + contentDescription = null, + ) + } + } + ) + } prefsItem { ListPref( key = "default_sort_type", diff --git a/app/src/main/java/com/huanchengfly/tieba/post/utils/AppPreferencesUtils.kt b/app/src/main/java/com/huanchengfly/tieba/post/utils/AppPreferencesUtils.kt index a6135b6e..d157290b 100644 --- a/app/src/main/java/com/huanchengfly/tieba/post/utils/AppPreferencesUtils.kt +++ b/app/src/main/java/com/huanchengfly/tieba/post/utils/AppPreferencesUtils.kt @@ -47,6 +47,8 @@ open class AppPreferencesUtils(private val context: Context) { key = "auto_sign_time" ) + var blockVideo by DataStoreDelegates.boolean(defaultValue = false) + var checkCIUpdate by DataStoreDelegates.boolean( defaultValue = false ) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index c260d9e5..7c8d84f7 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -674,4 +674,5 @@ 查看全部 %d 条回复 贴子更新到了第 %d 楼 由于你的屏蔽设置,第 %d 楼已被屏蔽 + 屏蔽视频贴子