pull/457/head
gedoor 5 years ago
parent 08a0205cfd
commit e27f5e27e0
  1. 9
      app/src/main/java/io/legado/app/model/localBook/LocalBook.kt
  2. 4
      app/src/main/java/io/legado/app/ui/association/FileAssociationViewModel.kt
  3. 28
      app/src/main/java/io/legado/app/ui/book/local/ImportBookActivity.kt
  4. 8
      app/src/main/java/io/legado/app/ui/book/local/ImportBookAdapter.kt
  5. 2
      app/src/main/java/io/legado/app/ui/book/local/ImportBookViewModel.kt
  6. 18
      app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt
  7. 13
      app/src/main/java/io/legado/app/ui/replace/ReplaceRuleActivity.kt
  8. 13
      app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt

@ -28,9 +28,11 @@ object LocalBook {
} }
} }
fun importFile(path: String): Book { fun importFile(uri: Uri): Book {
val fileName = if (path.isContentPath()) { val path: String
val doc = DocumentFile.fromSingleUri(App.INSTANCE, Uri.parse(path)) val fileName = if (uri.isContentPath()) {
path = uri.toString()
val doc = DocumentFile.fromSingleUri(App.INSTANCE, uri)
doc?.let { doc?.let {
val bookFile = FileUtils.getFile(AnalyzeTxtFile.cacheFolder, it.name!!) val bookFile = FileUtils.getFile(AnalyzeTxtFile.cacheFolder, it.name!!)
if (!bookFile.exists()) { if (!bookFile.exists()) {
@ -42,6 +44,7 @@ object LocalBook {
} }
doc?.name!! doc?.name!!
} else { } else {
path = uri.path!!
File(path).name File(path).name
} }
val str = fileName.substringBeforeLast(".") val str = fileName.substringBeforeLast(".")

@ -46,9 +46,9 @@ class FileAssociationViewModel(application: Application) : BaseViewModel(applica
} }
if (scheme.isEmpty()) { if (scheme.isEmpty()) {
val book = if (uri.scheme == "content") { val book = if (uri.scheme == "content") {
LocalBook.importFile(uri.toString()) LocalBook.importFile(uri)
} else { } else {
LocalBook.importFile(uri.path.toString()) LocalBook.importFile(uri)
} }
val intent = Intent(context, ReadBookActivity::class.java) val intent = Intent(context, ReadBookActivity::class.java)
intent.putExtra("bookUrl", book.bookUrl) intent.putExtra("bookUrl", book.bookUrl)

@ -39,6 +39,7 @@ import java.util.*
class ImportBookActivity : VMBaseActivity<ImportBookViewModel>(R.layout.activity_import_book), class ImportBookActivity : VMBaseActivity<ImportBookViewModel>(R.layout.activity_import_book),
FilePickerDialog.CallBack, FilePickerDialog.CallBack,
PopupMenu.OnMenuItemClickListener, PopupMenu.OnMenuItemClickListener,
SelectActionBar.CallBack,
ImportBookAdapter.CallBack { ImportBookAdapter.CallBack {
private val requestCodeSelectFolder = 342 private val requestCodeSelectFolder = 342
private var rootDoc: DocumentFile? = null private var rootDoc: DocumentFile? = null
@ -75,21 +76,12 @@ class ImportBookActivity : VMBaseActivity<ImportBookViewModel>(R.layout.activity
when (item?.itemId) { when (item?.itemId) {
R.id.menu_del_selection -> R.id.menu_del_selection ->
viewModel.deleteDoc(adapter.selectedUris) { viewModel.deleteDoc(adapter.selectedUris) {
upPath() adapter.removeSelection()
} }
} }
return false return false
} }
private fun initView() {
lay_top.setBackgroundColor(backgroundColor)
recycler_view.layoutManager = LinearLayoutManager(this)
adapter = ImportBookAdapter(this, this)
recycler_view.adapter = adapter
select_action_bar.setMainActionText(R.string.add_to_shelf)
select_action_bar.inflateMenu(R.menu.import_book_sel)
select_action_bar.setOnMenuItemClickListener(this)
select_action_bar.setCallBack(object : SelectActionBar.CallBack {
override fun selectAll(selectAll: Boolean) { override fun selectAll(selectAll: Boolean) {
adapter.selectAll(selectAll) adapter.selectAll(selectAll)
} }
@ -100,11 +92,19 @@ class ImportBookActivity : VMBaseActivity<ImportBookViewModel>(R.layout.activity
override fun onClickMainAction() { override fun onClickMainAction() {
viewModel.addToBookshelf(adapter.selectedUris) { viewModel.addToBookshelf(adapter.selectedUris) {
upPath() adapter.notifyDataSetChanged()
} }
} }
})
private fun initView() {
lay_top.setBackgroundColor(backgroundColor)
recycler_view.layoutManager = LinearLayoutManager(this)
adapter = ImportBookAdapter(this, this)
recycler_view.adapter = adapter
select_action_bar.setMainActionText(R.string.add_to_shelf)
select_action_bar.inflateMenu(R.menu.import_book_sel)
select_action_bar.setOnMenuItemClickListener(this)
select_action_bar.setCallBack(this)
} }
private fun initEvent() { private fun initEvent() {
@ -210,7 +210,7 @@ class ImportBookActivity : VMBaseActivity<ImportBookViewModel>(R.layout.activity
DocumentsContract.Document.MIME_TYPE_DIR, DocumentsContract.Document.MIME_TYPE_DIR,
it.length(), it.length(),
Date(it.lastModified()), Date(it.lastModified()),
Uri.parse(it.absolutePath) Uri.fromFile(it)
) )
) )
} else if (it.name.endsWith(".txt", true) } else if (it.name.endsWith(".txt", true)
@ -222,7 +222,7 @@ class ImportBookActivity : VMBaseActivity<ImportBookViewModel>(R.layout.activity
it.extension, it.extension,
it.length(), it.length(),
Date(it.lastModified()), Date(it.lastModified()),
Uri.parse(it.absolutePath) Uri.fromFile(it)
) )
) )
} }

@ -66,6 +66,14 @@ class ImportBookAdapter(context: Context, val callBack: CallBack) :
callBack.upCountView() callBack.upCountView()
} }
fun removeSelection() {
for (i in getItems().lastIndex downTo 0) {
if (getItem(i)?.uri.toString() in selectedUris) {
removeItem(i)
}
}
}
override fun convert(holder: ItemViewHolder, item: DocItem, payloads: MutableList<Any>) { override fun convert(holder: ItemViewHolder, item: DocItem, payloads: MutableList<Any>) {
holder.itemView.apply { holder.itemView.apply {
if (payloads.isEmpty()) { if (payloads.isEmpty()) {

@ -16,7 +16,7 @@ class ImportBookViewModel(application: Application) : BaseViewModel(application)
fun addToBookshelf(uriList: HashSet<String>, finally: () -> Unit) { fun addToBookshelf(uriList: HashSet<String>, finally: () -> Unit) {
execute { execute {
uriList.forEach { uriList.forEach {
LocalBook.importFile(it) LocalBook.importFile(Uri.parse(it))
} }
}.onFinally { }.onFinally {
finally.invoke() finally.invoke()

@ -53,6 +53,7 @@ class BookSourceActivity : VMBaseActivity<BookSourceViewModel>(R.layout.activity
PopupMenu.OnMenuItemClickListener, PopupMenu.OnMenuItemClickListener,
BookSourceAdapter.CallBack, BookSourceAdapter.CallBack,
FilePickerDialog.CallBack, FilePickerDialog.CallBack,
SelectActionBar.CallBack,
SearchView.OnQueryTextListener { SearchView.OnQueryTextListener {
override val viewModel: BookSourceViewModel override val viewModel: BookSourceViewModel
get() = getViewModel(BookSourceViewModel::class.java) get() = getViewModel(BookSourceViewModel::class.java)
@ -244,11 +245,6 @@ class BookSourceActivity : VMBaseActivity<BookSourceViewModel>(R.layout.activity
}) })
} }
private fun initSelectActionBar() {
select_action_bar.setMainActionText(R.string.delete)
select_action_bar.inflateMenu(R.menu.book_source_sel)
select_action_bar.setOnMenuItemClickListener(this)
select_action_bar.setCallBack(object : SelectActionBar.CallBack {
override fun selectAll(selectAll: Boolean) { override fun selectAll(selectAll: Boolean) {
if (selectAll) { if (selectAll) {
adapter.selectAll() adapter.selectAll()
@ -262,15 +258,17 @@ class BookSourceActivity : VMBaseActivity<BookSourceViewModel>(R.layout.activity
} }
override fun onClickMainAction() { override fun onClickMainAction() {
this@BookSourceActivity alert(titleResource = R.string.draw, messageResource = R.string.sure_del) {
.alert(titleResource = R.string.draw, messageResource = R.string.sure_del) {
okButton { viewModel.delSelection(adapter.getSelection()) } okButton { viewModel.delSelection(adapter.getSelection()) }
noButton { } noButton { }
}.show().applyTint()
} }
.show().applyTint()
}
})
private fun initSelectActionBar() {
select_action_bar.setMainActionText(R.string.delete)
select_action_bar.inflateMenu(R.menu.book_source_sel)
select_action_bar.setOnMenuItemClickListener(this)
select_action_bar.setCallBack(this)
} }
override fun onMenuItemClick(item: MenuItem?): Boolean { override fun onMenuItemClick(item: MenuItem?): Boolean {

@ -50,6 +50,7 @@ class ReplaceRuleActivity :
SearchView.OnQueryTextListener, SearchView.OnQueryTextListener,
PopupMenu.OnMenuItemClickListener, PopupMenu.OnMenuItemClickListener,
FilePickerDialog.CallBack, FilePickerDialog.CallBack,
SelectActionBar.CallBack,
ReplaceRuleAdapter.CallBack { ReplaceRuleAdapter.CallBack {
override val viewModel: ReplaceRuleViewModel override val viewModel: ReplaceRuleViewModel
get() = getViewModel(ReplaceRuleViewModel::class.java) get() = getViewModel(ReplaceRuleViewModel::class.java)
@ -107,11 +108,6 @@ class ReplaceRuleActivity :
search_view.setOnQueryTextListener(this) search_view.setOnQueryTextListener(this)
} }
private fun initSelectActionView() {
select_action_bar.setMainActionText(R.string.delete)
select_action_bar.inflateMenu(R.menu.replace_rule_sel)
select_action_bar.setOnMenuItemClickListener(this)
select_action_bar.setCallBack(object : SelectActionBar.CallBack {
override fun selectAll(selectAll: Boolean) { override fun selectAll(selectAll: Boolean) {
if (selectAll) { if (selectAll) {
adapter.selectAll() adapter.selectAll()
@ -127,7 +123,12 @@ class ReplaceRuleActivity :
override fun onClickMainAction() { override fun onClickMainAction() {
delSourceDialog() delSourceDialog()
} }
})
private fun initSelectActionView() {
select_action_bar.setMainActionText(R.string.delete)
select_action_bar.inflateMenu(R.menu.replace_rule_sel)
select_action_bar.setOnMenuItemClickListener(this)
select_action_bar.setCallBack(this)
} }
private fun delSourceDialog() { private fun delSourceDialog() {

@ -48,6 +48,7 @@ import java.util.*
class RssSourceActivity : VMBaseActivity<RssSourceViewModel>(R.layout.activity_rss_source), class RssSourceActivity : VMBaseActivity<RssSourceViewModel>(R.layout.activity_rss_source),
PopupMenu.OnMenuItemClickListener, PopupMenu.OnMenuItemClickListener,
FilePickerDialog.CallBack, FilePickerDialog.CallBack,
SelectActionBar.CallBack,
RssSourceAdapter.CallBack { RssSourceAdapter.CallBack {
override val viewModel: RssSourceViewModel override val viewModel: RssSourceViewModel
@ -153,11 +154,6 @@ class RssSourceActivity : VMBaseActivity<RssSourceViewModel>(R.layout.activity_r
}) })
} }
private fun initViewEvent() {
select_action_bar.setMainActionText(R.string.delete)
select_action_bar.inflateMenu(R.menu.rss_source_sel)
select_action_bar.setOnMenuItemClickListener(this)
select_action_bar.setCallBack(object : SelectActionBar.CallBack {
override fun selectAll(selectAll: Boolean) { override fun selectAll(selectAll: Boolean) {
if (selectAll) { if (selectAll) {
adapter.selectAll() adapter.selectAll()
@ -173,7 +169,12 @@ class RssSourceActivity : VMBaseActivity<RssSourceViewModel>(R.layout.activity_r
override fun onClickMainAction() { override fun onClickMainAction() {
delSourceDialog() delSourceDialog()
} }
})
private fun initViewEvent() {
select_action_bar.setMainActionText(R.string.delete)
select_action_bar.inflateMenu(R.menu.rss_source_sel)
select_action_bar.setOnMenuItemClickListener(this)
select_action_bar.setCallBack(this)
} }
private fun delSourceDialog() { private fun delSourceDialog() {

Loading…
Cancel
Save