mirror of
https://github.com/fumiama/copymanga.git
synced 2026-06-10 10:24:29 +08:00
v1.3.1
1. 增加下载页面点击已下载漫画进行观看功能 2. 修复加载某些文件闪退
This commit is contained in:
@@ -3,14 +3,15 @@ package top.fumiama.copymanga.activity
|
||||
import android.animation.ObjectAnimator
|
||||
import android.annotation.SuppressLint
|
||||
import android.app.Activity
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.os.Looper
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.view.ViewTreeObserver
|
||||
import android.view.WindowManager
|
||||
import android.widget.Toast
|
||||
import android.widget.ToggleButton
|
||||
import com.google.gson.Gson
|
||||
import kotlinx.android.synthetic.main.activity_dl.*
|
||||
import kotlinx.android.synthetic.main.button_tbutton.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 top.fumiama.copymanga.R
|
||||
import top.fumiama.copymanga.activity.MainActivity.Companion.mh
|
||||
import top.fumiama.copymanga.data.ComicStructure
|
||||
import top.fumiama.copymanga.handler.DlHandler
|
||||
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.ToolsBox
|
||||
import top.fumiama.copymanga.view.LazyScrollView
|
||||
import java.io.File
|
||||
import java.lang.Thread.sleep
|
||||
import java.lang.ref.WeakReference
|
||||
import java.util.zip.ZipFile
|
||||
|
||||
|
||||
class DlActivity : Activity() {
|
||||
@@ -48,6 +50,7 @@ class DlActivity : Activity() {
|
||||
private lateinit var toolsBox: ToolsBox
|
||||
lateinit var mangaDlTools: MangaDlTools
|
||||
var multiSelect = false
|
||||
private var zipArrayList: Array<String> = arrayOf()
|
||||
|
||||
|
||||
@ExperimentalStdlibApi
|
||||
@@ -57,7 +60,7 @@ class DlActivity : Activity() {
|
||||
setContentView(R.layout.activity_dl)
|
||||
mh?.saveUrlsOnly = true
|
||||
mangaDlTools = MangaDlTools(this)
|
||||
handler.sendEmptyMessage(-2)
|
||||
handler.sendEmptyMessage(-2) //setLayouts
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
@@ -88,7 +91,7 @@ class DlActivity : Activity() {
|
||||
}
|
||||
|
||||
private fun dlThead(dlMethod: (i: ToggleButton) -> Unit) {
|
||||
sleep(100000)
|
||||
sleep(10000)
|
||||
for (i in tbtnlist.listIterator()) {
|
||||
if (i.isChecked) dlMethod(i)
|
||||
if (!canDl) {
|
||||
@@ -149,12 +152,12 @@ class DlActivity : Activity() {
|
||||
}
|
||||
|
||||
private fun showMultiSelectInfo() {
|
||||
toolsBox.buildInfo("进入多选模式?", "确定后,长按下载条可选中全部漫画,而不仅限于未下载者。",
|
||||
toolsBox.buildInfo("进入多选模式?", "确定后,长按下载条可选中全部漫画,而不仅限于未下载者;点击已下载漫画可进行选择。",
|
||||
"确定", null, "取消", { multiSelect = true })
|
||||
}
|
||||
|
||||
private fun analyzeStructure() {
|
||||
comicStructure?.let {
|
||||
Gson().fromJson(json?.reader(), Array<ComicStructure>::class.java)?.let {
|
||||
for (group in it) {
|
||||
val tc = layoutInflater.inflate(R.layout.line_caption, ldwn, false)
|
||||
tc.tcptn.text = group.name
|
||||
@@ -176,6 +179,10 @@ class DlActivity : Activity() {
|
||||
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
|
||||
@@ -220,6 +227,8 @@ class DlActivity : Activity() {
|
||||
tbtnlist += tbv.tbtn
|
||||
tbtncnt++
|
||||
tbtnUrlList.add(url)
|
||||
val zipPosition = zipArrayList.size
|
||||
zipArrayList += "$title.zip"
|
||||
tbv.tbtn.textOff = title
|
||||
tbv.tbtn.textOn = title
|
||||
tbv.tbtn.text = title
|
||||
@@ -234,10 +243,16 @@ class DlActivity : Activity() {
|
||||
ltbtn.ltbtn.addView(tbv)
|
||||
ltbtn.invalidate()
|
||||
tbv.tbtn.setOnClickListener {
|
||||
val normalAct = (multiSelect && zipf.exists()) || !zipf.exists()
|
||||
if (zipf.exists() && !it.tbtn.isChecked) it.tbtn.setBackgroundResource(R.drawable.rndbg_checked)
|
||||
else it.tbtn.setBackgroundResource(R.drawable.toggle_button)
|
||||
if (it.tbtn.isChecked) tdwn.text = "$dldChapter/${++checkedChapter}"
|
||||
else tdwn.text = "$dldChapter/${--checkedChapter}"
|
||||
else if(normalAct) it.tbtn.setBackgroundResource(R.drawable.toggle_button)
|
||||
if(normalAct){
|
||||
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 {
|
||||
if (zipf.exists()) {
|
||||
@@ -271,6 +286,15 @@ class DlActivity : Activity() {
|
||||
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) {
|
||||
f.delete()
|
||||
v.setBackgroundResource(R.drawable.toggle_button)
|
||||
@@ -301,5 +325,6 @@ class DlActivity : Activity() {
|
||||
|
||||
companion object {
|
||||
var comicName = "Null"
|
||||
var json: String? = null
|
||||
}
|
||||
}
|
||||
@@ -18,46 +18,49 @@ import java.util.regex.Pattern
|
||||
import java.util.zip.ZipInputStream
|
||||
|
||||
class DlListActivity:Activity() {
|
||||
var nullZipDirStr = emptyArray<String>()
|
||||
var handler: DlLHandler? = null
|
||||
var loadingDialog: Dialog? = null
|
||||
private var nullZipDirStr = emptyArray<String>()
|
||||
private var handler: DlLHandler? = null
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_dlist)
|
||||
ttitle.text = intent.getStringExtra("title")
|
||||
loadingDialog = Dialog(this)
|
||||
loadingDialog?.setContentView(R.layout.dialog_loading)
|
||||
handler = DlLHandler(Looper.myLooper()!!, this)
|
||||
handler?.obtainMessage(3, currentDir)?.sendToTarget() //call scanFile
|
||||
}
|
||||
|
||||
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()
|
||||
else o1[0] - o2[0]
|
||||
}?.let {
|
||||
mylv.adapter = ArrayAdapter(this, android.R.layout.simple_list_item_1, it)
|
||||
mylv.setOnItemClickListener { _, _, position, _ ->
|
||||
val chosenFile = File(cd, it[position])
|
||||
val chosenJson = File(chosenFile, "info.bin")
|
||||
//Toast.makeText(this, "进入$chosenFile", Toast.LENGTH_SHORT).show()
|
||||
if (chosenFile.isDirectory) {
|
||||
currentDir = chosenFile
|
||||
startActivity(
|
||||
Intent(
|
||||
this,
|
||||
DlListActivity::class.java
|
||||
).putExtra("title", it[position])
|
||||
)
|
||||
}
|
||||
else{
|
||||
Toast.makeText(this, "加载中...", Toast.LENGTH_SHORT).show()
|
||||
ViewMangaActivity.zipFile = chosenFile
|
||||
ViewMangaActivity.titleText = it[position]
|
||||
ViewMangaActivity.zipPosition = position
|
||||
ViewMangaActivity.zipList = it
|
||||
ViewMangaActivity.cd = cd
|
||||
startActivity(Intent(this, ViewMangaActivity::class.java))
|
||||
when {
|
||||
chosenJson.exists() -> callDownloadActivity(chosenJson)
|
||||
chosenFile.isDirectory -> {
|
||||
currentDir = chosenFile
|
||||
startActivity(
|
||||
Intent(
|
||||
this,
|
||||
DlListActivity::class.java
|
||||
).putExtra("title", it[position])
|
||||
)
|
||||
}
|
||||
chosenFile.name.endsWith(".zip") -> {
|
||||
Toast.makeText(this, "加载中...", Toast.LENGTH_SHORT).show()
|
||||
ViewMangaActivity.zipFile = chosenFile
|
||||
ViewMangaActivity.titleText = it[position]
|
||||
ViewMangaActivity.zipPosition = position
|
||||
ViewMangaActivity.zipList = it
|
||||
ViewMangaActivity.cd = cd
|
||||
startActivity(Intent(this, ViewMangaActivity::class.java))
|
||||
}
|
||||
}
|
||||
}
|
||||
mylv.setOnItemLongClickListener { _, _, position, _ ->
|
||||
@@ -91,9 +94,11 @@ class DlListActivity:Activity() {
|
||||
else Toast.makeText(this, "未发现错误", Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
|
||||
fun showLoading() = loadingDialog?.show()
|
||||
|
||||
fun hideLoading() = loadingDialog?.hide()
|
||||
private fun callDownloadActivity(jsonFile: File){
|
||||
DlActivity.json = jsonFile.readText()
|
||||
DlActivity.comicName = jsonFile.parentFile?.name?:"Null"
|
||||
startActivity(Intent(this, DlActivity::class.java))
|
||||
}
|
||||
|
||||
private fun findNullWebpZipFileInDir(f: File){
|
||||
if (f.isDirectory) f.listFiles()?.let {
|
||||
@@ -156,7 +161,7 @@ class DlListActivity:Activity() {
|
||||
while (matcher.find()) newString.append(matcher.group())
|
||||
}
|
||||
//Log.d("MyDLL2", newString.toString().toFloat().toString())
|
||||
return newString.toString().toFloat()
|
||||
return if(newString.isEmpty()) 0f else newString.toString().toFloat()
|
||||
}
|
||||
|
||||
companion object{
|
||||
|
||||
@@ -94,17 +94,21 @@ class ViewMangaActivity : Activity() {
|
||||
tt.start()
|
||||
ttitle.text = titleText
|
||||
//isearch.visibility = View.VISIBLE
|
||||
try {
|
||||
count = if (mangaZip != null) countZipItems() else imgUrls.size
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
toolsBox.toastError("分析图片url错误")
|
||||
}
|
||||
try {
|
||||
prepareItems()
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
toolsBox.toastError("准备控件错误")
|
||||
Log.d("MyVM", "dlZip2View: $dlZip2View, mangaZip: $mangaZip")
|
||||
if(dlZip2View && mangaZip?.exists() != true) toolsBox.toastError("已经到头了~")
|
||||
else {
|
||||
try {
|
||||
count = if (dlZip2View) countZipItems() else imgUrls.size
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
toolsBox.toastError("分析图片url错误")
|
||||
}
|
||||
try {
|
||||
prepareItems()
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
toolsBox.toastError("准备控件错误")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,8 @@ class DlHandler(activity: DlActivity, looper: Looper) : Handler(looper) {
|
||||
private val da = WeakReference(activity)
|
||||
private val d
|
||||
get() = da.get()
|
||||
private var size = 0
|
||||
private var refreshSize = true
|
||||
|
||||
@ExperimentalStdlibApi
|
||||
@SuppressLint("SetTextI18n")
|
||||
@@ -70,13 +72,13 @@ class DlHandler(activity: DlActivity, looper: Looper) : Handler(looper) {
|
||||
d?.tdwn?.text = "${d?.dldChapter}/${d?.checkedChapter}"
|
||||
}
|
||||
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)
|
||||
if (!(msg.obj as Boolean)) {
|
||||
Toast.makeText(d, "下载${d?.tbtnlist?.get(msg.arg1)?.textOn}的第${msg.arg2}页失败", Toast.LENGTH_SHORT).show()
|
||||
}else{
|
||||
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}"
|
||||
@@ -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()
|
||||
}
|
||||
}
|
||||
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
|
||||
}
|
||||
}
|
||||
@@ -13,15 +13,9 @@ class DlLHandler(looper: Looper, activity: DlListActivity): Handler(looper) {
|
||||
override fun handleMessage(msg: Message) {
|
||||
super.handleMessage(msg)
|
||||
when(msg.what){
|
||||
1 -> load { dll.get()?.checkDir(msg.obj as File) }
|
||||
2 -> load { dll.get()?.rmrf(msg.obj as File) }
|
||||
3 -> load { dll.get()?.scanFile(msg.obj as File) }
|
||||
1 -> dll.get()?.checkDir(msg.obj as File)
|
||||
2 -> dll.get()?.rmrf(msg.obj as File)
|
||||
3 -> dll.get()?.scanFile(msg.obj as File)
|
||||
}
|
||||
}
|
||||
|
||||
private fun load(func:()->Unit){
|
||||
dll.get()?.showLoading()
|
||||
func()
|
||||
dll.get()?.hideLoading()
|
||||
}
|
||||
}
|
||||
@@ -5,16 +5,11 @@ import android.content.Intent
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
import android.os.Message
|
||||
import android.util.Log
|
||||
import android.view.View
|
||||
import com.google.gson.Gson
|
||||
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.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
|
||||
|
||||
class MainHandler(looper: Looper):Handler(looper) {
|
||||
@@ -62,7 +57,7 @@ class MainHandler(looper: Looper):Handler(looper) {
|
||||
private fun setFab(content: String){
|
||||
//Log.d("MyMH", "Get chapter json: $content")
|
||||
showDlList = false
|
||||
comicStructure = Gson().fromJson(content.reader(), Array<ComicStructure>::class.java)
|
||||
json = content
|
||||
showFab()
|
||||
}
|
||||
private fun setFab2DlList(){
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package top.fumiama.copymanga.tool
|
||||
|
||||
import android.os.Looper
|
||||
import android.widget.Toast
|
||||
import top.fumiama.copymanga.R
|
||||
import top.fumiama.copymanga.activity.DlActivity
|
||||
import top.fumiama.copymanga.data.ComicStructure
|
||||
@@ -92,6 +90,5 @@ class MangaDlTools(activity: DlActivity) {
|
||||
|
||||
companion object {
|
||||
var wmdlt: WeakReference<MangaDlTools>? = null
|
||||
var comicStructure: Array<ComicStructure>? = null
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
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
|
||||
@@ -42,7 +43,7 @@ class PagesManager(w: WeakReference<ViewMangaActivity>) {
|
||||
if (if(goNext)isEndR else isEndL){
|
||||
ViewMangaActivity.zipPosition = newZipPosition
|
||||
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.tt.canDo = false
|
||||
v.finish()
|
||||
|
||||
@@ -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>
|
||||
Reference in New Issue
Block a user