|
|
|
@ -1,29 +1,26 @@ |
|
|
|
|
package io.legado.app.ui.book.changesource |
|
|
|
|
|
|
|
|
|
import android.os.Bundle |
|
|
|
|
import android.view.LayoutInflater |
|
|
|
|
import android.view.MenuItem |
|
|
|
|
import android.view.View |
|
|
|
|
import android.view.ViewGroup |
|
|
|
|
import android.view.* |
|
|
|
|
import androidx.appcompat.widget.SearchView |
|
|
|
|
import androidx.appcompat.widget.Toolbar |
|
|
|
|
import androidx.fragment.app.FragmentManager |
|
|
|
|
import androidx.recyclerview.widget.DiffUtil |
|
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager |
|
|
|
|
import androidx.recyclerview.widget.RecyclerView |
|
|
|
|
import io.legado.app.App |
|
|
|
|
import io.legado.app.R |
|
|
|
|
import io.legado.app.base.BaseDialogFragment |
|
|
|
|
import io.legado.app.constant.AppPattern |
|
|
|
|
import io.legado.app.constant.PreferKey |
|
|
|
|
import io.legado.app.data.entities.Book |
|
|
|
|
import io.legado.app.data.entities.SearchBook |
|
|
|
|
import io.legado.app.databinding.DialogChangeSourceBinding |
|
|
|
|
import io.legado.app.help.AppConfig |
|
|
|
|
import io.legado.app.lib.theme.primaryColor |
|
|
|
|
import io.legado.app.ui.book.source.manage.BookSourceActivity |
|
|
|
|
import io.legado.app.ui.widget.recycler.VerticalDivider |
|
|
|
|
import io.legado.app.utils.applyTint |
|
|
|
|
import io.legado.app.utils.getSize |
|
|
|
|
import io.legado.app.utils.getViewModel |
|
|
|
|
import io.legado.app.utils.putPrefBoolean |
|
|
|
|
import io.legado.app.utils.* |
|
|
|
|
import io.legado.app.utils.viewbindingdelegate.viewBinding |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -47,6 +44,7 @@ class ChangeSourceDialog : BaseDialogFragment(), |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private val binding by viewBinding(DialogChangeSourceBinding::bind) |
|
|
|
|
private val groups = linkedSetOf<String>() |
|
|
|
|
private var callBack: CallBack? = null |
|
|
|
|
private lateinit var viewModel: ChangeSourceViewModel |
|
|
|
|
lateinit var adapter: ChangeSourceAdapter |
|
|
|
@ -90,6 +88,7 @@ class ChangeSourceDialog : BaseDialogFragment(), |
|
|
|
|
binding.toolBar.menu.findItem(R.id.menu_load_info)?.isChecked = |
|
|
|
|
AppConfig.changeSourceLoadInfo |
|
|
|
|
binding.toolBar.menu.findItem(R.id.menu_load_toc)?.isChecked = AppConfig.changeSourceLoadToc |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private fun initRecyclerView() { |
|
|
|
@ -150,6 +149,13 @@ class ChangeSourceDialog : BaseDialogFragment(), |
|
|
|
|
adapter.setItems(it) |
|
|
|
|
diffResult.dispatchUpdatesTo(adapter) |
|
|
|
|
}) |
|
|
|
|
App.db.bookSourceDao.liveGroupEnabled().observe(this, { |
|
|
|
|
groups.clear() |
|
|
|
|
it.map { group -> |
|
|
|
|
groups.addAll(group.splitNotBlank(AppPattern.splitGroupRegex)) |
|
|
|
|
} |
|
|
|
|
upGroupMenu() |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private val stopMenuItem: MenuItem? |
|
|
|
@ -166,6 +172,18 @@ class ChangeSourceDialog : BaseDialogFragment(), |
|
|
|
|
item.isChecked = !item.isChecked |
|
|
|
|
} |
|
|
|
|
R.id.menu_stop -> viewModel.stopSearch() |
|
|
|
|
R.id.menu_source_manage -> startActivity<BookSourceActivity>() |
|
|
|
|
else -> if (item?.groupId == R.id.source_group) { |
|
|
|
|
if (!item.isChecked) { |
|
|
|
|
item.isChecked = true |
|
|
|
|
if (item.title.toString() == getString(R.string.all_source)) { |
|
|
|
|
putPrefString("searchGroup", "") |
|
|
|
|
} else { |
|
|
|
|
putPrefString("searchGroup", item.title.toString()) |
|
|
|
|
} |
|
|
|
|
viewModel.stopSearch() |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return false |
|
|
|
|
} |
|
|
|
@ -184,6 +202,28 @@ class ChangeSourceDialog : BaseDialogFragment(), |
|
|
|
|
viewModel.disableSource(searchBook) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 更新分组菜单 |
|
|
|
|
*/ |
|
|
|
|
private fun upGroupMenu() { |
|
|
|
|
val menu: Menu = binding.toolBar.menu |
|
|
|
|
val selectedGroup = getPrefString("searchGroup") ?: "" |
|
|
|
|
menu.removeGroup(R.id.source_group) |
|
|
|
|
var item = menu.add(R.id.source_group, Menu.NONE, Menu.NONE, R.string.all_source) |
|
|
|
|
if (selectedGroup == "") { |
|
|
|
|
item?.isChecked = true |
|
|
|
|
} |
|
|
|
|
groups.sortedWith { o1, o2 -> |
|
|
|
|
o1.cnCompare(o2) |
|
|
|
|
}.map { |
|
|
|
|
item = menu.add(R.id.source_group, Menu.NONE, Menu.NONE, it) |
|
|
|
|
if (it == selectedGroup) { |
|
|
|
|
item.isChecked = true |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
menu.setGroupCheckable(R.id.source_group, true, true) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
interface CallBack { |
|
|
|
|
val oldBook: Book? |
|
|
|
|
fun changeTo(book: Book) |
|
|
|
|