diff --git a/app/src/main/java/io/legado/app/model/AudioPlay.kt b/app/src/main/java/io/legado/app/model/AudioPlay.kt index 7211858db..f224f6d09 100644 --- a/app/src/main/java/io/legado/app/model/AudioPlay.kt +++ b/app/src/main/java/io/legado/app/model/AudioPlay.kt @@ -15,6 +15,7 @@ import io.legado.app.help.coroutine.Coroutine import io.legado.app.service.AudioPlayService import io.legado.app.utils.postEvent import io.legado.app.utils.startService +import splitties.init.appCtx object AudioPlay { var titleData = MutableLiveData() @@ -138,10 +139,17 @@ object AudioPlay { } } - fun addTimer(context: Context) { - val intent = Intent(context, AudioPlayService::class.java) + fun addTimer() { + val intent = Intent(appCtx, AudioPlayService::class.java) intent.action = IntentAction.addTimer - context.startService(intent) + appCtx.startService(intent) + } + + fun setTimer(minute: Int) { + val intent = Intent(appCtx, AudioPlayService::class.java) + intent.action = IntentAction.setTimer + intent.putExtra("minute", minute) + appCtx.startService(intent) } fun saveRead(book: Book) { diff --git a/app/src/main/java/io/legado/app/ui/book/audio/AudioPlayActivity.kt b/app/src/main/java/io/legado/app/ui/book/audio/AudioPlayActivity.kt index e83ebcf59..acbde8820 100644 --- a/app/src/main/java/io/legado/app/ui/book/audio/AudioPlayActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/audio/AudioPlayActivity.kt @@ -9,6 +9,7 @@ import android.view.Menu import android.view.MenuItem import android.widget.SeekBar import androidx.activity.viewModels +import androidx.compose.runtime.mutableStateOf import io.legado.app.R import io.legado.app.base.VMBaseActivity import io.legado.app.constant.EventBus @@ -26,6 +27,7 @@ import io.legado.app.ui.book.changesource.ChangeBookSourceDialog import io.legado.app.ui.book.source.edit.BookSourceEditActivity import io.legado.app.ui.book.toc.TocActivityResult import io.legado.app.ui.login.SourceLoginActivity +import io.legado.app.ui.theme.AppTheme import io.legado.app.ui.widget.seekbar.SeekBarChangeListener import io.legado.app.utils.* import io.legado.app.utils.viewbindingdelegate.viewBinding @@ -43,6 +45,7 @@ class AudioPlayActivity : override val viewModel by viewModels() private var menu: Menu? = null private var adjustProgress = false + private val timerViewState = mutableStateOf(false) private val progressTimeFormat by lazy { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { SimpleDateFormat("mm:ss", Locale.getDefault()) @@ -154,7 +157,15 @@ class AudioPlayActivity : AudioPlay.adjustSpeed(this@AudioPlayActivity, -0.1f) } binding.ivTimer.setOnClickListener { - AudioPlay.addTimer(this@AudioPlayActivity) + timerViewState.value = true + } + binding.composeView.setContent { + AppTheme { + TimerView( + state = timerViewState, + binding.ivTimer + ) + } } } diff --git a/app/src/main/java/io/legado/app/ui/book/audio/ComposeView.kt b/app/src/main/java/io/legado/app/ui/book/audio/ComposeView.kt new file mode 100644 index 000000000..da32c62c9 --- /dev/null +++ b/app/src/main/java/io/legado/app/ui/book/audio/ComposeView.kt @@ -0,0 +1,29 @@ +package io.legado.app.ui.book.audio + +import android.view.View +import androidx.compose.material.Slider +import androidx.compose.runtime.Composable +import androidx.compose.runtime.MutableState +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember +import androidx.compose.ui.window.Dialog +import io.legado.app.model.AudioPlay +import io.legado.app.service.AudioPlayService + + +@Composable +fun TimerView(state: MutableState, parent: View) { + val intOffset = IntArray(2) + parent.getLocationInWindow(intOffset) + if (state.value) { + val timeMinute = remember { + mutableStateOf(AudioPlayService.timeMinute) + } + Dialog(onDismissRequest = { state.value = false }) { + Slider(value = timeMinute.value.toFloat(), onValueChange = { + timeMinute.value = it.toInt() + AudioPlay.setTimer(it.toInt()) + }, valueRange = 0f..180f) + } + } +} \ No newline at end of file diff --git a/app/src/main/res/layout/activity_audio_play.xml b/app/src/main/res/layout/activity_audio_play.xml index 37d157d7f..7b984a74d 100644 --- a/app/src/main/res/layout/activity_audio_play.xml +++ b/app/src/main/res/layout/activity_audio_play.xml @@ -223,4 +223,10 @@ + + \ No newline at end of file