From ec970564cd432c8966b3e5663e2464c607acc7b3 Mon Sep 17 00:00:00 2001 From: gedoor Date: Fri, 10 Sep 2021 09:32:36 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/api/controller/BookController.kt | 2 +- .../java/io/legado/app/constant/AppLog.kt | 22 ++++------ .../io/legado/app/data/entities/BaseSource.kt | 5 ++- .../io/legado/app/data/entities/BookSource.kt | 2 +- .../main/java/io/legado/app/help/BookHelp.kt | 2 +- .../io/legado/app/help/BookSourceAnalyzer.kt | 2 +- .../java/io/legado/app/help/JsExtensions.kt | 14 +++---- .../java/io/legado/app/help/ReadBookConfig.kt | 6 +-- .../java/io/legado/app/help/ThemeConfig.kt | 2 +- .../io/legado/app/help/coroutine/Coroutine.kt | 3 +- .../java/io/legado/app/help/http/SSLHelper.kt | 9 ++-- .../app/help/http/cronet/CronetLoader.kt | 21 +++++----- .../io/legado/app/help/storage/Preferences.kt | 7 ++-- .../io/legado/app/help/storage/Restore.kt | 10 ++--- .../java/io/legado/app/lib/webdav/WebDav.kt | 5 ++- .../java/io/legado/app/model/CacheBook.kt | 7 +++- .../main/java/io/legado/app/model/ReadBook.kt | 3 +- .../model/analyzeRule/AnalyzeByJSonPath.kt | 3 +- .../app/model/analyzeRule/AnalyzeByJSoup.kt | 3 +- .../app/model/analyzeRule/AnalyzeRule.kt | 2 +- .../io/legado/app/model/localBook/EpubFile.kt | 11 ++--- .../io/legado/app/model/localBook/UmdFile.kt | 7 +--- .../io/legado/app/service/AudioPlayService.kt | 8 ++-- .../app/service/HttpReadAloudService.kt | 2 +- .../java/io/legado/app/service/WebService.kt | 2 +- .../io/legado/app/service/WebTileService.kt | 3 +- .../io/legado/app/ui/about/AppLogDialog.kt | 41 +++++++++++++++++++ .../io/legado/app/ui/about/DonateFragment.kt | 7 +--- .../association/FileAssociationViewModel.kt | 3 +- .../association/ImportBookSourceViewModel.kt | 2 +- .../legado/app/ui/book/cache/CacheActivity.kt | 6 +-- .../app/ui/book/cache/CacheViewModel.kt | 4 +- .../changesource/ChangeSourceViewModel.kt | 5 ++- .../ui/book/explore/ExploreShowViewModel.kt | 3 +- .../legado/app/ui/book/read/TextActionMenu.kt | 2 +- .../ui/book/read/config/BgTextConfigDialog.kt | 6 +-- .../source/edit/BookSourceEditViewModel.kt | 4 +- .../app/ui/document/HandleFileViewModel.kt | 5 ++- .../legado/app/ui/login/RuleUiLoginDialog.kt | 2 +- .../io/legado/app/ui/main/MainViewModel.kt | 3 +- .../ui/rss/article/RssArticlesViewModel.kt | 5 ++- .../rss/source/edit/RssSourceEditViewModel.kt | 2 +- .../io/legado/app/ui/widget/SearchView.kt | 3 +- .../ui/widget/anima/explosion_field/Utils.kt | 3 +- .../legado/app/ui/widget/font/FontAdapter.kt | 2 +- .../app/ui/widget/image/CircleImageView.kt | 3 +- .../main/java/io/legado/app/utils/ACache.kt | 28 ++++++------- .../io/legado/app/utils/ContextExtensions.kt | 4 +- .../java/io/legado/app/utils/DocumentUtils.kt | 2 +- .../java/io/legado/app/utils/FileUtils.kt | 4 +- .../main/java/io/legado/app/utils/LogUtils.kt | 19 ++++++++- .../main/java/io/legado/app/utils/MD5Utils.kt | 2 +- .../java/io/legado/app/utils/NetworkUtils.kt | 6 +-- .../java/io/legado/app/utils/RealPathUtil.kt | 4 +- .../java/io/legado/app/utils/StringUtils.kt | 2 +- .../java/io/legado/app/utils/SystemUtils.kt | 2 +- .../java/io/legado/app/utils/UriExtensions.kt | 4 +- .../io/legado/app/utils/ViewExtensions.kt | 2 +- .../main/java/io/legado/app/utils/ZipUtils.kt | 2 +- .../io/legado/app/web/SourceDebugWebSocket.kt | 7 +--- .../epublib/epub/PackageDocumentWriter.java | 5 ++- 61 files changed, 215 insertions(+), 152 deletions(-) create mode 100644 app/src/main/java/io/legado/app/ui/about/AppLogDialog.kt diff --git a/app/src/main/java/io/legado/app/api/controller/BookController.kt b/app/src/main/java/io/legado/app/api/controller/BookController.kt index 57f4f9a30..49840e844 100644 --- a/app/src/main/java/io/legado/app/api/controller/BookController.kt +++ b/app/src/main/java/io/legado/app/api/controller/BookController.kt @@ -216,7 +216,7 @@ object BookController { if (book.isUmd()) UmdFile.upBookInfo(book) appDb.bookDao.insert(book) } catch (e: Exception) { - e.printStackTrace() + e.printOnDebug() return returnData.setErrorMsg( e.localizedMessage ?: appCtx.getString(R.string.unknown_error) ) diff --git a/app/src/main/java/io/legado/app/constant/AppLog.kt b/app/src/main/java/io/legado/app/constant/AppLog.kt index 038027342..5a7b24498 100644 --- a/app/src/main/java/io/legado/app/constant/AppLog.kt +++ b/app/src/main/java/io/legado/app/constant/AppLog.kt @@ -1,24 +1,16 @@ package io.legado.app.constant -import android.annotation.SuppressLint -import java.text.SimpleDateFormat -import java.util.* - object AppLog { - @SuppressLint("ConstantLocale") - private val logTimeFormat = SimpleDateFormat("[mm:ss.SSS]", Locale.getDefault()) - - val logs = arrayListOf() + val logs = arrayListOf>() - fun addLog(log: String?) { - log ?: return - synchronized(logs) { - if (logs.size > 1000) { - logs.removeLastOrNull() - } - logs.add(0, logTimeFormat.format(Date()) + " " + log) + @Synchronized + fun addLog(message: String?, throwable: Throwable?) { + message ?: return + if (logs.size > 1000) { + logs.removeLastOrNull() } + logs.add(0, Triple(System.currentTimeMillis(), message, throwable)) } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/data/entities/BaseSource.kt b/app/src/main/java/io/legado/app/data/entities/BaseSource.kt index 7a7864a7e..5422f6ede 100644 --- a/app/src/main/java/io/legado/app/data/entities/BaseSource.kt +++ b/app/src/main/java/io/legado/app/data/entities/BaseSource.kt @@ -10,6 +10,7 @@ import io.legado.app.help.http.CookieStore import io.legado.app.utils.EncoderUtils import io.legado.app.utils.GSON import io.legado.app.utils.fromJsonObject +import io.legado.app.utils.printOnDebug import javax.script.SimpleBindings /** @@ -95,7 +96,7 @@ interface BaseSource : JsExtensions { ?: return null return String(decodeBytes) } catch (e: Exception) { - e.printStackTrace() + e.printOnDebug() return null } } @@ -115,7 +116,7 @@ interface BaseSource : JsExtensions { CacheManager.put("userInfo_${getStoreUrl()}", encodeStr) true } catch (e: Exception) { - e.printStackTrace() + e.printOnDebug() false } } diff --git a/app/src/main/java/io/legado/app/data/entities/BookSource.kt b/app/src/main/java/io/legado/app/data/entities/BookSource.kt index 625b9155b..537827f14 100644 --- a/app/src/main/java/io/legado/app/data/entities/BookSource.kt +++ b/app/src/main/java/io/legado/app/data/entities/BookSource.kt @@ -91,7 +91,7 @@ data class BookSource( } } }.onFailure { - it.printStackTrace() + it.printOnDebug() kinds.add(ExploreKind(it.localizedMessage ?: "")) } } diff --git a/app/src/main/java/io/legado/app/help/BookHelp.kt b/app/src/main/java/io/legado/app/help/BookHelp.kt index 1d125eb8d..46dd9faeb 100644 --- a/app/src/main/java/io/legado/app/help/BookHelp.kt +++ b/app/src/main/java/io/legado/app/help/BookHelp.kt @@ -126,7 +126,7 @@ object BookHelp { ).writeBytes(it) } } catch (e: Exception) { - e.printStackTrace() + e.printOnDebug() } finally { downloadImages.remove(src) } diff --git a/app/src/main/java/io/legado/app/help/BookSourceAnalyzer.kt b/app/src/main/java/io/legado/app/help/BookSourceAnalyzer.kt index 909755f95..e68576ac3 100644 --- a/app/src/main/java/io/legado/app/help/BookSourceAnalyzer.kt +++ b/app/src/main/java/io/legado/app/help/BookSourceAnalyzer.kt @@ -140,7 +140,7 @@ object BookSourceAnalyzer { } } } catch (e: Exception) { - e.printStackTrace() + e.printOnDebug() } return source } diff --git a/app/src/main/java/io/legado/app/help/JsExtensions.kt b/app/src/main/java/io/legado/app/help/JsExtensions.kt index a1bdcef74..691f89c1d 100644 --- a/app/src/main/java/io/legado/app/help/JsExtensions.kt +++ b/app/src/main/java/io/legado/app/help/JsExtensions.kt @@ -45,7 +45,7 @@ interface JsExtensions { val analyzeUrl = AnalyzeUrl(urlStr, source = getSource()) analyzeUrl.getStrResponse().body }.onFailure { - it.printStackTrace() + it.printOnDebug() }.getOrElse { it.msg } @@ -80,7 +80,7 @@ interface JsExtensions { kotlin.runCatching { analyzeUrl.getStrResponse() }.onFailure { - it.printStackTrace() + it.printOnDebug() }.getOrElse { StrResponse(analyzeUrl.url, it.localizedMessage) } @@ -94,7 +94,7 @@ interface JsExtensions { kotlin.runCatching { analyzeUrl.getStrResponse() }.onFailure { - it.printStackTrace() + it.printOnDebug() }.getOrElse { StrResponse(analyzeUrl.url, it.localizedMessage) } @@ -480,7 +480,7 @@ interface JsExtensions { iv.encodeToByteArray() ) } catch (e: java.lang.Exception) { - e.printStackTrace() + e.printOnDebug() log(e.localizedMessage ?: "aesDecodeToByteArrayERROR") null } @@ -519,7 +519,7 @@ interface JsExtensions { iv.encodeToByteArray() ) } catch (e: Exception) { - e.printStackTrace() + e.printOnDebug() log(e.localizedMessage ?: "aesDecodeToByteArrayERROR") null } @@ -557,7 +557,7 @@ interface JsExtensions { iv.encodeToByteArray() ) } catch (e: Exception) { - e.printStackTrace() + e.printOnDebug() log(e.localizedMessage ?: "aesEncodeToByteArrayERROR") null } @@ -594,7 +594,7 @@ interface JsExtensions { iv.encodeToByteArray() ) } catch (e: Exception) { - e.printStackTrace() + e.printOnDebug() log(e.localizedMessage ?: "aesEncodeToBase64ByteArrayERROR") null } diff --git a/app/src/main/java/io/legado/app/help/ReadBookConfig.kt b/app/src/main/java/io/legado/app/help/ReadBookConfig.kt index 2598e9c94..c7fc4676e 100644 --- a/app/src/main/java/io/legado/app/help/ReadBookConfig.kt +++ b/app/src/main/java/io/legado/app/help/ReadBookConfig.kt @@ -61,7 +61,7 @@ object ReadBookConfig { val json = configFile.readText() configs = GSON.fromJsonArray(json) } catch (e: Exception) { - e.printStackTrace() + e.printOnDebug() } } (configs ?: DefaultData.readConfigs).let { @@ -78,7 +78,7 @@ object ReadBookConfig { val json = configFile.readText() c = GSON.fromJsonObject(json) } catch (e: Exception) { - e.printStackTrace() + e.printOnDebug() } } shareConfig = c ?: configList.getOrNull(5) ?: Config() @@ -570,7 +570,7 @@ object ReadBookConfig { ) } } catch (e: Exception) { - e.printStackTrace() + e.printOnDebug() } return bgDrawable ?: ColorDrawable(appCtx.getCompatColor(R.color.background)) } diff --git a/app/src/main/java/io/legado/app/help/ThemeConfig.kt b/app/src/main/java/io/legado/app/help/ThemeConfig.kt index 8918a3596..805a83255 100644 --- a/app/src/main/java/io/legado/app/help/ThemeConfig.kt +++ b/app/src/main/java/io/legado/app/help/ThemeConfig.kt @@ -108,7 +108,7 @@ object ThemeConfig { val json = configFile.readText() return GSON.fromJsonArray(json) }.onFailure { - it.printStackTrace() + it.printOnDebug() } } return null diff --git a/app/src/main/java/io/legado/app/help/coroutine/Coroutine.kt b/app/src/main/java/io/legado/app/help/coroutine/Coroutine.kt index e2e89ffe2..d12a053b6 100644 --- a/app/src/main/java/io/legado/app/help/coroutine/Coroutine.kt +++ b/app/src/main/java/io/legado/app/help/coroutine/Coroutine.kt @@ -1,6 +1,7 @@ package io.legado.app.help.coroutine import io.legado.app.BuildConfig +import io.legado.app.utils.printOnDebug import kotlinx.coroutines.* import kotlin.coroutines.CoroutineContext @@ -143,7 +144,7 @@ class Coroutine( } } catch (e: Throwable) { if (BuildConfig.DEBUG) { - e.printStackTrace() + e.printOnDebug() } val consume: Boolean = errorReturn?.value?.let { value -> if (isActive) { diff --git a/app/src/main/java/io/legado/app/help/http/SSLHelper.kt b/app/src/main/java/io/legado/app/help/http/SSLHelper.kt index 81e9c74f7..634595d96 100644 --- a/app/src/main/java/io/legado/app/help/http/SSLHelper.kt +++ b/app/src/main/java/io/legado/app/help/http/SSLHelper.kt @@ -1,6 +1,7 @@ package io.legado.app.help.http import android.annotation.SuppressLint +import io.legado.app.utils.printOnDebug import java.io.IOException import java.io.InputStream import java.security.KeyManagementException @@ -125,9 +126,9 @@ object SSLHelper { sslParams.trustManager = manager return sslParams } catch (e: NoSuchAlgorithmException) { - e.printStackTrace() + e.printOnDebug() } catch (e: KeyManagementException) { - e.printStackTrace() + e.printOnDebug() } return null } @@ -141,7 +142,7 @@ object SSLHelper { kmf.init(clientKeyStore, password.toCharArray()) return kmf.keyManagers } catch (e: Exception) { - e.printStackTrace() + e.printOnDebug() } return null } @@ -160,7 +161,7 @@ object SSLHelper { try { certStream.close() } catch (e: IOException) { - e.printStackTrace() + e.printOnDebug() } } //我们创建一个默认类型的TrustManagerFactory diff --git a/app/src/main/java/io/legado/app/help/http/cronet/CronetLoader.kt b/app/src/main/java/io/legado/app/help/http/cronet/CronetLoader.kt index 67c48af5e..496774b50 100644 --- a/app/src/main/java/io/legado/app/help/http/cronet/CronetLoader.kt +++ b/app/src/main/java/io/legado/app/help/http/cronet/CronetLoader.kt @@ -10,6 +10,7 @@ import com.google.android.gms.net.CronetProviderInstaller import io.legado.app.BuildConfig import io.legado.app.help.AppConfig import io.legado.app.help.coroutine.Coroutine +import io.legado.app.utils.printOnDebug import org.chromium.net.CronetEngine import org.json.JSONObject import splitties.init.appCtx @@ -163,7 +164,7 @@ object CronetLoader : CronetEngine.Builder.LibraryLoader() { abiField.isAccessible = true cpuAbi = abiField.get(appInfo) as String? } catch (e: Exception) { - e.printStackTrace() + e.printOnDebug() } if (TextUtils.isEmpty(cpuAbi)) { cpuAbi = Build.SUPPORTED_ABIS[0] @@ -214,7 +215,7 @@ object CronetLoader : CronetEngine.Builder.LibraryLoader() { } return true } catch (e: Throwable) { - e.printStackTrace() + e.printOnDebug() if (destFile.exists() && !destFile.delete()) { destFile.deleteOnExit() } @@ -223,14 +224,14 @@ object CronetLoader : CronetEngine.Builder.LibraryLoader() { try { inputStream.close() } catch (e: IOException) { - e.printStackTrace() + e.printOnDebug() } } if (outputStream != null) { try { outputStream.close() } catch (e: IOException) { - e.printStackTrace() + e.printOnDebug() } } } @@ -303,20 +304,20 @@ object CronetLoader : CronetEngine.Builder.LibraryLoader() { } return true } catch (e: Exception) { - e.printStackTrace() + e.printOnDebug() } finally { if (fileInputStream != null) { try { fileInputStream.close() } catch (e: Exception) { - e.printStackTrace() + e.printOnDebug() } } if (os != null) { try { os.close() } catch (e: Exception) { - e.printStackTrace() + e.printOnDebug() } } } @@ -338,15 +339,15 @@ object CronetLoader : CronetEngine.Builder.LibraryLoader() { } return String.format("%032x", BigInteger(1, md5.digest())).lowercase() } catch (e: Exception) { - e.printStackTrace() + e.printOnDebug() } catch (e: OutOfMemoryError) { - e.printStackTrace() + e.printOnDebug() } finally { if (fileInputStream != null) { try { fileInputStream.close() } catch (e: Exception) { - e.printStackTrace() + e.printOnDebug() } } } diff --git a/app/src/main/java/io/legado/app/help/storage/Preferences.kt b/app/src/main/java/io/legado/app/help/storage/Preferences.kt index d0674f01e..e640eadc0 100644 --- a/app/src/main/java/io/legado/app/help/storage/Preferences.kt +++ b/app/src/main/java/io/legado/app/help/storage/Preferences.kt @@ -4,6 +4,7 @@ import android.app.Activity import android.content.Context import android.content.ContextWrapper import android.content.SharedPreferences +import io.legado.app.utils.printOnDebug import java.io.File object Preferences { @@ -36,11 +37,11 @@ object Preferences { // 返回修改路径以后的 SharedPreferences :%FILE_PATH%/%fileName%.xml return context.getSharedPreferences(fileName, Activity.MODE_PRIVATE) } catch (e: NoSuchFieldException) { - e.printStackTrace() + e.printOnDebug() } catch (e: IllegalArgumentException) { - e.printStackTrace() + e.printOnDebug() } catch (e: IllegalAccessException) { - e.printStackTrace() + e.printOnDebug() } return null } diff --git a/app/src/main/java/io/legado/app/help/storage/Restore.kt b/app/src/main/java/io/legado/app/help/storage/Restore.kt index 84b3e3a5a..43ff36a36 100644 --- a/app/src/main/java/io/legado/app/help/storage/Restore.kt +++ b/app/src/main/java/io/legado/app/help/storage/Restore.kt @@ -94,7 +94,7 @@ object Restore { } } } catch (e: Exception) { - e.printStackTrace() + e.printOnDebug() } } } @@ -169,7 +169,7 @@ object Restore { ThemeConfig.upConfig() } } catch (e: Exception) { - e.printStackTrace() + e.printOnDebug() } if (!ignoreReadConfig) { try { @@ -181,7 +181,7 @@ object Restore { ReadBookConfig.initConfigs() } } catch (e: Exception) { - e.printStackTrace() + e.printOnDebug() } try { val file = @@ -192,7 +192,7 @@ object Restore { ReadBookConfig.initShareConfig() } } catch (e: Exception) { - e.printStackTrace() + e.printOnDebug() } } Preferences.getSharedPreferences(appCtx, path, "config")?.all?.let { map -> @@ -267,7 +267,7 @@ object Restore { val json = file.readText() return GSON.fromJsonArray(json) } catch (e: Exception) { - e.printStackTrace() + e.printOnDebug() } return null } diff --git a/app/src/main/java/io/legado/app/lib/webdav/WebDav.kt b/app/src/main/java/io/legado/app/lib/webdav/WebDav.kt index 93e3752b2..6d5beb185 100644 --- a/app/src/main/java/io/legado/app/lib/webdav/WebDav.kt +++ b/app/src/main/java/io/legado/app/lib/webdav/WebDav.kt @@ -3,6 +3,7 @@ package io.legado.app.lib.webdav import io.legado.app.help.http.newCall import io.legado.app.help.http.okHttpClient import io.legado.app.help.http.text +import io.legado.app.utils.printOnDebug import okhttp3.* import okhttp3.MediaType.Companion.toMediaType import okhttp3.RequestBody.Companion.asRequestBody @@ -101,7 +102,7 @@ class WebDav(urlStr: String) { method("PROPFIND", requestBody) }.text() }.onFailure { - it.printStackTrace() + it.printOnDebug() }.getOrNull() } return null @@ -133,7 +134,7 @@ class WebDav(urlStr: String) { } list.add(webDavFile) } catch (e: MalformedURLException) { - e.printStackTrace() + e.printOnDebug() } } } diff --git a/app/src/main/java/io/legado/app/model/CacheBook.kt b/app/src/main/java/io/legado/app/model/CacheBook.kt index 8515e6541..139b5c606 100644 --- a/app/src/main/java/io/legado/app/model/CacheBook.kt +++ b/app/src/main/java/io/legado/app/model/CacheBook.kt @@ -12,6 +12,7 @@ import io.legado.app.help.BookHelp import io.legado.app.model.webBook.WebBook import io.legado.app.service.CacheBookService import io.legado.app.utils.postEvent +import io.legado.app.utils.printOnDebug import io.legado.app.utils.startService import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.delay @@ -169,7 +170,11 @@ class CacheBook(var bookSource: BookSource, var book: Book) { if (errorDownloadMap[index] ?: 0 < 3) { waitDownloadSet.add(index) } else { - AppLog.addLog("${book.name}-${chapterTitle} ${error.localizedMessage}") + AppLog.addLog( + "download ${book.name}-${chapterTitle} error:${error.localizedMessage}", + error + ) + error.printOnDebug() } } diff --git a/app/src/main/java/io/legado/app/model/ReadBook.kt b/app/src/main/java/io/legado/app/model/ReadBook.kt index 58882a879..0c90eb1bb 100644 --- a/app/src/main/java/io/legado/app/model/ReadBook.kt +++ b/app/src/main/java/io/legado/app/model/ReadBook.kt @@ -14,6 +14,7 @@ import io.legado.app.ui.book.read.page.entities.TextChapter import io.legado.app.ui.book.read.page.provider.ChapterProvider import io.legado.app.ui.book.read.page.provider.ImageProvider import io.legado.app.utils.msg +import io.legado.app.utils.printOnDebug import io.legado.app.utils.toastOnUi import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers.IO @@ -365,7 +366,7 @@ object ReadBook : CoroutineScope by MainScope() { } } }.onError { - it.printStackTrace() + it.printOnDebug() appCtx.toastOnUi("ChapterProvider ERROR:\n${it.msg}") }.onSuccess { success?.invoke() diff --git a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeByJSonPath.kt b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeByJSonPath.kt index 5ca202521..a2f01b009 100644 --- a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeByJSonPath.kt +++ b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeByJSonPath.kt @@ -3,6 +3,7 @@ package io.legado.app.model.analyzeRule import androidx.annotation.Keep import com.jayway.jsonpath.JsonPath import com.jayway.jsonpath.ReadContext +import io.legado.app.utils.printOnDebug import java.util.* @Suppress("RegExpRedundantEscape") @@ -155,7 +156,7 @@ class AnalyzeByJSonPath(json: Any) { try { return it.read>(rules[0]) } catch (e: Exception) { - e.printStackTrace() + e.printOnDebug() } } return null diff --git a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeByJSoup.kt b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeByJSoup.kt index d9e69c874..19d016416 100644 --- a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeByJSoup.kt +++ b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeByJSoup.kt @@ -1,6 +1,7 @@ package io.legado.app.model.analyzeRule import androidx.annotation.Keep +import io.legado.app.utils.printOnDebug import org.jsoup.Jsoup import org.jsoup.nodes.Element import org.jsoup.select.Collector @@ -254,7 +255,7 @@ class AnalyzeByJSoup(doc: Any) { } } } catch (e: Exception) { - e.printStackTrace() + e.printOnDebug() } return textS diff --git a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt index d088deac5..c76253b7d 100644 --- a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt +++ b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt @@ -653,7 +653,7 @@ class AnalyzeRule( val analyzeUrl = AnalyzeUrl(urlStr, book = book, source = source) analyzeUrl.getStrResponse().body }.onFailure { - it.printStackTrace() + it.printOnDebug() }.getOrElse { it.msg } diff --git a/app/src/main/java/io/legado/app/model/localBook/EpubFile.kt b/app/src/main/java/io/legado/app/model/localBook/EpubFile.kt index c4be8584e..80e56c2d6 100644 --- a/app/src/main/java/io/legado/app/model/localBook/EpubFile.kt +++ b/app/src/main/java/io/legado/app/model/localBook/EpubFile.kt @@ -6,10 +6,7 @@ import android.text.TextUtils import io.legado.app.data.entities.Book import io.legado.app.data.entities.BookChapter import io.legado.app.help.BookHelp -import io.legado.app.utils.FileUtils -import io.legado.app.utils.HtmlFormatter -import io.legado.app.utils.MD5Utils -import io.legado.app.utils.externalFiles +import io.legado.app.utils.* import me.ag2s.epublib.domain.EpubBook import me.ag2s.epublib.epub.EpubReader import org.jsoup.Jsoup @@ -97,7 +94,7 @@ class EpubFile(var book: Book) { } } } catch (e: Exception) { - e.printStackTrace() + e.printOnDebug() } } @@ -111,7 +108,7 @@ class EpubFile(var book: Book) { } catch (e: Exception) { - e.printStackTrace() + e.printOnDebug() } return null } @@ -208,7 +205,7 @@ class EpubFile(var book: Book) { title = elements[0].text() } } catch (e: IOException) { - e.printStackTrace() + e.printOnDebug() } } val chapter = BookChapter() diff --git a/app/src/main/java/io/legado/app/model/localBook/UmdFile.kt b/app/src/main/java/io/legado/app/model/localBook/UmdFile.kt index 0a40f9756..a706179ed 100644 --- a/app/src/main/java/io/legado/app/model/localBook/UmdFile.kt +++ b/app/src/main/java/io/legado/app/model/localBook/UmdFile.kt @@ -4,10 +4,7 @@ import android.net.Uri import android.util.Log import io.legado.app.data.entities.Book import io.legado.app.data.entities.BookChapter -import io.legado.app.utils.FileUtils -import io.legado.app.utils.MD5Utils -import io.legado.app.utils.externalFiles -import io.legado.app.utils.isContentScheme +import io.legado.app.utils.* import me.ag2s.umdlib.domain.UmdBook import me.ag2s.umdlib.umd.UmdReader import splitties.init.appCtx @@ -82,7 +79,7 @@ class UmdFile(var book: Book) { } } } catch (e: Exception) { - e.printStackTrace() + e.printOnDebug() } } diff --git a/app/src/main/java/io/legado/app/service/AudioPlayService.kt b/app/src/main/java/io/legado/app/service/AudioPlayService.kt index 98de0b36f..4fafff661 100644 --- a/app/src/main/java/io/legado/app/service/AudioPlayService.kt +++ b/app/src/main/java/io/legado/app/service/AudioPlayService.kt @@ -137,7 +137,7 @@ class AudioPlayService : BaseService(), exoPlayer.playWhenReady = true exoPlayer.prepare() }.onFailure { - it.printStackTrace() + it.printOnDebug() toastOnUi("$url ${it.localizedMessage}") stopSelf() } @@ -158,7 +158,7 @@ class AudioPlayService : BaseService(), postEvent(EventBus.AUDIO_STATE, Status.PAUSE) upNotification() } catch (e: Exception) { - e.printStackTrace() + e.printOnDebug() } } @@ -177,7 +177,7 @@ class AudioPlayService : BaseService(), postEvent(EventBus.AUDIO_STATE, Status.PLAY) upNotification() } catch (e: Exception) { - e.printStackTrace() + e.printOnDebug() stopSelf() } } @@ -246,7 +246,7 @@ class AudioPlayService : BaseService(), super.onPlayerError(error) AudioPlay.status = Status.STOP postEvent(EventBus.AUDIO_STATE, Status.STOP) - error.printStackTrace() + error.printOnDebug() } override fun onPlayerErrorChanged(error: PlaybackException?) { diff --git a/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt b/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt index 4fb03c628..ce24cf76f 100644 --- a/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt +++ b/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt @@ -148,7 +148,7 @@ class HttpReadAloudService : BaseReadAloudService(), playingIndex = nowSpeak postEvent(EventBus.TTS_PROGRESS, readAloudNumber + 1) } catch (e: Exception) { - e.printStackTrace() + e.printOnDebug() } } } diff --git a/app/src/main/java/io/legado/app/service/WebService.kt b/app/src/main/java/io/legado/app/service/WebService.kt index 06478e1e6..3bfb7c524 100644 --- a/app/src/main/java/io/legado/app/service/WebService.kt +++ b/app/src/main/java/io/legado/app/service/WebService.kt @@ -86,7 +86,7 @@ class WebService : BaseService() { upNotification() } catch (e: IOException) { toastOnUi(e.localizedMessage ?: "") - e.printStackTrace() + e.printOnDebug() stopSelf() } } else { diff --git a/app/src/main/java/io/legado/app/service/WebTileService.kt b/app/src/main/java/io/legado/app/service/WebTileService.kt index 9049db46f..3c964bf71 100644 --- a/app/src/main/java/io/legado/app/service/WebTileService.kt +++ b/app/src/main/java/io/legado/app/service/WebTileService.kt @@ -7,6 +7,7 @@ import android.service.quicksettings.Tile import android.service.quicksettings.TileService import androidx.annotation.RequiresApi import io.legado.app.constant.IntentAction +import io.legado.app.utils.printOnDebug import io.legado.app.utils.startService /** @@ -44,7 +45,7 @@ class WebTileService : TileService() { } } } catch (e: Exception) { - e.printStackTrace() + e.printOnDebug() } return super.onStartCommand(intent, flags, startId) } diff --git a/app/src/main/java/io/legado/app/ui/about/AppLogDialog.kt b/app/src/main/java/io/legado/app/ui/about/AppLogDialog.kt new file mode 100644 index 000000000..301a3de4a --- /dev/null +++ b/app/src/main/java/io/legado/app/ui/about/AppLogDialog.kt @@ -0,0 +1,41 @@ +package io.legado.app.ui.about + +import android.os.Bundle +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import androidx.fragment.app.FragmentManager +import io.legado.app.R +import io.legado.app.base.BaseDialogFragment +import io.legado.app.utils.windowSize + +class AppLogDialog : BaseDialogFragment() { + + companion object { + fun show(fragmentManager: FragmentManager) { + AppLogDialog().show(fragmentManager, "appLogDialog") + } + } + + override fun onStart() { + super.onStart() + val dm = requireActivity().windowSize + dialog?.window?.setLayout( + (dm.widthPixels * 0.9).toInt(), + ViewGroup.LayoutParams.WRAP_CONTENT + ) + } + + override fun onCreateView( + inflater: LayoutInflater, + container: ViewGroup?, + savedInstanceState: Bundle? + ): View? { + return inflater.inflate(R.layout.dialog_book_group_edit, container) + } + + override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) { + + } + +} \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/about/DonateFragment.kt b/app/src/main/java/io/legado/app/ui/about/DonateFragment.kt index 29da08d54..857989643 100644 --- a/app/src/main/java/io/legado/app/ui/about/DonateFragment.kt +++ b/app/src/main/java/io/legado/app/ui/about/DonateFragment.kt @@ -7,10 +7,7 @@ import android.view.View import androidx.preference.Preference import androidx.preference.PreferenceFragmentCompat import io.legado.app.R -import io.legado.app.utils.ACache -import io.legado.app.utils.longToastOnUi -import io.legado.app.utils.openUrl -import io.legado.app.utils.sendToClip +import io.legado.app.utils.* class DonateFragment : PreferenceFragmentCompat() { @@ -49,7 +46,7 @@ class DonateFragment : PreferenceFragmentCompat() { intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) context.startActivity(intent) } catch (e: Exception) { - e.printStackTrace() + e.printOnDebug() } finally { ACache.get(requireContext(), cacheDir = false) .put("proTime", System.currentTimeMillis()) diff --git a/app/src/main/java/io/legado/app/ui/association/FileAssociationViewModel.kt b/app/src/main/java/io/legado/app/ui/association/FileAssociationViewModel.kt index b445d62bf..06092e3d9 100644 --- a/app/src/main/java/io/legado/app/ui/association/FileAssociationViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/association/FileAssociationViewModel.kt @@ -7,6 +7,7 @@ import androidx.lifecycle.MutableLiveData import io.legado.app.base.BaseViewModel import io.legado.app.model.localBook.LocalBook import io.legado.app.utils.isJson +import io.legado.app.utils.printOnDebug import io.legado.app.utils.readText import java.io.File @@ -53,7 +54,7 @@ class FileAssociationViewModel(application: Application) : BaseViewModel(applica onLineImportLive.postValue(uri) } }.onError { - it.printStackTrace() + it.printOnDebug() errorLiveData.postValue(it.localizedMessage) } } diff --git a/app/src/main/java/io/legado/app/ui/association/ImportBookSourceViewModel.kt b/app/src/main/java/io/legado/app/ui/association/ImportBookSourceViewModel.kt index 82b64796b..530063a15 100644 --- a/app/src/main/java/io/legado/app/ui/association/ImportBookSourceViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/association/ImportBookSourceViewModel.kt @@ -117,7 +117,7 @@ class ImportBookSourceViewModel(app: Application) : BaseViewModel(app) { else -> throw Exception(context.getString(R.string.wrong_format)) } }.onError { - it.printStackTrace() + it.printOnDebug() errorLiveData.postValue(it.localizedMessage ?: "") }.onSuccess { comparisonSource() diff --git a/app/src/main/java/io/legado/app/ui/book/cache/CacheActivity.kt b/app/src/main/java/io/legado/app/ui/book/cache/CacheActivity.kt index d90147355..881b5a824 100644 --- a/app/src/main/java/io/legado/app/ui/book/cache/CacheActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/cache/CacheActivity.kt @@ -11,7 +11,6 @@ import io.legado.app.R import io.legado.app.base.VMBaseActivity import io.legado.app.constant.AppConst import io.legado.app.constant.AppConst.charsets -import io.legado.app.constant.AppLog import io.legado.app.constant.EventBus import io.legado.app.constant.PreferKey import io.legado.app.data.appDb @@ -26,8 +25,8 @@ import io.legado.app.lib.dialogs.SelectItem import io.legado.app.lib.dialogs.alert import io.legado.app.lib.dialogs.selector import io.legado.app.model.CacheBook +import io.legado.app.ui.about.AppLogDialog import io.legado.app.ui.document.HandleFileContract -import io.legado.app.ui.widget.dialog.TextListDialog import io.legado.app.utils.* import io.legado.app.utils.viewbindingdelegate.viewBinding import kotlinx.coroutines.Dispatchers @@ -136,8 +135,7 @@ class CacheActivity : VMBaseActivity() R.id.menu_export_file_name -> alertExportFileName() R.id.menu_export_type -> showExportTypeConfig() R.id.menu_export_charset -> showCharsetConfig() - R.id.menu_log -> - TextListDialog.show(supportFragmentManager, getString(R.string.log), AppLog.logs) + R.id.menu_log -> AppLogDialog.show(supportFragmentManager) else -> if (item.groupId == R.id.menu_group) { binding.titleBar.subtitle = item.title groupId = appDb.bookGroupDao.getByName(item.title.toString())?.groupId ?: 0 diff --git a/app/src/main/java/io/legado/app/ui/book/cache/CacheViewModel.kt b/app/src/main/java/io/legado/app/ui/book/cache/CacheViewModel.kt index 4a60240ff..b2152444c 100644 --- a/app/src/main/java/io/legado/app/ui/book/cache/CacheViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/cache/CacheViewModel.kt @@ -56,7 +56,7 @@ class CacheViewModel(application: Application) : BaseViewModel(application) { } }.onError { finally(it.localizedMessage ?: "ERROR") - it.printStackTrace() + it.printOnDebug() }.onSuccess { finally(context.getString(R.string.success)) } @@ -187,7 +187,7 @@ class CacheViewModel(application: Application) : BaseViewModel(application) { } }.onError { finally(it.localizedMessage ?: "ERROR") - it.printStackTrace() + it.printOnDebug() }.onSuccess { finally(context.getString(R.string.success)) } diff --git a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceViewModel.kt b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceViewModel.kt index 61244dd47..ec9eb6bc2 100644 --- a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceViewModel.kt @@ -17,6 +17,7 @@ import io.legado.app.help.coroutine.CompositeCoroutine import io.legado.app.model.webBook.WebBook import io.legado.app.utils.getPrefBoolean import io.legado.app.utils.getPrefString +import io.legado.app.utils.printOnDebug import kotlinx.coroutines.* import kotlinx.coroutines.Dispatchers.IO import splitties.init.appCtx @@ -184,7 +185,7 @@ class ChangeSourceViewModel(application: Application) : BaseViewModel(applicatio searchFinish(searchBook) } }.onError { - it.printStackTrace() + it.printOnDebug() } } @@ -197,7 +198,7 @@ class ChangeSourceViewModel(application: Application) : BaseViewModel(applicatio searchFinish(searchBook) } }.onError { - it.printStackTrace() + it.printOnDebug() } } diff --git a/app/src/main/java/io/legado/app/ui/book/explore/ExploreShowViewModel.kt b/app/src/main/java/io/legado/app/ui/book/explore/ExploreShowViewModel.kt index a03164fe3..eeadaeadc 100644 --- a/app/src/main/java/io/legado/app/ui/book/explore/ExploreShowViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/explore/ExploreShowViewModel.kt @@ -10,6 +10,7 @@ import io.legado.app.data.entities.BookSource import io.legado.app.data.entities.SearchBook import io.legado.app.model.webBook.WebBook import io.legado.app.utils.msg +import io.legado.app.utils.printOnDebug import kotlinx.coroutines.Dispatchers.IO class ExploreShowViewModel(application: Application) : BaseViewModel(application) { @@ -42,7 +43,7 @@ class ExploreShowViewModel(application: Application) : BaseViewModel(application appDb.searchBookDao.insert(*searchBooks.toTypedArray()) page++ }.onError { - it.printStackTrace() + it.printOnDebug() errorLiveData.postValue(it.msg) } } diff --git a/app/src/main/java/io/legado/app/ui/book/read/TextActionMenu.kt b/app/src/main/java/io/legado/app/ui/book/read/TextActionMenu.kt index 811f813f3..26a7f16b6 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/TextActionMenu.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/TextActionMenu.kt @@ -149,7 +149,7 @@ class TextActionMenu(private val context: Context, private val callBack: CallBac } context.startActivity(intent) }.onFailure { - it.printStackTrace() + it.printOnDebug() context.toastOnUi(it.localizedMessage ?: "ERROR") } } diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt index d08cee1aa..4df4eb0ac 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt @@ -282,7 +282,7 @@ class BgTextConfigDialog : BaseDialogFragment() { }.onSuccess { toastOnUi("导出成功, 文件名为 $exportFileName") }.onError { - it.printStackTrace() + it.printOnDebug() longToast("导出失败:${it.localizedMessage}") } } @@ -319,7 +319,7 @@ class BgTextConfigDialog : BaseDialogFragment() { @Suppress("BlockingMethodInNonBlockingContext") importConfig(uri.readBytes(requireContext())!!) }.onError { - it.printStackTrace() + it.printOnDebug() longToast("导入失败:${it.localizedMessage}") } } @@ -333,7 +333,7 @@ class BgTextConfigDialog : BaseDialogFragment() { postEvent(EventBus.UP_CONFIG, true) toastOnUi("导入成功") }.onError { - it.printStackTrace() + it.printOnDebug() longToast("导入失败:${it.localizedMessage}") } } diff --git a/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditViewModel.kt b/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditViewModel.kt index 4fcb45f6b..88c9c250d 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditViewModel.kt @@ -47,7 +47,7 @@ class BookSourceEditViewModel(application: Application) : BaseViewModel(applicat success?.invoke() }.onError { context.toastOnUi(it.localizedMessage) - it.printStackTrace() + it.printOnDebug() } } @@ -61,7 +61,7 @@ class BookSourceEditViewModel(application: Application) : BaseViewModel(applicat } }.onError { context.toastOnUi(it.localizedMessage ?: "Error") - it.printStackTrace() + it.printOnDebug() } } diff --git a/app/src/main/java/io/legado/app/ui/document/HandleFileViewModel.kt b/app/src/main/java/io/legado/app/ui/document/HandleFileViewModel.kt index 60405b6c0..71168e333 100644 --- a/app/src/main/java/io/legado/app/ui/document/HandleFileViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/document/HandleFileViewModel.kt @@ -8,6 +8,7 @@ import io.legado.app.base.BaseViewModel import io.legado.app.help.DirectLinkUpload import io.legado.app.utils.FileUtils import io.legado.app.utils.isContentScheme +import io.legado.app.utils.printOnDebug import io.legado.app.utils.writeBytes import java.io.File @@ -26,7 +27,7 @@ class HandleFileViewModel(application: Application) : BaseViewModel(application) }.onSuccess { success.invoke(it) }.onError { - it.printStackTrace() + it.printOnDebug() errorLiveData.postValue(it.localizedMessage) } } @@ -46,7 +47,7 @@ class HandleFileViewModel(application: Application) : BaseViewModel(application) Uri.fromFile(newFile) } }.onError { - it.printStackTrace() + it.printOnDebug() errorLiveData.postValue(it.localizedMessage) }.onSuccess { success.invoke(it) diff --git a/app/src/main/java/io/legado/app/ui/login/RuleUiLoginDialog.kt b/app/src/main/java/io/legado/app/ui/login/RuleUiLoginDialog.kt index 63ad91368..d6dbfe8cd 100644 --- a/app/src/main/java/io/legado/app/ui/login/RuleUiLoginDialog.kt +++ b/app/src/main/java/io/legado/app/ui/login/RuleUiLoginDialog.kt @@ -129,7 +129,7 @@ class RuleUiLoginDialog : BaseDialogFragment() { dismiss() } } catch (e: Exception) { - e.printStackTrace() + e.printOnDebug() toastOnUi("error:${e.localizedMessage}") } } diff --git a/app/src/main/java/io/legado/app/ui/main/MainViewModel.kt b/app/src/main/java/io/legado/app/ui/main/MainViewModel.kt index c47d2869b..a42a921c3 100644 --- a/app/src/main/java/io/legado/app/ui/main/MainViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/main/MainViewModel.kt @@ -13,6 +13,7 @@ import io.legado.app.help.LocalConfig import io.legado.app.model.CacheBook import io.legado.app.model.webBook.WebBook import io.legado.app.utils.postEvent +import io.legado.app.utils.printOnDebug import kotlinx.coroutines.asCoroutineDispatcher import java.util.concurrent.ConcurrentHashMap import java.util.concurrent.CopyOnWriteArraySet @@ -89,7 +90,7 @@ class MainViewModel(application: Application) : BaseViewModel(application) { ) CacheBook.start(context, book.bookUrl, book.durChapterIndex, endIndex) }.onError(upTocPool) { - it.printStackTrace() + it.printOnDebug() }.onFinally(upTocPool) { synchronized(this) { bookMap.remove(bookEntry.key) diff --git a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesViewModel.kt b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesViewModel.kt index 1a414dec6..de87c3a55 100644 --- a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesViewModel.kt @@ -9,6 +9,7 @@ import io.legado.app.data.appDb import io.legado.app.data.entities.RssArticle import io.legado.app.data.entities.RssSource import io.legado.app.model.rss.Rss +import io.legado.app.utils.printOnDebug import io.legado.app.utils.toastOnUi import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext @@ -52,7 +53,7 @@ class RssArticlesViewModel(application: Application) : BaseViewModel(application } }.onError { loadFinally.postValue(false) - it.printStackTrace() + it.printOnDebug() context.toastOnUi(it.localizedMessage) } } @@ -68,7 +69,7 @@ class RssArticlesViewModel(application: Application) : BaseViewModel(application loadMoreSuccess(it.first) } .onError { - it.printStackTrace() + it.printOnDebug() loadFinally.postValue(false) } } else { diff --git a/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditViewModel.kt b/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditViewModel.kt index 7e14a56e8..453c791f2 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditViewModel.kt @@ -38,7 +38,7 @@ class RssSourceEditViewModel(application: Application) : BaseViewModel(applicati success() }.onError { context.toastOnUi(it.localizedMessage) - it.printStackTrace() + it.printOnDebug() } } diff --git a/app/src/main/java/io/legado/app/ui/widget/SearchView.kt b/app/src/main/java/io/legado/app/ui/widget/SearchView.kt index 975fe9d57..b41d6b418 100644 --- a/app/src/main/java/io/legado/app/ui/widget/SearchView.kt +++ b/app/src/main/java/io/legado/app/ui/widget/SearchView.kt @@ -15,6 +15,7 @@ import android.view.Gravity import android.widget.TextView import androidx.appcompat.widget.SearchView import io.legado.app.R +import io.legado.app.utils.printOnDebug class SearchView @JvmOverloads constructor( context: Context, @@ -42,7 +43,7 @@ class SearchView @JvmOverloads constructor( textView!!.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14f) textView!!.gravity = Gravity.CENTER_VERTICAL } catch (e: Exception) { - e.printStackTrace() + e.printOnDebug() } } diff --git a/app/src/main/java/io/legado/app/ui/widget/anima/explosion_field/Utils.kt b/app/src/main/java/io/legado/app/ui/widget/anima/explosion_field/Utils.kt index 6e33941fb..0974e4a97 100644 --- a/app/src/main/java/io/legado/app/ui/widget/anima/explosion_field/Utils.kt +++ b/app/src/main/java/io/legado/app/ui/widget/anima/explosion_field/Utils.kt @@ -22,6 +22,7 @@ import android.graphics.Canvas import android.graphics.drawable.BitmapDrawable import android.view.View import android.widget.ImageView +import io.legado.app.utils.printOnDebug import kotlin.math.roundToInt object Utils { @@ -65,7 +66,7 @@ object Utils { try { return Bitmap.createBitmap(width, height, config) } catch (e: OutOfMemoryError) { - e.printStackTrace() + e.printOnDebug() if (retryCount > 0) { System.gc() return createBitmapSafely(width, height, config, retryCount - 1) diff --git a/app/src/main/java/io/legado/app/ui/widget/font/FontAdapter.kt b/app/src/main/java/io/legado/app/ui/widget/font/FontAdapter.kt index ddd689a12..5dcb8868a 100644 --- a/app/src/main/java/io/legado/app/ui/widget/font/FontAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/widget/font/FontAdapter.kt @@ -41,7 +41,7 @@ class FontAdapter(context: Context, val callBack: CallBack) : } tvFont.typeface = typeface }.onFailure { - it.printStackTrace() + it.printOnDebug() context.toastOnUi("Read ${item.name} Error: ${it.localizedMessage}") } tvFont.text = item.name diff --git a/app/src/main/java/io/legado/app/ui/widget/image/CircleImageView.kt b/app/src/main/java/io/legado/app/ui/widget/image/CircleImageView.kt index c84097a80..80b65c536 100644 --- a/app/src/main/java/io/legado/app/ui/widget/image/CircleImageView.kt +++ b/app/src/main/java/io/legado/app/ui/widget/image/CircleImageView.kt @@ -20,6 +20,7 @@ import androidx.annotation.RequiresApi import androidx.appcompat.widget.AppCompatImageView import io.legado.app.R import io.legado.app.utils.getCompatColor +import io.legado.app.utils.printOnDebug import io.legado.app.utils.sp import kotlin.math.min import kotlin.math.pow @@ -316,7 +317,7 @@ class CircleImageView @JvmOverloads constructor( drawable.draw(canvas) bitmap } catch (e: Exception) { - e.printStackTrace() + e.printOnDebug() null } diff --git a/app/src/main/java/io/legado/app/utils/ACache.kt b/app/src/main/java/io/legado/app/utils/ACache.kt index 934e0b1f1..64f526dcf 100644 --- a/app/src/main/java/io/legado/app/utils/ACache.kt +++ b/app/src/main/java/io/legado/app/utils/ACache.kt @@ -74,7 +74,7 @@ class ACache private constructor(cacheDir: File, max_size: Long, max_count: Int) } mCache = ACacheManager(cacheDir, max_size, max_count) } catch (e: Exception) { - e.printStackTrace() + e.printOnDebug() } } @@ -96,7 +96,7 @@ class ACache private constructor(cacheDir: File, max_size: Long, max_count: Int) file.writeText(value) mCache.put(file) } catch (e: Exception) { - e.printStackTrace() + e.printOnDebug() } } } @@ -131,7 +131,7 @@ class ACache private constructor(cacheDir: File, max_size: Long, max_count: Int) removeFile = true } } catch (e: IOException) { - e.printStackTrace() + e.printOnDebug() } finally { if (removeFile) remove(key) @@ -269,7 +269,7 @@ class ACache private constructor(cacheDir: File, max_size: Long, max_count: Int) null } } catch (e: Exception) { - e.printStackTrace() + e.printOnDebug() } finally { if (removeFile) remove(key) @@ -299,7 +299,7 @@ class ACache private constructor(cacheDir: File, max_size: Long, max_count: Int) } } } catch (e: Exception) { - e.printStackTrace() + e.printOnDebug() } } @@ -318,18 +318,18 @@ class ACache private constructor(cacheDir: File, max_size: Long, max_count: Int) ois = ObjectInputStream(bis) return ois.readObject() } catch (e: Exception) { - e.printStackTrace() + e.printOnDebug() } finally { try { bis?.close() } catch (e: IOException) { - e.printStackTrace() + e.printOnDebug() } try { ois?.close() } catch (e: IOException) { - e.printStackTrace() + e.printOnDebug() } } @@ -427,7 +427,7 @@ class ACache private constructor(cacheDir: File, max_size: Long, max_count: Int) return f } } catch (e: Exception) { - e.printStackTrace() + e.printOnDebug() } } return null @@ -488,7 +488,7 @@ class ACache private constructor(cacheDir: File, max_size: Long, max_count: Int) } } } catch (e: Exception) { - e.printStackTrace() + e.printOnDebug() } return false @@ -662,7 +662,7 @@ class ACache private constructor(cacheDir: File, max_size: Long, max_count: Int) cacheCount.set(count) } } catch (e: Exception) { - e.printStackTrace() + e.printOnDebug() } @@ -693,7 +693,7 @@ class ACache private constructor(cacheDir: File, max_size: Long, max_count: Int) file.setLastModified(currentTime) lastUsageDates[file] = currentTime } catch (e: Exception) { - e.printStackTrace() + e.printOnDebug() } } @@ -727,7 +727,7 @@ class ACache private constructor(cacheDir: File, max_size: Long, max_count: Int) } } } catch (e: Exception) { - e.printStackTrace() + e.printOnDebug() } } @@ -767,7 +767,7 @@ class ACache private constructor(cacheDir: File, max_size: Long, max_count: Int) } return fileSize } catch (e: Exception) { - e.printStackTrace() + e.printOnDebug() return 0 } diff --git a/app/src/main/java/io/legado/app/utils/ContextExtensions.kt b/app/src/main/java/io/legado/app/utils/ContextExtensions.kt index 38182a14b..417f43b28 100644 --- a/app/src/main/java/io/legado/app/utils/ContextExtensions.kt +++ b/app/src/main/java/io/legado/app/utils/ContextExtensions.kt @@ -157,7 +157,7 @@ val Context.sysScreenOffTime: Int screenOffTime = Settings.System.getInt(contentResolver, Settings.System.SCREEN_OFF_TIMEOUT) } catch (e: Exception) { - e.printStackTrace() + e.printOnDebug() } return screenOffTime } @@ -299,7 +299,7 @@ val Context.channel: String val appInfo = pm.getApplicationInfo(packageName, PackageManager.GET_META_DATA) return appInfo.metaData.getString("channel") ?: "" } catch (e: Exception) { - e.printStackTrace() + e.printOnDebug() } return "" } diff --git a/app/src/main/java/io/legado/app/utils/DocumentUtils.kt b/app/src/main/java/io/legado/app/utils/DocumentUtils.kt index 4a4341a0d..1c428ea78 100644 --- a/app/src/main/java/io/legado/app/utils/DocumentUtils.kt +++ b/app/src/main/java/io/legado/app/utils/DocumentUtils.kt @@ -130,7 +130,7 @@ object DocumentUtils { } } } catch (e: Exception) { - e.printStackTrace() + e.printOnDebug() } finally { c?.close() } diff --git a/app/src/main/java/io/legado/app/utils/FileUtils.kt b/app/src/main/java/io/legado/app/utils/FileUtils.kt index feac3c98a..071050a8a 100644 --- a/app/src/main/java/io/legado/app/utils/FileUtils.kt +++ b/app/src/main/java/io/legado/app/utils/FileUtils.kt @@ -50,7 +50,7 @@ object FileUtils { file.createNewFile() } } catch (e: IOException) { - e.printStackTrace() + e.printOnDebug() } return file } @@ -113,7 +113,7 @@ object FileUtils { try { sdCardDirectory = File(sdCardDirectory).canonicalPath } catch (ioe: IOException) { - ioe.printStackTrace() + ioe.printOnDebug() } return sdCardDirectory } diff --git a/app/src/main/java/io/legado/app/utils/LogUtils.kt b/app/src/main/java/io/legado/app/utils/LogUtils.kt index b94274a3b..6aea8719d 100644 --- a/app/src/main/java/io/legado/app/utils/LogUtils.kt +++ b/app/src/main/java/io/legado/app/utils/LogUtils.kt @@ -1,6 +1,9 @@ +@file:Suppress("unused") + package io.legado.app.utils import android.annotation.SuppressLint +import io.legado.app.BuildConfig import splitties.init.appCtx import java.text.SimpleDateFormat import java.util.* @@ -8,7 +11,7 @@ import java.util.logging.* @Suppress("unused") object LogUtils { - const val TIME_PATTERN = "yyyy-MM-dd HH:mm:ss" + const val TIME_PATTERN = "yy-MM-dd HH:mm:ss.SSS" @JvmStatic fun d(tag: String, msg: String) { @@ -64,4 +67,18 @@ object LogUtils { val sdf = SimpleDateFormat(pattern) return sdf.format(date) } +} + +fun Throwable.printOnDebug() { + if (BuildConfig.DEBUG) { + printStackTrace() + } +} + +fun dLog(tag: String, msg: String) { + LogUtils.d(tag, msg) +} + +fun eLog(tag: String, msg: String) { + LogUtils.e(tag, msg) } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/utils/MD5Utils.kt b/app/src/main/java/io/legado/app/utils/MD5Utils.kt index c0ce9febe..829799597 100644 --- a/app/src/main/java/io/legado/app/utils/MD5Utils.kt +++ b/app/src/main/java/io/legado/app/utils/MD5Utils.kt @@ -25,7 +25,7 @@ object MD5Utils { } reStr = stringBuffer.toString() } catch (e: NoSuchAlgorithmException) { - e.printStackTrace() + e.printOnDebug() } return reStr diff --git a/app/src/main/java/io/legado/app/utils/NetworkUtils.kt b/app/src/main/java/io/legado/app/utils/NetworkUtils.kt index 74f573f38..951cf8cde 100644 --- a/app/src/main/java/io/legado/app/utils/NetworkUtils.kt +++ b/app/src/main/java/io/legado/app/utils/NetworkUtils.kt @@ -114,7 +114,7 @@ object NetworkUtils { relativeUrl = parseUrl.toString() return relativeUrl } catch (e: Exception) { - e.printStackTrace() + e.printOnDebug() } return relativeUrl } @@ -130,7 +130,7 @@ object NetworkUtils { relativeUrl = parseUrl.toString() return relativeUrl } catch (e: Exception) { - e.printStackTrace() + e.printOnDebug() } return relativeUrl } @@ -158,7 +158,7 @@ object NetworkUtils { try { enumeration = NetworkInterface.getNetworkInterfaces() } catch (e: SocketException) { - e.printStackTrace() + e.printOnDebug() } if (enumeration != null) { diff --git a/app/src/main/java/io/legado/app/utils/RealPathUtil.kt b/app/src/main/java/io/legado/app/utils/RealPathUtil.kt index 1f9998277..7205ba078 100644 --- a/app/src/main/java/io/legado/app/utils/RealPathUtil.kt +++ b/app/src/main/java/io/legado/app/utils/RealPathUtil.kt @@ -111,7 +111,7 @@ object RealPathUtil { return cursor.getString(index) } } catch (e: IllegalArgumentException) { - e.printStackTrace() + e.printOnDebug() val file = File(context.cacheDir, "tmp") val filePath = file.absolutePath var input: FileInputStream? = null @@ -130,7 +130,7 @@ object RealPathUtil { } return File(filePath).absolutePath } catch (ignored: IOException) { - ignored.printStackTrace() + ignored.printOnDebug() } finally { input?.close() output?.close() diff --git a/app/src/main/java/io/legado/app/utils/StringUtils.kt b/app/src/main/java/io/legado/app/utils/StringUtils.kt index 3a2bda745..538e5482f 100644 --- a/app/src/main/java/io/legado/app/utils/StringUtils.kt +++ b/app/src/main/java/io/legado/app/utils/StringUtils.kt @@ -95,7 +95,7 @@ object StringUtils { } } }.onFailure { - it.printStackTrace() + it.printOnDebug() } return "" diff --git a/app/src/main/java/io/legado/app/utils/SystemUtils.kt b/app/src/main/java/io/legado/app/utils/SystemUtils.kt index f1c135306..15162d7a3 100644 --- a/app/src/main/java/io/legado/app/utils/SystemUtils.kt +++ b/app/src/main/java/io/legado/app/utils/SystemUtils.kt @@ -21,7 +21,7 @@ object SystemUtils { Settings.System.SCREEN_OFF_TIMEOUT ) }.onFailure { - it.printStackTrace() + it.printOnDebug() } return screenOffTime diff --git a/app/src/main/java/io/legado/app/utils/UriExtensions.kt b/app/src/main/java/io/legado/app/utils/UriExtensions.kt index 5d52b26dd..32fecad88 100644 --- a/app/src/main/java/io/legado/app/utils/UriExtensions.kt +++ b/app/src/main/java/io/legado/app/utils/UriExtensions.kt @@ -41,7 +41,7 @@ fun AppCompatActivity.readUri(uri: Uri?, success: (name: String, bytes: ByteArra .request() } } catch (e: Exception) { - e.printStackTrace() + e.printOnDebug() toastOnUi(e.localizedMessage ?: "read uri error") } } @@ -75,7 +75,7 @@ fun Fragment.readUri(uri: Uri?, success: (name: String, bytes: ByteArray) -> Uni .request() } } catch (e: Exception) { - e.printStackTrace() + e.printOnDebug() toastOnUi(e.localizedMessage ?: "read uri error") } } diff --git a/app/src/main/java/io/legado/app/utils/ViewExtensions.kt b/app/src/main/java/io/legado/app/utils/ViewExtensions.kt index f2b08ef3c..cf40f519e 100644 --- a/app/src/main/java/io/legado/app/utils/ViewExtensions.kt +++ b/app/src/main/java/io/legado/app/utils/ViewExtensions.kt @@ -110,6 +110,6 @@ fun PopupMenu.show(x: Int, y: Int) { field.isAccessible = true (field.get(this) as MenuPopupHelper).show(x, y) }.onFailure { - it.printStackTrace() + it.printOnDebug() } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/utils/ZipUtils.kt b/app/src/main/java/io/legado/app/utils/ZipUtils.kt index b839066af..f7d6ec194 100644 --- a/app/src/main/java/io/legado/app/utils/ZipUtils.kt +++ b/app/src/main/java/io/legado/app/utils/ZipUtils.kt @@ -369,7 +369,7 @@ object ZipUtils { return try { file.createNewFile() } catch (e: IOException) { - e.printStackTrace() + e.printOnDebug() false } } diff --git a/app/src/main/java/io/legado/app/web/SourceDebugWebSocket.kt b/app/src/main/java/io/legado/app/web/SourceDebugWebSocket.kt index 847bc4aad..7bc56202d 100644 --- a/app/src/main/java/io/legado/app/web/SourceDebugWebSocket.kt +++ b/app/src/main/java/io/legado/app/web/SourceDebugWebSocket.kt @@ -6,10 +6,7 @@ import fi.iki.elonen.NanoWSD import io.legado.app.R import io.legado.app.data.appDb import io.legado.app.model.Debug -import io.legado.app.utils.GSON -import io.legado.app.utils.fromJsonObject -import io.legado.app.utils.isJson -import io.legado.app.utils.runOnIO +import io.legado.app.utils.* import kotlinx.coroutines.* import kotlinx.coroutines.Dispatchers.IO import splitties.init.appCtx @@ -89,7 +86,7 @@ class SourceDebugWebSocket(handshakeRequest: NanoHTTPD.IHTTPSession) : close(NanoWSD.WebSocketFrame.CloseCode.NormalClosure, "调试结束", false) } }.onFailure { - it.printStackTrace() + it.printOnDebug() } } } diff --git a/epublib/src/main/java/me/ag2s/epublib/epub/PackageDocumentWriter.java b/epublib/src/main/java/me/ag2s/epublib/epub/PackageDocumentWriter.java index 49db82ae6..060f80aa1 100644 --- a/epublib/src/main/java/me/ag2s/epublib/epub/PackageDocumentWriter.java +++ b/epublib/src/main/java/me/ag2s/epublib/epub/PackageDocumentWriter.java @@ -9,6 +9,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; +import me.ag2s.epublib.BuildConfig; import me.ag2s.epublib.Constants; import me.ag2s.epublib.domain.EpubBook; import me.ag2s.epublib.domain.Guide; @@ -51,7 +52,9 @@ public class PackageDocumentWriter extends PackageDocumentBase { serializer.endDocument(); serializer.flush(); } catch (IOException e) { - e.printStackTrace(); + if (BuildConfig.DEBUG) { + e.printStackTrace(); + } } }