pull/1319/head
gedoor 3 years ago
parent f1788ed904
commit ec970564cd
  1. 2
      app/src/main/java/io/legado/app/api/controller/BookController.kt
  2. 18
      app/src/main/java/io/legado/app/constant/AppLog.kt
  3. 5
      app/src/main/java/io/legado/app/data/entities/BaseSource.kt
  4. 2
      app/src/main/java/io/legado/app/data/entities/BookSource.kt
  5. 2
      app/src/main/java/io/legado/app/help/BookHelp.kt
  6. 2
      app/src/main/java/io/legado/app/help/BookSourceAnalyzer.kt
  7. 14
      app/src/main/java/io/legado/app/help/JsExtensions.kt
  8. 6
      app/src/main/java/io/legado/app/help/ReadBookConfig.kt
  9. 2
      app/src/main/java/io/legado/app/help/ThemeConfig.kt
  10. 3
      app/src/main/java/io/legado/app/help/coroutine/Coroutine.kt
  11. 9
      app/src/main/java/io/legado/app/help/http/SSLHelper.kt
  12. 21
      app/src/main/java/io/legado/app/help/http/cronet/CronetLoader.kt
  13. 7
      app/src/main/java/io/legado/app/help/storage/Preferences.kt
  14. 10
      app/src/main/java/io/legado/app/help/storage/Restore.kt
  15. 5
      app/src/main/java/io/legado/app/lib/webdav/WebDav.kt
  16. 7
      app/src/main/java/io/legado/app/model/CacheBook.kt
  17. 3
      app/src/main/java/io/legado/app/model/ReadBook.kt
  18. 3
      app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeByJSonPath.kt
  19. 3
      app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeByJSoup.kt
  20. 2
      app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt
  21. 11
      app/src/main/java/io/legado/app/model/localBook/EpubFile.kt
  22. 7
      app/src/main/java/io/legado/app/model/localBook/UmdFile.kt
  23. 8
      app/src/main/java/io/legado/app/service/AudioPlayService.kt
  24. 2
      app/src/main/java/io/legado/app/service/HttpReadAloudService.kt
  25. 2
      app/src/main/java/io/legado/app/service/WebService.kt
  26. 3
      app/src/main/java/io/legado/app/service/WebTileService.kt
  27. 41
      app/src/main/java/io/legado/app/ui/about/AppLogDialog.kt
  28. 7
      app/src/main/java/io/legado/app/ui/about/DonateFragment.kt
  29. 3
      app/src/main/java/io/legado/app/ui/association/FileAssociationViewModel.kt
  30. 2
      app/src/main/java/io/legado/app/ui/association/ImportBookSourceViewModel.kt
  31. 6
      app/src/main/java/io/legado/app/ui/book/cache/CacheActivity.kt
  32. 4
      app/src/main/java/io/legado/app/ui/book/cache/CacheViewModel.kt
  33. 5
      app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceViewModel.kt
  34. 3
      app/src/main/java/io/legado/app/ui/book/explore/ExploreShowViewModel.kt
  35. 2
      app/src/main/java/io/legado/app/ui/book/read/TextActionMenu.kt
  36. 6
      app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt
  37. 4
      app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditViewModel.kt
  38. 5
      app/src/main/java/io/legado/app/ui/document/HandleFileViewModel.kt
  39. 2
      app/src/main/java/io/legado/app/ui/login/RuleUiLoginDialog.kt
  40. 3
      app/src/main/java/io/legado/app/ui/main/MainViewModel.kt
  41. 5
      app/src/main/java/io/legado/app/ui/rss/article/RssArticlesViewModel.kt
  42. 2
      app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditViewModel.kt
  43. 3
      app/src/main/java/io/legado/app/ui/widget/SearchView.kt
  44. 3
      app/src/main/java/io/legado/app/ui/widget/anima/explosion_field/Utils.kt
  45. 2
      app/src/main/java/io/legado/app/ui/widget/font/FontAdapter.kt
  46. 3
      app/src/main/java/io/legado/app/ui/widget/image/CircleImageView.kt
  47. 28
      app/src/main/java/io/legado/app/utils/ACache.kt
  48. 4
      app/src/main/java/io/legado/app/utils/ContextExtensions.kt
  49. 2
      app/src/main/java/io/legado/app/utils/DocumentUtils.kt
  50. 4
      app/src/main/java/io/legado/app/utils/FileUtils.kt
  51. 19
      app/src/main/java/io/legado/app/utils/LogUtils.kt
  52. 2
      app/src/main/java/io/legado/app/utils/MD5Utils.kt
  53. 6
      app/src/main/java/io/legado/app/utils/NetworkUtils.kt
  54. 4
      app/src/main/java/io/legado/app/utils/RealPathUtil.kt
  55. 2
      app/src/main/java/io/legado/app/utils/StringUtils.kt
  56. 2
      app/src/main/java/io/legado/app/utils/SystemUtils.kt
  57. 4
      app/src/main/java/io/legado/app/utils/UriExtensions.kt
  58. 2
      app/src/main/java/io/legado/app/utils/ViewExtensions.kt
  59. 2
      app/src/main/java/io/legado/app/utils/ZipUtils.kt
  60. 7
      app/src/main/java/io/legado/app/web/SourceDebugWebSocket.kt
  61. 3
      epublib/src/main/java/me/ag2s/epublib/epub/PackageDocumentWriter.java

