1
0
mirror of https://github.com/fumiama/copymanga.git synced 2026-06-05 07:20:23 +08:00
新增
1. 支持无网络时从下载访问漫画详情页
修复
1. 保存封面超时时间过短
2. 竖向翻页回到上一段闪退
3. 无动画阅览时加载下一页闪屏
4. 排行页快速点击tab时显示错乱
优化
1. 我的下载页的无用代码
This commit is contained in:
源文雨
2024-03-11 03:20:22 +09:00
parent f85191cd0f
commit 35337f2a3f
17 changed files with 83 additions and 42 deletions

View File

@@ -8,7 +8,7 @@ android {
applicationId 'top.fumiama.copymanga'
minSdkVersion 23
targetSdkVersion 34
versionCode 48
versionCode 49
versionName '2.2.1'
resourceConfigurations += ['zh', 'zh-rCN']

View File

@@ -14,7 +14,7 @@
android:usesCleartextTraffic="true">
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.fileprovider"
android:authorities="top.fumiama.copymanga.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
@@ -22,25 +22,24 @@
android:resource="@xml/provider_paths" />
</provider>
<activity
android:name="${applicationId}.MainActivity"
android:name="top.fumiama.copymanga.MainActivity"
android:theme="@style/AppTheme.NoActionBar"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<action android:name="${applicationId}.SHARE"/>
<action android:name="top.fumiama.copymanga.SHARE"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
<activity
android:name="${applicationId}.LoginActivity"
android:name="top.fumiama.copymanga.LoginActivity"
android:theme="@style/AppTheme.NoActionBar"/>
<activity
android:name="com.yalantis.ucrop.UCropActivity"
android:screenOrientation="fullSensor"
android:theme="@style/Theme.AppCompat.Light.NoActionBar"/>
<activity
android:name="${applicationId}.ui.vm.ViewMangaActivity"
android:name="top.fumiama.copymanga.ui.vm.ViewMangaActivity"
android:theme="@style/AppTheme.NoActionBar"/>
</application>

View File

@@ -44,6 +44,7 @@ import kotlinx.android.synthetic.main.activity_main.*
import kotlinx.android.synthetic.main.app_bar_main.*
import kotlinx.android.synthetic.main.nav_header_main.*
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import top.fumiama.copymanga.manga.Shelf
@@ -130,7 +131,7 @@ class MainActivity : AppCompatActivity() {
Log.d("MyMA", "start menu waiting")
lifecycleScope.launch {
withContext(Dispatchers.IO) {
sleep(1000)
delay(1000)
withContext(Dispatchers.Main) {
isMenuWaiting = false
Log.d("MyMA", "finish menu waiting")

View File

@@ -5,10 +5,13 @@ import com.google.gson.Gson
import kotlinx.android.synthetic.main.card_book.*
import kotlinx.android.synthetic.main.line_booktandb.*
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.withContext
import top.fumiama.copymanga.json.BookInfoStructure
import top.fumiama.copymanga.json.ThemeStructure
import top.fumiama.copymanga.json.VolumeStructure
import top.fumiama.copymanga.template.http.PausableDownloader
import top.fumiama.copymanga.tools.api.CMApi
import top.fumiama.copymanga.tools.http.DownloadTools
import top.fumiama.dmzj.copymanga.R
@@ -107,7 +110,9 @@ class Book(val path: String, private val getString: (Int) -> String, private val
mGroupPathWords.forEachIndexed { i, g ->
Volume(path, g, getString) {
return@Volume exit
}.updateChapters(mCounts[i])?.let { volumes += it }
}.updateChapters(mCounts[i])?.let {
volumes += it
}
}
}
if (!exit && volumes.size == mGroupPathWords.size) {
@@ -127,9 +132,11 @@ class Book(val path: String, private val getString: (Int) -> String, private val
File(mangaFolder, "info.json").writeText(mJsonString)
File(mangaFolder, "grps.json").writeText(Gson().toJson(mKeys))
(cover?.let { CMApi.proxy?.wrap(it) } ?:cover)?.let {
DownloadTools.getHttpContent(it, null, mUserAgent)
}?.let { data ->
File(mangaFolder, "head.jpg").writeBytes(data)
Thread {
DownloadTools.getHttpContent(it, -1)?.let { data ->
File(mangaFolder, "head.jpg").writeBytes(data)
}
}.start()
}
}
}

View File

@@ -8,6 +8,7 @@ import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.lifecycleScope
import com.google.gson.Gson
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import top.fumiama.copymanga.MainActivity.Companion.mainWeakReference
@@ -94,13 +95,13 @@ open class AutoDownloadHandler(
}
fi.close()
if(!pass) {
sleep(2000)
delay(2000)
continue
}
break
} catch (e: Exception) {
e.printStackTrace()
sleep(2000)
delay(2000)
}
}
}

View File

@@ -2,6 +2,7 @@ package top.fumiama.copymanga.template.http
import android.util.Log
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.withContext
import top.fumiama.copymanga.MainActivity.Companion.mainWeakReference
import top.fumiama.copymanga.tools.http.DownloadTools
@@ -23,7 +24,7 @@ class PausableDownloader(private val url: String, private val waitMilliseconds:
break
} catch (e: Exception) {
e.printStackTrace()
if (waitMilliseconds > 0) sleep(200+Random.nextLong(waitMilliseconds))
if (waitMilliseconds > 0) delay(200+Random.nextLong(waitMilliseconds))
}
}
Log.d("MyPD", "found exit = $exit")

