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 mediaButtonIntent, PendingIntent.FLAG_CANCEL_CURRENT
) )
mediaSessionCompat = MediaSessionCompat( mediaSessionCompat = MediaSessionCompat(this, tag)
this, tag, mComponent,
mediaButtonReceiverPendingIntent
)
mediaSessionCompat?.setCallback(object : MediaSessionCompat.Callback() { mediaSessionCompat?.setCallback(object : MediaSessionCompat.Callback() {
override fun onMediaButtonEvent(mediaButtonEvent: Intent): Boolean { override fun onMediaButtonEvent(mediaButtonEvent: Intent): Boolean {
return MediaButtonReceiver.handleIntent(this@ReadAloudService, mediaButtonEvent) return MediaButtonReceiver.handleIntent(this@ReadAloudService, mediaButtonEvent)

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

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