pull/1352/head
gedoor 3 years ago
parent c1727d5373
commit c6191403b7
  1. 18
      app/src/main/java/io/legado/app/ui/book/changecover/ChangeCoverDialog.kt
  2. 10
      app/src/main/java/io/legado/app/ui/book/changecover/ChangeCoverViewModel.kt
  3. 16
      app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceDialog.kt
  4. 2
      app/src/main/res/menu/change_cover.xml
  5. 2
      app/src/main/res/menu/change_source.xml

@ -33,6 +33,9 @@ class ChangeCoverDialog() : BaseDialogFragment(),
private val viewModel: ChangeCoverViewModel by viewModels() private val viewModel: ChangeCoverViewModel by viewModels()
private val adapter by lazy { CoverAdapter(requireContext(), this) } private val adapter by lazy { CoverAdapter(requireContext(), this) }
private val startStopMenuItem: MenuItem?
get() = binding.toolBar.menu.findItem(R.id.menu_start_stop)
override fun onStart() { override fun onStart() {
super.onStart() super.onStart()
val dm = requireActivity().windowSize val dm = requireActivity().windowSize
@ -73,9 +76,15 @@ class ChangeCoverDialog() : BaseDialogFragment(),
viewModel.searchStateData.observe(viewLifecycleOwner, { viewModel.searchStateData.observe(viewLifecycleOwner, {
binding.refreshProgressBar.isAutoLoading = it binding.refreshProgressBar.isAutoLoading = it
if (it) { if (it) {
stopMenuItem?.setIcon(R.drawable.ic_stop_black_24dp) startStopMenuItem?.let { item ->
item.setIcon(R.drawable.ic_stop_black_24dp)
item.setTitle(R.string.stop)
}
} else { } else {
stopMenuItem?.setIcon(R.drawable.ic_refresh_black_24dp) startStopMenuItem?.let { item ->
item.setIcon(R.drawable.ic_refresh_black_24dp)
item.setTitle(R.string.refresh)
}
} }
binding.toolBar.menu.applyTint(requireContext()) binding.toolBar.menu.applyTint(requireContext())
}) })
@ -86,14 +95,11 @@ class ChangeCoverDialog() : BaseDialogFragment(),
override fun onMenuItemClick(item: MenuItem?): Boolean { override fun onMenuItemClick(item: MenuItem?): Boolean {
when (item?.itemId) { when (item?.itemId) {
R.id.menu_stop -> viewModel.stopSearch() R.id.menu_start_stop -> viewModel.startOrStopSearch()
} }
return false return false
} }
private val stopMenuItem: MenuItem?
get() = binding.toolBar.menu.findItem(R.id.menu_stop)
override fun changeTo(coverUrl: String) { override fun changeTo(coverUrl: String) {
callBack?.coverChangeTo(coverUrl) callBack?.coverChangeTo(coverUrl)
dismissAllowingStateLoss() dismissAllowingStateLoss()

@ -81,6 +81,7 @@ class ChangeCoverViewModel(application: Application) : BaseViewModel(application
private fun startSearch() { private fun startSearch() {
execute { execute {
stopSearch()
bookSourceList.clear() bookSourceList.clear()
bookSourceList.addAll(appDb.bookSourceDao.allEnabled) bookSourceList.addAll(appDb.bookSourceDao.allEnabled)
searchStateData.postValue(true) searchStateData.postValue(true)
@ -142,14 +143,19 @@ class ChangeCoverViewModel(application: Application) : BaseViewModel(application
} }
} }
fun stopSearch() { fun startOrStopSearch() {
if (tasks.isEmpty) { if (tasks.isEmpty) {
startSearch() startSearch()
} else { } else {
stopSearch()
}
}
fun stopSearch() {
tasks.clear() tasks.clear()
searchPool?.close()
searchStateData.postValue(false) searchStateData.postValue(false)
} }
}
override fun onCleared() { override fun onCleared() {
super.onCleared() super.onCleared()

@ -140,9 +140,15 @@ class ChangeSourceDialog() : BaseDialogFragment(),
viewModel.searchStateData.observe(viewLifecycleOwner, { viewModel.searchStateData.observe(viewLifecycleOwner, {
binding.refreshProgressBar.isAutoLoading = it binding.refreshProgressBar.isAutoLoading = it
if (it) { if (it) {
stopMenuItem?.setIcon(R.drawable.ic_stop_black_24dp) startStopMenuItem?.let { item ->
item.setIcon(R.drawable.ic_stop_black_24dp)
item.setTitle(R.string.stop)
}
} else { } else {
stopMenuItem?.setIcon(R.drawable.ic_refresh_black_24dp) startStopMenuItem?.let { item ->
item.setIcon(R.drawable.ic_refresh_black_24dp)
item.setTitle(R.string.refresh)
}
} }
binding.toolBar.menu.applyTint(requireContext()) binding.toolBar.menu.applyTint(requireContext())
}) })
@ -160,8 +166,8 @@ class ChangeSourceDialog() : BaseDialogFragment(),
} }
} }
private val stopMenuItem: MenuItem? private val startStopMenuItem: MenuItem?
get() = binding.toolBar.menu.findItem(R.id.menu_stop) get() = binding.toolBar.menu.findItem(R.id.menu_start_stop)
override fun onMenuItemClick(item: MenuItem?): Boolean { override fun onMenuItemClick(item: MenuItem?): Boolean {
when (item?.itemId) { when (item?.itemId) {
@ -178,7 +184,7 @@ class ChangeSourceDialog() : BaseDialogFragment(),
putPrefBoolean(PreferKey.changeSourceLoadInfo, !item.isChecked) putPrefBoolean(PreferKey.changeSourceLoadInfo, !item.isChecked)
item.isChecked = !item.isChecked item.isChecked = !item.isChecked
} }
R.id.menu_stop -> viewModel.startOrStopSearch() R.id.menu_start_stop -> viewModel.startOrStopSearch()
R.id.menu_source_manage -> startActivity<BookSourceActivity>() R.id.menu_source_manage -> startActivity<BookSourceActivity>()
else -> if (item?.groupId == R.id.source_group) { else -> if (item?.groupId == R.id.source_group) {
if (!item.isChecked) { if (!item.isChecked) {

@ -4,7 +4,7 @@
xmlns:app="http://schemas.android.com/apk/res-auto"> xmlns:app="http://schemas.android.com/apk/res-auto">
<item <item
android:id="@+id/menu_stop" android:id="@+id/menu_start_stop"
android:title="@string/stop" android:title="@string/stop"
android:icon="@drawable/ic_refresh_white_24dp" android:icon="@drawable/ic_refresh_white_24dp"
app:showAsAction="always" app:showAsAction="always"

@ -12,7 +12,7 @@
tools:ignore="AlwaysShowAction" /> tools:ignore="AlwaysShowAction" />
<item <item
android:id="@+id/menu_stop" android:id="@+id/menu_start_stop"
android:title="@string/stop" android:title="@string/stop"
android:icon="@drawable/ic_refresh_white_24dp" android:icon="@drawable/ic_refresh_white_24dp"
app:showAsAction="always" app:showAsAction="always"

Loading…
Cancel
Save