Skip to content

Commit

Permalink
修改错误名称并补全偷懒没写的代码
Browse files Browse the repository at this point in the history
`DanmakuWebmark` -> `DanmakuMask`
  • Loading branch information
aaa1115910 committed Dec 22, 2024
1 parent d5120bc commit 58d9bfe
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,7 @@ data class VideoPlayerControllerData(
val currentDanmakuTransparency: DanmakuTransparency = DanmakuTransparency.T1,
val currentDanmakuOpacity: Float = 1f,
val currentDanmakuArea: Float = 1f,
val currentDanmakuMask: Boolean = false,
val currentSubtitleId: Long = 0,
val currentSubtitleData: List<SubtitleItem> = emptyList(),
val currentPosition: Long = 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ fun MenuController(
onDanmakuSizeChange: (Float) -> Unit,
onDanmakuOpacityChange: (Float) -> Unit,
onDanmakuAreaChange: (Float) -> Unit,
onDanmakuMaskChange: (Boolean) -> Unit = {},
onSubtitleChange: (Subtitle) -> Unit,
onSubtitleSizeChange: (TextUnit) -> Unit,
onSubtitleBackgroundOpacityChange: (Float) -> Unit,
Expand Down Expand Up @@ -111,6 +112,7 @@ fun MenuController(
onDanmakuSizeChange = onDanmakuSizeChange,
onDanmakuOpacityChange = onDanmakuOpacityChange,
onDanmakuAreaChange = onDanmakuAreaChange,
onDanmakuMaskChange = onDanmakuMaskChange,
onSubtitleChange = onSubtitleChange,
onSubtitleSizeChange = onSubtitleSizeChange,
onSubtitleBackgroundOpacityChange = onSubtitleBackgroundOpacityChange,
Expand All @@ -133,6 +135,7 @@ fun MenuController(
onDanmakuSizeChange: (Float) -> Unit,
onDanmakuOpacityChange: (Float) -> Unit,
onDanmakuAreaChange: (Float) -> Unit,
onDanmakuMaskChange: (Boolean) -> Unit = {},
onSubtitleChange: (Subtitle) -> Unit,
onSubtitleSizeChange: (TextUnit) -> Unit,
onSubtitleBackgroundOpacityChange: (Float) -> Unit,
Expand Down Expand Up @@ -168,6 +171,7 @@ fun MenuController(
onDanmakuSizeChange = onDanmakuSizeChange,
onDanmakuOpacityChange = onDanmakuOpacityChange,
onDanmakuAreaChange = onDanmakuAreaChange,
onDanmakuMaskChange = onDanmakuMaskChange,
onFocusStateChange = { focusState = it },
onSubtitleChange = onSubtitleChange,
onSubtitleSizeChange = onSubtitleSizeChange,
Expand Down Expand Up @@ -209,6 +213,7 @@ private fun MenuList(
onDanmakuSizeChange: (Float) -> Unit,
onDanmakuOpacityChange: (Float) -> Unit,
onDanmakuAreaChange: (Float) -> Unit,
onDanmakuMaskChange: (Boolean) -> Unit = {},
onSubtitleChange: (Subtitle) -> Unit,
onSubtitleSizeChange: (TextUnit) -> Unit,
onSubtitleBackgroundOpacityChange: (Float) -> Unit,
Expand Down Expand Up @@ -238,6 +243,7 @@ private fun MenuList(
onDanmakuOpacityChange = onDanmakuOpacityChange,
onDanmakuAreaChange = onDanmakuAreaChange,
onFocusStateChange = onFocusStateChange,
onDanmakuMaskChange = onDanmakuMaskChange
)
}

Expand Down Expand Up @@ -278,7 +284,7 @@ enum class VideoPlayerDanmakuMenuItem(private val strRes: Int) {
Size(R.string.video_player_menu_danmaku_size),
Opacity(R.string.video_player_menu_danmaku_opacity),
Area(R.string.video_player_menu_danmaku_area),
Webmark(R.string.video_player_menu_danmaku_webmark);
Mask(R.string.video_player_menu_danmaku_mask);

fun getDisplayName(context: Context) = context.getString(strRes)
}
Expand Down Expand Up @@ -317,6 +323,7 @@ fun MenuControllerPreview() {
var currentDanmakuSize by remember { mutableFloatStateOf(1f) }
var currentDanmakuOpacity by remember { mutableFloatStateOf(1f) }
var currentDanmakuArea by remember { mutableFloatStateOf(1f) }
var currentDanmakuMask by remember { mutableStateOf(false) }

var currentSubtitleId by remember { mutableLongStateOf(-1L) }
val currentSubtitleList = remember { mutableStateListOf<Subtitle>() }
Expand Down Expand Up @@ -398,6 +405,7 @@ fun MenuControllerPreview() {
currentDanmakuScale = currentDanmakuSize,
currentDanmakuOpacity = currentDanmakuOpacity,
currentDanmakuArea = currentDanmakuArea,
currentDanmakuMask = currentDanmakuMask,

currentSubtitleId = currentSubtitleId,
availableSubtitleTracks = currentSubtitleList,
Expand Down Expand Up @@ -426,6 +434,7 @@ fun MenuControllerPreview() {
onDanmakuSizeChange = { currentDanmakuSize = it },
onDanmakuOpacityChange = { currentDanmakuOpacity = it },
onDanmakuAreaChange = { currentDanmakuArea = it },
onDanmakuMaskChange = { currentDanmakuMask = it },
onSubtitleChange = { currentSubtitleId = it.id },
onSubtitleSizeChange = { currentSubtitleFontSize = it },
onSubtitleBackgroundOpacityChange = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ fun VideoPlayerController(
onDanmakuSizeChange: (Float) -> Unit,
onDanmakuOpacityChange: (Float) -> Unit,
onDanmakuAreaChange: (Float) -> Unit,
onDanmakuMaskChange: (Boolean) -> Unit,
onSubtitleChange: (Subtitle) -> Unit,
onSubtitleSizeChange: (TextUnit) -> Unit,
onSubtitleBackgroundOpacityChange: (Float) -> Unit,
Expand Down Expand Up @@ -365,6 +366,7 @@ fun VideoPlayerController(
onDanmakuSizeChange = onDanmakuSizeChange,
onDanmakuOpacityChange = onDanmakuOpacityChange,
onDanmakuAreaChange = onDanmakuAreaChange,
onDanmakuMaskChange = onDanmakuMaskChange,
onSubtitleChange = onSubtitleChange,
onSubtitleSizeChange = onSubtitleSizeChange,
onSubtitleBackgroundOpacityChange = onSubtitleBackgroundOpacityChange,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import dev.aaa1115910.bv.component.controllers2.playermenu.component.RadioMenuLi
import dev.aaa1115910.bv.component.controllers2.playermenu.component.StepLessMenuItem
import dev.aaa1115910.bv.component.createCustomInitialFocusRestorerModifiers
import dev.aaa1115910.bv.component.ifElse
import dev.aaa1115910.bv.util.Prefs
import java.text.NumberFormat

@Composable
Expand All @@ -46,6 +45,7 @@ fun DanmakuMenuList(
onDanmakuSizeChange: (Float) -> Unit,
onDanmakuOpacityChange: (Float) -> Unit,
onDanmakuAreaChange: (Float) -> Unit,
onDanmakuMaskChange: (Boolean) -> Unit,
onFocusStateChange: (MenuFocusState) -> Unit
) {
val context = LocalContext.current
Expand All @@ -61,7 +61,7 @@ fun DanmakuMenuList(
verticalAlignment = Alignment.CenterVertically
) {
val menuItemsModifier = Modifier
.width(200.dp)
.width(216.dp)
.padding(horizontal = 8.dp)
AnimatedVisibility(visible = focusState.focusState != MenuFocusState.MenuNav) {
when (selectedDanmakuMenuItem) {
Expand Down Expand Up @@ -146,11 +146,11 @@ fun DanmakuMenuList(
onFocusBackToParent = { onFocusStateChange(MenuFocusState.Menu) }
)

VideoPlayerDanmakuMenuItem.Webmark -> RadioMenuList(
VideoPlayerDanmakuMenuItem.Mask -> RadioMenuList(
modifier = menuItemsModifier,
items = listOf("关闭", "开启"),
selected = if (Prefs.enableWebmark) 1 else 0,
onSelectedChanged = { Prefs.enableWebmark = it == 1 },
selected = if (data.currentDanmakuMask) 1 else 0,
onSelectedChanged = { onDanmakuMaskChange(it == 1) },
onFocusBackToParent = { onFocusStateChange(MenuFocusState.Menu) }
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import com.kuaishou.akdanmaku.data.DanmakuItemData
import com.kuaishou.akdanmaku.ecs.component.filter.TypeFilter
import com.kuaishou.akdanmaku.ext.RETAINER_BILIBILI
import dev.aaa1115910.biliapi.entity.danmaku.DanmakuMaskFrame
import dev.aaa1115910.biliapi.entity.video.VideoShot
import dev.aaa1115910.bv.component.DanmakuPlayerCompose
import dev.aaa1115910.bv.component.controllers.LocalVideoPlayerControllerData
import dev.aaa1115910.bv.component.controllers.VideoPlayerControllerData
Expand Down Expand Up @@ -447,6 +446,7 @@ fun VideoPlayerV3Screen(
currentDanmakuScale = playerViewModel.currentDanmakuScale,
currentDanmakuOpacity = playerViewModel.currentDanmakuOpacity,
currentDanmakuArea = playerViewModel.currentDanmakuArea,
currentDanmakuMask = playerViewModel.currentDanmakuMask,
currentSubtitleId = playerViewModel.currentSubtitleId,
currentSubtitleData = playerViewModel.currentSubtitleData,
currentSubtitleFontSize = playerViewModel.currentSubtitleFontSize,
Expand Down Expand Up @@ -588,6 +588,11 @@ fun VideoPlayerV3Screen(
Prefs.defaultDanmakuArea = area
playerViewModel.currentDanmakuArea = area
},
onDanmakuMaskChange = { mask ->
logger.info { "On danmaku mask change: $mask" }
Prefs.defaultDanmakuMask = mask
playerViewModel.currentDanmakuMask = mask
},
onSubtitleChange = { subtitle ->
playerViewModel.loadSubtitle(subtitle.id)
},
Expand Down Expand Up @@ -634,7 +639,7 @@ fun VideoPlayerV3Screen(
// 突然变成完全不透明一瞬间,因此这次新版选择直接在此处设置透明度
.alpha(playerViewModel.currentDanmakuOpacity)
.ifElse(
{ Prefs.enableWebmark },
{ playerViewModel.currentDanmakuMask },
Modifier.danmakuMask(currentDanmakuMaskFrame)
),
danmakuPlayer = playerViewModel.danmakuPlayer
Expand Down
12 changes: 7 additions & 5 deletions app/src/main/kotlin/dev/aaa1115910/bv/util/Prefs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -279,9 +279,11 @@ object Prefs {
get() = runBlocking { dsm.getPreferenceFlow(PrefKeys.prefPreferOfficialCdnRequest).first() }
set(value) = runBlocking { dsm.editPreference(PrefKeys.prefPreferOfficialCdn, value) }

var enableWebmark: Boolean
get() = runBlocking { dsm.getPreferenceFlow(PrefKeys.prefPreferEnableWebmarkRequest).first() }
set(value) = runBlocking { dsm.editPreference(PrefKeys.prefEnableWebmark, value) }
var defaultDanmakuMask: Boolean
get() = runBlocking {
dsm.getPreferenceFlow(PrefKeys.prefDefaultDanmakuMaskRequest).first()
}
set(value) = runBlocking { dsm.editPreference(PrefKeys.prefDefaultDanmakuMask, value) }
}

private object PrefKeys {
Expand Down Expand Up @@ -324,7 +326,7 @@ private object PrefKeys {
val prefLastVersionCodeKey = intPreferencesKey("last_version_code")
val prefShowedRemoteControllerPanelDemoKey = booleanPreferencesKey("showed_rcpd")
val prefPreferOfficialCdn = booleanPreferencesKey("prefer_official_cdn")
val prefEnableWebmark = booleanPreferencesKey("prefer_enable_webmark")
val prefDefaultDanmakuMask = booleanPreferencesKey("prefer_enable_webmark")

val prefIsLoginRequest = PreferenceRequest(prefIsLoginKey, false)
val prefUidRequest = PreferenceRequest(prefUidKey, 0)
Expand Down Expand Up @@ -375,5 +377,5 @@ private object PrefKeys {
val prefShowedRemoteControllerPanelDemoRequest =
PreferenceRequest(prefShowedRemoteControllerPanelDemoKey, false)
val prefPreferOfficialCdnRequest = PreferenceRequest(prefPreferOfficialCdn, false)
val prefPreferEnableWebmarkRequest = PreferenceRequest(prefEnableWebmark, false)
val prefDefaultDanmakuMaskRequest = PreferenceRequest(prefDefaultDanmakuMask, false)
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ class VideoPlayerV3ViewModel(
addAll(Prefs.defaultDanmakuTypes)
}
var currentDanmakuArea by mutableFloatStateOf(Prefs.defaultDanmakuArea)
var currentDanmakuMask by mutableStateOf(Prefs.defaultDanmakuMask)
var currentSubtitleId by mutableLongStateOf(-1L)
var currentSubtitleData = mutableStateListOf<SubtitleItem>()
var currentSubtitleFontSize by mutableStateOf(Prefs.defaultSubtitleFontSize)
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,6 @@
<string name="resolution_hdr_short">HDR</string>

<string name="search_input_history">历史记录</string>
<string name="title_activity_toview">现在不看</string>
<string name="search_input_hotword">bilibili 热搜</string>
<string name="search_input_soft_keybord_clear">清空</string>
<string name="search_input_soft_keybord_delete">删除</string>
Expand Down Expand Up @@ -279,6 +278,7 @@
<string name="title_activity_settings">设置</string>
<string name="title_activity_speed_test">网络测速</string>
<string name="title_activity_tag">视频标签</string>
<string name="title_activity_toview">现在不看</string>
<string name="title_activity_up_info">UP 投稿</string>
<string name="title_activity_user_info">用户信息</string>
<string name="title_activity_user_lock_settings">用户锁设置</string>
Expand Down Expand Up @@ -465,14 +465,14 @@
<string name="video_info_tags">标签</string>
<string name="video_info_time">投稿时间: %1$s</string>
<string name="video_player_menu_danmaku_area">显示区域</string>
<string name="video_player_menu_danmaku_mask">防遮挡</string>
<string name="video_player_menu_danmaku_opacity">不透明度</string>
<string name="video_player_menu_danmaku_size">字体缩放</string>
<string name="video_player_menu_danmaku_switch">弹幕类型</string>
<string name="video_player_menu_danmaku_type_all">全部弹幕</string>
<string name="video_player_menu_danmaku_type_bottom">底部弹幕</string>
<string name="video_player_menu_danmaku_type_cross">滚动弹幕</string>
<string name="video_player_menu_danmaku_type_top">顶部弹幕</string>
<string name="video_player_menu_danmaku_webmark">防遮挡</string>
<string name="video_player_menu_nav_danmaku">弹幕设置</string>
<string name="video_player_menu_nav_picture">画面音频</string>
<string name="video_player_menu_nav_subtitle">字幕设置</string>
Expand Down

0 comments on commit 58d9bfe

Please sign in to comment.