|
|
|
@ -5,8 +5,10 @@ import android.content.Context |
|
|
|
|
import android.content.DialogInterface |
|
|
|
|
import android.os.Bundle |
|
|
|
|
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.fragment.app.viewModels |
|
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager |
|
|
|
@ -14,15 +16,23 @@ import io.legado.app.R |
|
|
|
|
import io.legado.app.base.BaseDialogFragment |
|
|
|
|
import io.legado.app.base.adapter.ItemViewHolder |
|
|
|
|
import io.legado.app.base.adapter.RecyclerAdapter |
|
|
|
|
import io.legado.app.constant.AppPattern |
|
|
|
|
import io.legado.app.constant.PreferKey |
|
|
|
|
import io.legado.app.data.appDb |
|
|
|
|
import io.legado.app.data.entities.ReplaceRule |
|
|
|
|
import io.legado.app.databinding.DialogCustomGroupBinding |
|
|
|
|
import io.legado.app.databinding.DialogRecyclerViewBinding |
|
|
|
|
import io.legado.app.databinding.ItemSourceImportBinding |
|
|
|
|
import io.legado.app.lib.dialogs.alert |
|
|
|
|
import io.legado.app.lib.theme.primaryColor |
|
|
|
|
import io.legado.app.ui.widget.dialog.WaitDialog |
|
|
|
|
import io.legado.app.utils.dp |
|
|
|
|
import io.legado.app.utils.putPrefBoolean |
|
|
|
|
import io.legado.app.utils.splitNotBlank |
|
|
|
|
import io.legado.app.utils.viewbindingdelegate.viewBinding |
|
|
|
|
import io.legado.app.utils.visible |
|
|
|
|
|
|
|
|
|
class ImportReplaceRuleDialog : BaseDialogFragment() { |
|
|
|
|
class ImportReplaceRuleDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener { |
|
|
|
|
|
|
|
|
|
companion object { |
|
|
|
|
fun start( |
|
|
|
@ -71,6 +81,7 @@ class ImportReplaceRuleDialog : BaseDialogFragment() { |
|
|
|
|
binding.toolBar.setBackgroundColor(primaryColor) |
|
|
|
|
binding.toolBar.setTitle(R.string.import_replace_rule) |
|
|
|
|
binding.rotateLoading.show() |
|
|
|
|
initMenu() |
|
|
|
|
adapter = SourcesAdapter(requireContext()) |
|
|
|
|
binding.recyclerView.layoutManager = LinearLayoutManager(requireContext()) |
|
|
|
|
binding.recyclerView.adapter = adapter |
|
|
|
@ -89,7 +100,7 @@ class ImportReplaceRuleDialog : BaseDialogFragment() { |
|
|
|
|
} |
|
|
|
|
binding.tvFooterLeft.visible() |
|
|
|
|
binding.tvFooterLeft.setOnClickListener { |
|
|
|
|
val selectAll = viewModel.isSelectAll() |
|
|
|
|
val selectAll = viewModel.isSelectAll |
|
|
|
|
viewModel.selectStatus.forEachIndexed { index, b -> |
|
|
|
|
if (b != !selectAll) { |
|
|
|
|
viewModel.selectStatus[index] = !selectAll |
|
|
|
@ -125,17 +136,65 @@ class ImportReplaceRuleDialog : BaseDialogFragment() { |
|
|
|
|
viewModel.import(source) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private fun initMenu() { |
|
|
|
|
binding.toolBar.setOnMenuItemClickListener(this) |
|
|
|
|
binding.toolBar.inflateMenu(R.menu.import_replace) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun onMenuItemClick(item: MenuItem?): Boolean { |
|
|
|
|
when (item?.itemId) { |
|
|
|
|
R.id.menu_new_group -> alertCustomGroup(item) |
|
|
|
|
R.id.menu_Keep_original_name -> { |
|
|
|
|
item.isChecked = !item.isChecked |
|
|
|
|
putPrefBoolean(PreferKey.importKeepName, item.isChecked) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return true |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private fun alertCustomGroup(item: MenuItem) { |
|
|
|
|
alert(R.string.diy_edit_source_group) { |
|
|
|
|
val alertBinding = DialogCustomGroupBinding.inflate(layoutInflater).apply { |
|
|
|
|
val groups = linkedSetOf<String>() |
|
|
|
|
appDb.bookSourceDao.allGroup.forEach { group -> |
|
|
|
|
groups.addAll(group.splitNotBlank(AppPattern.splitGroupRegex)) |
|
|
|
|
} |
|
|
|
|
textInputLayout.setHint(R.string.group_name) |
|
|
|
|
editView.setFilterValues(groups.toList()) |
|
|
|
|
editView.dropDownHeight = 180.dp |
|
|
|
|
} |
|
|
|
|
customView { |
|
|
|
|
alertBinding.root |
|
|
|
|
} |
|
|
|
|
okButton { |
|
|
|
|
viewModel.isAddGroup = alertBinding.swAddGroup.isChecked |
|
|
|
|
viewModel.groupName = alertBinding.editView.text?.toString() |
|
|
|
|
if (viewModel.groupName.isNullOrBlank()) { |
|
|
|
|
item.title = getString(R.string.diy_source_group) |
|
|
|
|
} else { |
|
|
|
|
val group = getString(R.string.diy_edit_source_group_title, viewModel.groupName) |
|
|
|
|
if (viewModel.isAddGroup) { |
|
|
|
|
item.title = "+$group" |
|
|
|
|
} else { |
|
|
|
|
item.title = group |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
noButton() |
|
|
|
|
}.show() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private fun upSelectText() { |
|
|
|
|
if (viewModel.isSelectAll()) { |
|
|
|
|
if (viewModel.isSelectAll) { |
|
|
|
|
binding.tvFooterLeft.text = getString( |
|
|
|
|
R.string.select_cancel_count, |
|
|
|
|
viewModel.selectCount(), |
|
|
|
|
viewModel.selectCount, |
|
|
|
|
viewModel.allRules.size |
|
|
|
|
) |
|
|
|
|
} else { |
|
|
|
|
binding.tvFooterLeft.text = getString( |
|
|
|
|
R.string.select_all_count, |
|
|
|
|
viewModel.selectCount(), |
|
|
|
|
viewModel.selectCount, |
|
|
|
|
viewModel.allRules.size |
|
|
|
|
) |
|
|
|
|
} |
|
|
|
@ -157,6 +216,15 @@ class ImportReplaceRuleDialog : BaseDialogFragment() { |
|
|
|
|
binding.run { |
|
|
|
|
cbSourceName.isChecked = viewModel.selectStatus[holder.layoutPosition] |
|
|
|
|
cbSourceName.text = item.name |
|
|
|
|
val localRule = viewModel.checkRules[holder.layoutPosition] |
|
|
|
|
tvSourceState.text = when { |
|
|
|
|
localRule == null -> "新规则" |
|
|
|
|
item.pattern != localRule.pattern |
|
|
|
|
|| item.replacement != localRule.replacement |
|
|
|
|
|| item.isRegex != localRule.isRegex |
|
|
|
|
|| item.scope != localRule.scope -> "更新" |
|
|
|
|
else -> "已存在" |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|