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. 12
      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 adapter by lazy { CoverAdapter(requireContext(), this) }
private val startStopMenuItem: MenuItem?
get() = binding.toolBar.menu.findItem(R.id.menu_start_stop)
override fun onStart() {
super.onStart()
val dm = requireActivity().windowSize
@ -73,9 +76,15 @@ class ChangeCoverDialog() : BaseDialogFragment(),
viewModel.searchStateData.observe(viewLifecycleOwner, {
binding.refreshProgressBar.isAutoLoading = 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 {
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())
})
@ -86,14 +95,11 @@ class ChangeCoverDialog() : BaseDialogFragment(),
override fun onMenuItemClick(item: MenuItem?): Boolean {
when (item?.itemId) {
R.id.menu_stop -> viewModel.stopSearch()
R.id.menu_start_stop -> viewModel.startOrStopSearch()
}
return false
}
private val stopMenuItem: MenuItem?
get() = binding.toolBar.menu.findItem(R.id.menu_stop)
override fun changeTo(coverUrl: String) {
callBack?.coverChangeTo(coverUrl)
dismissAllowingStateLoss()

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

@ -140,9 +140,15 @@ class ChangeSourceDialog() : BaseDialogFragment(),
viewModel.searchStateData.observe(viewLifecycleOwner, {
binding.refreshProgressBar.isAutoLoading = 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 {
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())
})
@ -160,8 +166,8 @@ class ChangeSourceDialog() : BaseDialogFragment(),
}
}
private val stopMenuItem: MenuItem?
get() = binding.toolBar.menu.findItem(R.id.menu_stop)
private val startStopMenuItem: MenuItem?
get() = binding.toolBar.menu.findItem(R.id.menu_start_stop)
override fun onMenuItemClick(item: MenuItem?): Boolean {
when (item?.itemId) {
@ -178,7 +184,7 @@ class ChangeSourceDialog() : BaseDialogFragment(),
putPrefBoolean(PreferKey.changeSourceLoadInfo, !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>()
else -> if (item?.groupId == R.id.source_group) {
if (!item.isChecked) {

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

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

Loading…
Cancel
Save