|
|
@ -1,19 +1,34 @@ |
|
|
|
package io.legado.app.ui.association |
|
|
|
package io.legado.app.ui.association |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import android.content.Context |
|
|
|
|
|
|
|
import android.content.DialogInterface |
|
|
|
import android.os.Bundle |
|
|
|
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.lifecycle.Observer |
|
|
|
import androidx.lifecycle.Observer |
|
|
|
|
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager |
|
|
|
import io.legado.app.R |
|
|
|
import io.legado.app.R |
|
|
|
|
|
|
|
import io.legado.app.base.BaseDialogFragment |
|
|
|
import io.legado.app.base.VMBaseActivity |
|
|
|
import io.legado.app.base.VMBaseActivity |
|
|
|
|
|
|
|
import io.legado.app.base.adapter.ItemViewHolder |
|
|
|
|
|
|
|
import io.legado.app.base.adapter.SimpleRecyclerAdapter |
|
|
|
import io.legado.app.constant.Theme |
|
|
|
import io.legado.app.constant.Theme |
|
|
|
import io.legado.app.data.entities.BookSource |
|
|
|
import io.legado.app.data.entities.BookSource |
|
|
|
import io.legado.app.help.IntentDataHelp |
|
|
|
import io.legado.app.help.IntentDataHelp |
|
|
|
import io.legado.app.help.SourceHelp |
|
|
|
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.noButton |
|
|
|
|
|
|
|
import io.legado.app.lib.dialogs.okButton |
|
|
|
import io.legado.app.lib.dialogs.okButton |
|
|
|
import io.legado.app.utils.applyTint |
|
|
|
import io.legado.app.utils.applyTint |
|
|
|
import io.legado.app.utils.getViewModel |
|
|
|
import io.legado.app.utils.getViewModel |
|
|
|
|
|
|
|
import io.legado.app.utils.visible |
|
|
|
import kotlinx.android.synthetic.main.activity_translucence.* |
|
|
|
import kotlinx.android.synthetic.main.activity_translucence.* |
|
|
|
|
|
|
|
import kotlinx.android.synthetic.main.dialog_recycler_view.* |
|
|
|
|
|
|
|
import kotlinx.android.synthetic.main.item_source_import.view.* |
|
|
|
|
|
|
|
import org.jetbrains.anko.sdk27.listeners.onClick |
|
|
|
import org.jetbrains.anko.toast |
|
|
|
import org.jetbrains.anko.toast |
|
|
|
|
|
|
|
|
|
|
|
class ImportBookSourceActivity : VMBaseActivity<ImportBookSourceViewModel>( |
|
|
|
class ImportBookSourceActivity : VMBaseActivity<ImportBookSourceViewModel>( |
|
|
@ -32,7 +47,7 @@ class ImportBookSourceActivity : VMBaseActivity<ImportBookSourceViewModel>( |
|
|
|
}) |
|
|
|
}) |
|
|
|
viewModel.successLiveData.observe(this, Observer { |
|
|
|
viewModel.successLiveData.observe(this, Observer { |
|
|
|
rotate_loading.hide() |
|
|
|
rotate_loading.hide() |
|
|
|
successDialog(it) |
|
|
|
successDialog() |
|
|
|
}) |
|
|
|
}) |
|
|
|
initData() |
|
|
|
initData() |
|
|
|
} |
|
|
|
} |
|
|
@ -78,16 +93,131 @@ class ImportBookSourceActivity : VMBaseActivity<ImportBookSourceViewModel>( |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private fun successDialog(allSource: ArrayList<BookSource>) { |
|
|
|
private fun successDialog() { |
|
|
|
alert("解析结果", "共${allSource.size}个书源,是否确认导入?") { |
|
|
|
val bundle = Bundle() |
|
|
|
okButton { |
|
|
|
val allSourceKey = IntentDataHelp.putData(viewModel.allSources, "source") |
|
|
|
SourceHelp.insertBookSource(*allSource.toTypedArray()) |
|
|
|
bundle.putString("allSourceKey", allSourceKey) |
|
|
|
|
|
|
|
val checkStatusKey = IntentDataHelp.putData(viewModel.sourceCheckState, "check") |
|
|
|
|
|
|
|
bundle.putString("checkStatusKey", checkStatusKey) |
|
|
|
|
|
|
|
val selectStatusKey = IntentDataHelp.putData(viewModel.selectStatus, "select") |
|
|
|
|
|
|
|
bundle.putString("selectStatusKey", selectStatusKey) |
|
|
|
|
|
|
|
SourcesDialog().apply { |
|
|
|
|
|
|
|
arguments = bundle |
|
|
|
|
|
|
|
}.show(supportFragmentManager, "SourceDialog") |
|
|
|
} |
|
|
|
} |
|
|
|
noButton { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class SourcesDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
lateinit var adapter: SourcesAdapter |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
override fun onStart() { |
|
|
|
|
|
|
|
super.onStart() |
|
|
|
|
|
|
|
val dm = DisplayMetrics() |
|
|
|
|
|
|
|
activity?.windowManager?.defaultDisplay?.getMetrics(dm) |
|
|
|
|
|
|
|
dialog?.window?.setLayout( |
|
|
|
|
|
|
|
(dm.widthPixels * 0.9).toInt(), |
|
|
|
|
|
|
|
ViewGroup.LayoutParams.WRAP_CONTENT |
|
|
|
|
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
|
}.show().applyTint().setOnDismissListener { |
|
|
|
|
|
|
|
finish() |
|
|
|
override fun onCreateView( |
|
|
|
|
|
|
|
inflater: LayoutInflater, |
|
|
|
|
|
|
|
container: ViewGroup?, |
|
|
|
|
|
|
|
savedInstanceState: Bundle? |
|
|
|
|
|
|
|
): View? { |
|
|
|
|
|
|
|
return inflater.inflate(R.layout.dialog_recycler_view, container) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) { |
|
|
|
|
|
|
|
tool_bar.title = "导入书源" |
|
|
|
|
|
|
|
initMenu() |
|
|
|
|
|
|
|
arguments?.let { |
|
|
|
|
|
|
|
adapter = SourcesAdapter(requireContext()) |
|
|
|
|
|
|
|
val allSources = |
|
|
|
|
|
|
|
IntentDataHelp.getData<ArrayList<BookSource>>(it.getString("allSourceKey")) |
|
|
|
|
|
|
|
adapter.sourceCheckState = |
|
|
|
|
|
|
|
IntentDataHelp.getData<ArrayList<Boolean>>(it.getString("checkStatusKey"))!! |
|
|
|
|
|
|
|
adapter.selectStatus = |
|
|
|
|
|
|
|
IntentDataHelp.getData<ArrayList<Boolean>>(it.getString("selectStatusKey"))!! |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
recycler_view.layoutManager = LinearLayoutManager(requireContext()) |
|
|
|
|
|
|
|
recycler_view.adapter = adapter |
|
|
|
|
|
|
|
adapter.setItems(allSources) |
|
|
|
|
|
|
|
tv_cancel.visible() |
|
|
|
|
|
|
|
tv_cancel.onClick { |
|
|
|
|
|
|
|
dismiss() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
tv_ok.visible() |
|
|
|
|
|
|
|
tv_ok.onClick { |
|
|
|
|
|
|
|
importSelect() |
|
|
|
|
|
|
|
dismiss() |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private fun initMenu() { |
|
|
|
|
|
|
|
tool_bar.setOnMenuItemClickListener(this) |
|
|
|
|
|
|
|
tool_bar.inflateMenu(R.menu.import_source) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
override fun onMenuItemClick(item: MenuItem): Boolean { |
|
|
|
|
|
|
|
when (item.itemId) { |
|
|
|
|
|
|
|
R.id.menu_select_all -> { |
|
|
|
|
|
|
|
adapter.selectStatus.forEachIndexed { index, b -> |
|
|
|
|
|
|
|
if (!b) { |
|
|
|
|
|
|
|
adapter.selectStatus[index] = true |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
adapter.notifyDataSetChanged() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return false |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
override fun onDismiss(dialog: DialogInterface) { |
|
|
|
|
|
|
|
super.onDismiss(dialog) |
|
|
|
|
|
|
|
activity?.finish() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private fun importSelect() { |
|
|
|
|
|
|
|
val selectSource = arrayListOf<BookSource>() |
|
|
|
|
|
|
|
adapter.selectStatus.forEachIndexed { index, b -> |
|
|
|
|
|
|
|
if (b) { |
|
|
|
|
|
|
|
selectSource.add(adapter.getItem(index)!!) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
SourceHelp.insertBookSource(*selectSource.toTypedArray()) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class SourcesAdapter(context: Context) : |
|
|
|
|
|
|
|
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>) { |
|
|
|
|
|
|
|
holder.itemView.apply { |
|
|
|
|
|
|
|
cb_source_name.isChecked = selectStatus[holder.layoutPosition] |
|
|
|
|
|
|
|
cb_source_name.text = item.bookSourceName |
|
|
|
|
|
|
|
tv_source_state.text = if (sourceCheckState[holder.layoutPosition]) { |
|
|
|
|
|
|
|
"已存在" |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
"新书源" |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
cb_source_name.setOnCheckedChangeListener { buttonView, isChecked -> |
|
|
|
|
|
|
|
if (buttonView.isPressed) { |
|
|
|
|
|
|
|
selectStatus[holder.layoutPosition] = isChecked |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
override fun registerListener(holder: ItemViewHolder) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |