pull/83/head
kunfei 5 years ago
parent f7e731ce40
commit aa496ea382
  1. 3
      app/src/main/java/io/legado/app/data/dao/BookDao.kt
  2. 13
      app/src/main/java/io/legado/app/ui/importbook/ImportBookActivity.kt
  3. 18
      app/src/main/java/io/legado/app/ui/importbook/ImportBookAdapter.kt

@ -17,6 +17,9 @@ interface BookDao {
@Query("SELECT * FROM books WHERE origin = '${BookType.local}' order by durChapterTime desc")
fun observeLocal(): LiveData<List<Book>>
@Query("SELECT bookUrl FROM books WHERE origin = '${BookType.local}' order by durChapterTime desc")
fun observeLocalUri(): LiveData<List<String>>
@Query("SELECT * FROM books WHERE origin <> '${BookType.local}' and type = 0 order by durChapterTime desc")
fun observeDownload(): LiveData<List<Book>>

@ -8,7 +8,10 @@ import android.os.Bundle
import android.view.Menu
import android.view.MenuItem
import androidx.documentfile.provider.DocumentFile
import androidx.lifecycle.LiveData
import androidx.lifecycle.Observer
import androidx.recyclerview.widget.LinearLayoutManager
import io.legado.app.App
import io.legado.app.R
import io.legado.app.base.VMBaseActivity
import io.legado.app.help.AppConfig
@ -24,6 +27,7 @@ class ImportBookActivity : VMBaseActivity<ImportBookViewModel>(R.layout.activity
private var rootDoc: DocumentFile? = null
private val subDirs = arrayListOf<String>()
private lateinit var importBookAdapter: ImportBookAdapter
private var localUriLiveData: LiveData<List<String>>? = null
override val viewModel: ImportBookViewModel
get() = getViewModel(ImportBookViewModel::class.java)
@ -31,6 +35,7 @@ class ImportBookActivity : VMBaseActivity<ImportBookViewModel>(R.layout.activity
override fun onActivityCreated(savedInstanceState: Bundle?) {
initView()
initEvent()
initData()
upRootDoc()
}
@ -64,6 +69,14 @@ class ImportBookActivity : VMBaseActivity<ImportBookViewModel>(R.layout.activity
}
}
private fun initData() {
localUriLiveData?.removeObservers(this)
localUriLiveData = App.db.bookDao().observeLocalUri()
localUriLiveData?.observe(this, Observer {
importBookAdapter.upBookHas(it)
})
}
private fun upRootDoc() {
AppConfig.importBookPath?.let {
val rootUri = Uri.parse(it)

@ -18,16 +18,30 @@ import java.util.*
class ImportBookAdapter(context: Context, val callBack: CallBack) :
SimpleRecyclerAdapter<DocumentFile>(context, R.layout.item_import_book) {
private var localUri = arrayListOf<String>()
fun upBookHas(uriList: List<String>) {
localUri.clear()
localUri.addAll(uriList)
notifyDataSetChanged()
}
override fun convert(holder: ItemViewHolder, item: DocumentFile, payloads: MutableList<Any>) {
holder.itemView.apply {
if (item.isDirectory) {
iv_icon.setImageResource(R.drawable.ic_folder)
iv_icon.visible()
cb_select.invisible()
ll_brief.gone()
} else {
iv_icon.invisible()
cb_select.visible()
if (localUri.contains(item.uri.toString())) {
iv_icon.setImageResource(R.drawable.ic_book_has)
iv_icon.visible()
cb_select.invisible()
} else {
iv_icon.invisible()
cb_select.visible()
}
ll_brief.visible()
tv_tag.text = item.name?.substringAfterLast(".")
tv_size.text = StringUtils.toSize(item.length())

Loading…
Cancel
Save