pull/32/head
kunfei 5 years ago
parent 0c7c225e9f
commit 430a444bf3
  1. 5
      app/src/main/java/io/legado/app/service/ReadAloudService.kt
  2. 8
      app/src/main/java/io/legado/app/ui/changesource/ChangeSourceDialog.kt
  3. 7
      app/src/main/java/io/legado/app/ui/changesource/ChangeSourceViewModel.kt

@ -333,10 +333,7 @@ class ReadAloudService : BaseService(), TextToSpeech.OnInitListener,
mediaButtonIntent, PendingIntent.FLAG_CANCEL_CURRENT
)
mediaSessionCompat = MediaSessionCompat(
this, tag, mComponent,
mediaButtonReceiverPendingIntent
)
mediaSessionCompat = MediaSessionCompat(this, tag)
mediaSessionCompat?.setCallback(object : MediaSessionCompat.Callback() {
override fun onMediaButtonEvent(mediaButtonEvent: Intent): Boolean {
return MediaButtonReceiver.handleIntent(this@ReadAloudService, mediaButtonEvent)

@ -8,6 +8,7 @@ import android.view.ViewGroup
import android.widget.LinearLayout
import androidx.appcompat.widget.SearchView
import androidx.fragment.app.DialogFragment
import androidx.lifecycle.Observer
import androidx.recyclerview.widget.DividerItemDecoration
import androidx.recyclerview.widget.LinearLayoutManager
import io.legado.app.R
@ -48,6 +49,9 @@ class ChangeSourceDialog : DialogFragment(),
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
viewModel.searchStateData.observe(viewLifecycleOwner, Observer {
refresh_progress_bar.isAutoLoading = it
})
arguments?.let { bundle ->
bundle.getString("name")?.let {
viewModel.name = it
@ -141,10 +145,6 @@ class ChangeSourceDialog : DialogFragment(),
return changeSourceAdapter
}
override fun upSearchState(isSearch: Boolean) {
refresh_progress_bar.isAutoLoading = isSearch
}
interface CallBack {
fun curOrigin(): String?
fun oldBook(): Book?

@ -1,6 +1,7 @@
package io.legado.app.ui.changesource
import android.app.Application
import androidx.lifecycle.MutableLiveData
import androidx.recyclerview.widget.DiffUtil
import io.legado.app.App
import io.legado.app.R
@ -17,6 +18,7 @@ import org.jetbrains.anko.debug
class ChangeSourceViewModel(application: Application) : BaseViewModel(application) {
var callBack: CallBack? = null
val searchStateData = MutableLiveData<Boolean>()
var name: String = ""
var author: String = ""
private var task: Coroutine<*>? = null
@ -50,7 +52,7 @@ class ChangeSourceViewModel(application: Application) : BaseViewModel(applicatio
fun search() {
task = execute {
callBack?.upSearchState(true)
searchStateData.postValue(true)
val bookSourceList = App.db.bookSourceDao().allEnabled
for (item in bookSourceList) {
//task取消时自动取消 by (scope = this@execute)
@ -73,7 +75,7 @@ class ChangeSourceViewModel(application: Application) : BaseViewModel(applicatio
}
task?.invokeOnCompletion {
callBack?.upSearchState(false)
searchStateData.postValue(false)
}
}
@ -125,6 +127,5 @@ class ChangeSourceViewModel(application: Application) : BaseViewModel(applicatio
interface CallBack {
fun adapter(): ChangeSourceAdapter
fun upSearchState(isSearch: Boolean)
}
}
Loading…
Cancel
Save