From 430a444bf3d68cfe8c1347649c7d1adad13bb38f Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 11 Sep 2019 09:39:28 +0800 Subject: [PATCH] up --- .../main/java/io/legado/app/service/ReadAloudService.kt | 5 +---- .../io/legado/app/ui/changesource/ChangeSourceDialog.kt | 8 ++++---- .../legado/app/ui/changesource/ChangeSourceViewModel.kt | 7 ++++--- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/io/legado/app/service/ReadAloudService.kt b/app/src/main/java/io/legado/app/service/ReadAloudService.kt index 5e4638dc1..1af82c149 100644 --- a/app/src/main/java/io/legado/app/service/ReadAloudService.kt +++ b/app/src/main/java/io/legado/app/service/ReadAloudService.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) diff --git a/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceDialog.kt b/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceDialog.kt index f5a1a6699..df03b920e 100644 --- a/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceDialog.kt +++ b/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceDialog.kt @@ -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? diff --git a/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceViewModel.kt b/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceViewModel.kt index 3839bebef..3159db258 100644 --- a/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceViewModel.kt @@ -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() 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) } } \ No newline at end of file