Skip to content

Commit

Permalink
update: danmaku setting
Browse files Browse the repository at this point in the history
  • Loading branch information
muedsa committed Nov 8, 2023
1 parent 863aa0f commit 1ed88cd
Show file tree
Hide file tree
Showing 13 changed files with 462 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright 2023 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package androidx.compose.material.icons.outlined

import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.materialIcon
import androidx.compose.material.icons.materialPath
import androidx.compose.ui.graphics.vector.ImageVector

public val Icons.Outlined.Remove: ImageVector
get() {
if (_remove != null) {
return _remove!!
}
_remove = materialIcon(name = "Outlined.Remove") {
materialPath {
moveTo(19.0F, 13.0F)
horizontalLineTo(5.0F)
verticalLineToRelative(-2.0F)
horizontalLineToRelative(14.0F)
verticalLineToRelative(2.0F)
close()
}
}
return _remove!!
}

private var _remove: ImageVector? = null
7 changes: 7 additions & 0 deletions app/src/main/kotlin/com/muedsa/agetv/AppModule.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.muedsa.agetv

import android.content.Context
import com.google.common.net.HttpHeaders
import com.jakewharton.retrofit2.converter.kotlinx.serialization.asConverterFactory
import com.muedsa.agetv.repository.AppRepository
import com.muedsa.agetv.repository.DataStoreRepo
import com.muedsa.agetv.service.AgeApiService
import com.muedsa.agetv.service.AgePlayerService
import com.muedsa.agetv.service.DanDanPlayApiService
Expand All @@ -11,6 +13,7 @@ import com.muedsa.uitl.LenientJson
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.android.qualifiers.ApplicationContext
import dagger.hilt.components.SingletonComponent
import okhttp3.MediaType.Companion.toMediaType
import okhttp3.OkHttpClient
Expand Down Expand Up @@ -88,4 +91,8 @@ internal object AppModule {
playerService = playerService,
danDanPlayApiService = danDanPlayApiService
)

@Singleton
@Provides
fun provideDataStoreRepository(@ApplicationContext app: Context) = DataStoreRepo(app)
}
12 changes: 12 additions & 0 deletions app/src/main/kotlin/com/muedsa/agetv/Perfs.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.muedsa.agetv

import androidx.datastore.preferences.core.booleanPreferencesKey
import androidx.datastore.preferences.core.intPreferencesKey

val KEY_DANMAKU_ENABLE = booleanPreferencesKey("danmaku_enable")

val KEY_DANMAKU_SIZE_SCALE = intPreferencesKey("danmaku_size_scale")

val KEY_DANMAKU_ALPHA = intPreferencesKey("danmaku_alpha")

val KEY_DANMAKU_SCREEN_PART = intPreferencesKey("danmaku_size_part")
8 changes: 8 additions & 0 deletions app/src/main/kotlin/com/muedsa/agetv/model/AppSettingModel.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.muedsa.agetv.model

data class AppSettingModel(
val danmakuEnable: Boolean,
val danmakuSizeScale: Int,
val danmakuAlpha: Int,
val danmakuScreenPart: Int
)
30 changes: 30 additions & 0 deletions app/src/main/kotlin/com/muedsa/agetv/repository/DataStoreRepo.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.muedsa.agetv.repository

import android.content.Context
import androidx.datastore.core.DataStore
import androidx.datastore.preferences.core.Preferences
import androidx.datastore.preferences.preferencesDataStore
import javax.inject.Inject

private const val PREFS_NAME = "setting"

private val Context.dataStore: DataStore<Preferences> by preferencesDataStore(name = PREFS_NAME)

