|
|
@ -1,29 +1,26 @@ |
|
|
|
package io.legado.app.ui.book.changesource |
|
|
|
package io.legado.app.ui.book.changesource |
|
|
|
|
|
|
|
|
|
|
|
import android.os.Bundle |
|
|
|
import android.os.Bundle |
|
|
|
import android.view.LayoutInflater |
|
|
|
import android.view.* |
|
|
|
import android.view.MenuItem |
|
|
|
|
|
|
|
import android.view.View |
|
|
|
|
|
|
|
import android.view.ViewGroup |
|
|
|
|
|
|
|
import androidx.appcompat.widget.SearchView |
|
|
|
import androidx.appcompat.widget.SearchView |
|
|
|
import androidx.appcompat.widget.Toolbar |
|
|
|
import androidx.appcompat.widget.Toolbar |
|
|
|
import androidx.fragment.app.FragmentManager |
|
|
|
import androidx.fragment.app.FragmentManager |
|
|
|
import androidx.recyclerview.widget.DiffUtil |
|
|
|
import androidx.recyclerview.widget.DiffUtil |
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager |
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager |
|
|
|
import androidx.recyclerview.widget.RecyclerView |
|
|
|
import androidx.recyclerview.widget.RecyclerView |
|
|
|
|
|
|
|
import io.legado.app.App |
|
|
|
import io.legado.app.R |
|
|
|
import io.legado.app.R |
|
|
|
import io.legado.app.base.BaseDialogFragment |
|
|
|
import io.legado.app.base.BaseDialogFragment |
|
|
|
|
|
|
|
import io.legado.app.constant.AppPattern |
|
|
|
import io.legado.app.constant.PreferKey |
|
|
|
import io.legado.app.constant.PreferKey |
|
|
|
import io.legado.app.data.entities.Book |
|
|
|
import io.legado.app.data.entities.Book |
|
|
|
import io.legado.app.data.entities.SearchBook |
|
|
|
import io.legado.app.data.entities.SearchBook |
|
|
|
import io.legado.app.databinding.DialogChangeSourceBinding |
|
|
|
import io.legado.app.databinding.DialogChangeSourceBinding |
|
|
|
import io.legado.app.help.AppConfig |
|
|
|
import io.legado.app.help.AppConfig |
|
|
|
import io.legado.app.lib.theme.primaryColor |
|
|
|
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.ui.widget.recycler.VerticalDivider |
|
|
|
import io.legado.app.utils.applyTint |
|
|
|
import io.legado.app.utils.* |
|
|
|
import io.legado.app.utils.getSize |
|
|
|
|
|
|
|
import io.legado.app.utils.getViewModel |
|
|
|
|
|
|
|
import io.legado.app.utils.putPrefBoolean |
|
|
|
|
|
|
|
import io.legado.app.utils.viewbindingdelegate.viewBinding |
|
|
|
import io.legado.app.utils.viewbindingdelegate.viewBinding |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -47,6 +44,7 @@ class ChangeSourceDialog : BaseDialogFragment(), |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private val binding by viewBinding(DialogChangeSourceBinding::bind) |
|
|
|
private val binding by viewBinding(DialogChangeSourceBinding::bind) |
|
|
|
|
|
|
|
private val groups = linkedSetOf<String>() |
|
|
|
private var callBack: CallBack? = null |
|
|
|
private var callBack: CallBack? = null |
|
|
|
private lateinit var viewModel: ChangeSourceViewModel |
|
|
|
private lateinit var viewModel: ChangeSourceViewModel |
|
|
|
lateinit var adapter: ChangeSourceAdapter |
|
|
|
lateinit var adapter: ChangeSourceAdapter |
|
|
@ -90,6 +88,7 @@ class ChangeSourceDialog : BaseDialogFragment(), |
|
|
|
binding.toolBar.menu.findItem(R.id.menu_load_info)?.isChecked = |
|
|
|
binding.toolBar.menu.findItem(R.id.menu_load_info)?.isChecked = |
|
|
|
AppConfig.changeSourceLoadInfo |
|
|
|
AppConfig.changeSourceLoadInfo |
|
|
|
binding.toolBar.menu.findItem(R.id.menu_load_toc)?.isChecked = AppConfig.changeSourceLoadToc |
|
|
|
binding.toolBar.menu.findItem(R.id.menu_load_toc)?.isChecked = AppConfig.changeSourceLoadToc |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private fun initRecyclerView() { |
|
|
|
private fun initRecyclerView() { |
|
|
@ -150,6 +149,13 @@ class ChangeSourceDialog : BaseDialogFragment(), |
|
|
|
adapter.setItems(it) |
|
|
|
adapter.setItems(it) |
|
|
|
diffResult.dispatchUpdatesTo(adapter) |
|
|
|
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? |
|
|
|
private val stopMenuItem: MenuItem? |
|
|
@ -166,6 +172,18 @@ class ChangeSourceDialog : BaseDialogFragment(), |
|
|
|
item.isChecked = !item.isChecked |
|
|
|
item.isChecked = !item.isChecked |
|
|
|
} |
|
|
|
} |
|
|
|
R.id.menu_stop -> viewModel.stopSearch() |
|
|
|
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 |
|
|
|
return false |
|
|
|
} |
|
|
|
} |
|
|
@ -184,6 +202,28 @@ class ChangeSourceDialog : BaseDialogFragment(), |
|
|
|
viewModel.disableSource(searchBook) |
|
|
|
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 { |
|
|
|
interface CallBack { |
|
|
|
val oldBook: Book? |
|
|
|
val oldBook: Book? |
|
|
|
fun changeTo(book: Book) |
|
|
|
fun changeTo(book: Book) |
|
|
|