View File

@@ -73,11 +73,18 @@ class BookFragment: NoBackRefreshFragment(R.layout.fragment_book) {
return@launch
}
Log.d("MyBF", "read path: ${book?.path}")
for (i in 1..4) {
mBookHandler?.sendEmptyMessageDelayed(i, (100*i).toLong())
for (i in 1..3) {
mBookHandler?.sendEmptyMessage(i)
}
book?.updateVolumes {
mBookHandler?.sendEmptyMessage(10)
try {
book?.updateVolumes {
mBookHandler?.sendEmptyMessage(10)
}
} catch (e: Exception) {
e.printStackTrace()
Toast.makeText(context, R.string.null_volume, Toast.LENGTH_SHORT).show()
findNavController().popBackStack()
return@launch
}
}
} else {

View File

@@ -27,6 +27,7 @@ import kotlinx.android.synthetic.main.line_caption.view.*
import kotlinx.android.synthetic.main.line_chapter.view.*
import kotlinx.android.synthetic.main.page_nested_list.view.*
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import top.fumiama.copymanga.MainActivity.Companion.mainWeakReference
@@ -83,7 +84,7 @@ class BookHandler(private val th: WeakReference<BookFragment>): Handler(Looper.m
if (book?.cover != null)
GlideUrl(CMApi.proxy?.wrap(book?.cover!!)?:book?.cover!!, CMApi.myGlideHeaders)
else book?.cachedCover
).timeout(10000).addListener(GlideHideLottieViewListener(WeakReference(laic)))
).addListener(GlideHideLottieViewListener(WeakReference(laic)))
load.into(imic)
context?.let { it1 -> GlideBlurTransformation(it1) }
?.let { it2 -> RequestOptions.bitmapTransform(it2) }
@@ -199,7 +200,7 @@ class BookHandler(private val th: WeakReference<BookFragment>): Handler(Looper.m
val f = CMApi.getZipFile(context?.getExternalFilesDir(""), comicName, keys[p], it.name)
//Log.d("MyBH", "i = $i, last=$last, add chapter ${it.name}, line is null: ${line == null}")
that?.isOnPause?.let { isOnPause ->
while (isOnPause && !exit) sleep(500)
while (isOnPause && !exit) delay(500)
if (exit) return@withContext
}?:return@withContext
if(line == null) {
@@ -260,7 +261,7 @@ class BookHandler(private val th: WeakReference<BookFragment>): Handler(Looper.m
chapterNames += it.name
ViewMangaActivity.uuidArray += it.uuid
that?.isOnPause?.let { isOnPause ->
while (isOnPause && !exit) sleep(500)
while (isOnPause && !exit) delay(500)
if (exit) return@withContext
}?:return@withContext
i++

View File

@@ -6,6 +6,7 @@ import com.google.android.material.tabs.TabLayout
import kotlinx.android.synthetic.main.fragment_rank.*
import kotlinx.android.synthetic.main.line_rank.view.*
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import top.fumiama.copymanga.template.ui.InfoCardLoader
@@ -75,7 +76,7 @@ class RankFragment : InfoCardLoader(R.layout.fragment_rank, R.id.action_nav_rank
lifecycleScope.launch {
isLoading = true
withContext(Dispatchers.IO) {
sleep(400)
delay(400)
withContext(Dispatchers.Main) {
reset()
addPage()

View File

@@ -8,6 +8,7 @@ import androidx.navigation.fragment.findNavController
import kotlinx.android.synthetic.main.anchor_popular.view.*
import kotlinx.android.synthetic.main.line_shelf.*
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import top.fumiama.copymanga.MainActivity
@@ -122,7 +123,7 @@ class ShelfFragment : InfoCardLoader(R.layout.fragment_shelf, R.id.action_nav_su
private fun resetDelayed() {
lifecycleScope.launch {
withContext(Dispatchers.IO) {
sleep(400)
delay(400)
withContext(Dispatchers.Main) {
reset()
addPage()

View File

@@ -8,6 +8,7 @@ import com.google.gson.Gson
import kotlinx.android.synthetic.main.anchor_popular.view.*
import kotlinx.android.synthetic.main.line_sort.*
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import top.fumiama.copymanga.json.FilterStructure
@@ -69,7 +70,7 @@ class SortFragment : StatusCardFlow(0, R.id.action_nav_sort_to_nav_book, R.layou
private fun suspendReset() {
lifecycleScope.launch {
withContext(Dispatchers.IO) {
sleep(400)
delay(400)
withContext(Dispatchers.Main) {
reset()
addPage()

View File

@@ -9,6 +9,7 @@ import androidx.navigation.fragment.findNavController
import com.google.gson.Gson
import kotlinx.android.synthetic.main.fragment_dlcomic.*
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import top.fumiama.copymanga.json.VolumeStructure
@@ -30,7 +31,7 @@ class ComicDlFragment: NoBackRefreshFragment(R.layout.fragment_dlcomic) {
arguments?.getBoolean("callFromOldDL", false) == true -> initOldComicData()
arguments?.containsKey("loadJson") == true -> context?.getExternalFilesDir("")?.let { home ->
arguments?.getString("name")?.let {
sleep(600)
delay(600)
Log.d("MyCDF", "loadJson by arguments")
start2load(
loadFromJson(arguments?.getString("loadJson")!!),

View File

@@ -24,6 +24,7 @@ import kotlinx.android.synthetic.main.fragment_home.*
import kotlinx.android.synthetic.main.line_word.view.*
import kotlinx.android.synthetic.main.viewpage_horizonal.view.*
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import top.fumiama.copymanga.MainActivity
@@ -163,10 +164,10 @@ class HomeFragment : NoBackRefreshFragment(R.layout.fragment_home) {
lifecycleScope.launch{
withContext(Dispatchers.IO) {
homeHandler.obtainMessage(-1, true).sendToTarget()
while(!MainActivity.isDrawerClosed) sleep(233)
while(!MainActivity.isDrawerClosed) delay(233)
//homeHandler.sendEmptyMessage(6) //removeAllViews
homeHandler.fhib = null
sleep(600)
delay(600)
homeHandler.startLoad()
}
}
@@ -196,7 +197,7 @@ class HomeFragment : NoBackRefreshFragment(R.layout.fragment_home) {
//Log.d("MyHomeFVP", "Load img: $it")
Glide.with(this@HomeFragment).load(
GlideUrl(CMApi.proxy?.wrap(it)?:it, CMApi.myGlideHeaders)
).addListener(GlideHideLottieViewListener(WeakReference(holder.itemView.lai))).timeout(10000).into(holder.itemView.vpi)
).addListener(GlideHideLottieViewListener(WeakReference(holder.itemView.lai))).into(holder.itemView.vpi)
}
holder.itemView.vpt.text = thisBanner?.brief
holder.itemView.vpc.setOnClickListener {

View File

@@ -24,6 +24,7 @@ import kotlinx.android.synthetic.main.card_book.view.*
import kotlinx.android.synthetic.main.fragment_home.*
import kotlinx.android.synthetic.main.line_1bookline.view.*
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import top.fumiama.copymanga.json.ComicStructure
@@ -36,6 +37,7 @@ import top.fumiama.copymanga.tools.ui.UITools
import top.fumiama.dmzj.copymanga.R
import java.lang.Thread.sleep
import java.lang.ref.WeakReference
import java.util.concurrent.atomic.AtomicInteger
class HomeHandler(private val that: WeakReference<HomeFragment>) : AutoDownloadHandler(
that.get()?.getString(R.string.mainPageApiUrl)!!.format(CMApi.myHostApiUrl),
@@ -225,7 +227,7 @@ class HomeHandler(private val that: WeakReference<HomeFragment>) : AutoDownloadH
inflateRank()
for(i in indexLines.indices) {
obtainMessage(8, i, 0).sendToTarget()
sleep(512)
delay(512)
}
obtainMessage(-1, false).sendToTarget() //closeLoad
}
@@ -271,7 +273,7 @@ class HomeHandler(private val that: WeakReference<HomeFragment>) : AutoDownloadH
//fhib = null
indexLines = arrayOf()
this@HomeHandler.sendEmptyMessage(6) //removeAllViews
sleep(300)
delay(300)
this@HomeHandler.sendEmptyMessage(0) //setLayouts
}
}
@@ -319,13 +321,21 @@ class HomeHandler(private val that: WeakReference<HomeFragment>) : AutoDownloadH
}
}
private var cardLoadingWaits = AtomicInteger()
private suspend fun setCards(cv: CardView, pw: String, name: String, img: String, isFinal: Boolean, isTopic: Boolean) = withContext(Dispatchers.Main) {
cv.tic.text = name
homeF?.let {
if(img.startsWith("http")) {
Glide.with(it).load(GlideUrl(CMApi.proxy?.wrap(img)?:img, CMApi.myGlideHeaders))
.addListener(GlideHideLottieViewListener(WeakReference(cv.laic)))
.timeout(20000).into(cv.imic)
Log.d("MyHH", "load card image: $img")
val waitMillis = cardLoadingWaits.getAndIncrement().toLong()*200
val g = Glide.with(it).load(GlideUrl(CMApi.proxy?.wrap(img)?:img, CMApi.myGlideHeaders))
.addListener(GlideHideLottieViewListener(WeakReference(cv.laic)) {
cardLoadingWaits.decrementAndGet()
})
if (waitMillis > 0) cv.imic.postDelayed({
g.into(cv.imic)
}, waitMillis) else g.into(cv.imic)
}
}
if (isFinal) cv.sgnic.visibility = View.VISIBLE

View File

@@ -7,22 +7,30 @@ import android.util.Log
import android.view.View
import android.view.Window
import androidx.annotation.Keep
import androidx.lifecycle.lifecycleScope
import androidx.preference.EditTextPreference
import androidx.preference.EditTextPreferenceDialogFragmentCompat
import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.async
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import top.fumiama.copymanga.tools.ui.UITools
import top.fumiama.dmzj.copymanga.R
import java.lang.Thread.sleep
class SettingsFragment: PreferenceFragmentCompat() {
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
Thread {
sleep(300)
activity?.runOnUiThread {
setPreferencesFromResource(R.xml.pref_setting, rootKey)
lifecycleScope.launch {
withContext(Dispatchers.IO) {
delay(300)
withContext(Dispatchers.Main) {
setPreferencesFromResource(R.xml.pref_setting, rootKey)
}
}
}.start()
}
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {

View File

@@ -245,14 +245,14 @@ class ViewMangaActivity : TitleActivityTemplate() {
}
@ExperimentalStdlibApi
private fun doPrepareWebImg() {
private fun doPrepareWebImg() = Thread {
getImgUrlArray()?.apply {
if(cut) {
Log.d("MyVM", "is cut, load all pages...")
handler.sendEmptyMessage(VMHandler.DIALOG_SHOW) //showDl
isCut = BooleanArray(size)
val analyzedCnt = BooleanArray(size)
forEachIndexed{ i, it ->
forEachIndexed { i, it ->
if(it != null) {
Thread{
DownloadTools.getHttpContent(CMApi.resolution.wrap(CMApi.proxy?.wrap(it)?:it), 1024)?.inputStream()?.let {
@@ -276,7 +276,7 @@ class ViewMangaActivity : TitleActivityTemplate() {
runOnUiThread { prepareItems() }
if (notUseVP) prepareDownloadTasks()
}
}
}.start()
@OptIn(ExperimentalStdlibApi::class)
fun initManga() {

View File

@@ -41,6 +41,7 @@
<string name="load_home_error">加载主页控件出错</string>
<string name="text_null">N/A</string>
<string name="null_book">获取图书信息失败</string>
<string name="null_volume">获取图书分卷失败</string>
<string name="web_error">网络错误</string>
<string name="download_cover_failed">保存封面失败</string>
<string name="download_cover_timeout">保存封面超时</string>