Skip to content

Commit b7afd97

Browse files
author
Mamba_out
committed
build: 更新 Gradle 版本和插件
- 将 Android Gradle 插件版本从 9.1.1 更新至 9.2.1。 - 更新 Gradle 包版本至 9.4.1,以确保兼容性和性能优化。
1 parent 153e62e commit b7afd97

3 files changed

Lines changed: 63 additions & 50 deletions

File tree

app/src/main/java/com/hippo/ehviewer/preference/RestoreDownloadPreference.kt

Lines changed: 60 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,16 @@
1616
package com.hippo.ehviewer.preference
1717

1818
import android.app.Activity
19-
import android.app.ProgressDialog
19+
import com.hippo.app.ProgressDialog
2020
import android.content.Context
21-
import android.os.AsyncTask
21+
import android.os.Handler
22+
import android.os.Looper
2223
import android.os.Parcel
2324
import android.os.Parcelable
2425
import android.util.AttributeSet
2526
import android.widget.Toast
2627
import androidx.preference.Preference
28+
import com.google.firebase.crashlytics.FirebaseCrashlytics
2729
import com.hippo.ehviewer.EhApplication
2830
import com.hippo.ehviewer.EhDB
2931
import com.hippo.ehviewer.R
@@ -37,13 +39,15 @@ import com.hippo.ehviewer.spider.SpiderQueen
3739
import com.hippo.lib.yorozuya.IOUtils
3840
import com.hippo.unifile.UniFile
3941
import com.hippo.util.ExceptionUtils.throwIfFatal
42+
import com.hippo.util.IoThreadPoolExecutor
4043
import okhttp3.OkHttpClient
4144
import java.io.IOException
4245
import java.io.InputStream
4346
import java.util.Collections
47+
import java.util.concurrent.atomic.AtomicBoolean
4448

