diff --git a/app/src/main/java/io/legado/app/service/DownloadService.kt b/app/src/main/java/io/legado/app/service/DownloadService.kt
index 320c344ab..f8a03d2ea 100644
--- a/app/src/main/java/io/legado/app/service/DownloadService.kt
+++ b/app/src/main/java/io/legado/app/service/DownloadService.kt
@@ -67,6 +67,8 @@ class DownloadService : BaseService() {
tasks.clear()
searchPool.close()
handler.removeCallbacks(runnable)
+ downloadMap.clear()
+ finalMap.clear()
super.onDestroy()
postEvent(EventBus.UP_DOWNLOAD, downloadMap)
}
diff --git a/app/src/main/java/io/legado/app/ui/download/DownloadAdapter.kt b/app/src/main/java/io/legado/app/ui/download/DownloadAdapter.kt
index bdfecd0e3..7546c0563 100644
--- a/app/src/main/java/io/legado/app/ui/download/DownloadAdapter.kt
+++ b/app/src/main/java/io/legado/app/ui/download/DownloadAdapter.kt
@@ -1,11 +1,13 @@
package io.legado.app.ui.download
import android.content.Context
+import android.widget.ImageView
import io.legado.app.R
import io.legado.app.base.adapter.ItemViewHolder
import io.legado.app.base.adapter.SimpleRecyclerAdapter
import io.legado.app.data.entities.Book
import io.legado.app.data.entities.BookChapter
+import io.legado.app.service.help.Download
import kotlinx.android.synthetic.main.item_download.view.*
import org.jetbrains.anko.sdk27.listeners.onClick
import org.jetbrains.anko.toast
@@ -29,27 +31,48 @@ class DownloadAdapter(context: Context, private val callBack: CallBack) :
tv_download.text =
context.getString(R.string.download_count, cs.size, item.totalChapterNum)
}
+ upDownloadIv(iv_download, item)
} else {
val cacheSize = cacheChapters[item.bookUrl]?.size ?: 0
tv_download.text =
context.getString(R.string.download_count, cacheSize, item.totalChapterNum)
+ upDownloadIv(iv_download, item)
}
}
}
override fun registerListener(holder: ItemViewHolder) {
- holder.itemView.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)
+ 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 {
+ 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 {
fun export(position: Int)
}
diff --git a/app/src/main/res/layout/item_download.xml b/app/src/main/res/layout/item_download.xml
index 3d774e41e..8413da785 100644
--- a/app/src/main/res/layout/item_download.xml
+++ b/app/src/main/res/layout/item_download.xml
@@ -10,7 +10,7 @@
android:layout_width="0dp"
android:layout_height="wrap_content"
android:singleLine="true"
- app:layout_constraintRight_toLeftOf="@+id/tv_export"
+ app:layout_constraintRight_toLeftOf="@+id/iv_download"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent" />
@@ -19,7 +19,7 @@
android:layout_width="0dp"
android:layout_height="wrap_content"
android:singleLine="true"
- app:layout_constraintRight_toLeftOf="@+id/tv_export"
+ app:layout_constraintRight_toLeftOf="@+id/iv_download"
app:layout_constraintTop_toBottomOf="@+id/tv_name"
app:layout_constraintLeft_toLeftOf="parent" />
@@ -28,10 +28,23 @@
android:layout_width="0dp"
android:layout_height="wrap_content"
android:singleLine="true"
- app:layout_constraintRight_toLeftOf="@+id/tv_export"
+ app:layout_constraintRight_toLeftOf="@+id/iv_download"
app:layout_constraintTop_toBottomOf="@id/tv_author"
app:layout_constraintLeft_toLeftOf="parent" />
+
+