From 8dcb62c9846455468955178598f8519a19d19572 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 26 Feb 2022 20:59:43 +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/build.gradle | 5 +- app/src/main/java/io/legado/app/App.kt | 4 -- .../java/io/legado/app/constant/AppLog.kt | 7 +++ .../io/legado/app/data/entities/BaseSource.kt | 6 +- .../io/legado/app/data/entities/BookSource.kt | 3 +- .../main/java/io/legado/app/help/BookHelp.kt | 3 +- .../java/io/legado/app/help/JsExtensions.kt | 21 +++---- .../java/io/legado/app/help/ReadBookConfig.kt | 10 ++-- .../java/io/legado/app/help/SourceAnalyzer.kt | 4 +- .../java/io/legado/app/help/ThemeConfig.kt | 4 +- .../io/legado/app/help/coroutine/Coroutine.kt | 5 +- .../java/io/legado/app/help/http/SSLHelper.kt | 11 ++-- .../app/help/http/cronet/CronetHelper.kt | 6 +- .../app/help/http/cronet/CronetInterceptor.kt | 5 +- .../app/help/http/cronet/CronetLoader.kt | 56 ++++++++++--------- .../help/http/cronet/CronetRequestCallback.kt | 11 ++-- .../io/legado/app/help/storage/OldBook.kt | 4 +- .../io/legado/app/help/storage/Preferences.kt | 11 ++-- .../io/legado/app/help/storage/Restore.kt | 12 ++-- .../java/io/legado/app/lib/webdav/WebDav.kt | 7 ++- .../java/io/legado/app/model/CacheBook.kt | 3 +- .../main/java/io/legado/app/model/ReadBook.kt | 4 +- .../model/analyzeRule/AnalyzeByJSonPath.kt | 9 +-- .../app/model/analyzeRule/AnalyzeRule.kt | 4 +- .../io/legado/app/model/localBook/EpubFile.kt | 11 ++-- .../legado/app/model/localBook/LocalBook.kt | 4 +- .../io/legado/app/model/localBook/UmdFile.kt | 10 ++-- .../io/legado/app/model/webBook/BookInfo.kt | 13 +++-- .../io/legado/app/service/AudioPlayService.kt | 9 ++- .../app/service/HttpReadAloudService.kt | 8 +-- .../java/io/legado/app/service/WebService.kt | 4 +- .../io/legado/app/service/WebTileService.kt | 4 +- .../io/legado/app/ui/about/DonateFragment.kt | 9 +-- .../ui/association/FileAssociationActivity.kt | 5 +- .../association/FileAssociationViewModel.kt | 5 +- .../association/ImportBookSourceViewModel.kt | 4 +- .../app/ui/book/cache/CacheViewModel.kt | 6 +- .../changesource/ChangeBookSourceViewModel.kt | 7 ++- .../ChangeChapterSourceViewModel.kt | 7 ++- .../ui/book/explore/ExploreShowViewModel.kt | 5 +- .../legado/app/ui/book/read/TextActionMenu.kt | 4 +- .../ui/book/read/config/BgTextConfigDialog.kt | 8 +-- .../source/edit/BookSourceEditViewModel.kt | 6 +- .../io/legado/app/ui/browser/WebViewModel.kt | 4 +- .../app/ui/document/HandleFileViewModel.kt | 10 +--- .../java/io/legado/app/ui/font/FontAdapter.kt | 4 +- .../legado/app/ui/login/SourceLoginDialog.kt | 4 +- .../io/legado/app/ui/main/MainViewModel.kt | 3 +- .../ui/rss/article/RssArticlesViewModel.kt | 8 ++- .../rss/source/edit/RssSourceEditViewModel.kt | 5 +- .../io/legado/app/ui/widget/SearchView.kt | 4 +- .../anima/explosion_field/ExplosionView.kt | 7 ++- .../ui/widget/anima/explosion_field/Utils.kt | 5 +- .../app/ui/widget/image/CircleImageView.kt | 9 +-- .../app/ui/widget/recycler/DividerNoLast.kt | 8 ++- .../widget/recycler/DragSelectTouchHelper.kt | 9 +-- .../main/java/io/legado/app/utils/ACache.kt | 32 +++++------ .../io/legado/app/utils/ContextExtensions.kt | 6 +- .../main/java/io/legado/app/utils/DebugLog.kt | 54 ++++++++++++++++++ .../java/io/legado/app/utils/FileUtils.kt | 6 +- .../io/legado/app/utils/GsonExtensions.kt | 8 ++- .../main/java/io/legado/app/utils/LogUtils.kt | 7 +++ .../main/java/io/legado/app/utils/MD5Utils.kt | 4 +- .../java/io/legado/app/utils/NetworkUtils.kt | 9 +-- .../java/io/legado/app/utils/RealPathUtil.kt | 8 +-- .../java/io/legado/app/utils/StringUtils.kt | 4 +- .../java/io/legado/app/utils/UriExtensions.kt | 6 +- .../io/legado/app/utils/ViewExtensions.kt | 4 +- .../main/java/io/legado/app/utils/ZipUtils.kt | 10 ++-- .../web/socket/BookSourceDebugWebSocket.kt | 9 +-- .../app/web/socket/RssSourceDebugWebSocket.kt | 9 +-- build.gradle | 1 + 72 files changed, 334 insertions(+), 267 deletions(-) create mode 100644 app/src/main/java/io/legado/app/utils/DebugLog.kt diff --git a/app/build.gradle b/app/build.gradle index 198696a2e..e41e23383 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -3,6 +3,7 @@ apply plugin: 'kotlin-android' apply plugin: 'kotlin-parcelize' apply plugin: 'kotlin-kapt' apply plugin: 'de.timfreiheit.resourceplaceholders' +apply plugin: 'com.google.gms.google-services' apply from: 'download.gradle' static def releaseTime() { @@ -150,7 +151,9 @@ dependencies { implementation('com.google.code.gson:gson:2.8.9') implementation('androidx.webkit:webkit:1.4.0') - implementation('com.jakewharton.timber:timber:5.0.1') + //firebase + implementation platform('com.google.firebase:firebase-bom:29.1.0') + implementation 'com.google.firebase:firebase-analytics-ktx' //media implementation("androidx.media:media:1.5.0") diff --git a/app/src/main/java/io/legado/app/App.kt b/app/src/main/java/io/legado/app/App.kt index c21437313..8170f6c96 100644 --- a/app/src/main/java/io/legado/app/App.kt +++ b/app/src/main/java/io/legado/app/App.kt @@ -18,16 +18,12 @@ import io.legado.app.help.ThemeConfig.applyDayNight import io.legado.app.help.http.cronet.CronetLoader import io.legado.app.utils.defaultSharedPreferences import splitties.systemservices.notificationManager -import timber.log.Timber class App : MultiDexApplication() { override fun onCreate() { super.onCreate() CrashHandler(this) - if (BuildConfig.DEBUG) { - Timber.plant(Timber.DebugTree()) - } //预下载Cronet so CronetLoader.preDownload() createNotificationChannels() 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 472976d47..82e3d3300 100644 --- a/app/src/main/java/io/legado/app/constant/AppLog.kt +++ b/app/src/main/java/io/legado/app/constant/AppLog.kt @@ -1,5 +1,7 @@ package io.legado.app.constant +import android.util.Log +import io.legado.app.BuildConfig import io.legado.app.help.AppConfig object AppLog { @@ -15,6 +17,11 @@ object AppLog { mLogs.removeLastOrNull() } mLogs.add(0, Triple(System.currentTimeMillis(), message, throwable)) + if (throwable != null) { + if (BuildConfig.DEBUG) { + Log.e(message, throwable.stackTraceToString()) + } + } } @Synchronized 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 2065799b1..00b5f07d2 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 @@ -2,6 +2,7 @@ package io.legado.app.data.entities import android.util.Base64 import io.legado.app.constant.AppConst +import io.legado.app.constant.AppLog import io.legado.app.data.entities.rule.RowUi import io.legado.app.help.AppConfig import io.legado.app.help.CacheManager @@ -11,7 +12,6 @@ import io.legado.app.utils.EncoderUtils import io.legado.app.utils.GSON import io.legado.app.utils.fromJsonArray import io.legado.app.utils.fromJsonObject -import timber.log.Timber import javax.script.SimpleBindings /** @@ -111,7 +111,7 @@ interface BaseSource : JsExtensions { ?: return null return String(decodeBytes) } catch (e: Exception) { - Timber.e(e) + AppLog.put("获取登陆信息出错", e) return null } } @@ -131,7 +131,7 @@ interface BaseSource : JsExtensions { CacheManager.put("userInfo_${getKey()}", encodeStr) true } catch (e: Exception) { - Timber.e(e) + AppLog.put("保存登陆信息出错", e) 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 7c1c09b44..7bdb2b30e 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 @@ -11,7 +11,6 @@ import io.legado.app.utils.* import kotlinx.parcelize.IgnoredOnParcel import kotlinx.parcelize.Parcelize import splitties.init.appCtx -import timber.log.Timber @Parcelize @TypeConverters(BookSource.Converters::class) @@ -120,7 +119,7 @@ data class BookSource( } }.onFailure { kinds.add(ExploreKind("ERROR:${it.localizedMessage}", it.stackTraceToString())) - Timber.e(it) + it.printOnDebug() } } return@lazy kinds 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 30ccebd24..91538ed62 100644 --- a/app/src/main/java/io/legado/app/help/BookHelp.kt +++ b/app/src/main/java/io/legado/app/help/BookHelp.kt @@ -16,7 +16,6 @@ import kotlinx.coroutines.async import kotlinx.coroutines.delay import org.apache.commons.text.similarity.JaccardSimilarity import splitties.init.appCtx -import timber.log.Timber import java.io.File import java.util.concurrent.CopyOnWriteArraySet import java.util.regex.Pattern @@ -131,7 +130,7 @@ object BookHelp { ).writeBytes(it) } } catch (e: Exception) { - Timber.e(e) + e.printOnDebug() } finally { downloadImages.remove(src) } 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 072a07c4d..6999546a4 100644 --- a/app/src/main/java/io/legado/app/help/JsExtensions.kt +++ b/app/src/main/java/io/legado/app/help/JsExtensions.kt @@ -6,7 +6,6 @@ import androidx.annotation.Keep import cn.hutool.crypto.digest.DigestUtil import cn.hutool.crypto.symmetric.AES import cn.hutool.crypto.symmetric.DESede -import io.legado.app.BuildConfig import io.legado.app.constant.AppConst import io.legado.app.constant.AppConst.dateFormat import io.legado.app.constant.AppLog @@ -22,7 +21,6 @@ import kotlinx.coroutines.runBlocking import org.jsoup.Connection import org.jsoup.Jsoup import splitties.init.appCtx -import timber.log.Timber import java.io.ByteArrayInputStream import java.io.ByteArrayOutputStream import java.io.File @@ -54,7 +52,7 @@ interface JsExtensions { analyzeUrl.getStrResponseAwait().body }.onFailure { log("ajax(${urlStr}) error\n${it.stackTraceToString()}") - Timber.e(it) + it.printOnDebug() }.getOrElse { it.msg } @@ -90,7 +88,7 @@ interface JsExtensions { analyzeUrl.getStrResponseAwait() }.onFailure { log("connect(${urlStr}) error\n${it.stackTraceToString()}") - Timber.e(it) + it.printOnDebug() }.getOrElse { StrResponse(analyzeUrl.url, it.localizedMessage) } @@ -105,7 +103,7 @@ interface JsExtensions { analyzeUrl.getStrResponseAwait() }.onFailure { log("ajax($urlStr,$header) error\n${it.stackTraceToString()}") - Timber.e(it) + it.printOnDebug() }.getOrElse { StrResponse(analyzeUrl.url, it.localizedMessage) } @@ -481,7 +479,7 @@ interface JsExtensions { CacheManager.put(key, qTTF) return qTTF } catch (e: Exception) { - Timber.e(e, "获取字体处理类出错") + AppLog.put("获取字体处理类出错", e) throw e } } @@ -518,9 +516,6 @@ interface JsExtensions { getSource()?.let { Debug.log(it.getKey(), msg.toString()) } ?: Debug.log(msg.toString()) - if (BuildConfig.DEBUG) { - Timber.d(msg.toString()) - } AppLog.putDebug(msg.toString()) return msg } @@ -561,7 +556,7 @@ interface JsExtensions { iv.encodeToByteArray() ) } catch (e: Exception) { - Timber.e(e) + e.printOnDebug() log(e.localizedMessage ?: "aesDecodeToByteArrayERROR") null } @@ -600,7 +595,7 @@ interface JsExtensions { iv.encodeToByteArray() ) } catch (e: Exception) { - Timber.e(e) + e.printOnDebug() log(e.localizedMessage ?: "aesDecodeToByteArrayERROR") null } @@ -638,7 +633,7 @@ interface JsExtensions { iv.encodeToByteArray() ) } catch (e: Exception) { - Timber.e(e) + e.printOnDebug() log(e.localizedMessage ?: "aesEncodeToByteArrayERROR") null } @@ -675,7 +670,7 @@ interface JsExtensions { iv.encodeToByteArray() ) } catch (e: Exception) { - Timber.e(e) + 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 c0b76fe04..45e789df3 100644 --- a/app/src/main/java/io/legado/app/help/ReadBookConfig.kt +++ b/app/src/main/java/io/legado/app/help/ReadBookConfig.kt @@ -13,7 +13,7 @@ import io.legado.app.utils.* import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.withContext import splitties.init.appCtx -import timber.log.Timber + import java.io.File /** @@ -62,7 +62,7 @@ object ReadBookConfig { val json = configFile.readText() configs = GSON.fromJsonArray(json) } catch (e: Exception) { - Timber.e(e) + e.printOnDebug() } } (configs ?: DefaultData.readConfigs).let { @@ -79,7 +79,7 @@ object ReadBookConfig { val json = configFile.readText() c = GSON.fromJsonObject(json) } catch (e: Exception) { - Timber.e(e) + e.printOnDebug() } } shareConfig = c ?: configList.getOrNull(5) ?: Config() @@ -580,9 +580,9 @@ object ReadBookConfig { ) } } catch (e: OutOfMemoryError) { - Timber.e(e) + e.printOnDebug() } catch (e: Exception) { - Timber.e(e) + e.printOnDebug() } return bgDrawable ?: ColorDrawable(appCtx.getCompatColor(R.color.background)) } diff --git a/app/src/main/java/io/legado/app/help/SourceAnalyzer.kt b/app/src/main/java/io/legado/app/help/SourceAnalyzer.kt index 02f33e0fc..666e21a66 100644 --- a/app/src/main/java/io/legado/app/help/SourceAnalyzer.kt +++ b/app/src/main/java/io/legado/app/help/SourceAnalyzer.kt @@ -7,7 +7,7 @@ import io.legado.app.constant.BookType import io.legado.app.data.entities.BookSource import io.legado.app.data.entities.rule.* import io.legado.app.utils.* -import timber.log.Timber + import java.util.regex.Pattern @Suppress("RegExpRedundantEscape") @@ -159,7 +159,7 @@ object SourceAnalyzer { } } } catch (e: Exception) { - Timber.e(e) + e.printOnDebug() } return source } 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 482c91df6..35ed45062 100644 --- a/app/src/main/java/io/legado/app/help/ThemeConfig.kt +++ b/app/src/main/java/io/legado/app/help/ThemeConfig.kt @@ -14,7 +14,7 @@ import io.legado.app.lib.theme.ThemeStore import io.legado.app.model.BookCover import io.legado.app.utils.* import splitties.init.appCtx -import timber.log.Timber + import java.io.File object ThemeConfig { @@ -108,7 +108,7 @@ object ThemeConfig { val json = configFile.readText() return GSON.fromJsonArray(json) }.onFailure { - Timber.e(it) + 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 70664c1d4..538d6a8e2 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,7 +1,8 @@ package io.legado.app.help.coroutine +import io.legado.app.utils.printOnDebug import kotlinx.coroutines.* -import timber.log.Timber + import kotlin.coroutines.CoroutineContext /** @@ -144,7 +145,7 @@ class Coroutine( ensureActive() success?.let { dispatchCallback(this, value, it) } } catch (e: Throwable) { - Timber.e(e) + e.printOnDebug() if (e is CancellationException && e !is TimeoutCancellationException) { return@launch } 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 ecbcc1f02..a0f26f24f 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,8 +1,9 @@ package io.legado.app.help.http import android.annotation.SuppressLint +import io.legado.app.utils.printOnDebug + -import timber.log.Timber import java.io.IOException import java.io.InputStream import java.security.KeyManagementException @@ -127,9 +128,9 @@ object SSLHelper { sslParams.trustManager = manager return sslParams } catch (e: NoSuchAlgorithmException) { - Timber.e(e) + e.printOnDebug() } catch (e: KeyManagementException) { - Timber.e(e) + e.printOnDebug() } return null } @@ -143,7 +144,7 @@ object SSLHelper { kmf.init(clientKeyStore, password.toCharArray()) return kmf.keyManagers } catch (e: Exception) { - Timber.e(e) + e.printOnDebug() } return null } @@ -162,7 +163,7 @@ object SSLHelper { try { certStream.close() } catch (e: IOException) { - Timber.e(e) + e.printOnDebug() } } //我们创建一个默认类型的TrustManagerFactory diff --git a/app/src/main/java/io/legado/app/help/http/cronet/CronetHelper.kt b/app/src/main/java/io/legado/app/help/http/cronet/CronetHelper.kt index 44d82438e..745d984ac 100644 --- a/app/src/main/java/io/legado/app/help/http/cronet/CronetHelper.kt +++ b/app/src/main/java/io/legado/app/help/http/cronet/CronetHelper.kt @@ -2,6 +2,7 @@ package io.legado.app.help.http.cronet import io.legado.app.constant.AppLog import io.legado.app.help.AppConfig +import io.legado.app.utils.DebugLog import okhttp3.Headers import okhttp3.MediaType import okhttp3.Request @@ -11,7 +12,7 @@ import org.chromium.net.ExperimentalCronetEngine import org.chromium.net.UploadDataProviders import org.chromium.net.UrlRequest import splitties.init.appCtx -import timber.log.Timber + import java.util.concurrent.ExecutorService import java.util.concurrent.Executors @@ -35,11 +36,10 @@ val cronetEngine: ExperimentalCronetEngine? by lazy { } try { val engine = builder.build() - Timber.d("Cronet Version:" + engine.versionString) + DebugLog.d("Cronet Version:", engine.versionString) return@lazy engine } catch (e: UnsatisfiedLinkError) { AppLog.put("初始化cronetEngine出错", e) - Timber.e(e, "初始化cronetEngine出错") return@lazy null } } diff --git a/app/src/main/java/io/legado/app/help/http/cronet/CronetInterceptor.kt b/app/src/main/java/io/legado/app/help/http/cronet/CronetInterceptor.kt index e1b2372b4..caeba568b 100644 --- a/app/src/main/java/io/legado/app/help/http/cronet/CronetInterceptor.kt +++ b/app/src/main/java/io/legado/app/help/http/cronet/CronetInterceptor.kt @@ -1,8 +1,9 @@ package io.legado.app.help.http.cronet import io.legado.app.help.http.CookieStore +import io.legado.app.utils.printOnDebug import okhttp3.* -import timber.log.Timber + class CronetInterceptor(private val cookieJar: CookieJar?) : Interceptor { @@ -33,7 +34,7 @@ class CronetInterceptor(private val cookieJar: CookieJar?) : Interceptor { if (!e.message.toString().contains("ERR_CERT_", true) && !e.message.toString().contains("ERR_SSL_", true) ) { - Timber.e(e) + e.printOnDebug() } chain.proceed(original) } 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 abcecfda2..010d1cd0d 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 @@ -8,11 +8,13 @@ import android.text.TextUtils import io.legado.app.BuildConfig import io.legado.app.help.AppConfig import io.legado.app.help.coroutine.Coroutine +import io.legado.app.utils.DebugLog +import io.legado.app.utils.printOnDebug import org.chromium.net.CronetEngine import org.json.JSONObject import splitties.init.appCtx -import timber.log.Timber + import java.io.* import java.math.BigInteger import java.net.HttpURLConnection @@ -36,16 +38,16 @@ object CronetLoader : CronetEngine.Builder.LibraryLoader() { init { soUrl = ("https://storage.googleapis.com/chromium-cronet/android/" - + soVersion + "/Release/cronet/libs/" - + getCpuAbi(appCtx) + "/" + soName) + + soVersion + "/Release/cronet/libs/" + + getCpuAbi(appCtx) + "/" + soName) md5 = getMd5(appCtx) val dir = appCtx.getDir("cronet", Context.MODE_PRIVATE) soFile = File(dir.toString() + "/" + getCpuAbi(appCtx), soName) downloadFile = File(appCtx.cacheDir.toString() + "/so_download", soName) - Timber.d("soName+:$soName") - Timber.d("destSuccessFile:$soFile") - Timber.d("tempFile:$downloadFile") - Timber.d("soUrl:$soUrl") + DebugLog.d(javaClass.simpleName, "soName+:$soName") + DebugLog.d(javaClass.simpleName, "destSuccessFile:$soFile") + DebugLog.d(javaClass.simpleName, "tempFile:$downloadFile") + DebugLog.d(javaClass.simpleName, "soUrl:$soUrl") } /** @@ -77,11 +79,11 @@ object CronetLoader : CronetEngine.Builder.LibraryLoader() { Coroutine.async { //md5 = getUrlMd5(md5Url) if (soFile.exists() && md5 == getFileMD5(soFile)) { - Timber.d("So 库已存在") + DebugLog.d(javaClass.simpleName, "So 库已存在") } else { download(soUrl, md5, downloadFile, soFile) } - Timber.d(soName) + DebugLog.d(javaClass.simpleName, soName) } } @@ -108,7 +110,7 @@ object CronetLoader : CronetEngine.Builder.LibraryLoader() { @SuppressLint("UnsafeDynamicallyLoadedCode") override fun loadLibrary(libName: String) { - Timber.d("libName:$libName") + DebugLog.d(javaClass.simpleName, "libName:$libName") val start = System.currentTimeMillis() @Suppress("SameParameterValue") try { @@ -120,13 +122,13 @@ object CronetLoader : CronetEngine.Builder.LibraryLoader() { //以下逻辑为cronet加载,优先加载本地,否则从远程加载 //首先调用系统行为进行加载 System.loadLibrary(libName) - Timber.d("load from system") + DebugLog.d(javaClass.simpleName, "load from system") } catch (e: Throwable) { //如果找不到,则从远程下载 //删除历史文件 deleteHistoryFile(Objects.requireNonNull(soFile.parentFile), soFile) //md5 = getUrlMd5(md5Url) - Timber.d("soMD5:$md5") + DebugLog.d(javaClass.simpleName, "soMD5:$md5") if (md5.length != 32 || soUrl.isEmpty()) { //如果md5或下载的url为空,则调用系统行为进行加载 System.loadLibrary(libName) @@ -145,7 +147,7 @@ object CronetLoader : CronetEngine.Builder.LibraryLoader() { if (fileMD5 != null && fileMD5.equals(md5, ignoreCase = true)) { //md5值一样,则加载 System.load(soFile.absolutePath) - Timber.d("load from:$soFile") + DebugLog.d(javaClass.simpleName, "load from:$soFile") return } //md5不一样则删除 @@ -156,7 +158,7 @@ object CronetLoader : CronetEngine.Builder.LibraryLoader() { //使用系统加载方法 System.loadLibrary(libName) } finally { - Timber.d("time:" + (System.currentTimeMillis() - start)) + DebugLog.d(javaClass.simpleName, "time:" + (System.currentTimeMillis() - start)) } } @@ -172,7 +174,7 @@ object CronetLoader : CronetEngine.Builder.LibraryLoader() { abiField.isAccessible = true cpuAbi = abiField.get(appInfo) as String? } catch (e: Exception) { - Timber.e(e) + e.printOnDebug() } if (TextUtils.isEmpty(cpuAbi)) { cpuAbi = Build.SUPPORTED_ABIS[0] @@ -191,7 +193,7 @@ object CronetLoader : CronetEngine.Builder.LibraryLoader() { for (f in files) { if (f.exists() && (currentFile == null || f.absolutePath != currentFile.absolutePath)) { val delete = f.delete() - Timber.d("delete file: $f result: $delete") + DebugLog.d(javaClass.simpleName, "delete file: $f result: $delete") if (!delete) { f.deleteOnExit() } @@ -223,7 +225,7 @@ object CronetLoader : CronetEngine.Builder.LibraryLoader() { } return true } catch (e: Throwable) { - Timber.e(e) + e.printOnDebug() if (destFile.exists() && !destFile.delete()) { destFile.deleteOnExit() } @@ -232,14 +234,14 @@ object CronetLoader : CronetEngine.Builder.LibraryLoader() { try { inputStream.close() } catch (e: IOException) { - Timber.e(e) + e.printOnDebug() } } if (outputStream != null) { try { outputStream.close() } catch (e: IOException) { - Timber.e(e) + e.printOnDebug() } } } @@ -263,7 +265,7 @@ object CronetLoader : CronetEngine.Builder.LibraryLoader() { download = true executor.execute { val result = downloadFileIfNotExist(url, downloadTempFile) - Timber.d("download result:$result") + DebugLog.d(javaClass.simpleName, "download result:$result") //文件md5再次校验 val fileMD5 = getFileMD5(downloadTempFile) if (md5 != null && !md5.equals(fileMD5, ignoreCase = true)) { @@ -274,7 +276,7 @@ object CronetLoader : CronetEngine.Builder.LibraryLoader() { download = false return@execute } - Timber.d("download success, copy to $destSuccessFile") + DebugLog.d(javaClass.simpleName, "download success, copy to $destSuccessFile") //下载成功拷贝文件 copyFile(downloadTempFile, destSuccessFile) cacheInstall = false @@ -313,20 +315,20 @@ object CronetLoader : CronetEngine.Builder.LibraryLoader() { } return true } catch (e: Exception) { - Timber.e(e) + e.printOnDebug() } finally { if (fileInputStream != null) { try { fileInputStream.close() } catch (e: Exception) { - Timber.e(e) + e.printOnDebug() } } if (os != null) { try { os.close() } catch (e: Exception) { - Timber.e(e) + e.printOnDebug() } } } @@ -348,15 +350,15 @@ object CronetLoader : CronetEngine.Builder.LibraryLoader() { } return String.format("%032x", BigInteger(1, md5.digest())).lowercase() } catch (e: Exception) { - Timber.e(e) + e.printOnDebug() } catch (e: OutOfMemoryError) { - Timber.e(e) + e.printOnDebug() } finally { if (fileInputStream != null) { try { fileInputStream.close() } catch (e: Exception) { - Timber.e(e) + e.printOnDebug() } } } diff --git a/app/src/main/java/io/legado/app/help/http/cronet/CronetRequestCallback.kt b/app/src/main/java/io/legado/app/help/http/cronet/CronetRequestCallback.kt index 30807dafc..9c9506e6d 100644 --- a/app/src/main/java/io/legado/app/help/http/cronet/CronetRequestCallback.kt +++ b/app/src/main/java/io/legado/app/help/http/cronet/CronetRequestCallback.kt @@ -2,6 +2,7 @@ package io.legado.app.help.http.cronet import android.os.ConditionVariable import io.legado.app.help.http.okHttpClient +import io.legado.app.utils.DebugLog import okhttp3.* import okhttp3.EventListener import okhttp3.MediaType.Companion.toMediaTypeOrNull @@ -10,7 +11,7 @@ import okio.Buffer import org.chromium.net.CronetException import org.chromium.net.UrlRequest import org.chromium.net.UrlResponseInfo -import timber.log.Timber + import java.io.IOException import java.nio.ByteBuffer import java.util.* @@ -86,7 +87,7 @@ class CronetRequestCallback @JvmOverloads internal constructor( // } // Log.e("Cronet", sb.toString()) //打印协议,用于调试 - Timber.i(info.negotiatedProtocol) + DebugLog.i(javaClass.name, info.negotiatedProtocol) if (eventListener != null) { eventListener.responseHeadersEnd(mCall, this.mResponse) eventListener.responseBodyStart(mCall) @@ -107,7 +108,7 @@ class CronetRequestCallback @JvmOverloads internal constructor( try { mBuffer.write(byteBuffer) } catch (e: IOException) { - Timber.i(e, "IOException during ByteBuffer read. Details: ") + DebugLog.i(javaClass.name, "IOException during ByteBuffer read. Details: ", e) throw e } byteBuffer.clear() @@ -135,7 +136,7 @@ class CronetRequestCallback @JvmOverloads internal constructor( //UrlResponseInfo可能为null override fun onFailed(request: UrlRequest, info: UrlResponseInfo?, error: CronetException) { - Timber.e(error.message.toString()) + DebugLog.i(javaClass.name, error.message.toString()) val msg = error.localizedMessage val e = IOException(msg?.substring(msg.indexOf("net::")), error) mException = e @@ -192,7 +193,7 @@ class CronetRequestCallback @JvmOverloads internal constructor( } add(key, value) } catch (e: Exception) { - Timber.w("Invalid HTTP header/value: $key$value") + DebugLog.w(javaClass.name, "Invalid HTTP header/value: $key$value") // Ignore that header } } diff --git a/app/src/main/java/io/legado/app/help/storage/OldBook.kt b/app/src/main/java/io/legado/app/help/storage/OldBook.kt index 64f8e45c4..fd3c939d8 100644 --- a/app/src/main/java/io/legado/app/help/storage/OldBook.kt +++ b/app/src/main/java/io/legado/app/help/storage/OldBook.kt @@ -3,7 +3,7 @@ package io.legado.app.help.storage import io.legado.app.data.appDb import io.legado.app.data.entities.Book import io.legado.app.utils.* -import timber.log.Timber + object OldBook { @@ -18,7 +18,7 @@ object OldBook { if (book.bookUrl.isBlank()) continue book.name = jsonItem.readString("$.bookInfoBean.name") ?: "" if (book.bookUrl in existingBooks) { - Timber.d("Found existing book: " + book.name) + DebugLog.d(javaClass.name, "Found existing book: " + book.name) continue } book.origin = jsonItem.readString("$.tag") ?: "" 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 3559ae944..c0fbdd6c8 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 @@ -1,11 +1,13 @@ package io.legado.app.help.storage +import android.annotation.SuppressLint import android.app.Activity import android.content.Context import android.content.ContextWrapper import android.content.SharedPreferences +import io.legado.app.utils.printOnDebug + -import timber.log.Timber import java.io.File object Preferences { @@ -17,6 +19,7 @@ object Preferences { * @param fileName 文件名,不需要 '.xml' 后缀 * @return */ + @SuppressLint("DiscouragedPrivateApi") fun getSharedPreferences( context: Context, dir: String, @@ -38,11 +41,11 @@ object Preferences { // 返回修改路径以后的 SharedPreferences :%FILE_PATH%/%fileName%.xml return context.getSharedPreferences(fileName, Activity.MODE_PRIVATE) } catch (e: NoSuchFieldException) { - Timber.e(e) + e.printOnDebug() } catch (e: IllegalArgumentException) { - Timber.e(e) + e.printOnDebug() } catch (e: IllegalAccessException) { - Timber.e(e) + 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 a8a6e789b..6cb9b6b45 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 @@ -20,7 +20,7 @@ import kotlinx.coroutines.Dispatchers.Main import kotlinx.coroutines.delay import kotlinx.coroutines.withContext import splitties.init.appCtx -import timber.log.Timber + import java.io.File @@ -53,7 +53,7 @@ object Restore : BackupRestore() { } } } catch (e: Exception) { - Timber.e(e) + e.printOnDebug() } } } @@ -129,7 +129,7 @@ object Restore : BackupRestore() { ThemeConfig.upConfig() } } catch (e: Exception) { - Timber.e(e) + e.printOnDebug() } if (!ignoreReadConfig) { //恢复阅读界面配置 @@ -142,7 +142,7 @@ object Restore : BackupRestore() { ReadBookConfig.initConfigs() } } catch (e: Exception) { - Timber.e(e) + e.printOnDebug() } try { val file = @@ -153,7 +153,7 @@ object Restore : BackupRestore() { ReadBookConfig.initShareConfig() } } catch (e: Exception) { - Timber.e(e) + e.printOnDebug() } } Preferences.getSharedPreferences(appCtx, path, "config")?.all?.let { map -> @@ -195,7 +195,7 @@ object Restore : BackupRestore() { val json = file.readText() return GSON.fromJsonArray(json) } catch (e: Exception) { - Timber.e(e) + 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 5ad61c645..4b565d345 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,13 +3,14 @@ package io.legado.app.lib.webdav import io.legado.app.help.http.newCallResponseBody import io.legado.app.help.http.okHttpClient import io.legado.app.help.http.text +import io.legado.app.utils.printOnDebug import okhttp3.Credentials import okhttp3.MediaType.Companion.toMediaType import okhttp3.RequestBody.Companion.asRequestBody import okhttp3.RequestBody.Companion.toRequestBody import org.intellij.lang.annotations.Language import org.jsoup.Jsoup -import timber.log.Timber + import java.io.File import java.io.InputStream import java.net.MalformedURLException @@ -100,7 +101,7 @@ class WebDav(urlStr: String) { method("PROPFIND", requestBody) }.text() }.onFailure { e -> - Timber.e(e) + e.printOnDebug() }.getOrNull() } return null @@ -132,7 +133,7 @@ class WebDav(urlStr: String) { } list.add(webDavFile) } catch (e: MalformedURLException) { - Timber.e(e) + 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 fbbc58a81..1e5ab1894 100644 --- a/app/src/main/java/io/legado/app/model/CacheBook.kt +++ b/app/src/main/java/io/legado/app/model/CacheBook.kt @@ -16,7 +16,7 @@ import io.legado.app.utils.postEvent import io.legado.app.utils.startService import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.delay -import timber.log.Timber + import java.util.concurrent.ConcurrentHashMap import kotlin.coroutines.CoroutineContext @@ -180,7 +180,6 @@ object CacheBook { "下载${book.name}-${chapterTitle}失败\n${error.localizedMessage}", error ) - Timber.e(error) } } 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 2826c6589..cfe5a816c 100644 --- a/app/src/main/java/io/legado/app/model/ReadBook.kt +++ b/app/src/main/java/io/legado/app/model/ReadBook.kt @@ -23,7 +23,7 @@ import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.MainScope import kotlinx.coroutines.delay import splitties.init.appCtx -import timber.log.Timber + @Suppress("MemberVisibilityCanBePrivate") @@ -378,7 +378,7 @@ object ReadBook : CoroutineScope by MainScope() { } } }.onError { - Timber.e(it) + AppLog.put("ChapterProvider ERROR", it) 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 4c0d79d36..b5b672e5b 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,7 +3,8 @@ package io.legado.app.model.analyzeRule import androidx.annotation.Keep import com.jayway.jsonpath.JsonPath import com.jayway.jsonpath.ReadContext -import timber.log.Timber +import io.legado.app.utils.printOnDebug + @Suppress("RegExpRedundantEscape") @Keep @@ -48,7 +49,7 @@ class AnalyzeByJSonPath(json: Any) { ob.toString() } } catch (e: Exception) { - Timber.e(e) + e.printOnDebug() } } return result @@ -85,7 +86,7 @@ class AnalyzeByJSonPath(json: Any) { result.add(obj.toString()) } } catch (e: Exception) { - Timber.e(e) + e.printOnDebug() } } else { result.add(st) @@ -135,7 +136,7 @@ class AnalyzeByJSonPath(json: Any) { try { return it.read>(rules[0]) } catch (e: Exception) { - Timber.e(e) + e.printOnDebug() } } } else { 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 9922cf0d6..5d654fb70 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 @@ -13,7 +13,7 @@ import io.legado.app.utils.* import kotlinx.coroutines.runBlocking import org.jsoup.nodes.Entities import org.mozilla.javascript.NativeObject -import timber.log.Timber + import java.net.URL import java.util.regex.Pattern import javax.script.SimpleBindings @@ -662,7 +662,7 @@ class AnalyzeRule( analyzeUrl.getStrResponseAwait().body }.onFailure { log("ajax(${urlStr}) error\n${it.stackTraceToString()}") - Timber.e(it) + 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 a9cd1de54..07b0aa0c6 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 @@ -5,10 +5,7 @@ import android.graphics.BitmapFactory import android.text.TextUtils 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.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.domain.Resource import me.ag2s.epublib.domain.TOCReference @@ -17,7 +14,7 @@ import org.jsoup.Jsoup import org.jsoup.nodes.Element import org.jsoup.select.Elements import splitties.init.appCtx -import timber.log.Timber + import java.io.File import java.io.FileOutputStream import java.io.IOException @@ -97,7 +94,7 @@ class EpubFile(var book: Book) { } } } catch (e: Exception) { - Timber.e(e) + e.printOnDebug() } } @@ -108,7 +105,7 @@ class EpubFile(var book: Book) { //通过懒加载读取epub return EpubReader().readEpub(bis, "utf-8") } catch (e: Exception) { - Timber.e(e) + e.printOnDebug() } return null } diff --git a/app/src/main/java/io/legado/app/model/localBook/LocalBook.kt b/app/src/main/java/io/legado/app/model/localBook/LocalBook.kt index 65bec08f5..66bef1143 100644 --- a/app/src/main/java/io/legado/app/model/localBook/LocalBook.kt +++ b/app/src/main/java/io/legado/app/model/localBook/LocalBook.kt @@ -12,7 +12,7 @@ import io.legado.app.help.BookHelp import io.legado.app.model.TocEmptyException import io.legado.app.utils.* import splitties.init.appCtx -import timber.log.Timber + import java.io.File import java.io.FileInputStream import java.io.FileNotFoundException @@ -69,7 +69,7 @@ object LocalBook { } } } catch (e: Exception) { - Timber.e(e) + e.printOnDebug() e.localizedMessage } } 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 c7304e552..811e65d71 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 @@ -2,13 +2,11 @@ package io.legado.app.model.localBook 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.* import me.ag2s.umdlib.domain.UmdBook import me.ag2s.umdlib.umd.UmdReader import splitties.init.appCtx -import timber.log.Timber + import java.io.File import java.io.InputStream @@ -77,7 +75,7 @@ class UmdFile(var book: Book) { } } } catch (e: Exception) { - Timber.e(e) + e.printOnDebug() } } @@ -111,7 +109,7 @@ class UmdFile(var book: Book) { chapter.index = index chapter.bookUrl = book.bookUrl chapter.url = index.toString() - Timber.d(chapter.url) + DebugLog.d(javaClass.name, chapter.url) chapterList.add(chapter) } book.latestChapterTitle = chapterList.lastOrNull()?.title diff --git a/app/src/main/java/io/legado/app/model/webBook/BookInfo.kt b/app/src/main/java/io/legado/app/model/webBook/BookInfo.kt index 153c8e3e7..4ce0ae765 100644 --- a/app/src/main/java/io/legado/app/model/webBook/BookInfo.kt +++ b/app/src/main/java/io/legado/app/model/webBook/BookInfo.kt @@ -7,13 +7,14 @@ import io.legado.app.help.BookHelp import io.legado.app.model.Debug import io.legado.app.model.NoStackTraceException import io.legado.app.model.analyzeRule.AnalyzeRule +import io.legado.app.utils.DebugLog import io.legado.app.utils.HtmlFormatter import io.legado.app.utils.NetworkUtils import io.legado.app.utils.StringUtils.wordCountFormat import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.ensureActive import splitties.init.appCtx -import timber.log.Timber + /** * 获取详情 @@ -87,7 +88,7 @@ object BookInfo { } ?: Debug.log(bookSource.bookSourceUrl, "└") } catch (e: Exception) { Debug.log(bookSource.bookSourceUrl, "└${e.localizedMessage}") - Timber.e(e, "获取分类出错") + DebugLog.e("获取分类出错", e) } scope.ensureActive() Debug.log(bookSource.bookSourceUrl, "┌获取字数") @@ -98,7 +99,7 @@ object BookInfo { } } catch (e: Exception) { Debug.log(bookSource.bookSourceUrl, "└${e.localizedMessage}") - Timber.e(e, "获取字数出错") + DebugLog.e("获取字数出错", e) } scope.ensureActive() Debug.log(bookSource.bookSourceUrl, "┌获取最新章节") @@ -109,7 +110,7 @@ object BookInfo { } } catch (e: Exception) { Debug.log(bookSource.bookSourceUrl, "└${e.localizedMessage}") - Timber.e(e, "获取最新章节出错") + DebugLog.e("获取最新章节出错", e) } scope.ensureActive() Debug.log(bookSource.bookSourceUrl, "┌获取简介") @@ -120,7 +121,7 @@ object BookInfo { } } catch (e: Exception) { Debug.log(bookSource.bookSourceUrl, "└${e.localizedMessage}") - Timber.e(e, "获取简介出错") + DebugLog.e("获取简介出错", e) } scope.ensureActive() Debug.log(bookSource.bookSourceUrl, "┌获取封面链接") @@ -131,7 +132,7 @@ object BookInfo { } } catch (e: Exception) { Debug.log(bookSource.bookSourceUrl, "└${e.localizedMessage}") - Timber.e(e, "获取封面出错") + DebugLog.e("获取封面出错", e) } scope.ensureActive() Debug.log(bookSource.bookSourceUrl, "┌获取目录链接") 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 7bfdc0727..75ece6ed3 100644 --- a/app/src/main/java/io/legado/app/service/AudioPlayService.kt +++ b/app/src/main/java/io/legado/app/service/AudioPlayService.kt @@ -33,7 +33,7 @@ import io.legado.app.utils.* import kotlinx.coroutines.* import kotlinx.coroutines.Dispatchers.Main import splitties.systemservices.audioManager -import timber.log.Timber + class AudioPlayService : BaseService(), @@ -138,7 +138,7 @@ class AudioPlayService : BaseService(), exoPlayer.playWhenReady = true exoPlayer.prepare() }.onFailure { - Timber.e(it) + it.printOnDebug() toastOnUi("$url ${it.localizedMessage}") stopSelf() } @@ -159,7 +159,7 @@ class AudioPlayService : BaseService(), postEvent(EventBus.AUDIO_STATE, Status.PAUSE) upNotification() } catch (e: Exception) { - Timber.e(e) + e.printOnDebug() } } @@ -178,7 +178,7 @@ class AudioPlayService : BaseService(), postEvent(EventBus.AUDIO_STATE, Status.PLAY) upNotification() } catch (e: Exception) { - Timber.e(e) + e.printOnDebug() stopSelf() } } @@ -250,7 +250,6 @@ class AudioPlayService : BaseService(), val errorMsg = "音频播放出错\n${error.errorCodeName} ${error.errorCode}" AppLog.put(errorMsg, error) toastOnUi(errorMsg) - Timber.e(error) } private fun setTimer(minute: Int) { 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 3ee4f7dc7..4d3d84648 100644 --- a/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt +++ b/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt @@ -19,7 +19,7 @@ import kotlinx.coroutines.sync.Mutex import kotlinx.coroutines.sync.withLock import okhttp3.Response import org.mozilla.javascript.WrappedException -import timber.log.Timber + import java.io.File import java.io.FileDescriptor import java.io.FileInputStream @@ -177,7 +177,7 @@ class HttpReadAloudService : BaseReadAloudService(), is ScriptException, is WrappedException -> { AppLog.put("js错误\n${it.localizedMessage}", it) toastOnUi("js错误\n${it.localizedMessage}") - Timber.e(it) + it.printOnDebug() cancel() pauseReadAloud(true) } @@ -198,7 +198,7 @@ class HttpReadAloudService : BaseReadAloudService(), downloadErrorNo++ val msg = "tts下载错误\n${it.localizedMessage}" AppLog.put(msg, it) - Timber.e(it) + it.printOnDebug() if (downloadErrorNo > 5) { pauseReadAloud(true) } else { @@ -222,7 +222,7 @@ class HttpReadAloudService : BaseReadAloudService(), playingIndex = nowSpeak postEvent(EventBus.TTS_PROGRESS, readAloudNumber + 1) } catch (e: Exception) { - Timber.e(e) + 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 fea7ca733..11c391b6c 100644 --- a/app/src/main/java/io/legado/app/service/WebService.kt +++ b/app/src/main/java/io/legado/app/service/WebService.kt @@ -13,7 +13,7 @@ import io.legado.app.constant.PreferKey import io.legado.app.utils.* import io.legado.app.web.HttpServer import io.legado.app.web.WebSocketServer -import timber.log.Timber + import java.io.IOException class WebService : BaseService() { @@ -88,7 +88,7 @@ class WebService : BaseService() { upNotification() } catch (e: IOException) { toastOnUi(e.localizedMessage ?: "") - Timber.e(e) + 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 83bb09cff..8b6560c68 100644 --- a/app/src/main/java/io/legado/app/service/WebTileService.kt +++ b/app/src/main/java/io/legado/app/service/WebTileService.kt @@ -6,7 +6,7 @@ import android.service.quicksettings.Tile import android.service.quicksettings.TileService import androidx.annotation.RequiresApi import io.legado.app.constant.IntentAction -import timber.log.Timber +import io.legado.app.utils.printOnDebug /** @@ -28,7 +28,7 @@ class WebTileService : TileService() { } } } catch (e: Exception) { - Timber.e(e) + e.printOnDebug() } return super.onStartCommand(intent, flags, startId) } 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 4d9f934b6..5bea6b2d9 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,11 +7,8 @@ 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 timber.log.Timber +import io.legado.app.utils.* + class DonateFragment : PreferenceFragmentCompat() { @@ -50,7 +47,7 @@ class DonateFragment : PreferenceFragmentCompat() { intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) context.startActivity(intent) } catch (e: Exception) { - Timber.e(e) + e.printOnDebug() } finally { ACache.get(requireContext(), cacheDir = false) .put("proTime", System.currentTimeMillis()) diff --git a/app/src/main/java/io/legado/app/ui/association/FileAssociationActivity.kt b/app/src/main/java/io/legado/app/ui/association/FileAssociationActivity.kt index 133cce8a3..13b880ac5 100644 --- a/app/src/main/java/io/legado/app/ui/association/FileAssociationActivity.kt +++ b/app/src/main/java/io/legado/app/ui/association/FileAssociationActivity.kt @@ -6,6 +6,7 @@ import androidx.activity.viewModels import androidx.documentfile.provider.DocumentFile import io.legado.app.R import io.legado.app.base.VMBaseActivity +import io.legado.app.constant.AppLog import io.legado.app.databinding.ActivityTranslucenceBinding import io.legado.app.help.AppConfig import io.legado.app.lib.dialogs.alert @@ -18,7 +19,7 @@ import io.legado.app.utils.viewbindingdelegate.viewBinding import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.launch import kotlinx.coroutines.withContext -import timber.log.Timber + import java.io.File import java.io.FileOutputStream @@ -145,7 +146,7 @@ class FileAssociationActivity : mode = HandleFileContract.DIR_SYS } else -> { - Timber.e(it, "导入书籍失败") + AppLog.put("导入书籍失败", it) toastOnUi(it.localizedMessage) finish() } 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 04d73f717..a0d401e82 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,8 +7,9 @@ import androidx.lifecycle.MutableLiveData import io.legado.app.model.NoStackTraceException 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 timber.log.Timber + import java.io.File class FileAssociationViewModel(application: Application) : BaseAssociationViewModel(application) { @@ -54,7 +55,7 @@ class FileAssociationViewModel(application: Application) : BaseAssociationViewMo onLineImportLive.postValue(uri) } }.onError { - Timber.e(it) + 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 e11eae675..d5ddcf74a 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 @@ -16,7 +16,7 @@ import io.legado.app.help.http.okHttpClient import io.legado.app.help.http.text import io.legado.app.model.NoStackTraceException import io.legado.app.utils.* -import timber.log.Timber + class ImportBookSourceViewModel(app: Application) : BaseViewModel(app) { var isAddGroup = false @@ -113,7 +113,7 @@ class ImportBookSourceViewModel(app: Application) : BaseViewModel(app) { else -> throw NoStackTraceException(context.getString(R.string.wrong_format)) } }.onError { - Timber.e(it) + it.printOnDebug() errorLiveData.postValue(it.localizedMessage ?: "") }.onSuccess { comparisonSource() 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 e21157ade..acd620578 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 @@ -28,7 +28,7 @@ import me.ag2s.epublib.domain.* import me.ag2s.epublib.epub.EpubWriter import me.ag2s.epublib.util.ResourceUtil import splitties.init.appCtx -import timber.log.Timber + import java.io.ByteArrayOutputStream import java.io.File import java.io.FileOutputStream @@ -71,7 +71,7 @@ class CacheViewModel(application: Application) : BaseViewModel(application) { exportProgress.remove(book.bookUrl) exportMsg[book.bookUrl] = it.localizedMessage ?: "ERROR" upAdapterLiveData.postValue(book.bookUrl) - Timber.e(it) + it.printOnDebug() }.onSuccess { exportProgress.remove(book.bookUrl) exportMsg[book.bookUrl] = context.getString(R.string.export_success) @@ -206,7 +206,7 @@ class CacheViewModel(application: Application) : BaseViewModel(application) { exportProgress.remove(book.bookUrl) exportMsg[book.bookUrl] = it.localizedMessage ?: "ERROR" upAdapterLiveData.postValue(book.bookUrl) - Timber.e(it) + it.printOnDebug() }.onSuccess { exportProgress.remove(book.bookUrl) exportMsg[book.bookUrl] = context.getString(R.string.export_success) diff --git a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeBookSourceViewModel.kt b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeBookSourceViewModel.kt index 93ecf8eb5..c635cf16e 100644 --- a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeBookSourceViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeBookSourceViewModel.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.Dispatchers.IO import kotlinx.coroutines.ExecutorCoroutineDispatcher import kotlinx.coroutines.asCoroutineDispatcher @@ -25,7 +26,7 @@ import kotlinx.coroutines.flow.callbackFlow import kotlinx.coroutines.flow.flowOn import kotlinx.coroutines.flow.map import splitties.init.appCtx -import timber.log.Timber + import java.util.* import java.util.concurrent.Executors import kotlin.math.min @@ -194,7 +195,7 @@ class ChangeBookSourceViewModel(application: Application) : BaseViewModel(applic searchCallback?.searchSuccess(searchBook) } }.onError(IO) { - Timber.e(it) + it.printOnDebug() } } @@ -205,7 +206,7 @@ class ChangeBookSourceViewModel(application: Application) : BaseViewModel(applic val searchBook: SearchBook = book.toSearchBook() searchCallback?.searchSuccess(searchBook) }.onError(IO) { - Timber.e(it) + it.printOnDebug() } } diff --git a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeChapterSourceViewModel.kt b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeChapterSourceViewModel.kt index 9654336c0..8a9031184 100644 --- a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeChapterSourceViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeChapterSourceViewModel.kt @@ -19,6 +19,7 @@ import io.legado.app.model.NoStackTraceException 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.Dispatchers.IO import kotlinx.coroutines.ExecutorCoroutineDispatcher import kotlinx.coroutines.asCoroutineDispatcher @@ -27,7 +28,7 @@ import kotlinx.coroutines.flow.callbackFlow import kotlinx.coroutines.flow.flowOn import kotlinx.coroutines.flow.map import splitties.init.appCtx -import timber.log.Timber + import java.util.* import java.util.concurrent.ConcurrentHashMap import java.util.concurrent.Executors @@ -204,7 +205,7 @@ class ChangeChapterSourceViewModel(application: Application) : BaseViewModel(app searchCallback?.searchSuccess(searchBook) } }.onError(IO) { - Timber.e(it) + it.printOnDebug() } } @@ -216,7 +217,7 @@ class ChangeChapterSourceViewModel(application: Application) : BaseViewModel(app val searchBook: SearchBook = book.toSearchBook() searchCallback?.searchSuccess(searchBook) }.onError(IO) { - Timber.e(it) + 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 acfbf2fcf..1ae0e2c61 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,9 +10,10 @@ 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 -import timber.log.Timber + class ExploreShowViewModel(application: Application) : BaseViewModel(application) { @@ -44,7 +45,7 @@ class ExploreShowViewModel(application: Application) : BaseViewModel(application appDb.searchBookDao.insert(*searchBooks.toTypedArray()) page++ }.onError { - Timber.e(it) + 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 9a0ec9460..8361cc29a 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 @@ -24,7 +24,7 @@ import io.legado.app.databinding.ItemTextBinding import io.legado.app.databinding.PopupActionMenuBinding import io.legado.app.service.BaseReadAloudService import io.legado.app.utils.* -import timber.log.Timber + import java.util.* @SuppressLint("RestrictedApi") @@ -210,7 +210,7 @@ class TextActionMenu(private val context: Context, private val callBack: CallBac } context.startActivity(intent) }.onFailure { - Timber.e(it) + 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 b320d567f..f3cbd8976 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 @@ -33,7 +33,7 @@ import io.legado.app.ui.document.HandleFileContract import io.legado.app.ui.widget.seekbar.SeekBarChangeListener import io.legado.app.utils.* import io.legado.app.utils.viewbindingdelegate.viewBinding -import timber.log.Timber + import java.io.File class BgTextConfigDialog : BaseDialogFragment(R.layout.dialog_read_bg_text) { @@ -293,7 +293,7 @@ class BgTextConfigDialog : BaseDialogFragment(R.layout.dialog_read_bg_text) { }.onSuccess { toastOnUi("导出成功, 文件名为 $exportFileName") }.onError { - Timber.e(it) + it.printOnDebug() longToast("导出失败:${it.localizedMessage}") } } @@ -330,7 +330,7 @@ class BgTextConfigDialog : BaseDialogFragment(R.layout.dialog_read_bg_text) { @Suppress("BlockingMethodInNonBlockingContext") importConfig(uri.readBytes(requireContext())) }.onError { - Timber.e(it) + it.printOnDebug() longToast("导入失败:${it.localizedMessage}") } } @@ -344,7 +344,7 @@ class BgTextConfigDialog : BaseDialogFragment(R.layout.dialog_read_bg_text) { postEvent(EventBus.UP_CONFIG, true) toastOnUi("导入成功") }.onError { - Timber.e(it) + 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 02ed8b4a2..948714664 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 @@ -10,7 +10,7 @@ import io.legado.app.help.http.okHttpClient import io.legado.app.model.NoStackTraceException import io.legado.app.utils.* import kotlinx.coroutines.Dispatchers -import timber.log.Timber + class BookSourceEditViewModel(application: Application) : BaseViewModel(application) { @@ -48,7 +48,7 @@ class BookSourceEditViewModel(application: Application) : BaseViewModel(applicat success?.invoke() }.onError { context.toastOnUi(it.localizedMessage) - Timber.e(it) + it.printOnDebug() } } @@ -62,7 +62,7 @@ class BookSourceEditViewModel(application: Application) : BaseViewModel(applicat } }.onError { context.toastOnUi(it.localizedMessage ?: "Error") - Timber.e(it) + it.printOnDebug() } } diff --git a/app/src/main/java/io/legado/app/ui/browser/WebViewModel.kt b/app/src/main/java/io/legado/app/ui/browser/WebViewModel.kt index dd72acb5b..6c3536b8a 100644 --- a/app/src/main/java/io/legado/app/ui/browser/WebViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/browser/WebViewModel.kt @@ -14,7 +14,7 @@ import io.legado.app.help.http.okHttpClient import io.legado.app.model.NoStackTraceException import io.legado.app.model.analyzeRule.AnalyzeUrl import io.legado.app.utils.* -import timber.log.Timber + import java.io.File import java.util.* @@ -41,7 +41,7 @@ class WebViewModel(application: Application) : BaseViewModel(application) { success.invoke() }.onError { context.toastOnUi("error\n${it.localizedMessage}") - Timber.e(it) + 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 b82bedd2a..26783c826 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 @@ -7,12 +7,8 @@ import androidx.lifecycle.MutableLiveData import io.legado.app.base.BaseViewModel import io.legado.app.constant.AppLog import io.legado.app.help.DirectLinkUpload -import io.legado.app.utils.FileUtils -import io.legado.app.utils.GSON -import io.legado.app.utils.isContentScheme +import io.legado.app.utils.* -import io.legado.app.utils.writeBytes -import timber.log.Timber import java.io.File class HandleFileViewModel(application: Application) : BaseViewModel(application) { @@ -31,7 +27,7 @@ class HandleFileViewModel(application: Application) : BaseViewModel(application) success.invoke(it) }.onError { AppLog.put("上传文件失败\n${it.localizedMessage}", it) - Timber.e(it) + it.printOnDebug() errorLiveData.postValue(it.localizedMessage) } } @@ -57,7 +53,7 @@ class HandleFileViewModel(application: Application) : BaseViewModel(application) Uri.fromFile(newFile) } }.onError { - Timber.e(it) + it.printOnDebug() errorLiveData.postValue(it.localizedMessage) }.onSuccess { success.invoke(it) diff --git a/app/src/main/java/io/legado/app/ui/font/FontAdapter.kt b/app/src/main/java/io/legado/app/ui/font/FontAdapter.kt index 31bc06f1f..b41249019 100644 --- a/app/src/main/java/io/legado/app/ui/font/FontAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/font/FontAdapter.kt @@ -8,7 +8,7 @@ import io.legado.app.base.adapter.ItemViewHolder import io.legado.app.base.adapter.RecyclerAdapter import io.legado.app.databinding.ItemFontBinding import io.legado.app.utils.* -import timber.log.Timber + import java.io.File import java.net.URLDecoder @@ -45,7 +45,7 @@ class FontAdapter(context: Context, curFilePath: String, val callBack: CallBack) } tvFont.typeface = typeface }.onFailure { - Timber.e(it) + 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/login/SourceLoginDialog.kt b/app/src/main/java/io/legado/app/ui/login/SourceLoginDialog.kt index 556599ae7..ef1ccab10 100644 --- a/app/src/main/java/io/legado/app/ui/login/SourceLoginDialog.kt +++ b/app/src/main/java/io/legado/app/ui/login/SourceLoginDialog.kt @@ -24,7 +24,7 @@ import kotlinx.coroutines.Dispatchers.Main import kotlinx.coroutines.launch import kotlinx.coroutines.withContext import splitties.views.onClick -import timber.log.Timber + class SourceLoginDialog : BaseDialogFragment(R.layout.dialog_login) { @@ -124,7 +124,7 @@ class SourceLoginDialog : BaseDialogFragment(R.layout.dialog_login) { } catch (e: Exception) { AppLog.put("登录出错\n${e.localizedMessage}", e) context?.toastOnUi("登录出错\n${e.localizedMessage}") - Timber.e(e) + e.printOnDebug() } } } 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 07ffce86d..c2c0c5f0d 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 @@ -18,7 +18,7 @@ import io.legado.app.model.webBook.WebBook import io.legado.app.service.CacheBookService import io.legado.app.utils.postEvent import kotlinx.coroutines.* -import timber.log.Timber + import java.util.concurrent.CopyOnWriteArraySet import java.util.concurrent.Executors import kotlin.math.min @@ -126,7 +126,6 @@ class MainViewModel(application: Application) : BaseViewModel(application) { addDownload(source, book) }.onError(upTocPool) { AppLog.put("${book.name} 更新目录失败\n${it.localizedMessage}", it) - Timber.e(it, "${book.name} 更新目录失败") }.onCancel(upTocPool) { upTocCancel(book.bookUrl) }.onFinally(upTocPool) { 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 808d37881..f7940f20c 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 @@ -5,15 +5,17 @@ import android.os.Bundle import androidx.lifecycle.MutableLiveData import androidx.lifecycle.viewModelScope import io.legado.app.base.BaseViewModel +import io.legado.app.constant.AppLog 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 -import timber.log.Timber + class RssArticlesViewModel(application: Application) : BaseViewModel(application) { val loadFinally = MutableLiveData() @@ -54,7 +56,7 @@ class RssArticlesViewModel(application: Application) : BaseViewModel(application } }.onError { loadFinally.postValue(false) - Timber.e(it) + AppLog.put("rss获取内容失败", it) context.toastOnUi(it.localizedMessage) } } @@ -70,7 +72,7 @@ class RssArticlesViewModel(application: Application) : BaseViewModel(application loadMoreSuccess(it.first) } .onError { - Timber.e(it) + 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 3f4ebfe95..62d2e3fcc 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 @@ -7,10 +7,11 @@ import io.legado.app.data.appDb import io.legado.app.data.entities.RssSource import io.legado.app.utils.getClipText import io.legado.app.utils.msg +import io.legado.app.utils.printOnDebug import io.legado.app.utils.toastOnUi import kotlinx.coroutines.Dispatchers -import timber.log.Timber + class RssSourceEditViewModel(application: Application) : BaseViewModel(application) { @@ -42,7 +43,7 @@ class RssSourceEditViewModel(application: Application) : BaseViewModel(applicati success() }.onError { context.toastOnUi(it.localizedMessage) - Timber.e(it) + 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 f2c289ef3..ae0e288ab 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,7 +15,7 @@ import android.view.Gravity import android.widget.TextView import androidx.appcompat.widget.SearchView import io.legado.app.R -import timber.log.Timber +import io.legado.app.utils.printOnDebug class SearchView @JvmOverloads constructor( @@ -44,7 +44,7 @@ class SearchView @JvmOverloads constructor( textView!!.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14f) textView!!.gravity = Gravity.CENTER_VERTICAL } catch (e: Exception) { - Timber.e(e) + e.printOnDebug() } } diff --git a/app/src/main/java/io/legado/app/ui/widget/anima/explosion_field/ExplosionView.kt b/app/src/main/java/io/legado/app/ui/widget/anima/explosion_field/ExplosionView.kt index 606e81b6c..1d7619d07 100644 --- a/app/src/main/java/io/legado/app/ui/widget/anima/explosion_field/ExplosionView.kt +++ b/app/src/main/java/io/legado/app/ui/widget/anima/explosion_field/ExplosionView.kt @@ -25,7 +25,8 @@ import android.graphics.Rect import android.media.MediaPlayer import android.util.AttributeSet import android.view.View -import timber.log.Timber +import io.legado.app.utils.DebugLog + import java.util.* @@ -125,11 +126,11 @@ class ExplosionView @JvmOverloads constructor(context: Context, attrs: Attribute } override fun onAnimationCancel(animator: Animator) { - Timber.i("CANCEL") + DebugLog.i(javaClass.name, "CANCEL") } override fun onAnimationRepeat(animator: Animator) { - Timber.i("REPEAT") + DebugLog.i(javaClass.name, "REPEAT") } }) 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 d04de80f0..0c2446e05 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,7 +22,8 @@ import android.graphics.Canvas import android.graphics.drawable.BitmapDrawable import android.view.View import android.widget.ImageView -import timber.log.Timber +import io.legado.app.utils.printOnDebug + import kotlin.math.roundToInt @@ -67,7 +68,7 @@ object Utils { try { return Bitmap.createBitmap(width, height, config) } catch (e: OutOfMemoryError) { - Timber.e(e) + 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/image/CircleImageView.kt b/app/src/main/java/io/legado/app/ui/widget/image/CircleImageView.kt index 47893d6c6..5f5c0a016 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,9 +20,10 @@ 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 timber.log.Timber + import kotlin.math.min import kotlin.math.pow @@ -151,10 +152,6 @@ class CircleImageView @JvmOverloads constructor( mReady = true - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - outlineProvider = OutlineProvider() - } - if (mSetupPending) { setup() mSetupPending = false @@ -318,7 +315,7 @@ class CircleImageView @JvmOverloads constructor( drawable.draw(canvas) bitmap } catch (e: Exception) { - Timber.e(e) + e.printOnDebug() null } diff --git a/app/src/main/java/io/legado/app/ui/widget/recycler/DividerNoLast.kt b/app/src/main/java/io/legado/app/ui/widget/recycler/DividerNoLast.kt index c1db3b6fc..9ac09b0cf 100644 --- a/app/src/main/java/io/legado/app/ui/widget/recycler/DividerNoLast.kt +++ b/app/src/main/java/io/legado/app/ui/widget/recycler/DividerNoLast.kt @@ -7,7 +7,8 @@ import android.graphics.drawable.Drawable import android.view.View import android.widget.LinearLayout import androidx.recyclerview.widget.RecyclerView -import timber.log.Timber +import io.legado.app.utils.DebugLog + import kotlin.math.roundToInt @@ -38,7 +39,10 @@ class DividerNoLast(context: Context, orientation: Int) : val a = context.obtainStyledAttributes(attrs) mDivider = a.getDrawable(0) if (mDivider == null) { - Timber.w("@android:attr/listDivider was not set in the theme used for this DividerItemDecoration. Please set that attribute all call setDrawable()") + DebugLog.w( + javaClass.name, + "@android:attr/listDivider was not set in the theme used for this DividerItemDecoration. Please set that attribute all call setDrawable()" + ) } a.recycle() setOrientation(orientation) diff --git a/app/src/main/java/io/legado/app/ui/widget/recycler/DragSelectTouchHelper.kt b/app/src/main/java/io/legado/app/ui/widget/recycler/DragSelectTouchHelper.kt index 129e0c9eb..0443be001 100644 --- a/app/src/main/java/io/legado/app/ui/widget/recycler/DragSelectTouchHelper.kt +++ b/app/src/main/java/io/legado/app/ui/widget/recycler/DragSelectTouchHelper.kt @@ -27,7 +27,8 @@ import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView.OnItemTouchListener import io.legado.app.BuildConfig import io.legado.app.ui.widget.recycler.DragSelectTouchHelper.AdvanceCallback.Mode -import timber.log.Timber +import io.legado.app.utils.DebugLog + import java.util.* import kotlin.math.max import kotlin.math.min @@ -971,15 +972,15 @@ class DragSelectTouchHelper( private object Logger { private val DEBUG = BuildConfig.DEBUG fun d(msg: String) { - Timber.d(msg) + DebugLog.d(javaClass.name, msg) } fun e(msg: String) { - Timber.e(msg) + DebugLog.e(javaClass.name, msg) } fun i(msg: String) { - Timber.i(msg) + DebugLog.i(javaClass.name, msg) } fun logSelectStateChange(before: Int, after: Int) { 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 b900095c3..be3e606df 100644 --- a/app/src/main/java/io/legado/app/utils/ACache.kt +++ b/app/src/main/java/io/legado/app/utils/ACache.kt @@ -11,7 +11,7 @@ import android.graphics.drawable.Drawable import org.json.JSONArray import org.json.JSONObject import splitties.init.appCtx -import timber.log.Timber + import java.io.* import java.util.* import java.util.concurrent.atomic.AtomicInteger @@ -70,11 +70,11 @@ class ACache private constructor(cacheDir: File, max_size: Long, max_count: Int) init { try { if (!cacheDir.exists() && !cacheDir.mkdirs()) { - Timber.i("can't make dirs in %s" + cacheDir.absolutePath) + DebugLog.i(javaClass.name, "can't make dirs in %s" + cacheDir.absolutePath) } mCache = ACacheManager(cacheDir, max_size, max_count) } catch (e: Exception) { - Timber.e(e) + 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) { - Timber.e(e) + e.printOnDebug() } } } @@ -131,7 +131,7 @@ class ACache private constructor(cacheDir: File, max_size: Long, max_count: Int) removeFile = true } } catch (e: IOException) { - Timber.e(e) + 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) { - Timber.e(e) + 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) { - Timber.e(e) + 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) { - Timber.e(e) + e.printOnDebug() } finally { try { bis?.close() } catch (e: IOException) { - Timber.e(e) + e.printOnDebug() } try { ois?.close() } catch (e: IOException) { - Timber.e(e) + e.printOnDebug() } } @@ -427,7 +427,7 @@ class ACache private constructor(cacheDir: File, max_size: Long, max_count: Int) return f } } catch (e: Exception) { - Timber.e(e) + e.printOnDebug() } } return null @@ -488,7 +488,7 @@ class ACache private constructor(cacheDir: File, max_size: Long, max_count: Int) } } } catch (e: Exception) { - Timber.e(e) + 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) { - Timber.e(e) + 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) { - Timber.e(e) + e.printOnDebug() } } @@ -727,7 +727,7 @@ class ACache private constructor(cacheDir: File, max_size: Long, max_count: Int) } } } catch (e: Exception) { - Timber.e(e) + e.printOnDebug() } } @@ -767,7 +767,7 @@ class ACache private constructor(cacheDir: File, max_size: Long, max_count: Int) } return fileSize } catch (e: Exception) { - Timber.e(e) + 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 f3cbc39a6..b32ea7bf1 100644 --- a/app/src/main/java/io/legado/app/utils/ContextExtensions.kt +++ b/app/src/main/java/io/legado/app/utils/ContextExtensions.kt @@ -29,7 +29,7 @@ import io.legado.app.R import io.legado.app.constant.AppConst import io.legado.app.help.IntentHelp import splitties.systemservices.clipboardManager -import timber.log.Timber + import java.io.File import java.io.FileOutputStream @@ -178,7 +178,7 @@ val Context.sysScreenOffTime: Int return kotlin.runCatching { Settings.System.getInt(contentResolver, Settings.System.SCREEN_OFF_TIMEOUT) }.onFailure { - Timber.e(it) + it.printOnDebug() }.getOrDefault(0) } @@ -338,7 +338,7 @@ val Context.channel: String val appInfo = pm.getApplicationInfo(packageName, PackageManager.GET_META_DATA) return appInfo.metaData.getString("channel") ?: "" } catch (e: Exception) { - Timber.e(e) + e.printOnDebug() } return "" } diff --git a/app/src/main/java/io/legado/app/utils/DebugLog.kt b/app/src/main/java/io/legado/app/utils/DebugLog.kt new file mode 100644 index 000000000..07295b45f --- /dev/null +++ b/app/src/main/java/io/legado/app/utils/DebugLog.kt @@ -0,0 +1,54 @@ +package io.legado.app.utils + +import android.util.Log +import io.legado.app.BuildConfig + +object DebugLog { + + fun e(tag: String, throwable: Throwable) { + if (BuildConfig.DEBUG) { + Log.e(tag, throwable.stackTraceToString()) + } + } + + fun e(tag: String, msg: String, throwable: Throwable? = null) { + if (BuildConfig.DEBUG) { + if (throwable == null) { + Log.e(tag, msg) + } else { + Log.e(tag, msg, throwable) + } + } + } + + fun d(tag: String, msg: String, throwable: Throwable? = null) { + if (BuildConfig.DEBUG) { + if (throwable == null) { + Log.d(tag, msg) + } else { + Log.d(tag, msg, throwable) + } + } + } + + fun i(tag: String, msg: String, throwable: Throwable? = null) { + if (BuildConfig.DEBUG) { + if (throwable == null) { + Log.i(tag, msg) + } else { + Log.i(tag, msg, throwable) + } + } + } + + fun w(tag: String, msg: String, throwable: Throwable? = null) { + if (BuildConfig.DEBUG) { + if (throwable == null) { + Log.w(tag, msg) + } else { + Log.w(tag, msg, throwable) + } + } + } + +} \ No newline at end of file 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 8b9d04afe..e233fd247 100644 --- a/app/src/main/java/io/legado/app/utils/FileUtils.kt +++ b/app/src/main/java/io/legado/app/utils/FileUtils.kt @@ -4,7 +4,7 @@ import android.os.Environment import android.webkit.MimeTypeMap import androidx.annotation.IntDef import splitties.init.appCtx -import timber.log.Timber + import java.io.* import java.nio.charset.Charset import java.text.SimpleDateFormat @@ -46,7 +46,7 @@ object FileUtils { file.createNewFile() } } catch (e: IOException) { - Timber.e(e) + e.printOnDebug() } return file } @@ -117,7 +117,7 @@ object FileUtils { try { sdCardDirectory = File(sdCardDirectory).canonicalPath } catch (e: IOException) { - Timber.e(e) + e.printOnDebug() } return sdCardDirectory } diff --git a/app/src/main/java/io/legado/app/utils/GsonExtensions.kt b/app/src/main/java/io/legado/app/utils/GsonExtensions.kt index c5535c407..878362ba3 100644 --- a/app/src/main/java/io/legado/app/utils/GsonExtensions.kt +++ b/app/src/main/java/io/legado/app/utils/GsonExtensions.kt @@ -4,7 +4,7 @@ import com.google.gson.* import com.google.gson.internal.LinkedTreeMap import com.google.gson.reflect.TypeToken import com.google.gson.stream.JsonWriter -import timber.log.Timber + import java.io.OutputStream import java.io.OutputStreamWriter import java.lang.reflect.ParameterizedType @@ -27,18 +27,20 @@ val GSON: Gson by lazy { inline fun genericType(): Type = object : TypeToken() {}.type inline fun Gson.fromJsonObject(json: String?): T? {//可转成任意类型 + json ?: return null return kotlin.runCatching { fromJson(json, genericType()) as? T }.onFailure { - Timber.e(it, json) + DebugLog.e("GSON解析出错", json, it) }.getOrNull() } inline fun Gson.fromJsonArray(json: String?): List? { + json ?: return null return kotlin.runCatching { fromJson(json, ParameterizedTypeImpl(T::class.java)) as? List }.onFailure { - Timber.e(it, json) + DebugLog.e("GSON解析出错", json, it) }.getOrNull() } 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 dd55e1773..e05d567c4 100644 --- a/app/src/main/java/io/legado/app/utils/LogUtils.kt +++ b/app/src/main/java/io/legado/app/utils/LogUtils.kt @@ -3,6 +3,7 @@ package io.legado.app.utils import android.annotation.SuppressLint +import io.legado.app.BuildConfig import io.legado.app.help.AppConfig import splitties.init.appCtx import java.text.SimpleDateFormat @@ -73,3 +74,9 @@ object LogUtils { return sdf.format(date) } } + +fun Throwable.printOnDebug() { + if (BuildConfig.DEBUG) { + printStackTrace() + } +} 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 4c4c6959c..0c27d38b3 100644 --- a/app/src/main/java/io/legado/app/utils/MD5Utils.kt +++ b/app/src/main/java/io/legado/app/utils/MD5Utils.kt @@ -1,6 +1,6 @@ package io.legado.app.utils -import timber.log.Timber + import java.security.MessageDigest import java.security.NoSuchAlgorithmException @@ -26,7 +26,7 @@ object MD5Utils { } reStr = stringBuffer.toString() } catch (e: NoSuchAlgorithmException) { - Timber.e(e) + 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 f4fa7386b..82c7636be 100644 --- a/app/src/main/java/io/legado/app/utils/NetworkUtils.kt +++ b/app/src/main/java/io/legado/app/utils/NetworkUtils.kt @@ -3,9 +3,10 @@ package io.legado.app.utils import android.net.ConnectivityManager import android.net.NetworkCapabilities import android.os.Build +import io.legado.app.constant.AppLog import okhttp3.internal.publicsuffix.PublicSuffixDatabase import splitties.systemservices.connectivityManager -import timber.log.Timber + import java.net.InetAddress import java.net.NetworkInterface import java.net.SocketException @@ -117,7 +118,7 @@ object NetworkUtils { relativeUrl = parseUrl.toString() return relativeUrl } catch (e: Exception) { - Timber.e(e) + e.printOnDebug() } return relativeUrl } @@ -134,7 +135,7 @@ object NetworkUtils { relativeUrl = parseUrl.toString() return relativeUrl } catch (e: Exception) { - Timber.e("网址拼接出错\n${e.localizedMessage}", e) + AppLog.put("网址拼接出错\n${e.localizedMessage}", e) } return relativeUrl } @@ -179,7 +180,7 @@ object NetworkUtils { try { enumeration = NetworkInterface.getNetworkInterfaces() } catch (e: SocketException) { - Timber.e(e) + 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 c502c97b9..72121998c 100644 --- a/app/src/main/java/io/legado/app/utils/RealPathUtil.kt +++ b/app/src/main/java/io/legado/app/utils/RealPathUtil.kt @@ -9,7 +9,7 @@ import android.os.Build import android.os.Environment import android.provider.DocumentsContract import android.provider.MediaStore -import timber.log.Timber + import java.io.File import java.io.FileInputStream import java.io.FileOutputStream @@ -112,7 +112,7 @@ object RealPathUtil { return cursor.getString(index) } } catch (e: IllegalArgumentException) { - Timber.e(e) + e.printOnDebug() val file = File(context.cacheDir, "tmp") val filePath = file.absolutePath var input: FileInputStream? = null @@ -130,8 +130,8 @@ object RealPathUtil { output.write(bytes, 0, read) } return File(filePath).absolutePath - } catch (ignored: IOException) { - Timber.e(ignored) + } catch (e: IOException) { + e.printStackTrace() } 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 43440fa86..4ae38fe46 100644 --- a/app/src/main/java/io/legado/app/utils/StringUtils.kt +++ b/app/src/main/java/io/legado/app/utils/StringUtils.kt @@ -2,7 +2,7 @@ package io.legado.app.utils import android.annotation.SuppressLint import android.text.TextUtils.isEmpty -import timber.log.Timber + import java.text.DecimalFormat import java.text.SimpleDateFormat import java.util.* @@ -83,7 +83,7 @@ object StringUtils { } } }.onFailure { - Timber.e(it) + it.printOnDebug() } return "" } 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 70717fe3b..22540356d 100644 --- a/app/src/main/java/io/legado/app/utils/UriExtensions.kt +++ b/app/src/main/java/io/legado/app/utils/UriExtensions.kt @@ -9,7 +9,7 @@ import io.legado.app.R import io.legado.app.lib.permission.Permissions import io.legado.app.lib.permission.PermissionsCompat import io.legado.app.model.NoStackTraceException -import timber.log.Timber + import java.io.File fun Uri.isContentScheme() = this.scheme == "content" @@ -42,7 +42,7 @@ fun AppCompatActivity.readUri(uri: Uri?, success: (name: String, bytes: ByteArra .request() } } catch (e: Exception) { - Timber.e(e) + 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) { - Timber.e(e) + 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 21e0030ee..4afec7b3e 100644 --- a/app/src/main/java/io/legado/app/utils/ViewExtensions.kt +++ b/app/src/main/java/io/legado/app/utils/ViewExtensions.kt @@ -21,7 +21,7 @@ import androidx.viewpager.widget.ViewPager import io.legado.app.help.AppConfig import io.legado.app.lib.theme.TintHelper import splitties.systemservices.inputMethodManager -import timber.log.Timber + import java.lang.reflect.Field @@ -170,6 +170,6 @@ fun PopupMenu.show(x: Int, y: Int) { field.isAccessible = true (field.get(this) as MenuPopupHelper).show(x, y) }.onFailure { - Timber.e(it) + 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 e7127fe58..e77c52db7 100644 --- a/app/src/main/java/io/legado/app/utils/ZipUtils.kt +++ b/app/src/main/java/io/legado/app/utils/ZipUtils.kt @@ -2,7 +2,7 @@ package io.legado.app.utils import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.withContext -import timber.log.Timber + import java.io.* import java.util.zip.ZipEntry import java.util.zip.ZipFile @@ -241,7 +241,7 @@ object ZipUtils { val entry = entries.nextElement() as ZipEntry val entryName = entry.name if (entryName.contains("../")) { - Timber.e("entryName: $entryName is dangerous!") + DebugLog.e(javaClass.name, "entryName: $entryName is dangerous!") continue } if (!unzipChildFile(destDir, files, zip, entry, entryName)) return files @@ -251,7 +251,7 @@ object ZipUtils { val entry = entries.nextElement() as ZipEntry val entryName = entry.name if (entryName.contains("../")) { - Timber.e("entryName: $entryName is dangerous!") + DebugLog.e(javaClass.name, "entryName: $entryName is dangerous!") continue } if (entryName.contains(keyword!!)) { @@ -314,7 +314,7 @@ object ZipUtils { while (entries.hasMoreElements()) { val entryName = (entries.nextElement() as ZipEntry).name if (entryName.contains("../")) { - Timber.e("entryName: $entryName is dangerous!") + DebugLog.e(javaClass.name, "entryName: $entryName is dangerous!") paths.add(entryName) } else { paths.add(entryName) @@ -368,7 +368,7 @@ object ZipUtils { return try { file.createNewFile() } catch (e: IOException) { - Timber.e(e) + e.printOnDebug() false } } diff --git a/app/src/main/java/io/legado/app/web/socket/BookSourceDebugWebSocket.kt b/app/src/main/java/io/legado/app/web/socket/BookSourceDebugWebSocket.kt index 3420afdce..e7c97182a 100644 --- a/app/src/main/java/io/legado/app/web/socket/BookSourceDebugWebSocket.kt +++ b/app/src/main/java/io/legado/app/web/socket/BookSourceDebugWebSocket.kt @@ -6,14 +6,11 @@ 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 -import timber.log.Timber + import java.io.IOException @@ -90,7 +87,7 @@ class BookSourceDebugWebSocket(handshakeRequest: NanoHTTPD.IHTTPSession) : close(NanoWSD.WebSocketFrame.CloseCode.NormalClosure, "调试结束", false) } }.onFailure { - Timber.e(it) + it.printOnDebug() } } } diff --git a/app/src/main/java/io/legado/app/web/socket/RssSourceDebugWebSocket.kt b/app/src/main/java/io/legado/app/web/socket/RssSourceDebugWebSocket.kt index 29fb9486d..1cd21eab6 100644 --- a/app/src/main/java/io/legado/app/web/socket/RssSourceDebugWebSocket.kt +++ b/app/src/main/java/io/legado/app/web/socket/RssSourceDebugWebSocket.kt @@ -6,14 +6,11 @@ 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 -import timber.log.Timber + import java.io.IOException @@ -89,7 +86,7 @@ class RssSourceDebugWebSocket(handshakeRequest: NanoHTTPD.IHTTPSession) : close(NanoWSD.WebSocketFrame.CloseCode.NormalClosure, "调试结束", false) } }.onFailure { - Timber.e(it) + it.printOnDebug() } } } diff --git a/build.gradle b/build.gradle index 933a8c530..0f9c28214 100644 --- a/build.gradle +++ b/build.gradle @@ -17,6 +17,7 @@ buildscript { classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" classpath 'de.timfreiheit.resourceplaceholders:placeholders:0.4' classpath 'de.undercouch:gradle-download-task:4.1.2' + classpath 'com.google.gms:google-services:4.3.10' } }