|
|
@ -1,6 +1,5 @@ |
|
|
|
package io.legado.app.ui.association |
|
|
|
package io.legado.app.ui.association |
|
|
|
|
|
|
|
|
|
|
|
import android.annotation.SuppressLint |
|
|
|
|
|
|
|
import android.content.Context |
|
|
|
import android.content.Context |
|
|
|
import android.content.DialogInterface |
|
|
|
import android.content.DialogInterface |
|
|
|
import android.os.Bundle |
|
|
|
import android.os.Bundle |
|
|
@ -21,7 +20,6 @@ import io.legado.app.lib.theme.primaryColor |
|
|
|
import io.legado.app.ui.widget.dialog.WaitDialog |
|
|
|
import io.legado.app.ui.widget.dialog.WaitDialog |
|
|
|
import io.legado.app.utils.* |
|
|
|
import io.legado.app.utils.* |
|
|
|
import io.legado.app.utils.viewbindingdelegate.viewBinding |
|
|
|
import io.legado.app.utils.viewbindingdelegate.viewBinding |
|
|
|
import splitties.views.onClick |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -39,58 +37,47 @@ class ImportOnLineBookFileDialog() : BaseDialogFragment(R.layout.dialog_recycler |
|
|
|
setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT) |
|
|
|
setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@SuppressLint("NotifyDataSetChanged") |
|
|
|
|
|
|
|
override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) { |
|
|
|
override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) { |
|
|
|
val bookUrl = arguments?.getString("bookUrl") |
|
|
|
val bookUrl = arguments?.getString("bookUrl") |
|
|
|
val infoHtml = arguments?.getString("infoHtml") |
|
|
|
viewModel.initData(bookUrl) |
|
|
|
viewModel.initData(bookUrl, infoHtml) |
|
|
|
|
|
|
|
binding.toolBar.setBackgroundColor(primaryColor) |
|
|
|
binding.toolBar.setBackgroundColor(primaryColor) |
|
|
|
//标题 |
|
|
|
binding.toolBar.setTitle(R.string.download_and_import_file) |
|
|
|
binding.toolBar.setTitle("导入在线书籍文件") |
|
|
|
|
|
|
|
binding.rotateLoading.show() |
|
|
|
binding.rotateLoading.show() |
|
|
|
binding.recyclerView.layoutManager = LinearLayoutManager(requireContext()) |
|
|
|
binding.recyclerView.layoutManager = LinearLayoutManager(requireContext()) |
|
|
|
binding.recyclerView.adapter = adapter |
|
|
|
binding.recyclerView.adapter = adapter |
|
|
|
binding.tvCancel.visible() |
|
|
|
viewModel.errorLiveData.observe(this) { |
|
|
|
binding.tvCancel.setOnClickListener { |
|
|
|
binding.rotateLoading.hide() |
|
|
|
dismissAllowingStateLoss() |
|
|
|
binding.tvMsg.apply { |
|
|
|
|
|
|
|
text = it |
|
|
|
|
|
|
|
visible() |
|
|
|
} |
|
|
|
} |
|
|
|
binding.tvOk.visible() |
|
|
|
|
|
|
|
binding.tvOk.setOnClickListener { |
|
|
|
|
|
|
|
val waitDialog = WaitDialog(requireContext()) |
|
|
|
|
|
|
|
waitDialog.show() |
|
|
|
|
|
|
|
viewModel.importSelect { |
|
|
|
|
|
|
|
waitDialog.dismiss() |
|
|
|
|
|
|
|
dismissAllowingStateLoss() |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
viewModel.successLiveData.observe(this) { |
|
|
|
|
|
|
|
binding.rotateLoading.hide() |
|
|
|
|
|
|
|
if (it > 0) { |
|
|
|
|
|
|
|
adapter.setItems(viewModel.allBookFiles) |
|
|
|
} |
|
|
|
} |
|
|
|
binding.tvFooterLeft.visible() |
|
|
|
|
|
|
|
binding.tvFooterLeft.setOnClickListener { |
|
|
|
|
|
|
|
val selectAll = viewModel.isSelectAll |
|
|
|
|
|
|
|
viewModel.selectStatus.forEachIndexed { index, b -> |
|
|
|
|
|
|
|
if (b != !selectAll) { |
|
|
|
|
|
|
|
viewModel.selectStatus[index] = !selectAll |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
viewModel.savedFileUriData.observe(this) { |
|
|
|
|
|
|
|
requireContext().openFileUri(it, "*/*") |
|
|
|
} |
|
|
|
} |
|
|
|
adapter.notifyDataSetChanged() |
|
|
|
|
|
|
|
upSelectText() |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
adapter.setItems(viewModel.allBookFiles) |
|
|
|
|
|
|
|
upSelectText() |
|
|
|
private fun importFileAndUpdate(url: String, fileName: String) { |
|
|
|
|
|
|
|
val waitDialog = WaitDialog(requireContext()) |
|
|
|
|
|
|
|
waitDialog.show() |
|
|
|
|
|
|
|
viewModel.importOnLineBookFile(url, fileName) { |
|
|
|
|
|
|
|
waitDialog.dismiss() |
|
|
|
|
|
|
|
dismissAllowingStateLoss() |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private fun upSelectText() { |
|
|
|
private fun downloadFile(url: String, fileName: String) { |
|
|
|
if (viewModel.isSelectAll) { |
|
|
|
val waitDialog = WaitDialog(requireContext()) |
|
|
|
binding.tvFooterLeft.text = getString( |
|
|
|
waitDialog.show() |
|
|
|
R.string.select_cancel_count, |
|
|
|
viewModel.downloadUrl(url, fileName) { |
|
|
|
viewModel.selectCount, |
|
|
|
waitDialog.dismiss() |
|
|
|
viewModel.allBookFiles.size |
|
|
|
dismissAllowingStateLoss() |
|
|
|
) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
binding.tvFooterLeft.text = getString( |
|
|
|
|
|
|
|
R.string.select_all_count, |
|
|
|
|
|
|
|
viewModel.selectCount, |
|
|
|
|
|
|
|
viewModel.allBookFiles.size |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -109,39 +96,32 @@ class ImportOnLineBookFileDialog() : BaseDialogFragment(R.layout.dialog_recycler |
|
|
|
payloads: MutableList<Any> |
|
|
|
payloads: MutableList<Any> |
|
|
|
) { |
|
|
|
) { |
|
|
|
binding.apply { |
|
|
|
binding.apply { |
|
|
|
cbFileName.isChecked = viewModel.selectStatus[holder.layoutPosition] |
|
|
|
|
|
|
|
cbFileName.text = item.second |
|
|
|
cbFileName.text = item.second |
|
|
|
if (item.third) { |
|
|
|
|
|
|
|
tvOpen.invisible() |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
tvOpen.visible() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override fun registerListener(holder: ItemViewHolder, binding: ItemBookFileImportBinding) { |
|
|
|
override fun registerListener( |
|
|
|
|
|
|
|
holder: ItemViewHolder, |
|
|
|
|
|
|
|
binding: ItemBookFileImportBinding |
|
|
|
|
|
|
|
) { |
|
|
|
binding.apply { |
|
|
|
binding.apply { |
|
|
|
cbFileName.setOnCheckedChangeListener { buttonView, isChecked -> |
|
|
|
cbFileName.setOnClickListener { |
|
|
|
if (buttonView.isPressed) { |
|
|
|
|
|
|
|
val selectFile = viewModel.allBookFiles[holder.layoutPosition] |
|
|
|
val selectFile = viewModel.allBookFiles[holder.layoutPosition] |
|
|
|
if (selectFile.third) { |
|
|
|
if (selectFile.third) { |
|
|
|
viewModel.selectStatus[holder.layoutPosition] = isChecked |
|
|
|
importFileAndUpdate(selectFile.first, selectFile.second) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
toastOnUi("不支持直接导入") |
|
|
|
alert( |
|
|
|
} |
|
|
|
title = getString(R.string.draw), |
|
|
|
upSelectText() |
|
|
|
message = getString(R.string.file_not_supported, selectFile.second) |
|
|
|
|
|
|
|
) { |
|
|
|
|
|
|
|
okButton { |
|
|
|
|
|
|
|
importFileAndUpdate(selectFile.first, selectFile.second) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
neutralButton(R.string.open_fun) { |
|
|
|
|
|
|
|
downloadFile(selectFile.first, selectFile.second) |
|
|
|
} |
|
|
|
} |
|
|
|
root.onClick { |
|
|
|
cancelButton() |
|
|
|
cbFileName.isChecked = !cbFileName.isChecked |
|
|
|
|
|
|
|
viewModel.selectStatus[holder.layoutPosition] = cbFileName.isChecked |
|
|
|
|
|
|
|
upSelectText() |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
tvOpen.setOnClickListener { |
|
|
|
|
|
|
|
val bookFile = viewModel.allBookFiles[holder.layoutPosition] |
|
|
|
|
|
|
|
//intent解压 |
|
|
|
|
|
|
|
viewModel.downloadUrl(bookFile.first, bookFile.second) { |
|
|
|
|
|
|
|
//openFileUri(it) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|