From 74f68f89078f7cf3cc145b57ca7c6054aab8ff18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=BA=90=E6=96=87=E9=9B=A8?= <41315874+fumiama@users.noreply.github.com> Date: Mon, 6 Nov 2023 02:47:29 +0900 Subject: [PATCH] =?UTF-8?q?v2.0.4=20=E4=BF=AE=E5=A4=8D=201.=20=E6=A8=AA?= =?UTF-8?q?=E5=90=91=E9=98=85=E8=A7=88=E6=BC=AB=E7=94=BB=E6=97=A0=E6=B3=95?= =?UTF-8?q?=E7=94=A8=E9=9F=B3=E9=87=8F=E9=94=AE=E7=BF=BB=E9=A1=B5(fix=20#3?= =?UTF-8?q?5)=202.=20=E7=BA=B5=E5=90=91=E6=81=A2=E5=A4=8D=E9=98=85?= =?UTF-8?q?=E8=A7=88=E8=BF=9B=E5=BA=A6=E9=94=99=E4=BD=8D=203.=20=E4=B8=80?= =?UTF-8?q?=E4=B8=AA=E4=BB=A5=E4=B8=8A=E5=88=86=E5=8D=B7=E7=9A=84=E6=BC=AB?= =?UTF-8?q?=E7=94=BB=E6=9C=80=E5=90=8E=E4=B8=80=E4=B8=AA=E7=AB=A0=E8=8A=82?= =?UTF-8?q?=E4=B8=BA=E5=A5=87=E6=95=B0=E6=97=B6=E6=97=A0=E6=B3=95=E6=98=BE?= =?UTF-8?q?=E7=A4=BA(=E5=A6=82=E5=A6=96=E5=BF=8D=E4=B8=89=E9=87=8D?= =?UTF-8?q?=E5=A5=8F)=204.=20=E4=B8=8B=E8=BD=BD=E9=A1=B5=E9=98=85=E8=A7=88?= =?UTF-8?q?=E5=B7=B2=E4=B8=8B=E8=BD=BD=E6=BC=AB=E7=94=BB=E5=8A=A0=E8=BD=BD?= =?UTF-8?q?=E4=B8=8B=E4=B8=80=E7=AB=A0=E5=A4=B1=E8=B4=A5=205.=20=E7=AB=96?= =?UTF-8?q?=E5=90=91=E9=98=85=E8=A7=88=E5=8F=AA=E6=9C=89=E4=B8=80=E9=A1=B5?= =?UTF-8?q?=E6=97=B6=E5=87=86=E5=A4=87=E4=B8=AD=E5=BC=B9=E6=A1=86=E4=B8=8D?= =?UTF-8?q?=E6=B6=88=E5=A4=B1=20=E4=BC=98=E5=8C=96=201.=20PagesManager=20?= =?UTF-8?q?=E5=86=85=E5=AD=98=E5=8D=A0=E7=94=A8=202.=20=E5=88=86=E7=B1=BB?= =?UTF-8?q?=E9=A1=B5=E9=BB=98=E8=AE=A4=E6=98=BE=E7=A4=BA=E6=9C=80=E6=96=B0?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=97=B6=E9=97=B4=203.=20=E4=B8=BB=E9=A1=B5?= =?UTF-8?q?=E3=80=81=E6=BC=AB=E7=94=BB=E8=AF=A6=E6=83=85=E9=A1=B5=E5=8A=A0?= =?UTF-8?q?=E8=BD=BD=E6=B5=81=E7=95=85=E5=BA=A6=204.=20=E7=99=BB=E5=BD=95?= =?UTF-8?q?=E9=A1=B5=E4=BD=BF=E7=94=A8=E5=8D=8F=E7=A8=8B=E9=87=8D=E6=9E=84?= =?UTF-8?q?(#36)=20by=20@Mrs4s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/build.gradle | 6 +- .../top/fumiama/copymanga/LoginActivity.kt | 2 - .../fumiama/copymanga/template/ui/CardList.kt | 3 +- .../fumiama/copymanga/ui/book/BookHandler.kt | 178 ++++++++++-------- .../ui/cardflow/sort/SortFragment.kt | 2 +- .../copymanga/ui/comicdl/ComicDlFragment.kt | 58 +++--- .../copymanga/ui/comicdl/ComicDlHandler.kt | 7 +- .../fumiama/copymanga/ui/home/HomeFragment.kt | 3 +- .../fumiama/copymanga/ui/home/HomeHandler.kt | 18 +- .../top/fumiama/copymanga/ui/vm/VMHandler.kt | 40 ++-- .../copymanga/ui/vm/ViewMangaActivity.kt | 25 +-- .../fumiama/copymanga/views/ScaleImageView.kt | 4 +- 12 files changed, 187 insertions(+), 159 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 673fd6c..7d9a344 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -8,8 +8,8 @@ android { applicationId 'top.fumiama.copymanga' minSdkVersion 23 targetSdkVersion 34 - versionCode 39 - versionName '2.0.3' + versionCode 40 + versionName '2.0.4' resConfigs 'zh', 'zh-rCN' testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" @@ -74,5 +74,5 @@ dependencies { implementation 'com.liaoinstan.springview:library:1.7.0' implementation 'com.github.zawadz88.materialpopupmenu:material-popup-menu:4.0.1' implementation 'com.lapism:search:2.4.1@aar' - implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.6.1' + implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.6.2' } diff --git a/app/src/main/java/top/fumiama/copymanga/LoginActivity.kt b/app/src/main/java/top/fumiama/copymanga/LoginActivity.kt index b19cedb..ee29040 100644 --- a/app/src/main/java/top/fumiama/copymanga/LoginActivity.kt +++ b/app/src/main/java/top/fumiama/copymanga/LoginActivity.kt @@ -6,9 +6,7 @@ import android.widget.Toast import androidx.appcompat.app.AppCompatActivity import androidx.lifecycle.lifecycleScope import kotlinx.android.synthetic.main.activity_login.* -import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch -import kotlinx.coroutines.withContext import top.fumiama.dmzj.copymanga.R import kotlin.random.Random diff --git a/app/src/main/java/top/fumiama/copymanga/template/ui/CardList.kt b/app/src/main/java/top/fumiama/copymanga/template/ui/CardList.kt index ebe2292..df7f53a 100644 --- a/app/src/main/java/top/fumiama/copymanga/template/ui/CardList.kt +++ b/app/src/main/java/top/fumiama/copymanga/template/ui/CardList.kt @@ -10,7 +10,6 @@ import com.bumptech.glide.load.model.GlideUrl import kotlinx.android.synthetic.main.card_book.view.* import kotlinx.android.synthetic.main.line_horizonal_empty.view.* import kotlinx.android.synthetic.main.line_lazybooklines.* -import top.fumiama.copymanga.MainActivity.Companion.mainWeakReference import top.fumiama.copymanga.tools.api.CMApi import top.fumiama.dmzj.copymanga.R import java.io.File @@ -76,7 +75,7 @@ class CardList( if (exitCardList) return manageRow() that?.apply { - layoutInflater.inflate(R.layout.card_book, mydll.ltbtn, false)?.let { + layoutInflater.inflate(R.layout.card_book, mydll?.ltbtn, false)?.let { val card = it.cic card.name = name card.append = append diff --git a/app/src/main/java/top/fumiama/copymanga/ui/book/BookHandler.kt b/app/src/main/java/top/fumiama/copymanga/ui/book/BookHandler.kt index 2097d64..2628ed5 100644 --- a/app/src/main/java/top/fumiama/copymanga/ui/book/BookHandler.kt +++ b/app/src/main/java/top/fumiama/copymanga/ui/book/BookHandler.kt @@ -73,9 +73,12 @@ class BookHandler(private val th: WeakReference, val path: String) 1 -> setCover() 2 -> setTexts() 3 -> that?.fbibinfo?.let { setInfoHeight(it) } - 4 -> setThemes() + 4 -> setAuthorsAndTags() 5 -> setOverScale() 6 -> if(complete) that?.navigate2dl() + 7 -> setVolumes() + 8 -> that?.apply { fbl?.addView(msg.obj as View) } + 9 -> endSetLayouts() } } @@ -108,14 +111,14 @@ class BookHandler(private val th: WeakReference, val path: String) cnts += it.count Log.d("MyBFH", "Add caption: ${it.name} @ ${it.path_word} of ${it.count}") } + for (i in 1..5) { + sendEmptyMessageDelayed(i, (100*i).toLong()) + } if(vols?.isEmpty() != false) initComicData() - Thread{ for (i in 1..5) { - sleep(512) - sendEmptyMessage(i) - } }.start() } - private fun endSetLayouts(){ + private fun endSetLayouts() { + if (exit) return that?.fbloading?.visibility = View.GONE complete = true that?.setStartRead() @@ -230,76 +233,92 @@ class BookHandler(private val th: WeakReference, val path: String) } } - private fun setThemes(){ - if (exit) return + private fun setAuthorsAndTags() { that?.apply { book?.results?.comic?.apply { - author?.let { setTheme(getString(R.string.author), it, R.id.action_nav_book_to_nav_author) } + author?.let { + setTheme( + getString(R.string.author), + it, + R.id.action_nav_book_to_nav_author + ) + } fbl.addView(layoutInflater.inflate(R.layout.div_h, fbl, false)) - theme?.let { setTheme(getString(R.string.caption), it, R.id.action_nav_book_to_nav_caption) } + theme?.let { + setTheme( + getString(R.string.caption), + it, + R.id.action_nav_book_to_nav_caption + ) + } } } - Thread{ - while (vols == null && !exit) sleep(1000) - if(exit) return@Thread - that?.apply { - book?.results?.apply { - that?.activity?.runOnUiThread{ - if(exit) return@runOnUiThread - ViewMangaActivity.fileArray = arrayOf() - urlArray = arrayOf() - ViewMangaActivity.uuidArray = arrayOf() - var i = 0 - vols?.forEachIndexed { iv, v -> - if(exit) return@runOnUiThread - fbl.addView(layoutInflater.inflate(R.layout.div_h, fbl, false)) - val t = layoutInflater.inflate(R.layout.line_caption, fbl, false) - t.tcptn.text = keys[iv] - fbl.addView(t) - fbl.addView(layoutInflater.inflate(R.layout.div_h, fbl, false)) - var line: View? = null - val last = v.results.list.size - 1 - v.results.list.forEach { - urlArray += CMApi.getChapterInfoApiUrl( - comic.path_word, - it.uuid - )?:"" - ViewMangaActivity.fileArray += CMApi.getZipFile(context?.getExternalFilesDir(""), comic.name, keys[iv], it.name) - chapterNames += it.name - ViewMangaActivity.uuidArray += it.uuid - if(line == null) { - if(i == last) { - line = layoutInflater.inflate(R.layout.line_chapter, that!!.fbl, false) - line?.lcc?.apply { - lct.text = it.name - val index = i - setOnClickListener { Reader.viewMangaAt(comic.name, index, urlArray) } - } - fbl?.addView(line) - } else { - line = layoutInflater.inflate(R.layout.line_2chapters, that!!.fbl, false) - line?.l2cl?.apply { - lct.text = it.name - val index = i - setOnClickListener { Reader.viewMangaAt(comic.name, index, urlArray) } - } - } - } else line?.l2cr?.apply { + } + + private fun addVolumesView(v: View) { + obtainMessage(8, v).sendToTarget() + } + + private fun setVolumes() = Thread { + if (exit) return@Thread + that?.apply { + book?.results?.apply { + ViewMangaActivity.fileArray = arrayOf() + urlArray = arrayOf() + ViewMangaActivity.uuidArray = arrayOf() + var i = 0 + var last = -1 + vols?.forEachIndexed { groupIndex, v -> + if(exit) return@Thread + addVolumesView(layoutInflater.inflate(R.layout.div_h, fbl, false)) + val t = layoutInflater.inflate(R.layout.line_caption, fbl, false) + t.tcptn.text = keys[groupIndex] + addVolumesView(t) + addVolumesView(layoutInflater.inflate(R.layout.div_h, fbl, false)) + var line: View? = null + last += v.results.list.size + v.results.list.forEach { + urlArray += CMApi.getChapterInfoApiUrl( + comic.path_word, + it.uuid + )?:"" + ViewMangaActivity.fileArray += CMApi.getZipFile(context?.getExternalFilesDir(""), comic.name, keys[groupIndex], it.name) + chapterNames += it.name + ViewMangaActivity.uuidArray += it.uuid + Log.d("MyBH", "i = $i, last=$last, add chapter ${it.name}, line is null: ${line == null}") + if(line == null) { + if(i == last) { + line = layoutInflater.inflate(R.layout.line_chapter, that!!.fbl, false) + line?.lcc?.apply { + lct.text = it.name + Log.d("MyBH", "add last single chapter ${it.name}") + val index = i + setOnClickListener { Reader.viewMangaAt(comic.name, index, urlArray) } + } + line?.let { l -> addVolumesView(l) } + + } else { + line = layoutInflater.inflate(R.layout.line_2chapters, that!!.fbl, false) + line?.l2cl?.apply { lct.text = it.name val index = i setOnClickListener { Reader.viewMangaAt(comic.name, index, urlArray) } - fbl?.addView(line) - line = null } - i++ } + } else line?.l2cr?.apply { + lct.text = it.name + val index = i + setOnClickListener { Reader.viewMangaAt(comic.name, index, urlArray) } + line?.let { l -> addVolumesView(l) } + line = null } - endSetLayouts() + i++ } } + sendEmptyMessage(9) // end set layout } - }.start() - } + } + }.start() private fun loadVolume(name: String, path: String, nav: Int){ if(complete) { @@ -311,7 +330,7 @@ class BookHandler(private val th: WeakReference, val path: String) } } - private fun initComicData() { + private fun initComicData() = Thread { var volumes = emptyArray() val counts = cnts.clone() gpws.forEachIndexed { i, gpw -> @@ -329,11 +348,11 @@ class BookHandler(private val th: WeakReference, val path: String) counts[i] = counts[i] - 100 CMApi.getGroupInfoApiUrl(path, gpw, offset)?.let { Log.d("MyBFH", "get api: $it") - if(ComicDlFragment.exit) return + if(ComicDlFragment.exit) return@Thread val ad = AutoDownloadThread(it) { result -> - Log.d("MyBFH", "第${i}卷返回") val r = Gson().fromJson(result?.decodeToString(), VolumeStructure::class.java) re[r.results.offset / 100] = r + Log.d("MyBFH", "第${i}卷返回, 大小: ${r.results.list.size}") } ads += ad ad.start() @@ -341,7 +360,6 @@ class BookHandler(private val th: WeakReference, val path: String) sleep(1000) } } while (counts[i] > 0) - Thread { var c = 0 while (c++ < 80) { sleep(1000) @@ -359,23 +377,21 @@ class BookHandler(private val th: WeakReference, val path: String) r?.results?.list = s r?.apply { volumes += this } } else re[0]?.apply { volumes += this } - }.start() } - Thread { - var c = 0 - while (c < 80 && volumes.size != gpws.size) { - sleep(1000) - if(ComicDlFragment.exit) return@Thread - Log.d("MyBFH", "已有:${volumes.size} 共:${gpws.size}") - c++ + var c = 0 + while (c < 80 && volumes.size != gpws.size) { + sleep(1000) + if(ComicDlFragment.exit) return@Thread + Log.d("MyBFH", "已有:${volumes.size} 共:${gpws.size}") + c++ + } + if (volumes.size == gpws.size) { + that?.activity?.runOnUiThread { + saveVolumes(volumes) + sendEmptyMessage(7) } - if (volumes.size == gpws.size) { - that?.activity?.runOnUiThread { - saveVolumes(volumes) - } - } - }.start() - } + } + }.start() private fun saveVolumes(volumes: Array) { that?.context?.getExternalFilesDir("")?.let { home -> diff --git a/app/src/main/java/top/fumiama/copymanga/ui/cardflow/sort/SortFragment.kt b/app/src/main/java/top/fumiama/copymanga/ui/cardflow/sort/SortFragment.kt index 992c536..9adbf95 100644 --- a/app/src/main/java/top/fumiama/copymanga/ui/cardflow/sort/SortFragment.kt +++ b/app/src/main/java/top/fumiama/copymanga/ui/cardflow/sort/SortFragment.kt @@ -15,7 +15,7 @@ import java.lang.Thread.sleep @ExperimentalStdlibApi class SortFragment : InfoCardLoader(R.layout.fragment_sort, R.id.action_nav_sort_to_nav_book) { - private val sortWay = listOf("datetime_updated", "-datetime_updated", "-popular", "popular") + private val sortWay = listOf("-datetime_updated", "datetime_updated", "-popular", "popular") private var theme = -1 private var region = -1 private var sortValue = 0 diff --git a/app/src/main/java/top/fumiama/copymanga/ui/comicdl/ComicDlFragment.kt b/app/src/main/java/top/fumiama/copymanga/ui/comicdl/ComicDlFragment.kt index ce1f137..a2fff93 100644 --- a/app/src/main/java/top/fumiama/copymanga/ui/comicdl/ComicDlFragment.kt +++ b/app/src/main/java/top/fumiama/copymanga/ui/comicdl/ComicDlFragment.kt @@ -86,7 +86,7 @@ class ComicDlFragment: NoBackRefreshFragment(R.layout.fragment_dlcomic) { menu.findItem(R.id.action_download)?.isVisible = false }*/ - private fun initComicData(pw: String?, gpws: Array?, counts: IntArray?) { + private fun initComicData(pw: String?, gpws: Array?, counts: IntArray?) = Thread { var volumes = emptyArray() if (gpws != null) { gpws.forEachIndexed { i, gpw -> @@ -99,7 +99,7 @@ class ComicDlFragment: NoBackRefreshFragment(R.layout.fragment_dlcomic) { do { counts?.set(i, counts[i] - 100) CMApi.getGroupInfoApiUrl(pw, gpw, offset)?.let { - if(exit) return + if(exit) return@Thread val ad = AutoDownloadThread(it) { result -> Log.d("MyCDF", "第${i}卷返回") val r = Gson().fromJson(result?.decodeToString(), VolumeStructure::class.java) @@ -110,42 +110,38 @@ class ComicDlFragment: NoBackRefreshFragment(R.layout.fragment_dlcomic) { offset += 100 } } while ((counts?.get(i) ?: 0) > 0) - Thread { - var c = 0 - while (c++ < 80) { - sleep(1000) - if(exit) return@Thread - if(re.all { it != null }) break - } - if(re.size > 1) { - val r = re[0] - var s = emptyArray() - re.forEach { - it?.results?.list?.forEach { - s += it - } - } - r?.results?.list = s - r?.apply { volumes += this } - } else re[0]?.apply { volumes += this } - }.start() - } - Thread { var c = 0 - while (c < 80 && volumes.size != gpws.size) { + while (c++ < 80) { sleep(1000) if(exit) return@Thread - Log.d("MyCDF", "已有:${volumes.size} 共:${gpws.size}") - c++ + if(re.all { it != null }) break } - if (volumes.size == gpws.size) { - activity?.runOnUiThread { - start2load(volumes) + if(re.size > 1) { + val r = re[0] + var s = emptyArray() + re.forEach { + it?.results?.list?.forEach { + s += it + } } + r?.results?.list = s + r?.apply { volumes += this } + } else re[0]?.apply { volumes += this } + } + var c = 0 + while (c < 80 && volumes.size != gpws.size) { + sleep(1000) + if(exit) return@Thread + Log.d("MyCDF", "已有:${volumes.size} 共:${gpws.size}") + c++ + } + if (volumes.size == gpws.size) { + activity?.runOnUiThread { + start2load(volumes) } - }.start() + } } - } + }.start() private fun initOldComicData() { handler = ComicDlHandler(Looper.myLooper()!!, diff --git a/app/src/main/java/top/fumiama/copymanga/ui/comicdl/ComicDlHandler.kt b/app/src/main/java/top/fumiama/copymanga/ui/comicdl/ComicDlHandler.kt index dcc5d6d..f700775 100644 --- a/app/src/main/java/top/fumiama/copymanga/ui/comicdl/ComicDlHandler.kt +++ b/app/src/main/java/top/fumiama/copymanga/ui/comicdl/ComicDlHandler.kt @@ -352,10 +352,9 @@ class ComicDlHandler(looper: Looper, private val th: WeakReference) : AutoDownloadH } } - private fun inflateCardLines() { + private fun inflateCardLines() = Thread{ if (indexLines.isNotEmpty()) indexLines = arrayOf() inflateRec() inflateTopics() @@ -220,14 +220,12 @@ class HomeHandler(private val that: WeakReference) : AutoDownloadH inflateNew() inflateFinish() inflateRank() - Thread{ - for(i in indexLines.indices) { - obtainMessage(8, i, 0).sendToTarget() - sleep(512) - } - obtainMessage(-1, false).sendToTarget() //closeLoad - }.start() - } + for(i in indexLines.indices) { + obtainMessage(8, i, 0).sendToTarget() + sleep(512) + } + obtainMessage(-1, false).sendToTarget() //closeLoad + }.start() private fun setBanner(v: Banner): Banner { v.viewTreeObserver.addOnGlobalLayoutListener(object : @@ -311,7 +309,7 @@ class HomeHandler(private val that: WeakReference) : AutoDownloadH private fun setCards(cv: CardView, pw: String, name: String, img: String, isFinal: Boolean, isTopic: Boolean) { cv.tic.text = name homeF?.let { - if(img.startsWith("http")) { + if(img.startsWith("http")) it.activity?.runOnUiThread { Glide.with(it).load(GlideUrl(CMApi.proxy?.wrap(img)?:img, CMApi.myGlideHeaders)).timeout(20000).into(cv.imic) } } diff --git a/app/src/main/java/top/fumiama/copymanga/ui/vm/VMHandler.kt b/app/src/main/java/top/fumiama/copymanga/ui/vm/VMHandler.kt index 94c0cd4..ec333e1 100644 --- a/app/src/main/java/top/fumiama/copymanga/ui/vm/VMHandler.kt +++ b/app/src/main/java/top/fumiama/copymanga/ui/vm/VMHandler.kt @@ -27,6 +27,7 @@ import java.lang.Thread.sleep import java.lang.ref.WeakReference import java.text.SimpleDateFormat import java.util.* +import java.util.concurrent.atomic.AtomicInteger class VMHandler(activity: ViewMangaActivity, url: String) : AutoDownloadHandler( url, Chapter2Return::class.java, Looper.myLooper()!! @@ -59,6 +60,7 @@ class VMHandler(activity: ViewMangaActivity, url: String) : AutoDownloadHandler( else -> "" } } + private var remainingImageCount = 0 @SuppressLint("SimpleDateFormat", "SetTextI18n") override fun handleMessage(msg: Message) { @@ -81,13 +83,14 @@ class VMHandler(activity: ViewMangaActivity, url: String) : AutoDownloadHandler( //simg.setHeight2FitImgWidth() //if(msg.arg2 == 1) sendEmptyMessage(DELAYED_RESTORE_PAGE_NUMBER) } - CLEAR_IMG_ON -> wv.get()?.clearImgOn(msg.obj as ScaleImageView) + CLEAR_IMG_ON -> { + val img = msg.obj as ScaleImageView + img.visibility = View.GONE + //sendEmptyMessage(DECREASE_IMAGE_COUNT_AND_RESTORE_PAGE_NUMBER_AT_ZERO) + } PREPARE_LAST_PAGE -> wv.get()?.prepareLastPage(msg.arg1, msg.arg2) DIALOG_SHOW -> dl.show() - DELAYED_RESTORE_PAGE_NUMBER -> Thread{ - sleep(233) - sendEmptyMessage(RESTORE_PAGE_NUMBER) - }.start() + LOAD_ITEM_SCROLL_MODE -> loadScrollMode(msg.arg1) LOAD_SCROLL_MODE -> loadScrollMode() LOAD_ITEM_IMAGES_INTO_LINE -> loadImagesIntoLine(msg.arg1) @@ -97,7 +100,8 @@ class VMHandler(activity: ViewMangaActivity, url: String) : AutoDownloadHandler( wv.get()?.restorePN() } LOAD_PAGE_FROM_ITEM -> { - val item = (pn - 1) / (wv.get()?.verticalLoadMaxCount?:20) * (wv.get()?.verticalLoadMaxCount?:20) + val verticalMaxCount = wv.get()?.verticalLoadMaxCount?:20 + val item = (pn - 1) / verticalMaxCount * verticalMaxCount loadScrollMode(item) Log.d("MyVMH", "Load page from $item") } @@ -113,6 +117,17 @@ class VMHandler(activity: ViewMangaActivity, url: String) : AutoDownloadHandler( } else { showInfCardFull(); true } + INIT_IMAGE_COUNT -> { + remainingImageCount = msg.arg1 + Log.d("MyVMH", "init remainingImageCount = $remainingImageCount") + } + DECREASE_IMAGE_COUNT_AND_RESTORE_PAGE_NUMBER_AT_ZERO -> { + if (--remainingImageCount == 0) { + Log.d("MyVMH", "last load page, restore pn...") + sendEmptyMessageDelayed(RESTORE_PAGE_NUMBER, 233) + } + Log.d("MyVMH", "remainingImageCount = $remainingImageCount") + } SET_NET_INFO -> wv.get()?.idtime?.text = SimpleDateFormat("HH:mm").format(Date()) + week + wv.get()?.toolsBox?.netInfo } } @@ -176,20 +191,21 @@ class VMHandler(activity: ViewMangaActivity, url: String) : AutoDownloadHandler( wv.get()?.initManga() wv.get()?.vprog?.visibility = View.GONE } - private fun loadImagesIntoLine(item: Int = (wv.get()?.currentItem?:0), maxCount: Int = (wv.get()?.verticalLoadMaxCount?:20)) /*= Thread*/{ + private fun loadImagesIntoLine(item: Int = (wv.get()?.currentItem?:0), maxCount: Int = (wv.get()?.verticalLoadMaxCount?:20)) = Thread{ Log.d("MyVMH", "Fun: loadImagesIntoLine($item, $maxCount)") wv.get()?.realCount?.let { count -> if(count > 0){ val notFull = item + maxCount > count val loadCount = (if(notFull) count - item else maxCount) - 1 + obtainMessage(INIT_IMAGE_COUNT, loadCount+1, 0).sendToTarget() Log.d("MyVMH", "count: $count, loadCount: $loadCount, notFull: $notFull") if(loadCount >= 0) for(i in 0..loadCount) obtainMessage(LOAD_IMG_ON,item + i, if(i == loadCount - 1) 1 else 0, wv.get()?.scrollImages?.get(i)).sendToTarget() - else sendEmptyMessage(DELAYED_RESTORE_PAGE_NUMBER) + //else sendEmptyMessageDelayed(RESTORE_PAGE_NUMBER, 233) if(notFull) obtainMessage(PREPARE_LAST_PAGE, loadCount + 1, maxCount).sendToTarget() - wv.get()?.updateSeekBar() + wv.get()?.let { it.runOnUiThread { it.updateSeekBar() } } } } - }//.start() + }.start() private fun loadScrollMode() { sendEmptyMessage(DIALOG_SHOW) @@ -233,7 +249,7 @@ class VMHandler(activity: ViewMangaActivity, url: String) : AutoDownloadHandler( const val CLEAR_IMG_ON = 5 const val PREPARE_LAST_PAGE = 6 const val DIALOG_SHOW = 7 - const val DELAYED_RESTORE_PAGE_NUMBER = 8 + //const val DELAYED_RESTORE_PAGE_NUMBER = 8 const val LOAD_ITEM_SCROLL_MODE = 9 const val LOAD_SCROLL_MODE = 10 const val LOAD_ITEM_IMAGES_INTO_LINE = 11 @@ -244,6 +260,8 @@ class VMHandler(activity: ViewMangaActivity, url: String) : AutoDownloadHandler( const val HIDE_INFO_CARD_FULL = 16 const val SHOW_INFO_CARD_FULL = 17 const val TRIGGER_INFO_CARD_FULL = 18 + const val INIT_IMAGE_COUNT = 19 + const val DECREASE_IMAGE_COUNT_AND_RESTORE_PAGE_NUMBER_AT_ZERO = 20 const val SET_NET_INFO = 22 } diff --git a/app/src/main/java/top/fumiama/copymanga/ui/vm/ViewMangaActivity.kt b/app/src/main/java/top/fumiama/copymanga/ui/vm/ViewMangaActivity.kt index 6406524..c98cbf7 100644 --- a/app/src/main/java/top/fumiama/copymanga/ui/vm/ViewMangaActivity.kt +++ b/app/src/main/java/top/fumiama/copymanga/ui/vm/ViewMangaActivity.kt @@ -92,7 +92,7 @@ class ViewMangaActivity : TitleActivityTemplate() { private var indexMap = intArrayOf() private var volTurnPage = false private var am: AudioManager? = null - private var pm: PagesManager? = null + var pm: PagesManager? = null private var fullyHideInfo = false val realCount get() = if(cut) indexMap.size else count @@ -171,10 +171,11 @@ class ViewMangaActivity : TitleActivityTemplate() { ) } - fun restorePN(){ + fun restorePN() { if (isPnValid) { isInScroll = false pageNum = pn + Log.d("MyVM", "restore pageNum to $pn") pn = -1 } setProgress() @@ -342,9 +343,10 @@ class ViewMangaActivity : TitleActivityTemplate() { } } - fun clearImgOn(imgView: ScaleImageView){ + /*fun clearImgOn(imgView: ScaleImageView){ imgView.visibility = View.GONE - } + handler.sendEmptyMessage(VMHandler.DECREASE_IMAGE_COUNT_AND_RESTORE_PAGE_NUMBER_AT_ZERO) + }*/ //private fun getTempFile(position: Int) = File(cacheDir, "$position") @@ -362,13 +364,14 @@ class ViewMangaActivity : TitleActivityTemplate() { private fun cutBitmap(bitmap: Bitmap, isEnd: Boolean) = Bitmap.createBitmap(bitmap, if(!isEnd) 0 else (bitmap.width/2), 0, bitmap.width/2, bitmap.height) - private fun loadImg(imgView: ScaleImageView, bitmap: Bitmap, isLast: Int = 0, useCut: Boolean, isLeft: Boolean, isPlaceholder: Boolean = true){ - val bitmap2load = if(useCut) cutBitmap(bitmap, isLeft) else bitmap + private fun loadImg(imgView: ScaleImageView, bitmap: Bitmap, isLast: Int = 0, useCut: Boolean, isLeft: Boolean, isPlaceholder: Boolean = true) { + val bitmap2load = if(!isPlaceholder && useCut) cutBitmap(bitmap, isLeft) else bitmap runOnUiThread { imgView.setImageBitmap(bitmap2load) - if(isVertical){ + if(!isPlaceholder && isVertical) { imgView.setHeight2FitImgWidth() - if (!isPlaceholder && isLast == 1) handler.sendEmptyMessage(VMHandler.DELAYED_RESTORE_PAGE_NUMBER) + handler.sendEmptyMessage(VMHandler.DECREASE_IMAGE_COUNT_AND_RESTORE_PAGE_NUMBER_AT_ZERO) + //if (!isPlaceholder && isLast == 1) handler.sendEmptyMessageDelayed(VMHandler.RESTORE_PAGE_NUMBER, 233) } } } @@ -410,8 +413,8 @@ class ViewMangaActivity : TitleActivityTemplate() { if(data != null && data.isNotEmpty()) { BitmapFactory.decodeByteArray(data, 0, data.size)?.let { loadImg(imgView, it, isLast, useCut, isLeft, false) - Log.d("MyVM", "Load from task") - }?:Log.d("MyVM", "null bitmap") + Log.d("MyVM", "Load position $position from task") + }?:Log.d("MyVM", "null bitmap at $position") } else getImgUrl(index2load)?.let { loadImgUrlInto(imgView, it, isLast, useCut, isLeft) } }.start() @@ -586,11 +589,11 @@ class ViewMangaActivity : TitleActivityTemplate() { @ExperimentalStdlibApi private fun prepareIdBtVH() { idtbvh.isChecked = isVertical + pm = PagesManager(WeakReference(this)) if (isVertical) { val vsps = vsp as SpringView vsps.footerView.lht.text = "更多" vsps.headerView.lht.text = "更多" - pm = PagesManager(WeakReference(this)) vsps.setListener(object :SpringView.OnFreshListener{ override fun onLoadmore() { //scrollForward() diff --git a/app/src/main/java/top/fumiama/copymanga/views/ScaleImageView.kt b/app/src/main/java/top/fumiama/copymanga/views/ScaleImageView.kt index 85042c5..108357c 100644 --- a/app/src/main/java/top/fumiama/copymanga/views/ScaleImageView.kt +++ b/app/src/main/java/top/fumiama/copymanga/views/ScaleImageView.kt @@ -679,7 +679,7 @@ class ScaleImageView : ImageView { override fun onSingleTapConfirmed(event: MotionEvent): Boolean { if(v == null) { v = ViewMangaActivity.va - v?.let { pm = PagesManager(it) } + v?.get()?.let { pm = it.pm } } //触发点击 if (mOnClickListener != null) { @@ -1632,6 +1632,6 @@ class ScaleImageView : ImageView { */ const val PINCH_MODE_SCALE = 2 - var pm:PagesManager? = null + var pm: PagesManager? = null } } \ No newline at end of file