diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro index 215f31c33..3733c9bc4 100644 --- a/app/proguard-rules.pro +++ b/app/proguard-rules.pro @@ -54,6 +54,8 @@ # Android开发中一些需要保留的公共部分 # ############################################# +# 屏蔽错误Unresolved class name +#noinspection ShrinkerUnresolvedReference # 保留我们使用的四大组件,自定义的Application等等这些类不被混淆 # 因为这些子类都有可能被外部调用 @@ -66,7 +68,6 @@ -keep public class * extends android.preference.Preference -keep public class * extends android.view.View - # 保留androidx下的所有类及其内部类 -keep class androidx.** {*;} diff --git a/app/src/main/assets/httpTTS.json b/app/src/main/assets/defaultData/httpTTS.json similarity index 100% rename from app/src/main/assets/httpTTS.json rename to app/src/main/assets/defaultData/httpTTS.json diff --git a/app/src/main/assets/readConfig.json b/app/src/main/assets/defaultData/readConfig.json similarity index 100% rename from app/src/main/assets/readConfig.json rename to app/src/main/assets/defaultData/readConfig.json diff --git a/app/src/main/assets/themeConfig.json b/app/src/main/assets/defaultData/themeConfig.json similarity index 100% rename from app/src/main/assets/themeConfig.json rename to app/src/main/assets/defaultData/themeConfig.json diff --git a/app/src/main/assets/txtTocRule.json b/app/src/main/assets/defaultData/txtTocRule.json similarity index 100% rename from app/src/main/assets/txtTocRule.json rename to app/src/main/assets/defaultData/txtTocRule.json diff --git a/app/src/main/assets/number.ttf b/app/src/main/assets/font/number.ttf similarity index 100% rename from app/src/main/assets/number.ttf rename to app/src/main/assets/font/number.ttf diff --git a/app/src/main/assets/help.md b/app/src/main/assets/help/help.md similarity index 100% rename from app/src/main/assets/help.md rename to app/src/main/assets/help/help.md diff --git a/app/src/main/assets/help/httpTts.md b/app/src/main/assets/help/httpTts.md new file mode 100644 index 000000000..f3beb4c6b --- /dev/null +++ b/app/src/main/assets/help/httpTts.md @@ -0,0 +1,15 @@ +# 在线朗读规则说明 + +* 在线朗读规则为url规则,同书源url +* js参数 +~~~ +speakText //朗读文本 +speakSpeed //朗读速度,0-45 +~~~ +* 例: +~~~ +http://tts.baidu.com/text2audio,{ + "method": "POST", + "body": "tex={{java.encodeURI(java.encodeURI(speakText))}}&spd={{String((speakSpeed + 5) / 10 + 4)}}&per=5003&cuid=baidu_speech_demo&idx=1&cod=2&lan=zh&ctp=1&pdt=1&vol=5&pit=5&_res_tag_=audio" +} +~~~ \ No newline at end of file diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index ec5355f22..70e2b98ae 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -3,6 +3,10 @@ * 关注合作公众号 **[小说拾遗]()** 获取好看的小说。 * 旧版数据导入教程:先在旧版阅读(2.x)中进行备份,然后在新版阅读(3.x)【我的】->【备份与恢复】,选择【导入旧版本数据】。 +**2020/10/19** +* 优化分组管理 +* 修复预下载没有保存的bug + **2020/10/18** * 优化分组管理,默认分组可以重命名了 * 修复书架空白的bug,是constraintlayout库新版本的bug diff --git a/app/src/main/java/io/legado/app/base/BaseFragment.kt b/app/src/main/java/io/legado/app/base/BaseFragment.kt index 155bb6076..eb7805029 100644 --- a/app/src/main/java/io/legado/app/base/BaseFragment.kt +++ b/app/src/main/java/io/legado/app/base/BaseFragment.kt @@ -15,6 +15,7 @@ import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Job import kotlin.coroutines.CoroutineContext +@Suppress("MemberVisibilityCanBePrivate") abstract class BaseFragment(layoutID: Int) : Fragment(layoutID), CoroutineScope { lateinit var job: Job diff --git a/app/src/main/java/io/legado/app/base/BaseService.kt b/app/src/main/java/io/legado/app/base/BaseService.kt index f00540526..192737447 100644 --- a/app/src/main/java/io/legado/app/base/BaseService.kt +++ b/app/src/main/java/io/legado/app/base/BaseService.kt @@ -18,7 +18,9 @@ abstract class BaseService : Service(), CoroutineScope by MainScope() { block: suspend CoroutineScope.() -> T ) = Coroutine.async(scope, context) { block() } - override fun onBind(intent: Intent?) = null + override fun onBind(intent: Intent?): IBinder? { + return null + } override fun onDestroy() { super.onDestroy() diff --git a/app/src/main/java/io/legado/app/base/BaseViewModel.kt b/app/src/main/java/io/legado/app/base/BaseViewModel.kt index c8332e0cc..e5432e204 100644 --- a/app/src/main/java/io/legado/app/base/BaseViewModel.kt +++ b/app/src/main/java/io/legado/app/base/BaseViewModel.kt @@ -11,6 +11,7 @@ import org.jetbrains.anko.AnkoLogger import org.jetbrains.anko.toast import kotlin.coroutines.CoroutineContext +@Suppress("unused") open class BaseViewModel(application: Application) : AndroidViewModel(application), CoroutineScope by MainScope(), AnkoLogger { diff --git a/app/src/main/java/io/legado/app/base/adapter/CommonRecyclerAdapter.kt b/app/src/main/java/io/legado/app/base/adapter/CommonRecyclerAdapter.kt index 0ae540837..4fd0fd520 100644 --- a/app/src/main/java/io/legado/app/base/adapter/CommonRecyclerAdapter.kt +++ b/app/src/main/java/io/legado/app/base/adapter/CommonRecyclerAdapter.kt @@ -15,6 +15,7 @@ import java.util.* * * 通用的adapter 可添加header,footer,以及不同类型item */ +@Suppress("unused", "MemberVisibilityCanBePrivate") abstract class CommonRecyclerAdapter(protected val context: Context) : RecyclerView.Adapter() { diff --git a/app/src/main/java/io/legado/app/base/adapter/InfiniteScrollListener.kt b/app/src/main/java/io/legado/app/base/adapter/InfiniteScrollListener.kt index a679f3e08..08f9716f3 100644 --- a/app/src/main/java/io/legado/app/base/adapter/InfiniteScrollListener.kt +++ b/app/src/main/java/io/legado/app/base/adapter/InfiniteScrollListener.kt @@ -8,6 +8,7 @@ import androidx.recyclerview.widget.RecyclerView * * 上拉加载更多 */ +@Suppress("unused") abstract class InfiniteScrollListener() : RecyclerView.OnScrollListener() { private val loadMoreRunnable = Runnable { onLoadMore() } diff --git a/app/src/main/java/io/legado/app/base/adapter/ItemAnimation.kt b/app/src/main/java/io/legado/app/base/adapter/ItemAnimation.kt index e2c37d708..3f70ca3ea 100644 --- a/app/src/main/java/io/legado/app/base/adapter/ItemAnimation.kt +++ b/app/src/main/java/io/legado/app/base/adapter/ItemAnimation.kt @@ -7,6 +7,7 @@ import io.legado.app.base.adapter.animations.* /** * Created by Invincible on 2017/12/15. */ +@Suppress("unused") class ItemAnimation private constructor() { var itemAnimEnabled = false diff --git a/app/src/main/java/io/legado/app/data/AppDatabase.kt b/app/src/main/java/io/legado/app/data/AppDatabase.kt index dc144493b..ab989580e 100644 --- a/app/src/main/java/io/legado/app/data/AppDatabase.kt +++ b/app/src/main/java/io/legado/app/data/AppDatabase.kt @@ -49,12 +49,10 @@ abstract class AppDatabase: RoomDatabase() { private val dbCallback = object : Callback() { override fun onCreate(db: SupportSQLiteDatabase) { - super.onCreate(db) db.setLocale(Locale.CHINESE) } override fun onOpen(db: SupportSQLiteDatabase) { - db.setLocale(Locale.CHINESE) db.execSQL( """ insert into book_groups(groupId, groupName, 'order', show) select ${AppConst.bookGroupAllId}, '全部', -10, 1 diff --git a/app/src/main/java/io/legado/app/data/entities/rule/ContentRule.kt b/app/src/main/java/io/legado/app/data/entities/rule/ContentRule.kt index a3c565652..ab6471dde 100644 --- a/app/src/main/java/io/legado/app/data/entities/rule/ContentRule.kt +++ b/app/src/main/java/io/legado/app/data/entities/rule/ContentRule.kt @@ -10,5 +10,5 @@ data class ContentRule( var webJs: String? = null, var sourceRegex: String? = null, var replaceRegex: String? = null, - var imageStyle: String? = null //默认大小居中,1最大宽度 + var imageStyle: String? = null //默认大小居中,FULL最大宽度 ) : Parcelable \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/help/ActivityHelp.kt b/app/src/main/java/io/legado/app/help/ActivityHelp.kt index 8d07a3500..9c9cb0175 100644 --- a/app/src/main/java/io/legado/app/help/ActivityHelp.kt +++ b/app/src/main/java/io/legado/app/help/ActivityHelp.kt @@ -10,6 +10,7 @@ import java.util.* /** * Activity管理器,管理项目中Activity的状态 */ +@Suppress("unused") object ActivityHelp : Application.ActivityLifecycleCallbacks { private val activities: MutableList> = arrayListOf() diff --git a/app/src/main/java/io/legado/app/help/BlurTransformation.kt b/app/src/main/java/io/legado/app/help/BlurTransformation.kt index 4493228c4..74de12038 100644 --- a/app/src/main/java/io/legado/app/help/BlurTransformation.kt +++ b/app/src/main/java/io/legado/app/help/BlurTransformation.kt @@ -28,7 +28,7 @@ class BlurTransformation(context: Context, private val radius: Int) : CenterCrop //图片缩小1/2 val width = (min(outWidth, transform.width) / 2f).roundToInt() val height = (min(outHeight, transform.height) / 2f).roundToInt() - val blurredBitmap = Bitmap.createScaledBitmap(transform, width, height, false); + val blurredBitmap = Bitmap.createScaledBitmap(transform, width, height, false) // Allocate memory for Renderscript to work with //分配用于渲染脚本的内存 val input = Allocation.createFromBitmap( 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 32d5262ce..4f1a2ba9f 100644 --- a/app/src/main/java/io/legado/app/help/BookHelp.kt +++ b/app/src/main/java/io/legado/app/help/BookHelp.kt @@ -267,8 +267,9 @@ object BookHelp { } } - private val chapterNamePattern = + private val chapterNamePattern by lazy { Pattern.compile("^(.*?第([\\d零〇一二两三四五六七八九十百千万壹贰叁肆伍陆柒捌玖拾佰仟0-9\\s]+)[章节篇回集])[、,。 ::.\\s]*") + } private fun getChapterNum(chapterName: String?): Int { if (chapterName != null) { @@ -280,15 +281,25 @@ object BookHelp { return -1 } - private fun getPureChapterName(chapterName: String?): String { + @Suppress("SpellCheckingInspection") + private val regexOther by lazy { // 所有非字母数字中日韩文字 CJK区+扩展A-F区 + return@lazy "[^\\w\\u4E00-\\u9FEF〇\\u3400-\\u4DBF\\u20000-\\u2A6DF\\u2A700-\\u2EBEF]".toRegex() + } + + private val regexA by lazy { + return@lazy "\\s".toRegex() + } + + private val regexB by lazy { + return@lazy "^第.*?章|[(\\[][^()\\[\\]]{2,}[)\\]]$".toRegex() + } + + private fun getPureChapterName(chapterName: String?): String { return if (chapterName == null) "" else StringUtils.fullToHalf(chapterName) - .replace("\\s".toRegex(), "") - .replace("^第.*?章|[(\\[][^()\\[\\]]{2,}[)\\]]$".toRegex(), "") - .replace( - "[^\\w\\u4E00-\\u9FEF〇\\u3400-\\u4DBF\\u20000-\\u2A6DF\\u2A700-\\u2EBEF]".toRegex(), - "" - ) + .replace(regexA, "") + .replace(regexB, "") + .replace(regexOther, "") } private var bookName: String? = null diff --git a/app/src/main/java/io/legado/app/help/DefaultData.kt b/app/src/main/java/io/legado/app/help/DefaultData.kt new file mode 100644 index 000000000..d1c016b90 --- /dev/null +++ b/app/src/main/java/io/legado/app/help/DefaultData.kt @@ -0,0 +1,47 @@ +package io.legado.app.help + +import io.legado.app.App +import io.legado.app.data.entities.HttpTTS +import io.legado.app.data.entities.TxtTocRule +import io.legado.app.utils.GSON +import io.legado.app.utils.fromJsonArray +import java.io.File + +object DefaultData { + + const val httpTtsFileName = "httpTTS.json" + const val txtTocRuleFileName = "txtTocRule.json" + + val defaultHttpTTS by lazy { + val json = + String( + App.INSTANCE.assets.open("defaultData${File.separator}$httpTtsFileName") + .readBytes() + ) + GSON.fromJsonArray(json)!! + } + + val defaultReadConfigs by lazy { + val json = String( + App.INSTANCE.assets.open("defaultData${File.separator}${ReadBookConfig.configFileName}") + .readBytes() + ) + GSON.fromJsonArray(json)!! + } + + val defaultTxtTocRules by lazy { + val json = String( + App.INSTANCE.assets.open("defaultData${File.separator}$txtTocRuleFileName") + .readBytes() + ) + GSON.fromJsonArray(json)!! + } + + val defaultThemeConfigs by lazy { + val json = String( + App.INSTANCE.assets.open("defaultData${File.separator}${ThemeConfig.configFileName}") + .readBytes() + ) + GSON.fromJsonArray(json)!! + } +} \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/help/DefaultValueHelp.kt b/app/src/main/java/io/legado/app/help/DefaultValueHelp.kt deleted file mode 100644 index 49338e960..000000000 --- a/app/src/main/java/io/legado/app/help/DefaultValueHelp.kt +++ /dev/null @@ -1,19 +0,0 @@ -package io.legado.app.help - -import io.legado.app.App -import io.legado.app.data.entities.HttpTTS -import io.legado.app.utils.GSON -import io.legado.app.utils.fromJsonArray - -object DefaultValueHelp { - - - fun initHttpTTS() { - val json = String(App.INSTANCE.assets.open("httpTTS.json").readBytes()) - GSON.fromJsonArray(json)?.let { - App.db.httpTTSDao().insert(*it.toTypedArray()) - } - } - - -} \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/help/EventMessage.kt b/app/src/main/java/io/legado/app/help/EventMessage.kt index fe9c80994..9e2606ea5 100644 --- a/app/src/main/java/io/legado/app/help/EventMessage.kt +++ b/app/src/main/java/io/legado/app/help/EventMessage.kt @@ -2,8 +2,7 @@ package io.legado.app.help import android.text.TextUtils -import java.util.Arrays - +@Suppress("unused") class EventMessage { var what: Int?=null diff --git a/app/src/main/java/io/legado/app/help/IntentHelp.kt b/app/src/main/java/io/legado/app/help/IntentHelp.kt index d7ed03af1..05b580272 100644 --- a/app/src/main/java/io/legado/app/help/IntentHelp.kt +++ b/app/src/main/java/io/legado/app/help/IntentHelp.kt @@ -7,6 +7,7 @@ import android.os.Bundle import io.legado.app.R import org.jetbrains.anko.toast +@Suppress("unused") object IntentHelp { diff --git a/app/src/main/java/io/legado/app/help/LayoutManager.kt b/app/src/main/java/io/legado/app/help/LayoutManager.kt index e633993c7..79b54bb0c 100644 --- a/app/src/main/java/io/legado/app/help/LayoutManager.kt +++ b/app/src/main/java/io/legado/app/help/LayoutManager.kt @@ -6,6 +6,7 @@ import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.StaggeredGridLayoutManager +@Suppress("unused") object LayoutManager { interface LayoutManagerFactory { 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 94eb04ee5..9ad5a9250 100644 --- a/app/src/main/java/io/legado/app/help/ReadBookConfig.kt +++ b/app/src/main/java/io/legado/app/help/ReadBookConfig.kt @@ -26,10 +26,6 @@ object ReadBookConfig { val shareConfigFilePath = FileUtils.getPath(App.INSTANCE.filesDir, shareConfigFileName) val configList: ArrayList = arrayListOf() lateinit var shareConfig: Config - private val defaultConfigs by lazy { - val json = String(App.INSTANCE.assets.open(configFileName).readBytes()) - GSON.fromJsonArray(json)!! - } var durConfig get() = getConfig(styleSelect) set(value) { @@ -68,7 +64,7 @@ object ReadBookConfig { e.printStackTrace() } } - (configs ?: defaultConfigs).let { + (configs ?: DefaultData.defaultReadConfigs).let { configList.clear() configList.addAll(it) } @@ -131,7 +127,7 @@ object ReadBookConfig { } private fun resetAll() { - defaultConfigs.let { + DefaultData.defaultReadConfigs.let { configList.clear() configList.addAll(it) save() 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 5061d129f..44948e17c 100644 --- a/app/src/main/java/io/legado/app/help/ThemeConfig.kt +++ b/app/src/main/java/io/legado/app/help/ThemeConfig.kt @@ -13,10 +13,7 @@ import java.io.File object ThemeConfig { const val configFileName = "themeConfig.json" val configFilePath = FileUtils.getPath(App.INSTANCE.filesDir, configFileName) - private val defaultConfigs by lazy { - val json = String(App.INSTANCE.assets.open(configFileName).readBytes()) - GSON.fromJsonArray(json)!! - } + val configList = arrayListOf() init { @@ -24,7 +21,7 @@ object ThemeConfig { } fun upConfig() { - (getConfigs() ?: defaultConfigs).let { + (getConfigs() ?: DefaultData.defaultThemeConfigs).let { configList.clear() configList.addAll(it) } diff --git a/app/src/main/java/io/legado/app/help/coroutine/CompositeCoroutine.kt b/app/src/main/java/io/legado/app/help/coroutine/CompositeCoroutine.kt index 1eb1102ba..14c123378 100644 --- a/app/src/main/java/io/legado/app/help/coroutine/CompositeCoroutine.kt +++ b/app/src/main/java/io/legado/app/help/coroutine/CompositeCoroutine.kt @@ -1,5 +1,6 @@ package io.legado.app.help.coroutine +@Suppress("unused") class CompositeCoroutine : CoroutineContainer { private var resources: HashSet>? = 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 0811eee10..a31c9d1e0 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 @@ -5,6 +5,7 @@ import kotlinx.coroutines.* import kotlin.coroutines.CoroutineContext +@Suppress("unused") class Coroutine( val scope: CoroutineScope, context: CoroutineContext = Dispatchers.IO, diff --git a/app/src/main/java/io/legado/app/help/http/CookieStore.kt b/app/src/main/java/io/legado/app/help/http/CookieStore.kt index 067435ddb..2f2bfaaec 100644 --- a/app/src/main/java/io/legado/app/help/http/CookieStore.kt +++ b/app/src/main/java/io/legado/app/help/http/CookieStore.kt @@ -1,3 +1,5 @@ +@file:Suppress("unused") + package io.legado.app.help.http import android.text.TextUtils diff --git a/app/src/main/java/io/legado/app/help/http/HttpHelper.kt b/app/src/main/java/io/legado/app/help/http/HttpHelper.kt index 1d9252164..3728f4819 100644 --- a/app/src/main/java/io/legado/app/help/http/HttpHelper.kt +++ b/app/src/main/java/io/legado/app/help/http/HttpHelper.kt @@ -112,7 +112,7 @@ object HttpHelper { proxy: String? = null ): Retrofit { val r = Regex("(http|socks4|socks5)://(.*):(\\d{2,5})(@.*@.*)?") - val ms = proxy?.let { r.findAll(it) }; + val ms = proxy?.let { r.findAll(it) } val group = ms?.first() var type = "direct" //直接连接 var host = "127.0.0.1" //代理服务器hostname @@ -135,9 +135,9 @@ object HttpHelper { val builder = client.newBuilder() if (type != "direct" && host != "") { if (type == "http") { - builder.proxy(Proxy(Proxy.Type.HTTP, InetSocketAddress(host, port))); + builder.proxy(Proxy(Proxy.Type.HTTP, InetSocketAddress(host, port))) } else { - builder.proxy(Proxy(Proxy.Type.SOCKS, InetSocketAddress(host, port))); + builder.proxy(Proxy(Proxy.Type.SOCKS, InetSocketAddress(host, port))) } if (username != "" && password != "") { builder.proxyAuthenticator { _, response -> //设置代理服务器账号密码 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 800304b62..52a131c71 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 @@ -12,6 +12,7 @@ import java.security.cert.CertificateFactory import java.security.cert.X509Certificate import javax.net.ssl.* +@Suppress("unused") object SSLHelper { /** diff --git a/app/src/main/java/io/legado/app/help/permission/Permissions.kt b/app/src/main/java/io/legado/app/help/permission/Permissions.kt index 236691f7f..978541f69 100644 --- a/app/src/main/java/io/legado/app/help/permission/Permissions.kt +++ b/app/src/main/java/io/legado/app/help/permission/Permissions.kt @@ -1,5 +1,6 @@ package io.legado.app.help.permission +@Suppress("unused") object Permissions { const val READ_CALENDAR = "android.permission.READ_CALENDAR" diff --git a/app/src/main/java/io/legado/app/help/permission/PermissionsCompat.kt b/app/src/main/java/io/legado/app/help/permission/PermissionsCompat.kt index 17104108b..1d118fd0e 100644 --- a/app/src/main/java/io/legado/app/help/permission/PermissionsCompat.kt +++ b/app/src/main/java/io/legado/app/help/permission/PermissionsCompat.kt @@ -5,6 +5,7 @@ import androidx.appcompat.app.AppCompatActivity import androidx.fragment.app.Fragment import java.util.* +@Suppress("unused") class PermissionsCompat private constructor() { private var request: Request? = null @@ -16,11 +17,11 @@ class PermissionsCompat private constructor() { companion object { // 检查权限, 如果已经拥有返回 true fun check(activity: AppCompatActivity, vararg permissions: String): Boolean { - var request = Request(activity) - var pers = ArrayList() + val request = Request(activity) + val pers = ArrayList() pers.addAll(listOf(*permissions)) - var data = request.getDeniedPermissions(pers.toTypedArray()) - return data == null; + val data = request.getDeniedPermissions(pers.toTypedArray()) + return data == null } } diff --git a/app/src/main/java/io/legado/app/help/storage/Backup.kt b/app/src/main/java/io/legado/app/help/storage/Backup.kt index 6e6cb6791..d0ecac945 100644 --- a/app/src/main/java/io/legado/app/help/storage/Backup.kt +++ b/app/src/main/java/io/legado/app/help/storage/Backup.kt @@ -5,6 +5,7 @@ import android.net.Uri import androidx.documentfile.provider.DocumentFile import io.legado.app.App import io.legado.app.constant.PreferKey +import io.legado.app.help.DefaultData import io.legado.app.help.ReadBookConfig import io.legado.app.help.ThemeConfig import io.legado.app.help.coroutine.Coroutine @@ -31,9 +32,9 @@ object Backup { "rssSource.json", "rssStar.json", "replaceRule.json", - "txtTocRule.json", "readRecord.json", - "httpTTS.json", + DefaultData.txtTocRuleFileName, + DefaultData.httpTtsFileName, ReadBookConfig.configFileName, ReadBookConfig.shareConfigFileName, ThemeConfig.configFileName, @@ -62,9 +63,9 @@ object Backup { writeListToJson(App.db.rssSourceDao().all, "rssSource.json", backupPath) writeListToJson(App.db.rssStarDao().all, "rssStar.json", backupPath) writeListToJson(App.db.replaceRuleDao().all, "replaceRule.json", backupPath) - writeListToJson(App.db.txtTocRule().all, "txtTocRule.json", backupPath) writeListToJson(App.db.readRecordDao().all, "readRecord.json", backupPath) - writeListToJson(App.db.httpTTSDao().all, "httpTTS.json", backupPath) + writeListToJson(App.db.txtTocRule().all, DefaultData.txtTocRuleFileName, backupPath) + writeListToJson(App.db.httpTTSDao().all, DefaultData.httpTtsFileName, backupPath) GSON.toJson(ReadBookConfig.configList).let { FileUtils.createFileIfNotExist(backupPath + File.separator + ReadBookConfig.configFileName) .writeText(it) diff --git a/app/src/main/java/io/legado/app/help/storage/ImportOldData.kt b/app/src/main/java/io/legado/app/help/storage/ImportOldData.kt index a1741c845..6648363df 100644 --- a/app/src/main/java/io/legado/app/help/storage/ImportOldData.kt +++ b/app/src/main/java/io/legado/app/help/storage/ImportOldData.kt @@ -100,7 +100,7 @@ object ImportOldData { return bookSources.size } - fun importOldReplaceRule(json: String): Int { + private fun importOldReplaceRule(json: String): Int { val rules = OldReplace.jsonToReplaceRules(json) App.db.replaceRuleDao().insert(*rules.toTypedArray()) return rules.size diff --git a/app/src/main/java/io/legado/app/help/storage/OldRule.kt b/app/src/main/java/io/legado/app/help/storage/OldRule.kt index 83084d5f3..616d0d359 100644 --- a/app/src/main/java/io/legado/app/help/storage/OldRule.kt +++ b/app/src/main/java/io/legado/app/help/storage/OldRule.kt @@ -9,6 +9,7 @@ import io.legado.app.help.storage.Restore.jsonPath import io.legado.app.utils.* import java.util.regex.Pattern +@Suppress("RegExpRedundantEscape") object OldRule { private val headerPattern = Pattern.compile("@Header:\\{.+?\\}", Pattern.CASE_INSENSITIVE) private val jsPattern = Pattern.compile("\\{\\{.+?\\}\\}", Pattern.CASE_INSENSITIVE) 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 174367557..3d376ade4 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 @@ -13,10 +13,7 @@ import io.legado.app.R import io.legado.app.constant.EventBus import io.legado.app.constant.PreferKey import io.legado.app.data.entities.* -import io.legado.app.help.AppConfig -import io.legado.app.help.LauncherIconHelp -import io.legado.app.help.ReadBookConfig -import io.legado.app.help.ThemeConfig +import io.legado.app.help.* import io.legado.app.service.help.ReadBook import io.legado.app.ui.book.read.page.provider.ChapterProvider import io.legado.app.utils.* @@ -81,7 +78,7 @@ object Restore { for (fileName in Backup.backupFileNames) { if (doc.name == fileName) { DocumentUtils.readText(context, doc.uri)?.let { - FileUtils.createFileIfNotExist(Backup.backupPath + File.separator + fileName) + FileUtils.createFileIfNotExist("${Backup.backupPath}${File.separator}$fileName") .writeText(it) } } @@ -94,7 +91,7 @@ object Restore { FileUtils.getFile(file, fileName).let { if (it.exists()) { it.copyTo( - FileUtils.createFileIfNotExist(Backup.backupPath + File.separator + fileName), + FileUtils.createFileIfNotExist("${Backup.backupPath}${File.separator}$fileName"), true ) } @@ -132,9 +129,12 @@ object Restore { fileToListT(path, "replaceRule.json")?.let { App.db.replaceRuleDao().insert(*it.toTypedArray()) } - fileToListT(path, "txtTocRule.json")?.let { + fileToListT(path, DefaultData.txtTocRuleFileName)?.let { App.db.txtTocRule().insert(*it.toTypedArray()) } + fileToListT(path, DefaultData.httpTtsFileName)?.let { + App.db.httpTTSDao().insert(*it.toTypedArray()) + } fileToListT(path, "readRecord.json")?.let { it.forEach { readRecord -> //判断是不是本机记录 @@ -149,9 +149,6 @@ object Restore { } } } - fileToListT(path, "httpTTS.json")?.let { - App.db.httpTTSDao().insert(*it.toTypedArray()) - } } } @@ -159,7 +156,7 @@ object Restore { withContext(IO) { try { val file = - FileUtils.createFileIfNotExist(path + File.separator + ThemeConfig.configFileName) + FileUtils.createFileIfNotExist("$path${File.separator}${ThemeConfig.configFileName}") if (file.exists()) { FileUtils.deleteFile(ThemeConfig.configFilePath) file.copyTo(File(ThemeConfig.configFilePath)) @@ -171,7 +168,7 @@ object Restore { if (!ignoreReadConfig) { try { val file = - FileUtils.createFileIfNotExist(path + File.separator + ReadBookConfig.configFileName) + FileUtils.createFileIfNotExist("$path${File.separator}${ReadBookConfig.configFileName}") if (file.exists()) { FileUtils.deleteFile(ReadBookConfig.configFilePath) file.copyTo(File(ReadBookConfig.configFilePath)) @@ -182,7 +179,7 @@ object Restore { } try { val file = - FileUtils.createFileIfNotExist(path + File.separator + ReadBookConfig.shareConfigFileName) + FileUtils.createFileIfNotExist("$path${File.separator}${ReadBookConfig.shareConfigFileName}") if (file.exists()) { FileUtils.deleteFile(ReadBookConfig.shareConfigFilePath) file.copyTo(File(ReadBookConfig.shareConfigFilePath)) diff --git a/app/src/main/java/io/legado/app/lib/theme/ATH.kt b/app/src/main/java/io/legado/app/lib/theme/ATH.kt index f69c5d40a..a7a3bd6d7 100644 --- a/app/src/main/java/io/legado/app/lib/theme/ATH.kt +++ b/app/src/main/java/io/legado/app/lib/theme/ATH.kt @@ -30,6 +30,7 @@ import org.jetbrains.anko.backgroundColor /** * @author Karim Abou Zeid (kabouzeid) */ +@Suppress("unused", "MemberVisibilityCanBePrivate") object ATH { @SuppressLint("CommitPrefEdits") diff --git a/app/src/main/java/io/legado/app/lib/theme/DrawableUtils.kt b/app/src/main/java/io/legado/app/lib/theme/DrawableUtils.kt index 660448088..d1bf3c499 100644 --- a/app/src/main/java/io/legado/app/lib/theme/DrawableUtils.kt +++ b/app/src/main/java/io/legado/app/lib/theme/DrawableUtils.kt @@ -11,6 +11,7 @@ import androidx.core.graphics.drawable.DrawableCompat /** * @author Karim Abou Zeid (kabouzeid) */ +@Suppress("unused") object DrawableUtils { fun createTransitionDrawable(@ColorInt startColor: Int, @ColorInt endColor: Int): TransitionDrawable { diff --git a/app/src/main/java/io/legado/app/lib/theme/MaterialValueHelper.kt b/app/src/main/java/io/legado/app/lib/theme/MaterialValueHelper.kt index 018e3dd60..5dadc5d85 100644 --- a/app/src/main/java/io/legado/app/lib/theme/MaterialValueHelper.kt +++ b/app/src/main/java/io/legado/app/lib/theme/MaterialValueHelper.kt @@ -1,3 +1,5 @@ +@file:Suppress("unused") + package io.legado.app.lib.theme import android.annotation.SuppressLint diff --git a/app/src/main/java/io/legado/app/lib/theme/NavigationViewUtils.kt b/app/src/main/java/io/legado/app/lib/theme/NavigationViewUtils.kt index c199ba855..28def35f1 100644 --- a/app/src/main/java/io/legado/app/lib/theme/NavigationViewUtils.kt +++ b/app/src/main/java/io/legado/app/lib/theme/NavigationViewUtils.kt @@ -8,6 +8,7 @@ import com.google.android.material.navigation.NavigationView /** * @author Karim Abou Zeid (kabouzeid) */ +@Suppress("unused") object NavigationViewUtils { fun setItemIconColors(navigationView: NavigationView, @ColorInt normalColor: Int, @ColorInt selectedColor: Int) { diff --git a/app/src/main/java/io/legado/app/lib/theme/Selector.kt b/app/src/main/java/io/legado/app/lib/theme/Selector.kt index 89a71198b..f98508b62 100644 --- a/app/src/main/java/io/legado/app/lib/theme/Selector.kt +++ b/app/src/main/java/io/legado/app/lib/theme/Selector.kt @@ -13,6 +13,7 @@ import androidx.annotation.DrawableRes import androidx.annotation.IntDef import androidx.core.content.ContextCompat +@Suppress("unused") object Selector { fun shapeBuild(): ShapeSelector { return ShapeSelector() @@ -260,7 +261,8 @@ object Selector { * @author hjy * created at 2017/12/11 22:34 */ - class DrawableSelector constructor() { + @Suppress("MemberVisibilityCanBePrivate") + class DrawableSelector { private var mDefaultDrawable: Drawable? = null private var mDisabledDrawable: Drawable? = null @@ -355,7 +357,7 @@ object Selector { * @author hjy * created at 2017/12/11 22:26 */ - class ColorSelector constructor() { + class ColorSelector { private var mDefaultColor: Int = 0 private var mDisabledColor: Int = 0 diff --git a/app/src/main/java/io/legado/app/lib/theme/ThemeStore.kt b/app/src/main/java/io/legado/app/lib/theme/ThemeStore.kt index 92ce315ed..182db2d40 100644 --- a/app/src/main/java/io/legado/app/lib/theme/ThemeStore.kt +++ b/app/src/main/java/io/legado/app/lib/theme/ThemeStore.kt @@ -16,6 +16,7 @@ import io.legado.app.utils.ColorUtils /** * @author Aidan Follestad (afollestad), Karim Abou Zeid (kabouzeid) */ +@Suppress("unused") class ThemeStore @SuppressLint("CommitPrefEdits") private constructor(private val mContext: Context) : ThemeStoreInterface { private val mEditor: SharedPreferences.Editor diff --git a/app/src/main/java/io/legado/app/lib/theme/TintHelper.kt b/app/src/main/java/io/legado/app/lib/theme/TintHelper.kt index 76313cd46..a719cc1b1 100644 --- a/app/src/main/java/io/legado/app/lib/theme/TintHelper.kt +++ b/app/src/main/java/io/legado/app/lib/theme/TintHelper.kt @@ -23,6 +23,7 @@ import io.legado.app.utils.ColorUtils /** * @author afollestad, plusCubed */ +@Suppress("MemberVisibilityCanBePrivate") object TintHelper { @SuppressLint("PrivateResource") @@ -37,7 +38,10 @@ object TintHelper { ) } - private fun getDisabledColorStateList(@ColorInt normal: Int, @ColorInt disabled: Int): ColorStateList { + private fun getDisabledColorStateList( + @ColorInt normal: Int, + @ColorInt disabled: Int + ): ColorStateList { return ColorStateList( arrayOf( intArrayOf(-android.R.attr.state_enabled), @@ -61,48 +65,52 @@ object TintHelper { ) val sl: ColorStateList - if (view is Button) { - sl = getDisabledColorStateList(color, disabled) - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && view.getBackground() is RippleDrawable) { - val rd = view.getBackground() as RippleDrawable - rd.setColor(ColorStateList.valueOf(rippleColor)) - } + when (view) { + is Button -> { + sl = getDisabledColorStateList(color, disabled) + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && view.getBackground() is RippleDrawable) { + val rd = view.getBackground() as RippleDrawable + rd.setColor(ColorStateList.valueOf(rippleColor)) + } - // Disabled text color state for buttons, may get overridden later by ATE tags - view.setTextColor( - getDisabledColorStateList( - textColor, - ContextCompat.getColor( - view.getContext(), - if (useDarkTheme) R.color.ate_button_text_disabled_dark else R.color.ate_button_text_disabled_light + // Disabled text color state for buttons, may get overridden later by ATE tags + view.setTextColor( + getDisabledColorStateList( + textColor, + ContextCompat.getColor( + view.getContext(), + if (useDarkTheme) R.color.ate_button_text_disabled_dark else R.color.ate_button_text_disabled_light + ) ) ) - ) - } else if (view is FloatingActionButton) { - // FloatingActionButton doesn't support disabled state? - sl = ColorStateList( - arrayOf( - intArrayOf(-android.R.attr.state_pressed), - intArrayOf(android.R.attr.state_pressed) - ), intArrayOf(color, pressed) - ) + } + is FloatingActionButton -> { + // FloatingActionButton doesn't support disabled state? + sl = ColorStateList( + arrayOf( + intArrayOf(-android.R.attr.state_pressed), + intArrayOf(android.R.attr.state_pressed) + ), intArrayOf(color, pressed) + ) - view.rippleColor = rippleColor - view.backgroundTintList = sl - if (view.drawable != null) - view.setImageDrawable(createTintedDrawable(view.drawable, textColor)) - return - } else { - sl = ColorStateList( - arrayOf( - intArrayOf(-android.R.attr.state_enabled), - intArrayOf(android.R.attr.state_enabled), - intArrayOf(android.R.attr.state_enabled, android.R.attr.state_pressed), - intArrayOf(android.R.attr.state_enabled, android.R.attr.state_activated), - intArrayOf(android.R.attr.state_enabled, android.R.attr.state_checked) - ), - intArrayOf(disabled, color, pressed, activated, activated) - ) + view.rippleColor = rippleColor + view.backgroundTintList = sl + if (view.drawable != null) + view.setImageDrawable(createTintedDrawable(view.drawable, textColor)) + return + } + else -> { + sl = ColorStateList( + arrayOf( + intArrayOf(-android.R.attr.state_enabled), + intArrayOf(android.R.attr.state_enabled), + intArrayOf(android.R.attr.state_enabled, android.R.attr.state_pressed), + intArrayOf(android.R.attr.state_enabled, android.R.attr.state_activated), + intArrayOf(android.R.attr.state_enabled, android.R.attr.state_checked) + ), + intArrayOf(disabled, color, pressed, activated, activated) + ) + } } var drawable: Drawable? = view.background @@ -386,7 +394,11 @@ object TintHelper { return createTintedDrawable(from, sl) } - fun setTint(switchView: Switch, @ColorInt color: Int, useDarker: Boolean) { + fun setTint( + @SuppressLint("UseSwitchCompatOrMaterialCode") switchView: Switch, + @ColorInt color: Int, + useDarker: Boolean + ) { if (switchView.trackDrawable != null) { switchView.trackDrawable = modifySwitchDrawable( switchView.context, diff --git a/app/src/main/java/io/legado/app/lib/theme/ViewUtils.kt b/app/src/main/java/io/legado/app/lib/theme/ViewUtils.kt index f3afa243c..bcbb794a1 100644 --- a/app/src/main/java/io/legado/app/lib/theme/ViewUtils.kt +++ b/app/src/main/java/io/legado/app/lib/theme/ViewUtils.kt @@ -10,6 +10,7 @@ import androidx.annotation.ColorInt /** * @author Karim Abou Zeid (kabouzeid) */ +@Suppress("unused") object ViewUtils { fun removeOnGlobalLayoutListener(v: View, listener: ViewTreeObserver.OnGlobalLayoutListener) { 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 03fc0d974..ab4f3303c 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 @@ -14,6 +14,7 @@ import java.net.URL import java.net.URLEncoder import java.util.* +@Suppress("unused") class WebDav(urlStr: String) { companion object { // 指定返回哪些属性 @@ -60,9 +61,9 @@ class WebDav(urlStr: String) { return field } - fun getPath() = url.toString() + val path get() = url.toString() - fun getHost() = url.host + val host: String? get() = url.host /** * 填充文件信息。实例化WebDAVFile对象时,并没有将远程文件的信息填充到实例中。需要手动填充! 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 e4c2829e8..85b4e1649 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 @@ -8,6 +8,7 @@ import io.legado.app.utils.splitNotBlank import java.util.* import java.util.regex.Pattern +@Suppress("RegExpRedundantEscape") @Keep class AnalyzeByJSonPath { private lateinit var ctx: ReadContext diff --git a/app/src/main/java/io/legado/app/model/localBook/AnalyzeTxtFile.kt b/app/src/main/java/io/legado/app/model/localBook/AnalyzeTxtFile.kt index 6dfa74594..77689d8a5 100644 --- a/app/src/main/java/io/legado/app/model/localBook/AnalyzeTxtFile.kt +++ b/app/src/main/java/io/legado/app/model/localBook/AnalyzeTxtFile.kt @@ -5,6 +5,7 @@ import io.legado.app.App import io.legado.app.data.entities.Book import io.legado.app.data.entities.BookChapter import io.legado.app.data.entities.TxtTocRule +import io.legado.app.help.DefaultData import io.legado.app.utils.* import java.io.File import java.io.RandomAccessFile @@ -281,24 +282,17 @@ class AnalyzeTxtFile { } private fun getTocRules(): List { - val rules = App.db.txtTocRule().enabled + var rules = App.db.txtTocRule().enabled if (rules.isEmpty()) { - return getDefaultEnabledRules() + rules = DefaultData.defaultTxtTocRules.apply { + App.db.txtTocRule().insert(*this.toTypedArray()) + }.filter { + it.enable + } } return rules } - fun getDefaultEnabledRules(): List { - App.INSTANCE.assets.open("txtTocRule.json").readBytes().let { byteArray -> - GSON.fromJsonArray(String(byteArray))?.let { txtTocRules -> - App.db.txtTocRule().insert(*txtTocRules.toTypedArray()) - return txtTocRules.filter { - it.enable - } - } - } - return emptyList() - } } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/model/rss/RssParserDefault.kt b/app/src/main/java/io/legado/app/model/rss/RssParserDefault.kt index 2a02c2bdc..2cb3d6c17 100644 --- a/app/src/main/java/io/legado/app/model/rss/RssParserDefault.kt +++ b/app/src/main/java/io/legado/app/model/rss/RssParserDefault.kt @@ -8,6 +8,7 @@ import org.xmlpull.v1.XmlPullParserFactory import java.io.IOException import java.io.StringReader +@Suppress("unused") object RssParserDefault { @Throws(XmlPullParserException::class, IOException::class) diff --git a/app/src/main/java/io/legado/app/receiver/TimeBatteryReceiver.kt b/app/src/main/java/io/legado/app/receiver/TimeBatteryReceiver.kt index ce2e04fbe..73737aa79 100644 --- a/app/src/main/java/io/legado/app/receiver/TimeBatteryReceiver.kt +++ b/app/src/main/java/io/legado/app/receiver/TimeBatteryReceiver.kt @@ -25,15 +25,13 @@ class TimeBatteryReceiver : BroadcastReceiver() { } override fun onReceive(context: Context?, intent: Intent?) { - intent?.action?.let { - when (it) { - Intent.ACTION_TIME_TICK -> { - postEvent(EventBus.TIME_CHANGED, "") - } - Intent.ACTION_BATTERY_CHANGED -> { - val level = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1) - postEvent(EventBus.BATTERY_CHANGED, level) - } + when (intent?.action) { + Intent.ACTION_TIME_TICK -> { + postEvent(EventBus.TIME_CHANGED, "") + } + Intent.ACTION_BATTERY_CHANGED -> { + val level = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1) + postEvent(EventBus.BATTERY_CHANGED, level) } } } diff --git a/app/src/main/java/io/legado/app/service/help/CacheBook.kt b/app/src/main/java/io/legado/app/service/help/CacheBook.kt index 18b68b332..3e96bd616 100644 --- a/app/src/main/java/io/legado/app/service/help/CacheBook.kt +++ b/app/src/main/java/io/legado/app/service/help/CacheBook.kt @@ -77,23 +77,16 @@ object CacheBook { downloadMap[book.bookUrl]?.add(chapter.index) webBook.getContent(book, chapter) .onSuccess(IO) { content -> + if (content.isNotBlank()) { + BookHelp.saveContent(book, chapter, content) + } if (ReadBook.book?.bookUrl == book.bookUrl) { - if (content.isEmpty()) { - ReadBook.contentLoadFinish( - book, - chapter, - App.INSTANCE.getString(R.string.content_empty), - resetPageOffset = resetPageOffset - ) - } else { - BookHelp.saveContent(book, chapter, content) - ReadBook.contentLoadFinish( - book, - chapter, - content, - resetPageOffset = resetPageOffset - ) - } + ReadBook.contentLoadFinish( + book, + chapter, + content.ifBlank { App.INSTANCE.getString(R.string.content_empty) }, + resetPageOffset = resetPageOffset + ) } }.onError { if (ReadBook.book?.bookUrl == book.bookUrl) { diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/SpeakEngineDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/SpeakEngineDialog.kt index 6ee1d5bda..f909bc727 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/SpeakEngineDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/SpeakEngineDialog.kt @@ -24,11 +24,13 @@ import io.legado.app.lib.dialogs.customView import io.legado.app.lib.dialogs.okButton import io.legado.app.lib.theme.primaryColor import io.legado.app.service.help.ReadAloud +import io.legado.app.ui.widget.dialog.TextDialog import io.legado.app.utils.* import kotlinx.android.synthetic.main.dialog_http_tts_edit.view.* import kotlinx.android.synthetic.main.dialog_recycler_view.* import kotlinx.android.synthetic.main.item_http_tts.view.* import org.jetbrains.anko.sdk27.listeners.onClick +import java.io.File class SpeakEngineDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener { @@ -126,6 +128,12 @@ class SpeakEngineDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener ReadAloud.upReadAloudClass() } } + neutralButton(R.string.help) { + val helpStr = String( + requireContext().assets.open("help${File.separator}httpTts.md").readBytes() + ) + TextDialog.show(childFragmentManager, helpStr, TextDialog.MD) + } }.show().applyTint() } diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/SpeakEngineViewModel.kt b/app/src/main/java/io/legado/app/ui/book/read/config/SpeakEngineViewModel.kt index 490eb6efd..bc30c346b 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/SpeakEngineViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/SpeakEngineViewModel.kt @@ -3,8 +3,8 @@ package io.legado.app.ui.book.read.config import android.app.Application import io.legado.app.App import io.legado.app.base.BaseViewModel -import io.legado.app.data.entities.TxtTocRule -import io.legado.app.help.DefaultValueHelp +import io.legado.app.data.entities.HttpTTS +import io.legado.app.help.DefaultData import io.legado.app.help.http.HttpHelper import io.legado.app.utils.GSON import io.legado.app.utils.fromJsonArray @@ -13,15 +13,17 @@ class SpeakEngineViewModel(application: Application) : BaseViewModel(application fun importDefault() { execute { - DefaultValueHelp.initHttpTTS() + DefaultData.defaultHttpTTS.let { + App.db.httpTTSDao().insert(*it.toTypedArray()) + } } } fun importOnLine(url: String, finally: (msg: String) -> Unit) { execute { HttpHelper.simpleGetAsync(url)?.let { json -> - GSON.fromJsonArray(json)?.let { - App.db.txtTocRule().insert(*it.toTypedArray()) + GSON.fromJsonArray(json)?.let { + App.db.httpTTSDao().insert(*it.toTypedArray()) } } }.onSuccess { diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/TocRegexViewModel.kt b/app/src/main/java/io/legado/app/ui/book/read/config/TocRegexViewModel.kt index 140a781e4..cebc521b8 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/TocRegexViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/TocRegexViewModel.kt @@ -4,8 +4,8 @@ import android.app.Application import io.legado.app.App import io.legado.app.base.BaseViewModel import io.legado.app.data.entities.TxtTocRule +import io.legado.app.help.DefaultData import io.legado.app.help.http.HttpHelper -import io.legado.app.model.localBook.AnalyzeTxtFile import io.legado.app.utils.GSON import io.legado.app.utils.fromJsonArray @@ -23,7 +23,9 @@ class TocRegexViewModel(application: Application) : BaseViewModel(application) { fun importDefault() { execute { App.db.txtTocRule().deleteDefault() - AnalyzeTxtFile.getDefaultEnabledRules() + DefaultData.defaultTxtTocRules.let { + App.db.txtTocRule().insert(*it.toTypedArray()) + } } } diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextLine.kt b/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextLine.kt index 9457bff37..7610ad9d3 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextLine.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextLine.kt @@ -4,6 +4,7 @@ import android.text.TextPaint import io.legado.app.ui.book.read.page.provider.ChapterProvider import io.legado.app.ui.book.read.page.provider.ChapterProvider.textHeight +@Suppress("unused") data class TextLine( var text: String = "", val textChars: ArrayList = arrayListOf(), diff --git a/app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt b/app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt index 179b2cd9b..7d5b1858a 100644 --- a/app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt @@ -144,7 +144,7 @@ class SearchViewModel(application: Application) : BaseViewModel(application), } } if (!scope.isActive) return - searchBooks.sortWith(Comparator { o1, o2 -> + searchBooks.sortWith { o1, o2 -> if (o1.name == searchKey && o2.name != searchKey) { 1 } else if (o1.name != searchKey && o2.name == searchKey) { @@ -168,7 +168,7 @@ class SearchViewModel(application: Application) : BaseViewModel(application), } else { 0 } - }) + } if (!scope.isActive) return searchBooks = copyDataS upAdapter() diff --git a/app/src/main/java/io/legado/app/ui/book/toc/ChapterListActivity.kt b/app/src/main/java/io/legado/app/ui/book/toc/ChapterListActivity.kt index b595bacbe..150619ce6 100644 --- a/app/src/main/java/io/legado/app/ui/book/toc/ChapterListActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/toc/ChapterListActivity.kt @@ -65,7 +65,7 @@ class ChapterListActivity : VMBaseActivity(R.layout.activi return super.onCompatCreateOptionsMenu(menu) } - private inner class TabFragmentPageAdapter internal constructor(fm: FragmentManager) : + private inner class TabFragmentPageAdapter(fm: FragmentManager) : FragmentPagerAdapter(fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT) { override fun getItem(position: Int): Fragment { return when (position) { diff --git a/app/src/main/java/io/legado/app/ui/filechooser/adapter/FileAdapter.kt b/app/src/main/java/io/legado/app/ui/filechooser/adapter/FileAdapter.kt index 4458b692e..12c45477a 100644 --- a/app/src/main/java/io/legado/app/ui/filechooser/adapter/FileAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/filechooser/adapter/FileAdapter.kt @@ -23,10 +23,10 @@ class FileAdapter(context: Context, val callBack: CallBack) : private var rootPath: String? = null var currentPath: String? = null private set - private val homeIcon = ConvertUtils.toDrawable(FilePickerIcon.getHOME()) - private val upIcon = ConvertUtils.toDrawable(FilePickerIcon.getUPDIR()) - private val folderIcon = ConvertUtils.toDrawable(FilePickerIcon.getFOLDER()) - private val fileIcon = ConvertUtils.toDrawable(FilePickerIcon.getFILE()) + private val homeIcon = ConvertUtils.toDrawable(FilePickerIcon.getHome()) + private val upIcon = ConvertUtils.toDrawable(FilePickerIcon.getUpDir()) + private val folderIcon = ConvertUtils.toDrawable(FilePickerIcon.getFolder()) + private val fileIcon = ConvertUtils.toDrawable(FilePickerIcon.getFile()) private val primaryTextColor = context.getPrimaryTextColor(!AppConfig.isNightTheme) private val disabledTextColor = context.getPrimaryDisabledTextColor(!AppConfig.isNightTheme) diff --git a/app/src/main/java/io/legado/app/ui/filechooser/adapter/PathAdapter.kt b/app/src/main/java/io/legado/app/ui/filechooser/adapter/PathAdapter.kt index 86ccf67c0..9d8cf6fab 100644 --- a/app/src/main/java/io/legado/app/ui/filechooser/adapter/PathAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/filechooser/adapter/PathAdapter.kt @@ -17,7 +17,7 @@ class PathAdapter(context: Context, val callBack: CallBack) : private val paths = LinkedList() @Suppress("DEPRECATION") private val sdCardDirectory = Environment.getExternalStorageDirectory().absolutePath - private val arrowIcon = ConvertUtils.toDrawable(FilePickerIcon.getARROW()) + private val arrowIcon = ConvertUtils.toDrawable(FilePickerIcon.getArrow()) fun getPath(position: Int): String { val tmp = StringBuilder("$sdCardDirectory/") diff --git a/app/src/main/java/io/legado/app/ui/filechooser/utils/FilePickerIcon.java b/app/src/main/java/io/legado/app/ui/filechooser/utils/FilePickerIcon.java index 6732626e4..c53ab6631 100644 --- a/app/src/main/java/io/legado/app/ui/filechooser/utils/FilePickerIcon.java +++ b/app/src/main/java/io/legado/app/ui/filechooser/utils/FilePickerIcon.java @@ -8,23 +8,23 @@ package io.legado.app.ui.filechooser.utils; */ public class FilePickerIcon { - public static byte[] getFILE() { + public static byte[] getFile() { return FILE; } - public static byte[] getFOLDER() { + public static byte[] getFolder() { return FOLDER; } - public static byte[] getHOME() { + public static byte[] getHome() { return HOME; } - public static byte[] getUPDIR() { + public static byte[] getUpDir() { return UPDIR; } - public static byte[] getARROW() { + public static byte[] getArrow() { return ARROW; } 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 8f45c4a9c..904df39e4 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 @@ -9,7 +9,7 @@ import io.legado.app.data.entities.Book import io.legado.app.data.entities.RssSource import io.legado.app.help.AppConfig import io.legado.app.help.BookHelp -import io.legado.app.help.DefaultValueHelp +import io.legado.app.help.DefaultData import io.legado.app.help.http.HttpHelper import io.legado.app.help.storage.Restore import io.legado.app.model.webBook.WebBook @@ -162,7 +162,9 @@ class MainViewModel(application: Application) : BaseViewModel(application) { execute { FileUtils.deleteFile(FileUtils.getPath(context.cacheDir, "Fonts")) if (App.db.httpTTSDao().count == 0) { - DefaultValueHelp.initHttpTTS() + DefaultData.defaultHttpTTS.let { + App.db.httpTTSDao().insert(*it.toTypedArray()) + } } } } diff --git a/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt b/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt index 20b36c065..e8eddefae 100644 --- a/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt @@ -54,7 +54,7 @@ class MyFragment : BaseFragment(R.layout.fragment_my_config), FileChooserDialog. override fun onCompatOptionsItemSelected(item: MenuItem) { when (item.itemId) { R.id.menu_help -> { - val text = String(requireContext().assets.open("help.md").readBytes()) + val text = String(requireContext().assets.open("help/help.md").readBytes()) TextDialog.show(childFragmentManager, text, TextDialog.MD) } } diff --git a/app/src/main/java/io/legado/app/ui/welcome/WelcomeActivity.kt b/app/src/main/java/io/legado/app/ui/welcome/WelcomeActivity.kt index 4b6d4a159..c22b8ec13 100644 --- a/app/src/main/java/io/legado/app/ui/welcome/WelcomeActivity.kt +++ b/app/src/main/java/io/legado/app/ui/welcome/WelcomeActivity.kt @@ -32,7 +32,7 @@ open class WelcomeActivity : BaseActivity(R.layout.activity_welcome) { private fun init() { Coroutine.async { - //清楚过期数据 + //清除过期数据 App.db.searchBookDao() .clearExpired(System.currentTimeMillis() - TimeUnit.DAYS.toMillis(1)) //初始化简繁转换引擎 diff --git a/app/src/main/java/io/legado/app/ui/widget/BatteryView.kt b/app/src/main/java/io/legado/app/ui/widget/BatteryView.kt index 3141c5a86..1711a650e 100644 --- a/app/src/main/java/io/legado/app/ui/widget/BatteryView.kt +++ b/app/src/main/java/io/legado/app/ui/widget/BatteryView.kt @@ -10,6 +10,7 @@ import android.util.AttributeSet import androidx.annotation.ColorInt import androidx.appcompat.widget.AppCompatTextView import io.legado.app.utils.dp +import java.io.File class BatteryView(context: Context, attrs: AttributeSet?) : AppCompatTextView(context, attrs) { private val batteryPaint = Paint() @@ -22,7 +23,7 @@ class BatteryView(context: Context, attrs: AttributeSet?) : AppCompatTextView(co batteryPaint.strokeWidth = 1.dp.toFloat() batteryPaint.isAntiAlias = true batteryPaint.color = paint.color - typeface = Typeface.createFromAsset(context.assets, "number.ttf") + typeface = Typeface.createFromAsset(context.assets, "font${File.separator}number.ttf") } fun setColor(@ColorInt color: Int) { diff --git a/app/src/main/java/io/legado/app/utils/StringExtensions.kt b/app/src/main/java/io/legado/app/utils/StringExtensions.kt index dc53b7bc8..a5c0d365d 100644 --- a/app/src/main/java/io/legado/app/utils/StringExtensions.kt +++ b/app/src/main/java/io/legado/app/utils/StringExtensions.kt @@ -1,3 +1,5 @@ +@file:Suppress("unused") + package io.legado.app.utils import android.net.Uri