4549
class RestoreDownloadPreference : Preference {
46-
private var mTask: AsyncTask<Void?, Any?, Any?>? = null
50+
private var mTask: RestoreTask? = null
4751

4852
constructor(context: Context, attrs: AttributeSet?) : super(context, attrs)
4953

@@ -56,33 +60,46 @@ class RestoreDownloadPreference : Preference {
5660
override fun onClick() {
5761
super.onClick()
5862
if (mTask == null) {
59-
mTask = RestoreTask(getContext()).execute()
63+
mTask = RestoreTask(context).also { it.start() }
6064
}
6165
}
6266

6367
override fun onDetached() {
64-
if (mTask != null) {
65-
mTask!!.cancel(true)
66-
mTask = null
67-
}
68+
mTask?.cancel()
69+
mTask = null
6870
super.onDetached()
6971
}
7072

71-
private inner class RestoreTask(private val mContext: Context) :
72-
AsyncTask<Void?, Any?, Any?>() {
73-
private val mApplication: EhApplication
74-
private val mManager: DownloadManager
75-
private val mHttpClient: OkHttpClient
73+
private inner class RestoreTask(private val mContext: Context) {
74+
private val mApplication: EhApplication =
75+
mContext.applicationContext as EhApplication
76+
private val mManager: DownloadManager =
77+
EhApplication.getDownloadManager(mApplication)
78+
private val mHttpClient: OkHttpClient =
79+
EhApplication.getOkHttpClient(mApplication)
80+
private val mHandler = Handler(Looper.getMainLooper())
81+
private val mCancelled = AtomicBoolean(false)
7682
private var mProgressDialog: ProgressDialog? = null
7783

78-
init {
79-
mApplication = mContext.getApplicationContext() as EhApplication
80-
mManager = EhApplication.getDownloadManager(mApplication)
81-
mHttpClient = EhApplication.getOkHttpClient(mApplication)
84+
fun start() {
85+
onPreExecute()
86+
IoThreadPoolExecutor.instance.execute {
87+
val result = doInBackground()
88+
mHandler.post {
89+
if (mCancelled.get()) {
90+
onCancelled()
91+
} else {
92+
onPostExecute(result)
93+
}
94+
}
95+
}
96+
}
97+
98+
fun cancel() {
99+
mCancelled.set(true)
82100
}
83101

84-
override fun onPreExecute() {
85-
super.onPreExecute()
102+
private fun onPreExecute() {
86103
mProgressDialog = ProgressDialog(mContext)
87104
mProgressDialog!!.setTitle(R.string.settings_download_restore_download_items)
88105
mProgressDialog!!.setIndeterminate(false)
@@ -95,18 +112,12 @@ class RestoreDownloadPreference : Preference {
95112
if (null == file || !file.isDirectory()) {
96113
return null
97114
}
98-
val siFile = file.findFile(SpiderQueen.SPIDER_INFO_FILENAME)
99-
if (null == siFile) {
100-
return null
101-
}
115+
val siFile = file.findFile(SpiderQueen.SPIDER_INFO_FILENAME) ?: return null
102116

103117
var `is`: InputStream? = null
104118
try {
105119
`is` = siFile.openInputStream()
106-
val spiderInfo = SpiderInfo.read(`is`)
107-
if (spiderInfo == null) {
108-
return null
109-
}
120+
val spiderInfo = SpiderInfo.read(`is`) ?: return null
110121
val gid = spiderInfo.gid
111122
if (mManager.containDownloadInfo(gid)) {
112123
return null
@@ -118,32 +129,33 @@ class RestoreDownloadPreference : Preference {
118129
restoreItem.dirname = file.getName()
119130
return restoreItem
120131
} catch (e: IOException) {
132+
FirebaseCrashlytics.getInstance().recordException(e)
121133
return null
122134
} finally {
123135
IOUtils.closeQuietly(`is`)
124136
}
125137
}
126138

127-
override fun doInBackground(vararg params: Void?): Any? {
128-
val dir = Settings.getDownloadLocation()
129-
if (null == dir) {
139+
private fun doInBackground(): Any? {
140+
if (mCancelled.get()) {
130141
return null
131142
}
143+
val dir = Settings.getDownloadLocation() ?: return null
132144

133-
val restoreItemList: MutableList<RestoreItem?> = ArrayList<RestoreItem?>()
145+
val restoreItemList: MutableList<RestoreItem?> = ArrayList()
134146

135-
val files = dir.listFiles()
136-
if (files == null) {
137-
return null
138-
}
147+
val files = dir.listFiles() ?: return null
139148

140149
val total = files.size
141150
publishProgress(0, total)
142151

143152
for (i in 0..<total) {
153+
if (mCancelled.get()) {
154+
return null
155+
}
144156
val file = files[i]
145157
val restoreItem = getRestoreItem(file)
146-
if (null != restoreItem) {
158+
if (restoreItem != null) {
147159
restoreItemList.add(restoreItem)
148160
}
149161
publishProgress(i + 1, total)
@@ -155,8 +167,8 @@ class RestoreDownloadPreference : Preference {
155167

156168
publishProgress(-1, -1)
157169

158-
try {
159-
return EhEngine.fillGalleryListByApi(
170+
return try {
171+
EhEngine.fillGalleryListByApi(
160172
null,
161173
mHttpClient,
162174
ArrayList<GalleryInfo?>(restoreItemList),
@@ -165,10 +177,14 @@ class RestoreDownloadPreference : Preference {
165177
} catch (e: Throwable) {
166178
throwIfFatal(e)
167179
e.printStackTrace()
168-
return null
180+
null
169181
}
170182
}
171183

184+
private fun publishProgress(progress: Int, max: Int) {
185+
mHandler.post { onProgressUpdate(progress, max) }
186+
}
187+
172188
val isContextValid: Boolean
173189
get() {
174190
if (mContext is Activity) {
@@ -184,7 +200,7 @@ class RestoreDownloadPreference : Preference {
184200
}
185201
if (this.isContextValid) {
186202
try {
187-
if (mProgressDialog!!.isShowing()) {
203+
if (mProgressDialog!!.isShowing) {
188204
mProgressDialog!!.dismiss()
189205
}
190206
} catch (e: IllegalArgumentException) {
@@ -194,11 +210,8 @@ class RestoreDownloadPreference : Preference {
194210
mProgressDialog = null
195211
}
196212

197-
override fun onProgressUpdate(vararg values: Any?) {
198-
super.onProgressUpdate(*values)
213+
private fun onProgressUpdate(progress: Int, max: Int) {
199214
if (mProgressDialog != null && this.isContextValid) {
200-
val progress = values[0] as Int
201-
val max = values[1] as Int
202215
if (progress == -1 && max == -1) {
203216
mProgressDialog!!.setIndeterminate(true)
204217
mProgressDialog!!.setMessage(mApplication.getString(R.string.settings_download_restore_download_items_get_gallery_info))
@@ -210,12 +223,12 @@ class RestoreDownloadPreference : Preference {
210223
}
211224
}
212225

213-
override fun onCancelled() {
226+
private fun onCancelled() {
214227
mTask = null
215228
dismissProgressDialog()
216229
}
217230

218-
override fun onPostExecute(o: Any?) {
231+
private fun onPostExecute(o: Any?) {
219232
mTask = null
220233
dismissProgressDialog()
221234
if (o !is MutableList<*>) {
@@ -284,6 +297,7 @@ class RestoreDownloadPreference : Preference {
284297
}
285298

286299
companion object {
300+
@JvmField
287301
val CREATOR: Parcelable.Creator<RestoreItem?> =
288302
object : Parcelable.Creator<RestoreItem?> {
289303
override fun createFromParcel(source: Parcel): RestoreItem {

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@
3636

3737
// Top-level build file where you can add configuration options common to all sub-projects/modules.
3838
plugins {
39-
id 'com.android.application' version '9.1.1' apply false
40-
id 'com.android.library' version '9.1.1' apply false
39+
id 'com.android.application' version '9.2.1' apply false
40+
id 'com.android.library' version '9.2.1' apply false
4141
id 'com.google.gms.google-services' version '4.4.2' apply false
4242
id "org.jetbrains.kotlin.android" version '2.2.10' apply false
4343
id "org.jetbrains.kotlin.plugin.parcelize" version "2.1.0" apply false

gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
#Thu Apr 30 13:31:17 CST 2026
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
4-
distributionSha256Sum=b266d5ff6b90eada6dc3b20cb090e3731302e553a27c5d3e4df1f0d76beaff06
5-
distributionUrl=https\://services.gradle.org/distributions/gradle-9.3.1-bin.zip
4+
distributionUrl=https\://services.gradle.org/distributions/gradle-9.4.1-bin.zip
65
networkTimeout=10000
76
validateDistributionUrl=true
87
zipStoreBase=GRADLE_USER_HOME

0 commit comments

Comments
 (0)