@ -216,7 +216,7 @@ object BookController {
if (book.isUmd()) UmdFile.upBookInfo(book)
appDb.bookDao.insert(book)
} catch (e: Exception) {
e.printStackTrace()
e.printOnDebug()
return returnData.setErrorMsg(
e.localizedMessage ?: appCtx.getString(R.string.unknown_error)
)

@ -1,24 +1,16 @@
package io.legado.app.constant
import android.annotation.SuppressLint
import java.text.SimpleDateFormat
import java.util.*
object AppLog {
@SuppressLint("ConstantLocale")
private val logTimeFormat = SimpleDateFormat("[mm:ss.SSS]", Locale.getDefault())
val logs = arrayListOf<String>()
val logs = arrayListOf<Triple<Long, String, Throwable?>>()
fun addLog(log: String?) {
log ?: return
synchronized(logs) {
@Synchronized
fun addLog(message: String?, throwable: Throwable?) {
message ?: return
if (logs.size > 1000) {
logs.removeLastOrNull()
}
logs.add(0, logTimeFormat.format(Date()) + " " + log)
}
logs.add(0, Triple(System.currentTimeMillis(), message, throwable))
}
}

@ -10,6 +10,7 @@ import io.legado.app.help.http.CookieStore
import io.legado.app.utils.EncoderUtils
import io.legado.app.utils.GSON
import io.legado.app.utils.fromJsonObject
import io.legado.app.utils.printOnDebug
import javax.script.SimpleBindings
/**
@ -95,7 +96,7 @@ interface BaseSource : JsExtensions {
?: return null
return String(decodeBytes)
} catch (e: Exception) {
e.printStackTrace()
e.printOnDebug()
return null
}
}
@ -115,7 +116,7 @@ interface BaseSource : JsExtensions {
CacheManager.put("userInfo_${getStoreUrl()}", encodeStr)
true
} catch (e: Exception) {
e.printStackTrace()
e.printOnDebug()
false
}
}

@ -91,7 +91,7 @@ data class BookSource(
}
}
}.onFailure {
it.printStackTrace()
it.printOnDebug()
kinds.add(ExploreKind(it.localizedMessage ?: ""))
}
}

@ -126,7 +126,7 @@ object BookHelp {
).writeBytes(it)
}
} catch (e: Exception) {
e.printStackTrace()
e.printOnDebug()
} finally {
downloadImages.remove(src)
}

@ -140,7 +140,7 @@ object BookSourceAnalyzer {
}
}
} catch (e: Exception) {
e.printStackTrace()
e.printOnDebug()
}
return source
}

@ -45,7 +45,7 @@ interface JsExtensions {
val analyzeUrl = AnalyzeUrl(urlStr, source = getSource())
analyzeUrl.getStrResponse().body
}.onFailure {
it.printStackTrace()
it.printOnDebug()
}.getOrElse {
it.msg
}
@ -80,7 +80,7 @@ interface JsExtensions {
kotlin.runCatching {
analyzeUrl.getStrResponse()
}.onFailure {
it.printStackTrace()
it.printOnDebug()
}.getOrElse {
StrResponse(analyzeUrl.url, it.localizedMessage)
}
@ -94,7 +94,7 @@ interface JsExtensions {
kotlin.runCatching {
analyzeUrl.getStrResponse()
}.onFailure {
it.printStackTrace()
it.printOnDebug()
}.getOrElse {
StrResponse(analyzeUrl.url, it.localizedMessage)
}
@ -480,7 +480,7 @@ interface JsExtensions {
iv.encodeToByteArray()
)
} catch (e: java.lang.Exception) {
e.printStackTrace()
e.printOnDebug()
log(e.localizedMessage ?: "aesDecodeToByteArrayERROR")
null
}
@ -519,7 +519,7 @@ interface JsExtensions {
iv.encodeToByteArray()
)
} catch (e: Exception) {
e.printStackTrace()
e.printOnDebug()
log(e.localizedMessage ?: "aesDecodeToByteArrayERROR")
null
}
@ -557,7 +557,7 @@ interface JsExtensions {
iv.encodeToByteArray()
)
} catch (e: Exception) {
e.printStackTrace()
e.printOnDebug()
log(e.localizedMessage ?: "aesEncodeToByteArrayERROR")
null
}
@ -594,7 +594,7 @@ interface JsExtensions {
iv.encodeToByteArray()
)
} catch (e: Exception) {
e.printStackTrace()
e.printOnDebug()
log(e.localizedMessage ?: "aesEncodeToBase64ByteArrayERROR")
null
}

@ -61,7 +61,7 @@ object ReadBookConfig {
val json = configFile.readText()
configs = GSON.fromJsonArray(json)
} catch (e: Exception) {
e.printStackTrace()
e.printOnDebug()
}
}
(configs ?: DefaultData.readConfigs).let {
@ -78,7 +78,7 @@ object ReadBookConfig {
val json = configFile.readText()
c = GSON.fromJsonObject(json)
} catch (e: Exception) {
e.printStackTrace()
e.printOnDebug()
}
}
shareConfig = c ?: configList.getOrNull(5) ?: Config()
@ -570,7 +570,7 @@ object ReadBookConfig {
)
}
} catch (e: Exception) {
e.printStackTrace()
e.printOnDebug()
}
return bgDrawable ?: ColorDrawable(appCtx.getCompatColor(R.color.background))
}

@ -108,7 +108,7 @@ object ThemeConfig {
val json = configFile.readText()
return GSON.fromJsonArray(json)
}.onFailure {
it.printStackTrace()
it.printOnDebug()
}
}
return null

@ -1,6 +1,7 @@
package io.legado.app.help.coroutine
import io.legado.app.BuildConfig
import io.legado.app.utils.printOnDebug
import kotlinx.coroutines.*
import kotlin.coroutines.CoroutineContext
@ -143,7 +144,7 @@ class Coroutine<T>(
}
} catch (e: Throwable) {
if (BuildConfig.DEBUG) {
e.printStackTrace()
e.printOnDebug()
}
val consume: Boolean = errorReturn?.value?.let { value ->
if (isActive) {

@ -1,6 +1,7 @@
package io.legado.app.help.http
import android.annotation.SuppressLint
import io.legado.app.utils.printOnDebug
import java.io.IOException
import java.io.InputStream
import java.security.KeyManagementException
@ -125,9 +126,9 @@ object SSLHelper {
sslParams.trustManager = manager
return sslParams
} catch (e: NoSuchAlgorithmException) {
e.printStackTrace()
e.printOnDebug()
} catch (e: KeyManagementException) {
e.printStackTrace()
e.printOnDebug()
}
return null
}
@ -141,7 +142,7 @@ object SSLHelper {
kmf.init(clientKeyStore, password.toCharArray())
return kmf.keyManagers
} catch (e: Exception) {
e.printStackTrace()
e.printOnDebug()
}
return null
}
@ -160,7 +161,7 @@ object SSLHelper {
try {
certStream.close()
} catch (e: IOException) {
e.printStackTrace()
e.printOnDebug()
}
}
//我们创建一个默认类型的TrustManagerFactory

@ -10,6 +10,7 @@ import com.google.android.gms.net.CronetProviderInstaller
import io.legado.app.BuildConfig
import io.legado.app.help.AppConfig
import io.legado.app.help.coroutine.Coroutine
import io.legado.app.utils.printOnDebug
import org.chromium.net.CronetEngine
import org.json.JSONObject
import splitties.init.appCtx
@ -163,7 +164,7 @@ object CronetLoader : CronetEngine.Builder.LibraryLoader() {
abiField.isAccessible = true
cpuAbi = abiField.get(appInfo) as String?
} catch (e: Exception) {
e.printStackTrace()
e.printOnDebug()
}
if (TextUtils.isEmpty(cpuAbi)) {
cpuAbi = Build.SUPPORTED_ABIS[0]
@ -214,7 +215,7 @@ object CronetLoader : CronetEngine.Builder.LibraryLoader() {
}
return true
} catch (e: Throwable) {
e.printStackTrace()
e.printOnDebug()
if (destFile.exists() && !destFile.delete()) {
destFile.deleteOnExit()
}
@ -223,14 +224,14 @@ object CronetLoader : CronetEngine.Builder.LibraryLoader() {
try {
inputStream.close()
} catch (e: IOException) {
e.printStackTrace()
e.printOnDebug()
}
}
if (outputStream != null) {
try {
outputStream.close()
} catch (e: IOException) {
e.printStackTrace()
e.printOnDebug()
}
}
}
@ -303,20 +304,20 @@ object CronetLoader : CronetEngine.Builder.LibraryLoader() {
}
return true
} catch (e: Exception) {
e.printStackTrace()
e.printOnDebug()
} finally {
if (fileInputStream != null) {
try {
fileInputStream.close()
} catch (e: Exception) {
e.printStackTrace()
e.printOnDebug()
}
}
if (os != null) {
try {
os.close()
} catch (e: Exception) {
e.printStackTrace()
e.printOnDebug()
}
}
}
@ -338,15 +339,15 @@ object CronetLoader : CronetEngine.Builder.LibraryLoader() {
}
return String.format("%032x", BigInteger(1, md5.digest())).lowercase()
} catch (e: Exception) {
e.printStackTrace()
e.printOnDebug()
} catch (e: OutOfMemoryError) {
e.printStackTrace()
e.printOnDebug()
} finally {
if (fileInputStream != null) {
try {
fileInputStream.close()
} catch (e: Exception) {
e.printStackTrace()
e.printOnDebug()
}
}
}

@ -4,6 +4,7 @@ import android.app.Activity
import android.content.Context
import android.content.ContextWrapper
import android.content.SharedPreferences
import io.legado.app.utils.printOnDebug
import java.io.File
object Preferences {
@ -36,11 +37,11 @@ object Preferences {
// 返回修改路径以后的 SharedPreferences :%FILE_PATH%/%fileName%.xml
return context.getSharedPreferences(fileName, Activity.MODE_PRIVATE)
} catch (e: NoSuchFieldException) {
e.printStackTrace()
e.printOnDebug()
} catch (e: IllegalArgumentException) {
e.printStackTrace()
e.printOnDebug()
} catch (e: IllegalAccessException) {
e.printStackTrace()
e.printOnDebug()
}
return null
}

@ -94,7 +94,7 @@ object Restore {
}
}
} catch (e: Exception) {
e.printStackTrace()
e.printOnDebug()
}
}
}
@ -169,7 +169,7 @@ object Restore {
ThemeConfig.upConfig()
}
} catch (e: Exception) {
e.printStackTrace()
e.printOnDebug()
}
if (!ignoreReadConfig) {
try {
@ -181,7 +181,7 @@ object Restore {
ReadBookConfig.initConfigs()
}
} catch (e: Exception) {
e.printStackTrace()
e.printOnDebug()
}
try {
val file =
@ -192,7 +192,7 @@ object Restore {
ReadBookConfig.initShareConfig()
}
} catch (e: Exception) {
e.printStackTrace()
e.printOnDebug()
}
}
Preferences.getSharedPreferences(appCtx, path, "config")?.all?.let { map ->
@ -267,7 +267,7 @@ object Restore {
val json = file.readText()
return GSON.fromJsonArray(json)
} catch (e: Exception) {
e.printStackTrace()
e.printOnDebug()
}
return null
}

@ -3,6 +3,7 @@ package io.legado.app.lib.webdav
import io.legado.app.help.http.newCall
import io.legado.app.help.http.okHttpClient
import io.legado.app.help.http.text
import io.legado.app.utils.printOnDebug
import okhttp3.*
import okhttp3.MediaType.Companion.toMediaType
import okhttp3.RequestBody.Companion.asRequestBody
@ -101,7 +102,7 @@ class WebDav(urlStr: String) {
method("PROPFIND", requestBody)
}.text()
}.onFailure {
it.printStackTrace()
it.printOnDebug()
}.getOrNull()
}
return null
@ -133,7 +134,7 @@ class WebDav(urlStr: String) {
}
list.add(webDavFile)
} catch (e: MalformedURLException) {
e.printStackTrace()
e.printOnDebug()
}
}
}

@ -12,6 +12,7 @@ import io.legado.app.help.BookHelp
import io.legado.app.model.webBook.WebBook
import io.legado.app.service.CacheBookService
import io.legado.app.utils.postEvent
import io.legado.app.utils.printOnDebug
import io.legado.app.utils.startService
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.delay
@ -169,7 +170,11 @@ class CacheBook(var bookSource: BookSource, var book: Book) {
if (errorDownloadMap[index] ?: 0 < 3) {
waitDownloadSet.add(index)
} else {
AppLog.addLog("${book.name}-${chapterTitle} ${error.localizedMessage}")
AppLog.addLog(
"download ${book.name}-${chapterTitle} error:${error.localizedMessage}",
error
)
error.printOnDebug()
}
}

@ -14,6 +14,7 @@ import io.legado.app.ui.book.read.page.entities.TextChapter
import io.legado.app.ui.book.read.page.provider.ChapterProvider
import io.legado.app.ui.book.read.page.provider.ImageProvider
import io.legado.app.utils.msg
import io.legado.app.utils.printOnDebug
import io.legado.app.utils.toastOnUi
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers.IO
@ -365,7 +366,7 @@ object ReadBook : CoroutineScope by MainScope() {
}
}
}.onError {
it.printStackTrace()
it.printOnDebug()
appCtx.toastOnUi("ChapterProvider ERROR:\n${it.msg}")
}.onSuccess {
success?.invoke()

@ -3,6 +3,7 @@ package io.legado.app.model.analyzeRule
import androidx.annotation.Keep
import com.jayway.jsonpath.JsonPath
import com.jayway.jsonpath.ReadContext
import io.legado.app.utils.printOnDebug
import java.util.*
@Suppress("RegExpRedundantEscape")
@ -155,7 +156,7 @@ class AnalyzeByJSonPath(json: Any) {
try {
return it.read<ArrayList<Any>>(rules[0])
} catch (e: Exception) {
e.printStackTrace()
e.printOnDebug()
}
}
return null

@ -1,6 +1,7 @@
package io.legado.app.model.analyzeRule
import androidx.annotation.Keep
import io.legado.app.utils.printOnDebug
import org.jsoup.Jsoup
import org.jsoup.nodes.Element
import org.jsoup.select.Collector
@ -254,7 +255,7 @@ class AnalyzeByJSoup(doc: Any) {
}
}
} catch (e: Exception) {
e.printStackTrace()
e.printOnDebug()
}
return textS

@ -653,7 +653,7 @@ class AnalyzeRule(
val analyzeUrl = AnalyzeUrl(urlStr, book = book, source = source)
analyzeUrl.getStrResponse().body
}.onFailure {
it.printStackTrace()
it.printOnDebug()
}.getOrElse {
it.msg
}

@ -6,10 +6,7 @@ import android.text.TextUtils
import io.legado.app.data.entities.Book
import io.legado.app.data.entities.BookChapter
import io.legado.app.help.BookHelp
import io.legado.app.utils.FileUtils
import io.legado.app.utils.HtmlFormatter
import io.legado.app.utils.MD5Utils
import io.legado.app.utils.externalFiles
import io.legado.app.utils.*
import me.ag2s.epublib.domain.EpubBook
import me.ag2s.epublib.epub.EpubReader
import org.jsoup.Jsoup
@ -97,7 +94,7 @@ class EpubFile(var book: Book) {
}
}
} catch (e: Exception) {
e.printStackTrace()
e.printOnDebug()
}
}
@ -111,7 +108,7 @@ class EpubFile(var book: Book) {
} catch (e: Exception) {
e.printStackTrace()
e.printOnDebug()
}
return null
}
@ -208,7 +205,7 @@ class EpubFile(var book: Book) {
title = elements[0].text()
}
} catch (e: IOException) {
e.printStackTrace()
e.printOnDebug()
}
}
val chapter = BookChapter()

@ -4,10 +4,7 @@ import android.net.Uri
import android.util.Log
import io.legado.app.data.entities.Book
import io.legado.app.data.entities.BookChapter
import io.legado.app.utils.FileUtils
import io.legado.app.utils.MD5Utils
import io.legado.app.utils.externalFiles
import io.legado.app.utils.isContentScheme
import io.legado.app.utils.*
import me.ag2s.umdlib.domain.UmdBook
import me.ag2s.umdlib.umd.UmdReader
import splitties.init.appCtx
@ -82,7 +79,7 @@ class UmdFile(var book: Book) {
}
}
} catch (e: Exception) {
e.printStackTrace()
e.printOnDebug()
}
}

@ -137,7 +137,7 @@ class AudioPlayService : BaseService(),
exoPlayer.playWhenReady = true
exoPlayer.prepare()
}.onFailure {
it.printStackTrace()
it.printOnDebug()
toastOnUi("$url ${it.localizedMessage}")
stopSelf()
}
@ -158,7 +158,7 @@ class AudioPlayService : BaseService(),
postEvent(EventBus.AUDIO_STATE, Status.PAUSE)
upNotification()
} catch (e: Exception) {
e.printStackTrace()
e.printOnDebug()
}
}
@ -177,7 +177,7 @@ class AudioPlayService : BaseService(),
postEvent(EventBus.AUDIO_STATE, Status.PLAY)
upNotification()
} catch (e: Exception) {
e.printStackTrace()
e.printOnDebug()
stopSelf()
}
}
@ -246,7 +246,7 @@ class AudioPlayService : BaseService(),
super.onPlayerError(error)
AudioPlay.status = Status.STOP
postEvent(EventBus.AUDIO_STATE, Status.STOP)
error.printStackTrace()
error.printOnDebug()
}
override fun onPlayerErrorChanged(error: PlaybackException?) {

@ -148,7 +148,7 @@ class HttpReadAloudService : BaseReadAloudService(),
playingIndex = nowSpeak
postEvent(EventBus.TTS_PROGRESS, readAloudNumber + 1)
} catch (e: Exception) {
e.printStackTrace()
e.printOnDebug()
}
}
}

@ -86,7 +86,7 @@ class WebService : BaseService() {
upNotification()
} catch (e: IOException) {
toastOnUi(e.localizedMessage ?: "")
e.printStackTrace()
e.printOnDebug()
stopSelf()
}
} else {

@ -7,6 +7,7 @@ import android.service.quicksettings.Tile
import android.service.quicksettings.TileService
import androidx.annotation.RequiresApi
import io.legado.app.constant.IntentAction
import io.legado.app.utils.printOnDebug
import io.legado.app.utils.startService
/**
@ -44,7 +45,7 @@ class WebTileService : TileService() {
}
}
} catch (e: Exception) {
e.printStackTrace()
e.printOnDebug()
}
return super.onStartCommand(intent, flags, startId)
}

@ -0,0 +1,41 @@
package io.legado.app.ui.about
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.FragmentManager
import io.legado.app.R
import io.legado.app.base.BaseDialogFragment
import io.legado.app.utils.windowSize
class AppLogDialog : BaseDialogFragment() {
companion object {
fun show(fragmentManager: FragmentManager) {
AppLogDialog().show(fragmentManager, "appLogDialog")
}
}
override fun onStart() {
super.onStart()
val dm = requireActivity().windowSize
dialog?.window?.setLayout(
(dm.widthPixels * 0.9).toInt(),
ViewGroup.LayoutParams.WRAP_CONTENT
)
}
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
return inflater.inflate(R.layout.dialog_book_group_edit, container)
}
override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) {
}
}

@ -7,10 +7,7 @@ import android.view.View
import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat
import io.legado.app.R
import io.legado.app.utils.ACache
import io.legado.app.utils.longToastOnUi
import io.legado.app.utils.openUrl
import io.legado.app.utils.sendToClip
import io.legado.app.utils.*
class DonateFragment : PreferenceFragmentCompat() {
@ -49,7 +46,7 @@ class DonateFragment : PreferenceFragmentCompat() {
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
context.startActivity(intent)
} catch (e: Exception) {
e.printStackTrace()
e.printOnDebug()
} finally {
ACache.get(requireContext(), cacheDir = false)
.put("proTime", System.currentTimeMillis())

@ -7,6 +7,7 @@ import androidx.lifecycle.MutableLiveData
import io.legado.app.base.BaseViewModel
import io.legado.app.model.localBook.LocalBook
import io.legado.app.utils.isJson
import io.legado.app.utils.printOnDebug
import io.legado.app.utils.readText
import java.io.File
@ -53,7 +54,7 @@ class FileAssociationViewModel(application: Application) : BaseViewModel(applica
onLineImportLive.postValue(uri)
}
}.onError {
it.printStackTrace()
it.printOnDebug()
errorLiveData.postValue(it.localizedMessage)
}
}

@ -117,7 +117,7 @@ class ImportBookSourceViewModel(app: Application) : BaseViewModel(app) {
else -> throw Exception(context.getString(R.string.wrong_format))
}
}.onError {
it.printStackTrace()
it.printOnDebug()
errorLiveData.postValue(it.localizedMessage ?: "")
}.onSuccess {
comparisonSource()

@ -11,7 +11,6 @@ import io.legado.app.R
import io.legado.app.base.VMBaseActivity
import io.legado.app.constant.AppConst
import io.legado.app.constant.AppConst.charsets
import io.legado.app.constant.AppLog
import io.legado.app.constant.EventBus
import io.legado.app.constant.PreferKey
import io.legado.app.data.appDb
@ -26,8 +25,8 @@ import io.legado.app.lib.dialogs.SelectItem
import io.legado.app.lib.dialogs.alert
import io.legado.app.lib.dialogs.selector
import io.legado.app.model.CacheBook
import io.legado.app.ui.about.AppLogDialog
import io.legado.app.ui.document.HandleFileContract
import io.legado.app.ui.widget.dialog.TextListDialog
import io.legado.app.utils.*
import io.legado.app.utils.viewbindingdelegate.viewBinding
import kotlinx.coroutines.Dispatchers
@ -136,8 +135,7 @@ class CacheActivity : VMBaseActivity<ActivityCacheBookBinding, CacheViewModel>()
R.id.menu_export_file_name -> alertExportFileName()
R.id.menu_export_type -> showExportTypeConfig()
R.id.menu_export_charset -> showCharsetConfig()
R.id.menu_log ->
TextListDialog.show(supportFragmentManager, getString(R.string.log), AppLog.logs)
R.id.menu_log -> AppLogDialog.show(supportFragmentManager)
else -> if (item.groupId == R.id.menu_group) {
binding.titleBar.subtitle = item.title
groupId = appDb.bookGroupDao.getByName(item.title.toString())?.groupId ?: 0

@ -56,7 +56,7 @@ class CacheViewModel(application: Application) : BaseViewModel(application) {
}
}.onError {
finally(it.localizedMessage ?: "ERROR")
it.printStackTrace()
it.printOnDebug()
}.onSuccess {
finally(context.getString(R.string.success))
}
@ -187,7 +187,7 @@ class CacheViewModel(application: Application) : BaseViewModel(application) {
}
}.onError {
finally(it.localizedMessage ?: "ERROR")
it.printStackTrace()
it.printOnDebug()
}.onSuccess {
finally(context.getString(R.string.success))
}

@ -17,6 +17,7 @@ import io.legado.app.help.coroutine.CompositeCoroutine
import io.legado.app.model.webBook.WebBook
import io.legado.app.utils.getPrefBoolean
import io.legado.app.utils.getPrefString
import io.legado.app.utils.printOnDebug
import kotlinx.coroutines.*
import kotlinx.coroutines.Dispatchers.IO
import splitties.init.appCtx
@ -184,7 +185,7 @@ class ChangeSourceViewModel(application: Application) : BaseViewModel(applicatio
searchFinish(searchBook)
}
}.onError {
it.printStackTrace()
it.printOnDebug()
}
}
@ -197,7 +198,7 @@ class ChangeSourceViewModel(application: Application) : BaseViewModel(applicatio
searchFinish(searchBook)
}
}.onError {
it.printStackTrace()
it.printOnDebug()
}
}

@ -10,6 +10,7 @@ import io.legado.app.data.entities.BookSource
import io.legado.app.data.entities.SearchBook
import io.legado.app.model.webBook.WebBook
import io.legado.app.utils.msg
import io.legado.app.utils.printOnDebug
import kotlinx.coroutines.Dispatchers.IO
class ExploreShowViewModel(application: Application) : BaseViewModel(application) {
@ -42,7 +43,7 @@ class ExploreShowViewModel(application: Application) : BaseViewModel(application
appDb.searchBookDao.insert(*searchBooks.toTypedArray())
page++
}.onError {
it.printStackTrace()
it.printOnDebug()
errorLiveData.postValue(it.msg)
}
}

@ -149,7 +149,7 @@ class TextActionMenu(private val context: Context, private val callBack: CallBac
}
context.startActivity(intent)
}.onFailure {
it.printStackTrace()
it.printOnDebug()
context.toastOnUi(it.localizedMessage ?: "ERROR")
}
}

@ -282,7 +282,7 @@ class BgTextConfigDialog : BaseDialogFragment() {
}.onSuccess {
toastOnUi("导出成功, 文件名为 $exportFileName")
}.onError {
it.printStackTrace()
it.printOnDebug()
longToast("导出失败:${it.localizedMessage}")
}
}
@ -319,7 +319,7 @@ class BgTextConfigDialog : BaseDialogFragment() {
@Suppress("BlockingMethodInNonBlockingContext")
importConfig(uri.readBytes(requireContext())!!)
}.onError {
it.printStackTrace()
it.printOnDebug()
longToast("导入失败:${it.localizedMessage}")
}
}
@ -333,7 +333,7 @@ class BgTextConfigDialog : BaseDialogFragment() {
postEvent(EventBus.UP_CONFIG, true)
toastOnUi("导入成功")
}.onError {
it.printStackTrace()
it.printOnDebug()
longToast("导入失败:${it.localizedMessage}")
}
}

@ -47,7 +47,7 @@ class BookSourceEditViewModel(application: Application) : BaseViewModel(applicat
success?.invoke()
}.onError {
context.toastOnUi(it.localizedMessage)
it.printStackTrace()
it.printOnDebug()
}
}
@ -61,7 +61,7 @@ class BookSourceEditViewModel(application: Application) : BaseViewModel(applicat
}
}.onError {
context.toastOnUi(it.localizedMessage ?: "Error")
it.printStackTrace()
it.printOnDebug()
}
}

@ -8,6 +8,7 @@ import io.legado.app.base.BaseViewModel
import io.legado.app.help.DirectLinkUpload
import io.legado.app.utils.FileUtils
import io.legado.app.utils.isContentScheme
import io.legado.app.utils.printOnDebug
import io.legado.app.utils.writeBytes
import java.io.File
@ -26,7 +27,7 @@ class HandleFileViewModel(application: Application) : BaseViewModel(application)
}.onSuccess {
success.invoke(it)
}.onError {
it.printStackTrace()
it.printOnDebug()
errorLiveData.postValue(it.localizedMessage)
}
}
@ -46,7 +47,7 @@ class HandleFileViewModel(application: Application) : BaseViewModel(application)
Uri.fromFile(newFile)
}
}.onError {
it.printStackTrace()
it.printOnDebug()
errorLiveData.postValue(it.localizedMessage)
}.onSuccess {
success.invoke(it)

@ -129,7 +129,7 @@ class RuleUiLoginDialog : BaseDialogFragment() {
dismiss()
}
} catch (e: Exception) {
e.printStackTrace()
e.printOnDebug()
toastOnUi("error:${e.localizedMessage}")
}
}

@ -13,6 +13,7 @@ import io.legado.app.help.LocalConfig
import io.legado.app.model.CacheBook
import io.legado.app.model.webBook.WebBook
import io.legado.app.utils.postEvent
import io.legado.app.utils.printOnDebug
import kotlinx.coroutines.asCoroutineDispatcher
import java.util.concurrent.ConcurrentHashMap
import java.util.concurrent.CopyOnWriteArraySet
@ -89,7 +90,7 @@ class MainViewModel(application: Application) : BaseViewModel(application) {
)
CacheBook.start(context, book.bookUrl, book.durChapterIndex, endIndex)
}.onError(upTocPool) {
it.printStackTrace()
it.printOnDebug()
}.onFinally(upTocPool) {
synchronized(this) {
bookMap.remove(bookEntry.key)

@ -9,6 +9,7 @@ import io.legado.app.data.appDb
import io.legado.app.data.entities.RssArticle
import io.legado.app.data.entities.RssSource
import io.legado.app.model.rss.Rss
import io.legado.app.utils.printOnDebug
import io.legado.app.utils.toastOnUi
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
@ -52,7 +53,7 @@ class RssArticlesViewModel(application: Application) : BaseViewModel(application
}
}.onError {
loadFinally.postValue(false)
it.printStackTrace()
it.printOnDebug()
context.toastOnUi(it.localizedMessage)
}
}
@ -68,7 +69,7 @@ class RssArticlesViewModel(application: Application) : BaseViewModel(application
loadMoreSuccess(it.first)
}
.onError {
it.printStackTrace()
it.printOnDebug()
loadFinally.postValue(false)
}
} else {

@ -38,7 +38,7 @@ class RssSourceEditViewModel(application: Application) : BaseViewModel(applicati
success()
}.onError {
context.toastOnUi(it.localizedMessage)
it.printStackTrace()
it.printOnDebug()
}
}

@ -15,6 +15,7 @@ import android.view.Gravity
import android.widget.TextView
import androidx.appcompat.widget.SearchView
import io.legado.app.R
import io.legado.app.utils.printOnDebug
class SearchView @JvmOverloads constructor(
context: Context,
@ -42,7 +43,7 @@ class SearchView @JvmOverloads constructor(
textView!!.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14f)
textView!!.gravity = Gravity.CENTER_VERTICAL
} catch (e: Exception) {
e.printStackTrace()
e.printOnDebug()
}
}

@ -22,6 +22,7 @@ import android.graphics.Canvas
import android.graphics.drawable.BitmapDrawable
import android.view.View
import android.widget.ImageView
import io.legado.app.utils.printOnDebug
import kotlin.math.roundToInt
object Utils {
@ -65,7 +66,7 @@ object Utils {
try {
return Bitmap.createBitmap(width, height, config)
} catch (e: OutOfMemoryError) {
e.printStackTrace()
e.printOnDebug()
if (retryCount > 0) {
System.gc()
return createBitmapSafely(width, height, config, retryCount - 1)

@ -41,7 +41,7 @@ class FontAdapter(context: Context, val callBack: CallBack) :
}
tvFont.typeface = typeface
}.onFailure {
it.printStackTrace()
it.printOnDebug()
context.toastOnUi("Read ${item.name} Error: ${it.localizedMessage}")
}
tvFont.text = item.name

@ -20,6 +20,7 @@ import androidx.annotation.RequiresApi
import androidx.appcompat.widget.AppCompatImageView
import io.legado.app.R
import io.legado.app.utils.getCompatColor
import io.legado.app.utils.printOnDebug
import io.legado.app.utils.sp
import kotlin.math.min
import kotlin.math.pow
@ -316,7 +317,7 @@ class CircleImageView @JvmOverloads constructor(
drawable.draw(canvas)
bitmap
} catch (e: Exception) {
e.printStackTrace()
e.printOnDebug()
null
}

@ -74,7 +74,7 @@ class ACache private constructor(cacheDir: File, max_size: Long, max_count: Int)
}
mCache = ACacheManager(cacheDir, max_size, max_count)
} catch (e: Exception) {
e.printStackTrace()
e.printOnDebug()
}
}
@ -96,7 +96,7 @@ class ACache private constructor(cacheDir: File, max_size: Long, max_count: Int)
file.writeText(value)
mCache.put(file)
} catch (e: Exception) {
e.printStackTrace()
e.printOnDebug()
}
}
}
@ -131,7 +131,7 @@ class ACache private constructor(cacheDir: File, max_size: Long, max_count: Int)
removeFile = true
}
} catch (e: IOException) {
e.printStackTrace()
e.printOnDebug()
} finally {
if (removeFile)
remove(key)
@ -269,7 +269,7 @@ class ACache private constructor(cacheDir: File, max_size: Long, max_count: Int)
null
}
} catch (e: Exception) {
e.printStackTrace()
e.printOnDebug()
} finally {
if (removeFile)
remove(key)
@ -299,7 +299,7 @@ class ACache private constructor(cacheDir: File, max_size: Long, max_count: Int)
}
}
} catch (e: Exception) {
e.printStackTrace()
e.printOnDebug()
}
}
@ -318,18 +318,18 @@ class ACache private constructor(cacheDir: File, max_size: Long, max_count: Int)
ois = ObjectInputStream(bis)
return ois.readObject()
} catch (e: Exception) {
e.printStackTrace()
e.printOnDebug()
} finally {
try {
bis?.close()
} catch (e: IOException) {
e.printStackTrace()
e.printOnDebug()
}
try {
ois?.close()
} catch (e: IOException) {
e.printStackTrace()
e.printOnDebug()
}
}
@ -427,7 +427,7 @@ class ACache private constructor(cacheDir: File, max_size: Long, max_count: Int)
return f
}
} catch (e: Exception) {
e.printStackTrace()
e.printOnDebug()
}
}
return null
@ -488,7 +488,7 @@ class ACache private constructor(cacheDir: File, max_size: Long, max_count: Int)
}
}
} catch (e: Exception) {
e.printStackTrace()
e.printOnDebug()
}
return false
@ -662,7 +662,7 @@ class ACache private constructor(cacheDir: File, max_size: Long, max_count: Int)
cacheCount.set(count)
}
} catch (e: Exception) {
e.printStackTrace()
e.printOnDebug()
}
@ -693,7 +693,7 @@ class ACache private constructor(cacheDir: File, max_size: Long, max_count: Int)
file.setLastModified(currentTime)
lastUsageDates[file] = currentTime
} catch (e: Exception) {
e.printStackTrace()
e.printOnDebug()
}
}
@ -727,7 +727,7 @@ class ACache private constructor(cacheDir: File, max_size: Long, max_count: Int)
}
}
} catch (e: Exception) {
e.printStackTrace()
e.printOnDebug()
}
}
@ -767,7 +767,7 @@ class ACache private constructor(cacheDir: File, max_size: Long, max_count: Int)
}
return fileSize
} catch (e: Exception) {
e.printStackTrace()
e.printOnDebug()
return 0
}

@ -157,7 +157,7 @@ val Context.sysScreenOffTime: Int
screenOffTime =
Settings.System.getInt(contentResolver, Settings.System.SCREEN_OFF_TIMEOUT)
} catch (e: Exception) {
e.printStackTrace()
e.printOnDebug()
}
return screenOffTime
}
@ -299,7 +299,7 @@ val Context.channel: String
val appInfo = pm.getApplicationInfo(packageName, PackageManager.GET_META_DATA)
return appInfo.metaData.getString("channel") ?: ""
} catch (e: Exception) {
e.printStackTrace()
e.printOnDebug()
}
return ""
}

@ -130,7 +130,7 @@ object DocumentUtils {
}
}
} catch (e: Exception) {
e.printStackTrace()
e.printOnDebug()
} finally {
c?.close()
}

@ -50,7 +50,7 @@ object FileUtils {
file.createNewFile()
}
} catch (e: IOException) {
e.printStackTrace()
e.printOnDebug()
}
return file
}
@ -113,7 +113,7 @@ object FileUtils {
try {
sdCardDirectory = File(sdCardDirectory).canonicalPath
} catch (ioe: IOException) {
ioe.printStackTrace()
ioe.printOnDebug()
}
return sdCardDirectory
}

@ -1,6 +1,9 @@
@file:Suppress("unused")
package io.legado.app.utils
import android.annotation.SuppressLint
import io.legado.app.BuildConfig
import splitties.init.appCtx
import java.text.SimpleDateFormat
import java.util.*
@ -8,7 +11,7 @@ import java.util.logging.*
@Suppress("unused")
object LogUtils {
const val TIME_PATTERN = "yyyy-MM-dd HH:mm:ss"
const val TIME_PATTERN = "yy-MM-dd HH:mm:ss.SSS"
@JvmStatic
fun d(tag: String, msg: String) {
@ -65,3 +68,17 @@ object LogUtils {
return sdf.format(date)
}
}
fun Throwable.printOnDebug() {
if (BuildConfig.DEBUG) {
printStackTrace()
}
}
fun dLog(tag: String, msg: String) {
LogUtils.d(tag, msg)
}
fun eLog(tag: String, msg: String) {
LogUtils.e(tag, msg)
}

@ -25,7 +25,7 @@ object MD5Utils {
}
reStr = stringBuffer.toString()
} catch (e: NoSuchAlgorithmException) {
e.printStackTrace()
e.printOnDebug()
}
return reStr

@ -114,7 +114,7 @@ object NetworkUtils {
relativeUrl = parseUrl.toString()
return relativeUrl
} catch (e: Exception) {
e.printStackTrace()
e.printOnDebug()
}
return relativeUrl
}
@ -130,7 +130,7 @@ object NetworkUtils {
relativeUrl = parseUrl.toString()
return relativeUrl
} catch (e: Exception) {
e.printStackTrace()
e.printOnDebug()
}
return relativeUrl
}
@ -158,7 +158,7 @@ object NetworkUtils {
try {
enumeration = NetworkInterface.getNetworkInterfaces()
} catch (e: SocketException) {
e.printStackTrace()
e.printOnDebug()
}
if (enumeration != null) {

@ -111,7 +111,7 @@ object RealPathUtil {
return cursor.getString(index)
}
} catch (e: IllegalArgumentException) {
e.printStackTrace()
e.printOnDebug()
val file = File(context.cacheDir, "tmp")
val filePath = file.absolutePath
var input: FileInputStream? = null
@ -130,7 +130,7 @@ object RealPathUtil {
}
return File(filePath).absolutePath
} catch (ignored: IOException) {
ignored.printStackTrace()
ignored.printOnDebug()
} finally {
input?.close()
output?.close()

@ -95,7 +95,7 @@ object StringUtils {
}
}
}.onFailure {
it.printStackTrace()
it.printOnDebug()
}
return ""

@ -21,7 +21,7 @@ object SystemUtils {
Settings.System.SCREEN_OFF_TIMEOUT
)
}.onFailure {
it.printStackTrace()
it.printOnDebug()
}
return screenOffTime

@ -41,7 +41,7 @@ fun AppCompatActivity.readUri(uri: Uri?, success: (name: String, bytes: ByteArra
.request()
}
} catch (e: Exception) {
e.printStackTrace()
e.printOnDebug()
toastOnUi(e.localizedMessage ?: "read uri error")
}
}
@ -75,7 +75,7 @@ fun Fragment.readUri(uri: Uri?, success: (name: String, bytes: ByteArray) -> Uni
.request()
}
} catch (e: Exception) {
e.printStackTrace()
e.printOnDebug()
toastOnUi(e.localizedMessage ?: "read uri error")
}
}

@ -110,6 +110,6 @@ fun PopupMenu.show(x: Int, y: Int) {
field.isAccessible = true
(field.get(this) as MenuPopupHelper).show(x, y)
}.onFailure {
it.printStackTrace()
it.printOnDebug()
}
}

@ -369,7 +369,7 @@ object ZipUtils {
return try {
file.createNewFile()
} catch (e: IOException) {
e.printStackTrace()
e.printOnDebug()
false
}
}

@ -6,10 +6,7 @@ import fi.iki.elonen.NanoWSD
import io.legado.app.R
import io.legado.app.data.appDb
import io.legado.app.model.Debug
import io.legado.app.utils.GSON
import io.legado.app.utils.fromJsonObject
import io.legado.app.utils.isJson
import io.legado.app.utils.runOnIO
import io.legado.app.utils.*
import kotlinx.coroutines.*
import kotlinx.coroutines.Dispatchers.IO
import splitties.init.appCtx
@ -89,7 +86,7 @@ class SourceDebugWebSocket(handshakeRequest: NanoHTTPD.IHTTPSession) :
close(NanoWSD.WebSocketFrame.CloseCode.NormalClosure, "调试结束", false)
}
}.onFailure {
it.printStackTrace()
it.printOnDebug()
}
}
}

@ -9,6 +9,7 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import me.ag2s.epublib.BuildConfig;
import me.ag2s.epublib.Constants;
import me.ag2s.epublib.domain.EpubBook;
import me.ag2s.epublib.domain.Guide;
@ -51,9 +52,11 @@ public class PackageDocumentWriter extends PackageDocumentBase {
serializer.endDocument();
serializer.flush();
} catch (IOException e) {
if (BuildConfig.DEBUG) {
e.printStackTrace();
}
}
}
/**
* Writes the package's spine.

Loading…
Cancel
Save