1
0
mirror of https://github.com/fumiama/copymanga.git synced 2026-06-08 17:00:28 +08:00
1. 更改 加载图片占位
2. 修复 重复写入info
3. 更改 长按删除提示语
4. 增加 翻到上一章时置于末页
5. 优化 浏览漫画性能
This commit is contained in:
fumiama
2021-01-09 14:39:37 +08:00
parent 36ea5cc149
commit 5bbe768882
13 changed files with 344 additions and 562 deletions

9
.idea/dictionaries/rumia.xml generated Normal file
View File

@@ -0,0 +1,9 @@
<component name="ProjectDictionaryState">
<dictionary name="rumia">
<words>
<w>cdwn</w>
<w>manga</w>
<w>rmrf</w>
</words>
</dictionary>
</component>

View File

@@ -11,8 +11,8 @@ android {
applicationId "top.fumiama.copymanga"
minSdkVersion 23
targetSdkVersion 30
versionCode 9
versionName '1.3.1'
versionCode 10
versionName '1.3.2'
resConfigs "zh", "zh-rCN"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

View File

@@ -25,6 +25,7 @@ import top.fumiama.copymanga.handler.DlHandler
import top.fumiama.copymanga.tool.MangaDlTools
import top.fumiama.copymanga.tool.MangaDlTools.Companion.wmdlt
import top.fumiama.copymanga.tool.ToolsBox
import top.fumiama.copymanga.view.ChapterToggleButton
import top.fumiama.copymanga.view.LazyScrollView
import java.io.File
import java.lang.Thread.sleep
@@ -41,17 +42,14 @@ class DlActivity : Activity() {
var haveDlStarted = false
private var btnNumPerRow = 4
private lateinit var ltbtn: View
var tbtnlist: List<ToggleButton> = arrayListOf()
var tbtnUrlList = arrayListOf<String>()
var tbtnlist: Array<ChapterToggleButton> = arrayOf()
private val handler = DlHandler(this, Looper.myLooper()!!)
private var btnw = 0
private var cdwnWidth = 0
private var canDl = false
private lateinit var toolsBox: ToolsBox
lateinit var mangaDlTools: MangaDlTools
private lateinit var mangaDlTools: MangaDlTools
var multiSelect = false
private var zipArrayList: Array<String> = arrayOf()
@ExperimentalStdlibApi
@SuppressLint("SetTextI18n")
@@ -85,14 +83,14 @@ class DlActivity : Activity() {
private fun fillChapters() {
mangaDlTools.allocateChapterUrls(checkedChapter)
for (i in tbtnlist.indices) {
if (tbtnlist[i].isChecked) mangaDlTools.dlChapterUrl(tbtnUrlList[i])
for (i in tbtnlist) {
if (i.isChecked) mangaDlTools.dlChapterUrl(i.url.toString())
}
}
private fun dlThead(dlMethod: (i: ToggleButton) -> Unit) {
private fun dlThread(dlMethod: (i: ChapterToggleButton) -> Unit) {
sleep(10000)
for (i in tbtnlist.listIterator()) {
for (i in tbtnlist) {
if (i.isChecked) dlMethod(i)
if (!canDl) {
checkedChapter -= dldChapter
@@ -139,7 +137,7 @@ class DlActivity : Activity() {
handler.sendEmptyMessage(9) //set dl card color to red
Toast.makeText(this, "十秒后开始下载...", Toast.LENGTH_SHORT).show()
fillChapters()
Thread { dlThead { downloadChapterPages(it) } }.start()
Thread { dlThread { downloadChapterPages(it) } }.start()
}
}
}
@@ -157,6 +155,7 @@ class DlActivity : Activity() {
}
private fun analyzeStructure() {
ViewMangaActivity.zipList = arrayOf()
Gson().fromJson(json?.reader(), Array<ComicStructure>::class.java)?.let {
for (group in it) {
val tc = layoutInflater.inflate(R.layout.line_caption, ldwn, false)
@@ -182,21 +181,21 @@ class DlActivity : Activity() {
val mangaHome = File("${getExternalFilesDir("")}/$comicName")
val jsonFile = File(mangaHome, "info.bin")
if(!mangaHome.exists()) mangaHome.mkdirs()
json?.let { jsonFile.writeText(it) }
if(!(jsonFile.exists() && intent.getBooleanExtra("callFromDlList", false))) json?.let { jsonFile.writeText(it) }
}
@ExperimentalStdlibApi
private fun downloadChapterPages(i: ToggleButton) {
private fun downloadChapterPages(i: ChapterToggleButton) {
mangaDlTools.onDownloadedListener =
object : MangaDlTools.OnDownloadedListener {
override fun handleMessage(succeed: Boolean) {
handler.obtainMessage(if (succeed) 1 else -1, tbtnlist.indexOf(i), 0)
handler.obtainMessage(if (succeed) 1 else -1, i.index, 0)
.sendToTarget()
}
override fun handleMessage(succeed: Boolean, pageNow: Int) {
handler.obtainMessage(
5,
tbtnlist.indexOf(i),
i.index,
pageNow,
succeed
).sendToTarget()
@@ -204,15 +203,17 @@ class DlActivity : Activity() {
override fun handleMessage(pageNow: Int){
handler.obtainMessage(
10,
tbtnlist.indexOf(i),
i.index,
pageNow
).sendToTarget()
}
}
mangaDlTools.dlChapterAndPackIntoZip(
File("${getExternalFilesDir("")}/$comicName/${i.hint}/${i.textOn}.zip"),
tbtnUrlList[tbtnlist.indexOf(i)].substringAfterLast("/")
)
i.hash?.let {
mangaDlTools.dlChapterAndPackIntoZip(
File("${getExternalFilesDir("")}/$comicName/${i.hint}/${i.textOn}.zip"),
it
)
}
}
@SuppressLint("SetTextI18n")
@@ -224,11 +225,12 @@ class DlActivity : Activity() {
isNewTitle = false
}
val tbv = layoutInflater.inflate(R.layout.button_tbutton, ltbtn.ltbtn, false)
tbv.tbtn.index = tbtnlist.size
tbtnlist += tbv.tbtn
tbv.tbtn.url = url
tbtncnt++
tbtnUrlList.add(url)
val zipPosition = zipArrayList.size
zipArrayList += "$title.zip"
val zipPosition = ViewMangaActivity.zipList?.size
ViewMangaActivity.zipList = ViewMangaActivity.zipList?.plus("$title.zip")
tbv.tbtn.textOff = title
tbv.tbtn.textOn = title
tbv.tbtn.text = title
@@ -251,7 +253,7 @@ class DlActivity : Activity() {
else tdwn.text = "$dldChapter/${--checkedChapter}"
}else if(it.tbtn.isChecked){
it.tbtn.isChecked = false
callVM(title, zipf, zipPosition)
zipPosition?.let { callVM(title, zipf, it) }
}
}
tbv.tbtn.setOnLongClickListener {
@@ -289,7 +291,7 @@ class DlActivity : Activity() {
private fun callVM(titleText: String, zipFile: File, zipPosition:Int){
ViewMangaActivity.titleText = titleText
ViewMangaActivity.zipFile = zipFile
ViewMangaActivity.zipList = zipArrayList
//ViewMangaActivity.zipList = zipArrayList
ViewMangaActivity.zipPosition = zipPosition
ViewMangaActivity.cd = zipFile.parentFile
startActivity(Intent(this, ViewMangaActivity::class.java))

View File

@@ -57,7 +57,7 @@ class DlListActivity:Activity() {
ViewMangaActivity.zipFile = chosenFile
ViewMangaActivity.titleText = it[position]
ViewMangaActivity.zipPosition = position
ViewMangaActivity.zipList = it
ViewMangaActivity.zipList = it as Array<String>
ViewMangaActivity.cd = cd
startActivity(Intent(this, ViewMangaActivity::class.java))
}
@@ -66,8 +66,8 @@ class DlListActivity:Activity() {
mylv.setOnItemLongClickListener { _, _, position, _ ->
val chosenFile = File(cd, it[position])
AlertDialog.Builder(this)
.setIcon(R.drawable.ic_launcher_foreground).setMessage("是否在此执行删除/查错?")
.setTitle("提示").setPositiveButton(android.R.string.ok){ _, _ ->
.setIcon(R.drawable.ic_launcher_foreground).setMessage("在此执行删除/查错?")
.setTitle("提示").setPositiveButton("删除"){ _, _ ->
if(chosenFile.exists()) handler?.obtainMessage(2, chosenFile)?.sendToTarget() //call rmrf
handler?.obtainMessage(3, cd)?.sendToTarget() //call scanFile
}.setNegativeButton(android.R.string.cancel){_, _ ->}
@@ -97,7 +97,10 @@ class DlListActivity:Activity() {
private fun callDownloadActivity(jsonFile: File){
DlActivity.json = jsonFile.readText()
DlActivity.comicName = jsonFile.parentFile?.name?:"Null"
startActivity(Intent(this, DlActivity::class.java))
startActivity(
Intent(this, DlActivity::class.java)
.putExtra("callFromDlList", true)
)
}
private fun findNullWebpZipFileInDir(f: File){

View File

@@ -26,7 +26,7 @@ class MainActivity: Activity() {
setContentView(R.layout.activity_main)
wm = WeakReference(this)
mh = MainHandler(Looper.getMainLooper())
mh = MainHandler(Looper.myLooper()!!)
toolsBox = ToolsBox(wm as WeakReference<Any>)
toolsBox?.netinfo?.let {
if(it == "无网络" || it == "错误"){

View File

@@ -5,10 +5,7 @@ import android.annotation.SuppressLint
import android.app.Activity
import android.graphics.Bitmap
import android.graphics.BitmapFactory
import android.os.Build
import android.os.Bundle
import android.os.Handler
import android.os.Message
import android.os.*
import android.util.Log
import android.view.LayoutInflater
import android.view.View
@@ -105,6 +102,13 @@ class ViewMangaActivity : Activity() {
}
try {
prepareItems()
if(pn > 0) {
pageNum = pn
pn = -1
}else if(pn == -2){
pageNum = count
pn = -1
}
} catch (e: Exception) {
e.printStackTrace()
toolsBox.toastError("准备控件错误")
@@ -152,7 +156,11 @@ class ViewMangaActivity : Activity() {
private fun loadOneImg() {
if(dlZip2View) onei.setImageBitmap(getImgBitmap(currentItem))
else Glide.with(this@ViewMangaActivity).load(imgUrls[currentItem]).placeholder(R.drawable.bg_comment).into(onei)
else Glide.with(this@ViewMangaActivity)
.load(imgUrls[currentItem])
.placeholder(R.drawable.ic_dl)
.dontAnimate()
.into(onei)
updateSeekBar()
}
@@ -338,7 +346,7 @@ class ViewMangaActivity : Activity() {
//Glide.with(this@ViewMangaActivity).load(it).placeholder(R.drawable.bg_comment).into(holder.itemView.onei)
holder.itemView.onei.setImageBitmap(it)
}
else Glide.with(this@ViewMangaActivity).load(imgUrls[pos]).placeholder(R.drawable.bg_comment).timeout(10000).into(holder.itemView.onei)
else Glide.with(this@ViewMangaActivity).load(imgUrls[pos]).placeholder(R.drawable.ic_dl).dontAnimate().timeout(10000).into(holder.itemView.onei)
}
override fun getItemCount(): Int {
@@ -377,7 +385,7 @@ class ViewMangaActivity : Activity() {
class MyHandler(
private val infcard: View,
private val toolsBox: ToolsBox
) : Handler() {
) : Handler(Looper.myLooper()!!) {
private var infcShowed = false
private var delta = -1f
get() {
@@ -429,7 +437,8 @@ class ViewMangaActivity : Activity() {
var nextChapterUrl: String? = null
var previousChapterUrl: String? = null
var zipPosition = 0
var zipList: Array<out String>? = null
var zipList: Array<String>? = null
var cd: File? = null
var pn = -1
}
}

View File

@@ -48,7 +48,7 @@ class DlHandler(activity: DlActivity, looper: Looper) : Handler(looper) {
d?.pdwn?.progress = 0
val selectDownloaded = d?.multiSelect?:false
if (d?.haveSElectAll == true) {
d?.tbtnlist?.listIterator()?.forEach { i ->
d?.tbtnlist?.forEach { i ->
if(i.freezesText) i.setBackgroundResource(R.drawable.rndbg_checked) else i.setBackgroundResource(R.drawable.toggle_button)
i.isChecked = false
}
@@ -62,7 +62,7 @@ class DlHandler(activity: DlActivity, looper: Looper) : Handler(looper) {
i.isChecked = true
it.checkedChapter++
}
for (i in it.tbtnlist.listIterator()) {
for (i in it.tbtnlist) {
if(selectDownloaded) checkBtn(i, it)
else if(!i.freezesText) checkBtn(i, it)
}
@@ -90,7 +90,7 @@ class DlHandler(activity: DlActivity, looper: Looper) : Handler(looper) {
}
private fun setSize(pageNow: Int, tbtnNo: Int){
if(refreshSize || size == 0) {
size = d?.tbtnUrlList?.get(tbtnNo)?.let { wmdlt?.get()?.getImgsCountByHash(it.substringAfterLast("/")) }?:0
size = d?.tbtnlist?.get(tbtnNo)?.hash?.let { wmdlt?.get()?.getImgsCountByHash(it) }?:0
refreshSize = false
}else if(pageNow == size) refreshSize = true
}

View File

@@ -28,9 +28,9 @@ class MainHandler(looper: Looper):Handler(looper) {
}
private fun loadUrlInHiddenWebView(url: String){wm?.get()?.wh?.loadUrl(url)}
private fun callViewManga(content: String){
val listChapter = content.split("\n")
val listChapter = content.split('\n')
if(!saveUrlsOnly) {
ViewMangaActivity.titleText = listChapter[0].substringBeforeLast(" ")
ViewMangaActivity.titleText = listChapter[0].substringBeforeLast(' ')
ViewMangaActivity.nextChapterUrl = listChapter[1].let { if(it == "null") null else it }
ViewMangaActivity.previousChapterUrl = listChapter[2].let { if(it == "null") null else it }
ViewMangaActivity.imgUrls = arrayOf()
@@ -39,7 +39,7 @@ class MainHandler(looper: Looper):Handler(looper) {
} else{
var imgs = arrayOf<String>()
for(i in 3 until listChapter.size) imgs += listChapter[i]
wmdlt?.get()?.setChapterImgs(listChapter[0].substringAfterLast(" "), imgs)
wmdlt?.get()?.setChapterImgs(listChapter[0].substringAfterLast(' '), imgs)
}
}
private fun updateLoadProgress(progress: Int){

View File

@@ -1,7 +1,6 @@
package top.fumiama.copymanga.tool
import android.content.Intent
import android.util.Log
import android.widget.Toast
import kotlinx.android.synthetic.main.activity_main.*
import top.fumiama.copymanga.activity.MainActivity.Companion.wm
@@ -21,9 +20,6 @@ class PagesManager(w: WeakReference<ViewMangaActivity>) {
private fun judgeNext() = v?.pageNum?:0 < v?.count?:0
@ExperimentalStdlibApi
private fun toPage(goNext:Boolean){
val chapterUrl = if(goNext) ViewMangaActivity.nextChapterUrl else ViewMangaActivity.previousChapterUrl
val newZipPosition = ViewMangaActivity.zipPosition + (if(goNext) 1 else -1)
val hint = if(goNext) "" else ""
if (v?.clicked == false) {
if (if(goNext)judgeNext() else judgePrevious()) {
if(goNext) {
@@ -33,33 +29,42 @@ class PagesManager(w: WeakReference<ViewMangaActivity>) {
v.scrollBack()
isEndL = false
}
} else if (chapterUrl != null) {
if (if(goNext)isEndR else isEndL) {
wm?.get()?.w?.loadUrl("javascript:invoke.clickClass(\"comicControlBottomTopClick\",${if(goNext)1 else 0});")
v.tt.canDo = false
v.finish()
} else doubleTapToast(hint, goNext)
} else if(v.dlZip2View && newZipPosition >= 0 && newZipPosition < ViewMangaActivity.zipList?.size?:0){
if (if(goNext)isEndR else isEndL){
ViewMangaActivity.zipPosition = newZipPosition
ViewMangaActivity.titleText = ViewMangaActivity.zipList?.get(newZipPosition) ?: "null"
ViewMangaActivity.zipFile = File(ViewMangaActivity.cd, ViewMangaActivity.titleText)
v.startActivity(Intent(v, ViewMangaActivity::class.java))
v.tt.canDo = false
v.finish()
}else doubleTapToast(hint, goNext)
} else {
val chapterUrl = if(goNext) ViewMangaActivity.nextChapterUrl else ViewMangaActivity.previousChapterUrl
if (chapterUrl != null) {
if (if(goNext)isEndR else isEndL) {
if(!goNext) ViewMangaActivity.pn = -2
wm?.get()?.w?.loadUrl("javascript:invoke.clickClass(\"comicControlBottomTopClick\",${if(goNext)1 else 0});")
v.tt.canDo = false
v.finish()
} else doubleTapToast(goNext)
} else {
val newZipPosition = ViewMangaActivity.zipPosition + (if(goNext) 1 else -1)
if(v.dlZip2View && newZipPosition >= 0 && newZipPosition < ViewMangaActivity.zipList?.size?:0){
if (if(goNext)isEndR else isEndL){
if(!goNext) ViewMangaActivity.pn = -2
ViewMangaActivity.zipPosition = newZipPosition
ViewMangaActivity.titleText = ViewMangaActivity.zipList?.get(newZipPosition) ?: "null"
ViewMangaActivity.zipFile = File(ViewMangaActivity.cd, ViewMangaActivity.titleText)
v.startActivity(Intent(v, ViewMangaActivity::class.java))
v.tt.canDo = false
v.finish()
}else doubleTapToast(goNext)
}
else Toast.makeText(
v.applicationContext,
"已经到头了~",
Toast.LENGTH_SHORT
).show()
}
}
else Toast.makeText(
v.applicationContext,
"已经到头了~",
Toast.LENGTH_SHORT
).show()
} else v?.hideObjs()
}
fun manageInfo(){
if (v?.clicked == false) v.showObjs() else v?.hideObjs()
}
private fun doubleTapToast(hint: String, goNext: Boolean){
private fun doubleTapToast(goNext: Boolean){
val hint = if(goNext) "" else ""
Toast.makeText(
v?.applicationContext,
"再次按下加载${hint}一章",

View File

@@ -0,0 +1,23 @@
package top.fumiama.copymanga.view
import android.content.Context
import android.util.AttributeSet
import android.widget.ToggleButton
class ChapterToggleButton: ToggleButton {
constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int): super(context, attrs, defStyleAttr)
constructor(context: Context?, attrs: AttributeSet?): super(context, attrs)
constructor(context: Context?): super(context, null)
var url: CharSequence? = null
val hash get() = url?.toString()?.substringAfterLast('/')
var caption: CharSequence? = null
var index: Int = 0
var chapterName: CharSequence = "null"
set(value) {
textOn = value
textOff = value
text = value
field = value
}
}

File diff suppressed because one or more lines are too long

View File

@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<ToggleButton xmlns:android="http://schemas.android.com/apk/res/android"
<top.fumiama.copymanga.view.ChapterToggleButton xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/tbtn"
android:layout_width="64dp"