|
|
|
@ -3,19 +3,24 @@ package io.legado.app.ui.book.changecover |
|
|
|
|
import android.os.Bundle |
|
|
|
|
import android.util.DisplayMetrics |
|
|
|
|
import android.view.LayoutInflater |
|
|
|
|
import android.view.MenuItem |
|
|
|
|
import android.view.View |
|
|
|
|
import android.view.ViewGroup |
|
|
|
|
import androidx.appcompat.widget.Toolbar |
|
|
|
|
import androidx.fragment.app.FragmentManager |
|
|
|
|
import androidx.lifecycle.Observer |
|
|
|
|
import androidx.recyclerview.widget.DiffUtil |
|
|
|
|
import androidx.recyclerview.widget.GridLayoutManager |
|
|
|
|
import io.legado.app.R |
|
|
|
|
import io.legado.app.base.BaseDialogFragment |
|
|
|
|
import io.legado.app.constant.Theme |
|
|
|
|
import io.legado.app.utils.applyTint |
|
|
|
|
import io.legado.app.utils.getViewModel |
|
|
|
|
import kotlinx.android.synthetic.main.dialog_change_source.* |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ChangeCoverDialog : BaseDialogFragment(), |
|
|
|
|
Toolbar.OnMenuItemClickListener, |
|
|
|
|
CoverAdapter.CallBack { |
|
|
|
|
|
|
|
|
|
companion object { |
|
|
|
@ -55,13 +60,19 @@ class ChangeCoverDialog : BaseDialogFragment(), |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) { |
|
|
|
|
viewModel.searchStateData.observe(viewLifecycleOwner, Observer { |
|
|
|
|
refresh_progress_bar.isAutoLoading = it |
|
|
|
|
}) |
|
|
|
|
tool_bar.setTitle(R.string.change_cover_source) |
|
|
|
|
arguments?.let { bundle -> |
|
|
|
|
viewModel.initData(bundle) |
|
|
|
|
viewModel.initData(arguments) |
|
|
|
|
initMenu() |
|
|
|
|
initView() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private fun initMenu() { |
|
|
|
|
tool_bar.inflateMenu(R.menu.change_cover) |
|
|
|
|
tool_bar.menu.applyTint(requireContext(), Theme.getTheme()) |
|
|
|
|
tool_bar.setOnMenuItemClickListener(this) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private fun initView() { |
|
|
|
|
recycler_view.layoutManager = GridLayoutManager(requireContext(), 3) |
|
|
|
|
adapter = CoverAdapter(requireContext(), this) |
|
|
|
|
recycler_view.adapter = adapter |
|
|
|
@ -70,6 +81,15 @@ class ChangeCoverDialog : BaseDialogFragment(), |
|
|
|
|
|
|
|
|
|
override fun observeLiveBus() { |
|
|
|
|
super.observeLiveBus() |
|
|
|
|
viewModel.searchStateData.observe(viewLifecycleOwner, Observer { |
|
|
|
|
refresh_progress_bar.isAutoLoading = it |
|
|
|
|
if (it) { |
|
|
|
|
stopMenuItem?.setIcon(R.drawable.ic_stop_black_24dp) |
|
|
|
|
} else { |
|
|
|
|
stopMenuItem?.setIcon(R.drawable.ic_refresh_black_24dp) |
|
|
|
|
} |
|
|
|
|
tool_bar.menu.applyTint(requireContext(), Theme.getTheme()) |
|
|
|
|
}) |
|
|
|
|
viewModel.searchBooksLiveData.observe(viewLifecycleOwner, Observer { |
|
|
|
|
val diffResult = DiffUtil.calculateDiff(DiffCallBack(adapter.getItems(), it)) |
|
|
|
|
adapter.setItems(it) |
|
|
|
@ -77,6 +97,16 @@ class ChangeCoverDialog : BaseDialogFragment(), |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun onMenuItemClick(item: MenuItem?): Boolean { |
|
|
|
|
when (item?.itemId) { |
|
|
|
|
R.id.menu_stop -> viewModel.stopSearch() |
|
|
|
|
} |
|
|
|
|
return false |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private val stopMenuItem: MenuItem? |
|
|
|
|
get() = tool_bar.menu.findItem(R.id.menu_stop) |
|
|
|
|
|
|
|
|
|
override fun changeTo(coverUrl: String) { |
|
|
|
|
callBack?.coverChangeTo(coverUrl) |
|
|
|
|
dismiss() |
|
|
|
|