|
|
@ -15,7 +15,6 @@ import io.legado.app.base.BaseDialogFragment |
|
|
|
import io.legado.app.base.adapter.ItemViewHolder |
|
|
|
import io.legado.app.base.adapter.ItemViewHolder |
|
|
|
import io.legado.app.base.adapter.SimpleRecyclerAdapter |
|
|
|
import io.legado.app.base.adapter.SimpleRecyclerAdapter |
|
|
|
import io.legado.app.data.entities.BookSource |
|
|
|
import io.legado.app.data.entities.BookSource |
|
|
|
import io.legado.app.help.SourceHelp |
|
|
|
|
|
|
|
import io.legado.app.lib.dialogs.alert |
|
|
|
import io.legado.app.lib.dialogs.alert |
|
|
|
import io.legado.app.lib.dialogs.customView |
|
|
|
import io.legado.app.lib.dialogs.customView |
|
|
|
import io.legado.app.lib.dialogs.noButton |
|
|
|
import io.legado.app.lib.dialogs.noButton |
|
|
@ -30,14 +29,14 @@ import kotlinx.android.synthetic.main.dialog_recycler_view.* |
|
|
|
import kotlinx.android.synthetic.main.item_source_import.view.* |
|
|
|
import kotlinx.android.synthetic.main.item_source_import.view.* |
|
|
|
import org.jetbrains.anko.sdk27.listeners.onClick |
|
|
|
import org.jetbrains.anko.sdk27.listeners.onClick |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 导入书源弹出窗口 |
|
|
|
|
|
|
|
*/ |
|
|
|
class ImportBookSourceDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener { |
|
|
|
class ImportBookSourceDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener { |
|
|
|
|
|
|
|
|
|
|
|
val viewModel: ImportBookSourceViewModel |
|
|
|
val viewModel: ImportBookSourceViewModel |
|
|
|
get() = |
|
|
|
get() = getViewModelOfActivity(ImportBookSourceViewModel::class.java) |
|
|
|
getViewModelOfActivity(ImportBookSourceViewModel::class.java) |
|
|
|
|
|
|
|
lateinit var adapter: SourcesAdapter |
|
|
|
lateinit var adapter: SourcesAdapter |
|
|
|
private var _groupName: String? = null |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
override fun onStart() { |
|
|
|
override fun onStart() { |
|
|
|
super.onStart() |
|
|
|
super.onStart() |
|
|
@ -60,21 +59,18 @@ class ImportBookSourceDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickList |
|
|
|
tool_bar.setTitle(R.string.import_book_source) |
|
|
|
tool_bar.setTitle(R.string.import_book_source) |
|
|
|
initMenu() |
|
|
|
initMenu() |
|
|
|
adapter = SourcesAdapter(requireContext()) |
|
|
|
adapter = SourcesAdapter(requireContext()) |
|
|
|
val allSources = viewModel.allSources |
|
|
|
|
|
|
|
adapter.sourceCheckState = viewModel.sourceCheckState |
|
|
|
|
|
|
|
adapter.selectStatus = viewModel.selectStatus |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
recycler_view.layoutManager = LinearLayoutManager(requireContext()) |
|
|
|
recycler_view.layoutManager = LinearLayoutManager(requireContext()) |
|
|
|
recycler_view.adapter = adapter |
|
|
|
recycler_view.adapter = adapter |
|
|
|
adapter.setItems(allSources) |
|
|
|
adapter.setItems(viewModel.allSources) |
|
|
|
tv_cancel.visible() |
|
|
|
tv_cancel.visible() |
|
|
|
tv_cancel.onClick { |
|
|
|
tv_cancel.onClick { |
|
|
|
dismiss() |
|
|
|
dismiss() |
|
|
|
} |
|
|
|
} |
|
|
|
tv_ok.visible() |
|
|
|
tv_ok.visible() |
|
|
|
tv_ok.onClick { |
|
|
|
tv_ok.onClick { |
|
|
|
importSelect() |
|
|
|
viewModel.importSelect { |
|
|
|
dismiss() |
|
|
|
dismiss() |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -96,25 +92,25 @@ class ImportBookSourceDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickList |
|
|
|
} |
|
|
|
} |
|
|
|
okButton { |
|
|
|
okButton { |
|
|
|
editText?.text?.toString()?.let { group -> |
|
|
|
editText?.text?.toString()?.let { group -> |
|
|
|
_groupName = group |
|
|
|
viewModel.groupName = group |
|
|
|
item.title = getString(R.string.diy_edit_source_group_title, _groupName) |
|
|
|
item.title = getString(R.string.diy_edit_source_group_title, group) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
noButton { } |
|
|
|
noButton { } |
|
|
|
}.show().applyTint() |
|
|
|
}.show().applyTint() |
|
|
|
} |
|
|
|
} |
|
|
|
R.id.menu_select_all -> { |
|
|
|
R.id.menu_select_all -> { |
|
|
|
adapter.selectStatus.forEachIndexed { index, b -> |
|
|
|
viewModel.selectStatus.forEachIndexed { index, b -> |
|
|
|
if (!b) { |
|
|
|
if (!b) { |
|
|
|
adapter.selectStatus[index] = true |
|
|
|
viewModel.selectStatus[index] = true |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
adapter.notifyDataSetChanged() |
|
|
|
adapter.notifyDataSetChanged() |
|
|
|
} |
|
|
|
} |
|
|
|
R.id.menu_un_select_all -> { |
|
|
|
R.id.menu_un_select_all -> { |
|
|
|
adapter.selectStatus.forEachIndexed { index, b -> |
|
|
|
viewModel.selectStatus.forEachIndexed { index, b -> |
|
|
|
if (b) { |
|
|
|
if (b) { |
|
|
|
adapter.selectStatus[index] = false |
|
|
|
viewModel.selectStatus[index] = false |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
adapter.notifyDataSetChanged() |
|
|
|
adapter.notifyDataSetChanged() |
|
|
@ -128,31 +124,15 @@ class ImportBookSourceDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickList |
|
|
|
activity?.finish() |
|
|
|
activity?.finish() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private fun importSelect() { |
|
|
|
|
|
|
|
val selectSource = arrayListOf<BookSource>() |
|
|
|
|
|
|
|
adapter.selectStatus.forEachIndexed { index, b -> |
|
|
|
|
|
|
|
if (_groupName != null) { |
|
|
|
|
|
|
|
adapter.getItem(index)!!.bookSourceGroup = _groupName |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (b) { |
|
|
|
|
|
|
|
selectSource.add(adapter.getItem(index)!!) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
SourceHelp.insertBookSource(*selectSource.toTypedArray()) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class SourcesAdapter(context: Context) : |
|
|
|
inner class SourcesAdapter(context: Context) : |
|
|
|
SimpleRecyclerAdapter<BookSource>(context, R.layout.item_source_import) { |
|
|
|
SimpleRecyclerAdapter<BookSource>(context, R.layout.item_source_import) { |
|
|
|
|
|
|
|
|
|
|
|
lateinit var sourceCheckState: ArrayList<Boolean> |
|
|
|
|
|
|
|
lateinit var selectStatus: ArrayList<Boolean> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
override fun convert(holder: ItemViewHolder, item: BookSource, payloads: MutableList<Any>) { |
|
|
|
override fun convert(holder: ItemViewHolder, item: BookSource, payloads: MutableList<Any>) { |
|
|
|
holder.itemView.apply { |
|
|
|
holder.itemView.apply { |
|
|
|
cb_source_name.isChecked = selectStatus[holder.layoutPosition] |
|
|
|
cb_source_name.isChecked = viewModel.selectStatus[holder.layoutPosition] |
|
|
|
cb_source_name.text = item.bookSourceName |
|
|
|
cb_source_name.text = item.bookSourceName |
|
|
|
tv_source_state.text = if (sourceCheckState[holder.layoutPosition]) { |
|
|
|
tv_source_state.text = if (viewModel.sourceCheckState[holder.layoutPosition]) { |
|
|
|
"已存在" |
|
|
|
"已存在" |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
"新书源" |
|
|
|
"新书源" |
|
|
@ -165,7 +145,7 @@ class ImportBookSourceDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickList |
|
|
|
holder.itemView.apply { |
|
|
|
holder.itemView.apply { |
|
|
|
cb_source_name.setOnCheckedChangeListener { buttonView, isChecked -> |
|
|
|
cb_source_name.setOnCheckedChangeListener { buttonView, isChecked -> |
|
|
|
if (buttonView.isPressed) { |
|
|
|
if (buttonView.isPressed) { |
|
|
|
selectStatus[holder.layoutPosition] = isChecked |
|
|
|
viewModel.selectStatus[holder.layoutPosition] = isChecked |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|