1
0
mirror of https://github.com/fumiama/copymanga.git synced 2026-06-21 18:00:24 +08:00
1. 增加下载页面点击已下载漫画进行观看功能
2. 修复加载某些文件闪退
This commit is contained in:
fumiama
2020-12-22 13:41:48 +08:00
parent 91b997973f
commit 36ea5cc149
11 changed files with 111 additions and 100 deletions

View File

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

View File

@@ -58,4 +58,14 @@
@com.google.gson.annotations.SerializedName <fields>; @com.google.gson.annotations.SerializedName <fields>;
} }
##---------------End: proguard configuration for Gson ---------- ##---------------End: proguard configuration for Gson ----------
-assumenosideeffects class android.util.Log {
public static *** d(...);
public static *** e(...);
public static *** i(...);
public static *** v(...);
public static *** println(...);
public static *** w(...);
public static *** wtf(...);
}

View File

@@ -3,14 +3,15 @@ package top.fumiama.copymanga.activity
import android.animation.ObjectAnimator import android.animation.ObjectAnimator
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.app.Activity import android.app.Activity
import android.content.Intent
import android.os.Bundle import android.os.Bundle
import android.os.Looper import android.os.Looper
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.view.ViewTreeObserver import android.view.ViewTreeObserver
import android.view.WindowManager
import android.widget.Toast import android.widget.Toast
import android.widget.ToggleButton import android.widget.ToggleButton
import com.google.gson.Gson
import kotlinx.android.synthetic.main.activity_dl.* import kotlinx.android.synthetic.main.activity_dl.*
import kotlinx.android.synthetic.main.button_tbutton.view.* import kotlinx.android.synthetic.main.button_tbutton.view.*
import kotlinx.android.synthetic.main.line_caption.view.* import kotlinx.android.synthetic.main.line_caption.view.*
@@ -19,15 +20,16 @@ import kotlinx.android.synthetic.main.widget_downloadbar.*
import kotlinx.android.synthetic.main.widget_titlebar.* import kotlinx.android.synthetic.main.widget_titlebar.*
import top.fumiama.copymanga.R import top.fumiama.copymanga.R
import top.fumiama.copymanga.activity.MainActivity.Companion.mh import top.fumiama.copymanga.activity.MainActivity.Companion.mh
import top.fumiama.copymanga.data.ComicStructure
import top.fumiama.copymanga.handler.DlHandler import top.fumiama.copymanga.handler.DlHandler
import top.fumiama.copymanga.tool.MangaDlTools import top.fumiama.copymanga.tool.MangaDlTools
import top.fumiama.copymanga.tool.MangaDlTools.Companion.comicStructure
import top.fumiama.copymanga.tool.MangaDlTools.Companion.wmdlt import top.fumiama.copymanga.tool.MangaDlTools.Companion.wmdlt
import top.fumiama.copymanga.tool.ToolsBox import top.fumiama.copymanga.tool.ToolsBox
import top.fumiama.copymanga.view.LazyScrollView import top.fumiama.copymanga.view.LazyScrollView
import java.io.File import java.io.File
import java.lang.Thread.sleep import java.lang.Thread.sleep
import java.lang.ref.WeakReference import java.lang.ref.WeakReference
import java.util.zip.ZipFile
class DlActivity : Activity() { class DlActivity : Activity() {
@@ -48,6 +50,7 @@ class DlActivity : Activity() {
private lateinit var toolsBox: ToolsBox private lateinit var toolsBox: ToolsBox
lateinit var mangaDlTools: MangaDlTools lateinit var mangaDlTools: MangaDlTools
var multiSelect = false var multiSelect = false
private var zipArrayList: Array<String> = arrayOf()
@ExperimentalStdlibApi @ExperimentalStdlibApi
@@ -57,7 +60,7 @@ class DlActivity : Activity() {
setContentView(R.layout.activity_dl) setContentView(R.layout.activity_dl)
mh?.saveUrlsOnly = true mh?.saveUrlsOnly = true
mangaDlTools = MangaDlTools(this) mangaDlTools = MangaDlTools(this)
handler.sendEmptyMessage(-2) handler.sendEmptyMessage(-2) //setLayouts
} }
override fun onDestroy() { override fun onDestroy() {
@@ -88,7 +91,7 @@ class DlActivity : Activity() {
} }
private fun dlThead(dlMethod: (i: ToggleButton) -> Unit) { private fun dlThead(dlMethod: (i: ToggleButton) -> Unit) {
sleep(100000) sleep(10000)
for (i in tbtnlist.listIterator()) { for (i in tbtnlist.listIterator()) {
if (i.isChecked) dlMethod(i) if (i.isChecked) dlMethod(i)
if (!canDl) { if (!canDl) {
@@ -149,12 +152,12 @@ class DlActivity : Activity() {
} }
private fun showMultiSelectInfo() { private fun showMultiSelectInfo() {
toolsBox.buildInfo("进入多选模式?", "确定后,长按下载条可选中全部漫画,而不仅限于未下载者。", toolsBox.buildInfo("进入多选模式?", "确定后,长按下载条可选中全部漫画,而不仅限于未下载者;点击已下载漫画可进行选择",
"确定", null, "取消", { multiSelect = true }) "确定", null, "取消", { multiSelect = true })
} }
private fun analyzeStructure() { private fun analyzeStructure() {
comicStructure?.let { Gson().fromJson(json?.reader(), Array<ComicStructure>::class.java)?.let {
for (group in it) { for (group in it) {
val tc = layoutInflater.inflate(R.layout.line_caption, ldwn, false) val tc = layoutInflater.inflate(R.layout.line_caption, ldwn, false)
tc.tcptn.text = group.name tc.tcptn.text = group.name
@@ -176,6 +179,10 @@ class DlActivity : Activity() {
for (chapter in group.chapters) addTbtn(chapter.name, chapter.url, group.name) for (chapter in group.chapters) addTbtn(chapter.name, chapter.url, group.name)
} }
} }
val mangaHome = File("${getExternalFilesDir("")}/$comicName")
val jsonFile = File(mangaHome, "info.bin")
if(!mangaHome.exists()) mangaHome.mkdirs()
json?.let { jsonFile.writeText(it) }
} }
@ExperimentalStdlibApi @ExperimentalStdlibApi
@@ -220,6 +227,8 @@ class DlActivity : Activity() {
tbtnlist += tbv.tbtn tbtnlist += tbv.tbtn
tbtncnt++ tbtncnt++
tbtnUrlList.add(url) tbtnUrlList.add(url)
val zipPosition = zipArrayList.size
zipArrayList += "$title.zip"
tbv.tbtn.textOff = title tbv.tbtn.textOff = title
tbv.tbtn.textOn = title tbv.tbtn.textOn = title
tbv.tbtn.text = title tbv.tbtn.text = title
@@ -234,10 +243,16 @@ class DlActivity : Activity() {
ltbtn.ltbtn.addView(tbv) ltbtn.ltbtn.addView(tbv)
ltbtn.invalidate() ltbtn.invalidate()
tbv.tbtn.setOnClickListener { tbv.tbtn.setOnClickListener {
val normalAct = (multiSelect && zipf.exists()) || !zipf.exists()
if (zipf.exists() && !it.tbtn.isChecked) it.tbtn.setBackgroundResource(R.drawable.rndbg_checked) if (zipf.exists() && !it.tbtn.isChecked) it.tbtn.setBackgroundResource(R.drawable.rndbg_checked)
else it.tbtn.setBackgroundResource(R.drawable.toggle_button) else if(normalAct) it.tbtn.setBackgroundResource(R.drawable.toggle_button)
if (it.tbtn.isChecked) tdwn.text = "$dldChapter/${++checkedChapter}" if(normalAct){
else tdwn.text = "$dldChapter/${--checkedChapter}" if (it.tbtn.isChecked) tdwn.text = "$dldChapter/${++checkedChapter}"
else tdwn.text = "$dldChapter/${--checkedChapter}"
}else if(it.tbtn.isChecked){
it.tbtn.isChecked = false
callVM(title, zipf, zipPosition)
}
} }
tbv.tbtn.setOnLongClickListener { tbv.tbtn.setOnLongClickListener {
if (zipf.exists()) { if (zipf.exists()) {
@@ -271,6 +286,15 @@ class DlActivity : Activity() {
handler.sendEmptyMessage(6) handler.sendEmptyMessage(6)
} }
private fun callVM(titleText: String, zipFile: File, zipPosition:Int){
ViewMangaActivity.titleText = titleText
ViewMangaActivity.zipFile = zipFile
ViewMangaActivity.zipList = zipArrayList
ViewMangaActivity.zipPosition = zipPosition
ViewMangaActivity.cd = zipFile.parentFile
startActivity(Intent(this, ViewMangaActivity::class.java))
}
private fun deleteChapter(f: File, v: ToggleButton) { private fun deleteChapter(f: File, v: ToggleButton) {
f.delete() f.delete()
v.setBackgroundResource(R.drawable.toggle_button) v.setBackgroundResource(R.drawable.toggle_button)
@@ -301,5 +325,6 @@ class DlActivity : Activity() {
companion object { companion object {
var comicName = "Null" var comicName = "Null"
var json: String? = null
} }
} }

View File

@@ -18,46 +18,49 @@ import java.util.regex.Pattern
import java.util.zip.ZipInputStream import java.util.zip.ZipInputStream
class DlListActivity:Activity() { class DlListActivity:Activity() {
var nullZipDirStr = emptyArray<String>() private var nullZipDirStr = emptyArray<String>()
var handler: DlLHandler? = null private var handler: DlLHandler? = null
var loadingDialog: Dialog? = null
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
setContentView(R.layout.activity_dlist) setContentView(R.layout.activity_dlist)
ttitle.text = intent.getStringExtra("title") ttitle.text = intent.getStringExtra("title")
loadingDialog = Dialog(this)
loadingDialog?.setContentView(R.layout.dialog_loading)
handler = DlLHandler(Looper.myLooper()!!, this) handler = DlLHandler(Looper.myLooper()!!, this)
handler?.obtainMessage(3, currentDir)?.sendToTarget() //call scanFile handler?.obtainMessage(3, currentDir)?.sendToTarget() //call scanFile
} }
fun scanFile(cd: File?){ fun scanFile(cd: File?){
cd?.list()?.sortedArrayWith { o1, o2 -> val isRoot = cd == getExternalFilesDir("")
val jsonFile = File(cd, "info.bin")
if(isRoot || !jsonFile.exists()) cd?.list()?.sortedArrayWith { o1, o2 ->
if(o1.endsWith(".zip") && o2.endsWith(".zip")) (10000*getFloat(o1) - 10000*getFloat(o2) + 0.5).toInt() if(o1.endsWith(".zip") && o2.endsWith(".zip")) (10000*getFloat(o1) - 10000*getFloat(o2) + 0.5).toInt()
else o1[0] - o2[0] else o1[0] - o2[0]
}?.let { }?.let {
mylv.adapter = ArrayAdapter(this, android.R.layout.simple_list_item_1, it) mylv.adapter = ArrayAdapter(this, android.R.layout.simple_list_item_1, it)
mylv.setOnItemClickListener { _, _, position, _ -> mylv.setOnItemClickListener { _, _, position, _ ->
val chosenFile = File(cd, it[position]) val chosenFile = File(cd, it[position])
val chosenJson = File(chosenFile, "info.bin")
//Toast.makeText(this, "进入$chosenFile", Toast.LENGTH_SHORT).show() //Toast.makeText(this, "进入$chosenFile", Toast.LENGTH_SHORT).show()
if (chosenFile.isDirectory) { when {
currentDir = chosenFile chosenJson.exists() -> callDownloadActivity(chosenJson)
startActivity( chosenFile.isDirectory -> {
Intent( currentDir = chosenFile
this, startActivity(
DlListActivity::class.java Intent(
).putExtra("title", it[position]) this,
) DlListActivity::class.java
} ).putExtra("title", it[position])
else{ )
Toast.makeText(this, "加载中...", Toast.LENGTH_SHORT).show() }
ViewMangaActivity.zipFile = chosenFile chosenFile.name.endsWith(".zip") -> {
ViewMangaActivity.titleText = it[position] Toast.makeText(this, "加载中...", Toast.LENGTH_SHORT).show()
ViewMangaActivity.zipPosition = position ViewMangaActivity.zipFile = chosenFile
ViewMangaActivity.zipList = it ViewMangaActivity.titleText = it[position]
ViewMangaActivity.cd = cd ViewMangaActivity.zipPosition = position
startActivity(Intent(this, ViewMangaActivity::class.java)) ViewMangaActivity.zipList = it
ViewMangaActivity.cd = cd
startActivity(Intent(this, ViewMangaActivity::class.java))
}
} }
} }
mylv.setOnItemLongClickListener { _, _, position, _ -> mylv.setOnItemLongClickListener { _, _, position, _ ->
@@ -91,9 +94,11 @@ class DlListActivity:Activity() {
else Toast.makeText(this, "未发现错误", Toast.LENGTH_SHORT).show() else Toast.makeText(this, "未发现错误", Toast.LENGTH_SHORT).show()
} }
fun showLoading() = loadingDialog?.show() private fun callDownloadActivity(jsonFile: File){
DlActivity.json = jsonFile.readText()
fun hideLoading() = loadingDialog?.hide() DlActivity.comicName = jsonFile.parentFile?.name?:"Null"
startActivity(Intent(this, DlActivity::class.java))
}
private fun findNullWebpZipFileInDir(f: File){ private fun findNullWebpZipFileInDir(f: File){
if (f.isDirectory) f.listFiles()?.let { if (f.isDirectory) f.listFiles()?.let {
@@ -156,7 +161,7 @@ class DlListActivity:Activity() {
while (matcher.find()) newString.append(matcher.group()) while (matcher.find()) newString.append(matcher.group())
} }
//Log.d("MyDLL2", newString.toString().toFloat().toString()) //Log.d("MyDLL2", newString.toString().toFloat().toString())
return newString.toString().toFloat() return if(newString.isEmpty()) 0f else newString.toString().toFloat()
} }
companion object{ companion object{

View File

@@ -94,17 +94,21 @@ class ViewMangaActivity : Activity() {
tt.start() tt.start()
ttitle.text = titleText ttitle.text = titleText
//isearch.visibility = View.VISIBLE //isearch.visibility = View.VISIBLE
try { Log.d("MyVM", "dlZip2View: $dlZip2View, mangaZip: $mangaZip")
count = if (mangaZip != null) countZipItems() else imgUrls.size if(dlZip2View && mangaZip?.exists() != true) toolsBox.toastError("已经到头了~")
} catch (e: Exception) { else {
e.printStackTrace() try {
toolsBox.toastError("分析图片url错误") count = if (dlZip2View) countZipItems() else imgUrls.size
} } catch (e: Exception) {
try { e.printStackTrace()
prepareItems() toolsBox.toastError("分析图片url错误")
} catch (e: Exception) { }
e.printStackTrace() try {
toolsBox.toastError("准备控件错误") prepareItems()
} catch (e: Exception) {
e.printStackTrace()
toolsBox.toastError("准备控件错误")
}
} }
} }

View File

@@ -16,6 +16,8 @@ class DlHandler(activity: DlActivity, looper: Looper) : Handler(looper) {
private val da = WeakReference(activity) private val da = WeakReference(activity)
private val d private val d
get() = da.get() get() = da.get()
private var size = 0
private var refreshSize = true
@ExperimentalStdlibApi @ExperimentalStdlibApi
@SuppressLint("SetTextI18n") @SuppressLint("SetTextI18n")
@@ -70,13 +72,13 @@ class DlHandler(activity: DlActivity, looper: Looper) : Handler(looper) {
d?.tdwn?.text = "${d?.dldChapter}/${d?.checkedChapter}" d?.tdwn?.text = "${d?.dldChapter}/${d?.checkedChapter}"
} }
5 -> { 5 -> {
val size = d?.tbtnUrlList?.get(msg.arg1)?.let { wmdlt?.get()?.getImgsCountByHash(it.substringAfterLast("/")) }?:0 setSize(msg.arg2, msg.arg1)
d?.updateProgressBar(msg.arg2, size) d?.updateProgressBar(msg.arg2, size)
if (!(msg.obj as Boolean)) { if (!(msg.obj as Boolean)) {
Toast.makeText(d, "下载${d?.tbtnlist?.get(msg.arg1)?.textOn}的第${msg.arg2}页失败", Toast.LENGTH_SHORT).show() Toast.makeText(d, "下载${d?.tbtnlist?.get(msg.arg1)?.textOn}的第${msg.arg2}页失败", Toast.LENGTH_SHORT).show()
}else{ }else{
val progressTxt = d?.tdwn?.text.toString() val progressTxt = d?.tdwn?.text.toString()
d?.tdwn?.text = "${progressTxt.substringBefore(" ")}${msg.arg2}/${size}" d?.tdwn?.text = "${progressTxt.substringBefore(' ')} ${msg.arg2}/${size} "
} }
} }
6 -> d?.tdwn?.text = "${d?.dldChapter}/${d?.checkedChapter}" 6 -> d?.tdwn?.text = "${d?.dldChapter}/${d?.checkedChapter}"
@@ -86,4 +88,10 @@ class DlHandler(activity: DlActivity, looper: Looper) : Handler(looper) {
10 -> Toast.makeText(d, "下载${d?.tbtnlist?.get(msg.arg1)?.textOn}的第${msg.arg2}页失败,尝试重新下载...", Toast.LENGTH_SHORT).show() 10 -> Toast.makeText(d, "下载${d?.tbtnlist?.get(msg.arg1)?.textOn}的第${msg.arg2}页失败,尝试重新下载...", Toast.LENGTH_SHORT).show()
} }
} }
private fun setSize(pageNow: Int, tbtnNo: Int){
if(refreshSize || size == 0) {
size = d?.tbtnUrlList?.get(tbtnNo)?.let { wmdlt?.get()?.getImgsCountByHash(it.substringAfterLast("/")) }?:0
refreshSize = false
}else if(pageNow == size) refreshSize = true
}
} }

View File

@@ -13,15 +13,9 @@ class DlLHandler(looper: Looper, activity: DlListActivity): Handler(looper) {
override fun handleMessage(msg: Message) { override fun handleMessage(msg: Message) {
super.handleMessage(msg) super.handleMessage(msg)
when(msg.what){ when(msg.what){
1 -> load { dll.get()?.checkDir(msg.obj as File) } 1 -> dll.get()?.checkDir(msg.obj as File)
2 -> load { dll.get()?.rmrf(msg.obj as File) } 2 -> dll.get()?.rmrf(msg.obj as File)
3 -> load { dll.get()?.scanFile(msg.obj as File) } 3 -> dll.get()?.scanFile(msg.obj as File)
} }
} }
private fun load(func:()->Unit){
dll.get()?.showLoading()
func()
dll.get()?.hideLoading()
}
} }

View File

@@ -5,16 +5,11 @@ import android.content.Intent
import android.os.Handler import android.os.Handler
import android.os.Looper import android.os.Looper
import android.os.Message import android.os.Message
import android.util.Log
import android.view.View import android.view.View
import com.google.gson.Gson
import kotlinx.android.synthetic.main.activity_main.* import kotlinx.android.synthetic.main.activity_main.*
import top.fumiama.copymanga.activity.DlActivity import top.fumiama.copymanga.activity.DlActivity.Companion.json
import top.fumiama.copymanga.activity.MainActivity.Companion.wm import top.fumiama.copymanga.activity.MainActivity.Companion.wm
import top.fumiama.copymanga.activity.ViewMangaActivity import top.fumiama.copymanga.activity.ViewMangaActivity
import top.fumiama.copymanga.data.ComicStructure
import top.fumiama.copymanga.tool.MangaDlTools
import top.fumiama.copymanga.tool.MangaDlTools.Companion.comicStructure
import top.fumiama.copymanga.tool.MangaDlTools.Companion.wmdlt import top.fumiama.copymanga.tool.MangaDlTools.Companion.wmdlt
class MainHandler(looper: Looper):Handler(looper) { class MainHandler(looper: Looper):Handler(looper) {
@@ -62,7 +57,7 @@ class MainHandler(looper: Looper):Handler(looper) {
private fun setFab(content: String){ private fun setFab(content: String){
//Log.d("MyMH", "Get chapter json: $content") //Log.d("MyMH", "Get chapter json: $content")
showDlList = false showDlList = false
comicStructure = Gson().fromJson(content.reader(), Array<ComicStructure>::class.java) json = content
showFab() showFab()
} }
private fun setFab2DlList(){ private fun setFab2DlList(){

View File

@@ -1,7 +1,5 @@
package top.fumiama.copymanga.tool package top.fumiama.copymanga.tool
import android.os.Looper
import android.widget.Toast
import top.fumiama.copymanga.R import top.fumiama.copymanga.R
import top.fumiama.copymanga.activity.DlActivity import top.fumiama.copymanga.activity.DlActivity
import top.fumiama.copymanga.data.ComicStructure import top.fumiama.copymanga.data.ComicStructure
@@ -92,6 +90,5 @@ class MangaDlTools(activity: DlActivity) {
companion object { companion object {
var wmdlt: WeakReference<MangaDlTools>? = null var wmdlt: WeakReference<MangaDlTools>? = null
var comicStructure: Array<ComicStructure>? = null
} }
} }

View File

@@ -1,6 +1,7 @@
package top.fumiama.copymanga.tool package top.fumiama.copymanga.tool
import android.content.Intent import android.content.Intent
import android.util.Log
import android.widget.Toast import android.widget.Toast
import kotlinx.android.synthetic.main.activity_main.* import kotlinx.android.synthetic.main.activity_main.*
import top.fumiama.copymanga.activity.MainActivity.Companion.wm import top.fumiama.copymanga.activity.MainActivity.Companion.wm
@@ -42,7 +43,7 @@ class PagesManager(w: WeakReference<ViewMangaActivity>) {
if (if(goNext)isEndR else isEndL){ if (if(goNext)isEndR else isEndL){
ViewMangaActivity.zipPosition = newZipPosition ViewMangaActivity.zipPosition = newZipPosition
ViewMangaActivity.titleText = ViewMangaActivity.zipList?.get(newZipPosition) ?: "null" ViewMangaActivity.titleText = ViewMangaActivity.zipList?.get(newZipPosition) ?: "null"
ViewMangaActivity.zipFile = ViewMangaActivity.zipList?.let { File(ViewMangaActivity.cd, ViewMangaActivity.titleText) } ViewMangaActivity.zipFile = File(ViewMangaActivity.cd, ViewMangaActivity.titleText)
v.startActivity(Intent(v, ViewMangaActivity::class.java)) v.startActivity(Intent(v, ViewMangaActivity::class.java))
v.tt.canDo = false v.tt.canDo = false
v.finish() v.finish()

View File

@@ -1,28 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="16dp">
<ProgressBar
android:id="@+id/punz"
style="?android:attr/progressBarStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toTopOf="@+id/tunz"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/tunz"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="准备中..."
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/punz" />
</androidx.constraintlayout.widget.ConstraintLayout>