pull/1740/head
kunfei 3 years ago
parent e1083b5d71
commit d57a70b482
  1. 14
      app/src/main/java/io/legado/app/model/AudioPlay.kt
  2. 13
      app/src/main/java/io/legado/app/ui/book/audio/AudioPlayActivity.kt
  3. 29
      app/src/main/java/io/legado/app/ui/book/audio/ComposeView.kt
  4. 6
      app/src/main/res/layout/activity_audio_play.xml

@ -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<String>()
@ -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) {

@ -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<AudioPlayViewModel>()
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
)
}
}
}

@ -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<Boolean>, 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)
}
}
}

@ -223,4 +223,10 @@
</LinearLayout>
<androidx.compose.ui.platform.ComposeView
android:id="@+id/compose_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
Loading…
Cancel
Save