1
0
mirror of https://github.com/fumiama/copymanga.git synced 2026-06-25 13:10:23 +08:00
修复
1. 横向阅览漫画无法用音量键翻页(fix #35)
2. 纵向恢复阅览进度错位
3. 一个以上分卷的漫画最后一个章节为奇数时无法显示(如妖忍三重奏)
4. 下载页阅览已下载漫画加载下一章失败
5. 竖向阅览只有一页时准备中弹框不消失
优化
1. PagesManager 内存占用
2. 分类页默认显示最新更新时间
3. 主页、漫画详情页加载流畅度
4. 登录页使用协程重构(#36) by @Mrs4s
This commit is contained in:
源文雨
2023-11-06 02:47:29 +09:00
parent 57e981356f
commit 74f68f8907
12 changed files with 187 additions and 159 deletions

View File

@@ -8,8 +8,8 @@ android {
applicationId 'top.fumiama.copymanga' applicationId 'top.fumiama.copymanga'
minSdkVersion 23 minSdkVersion 23
targetSdkVersion 34 targetSdkVersion 34
versionCode 39 versionCode 40
versionName '2.0.3' versionName '2.0.4'
resConfigs 'zh', 'zh-rCN' resConfigs 'zh', 'zh-rCN'
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
@@ -74,5 +74,5 @@ dependencies {
implementation 'com.liaoinstan.springview:library:1.7.0' implementation 'com.liaoinstan.springview:library:1.7.0'
implementation 'com.github.zawadz88.materialpopupmenu:material-popup-menu:4.0.1' implementation 'com.github.zawadz88.materialpopupmenu:material-popup-menu:4.0.1'
implementation 'com.lapism:search:2.4.1@aar' 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'
} }

View File

@@ -6,9 +6,7 @@ import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.lifecycleScope import androidx.lifecycle.lifecycleScope
import kotlinx.android.synthetic.main.activity_login.* import kotlinx.android.synthetic.main.activity_login.*
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import top.fumiama.dmzj.copymanga.R import top.fumiama.dmzj.copymanga.R
import kotlin.random.Random import kotlin.random.Random

View File

@@ -10,7 +10,6 @@ import com.bumptech.glide.load.model.GlideUrl
import kotlinx.android.synthetic.main.card_book.view.* import kotlinx.android.synthetic.main.card_book.view.*
import kotlinx.android.synthetic.main.line_horizonal_empty.view.* import kotlinx.android.synthetic.main.line_horizonal_empty.view.*
import kotlinx.android.synthetic.main.line_lazybooklines.* import kotlinx.android.synthetic.main.line_lazybooklines.*
import top.fumiama.copymanga.MainActivity.Companion.mainWeakReference
import top.fumiama.copymanga.tools.api.CMApi import top.fumiama.copymanga.tools.api.CMApi
import top.fumiama.dmzj.copymanga.R import top.fumiama.dmzj.copymanga.R
import java.io.File import java.io.File
@@ -76,7 +75,7 @@ class CardList(
if (exitCardList) return if (exitCardList) return
manageRow() manageRow()
that?.apply { 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 val card = it.cic
card.name = name card.name = name
card.append = append card.append = append

View File

@@ -73,9 +73,12 @@ class BookHandler(private val th: WeakReference<BookFragment>, val path: String)
1 -> setCover() 1 -> setCover()
2 -> setTexts() 2 -> setTexts()
3 -> that?.fbibinfo?.let { setInfoHeight(it) } 3 -> that?.fbibinfo?.let { setInfoHeight(it) }
4 -> setThemes() 4 -> setAuthorsAndTags()
5 -> setOverScale() 5 -> setOverScale()
6 -> if(complete) that?.navigate2dl() 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<BookFragment>, val path: String)
cnts += it.count cnts += it.count
Log.d("MyBFH", "Add caption: ${it.name} @ ${it.path_word} of ${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() 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 that?.fbloading?.visibility = View.GONE
complete = true complete = true
that?.setStartRead() that?.setStartRead()
@@ -230,76 +233,92 @@ class BookHandler(private val th: WeakReference<BookFragment>, val path: String)
} }
} }
private fun setThemes(){ private fun setAuthorsAndTags() {
if (exit) return
that?.apply { that?.apply {
book?.results?.comic?.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)) 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 private fun addVolumesView(v: View) {
that?.apply { obtainMessage(8, v).sendToTarget()
book?.results?.apply { }
that?.activity?.runOnUiThread{
if(exit) return@runOnUiThread private fun setVolumes() = Thread {
ViewMangaActivity.fileArray = arrayOf() if (exit) return@Thread
urlArray = arrayOf() that?.apply {
ViewMangaActivity.uuidArray = arrayOf() book?.results?.apply {
var i = 0 ViewMangaActivity.fileArray = arrayOf()
vols?.forEachIndexed { iv, v -> urlArray = arrayOf()
if(exit) return@runOnUiThread ViewMangaActivity.uuidArray = arrayOf()
fbl.addView(layoutInflater.inflate(R.layout.div_h, fbl, false)) var i = 0
val t = layoutInflater.inflate(R.layout.line_caption, fbl, false) var last = -1
t.tcptn.text = keys[iv] vols?.forEachIndexed { groupIndex, v ->
fbl.addView(t) if(exit) return@Thread
fbl.addView(layoutInflater.inflate(R.layout.div_h, fbl, false)) addVolumesView(layoutInflater.inflate(R.layout.div_h, fbl, false))
var line: View? = null val t = layoutInflater.inflate(R.layout.line_caption, fbl, false)
val last = v.results.list.size - 1 t.tcptn.text = keys[groupIndex]
v.results.list.forEach { addVolumesView(t)
urlArray += CMApi.getChapterInfoApiUrl( addVolumesView(layoutInflater.inflate(R.layout.div_h, fbl, false))
comic.path_word, var line: View? = null
it.uuid last += v.results.list.size
)?:"" v.results.list.forEach {
ViewMangaActivity.fileArray += CMApi.getZipFile(context?.getExternalFilesDir(""), comic.name, keys[iv], it.name) urlArray += CMApi.getChapterInfoApiUrl(
chapterNames += it.name comic.path_word,
ViewMangaActivity.uuidArray += it.uuid it.uuid
if(line == null) { )?:""
if(i == last) { ViewMangaActivity.fileArray += CMApi.getZipFile(context?.getExternalFilesDir(""), comic.name, keys[groupIndex], it.name)
line = layoutInflater.inflate(R.layout.line_chapter, that!!.fbl, false) chapterNames += it.name
line?.lcc?.apply { ViewMangaActivity.uuidArray += it.uuid
lct.text = it.name Log.d("MyBH", "i = $i, last=$last, add chapter ${it.name}, line is null: ${line == null}")
val index = i if(line == null) {
setOnClickListener { Reader.viewMangaAt(comic.name, index, urlArray) } if(i == last) {
} line = layoutInflater.inflate(R.layout.line_chapter, that!!.fbl, false)
fbl?.addView(line) line?.lcc?.apply {
} else { lct.text = it.name
line = layoutInflater.inflate(R.layout.line_2chapters, that!!.fbl, false) Log.d("MyBH", "add last single chapter ${it.name}")
line?.l2cl?.apply { val index = i
lct.text = it.name setOnClickListener { Reader.viewMangaAt(comic.name, index, urlArray) }
val index = i }
setOnClickListener { Reader.viewMangaAt(comic.name, index, urlArray) } line?.let { l -> addVolumesView(l) }
}
} } else {
} else line?.l2cr?.apply { line = layoutInflater.inflate(R.layout.line_2chapters, that!!.fbl, false)
line?.l2cl?.apply {
lct.text = it.name lct.text = it.name
val index = i val index = i
setOnClickListener { Reader.viewMangaAt(comic.name, index, urlArray) } 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){ private fun loadVolume(name: String, path: String, nav: Int){
if(complete) { if(complete) {
@@ -311,7 +330,7 @@ class BookHandler(private val th: WeakReference<BookFragment>, val path: String)
} }
} }
private fun initComicData() { private fun initComicData() = Thread {
var volumes = emptyArray<VolumeStructure>() var volumes = emptyArray<VolumeStructure>()
val counts = cnts.clone() val counts = cnts.clone()
gpws.forEachIndexed { i, gpw -> gpws.forEachIndexed { i, gpw ->
@@ -329,11 +348,11 @@ class BookHandler(private val th: WeakReference<BookFragment>, val path: String)
counts[i] = counts[i] - 100 counts[i] = counts[i] - 100
CMApi.getGroupInfoApiUrl(path, gpw, offset)?.let { CMApi.getGroupInfoApiUrl(path, gpw, offset)?.let {
Log.d("MyBFH", "get api: $it") Log.d("MyBFH", "get api: $it")
if(ComicDlFragment.exit) return if(ComicDlFragment.exit) return@Thread
val ad = AutoDownloadThread(it) { result -> val ad = AutoDownloadThread(it) { result ->
Log.d("MyBFH", "${i}卷返回")
val r = Gson().fromJson(result?.decodeToString(), VolumeStructure::class.java) val r = Gson().fromJson(result?.decodeToString(), VolumeStructure::class.java)
re[r.results.offset / 100] = r re[r.results.offset / 100] = r
Log.d("MyBFH", "${i}卷返回, 大小: ${r.results.list.size}")
} }
ads += ad ads += ad
ad.start() ad.start()
@@ -341,7 +360,6 @@ class BookHandler(private val th: WeakReference<BookFragment>, val path: String)
sleep(1000) sleep(1000)
} }
} while (counts[i] > 0) } while (counts[i] > 0)
Thread {
var c = 0 var c = 0
while (c++ < 80) { while (c++ < 80) {
sleep(1000) sleep(1000)
@@ -359,23 +377,21 @@ class BookHandler(private val th: WeakReference<BookFragment>, val path: String)
r?.results?.list = s r?.results?.list = s
r?.apply { volumes += this } r?.apply { volumes += this }
} else re[0]?.apply { volumes += this } } else re[0]?.apply { volumes += this }
}.start()
} }
Thread { var c = 0
var c = 0 while (c < 80 && volumes.size != gpws.size) {
while (c < 80 && volumes.size != gpws.size) { sleep(1000)
sleep(1000) if(ComicDlFragment.exit) return@Thread
if(ComicDlFragment.exit) return@Thread Log.d("MyBFH", "已有:${volumes.size} 共:${gpws.size}")
Log.d("MyBFH", "已有:${volumes.size} 共:${gpws.size}") c++
c++ }
if (volumes.size == gpws.size) {
that?.activity?.runOnUiThread {
saveVolumes(volumes)
sendEmptyMessage(7)
} }
if (volumes.size == gpws.size) { }
that?.activity?.runOnUiThread { }.start()
saveVolumes(volumes)
}
}
}.start()
}
private fun saveVolumes(volumes: Array<VolumeStructure>) { private fun saveVolumes(volumes: Array<VolumeStructure>) {
that?.context?.getExternalFilesDir("")?.let { home -> that?.context?.getExternalFilesDir("")?.let { home ->

View File

@@ -15,7 +15,7 @@ import java.lang.Thread.sleep
@ExperimentalStdlibApi @ExperimentalStdlibApi
class SortFragment : InfoCardLoader(R.layout.fragment_sort, R.id.action_nav_sort_to_nav_book) { 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 theme = -1
private var region = -1 private var region = -1
private var sortValue = 0 private var sortValue = 0

View File

@@ -86,7 +86,7 @@ class ComicDlFragment: NoBackRefreshFragment(R.layout.fragment_dlcomic) {
menu.findItem(R.id.action_download)?.isVisible = false menu.findItem(R.id.action_download)?.isVisible = false
}*/ }*/
private fun initComicData(pw: String?, gpws: Array<String>?, counts: IntArray?) { private fun initComicData(pw: String?, gpws: Array<String>?, counts: IntArray?) = Thread {
var volumes = emptyArray<VolumeStructure>() var volumes = emptyArray<VolumeStructure>()
if (gpws != null) { if (gpws != null) {
gpws.forEachIndexed { i, gpw -> gpws.forEachIndexed { i, gpw ->
@@ -99,7 +99,7 @@ class ComicDlFragment: NoBackRefreshFragment(R.layout.fragment_dlcomic) {
do { do {
counts?.set(i, counts[i] - 100) counts?.set(i, counts[i] - 100)
CMApi.getGroupInfoApiUrl(pw, gpw, offset)?.let { CMApi.getGroupInfoApiUrl(pw, gpw, offset)?.let {
if(exit) return if(exit) return@Thread
val ad = AutoDownloadThread(it) { result -> val ad = AutoDownloadThread(it) { result ->
Log.d("MyCDF", "${i}卷返回") Log.d("MyCDF", "${i}卷返回")
val r = Gson().fromJson(result?.decodeToString(), VolumeStructure::class.java) val r = Gson().fromJson(result?.decodeToString(), VolumeStructure::class.java)
@@ -110,42 +110,38 @@ class ComicDlFragment: NoBackRefreshFragment(R.layout.fragment_dlcomic) {
offset += 100 offset += 100
} }
} while ((counts?.get(i) ?: 0) > 0) } 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<ChapterStructure>()
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 var c = 0
while (c < 80 && volumes.size != gpws.size) { while (c++ < 80) {
sleep(1000) sleep(1000)
if(exit) return@Thread if(exit) return@Thread
Log.d("MyCDF", "已有:${volumes.size} 共:${gpws.size}") if(re.all { it != null }) break
c++
} }
if (volumes.size == gpws.size) { if(re.size > 1) {
activity?.runOnUiThread { val r = re[0]
start2load(volumes) var s = emptyArray<ChapterStructure>()
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() { private fun initOldComicData() {
handler = ComicDlHandler(Looper.myLooper()!!, handler = ComicDlHandler(Looper.myLooper()!!,

View File

@@ -352,10 +352,9 @@ class ComicDlHandler(looper: Looper, private val th: WeakReference<ComicDlFragme
ViewMangaActivity.dlhandler = this ViewMangaActivity.dlhandler = this
ViewMangaActivity.position = it.tbtn.index ViewMangaActivity.position = it.tbtn.index
dl?.show() dl?.show()
val intent = Intent(that?.context, ViewMangaActivity::class.java)
that?.startActivity(Intent(that!!.context, ViewMangaActivity::class.java) intent.putExtra("urlArray", urlArray).putExtra("callFrom", "zipFirst")
.putExtra("callFrom", "zipFirst") that?.startActivity(intent)
)
} else { } else {
it.tbtn.setBackgroundResource(R.drawable.toggle_button) it.tbtn.setBackgroundResource(R.drawable.toggle_button)
if (it.tbtn.isChecked) that?.tdwn?.text = "$dldChapter/${++checkedChapter}" if (it.tbtn.isChecked) that?.tdwn?.text = "$dldChapter/${++checkedChapter}"

View File

@@ -207,7 +207,8 @@ class HomeFragment : NoBackRefreshFragment(R.layout.fragment_home) {
holder.itemView.ta.text = "搜索 \"$query\"" holder.itemView.ta.text = "搜索 \"$query\""
holder.itemView.tb.text = "$count 条结果" holder.itemView.tb.text = "$count 条结果"
holder.itemView.lwi.visibility = View.INVISIBLE holder.itemView.lwi.visibility = View.INVISIBLE
if (query?.isNotEmpty() == true) holder.itemView.lwc.setOnClickListener { holder.itemView.lwc.setOnClickListener {
if (query?.isNotEmpty() != true) return@setOnClickListener
val bundle = Bundle() val bundle = Bundle()
bundle.putCharSequence("query", query) bundle.putCharSequence("query", query)
bundle.putString("type", type) bundle.putString("type", type)

View File

@@ -212,7 +212,7 @@ class HomeHandler(private val that: WeakReference<HomeFragment>) : AutoDownloadH
} }
} }
private fun inflateCardLines() { private fun inflateCardLines() = Thread{
if (indexLines.isNotEmpty()) indexLines = arrayOf() if (indexLines.isNotEmpty()) indexLines = arrayOf()
inflateRec() inflateRec()
inflateTopics() inflateTopics()
@@ -220,14 +220,12 @@ class HomeHandler(private val that: WeakReference<HomeFragment>) : AutoDownloadH
inflateNew() inflateNew()
inflateFinish() inflateFinish()
inflateRank() inflateRank()
Thread{ for(i in indexLines.indices) {
for(i in indexLines.indices) { obtainMessage(8, i, 0).sendToTarget()
obtainMessage(8, i, 0).sendToTarget() sleep(512)
sleep(512) }
} obtainMessage(-1, false).sendToTarget() //closeLoad
obtainMessage(-1, false).sendToTarget() //closeLoad }.start()
}.start()
}
private fun setBanner(v: Banner): Banner { private fun setBanner(v: Banner): Banner {
v.viewTreeObserver.addOnGlobalLayoutListener(object : v.viewTreeObserver.addOnGlobalLayoutListener(object :
@@ -311,7 +309,7 @@ class HomeHandler(private val that: WeakReference<HomeFragment>) : AutoDownloadH
private fun setCards(cv: CardView, pw: String, name: String, img: String, isFinal: Boolean, isTopic: Boolean) { private fun setCards(cv: CardView, pw: String, name: String, img: String, isFinal: Boolean, isTopic: Boolean) {
cv.tic.text = name cv.tic.text = name
homeF?.let { 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) Glide.with(it).load(GlideUrl(CMApi.proxy?.wrap(img)?:img, CMApi.myGlideHeaders)).timeout(20000).into(cv.imic)
} }
} }

View File

@@ -27,6 +27,7 @@ import java.lang.Thread.sleep
import java.lang.ref.WeakReference import java.lang.ref.WeakReference
import java.text.SimpleDateFormat import java.text.SimpleDateFormat
import java.util.* import java.util.*
import java.util.concurrent.atomic.AtomicInteger
class VMHandler(activity: ViewMangaActivity, url: String) : AutoDownloadHandler( class VMHandler(activity: ViewMangaActivity, url: String) : AutoDownloadHandler(
url, Chapter2Return::class.java, Looper.myLooper()!! url, Chapter2Return::class.java, Looper.myLooper()!!
@@ -59,6 +60,7 @@ class VMHandler(activity: ViewMangaActivity, url: String) : AutoDownloadHandler(
else -> "" else -> ""
} }
} }
private var remainingImageCount = 0
@SuppressLint("SimpleDateFormat", "SetTextI18n") @SuppressLint("SimpleDateFormat", "SetTextI18n")
override fun handleMessage(msg: Message) { override fun handleMessage(msg: Message) {
@@ -81,13 +83,14 @@ class VMHandler(activity: ViewMangaActivity, url: String) : AutoDownloadHandler(
//simg.setHeight2FitImgWidth() //simg.setHeight2FitImgWidth()
//if(msg.arg2 == 1) sendEmptyMessage(DELAYED_RESTORE_PAGE_NUMBER) //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) PREPARE_LAST_PAGE -> wv.get()?.prepareLastPage(msg.arg1, msg.arg2)
DIALOG_SHOW -> dl.show() DIALOG_SHOW -> dl.show()
DELAYED_RESTORE_PAGE_NUMBER -> Thread{
sleep(233)
sendEmptyMessage(RESTORE_PAGE_NUMBER)
}.start()
LOAD_ITEM_SCROLL_MODE -> loadScrollMode(msg.arg1) LOAD_ITEM_SCROLL_MODE -> loadScrollMode(msg.arg1)
LOAD_SCROLL_MODE -> loadScrollMode() LOAD_SCROLL_MODE -> loadScrollMode()
LOAD_ITEM_IMAGES_INTO_LINE -> loadImagesIntoLine(msg.arg1) LOAD_ITEM_IMAGES_INTO_LINE -> loadImagesIntoLine(msg.arg1)
@@ -97,7 +100,8 @@ class VMHandler(activity: ViewMangaActivity, url: String) : AutoDownloadHandler(
wv.get()?.restorePN() wv.get()?.restorePN()
} }
LOAD_PAGE_FROM_ITEM -> { 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) loadScrollMode(item)
Log.d("MyVMH", "Load page from $item") Log.d("MyVMH", "Load page from $item")
} }
@@ -113,6 +117,17 @@ class VMHandler(activity: ViewMangaActivity, url: String) : AutoDownloadHandler(
} else { } else {
showInfCardFull(); true 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 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()?.initManga()
wv.get()?.vprog?.visibility = View.GONE 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)") Log.d("MyVMH", "Fun: loadImagesIntoLine($item, $maxCount)")
wv.get()?.realCount?.let { count -> wv.get()?.realCount?.let { count ->
if(count > 0){ if(count > 0){
val notFull = item + maxCount > count val notFull = item + maxCount > count
val loadCount = (if(notFull) count - item else maxCount) - 1 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") 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() 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() 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() { private fun loadScrollMode() {
sendEmptyMessage(DIALOG_SHOW) sendEmptyMessage(DIALOG_SHOW)
@@ -233,7 +249,7 @@ class VMHandler(activity: ViewMangaActivity, url: String) : AutoDownloadHandler(
const val CLEAR_IMG_ON = 5 const val CLEAR_IMG_ON = 5
const val PREPARE_LAST_PAGE = 6 const val PREPARE_LAST_PAGE = 6
const val DIALOG_SHOW = 7 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_ITEM_SCROLL_MODE = 9
const val LOAD_SCROLL_MODE = 10 const val LOAD_SCROLL_MODE = 10
const val LOAD_ITEM_IMAGES_INTO_LINE = 11 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 HIDE_INFO_CARD_FULL = 16
const val SHOW_INFO_CARD_FULL = 17 const val SHOW_INFO_CARD_FULL = 17
const val TRIGGER_INFO_CARD_FULL = 18 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 const val SET_NET_INFO = 22
} }

View File

@@ -92,7 +92,7 @@ class ViewMangaActivity : TitleActivityTemplate() {
private var indexMap = intArrayOf() private var indexMap = intArrayOf()
private var volTurnPage = false private var volTurnPage = false
private var am: AudioManager? = null private var am: AudioManager? = null
private var pm: PagesManager? = null var pm: PagesManager? = null
private var fullyHideInfo = false private var fullyHideInfo = false
val realCount get() = if(cut) indexMap.size else count val realCount get() = if(cut) indexMap.size else count
@@ -171,10 +171,11 @@ class ViewMangaActivity : TitleActivityTemplate() {
) )
} }
fun restorePN(){ fun restorePN() {
if (isPnValid) { if (isPnValid) {
isInScroll = false isInScroll = false
pageNum = pn pageNum = pn
Log.d("MyVM", "restore pageNum to $pn")
pn = -1 pn = -1
} }
setProgress() setProgress()
@@ -342,9 +343,10 @@ class ViewMangaActivity : TitleActivityTemplate() {
} }
} }
fun clearImgOn(imgView: ScaleImageView){ /*fun clearImgOn(imgView: ScaleImageView){
imgView.visibility = View.GONE imgView.visibility = View.GONE
} handler.sendEmptyMessage(VMHandler.DECREASE_IMAGE_COUNT_AND_RESTORE_PAGE_NUMBER_AT_ZERO)
}*/
//private fun getTempFile(position: Int) = File(cacheDir, "$position") //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 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){ 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 val bitmap2load = if(!isPlaceholder && useCut) cutBitmap(bitmap, isLeft) else bitmap
runOnUiThread { runOnUiThread {
imgView.setImageBitmap(bitmap2load) imgView.setImageBitmap(bitmap2load)
if(isVertical){ if(!isPlaceholder && isVertical) {
imgView.setHeight2FitImgWidth() 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()) { if(data != null && data.isNotEmpty()) {
BitmapFactory.decodeByteArray(data, 0, data.size)?.let { BitmapFactory.decodeByteArray(data, 0, data.size)?.let {
loadImg(imgView, it, isLast, useCut, isLeft, false) loadImg(imgView, it, isLast, useCut, isLeft, false)
Log.d("MyVM", "Load from task") Log.d("MyVM", "Load position $position from task")
}?:Log.d("MyVM", "null bitmap") }?:Log.d("MyVM", "null bitmap at $position")
} }
else getImgUrl(index2load)?.let { loadImgUrlInto(imgView, it, isLast, useCut, isLeft) } else getImgUrl(index2load)?.let { loadImgUrlInto(imgView, it, isLast, useCut, isLeft) }
}.start() }.start()
@@ -586,11 +589,11 @@ class ViewMangaActivity : TitleActivityTemplate() {
@ExperimentalStdlibApi @ExperimentalStdlibApi
private fun prepareIdBtVH() { private fun prepareIdBtVH() {
idtbvh.isChecked = isVertical idtbvh.isChecked = isVertical
pm = PagesManager(WeakReference(this))
if (isVertical) { if (isVertical) {
val vsps = vsp as SpringView val vsps = vsp as SpringView
vsps.footerView.lht.text = "更多" vsps.footerView.lht.text = "更多"
vsps.headerView.lht.text = "更多" vsps.headerView.lht.text = "更多"
pm = PagesManager(WeakReference(this))
vsps.setListener(object :SpringView.OnFreshListener{ vsps.setListener(object :SpringView.OnFreshListener{
override fun onLoadmore() { override fun onLoadmore() {
//scrollForward() //scrollForward()

View File

@@ -679,7 +679,7 @@ class ScaleImageView : ImageView {
override fun onSingleTapConfirmed(event: MotionEvent): Boolean { override fun onSingleTapConfirmed(event: MotionEvent): Boolean {
if(v == null) { if(v == null) {
v = ViewMangaActivity.va v = ViewMangaActivity.va
v?.let { pm = PagesManager(it) } v?.get()?.let { pm = it.pm }
} }
//触发点击 //触发点击
if (mOnClickListener != null) { if (mOnClickListener != null) {
@@ -1632,6 +1632,6 @@ class ScaleImageView : ImageView {
*/ */
const val PINCH_MODE_SCALE = 2 const val PINCH_MODE_SCALE = 2
var pm:PagesManager? = null var pm: PagesManager? = null
} }
} }