From 26b6309813afddedaa871c1d9b28c96aeb7e21c1 Mon Sep 17 00:00:00 2001 From: wqfantexi Date: Sat, 7 Mar 2020 22:47:36 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=B8=8B=E8=BD=BD?= =?UTF-8?q?=E8=BF=9B=E5=BA=A6=E6=8F=90=E7=A4=BA=20=20=E8=BF=9B=E5=BA=A620/?= =?UTF-8?q?100=EF=BC=8C=E6=88=90=E5=8A=9F18=EF=BC=8C=E7=AC=AC=E4=B8=89?= =?UTF-8?q?=E7=AB=A0=20=E5=86=B2=E5=A4=A9=E4=B8=80=E7=AC=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/service/DownloadService.kt | 37 +++++++++++++++++-- 1 file changed, 34 insertions(+), 3 deletions(-) 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 b5b983476..732506449 100644 --- a/app/src/main/java/io/legado/app/service/DownloadService.kt +++ b/app/src/main/java/io/legado/app/service/DownloadService.kt @@ -29,8 +29,10 @@ class DownloadService : BaseService() { private val handler = Handler() private var runnable: Runnable = Runnable { upDownload() } private val downloadMap = hashMapOf>() + private val downloadCount = hashMapOf(); private val finalMap = hashMapOf>() private var notificationContent = "正在启动下载" + private val notificationBuilder by lazy { val builder = NotificationCompat.Builder(this, AppConst.channelIdDownload) .setSmallIcon(R.drawable.ic_download) @@ -97,6 +99,11 @@ class DownloadService : BaseService() { finalMap.remove(bookUrl) } + private fun updateNotification(downloadCount:DownloadCount, totalCount: Int, content: String){ + notificationContent = + "进度:${downloadCount.downloadFinishedCount}/$totalCount,成功:${downloadCount.successCount},$content" + } + private fun download() { val task = Coroutine.async(this, context = searchPool) { downloadMap.forEach { entry -> @@ -106,6 +113,9 @@ class DownloadService : BaseService() { val bookSource = App.db.bookSourceDao().getBookSource(book.origin) ?: return@async val webBook = WebBook(bookSource) + + downloadCount[entry.key] = DownloadCount() + entry.value.forEach { chapter -> if (!isActive) return@async if (downloadMap.containsKey(book.bookUrl)) { @@ -116,16 +126,19 @@ class DownloadService : BaseService() { scope = this, context = searchPool ) - .onStart { - notificationContent = chapter.title - } + //.onStart { + // notificationContent = "启动:" + chapter.title + //} .onSuccess(IO) { content -> content?.let { + downloadCount[entry.key]?.increaseSuccess() BookHelp.saveContent(book, chapter, content) } } .onFinally(IO) { synchronized(this@DownloadService) { + downloadCount[entry.key]?.increaseFinished() + downloadCount[entry.key]?.let { updateNotification(it, entry.value.size, chapter.title) } val chapterMap = finalMap[book.bookUrl] ?: linkedSetOf().apply { @@ -135,9 +148,14 @@ class DownloadService : BaseService() { if (chapterMap.size == entry.value.size) { downloadMap.remove(book.bookUrl) finalMap.remove(book.bookUrl) + downloadCount.remove(entry.key) } } } + } else{ + //无需下载的,设置为增加成功 + downloadCount[entry.key]?.increaseSuccess() + downloadCount[entry.key]?.increaseFinished() } } } @@ -176,4 +194,17 @@ class DownloadService : BaseService() { val notification = builder.build() startForeground(AppConst.notificationIdDownload, notification) } +} + +class DownloadCount{ + @Volatile public var downloadFinishedCount = 0 // 下载完成的条目数量 + @Volatile public var successCount = 0 //下载成功的条目数量 + + fun increaseSuccess(){ + ++successCount; + } + + fun increaseFinished(){ + ++downloadFinishedCount; + } } \ No newline at end of file From 0f3580cfe3b9310082b449fd5f6da7b994d82e65 Mon Sep 17 00:00:00 2001 From: Celeter Date: Sun, 8 Mar 2020 18:10:03 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E5=8A=A0=E4=BA=86=E4=B8=8A=E4=B8=80?= =?UTF-8?q?=E7=AB=A0=E4=B8=8B=E4=B8=80=E7=AB=A0=E6=8C=89=E9=92=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/assets/web/bookshelf.html | 3 +++ app/src/main/assets/web/bookshelf.js | 20 ++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/app/src/main/assets/web/bookshelf.html b/app/src/main/assets/web/bookshelf.html index d5a37ae51..86639426f 100644 --- a/app/src/main/assets/web/bookshelf.html +++ b/app/src/main/assets/web/bookshelf.html @@ -28,6 +28,9 @@
+
+
+
diff --git a/app/src/main/assets/web/bookshelf.js b/app/src/main/assets/web/bookshelf.js index 19909b0f5..338332ab8 100644 --- a/app/src/main/assets/web/bookshelf.js +++ b/app/src/main/assets/web/bookshelf.js @@ -130,6 +130,25 @@ $('#showchapter').addEventListener("click", () => { window.location.hash = "#chapter"; }); +var now_chapter = -1; +$('#up').addEventListener('click', e => { + if (now_chapter > 0) { + now_chapter--; + let clickEvent = document.createEvent('MouseEvents'); + clickEvent.initEvent("click", true, false); + $('[data-index="' + now_chapter + '"]').dispatchEvent(clickEvent); + } +}); + +$('#down').addEventListener('click', e => { + if (now_chapter > -1) { + now_chapter++; + let clickEvent = document.createEvent('MouseEvents'); + clickEvent.initEvent("click", true, false); + $('[data-index="' + now_chapter + '"]').dispatchEvent(clickEvent); + } +}); + $('#chapter').addEventListener("click", (e) => { if (e.target.tagName === "BUTTON") { var url = e.target.getAttribute("data-url"); @@ -141,6 +160,7 @@ $('#chapter').addEventListener("click", (e) => { if (!index && (0 != index)) { alert("未取得章节索引"); } + now_chapter = parseInt(index); $("#content").innerHTML = "

" + name + " 加载中...

"; fetch(apiAddress("getBookContent", url, index), { mode: "cors" }) .then(res => res.json()) From 7e8cdac00601ea2a85918128069966dcd99d6865 Mon Sep 17 00:00:00 2001 From: Celeter Date: Sun, 8 Mar 2020 18:29:47 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/assets/web/bookshelf.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/src/main/assets/web/bookshelf.js b/app/src/main/assets/web/bookshelf.js index 338332ab8..02e90a6ab 100644 --- a/app/src/main/assets/web/bookshelf.js +++ b/app/src/main/assets/web/bookshelf.js @@ -6,6 +6,8 @@ , books ; +var now_chapter = -1; + var formatTime = value => { return new Date(value).toLocaleString('zh-CN', { hour12: false, year: "numeric", month: "2-digit", day: "2-digit", hour: "2-digit", minute: "2-digit", second: "2-digit" @@ -62,6 +64,7 @@ var init = () => { }); $$('#books img').forEach(bookImg => bookImg.addEventListener("click", () => { + now_chapter = -1 $('#allcontent').classList.add("read"); var book = books[bookImg.getAttribute("data-series-num")]; $("#info").innerHTML = ` @@ -130,7 +133,6 @@ $('#showchapter').addEventListener("click", () => { window.location.hash = "#chapter"; }); -var now_chapter = -1; $('#up').addEventListener('click', e => { if (now_chapter > 0) { now_chapter--;