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 56831f09e..5addf8c53 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 @@ -20,6 +20,7 @@ import io.legado.app.model.webBook.WebBook import io.legado.app.utils.* import kotlinx.coroutines.runBlocking import splitties.init.appCtx +import timber.log.Timber object BookController { @@ -209,7 +210,7 @@ object BookController { if (book.isUmd()) UmdFile.upBookInfo(book) appDb.bookDao.insert(book) } catch (e: Exception) { - e.printOnDebug() + Timber.e(e) return returnData.setErrorMsg( e.localizedMessage ?: appCtx.getString(R.string.unknown_error) ) 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 4be5c9ed5..2065799b1 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 @@ -7,7 +7,11 @@ import io.legado.app.help.AppConfig import io.legado.app.help.CacheManager import io.legado.app.help.JsExtensions import io.legado.app.help.http.CookieStore -import io.legado.app.utils.* +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 /** @@ -107,7 +111,7 @@ interface BaseSource : JsExtensions { ?: return null return String(decodeBytes) } catch (e: Exception) { - e.printOnDebug() + Timber.e(e) return null } } @@ -127,7 +131,7 @@ interface BaseSource : JsExtensions { CacheManager.put("userInfo_${getKey()}", encodeStr) true } catch (e: Exception) { - e.printOnDebug() + Timber.e(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 3af5891eb..b97e1ab54 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 @@ -9,6 +9,7 @@ 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) @@ -92,7 +93,7 @@ data class BookSource( } }.onFailure { kinds.add(ExploreKind("ERROR:${it.localizedMessage}", it.stackTraceToString())) - it.printOnDebug() + Timber.e(it) } } 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 ffd226137..f71d3bfde 100644 --- a/app/src/main/java/io/legado/app/help/BookHelp.kt +++ b/app/src/main/java/io/legado/app/help/BookHelp.kt @@ -14,6 +14,7 @@ import io.legado.app.utils.* 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 @@ -121,7 +122,7 @@ object BookHelp { ).writeBytes(it) } } catch (e: Exception) { - e.printOnDebug() + Timber.e(e) } finally { downloadImages.remove(src) } diff --git a/app/src/main/java/io/legado/app/help/CrashHandler.kt b/app/src/main/java/io/legado/app/help/CrashHandler.kt index 5d6ff64e7..892b8c831 100644 --- a/app/src/main/java/io/legado/app/help/CrashHandler.kt +++ b/app/src/main/java/io/legado/app/help/CrashHandler.kt @@ -3,7 +3,6 @@ package io.legado.app.help import android.annotation.SuppressLint import android.content.Context import android.os.Build -import android.util.Log import io.legado.app.constant.AppConst import io.legado.app.model.ReadAloud import io.legado.app.utils.FileUtils @@ -21,7 +20,6 @@ import java.util.concurrent.TimeUnit */ @Suppress("DEPRECATION") class CrashHandler(val context: Context) : Thread.UncaughtExceptionHandler { - private val tag = this.javaClass.simpleName /** * 系统默认UncaughtExceptionHandler @@ -59,9 +57,7 @@ class CrashHandler(val context: Context) : Thread.UncaughtExceptionHandler { private fun handleException(ex: Throwable?) { if (ex == null) return //收集设备参数信息 - collectDeviceInfo(context) - //添加自定义信息 - addCustomInfo() + collectDeviceInfo() //保存日志文件 saveCrashInfo2File(ex) context.longToastOnUi(ex.msg) @@ -70,7 +66,7 @@ class CrashHandler(val context: Context) : Thread.UncaughtExceptionHandler { /** * 收集设备参数信息 */ - private fun collectDeviceInfo(ctx: Context) { + private fun collectDeviceInfo() { kotlin.runCatching { //获取系统信息 paramsMap["MANUFACTURER"] = Build.MANUFACTURER @@ -83,13 +79,6 @@ class CrashHandler(val context: Context) : Thread.UncaughtExceptionHandler { } } - /** - * 添加自定义参数 - */ - private fun addCustomInfo() { - Log.i(tag, "addCustomInfo: 程序出错了...") - } - /** * 保存错误信息到文件中 */ 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 9d901c1c9..b7184f11a 100644 --- a/app/src/main/java/io/legado/app/help/JsExtensions.kt +++ b/app/src/main/java/io/legado/app/help/JsExtensions.kt @@ -19,6 +19,7 @@ import org.apache.commons.lang3.time.DateFormatUtils 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 @@ -49,7 +50,7 @@ interface JsExtensions { analyzeUrl.getStrResponseAwait().body }.onFailure { log("ajax(${urlStr}) error\n${it.stackTraceToString()}") - it.printOnDebug() + Timber.e(it) }.getOrElse { it.msg } @@ -85,7 +86,7 @@ interface JsExtensions { analyzeUrl.getStrResponseAwait() }.onFailure { log("connect(${urlStr}) error\n${it.stackTraceToString()}") - it.printOnDebug() + Timber.e(it) }.getOrElse { StrResponse(analyzeUrl.url, it.localizedMessage) } @@ -100,7 +101,7 @@ interface JsExtensions { analyzeUrl.getStrResponseAwait() }.onFailure { log("ajax($urlStr,$header) error\n${it.stackTraceToString()}") - it.printOnDebug() + Timber.e(it) }.getOrElse { StrResponse(analyzeUrl.url, it.localizedMessage) } @@ -510,8 +511,8 @@ interface JsExtensions { transformation, iv.encodeToByteArray() ) - } catch (e: java.lang.Exception) { - e.printOnDebug() + } catch (e: Exception) { + Timber.e(e) log(e.localizedMessage ?: "aesDecodeToByteArrayERROR") null } @@ -550,7 +551,7 @@ interface JsExtensions { iv.encodeToByteArray() ) } catch (e: Exception) { - e.printOnDebug() + Timber.e(e) log(e.localizedMessage ?: "aesDecodeToByteArrayERROR") null } @@ -588,7 +589,7 @@ interface JsExtensions { iv.encodeToByteArray() ) } catch (e: Exception) { - e.printOnDebug() + Timber.e(e) log(e.localizedMessage ?: "aesEncodeToByteArrayERROR") null } @@ -625,7 +626,7 @@ interface JsExtensions { iv.encodeToByteArray() ) } catch (e: Exception) { - e.printOnDebug() + Timber.e(e) 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 e0b48cae4..540806f2c 100644 --- a/app/src/main/java/io/legado/app/help/ReadBookConfig.kt +++ b/app/src/main/java/io/legado/app/help/ReadBookConfig.kt @@ -62,7 +62,7 @@ object ReadBookConfig { val json = configFile.readText() configs = GSON.fromJsonArray(json) } catch (e: Exception) { - e.printOnDebug() + Timber.e(e) } } (configs ?: DefaultData.readConfigs).let { @@ -79,7 +79,7 @@ object ReadBookConfig { val json = configFile.readText() c = GSON.fromJsonObject(json) } catch (e: Exception) { - e.printOnDebug() + Timber.e(e) } } shareConfig = c ?: configList.getOrNull(5) ?: Config() 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 8af8c28bc..f84159c01 100644 --- a/app/src/main/java/io/legado/app/help/SourceAnalyzer.kt +++ b/app/src/main/java/io/legado/app/help/SourceAnalyzer.kt @@ -7,6 +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") @@ -156,7 +157,7 @@ object SourceAnalyzer { } } } catch (e: Exception) { - e.printOnDebug() + Timber.e(e) } 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 2206f51b5..0de2d2077 100644 --- a/app/src/main/java/io/legado/app/help/ThemeConfig.kt +++ b/app/src/main/java/io/legado/app/help/ThemeConfig.kt @@ -14,6 +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 +109,7 @@ object ThemeConfig { val json = configFile.readText() return GSON.fromJsonArray(json) }.onFailure { - it.printOnDebug() + Timber.e(it) } } 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 d12a053b6..350907350 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,8 +1,8 @@ package io.legado.app.help.coroutine import io.legado.app.BuildConfig -import io.legado.app.utils.printOnDebug import kotlinx.coroutines.* +import timber.log.Timber import kotlin.coroutines.CoroutineContext @@ -144,7 +144,7 @@ class Coroutine( } } catch (e: Throwable) { if (BuildConfig.DEBUG) { - e.printOnDebug() + Timber.e(e) } 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 634595d96..ecbcc1f02 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,7 +1,8 @@ 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 @@ -126,9 +127,9 @@ object SSLHelper { sslParams.trustManager = manager return sslParams } catch (e: NoSuchAlgorithmException) { - e.printOnDebug() + Timber.e(e) } catch (e: KeyManagementException) { - e.printOnDebug() + Timber.e(e) } return null } @@ -142,7 +143,7 @@ object SSLHelper { kmf.init(clientKeyStore, password.toCharArray()) return kmf.keyManagers } catch (e: Exception) { - e.printOnDebug() + Timber.e(e) } return null } @@ -161,7 +162,7 @@ object SSLHelper { try { certStream.close() } catch (e: IOException) { - e.printOnDebug() + Timber.e(e) } } //我们创建一个默认类型的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 ff5ec0724..20900f456 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 @@ -9,7 +9,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 @@ -179,7 +179,7 @@ object CronetLoader : CronetEngine.Builder.LibraryLoader() { abiField.isAccessible = true cpuAbi = abiField.get(appInfo) as String? } catch (e: Exception) { - e.printOnDebug() + Timber.e(e) } if (TextUtils.isEmpty(cpuAbi)) { cpuAbi = Build.SUPPORTED_ABIS[0] @@ -230,7 +230,7 @@ object CronetLoader : CronetEngine.Builder.LibraryLoader() { } return true } catch (e: Throwable) { - e.printOnDebug() + Timber.e(e) if (destFile.exists() && !destFile.delete()) { destFile.deleteOnExit() } @@ -239,14 +239,14 @@ object CronetLoader : CronetEngine.Builder.LibraryLoader() { try { inputStream.close() } catch (e: IOException) { - e.printOnDebug() + Timber.e(e) } } if (outputStream != null) { try { outputStream.close() } catch (e: IOException) { - e.printOnDebug() + Timber.e(e) } } } @@ -320,20 +320,20 @@ object CronetLoader : CronetEngine.Builder.LibraryLoader() { } return true } catch (e: Exception) { - e.printOnDebug() + Timber.e(e) } finally { if (fileInputStream != null) { try { fileInputStream.close() } catch (e: Exception) { - e.printOnDebug() + Timber.e(e) } } if (os != null) { try { os.close() } catch (e: Exception) { - e.printOnDebug() + Timber.e(e) } } } @@ -355,15 +355,15 @@ object CronetLoader : CronetEngine.Builder.LibraryLoader() { } return String.format("%032x", BigInteger(1, md5.digest())).lowercase() } catch (e: Exception) { - e.printOnDebug() + Timber.e(e) } catch (e: OutOfMemoryError) { - e.printOnDebug() + Timber.e(e) } finally { if (fileInputStream != null) { try { fileInputStream.close() } catch (e: Exception) { - e.printOnDebug() + Timber.e(e) } } } 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 e640eadc0..3559ae944 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,7 +4,8 @@ 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 { @@ -37,11 +38,11 @@ object Preferences { // 返回修改路径以后的 SharedPreferences :%FILE_PATH%/%fileName%.xml return context.getSharedPreferences(fileName, Activity.MODE_PRIVATE) } catch (e: NoSuchFieldException) { - e.printOnDebug() + Timber.e(e) } catch (e: IllegalArgumentException) { - e.printOnDebug() + Timber.e(e) } catch (e: IllegalAccessException) { - e.printOnDebug() + Timber.e(e) } 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 0820032d5..8baee57e8 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,6 +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 @@ -92,7 +93,7 @@ object Restore { } } } catch (e: Exception) { - e.printOnDebug() + Timber.e(e) } } } @@ -168,7 +169,7 @@ object Restore { ThemeConfig.upConfig() } } catch (e: Exception) { - e.printOnDebug() + Timber.e(e) } if (!ignoreReadConfig) { //恢复阅读界面配置 @@ -181,7 +182,7 @@ object Restore { ReadBookConfig.initConfigs() } } catch (e: Exception) { - e.printOnDebug() + Timber.e(e) } try { val file = @@ -192,7 +193,7 @@ object Restore { ReadBookConfig.initShareConfig() } } catch (e: Exception) { - e.printOnDebug() + Timber.e(e) } } Preferences.getSharedPreferences(appCtx, path, "config")?.all?.let { map -> @@ -262,7 +263,7 @@ object Restore { val json = file.readText() return GSON.fromJsonArray(json) } catch (e: Exception) { - e.printOnDebug() + Timber.e(e) } 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 d2d488841..8ed1af146 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,13 @@ 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.* 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 @@ -101,8 +101,8 @@ class WebDav(urlStr: String) { val requestBody = requestPropsStr.toRequestBody("text/plain".toMediaType()) method("PROPFIND", requestBody) }.text() - }.onFailure { - it.printOnDebug() + }.onFailure { e -> + Timber.e(e) }.getOrNull() } return null @@ -134,7 +134,7 @@ class WebDav(urlStr: String) { } list.add(webDavFile) } catch (e: MalformedURLException) { - e.printOnDebug() + Timber.e(e) } } } 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 467e4f4bc..2174dbfd3 100644 --- a/app/src/main/java/io/legado/app/model/CacheBook.kt +++ b/app/src/main/java/io/legado/app/model/CacheBook.kt @@ -12,10 +12,11 @@ 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 +import timber.log.Timber import java.util.concurrent.ConcurrentHashMap import kotlin.coroutines.CoroutineContext @@ -177,7 +178,7 @@ object CacheBook { "下载${book.name}-${chapterTitle}失败\n${error.localizedMessage}", error ) - error.printOnDebug() + 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 8c9ef0b3b..df0d2014d 100644 --- a/app/src/main/java/io/legado/app/model/ReadBook.kt +++ b/app/src/main/java/io/legado/app/model/ReadBook.kt @@ -16,13 +16,14 @@ 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 import kotlinx.coroutines.MainScope import kotlinx.coroutines.delay import splitties.init.appCtx +import timber.log.Timber @Suppress("MemberVisibilityCanBePrivate") @@ -365,7 +366,7 @@ object ReadBook : CoroutineScope by MainScope() { } } }.onError { - it.printOnDebug() + Timber.e(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 9149d198a..084624513 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 io.legado.app.utils.printOnDebug + +import timber.log.Timber import java.util.* @Suppress("RegExpRedundantEscape") @@ -49,7 +50,7 @@ class AnalyzeByJSonPath(json: Any) { ob.toString() } } catch (e: Exception) { - e.printOnDebug() + Timber.e(e) } } return result @@ -86,7 +87,7 @@ class AnalyzeByJSonPath(json: Any) { result.add(obj.toString()) } } catch (e: Exception) { - e.printOnDebug() + Timber.e(e) } } else { result.add(st) @@ -136,7 +137,7 @@ class AnalyzeByJSonPath(json: Any) { try { return it.read>(rules[0]) } catch (e: Exception) { - e.printOnDebug() + Timber.e(e) } } } 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 acd036e4b..4837ffe7d 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 @@ -14,6 +14,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.* import java.util.regex.Pattern @@ -658,7 +659,7 @@ class AnalyzeRule( analyzeUrl.getStrResponseAwait().body }.onFailure { log("ajax(${urlStr}) error\n${it.stackTraceToString()}") - it.printOnDebug() + Timber.e(it) }.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 80e56c2d6..8e526b60f 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,11 +6,15 @@ 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.* +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 me.ag2s.epublib.domain.EpubBook import me.ag2s.epublib.epub.EpubReader import org.jsoup.Jsoup import splitties.init.appCtx +import timber.log.Timber import java.io.File import java.io.FileOutputStream import java.io.IOException @@ -94,7 +98,7 @@ class EpubFile(var book: Book) { } } } catch (e: Exception) { - e.printOnDebug() + Timber.e(e) } } @@ -108,7 +112,7 @@ class EpubFile(var book: Book) { } catch (e: Exception) { - e.printOnDebug() + Timber.e(e) } return null } @@ -205,7 +209,7 @@ class EpubFile(var book: Book) { title = elements[0].text() } } catch (e: IOException) { - e.printOnDebug() + Timber.e(e) } } 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 a706179ed..5d7e3626d 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,14 @@ 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.* +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 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 import java.util.* @@ -79,7 +83,7 @@ class UmdFile(var book: Book) { } } } catch (e: Exception) { - e.printOnDebug() + Timber.e(e) } } 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 6a0a919db..e74cd7b38 100644 --- a/app/src/main/java/io/legado/app/service/AudioPlayService.kt +++ b/app/src/main/java/io/legado/app/service/AudioPlayService.kt @@ -32,6 +32,7 @@ import io.legado.app.ui.book.audio.AudioPlayActivity import io.legado.app.utils.* import kotlinx.coroutines.* import kotlinx.coroutines.Dispatchers.Main +import timber.log.Timber class AudioPlayService : BaseService(), @@ -139,7 +140,7 @@ class AudioPlayService : BaseService(), exoPlayer.playWhenReady = true exoPlayer.prepare() }.onFailure { - it.printOnDebug() + Timber.e(it) toastOnUi("$url ${it.localizedMessage}") stopSelf() } @@ -160,7 +161,7 @@ class AudioPlayService : BaseService(), postEvent(EventBus.AUDIO_STATE, Status.PAUSE) upNotification() } catch (e: Exception) { - e.printOnDebug() + Timber.e(e) } } @@ -179,7 +180,7 @@ class AudioPlayService : BaseService(), postEvent(EventBus.AUDIO_STATE, Status.PLAY) upNotification() } catch (e: Exception) { - e.printOnDebug() + Timber.e(e) stopSelf() } } @@ -251,7 +252,7 @@ class AudioPlayService : BaseService(), val errorMsg = "音频播放出错\n${error.errorCodeName} ${error.errorCode}" AppLog.put(errorMsg, error) toastOnUi(errorMsg) - error.printOnDebug() + 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 db5a97951..0516531a2 100644 --- a/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt +++ b/app/src/main/java/io/legado/app/service/HttpReadAloudService.kt @@ -17,6 +17,7 @@ import kotlinx.coroutines.* import kotlinx.coroutines.sync.Mutex import kotlinx.coroutines.sync.withLock import okhttp3.Response +import timber.log.Timber import java.io.File import java.io.FileDescriptor import java.io.FileInputStream @@ -196,7 +197,7 @@ class HttpReadAloudService : BaseReadAloudService(), createSilentSound(fileName) AppLog.put("tts接口错误\n${e.localizedMessage}", e) toastOnUi("tts接口错误\n${e.localizedMessage}") - e.printOnDebug() + Timber.e(e) } } } @@ -213,7 +214,7 @@ class HttpReadAloudService : BaseReadAloudService(), playingIndex = nowSpeak postEvent(EventBus.TTS_PROGRESS, readAloudNumber + 1) } catch (e: Exception) { - e.printOnDebug() + Timber.e(e) } } } 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 56d196a4b..25fc5298a 100644 --- a/app/src/main/java/io/legado/app/service/WebService.kt +++ b/app/src/main/java/io/legado/app/service/WebService.kt @@ -14,6 +14,7 @@ import io.legado.app.ui.main.MainActivity 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() { @@ -87,7 +88,7 @@ class WebService : BaseService() { upNotification() } catch (e: IOException) { toastOnUi(e.localizedMessage ?: "") - e.printOnDebug() + Timber.e(e) 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 44513962e..83bb09cff 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,8 @@ 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 timber.log.Timber + /** * web服务快捷开关 @@ -27,7 +28,7 @@ class WebTileService : TileService() { } } } catch (e: Exception) { - e.printOnDebug() + Timber.e(e) } 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 857989643..94c7a7baf 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,7 +7,11 @@ import android.view.View import androidx.preference.Preference import androidx.preference.PreferenceFragmentCompat import io.legado.app.R -import io.legado.app.utils.* +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 class DonateFragment : PreferenceFragmentCompat() { @@ -46,7 +50,7 @@ class DonateFragment : PreferenceFragmentCompat() { intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) context.startActivity(intent) } catch (e: Exception) { - e.printOnDebug() + Timber.e(e) } 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 008d83dd3..53b3164b0 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 @@ -8,8 +8,9 @@ import io.legado.app.base.BaseViewModel 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) : BaseViewModel(application) { @@ -54,7 +55,7 @@ class FileAssociationViewModel(application: Application) : BaseViewModel(applica onLineImportLive.postValue(uri) } }.onError { - it.printOnDebug() + Timber.e(it) 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 520886401..9c1c7b83f 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 @@ -17,6 +17,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 +114,7 @@ class ImportBookSourceViewModel(app: Application) : BaseViewModel(app) { else -> throw NoStackTraceException(context.getString(R.string.wrong_format)) } }.onError { - it.printOnDebug() + Timber.e(it) 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 c667f8768..f0a52176c 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,6 +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 @@ -70,7 +71,7 @@ class CacheViewModel(application: Application) : BaseViewModel(application) { exportProgress.remove(book.bookUrl) exportMsg[book.bookUrl] = it.localizedMessage ?: "ERROR" upAdapterLiveData.postValue(book.bookUrl) - it.printOnDebug() + Timber.e(it) }.onSuccess { exportProgress.remove(book.bookUrl) exportMsg[book.bookUrl] = context.getString(R.string.export_success) @@ -205,7 +206,7 @@ class CacheViewModel(application: Application) : BaseViewModel(application) { exportProgress.remove(book.bookUrl) exportMsg[book.bookUrl] = it.localizedMessage ?: "ERROR" upAdapterLiveData.postValue(book.bookUrl) - it.printOnDebug() + Timber.e(it) }.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/ChangeSourceViewModel.kt b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceViewModel.kt index 84a7cafc3..5771fde07 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,10 +17,11 @@ 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 +import timber.log.Timber import java.util.concurrent.CopyOnWriteArraySet import java.util.concurrent.Executors import kotlin.math.min @@ -187,7 +188,7 @@ class ChangeSourceViewModel(application: Application) : BaseViewModel(applicatio searchFinish(searchBook) } }.onError { - it.printOnDebug() + Timber.e(it) } } @@ -198,7 +199,7 @@ class ChangeSourceViewModel(application: Application) : BaseViewModel(applicatio val searchBook: SearchBook = book.toSearchBook() searchFinish(searchBook) }.onError { - it.printOnDebug() + Timber.e(it) } } 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 eeadaeadc..acfbf2fcf 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,8 +10,9 @@ 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) { @@ -43,7 +44,7 @@ class ExploreShowViewModel(application: Application) : BaseViewModel(application appDb.searchBookDao.insert(*searchBooks.toTypedArray()) page++ }.onError { - it.printOnDebug() + Timber.e(it) 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 976f34a2a..9a0ec9460 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,6 +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") @@ -209,7 +210,7 @@ class TextActionMenu(private val context: Context, private val callBack: CallBac } context.startActivity(intent) }.onFailure { - it.printOnDebug() + Timber.e(it) 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 8ca29f81c..6ff08a850 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 @@ -28,6 +28,7 @@ import io.legado.app.ui.book.read.ReadBookActivity import io.legado.app.ui.document.HandleFileContract 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) { @@ -273,7 +274,7 @@ class BgTextConfigDialog : BaseDialogFragment(R.layout.dialog_read_bg_text) { }.onSuccess { toastOnUi("导出成功, 文件名为 $exportFileName") }.onError { - it.printOnDebug() + Timber.e(it) longToast("导出失败:${it.localizedMessage}") } } @@ -310,7 +311,7 @@ class BgTextConfigDialog : BaseDialogFragment(R.layout.dialog_read_bg_text) { @Suppress("BlockingMethodInNonBlockingContext") importConfig(uri.readBytes(requireContext())!!) }.onError { - it.printOnDebug() + Timber.e(it) longToast("导入失败:${it.localizedMessage}") } } @@ -324,7 +325,7 @@ class BgTextConfigDialog : BaseDialogFragment(R.layout.dialog_read_bg_text) { postEvent(EventBus.UP_CONFIG, true) toastOnUi("导入成功") }.onError { - it.printOnDebug() + Timber.e(it) 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 71c5673d0..0038ed4db 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 @@ -11,6 +11,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 +49,7 @@ class BookSourceEditViewModel(application: Application) : BaseViewModel(applicat success?.invoke() }.onError { context.toastOnUi(it.localizedMessage) - it.printOnDebug() + Timber.e(it) } } @@ -62,7 +63,7 @@ class BookSourceEditViewModel(application: Application) : BaseViewModel(applicat } }.onError { context.toastOnUi(it.localizedMessage ?: "Error") - it.printOnDebug() + Timber.e(it) } } 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 bcd77ad43..dd72acb5b 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,6 +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.* @@ -40,7 +41,7 @@ class WebViewModel(application: Application) : BaseViewModel(application) { success.invoke() }.onError { context.toastOnUi("error\n${it.localizedMessage}") - it.printOnDebug() + Timber.e(it) } } 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 11b50dfd7..14cf13334 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 @@ -9,8 +9,9 @@ import io.legado.app.constant.AppLog 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 timber.log.Timber import java.io.File class HandleFileViewModel(application: Application) : BaseViewModel(application) { @@ -29,7 +30,7 @@ class HandleFileViewModel(application: Application) : BaseViewModel(application) success.invoke(it) }.onError { AppLog.put("上传文件失败\n${it.localizedMessage}", it) - it.printOnDebug() + Timber.e(it) errorLiveData.postValue(it.localizedMessage) } } @@ -49,7 +50,7 @@ class HandleFileViewModel(application: Application) : BaseViewModel(application) Uri.fromFile(newFile) } }.onError { - it.printOnDebug() + Timber.e(it) errorLiveData.postValue(it.localizedMessage) }.onSuccess { success.invoke(it) 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 6d8f089b2..556599ae7 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,6 +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) { @@ -123,7 +124,7 @@ class SourceLoginDialog : BaseDialogFragment(R.layout.dialog_login) { } catch (e: Exception) { AppLog.put("登录出错\n${e.localizedMessage}", e) context?.toastOnUi("登录出错\n${e.localizedMessage}") - e.printOnDebug() + Timber.e(e) } } } 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 b91451a63..8d5e1224a 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 @@ -17,8 +17,9 @@ import io.legado.app.model.CacheBook 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 kotlinx.coroutines.* +import timber.log.Timber import java.util.concurrent.CopyOnWriteArraySet import java.util.concurrent.Executors import kotlin.math.min @@ -126,7 +127,7 @@ class MainViewModel(application: Application) : BaseViewModel(application) { addDownload(source, book) }.onError(upTocPool) { AppLog.put("${book.name} 更新目录失败\n${it.localizedMessage}", it) - it.printOnDebug() + Timber.e(it) }.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 de87c3a55..808d37881 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,10 +9,11 @@ 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() @@ -53,7 +54,7 @@ class RssArticlesViewModel(application: Application) : BaseViewModel(application } }.onError { loadFinally.postValue(false) - it.printOnDebug() + Timber.e(it) context.toastOnUi(it.localizedMessage) } } @@ -69,7 +70,7 @@ class RssArticlesViewModel(application: Application) : BaseViewModel(application loadMoreSuccess(it.first) } .onError { - it.printOnDebug() + Timber.e(it) 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 768a4b3b7..3f4ebfe95 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,9 +7,10 @@ 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) { @@ -41,7 +42,7 @@ class RssSourceEditViewModel(application: Application) : BaseViewModel(applicati success() }.onError { context.toastOnUi(it.localizedMessage) - it.printOnDebug() + Timber.e(it) } } 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 b41d6b418..f2c289ef3 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,8 @@ import android.view.Gravity import android.widget.TextView import androidx.appcompat.widget.SearchView import io.legado.app.R -import io.legado.app.utils.printOnDebug +import timber.log.Timber + class SearchView @JvmOverloads constructor( context: Context, @@ -43,7 +44,7 @@ class SearchView @JvmOverloads constructor( textView!!.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14f) textView!!.gravity = Gravity.CENTER_VERTICAL } catch (e: Exception) { - e.printOnDebug() + Timber.e(e) } } 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 0974e4a97..d04de80f0 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 io.legado.app.utils.printOnDebug +import timber.log.Timber + import kotlin.math.roundToInt object Utils { @@ -66,7 +67,7 @@ object Utils { try { return Bitmap.createBitmap(width, height, config) } catch (e: OutOfMemoryError) { - e.printOnDebug() + Timber.e(e) 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 5dcb8868a..7d4fe0ccb 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 @@ -8,6 +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 @@ -41,7 +42,7 @@ class FontAdapter(context: Context, val callBack: CallBack) : } tvFont.typeface = typeface }.onFailure { - it.printOnDebug() + Timber.e(it) 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 80b65c536..47893d6c6 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,8 +20,9 @@ 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 @@ -317,7 +318,7 @@ class CircleImageView @JvmOverloads constructor( drawable.draw(canvas) bitmap } catch (e: Exception) { - e.printOnDebug() + Timber.e(e) 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 64f526dcf..11b448aa6 100644 --- a/app/src/main/java/io/legado/app/utils/ACache.kt +++ b/app/src/main/java/io/legado/app/utils/ACache.kt @@ -8,10 +8,10 @@ import android.graphics.Canvas import android.graphics.PixelFormat import android.graphics.drawable.BitmapDrawable import android.graphics.drawable.Drawable -import android.util.Log 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()) { - Log.i("ACache", "can't make dirs in %s" + cacheDir.absolutePath) + Timber.i("can't make dirs in %s" + cacheDir.absolutePath) } mCache = ACacheManager(cacheDir, max_size, max_count) } catch (e: Exception) { - e.printOnDebug() + Timber.e(e) } } @@ -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.printOnDebug() + Timber.e(e) } } } @@ -131,7 +131,7 @@ class ACache private constructor(cacheDir: File, max_size: Long, max_count: Int) removeFile = true } } catch (e: IOException) { - e.printOnDebug() + Timber.e(e) } 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.printOnDebug() + Timber.e(e) } 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.printOnDebug() + Timber.e(e) } } @@ -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.printOnDebug() + Timber.e(e) } finally { try { bis?.close() } catch (e: IOException) { - e.printOnDebug() + Timber.e(e) } try { ois?.close() } catch (e: IOException) { - e.printOnDebug() + Timber.e(e) } } @@ -427,7 +427,7 @@ class ACache private constructor(cacheDir: File, max_size: Long, max_count: Int) return f } } catch (e: Exception) { - e.printOnDebug() + Timber.e(e) } } return null @@ -488,7 +488,7 @@ class ACache private constructor(cacheDir: File, max_size: Long, max_count: Int) } } } catch (e: Exception) { - e.printOnDebug() + Timber.e(e) } 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.printOnDebug() + Timber.e(e) } @@ -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.printOnDebug() + Timber.e(e) } } @@ -727,7 +727,7 @@ class ACache private constructor(cacheDir: File, max_size: Long, max_count: Int) } } } catch (e: Exception) { - e.printOnDebug() + Timber.e(e) } } @@ -767,7 +767,7 @@ class ACache private constructor(cacheDir: File, max_size: Long, max_count: Int) } return fileSize } catch (e: Exception) { - e.printOnDebug() + Timber.e(e) 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 3b6156a7c..35b7d00ac 100644 --- a/app/src/main/java/io/legado/app/utils/ContextExtensions.kt +++ b/app/src/main/java/io/legado/app/utils/ContextExtensions.kt @@ -27,6 +27,7 @@ import androidx.preference.PreferenceManager import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel import io.legado.app.R import io.legado.app.constant.AppConst +import timber.log.Timber import java.io.File import java.io.FileOutputStream @@ -158,7 +159,7 @@ val Context.sysScreenOffTime: Int screenOffTime = Settings.System.getInt(contentResolver, Settings.System.SCREEN_OFF_TIMEOUT) } catch (e: Exception) { - e.printOnDebug() + Timber.e(e) } return screenOffTime } @@ -316,7 +317,7 @@ val Context.channel: String val appInfo = pm.getApplicationInfo(packageName, PackageManager.GET_META_DATA) return appInfo.metaData.getString("channel") ?: "" } catch (e: Exception) { - e.printOnDebug() + Timber.e(e) } 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 0604aaacb..40274b8a3 100644 --- a/app/src/main/java/io/legado/app/utils/DocumentUtils.kt +++ b/app/src/main/java/io/legado/app/utils/DocumentUtils.kt @@ -5,6 +5,7 @@ import android.database.Cursor import android.net.Uri import android.provider.DocumentsContract import androidx.documentfile.provider.DocumentFile +import timber.log.Timber import java.nio.charset.Charset import java.util.* @@ -131,7 +132,7 @@ object DocumentUtils { } } } catch (e: Exception) { - e.printOnDebug() + Timber.e(e) } finally { cursor?.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 81facf72d..6370bc300 100644 --- a/app/src/main/java/io/legado/app/utils/FileUtils.kt +++ b/app/src/main/java/io/legado/app/utils/FileUtils.kt @@ -5,6 +5,7 @@ import android.webkit.MimeTypeMap import androidx.annotation.IntDef import io.legado.app.ui.document.utils.ConvertUtils import splitties.init.appCtx +import timber.log.Timber import java.io.* import java.nio.charset.Charset import java.text.SimpleDateFormat @@ -46,7 +47,7 @@ object FileUtils { file.createNewFile() } } catch (e: IOException) { - e.printOnDebug() + Timber.e(e) } return file } @@ -116,8 +117,8 @@ object FileUtils { var sdCardDirectory = Environment.getExternalStorageDirectory().absolutePath try { sdCardDirectory = File(sdCardDirectory).canonicalPath - } catch (ioe: IOException) { - ioe.printOnDebug() + } catch (e: IOException) { + Timber.e(e) } 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 a73233235..a409410ff 100644 --- a/app/src/main/java/io/legado/app/utils/GsonExtensions.kt +++ b/app/src/main/java/io/legado/app/utils/GsonExtensions.kt @@ -3,6 +3,7 @@ package io.legado.app.utils import com.google.gson.* import com.google.gson.internal.LinkedTreeMap import com.google.gson.reflect.TypeToken +import timber.log.Timber import java.lang.reflect.ParameterizedType import java.lang.reflect.Type import kotlin.math.ceil @@ -26,7 +27,7 @@ inline fun Gson.fromJsonObject(json: String?): T? {//可转成任意 return kotlin.runCatching { fromJson(json, genericType()) as? T }.onFailure { - it.printOnDebug() + Timber.e(it) }.getOrNull() } @@ -34,7 +35,7 @@ inline fun Gson.fromJsonArray(json: String?): List? { return kotlin.runCatching { fromJson(json, ParameterizedTypeImpl(T::class.java)) as? List }.onFailure { - it.printOnDebug() + Timber.e(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 f7e804d77..96bda9b86 100644 --- a/app/src/main/java/io/legado/app/utils/LogUtils.kt +++ b/app/src/main/java/io/legado/app/utils/LogUtils.kt @@ -3,7 +3,6 @@ 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.* @@ -71,12 +70,6 @@ object LogUtils { } } -fun Throwable.printOnDebug() { - if (BuildConfig.DEBUG) { - printStackTrace() - } -} - fun dLog(tag: String, msg: String) { LogUtils.d(tag, msg) } 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 829799597..4c4c6959c 100644 --- a/app/src/main/java/io/legado/app/utils/MD5Utils.kt +++ b/app/src/main/java/io/legado/app/utils/MD5Utils.kt @@ -1,5 +1,6 @@ package io.legado.app.utils +import timber.log.Timber import java.security.MessageDigest import java.security.NoSuchAlgorithmException @@ -25,7 +26,7 @@ object MD5Utils { } reStr = stringBuffer.toString() } catch (e: NoSuchAlgorithmException) { - e.printOnDebug() + Timber.e(e) } 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 951cf8cde..6c33aed99 100644 --- a/app/src/main/java/io/legado/app/utils/NetworkUtils.kt +++ b/app/src/main/java/io/legado/app/utils/NetworkUtils.kt @@ -4,6 +4,7 @@ import android.net.ConnectivityManager import android.net.NetworkCapabilities import android.os.Build import splitties.systemservices.connectivityManager +import timber.log.Timber import java.net.InetAddress import java.net.NetworkInterface import java.net.SocketException @@ -114,7 +115,7 @@ object NetworkUtils { relativeUrl = parseUrl.toString() return relativeUrl } catch (e: Exception) { - e.printOnDebug() + Timber.e(e) } return relativeUrl } @@ -130,7 +131,7 @@ object NetworkUtils { relativeUrl = parseUrl.toString() return relativeUrl } catch (e: Exception) { - e.printOnDebug() + Timber.e(e) } return relativeUrl } @@ -158,7 +159,7 @@ object NetworkUtils { try { enumeration = NetworkInterface.getNetworkInterfaces() } catch (e: SocketException) { - e.printOnDebug() + Timber.e(e) } 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 7205ba078..c502c97b9 100644 --- a/app/src/main/java/io/legado/app/utils/RealPathUtil.kt +++ b/app/src/main/java/io/legado/app/utils/RealPathUtil.kt @@ -9,6 +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 @@ -111,7 +112,7 @@ object RealPathUtil { return cursor.getString(index) } } catch (e: IllegalArgumentException) { - e.printOnDebug() + Timber.e(e) val file = File(context.cacheDir, "tmp") val filePath = file.absolutePath var input: FileInputStream? = null @@ -130,7 +131,7 @@ object RealPathUtil { } return File(filePath).absolutePath } catch (ignored: IOException) { - ignored.printOnDebug() + Timber.e(ignored) } 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 c12c0dcc8..6d9d49eca 100644 --- a/app/src/main/java/io/legado/app/utils/StringUtils.kt +++ b/app/src/main/java/io/legado/app/utils/StringUtils.kt @@ -2,6 +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.* @@ -95,7 +96,7 @@ object StringUtils { } } }.onFailure { - it.printOnDebug() + Timber.e(it) } 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 15162d7a3..af953f294 100644 --- a/app/src/main/java/io/legado/app/utils/SystemUtils.kt +++ b/app/src/main/java/io/legado/app/utils/SystemUtils.kt @@ -8,6 +8,7 @@ import android.content.Intent import android.net.Uri import android.os.PowerManager import android.provider.Settings +import timber.log.Timber @Suppress("unused") @@ -21,7 +22,7 @@ object SystemUtils { Settings.System.SCREEN_OFF_TIMEOUT ) }.onFailure { - it.printOnDebug() + Timber.e(it) } 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 0e2a318fb..55fe96450 100644 --- a/app/src/main/java/io/legado/app/utils/UriExtensions.kt +++ b/app/src/main/java/io/legado/app/utils/UriExtensions.kt @@ -9,6 +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 +43,7 @@ fun AppCompatActivity.readUri(uri: Uri?, success: (name: String, bytes: ByteArra .request() } } catch (e: Exception) { - e.printOnDebug() + Timber.e(e) toastOnUi(e.localizedMessage ?: "read uri error") } } @@ -76,7 +77,7 @@ fun Fragment.readUri(uri: Uri?, success: (name: String, bytes: ByteArray) -> Uni .request() } } catch (e: Exception) { - e.printOnDebug() + Timber.e(e) 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 700dda057..05f96defe 100644 --- a/app/src/main/java/io/legado/app/utils/ViewExtensions.kt +++ b/app/src/main/java/io/legado/app/utils/ViewExtensions.kt @@ -22,6 +22,7 @@ import androidx.viewpager.widget.ViewPager import io.legado.app.help.AppConfig import io.legado.app.lib.theme.TintHelper import splitties.init.appCtx +import timber.log.Timber import java.lang.reflect.Field @@ -171,6 +172,6 @@ fun PopupMenu.show(x: Int, y: Int) { field.isAccessible = true (field.get(this) as MenuPopupHelper).show(x, y) }.onFailure { - it.printOnDebug() + Timber.e(it) } } \ 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 c3cef46cb..ebfcdc13e 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.printOnDebug() + Timber.e(e) 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 4bf0ef35f..62abbdec2 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 @@ -10,6 +10,7 @@ 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 @@ -86,7 +87,7 @@ class BookSourceDebugWebSocket(handshakeRequest: NanoHTTPD.IHTTPSession) : close(NanoWSD.WebSocketFrame.CloseCode.NormalClosure, "调试结束", false) } }.onFailure { - it.printOnDebug() + Timber.e(it) } } } 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 f99c0a7e2..73a1f87b2 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 @@ -10,6 +10,7 @@ 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 @@ -85,7 +86,7 @@ class RssSourceDebugWebSocket(handshakeRequest: NanoHTTPD.IHTTPSession) : close(NanoWSD.WebSocketFrame.CloseCode.NormalClosure, "调试结束", false) } }.onFailure { - it.printOnDebug() + Timber.e(it) } } }