|
|
@ -1,11 +1,13 @@ |
|
|
|
package io.legado.app.ui.download |
|
|
|
package io.legado.app.ui.download |
|
|
|
|
|
|
|
|
|
|
|
import android.content.Context |
|
|
|
import android.content.Context |
|
|
|
|
|
|
|
import android.widget.ImageView |
|
|
|
import io.legado.app.R |
|
|
|
import io.legado.app.R |
|
|
|
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.Book |
|
|
|
import io.legado.app.data.entities.Book |
|
|
|
import io.legado.app.data.entities.BookChapter |
|
|
|
import io.legado.app.data.entities.BookChapter |
|
|
|
|
|
|
|
import io.legado.app.service.help.Download |
|
|
|
import kotlinx.android.synthetic.main.item_download.view.* |
|
|
|
import kotlinx.android.synthetic.main.item_download.view.* |
|
|
|
import org.jetbrains.anko.sdk27.listeners.onClick |
|
|
|
import org.jetbrains.anko.sdk27.listeners.onClick |
|
|
|
import org.jetbrains.anko.toast |
|
|
|
import org.jetbrains.anko.toast |
|
|
@ -29,16 +31,24 @@ class DownloadAdapter(context: Context, private val callBack: CallBack) : |
|
|
|
tv_download.text = |
|
|
|
tv_download.text = |
|
|
|
context.getString(R.string.download_count, cs.size, item.totalChapterNum) |
|
|
|
context.getString(R.string.download_count, cs.size, item.totalChapterNum) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
upDownloadIv(iv_download, item) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
val cacheSize = cacheChapters[item.bookUrl]?.size ?: 0 |
|
|
|
val cacheSize = cacheChapters[item.bookUrl]?.size ?: 0 |
|
|
|
tv_download.text = |
|
|
|
tv_download.text = |
|
|
|
context.getString(R.string.download_count, cacheSize, item.totalChapterNum) |
|
|
|
context.getString(R.string.download_count, cacheSize, item.totalChapterNum) |
|
|
|
|
|
|
|
upDownloadIv(iv_download, item) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override fun registerListener(holder: ItemViewHolder) { |
|
|
|
override fun registerListener(holder: ItemViewHolder) { |
|
|
|
holder.itemView.tv_export.onClick { |
|
|
|
holder.itemView.apply { |
|
|
|
|
|
|
|
iv_download.onClick { |
|
|
|
|
|
|
|
getItem(holder.layoutPosition)?.let { |
|
|
|
|
|
|
|
Download.start(context, it.bookUrl, 0, it.totalChapterNum) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
tv_export.onClick { |
|
|
|
getItem(holder.layoutPosition)?.let { |
|
|
|
getItem(holder.layoutPosition)?.let { |
|
|
|
val cacheSize = cacheChapters[it.bookUrl]?.size ?: 0 |
|
|
|
val cacheSize = cacheChapters[it.bookUrl]?.size ?: 0 |
|
|
|
if (cacheSize < it.totalChapterNum) { |
|
|
|
if (cacheSize < it.totalChapterNum) { |
|
|
@ -49,6 +59,19 @@ class DownloadAdapter(context: Context, private val callBack: CallBack) : |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private fun upDownloadIv(iv: ImageView, book: Book) { |
|
|
|
|
|
|
|
downloadMap?.let { |
|
|
|
|
|
|
|
if (it.containsKey(book.bookUrl)) { |
|
|
|
|
|
|
|
iv.setImageResource(R.drawable.ic_stop_black_24dp) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
iv.setImageResource(R.drawable.ic_play_24dp) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} ?: let { |
|
|
|
|
|
|
|
iv.setImageResource(R.drawable.ic_play_24dp) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
interface CallBack { |
|
|
|
interface CallBack { |
|
|
|
fun export(position: Int) |
|
|
|
fun export(position: Int) |
|
|
|