class DataStoreRepo @Inject constructor(private val context: Context) {

val dataStore: DataStore<Preferences> = context.dataStore

// suspend fun <T> get(key: Preferences.Key<T>): T? {
// return dataStore.data.first()[key]
// }
//
// suspend fun collectPrefs(collector: FlowCollector<Preferences>) {
// dataStore.data.collect(collector)
// }
//
// suspend fun putString(key: Preferences.Key<String>, value: String) {
// dataStore.edit {
// it[key] = value
// }
// }
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,14 @@ import androidx.tv.material3.AssistChip
import androidx.tv.material3.ExperimentalTvMaterial3Api
import androidx.tv.material3.Icon
import androidx.tv.material3.MaterialTheme
import androidx.tv.material3.OutlinedButton
import androidx.tv.material3.Text
import com.muedsa.agetv.PlaybackActivity
import com.muedsa.agetv.model.LazyType
import com.muedsa.agetv.ui.AgePosterSize
import com.muedsa.agetv.ui.RankFontColor
import com.muedsa.agetv.ui.RankIconColor
import com.muedsa.agetv.ui.navigation.NavigationItems
import com.muedsa.agetv.viewmodel.AnimeDetailViewModel
import com.muedsa.compose.tv.model.ContentModel
import com.muedsa.compose.tv.theme.ScreenPaddingLeft
Expand All @@ -68,7 +70,8 @@ import kotlinx.coroutines.flow.update
@Composable
fun AnimeDetailScreen(
viewModel: AnimeDetailViewModel = hiltViewModel(),
errorMsgBoxState: ErrorMessageBoxState
errorMsgBoxState: ErrorMessageBoxState,
onNavigate: (NavigationItems, List<String>?) -> Unit = { _, _ -> }
) {
val context = LocalContext.current
val configuration = LocalConfiguration.current
Expand Down Expand Up @@ -219,11 +222,11 @@ fun AnimeDetailScreen(
Spacer(modifier = Modifier.height(25.dp))
}

// 播放源
// 按钮列表
item {

// 切换播放源
Row(verticalAlignment = Alignment.CenterVertically) {
// 切换播放源
Text(
text = "播放源",
color = MaterialTheme.colorScheme.onBackground,
Expand Down Expand Up @@ -278,9 +281,21 @@ fun AnimeDetailScreen(
}
)
}

Spacer(modifier = Modifier.width(25.dp))
OutlinedButton(
onClick = {
onNavigate(NavigationItems.Setting, null)
}
) {
Text(text = "设置")
}
}
Spacer(modifier = Modifier.height(20.dp))
}

// 切换播放源
item {
FlowRow(
modifier = Modifier.fillMaxWidth(0.9f),
verticalArrangement = Arrangement.Center,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,20 @@ fun PlaybackScreen(
episodeTitle: String,
mediaUrl: String,
danEpisodeId: Long = 0,
viewModel: PlaybackViewModel = hiltViewModel()
playbackViewModel: PlaybackViewModel = hiltViewModel(),
) {
val activity = (LocalContext.current as? Activity)

val errorMsgBoxState = remember { ErrorMessageBoxState() }
ErrorMessageBox(state = errorMsgBoxState) {

val danmakuListLD by viewModel.danmakuListLDSF.collectAsState()
val danmakuSettingLD by playbackViewModel.danmakuSettingLDSF.collectAsState()
val danmakuListLD by playbackViewModel.danmakuListLDSF.collectAsState()

LaunchedEffect(key1 = danEpisodeId) {
viewModel.loadDanmakuList(danEpisodeId)
LaunchedEffect(key1 = danmakuSettingLD) {
if (danmakuListLD.type == LazyType.FAILURE) {
errorMsgBoxState.error(danmakuListLD.error)
}
}

LaunchedEffect(key1 = danmakuListLD) {
Expand All @@ -49,9 +52,16 @@ fun PlaybackScreen(
}
}

if (danmakuListLD.type == LazyType.SUCCESS) {
if (danmakuListLD.type == LazyType.SUCCESS && danmakuSettingLD.type == LazyType.SUCCESS) {
var danmakuSetting = danmakuSettingLD.data!!

DanmakuVideoPlayer(
debug = BuildConfig.DEBUG,
danmakuConfigSetting = {
textSizeScale = danmakuSetting.danmakuSizeScale / 100f
alpha = danmakuSetting.danmakuAlpha / 100f
screenPart = danmakuSetting.danmakuScreenPart / 100f
},
danmakuPlayerInit = {
if (!danmakuListLD.data.isNullOrEmpty()) {
updateData(danmakuListLD.data!!)
Expand All @@ -70,7 +80,7 @@ fun PlaybackScreen(

override fun onRenderedFirstFrame() {
stopState.value = false
viewModel.registerPlayerPositionSaver(
playbackViewModel.registerPlayerPositionSaver(
aid,
episodeTitle,
this@DanmakuVideoPlayer,
Expand Down Expand Up @@ -105,5 +115,16 @@ fun PlaybackScreen(
prepare()
}
}

if (danmakuSettingLD.type == LazyType.SUCCESS) {
val danmakuSetting = danmakuSettingLD.data!!
LaunchedEffect(key1 = danEpisodeId) {
playbackViewModel.loadDanmakuList(
if (danmakuSetting.danmakuEnable)
danEpisodeId
else 0
)
}
}
}
}
Loading

0 comments on commit 1ed88cd

Please sign in to comment.