|
|
@ -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,27 +31,48 @@ 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 { |
|
|
|
getItem(holder.layoutPosition)?.let { |
|
|
|
iv_download.onClick { |
|
|
|
val cacheSize = cacheChapters[it.bookUrl]?.size ?: 0 |
|
|
|
getItem(holder.layoutPosition)?.let { |
|
|
|
if (cacheSize < it.totalChapterNum) { |
|
|
|
Download.start(context, it.bookUrl, 0, it.totalChapterNum) |
|
|
|
context.toast("未下载完成") |
|
|
|
} |
|
|
|
} else { |
|
|
|
} |
|
|
|
callBack.export(holder.layoutPosition) |
|
|
|
tv_export.onClick { |
|
|
|
|
|
|
|
getItem(holder.layoutPosition)?.let { |
|
|
|
|
|
|
|
val cacheSize = cacheChapters[it.bookUrl]?.size ?: 0 |
|
|
|
|
|
|
|
if (cacheSize < it.totalChapterNum) { |
|
|
|
|
|
|
|
context.toast("未下载完成") |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
callBack.export(holder.layoutPosition) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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) |
|
|
|
} |
|
|
|
} |
|
|
|