diff --git a/app/src/main/assets/help.md b/app/src/main/assets/help.md index 145139a13..9f77645b6 100644 --- a/app/src/main/assets/help.md +++ b/app/src/main/assets/help.md @@ -1,3 +1,5 @@ +## 常见问题 + 1.为什么第一次安装好之后什么东西都没有? * 因为阅读只是一个转码工具,不提供内容,第一次安装app,需要自己手动导入书源,可以从QQ群、公众号“开源阅读软件”、酷安评论里获取由书友制作分享的书源。 diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index 5410750cb..cb38140fe 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -1,9 +1,20 @@ ## 更新日志 * 旧版数据导入教程:先在旧版阅读(2.x)中进行备份,然后在新版阅读(3.x)【我的】->【备份与恢复】,选择【导入旧版本数据】。 * 请关注[开源阅读]()支持我,同时关注合作公众号[小说拾遗](),阅读公众号小编。 +* 弄了个企业公众号[开源阅读](),后面弄好后会把原来的[开源阅读软件]()迁移过来 + +**2020/03/19** +* 美化界面我的 by yangyxd +* 优化搜索 + +**2020/03/18** +* 尝试修复搜索时崩溃 +* 解决看过书籍的移到顶部需要向上滚动才能看到的bug +* 只有再书源被删除找不到书源时才会自动换源 +* 美化界面 by yangyxd +* 订阅后台播放 **2020/03/16** -* 弄了个企业公众号[开源阅读](),后面弄好后会把原来的开源阅读软件迁移过来 * 修复滚动模式切换章节位置不归0的bug * 修复文字选择更多菜单在部分手机上报错的bug * 修复文字选择菜单问题 diff --git a/app/src/main/java/io/legado/app/data/entities/Book.kt b/app/src/main/java/io/legado/app/data/entities/Book.kt index 9e50a6d4c..0dd5cab9e 100644 --- a/app/src/main/java/io/legado/app/data/entities/Book.kt +++ b/app/src/main/java/io/legado/app/data/entities/Book.kt @@ -32,7 +32,7 @@ data class Book( var customIntro: String? = null, // 简介内容(用户修改) var charset: String? = null, // 自定义字符集名称(仅适用于本地书籍) var type: Int = 0, // 0:text 1:audio - var group: Int = 1, // 自定义分组索引号 + var group: Int = 0, // 自定义分组索引号 var latestChapterTitle: String? = null, // 最新章节标题 var latestChapterTime: Long = System.currentTimeMillis(), // 最新章节标题更新时间 var lastCheckTime: Long = System.currentTimeMillis(), // 最近一次更新书籍信息的时间 diff --git a/app/src/main/java/io/legado/app/help/LauncherIconHelp.kt b/app/src/main/java/io/legado/app/help/LauncherIconHelp.kt index 90c63e4b7..b859336e4 100644 --- a/app/src/main/java/io/legado/app/help/LauncherIconHelp.kt +++ b/app/src/main/java/io/legado/app/help/LauncherIconHelp.kt @@ -19,7 +19,8 @@ object LauncherIconHelp { ComponentName(App.INSTANCE, Launcher2::class.java.name), ComponentName(App.INSTANCE, Launcher3::class.java.name), ComponentName(App.INSTANCE, Launcher4::class.java.name), - ComponentName(App.INSTANCE, Launcher5::class.java.name) + ComponentName(App.INSTANCE, Launcher5::class.java.name), + ComponentName(App.INSTANCE, Launcher6::class.java.name) ) fun changeIcon(icon: String?) { 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 e9fd0df86..0811eee10 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 @@ -6,7 +6,7 @@ import kotlin.coroutines.CoroutineContext class Coroutine( - scope: CoroutineScope, + val scope: CoroutineScope, context: CoroutineContext = Dispatchers.IO, block: suspend CoroutineScope.() -> T ) { @@ -28,9 +28,10 @@ class Coroutine( private val job: Job private var start: VoidCallback? = null - private var success: Callback? = null + private var success: Callback? = null private var error: Callback? = null private var finally: VoidCallback? = null + private var cancel: VoidCallback? = null private var timeMillis: Long? = null private var errorReturn: Result? = null @@ -45,7 +46,7 @@ class Coroutine( get() = job.isCompleted init { - this.job = executeInternal(scope, context, block) + this.job = executeInternal(context, block) } fun timeout(timeMillis: () -> Long): Coroutine { @@ -78,7 +79,7 @@ class Coroutine( fun onSuccess( context: CoroutineContext? = null, - block: suspend CoroutineScope.(T?) -> Unit + block: suspend CoroutineScope.(T) -> Unit ): Coroutine { this.success = Callback(context, block) return this@Coroutine @@ -100,9 +101,28 @@ class Coroutine( return this@Coroutine } + fun onCancel( + context: CoroutineContext? = null, + block: suspend CoroutineScope.() -> Unit + ): Coroutine { + this.cancel = VoidCallback(context, block) + return this@Coroutine + } + //取消当前任务 fun cancel(cause: CancellationException? = null) { job.cancel(cause) + cancel?.let { + MainScope().launch { + if (null == it.context) { + it.block.invoke(scope) + } else { + withContext(scope.coroutineContext.plus(it.context)) { + it.block.invoke(this) + } + } + } + } } fun invokeOnCompletion(handler: CompletionHandler): DisposableHandle { @@ -110,7 +130,6 @@ class Coroutine( } private fun executeInternal( - scope: CoroutineScope, context: CoroutineContext, block: suspend CoroutineScope.() -> T ): Job { @@ -118,21 +137,27 @@ class Coroutine( try { start?.let { dispatchVoidCallback(this, it) } val value = executeBlock(scope, context, timeMillis ?: 0L, block) - success?.let { dispatchCallback(this, value, it) } + if (isActive) { + success?.let { dispatchCallback(this, value, it) } + } } catch (e: Throwable) { if (BuildConfig.DEBUG) { e.printStackTrace() } val consume: Boolean = errorReturn?.value?.let { value -> - success?.let { dispatchCallback(this, value, it) } + if (isActive) { + success?.let { dispatchCallback(this, value, it) } + } true } ?: false - if (!consume) { + if (!consume && isActive) { error?.let { dispatchCallback(this, e, it) } } } finally { - finally?.let { dispatchVoidCallback(this, it) } + if (isActive) { + finally?.let { dispatchVoidCallback(this, it) } + } } } } @@ -152,6 +177,7 @@ class Coroutine( value: R, callback: Callback ) { + if (!scope.isActive) return if (null == callback.context) { callback.block.invoke(scope, value) } else { @@ -166,7 +192,7 @@ class Coroutine( context: CoroutineContext, timeMillis: Long, noinline block: suspend CoroutineScope.() -> T - ): T? { + ): T { return withContext(scope.coroutineContext.plus(context)) { if (timeMillis > 0L) withTimeout(timeMillis) { block() 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 8c4fa8fc2..32bc2b765 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 @@ -54,35 +54,37 @@ object Backup { suspend fun backup(context: Context, path: String = legadoPath) { context.putPrefLong(PreferKey.lastBackup, System.currentTimeMillis()) withContext(IO) { - writeListToJson(App.db.bookDao().all, "bookshelf.json", backupPath) - writeListToJson(App.db.bookGroupDao().all, "bookGroup.json", backupPath) - writeListToJson(App.db.bookSourceDao().all, "bookSource.json", backupPath) - writeListToJson(App.db.rssSourceDao().all, "rssSource.json", backupPath) - writeListToJson(App.db.rssStarDao().all, "rssStar.json", backupPath) - writeListToJson(App.db.replaceRuleDao().all, "replaceRule.json", backupPath) - GSON.toJson(ReadBookConfig.configList)?.let { - FileUtils.createFileIfNotExist(backupPath + File.separator + ReadBookConfig.readConfigFileName) - .writeText(it) - } - Preferences.getSharedPreferences(App.INSTANCE, backupPath, "config")?.let { sp -> - val edit = sp.edit() - App.INSTANCE.defaultSharedPreferences.all.map { - when (val value = it.value) { - is Int -> edit.putInt(it.key, value) - is Boolean -> edit.putBoolean(it.key, value) - is Long -> edit.putLong(it.key, value) - is Float -> edit.putFloat(it.key, value) - is String -> edit.putString(it.key, value) - else -> Unit + synchronized(this@Backup) { + writeListToJson(App.db.bookDao().all, "bookshelf.json", backupPath) + writeListToJson(App.db.bookGroupDao().all, "bookGroup.json", backupPath) + writeListToJson(App.db.bookSourceDao().all, "bookSource.json", backupPath) + writeListToJson(App.db.rssSourceDao().all, "rssSource.json", backupPath) + writeListToJson(App.db.rssStarDao().all, "rssStar.json", backupPath) + writeListToJson(App.db.replaceRuleDao().all, "replaceRule.json", backupPath) + GSON.toJson(ReadBookConfig.configList)?.let { + FileUtils.createFileIfNotExist(backupPath + File.separator + ReadBookConfig.readConfigFileName) + .writeText(it) + } + Preferences.getSharedPreferences(App.INSTANCE, backupPath, "config")?.let { sp -> + val edit = sp.edit() + App.INSTANCE.defaultSharedPreferences.all.map { + when (val value = it.value) { + is Int -> edit.putInt(it.key, value) + is Boolean -> edit.putBoolean(it.key, value) + is Long -> edit.putLong(it.key, value) + is Float -> edit.putFloat(it.key, value) + is String -> edit.putString(it.key, value) + else -> Unit + } } + edit.commit() + } + WebDavHelp.backUpWebDav(backupPath) + if (path.isContentPath()) { + copyBackup(context, Uri.parse(path)) + } else { + copyBackup(File(path)) } - edit.commit() - } - WebDavHelp.backUpWebDav(backupPath) - if (path.isContentPath()) { - copyBackup(context, Uri.parse(path)) - } else { - copyBackup(File(path)) } } } @@ -96,6 +98,7 @@ object Backup { @Throws(java.lang.Exception::class) private fun copyBackup(context: Context, uri: Uri) { + DocumentFile.fromTreeUri(context, uri)?.let { treeDoc -> for (fileName in backupFileNames) { val file = File(backupPath + File.separator + fileName) diff --git a/app/src/main/java/io/legado/app/help/storage/OldBook.kt b/app/src/main/java/io/legado/app/help/storage/OldBook.kt index f8321973c..a782cf5f5 100644 --- a/app/src/main/java/io/legado/app/help/storage/OldBook.kt +++ b/app/src/main/java/io/legado/app/help/storage/OldBook.kt @@ -40,7 +40,6 @@ object OldBook { book.durChapterTitle = jsonItem.readString("$.durChapterName") book.durChapterPos = jsonItem.readInt("$.durChapterPage") ?: 0 book.durChapterTime = jsonItem.readLong("$.finalDate") ?: 0 - book.group = jsonItem.readInt("$.group") ?: 0 book.intro = jsonItem.readString("$.bookInfoBean.introduce") book.latestChapterTitle = jsonItem.readString("$.lastChapterName") book.lastCheckCount = jsonItem.readInt("$.newChapters") ?: 0 diff --git a/app/src/main/java/io/legado/app/model/Debug.kt b/app/src/main/java/io/legado/app/model/Debug.kt index 7d7ec3627..2acd8ac9e 100644 --- a/app/src/main/java/io/legado/app/model/Debug.kt +++ b/app/src/main/java/io/legado/app/model/Debug.kt @@ -56,9 +56,7 @@ object Debug { log(debugSource, "︾开始解析") Rss.getArticles(rssSource, null) .onSuccess { - if (it == null) { - log(debugSource, "︽解析失败", state = -1) - } else if(it.articles.isEmpty()) { + if (it.articles.isEmpty()) { log(debugSource, "⇒列表页解析成功,为空") log(debugSource, "︽解析完成", state = 1000) } else { @@ -140,14 +138,12 @@ object Debug { log(debugSource, "︾开始解析发现页") val explore = webBook.exploreBook(url, 1) .onSuccess { exploreBooks -> - exploreBooks?.let { - if (exploreBooks.isNotEmpty()) { - log(debugSource, "︽发现页解析完成") - log(debugSource, showTime = false) - infoDebug(webBook, exploreBooks[0].toBook()) - } else { - log(debugSource, "︽未获取到书籍", state = -1) - } + if (exploreBooks.isNotEmpty()) { + log(debugSource, "︽发现页解析完成") + log(debugSource, showTime = false) + infoDebug(webBook, exploreBooks[0].toBook()) + } else { + log(debugSource, "︽未获取到书籍", state = -1) } } .onError { @@ -164,14 +160,12 @@ object Debug { log(debugSource, "︾开始解析搜索页") val search = webBook.searchBook(key, 1) .onSuccess { searchBooks -> - searchBooks?.let { - if (searchBooks.isNotEmpty()) { - log(debugSource, "︽搜索页解析完成") - log(debugSource, showTime = false) - infoDebug(webBook, searchBooks[0].toBook()) - } else { - log(debugSource, "︽未获取到书籍", state = -1) - } + if (searchBooks.isNotEmpty()) { + log(debugSource, "︽搜索页解析完成") + log(debugSource, showTime = false) + infoDebug(webBook, searchBooks[0].toBook()) + } else { + log(debugSource, "︽未获取到书籍", state = -1) } } .onError { @@ -197,16 +191,14 @@ object Debug { private fun tocDebug(webBook: WebBook, book: Book) { log(debugSource, "︾开始解析目录页") val chapterList = webBook.getChapterList(book) - .onSuccess { chapterList -> - chapterList?.let { - if (it.isNotEmpty()) { - log(debugSource, "︽目录页解析完成") - log(debugSource, showTime = false) - val nextChapterUrl = if (it.size > 1) it[1].url else null - contentDebug(webBook, book, it[0], nextChapterUrl) - } else { - log(debugSource, "︽目录列表为空", state = -1) - } + .onSuccess { + if (it.isNotEmpty()) { + log(debugSource, "︽目录页解析完成") + log(debugSource, showTime = false) + val nextChapterUrl = if (it.size > 1) it[1].url else null + contentDebug(webBook, book, it[0], nextChapterUrl) + } else { + log(debugSource, "︽目录列表为空", state = -1) } } .onError { diff --git a/app/src/main/java/io/legado/app/model/SearchBookModel.kt b/app/src/main/java/io/legado/app/model/SearchBookModel.kt new file mode 100644 index 000000000..1f6cac065 --- /dev/null +++ b/app/src/main/java/io/legado/app/model/SearchBookModel.kt @@ -0,0 +1,93 @@ +package io.legado.app.model + +import io.legado.app.App +import io.legado.app.data.entities.SearchBook +import io.legado.app.help.AppConfig +import io.legado.app.help.coroutine.Coroutine +import io.legado.app.utils.getPrefString +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Dispatchers.IO +import kotlinx.coroutines.asCoroutineDispatcher +import java.util.concurrent.Executors + +class SearchBookModel(private val scope: CoroutineScope, private val callBack: CallBack) { + private var searchPool = + Executors.newFixedThreadPool(AppConfig.threadCount).asCoroutineDispatcher() + private var mSearchId = System.currentTimeMillis() + private var searchPage = 1 + private var searchKey: String = "" + private var task: Coroutine<*>? = null + + private fun initSearchPool() { + searchPool = + Executors.newFixedThreadPool(AppConfig.threadCount).asCoroutineDispatcher() + } + + fun search(searchId: Long, key: String) { + if (searchId != mSearchId) { + task?.cancel() + searchPool.close() + initSearchPool() + mSearchId = searchId + searchPage = 1 + if (key.isEmpty()) { + return + } else { + this.searchKey = key + } + } else { + searchPage++ + } + task = Coroutine.async(scope, searchPool) { + val searchGroup = App.INSTANCE.getPrefString("searchGroup") ?: "" + val bookSourceList = if (searchGroup.isBlank()) { + App.db.bookSourceDao().allEnabled + } else { + App.db.bookSourceDao().getEnabledByGroup(searchGroup) + } + for (item in bookSourceList) { + //task取消时自动取消 by (scope = this@execute) + WebBook(item).searchBook( + searchKey, + searchPage, + scope = this, + context = searchPool + ) + .timeout(30000L) + .onSuccess(IO) { + if (searchId == mSearchId) { + callBack.onSearchSuccess(it) + } + } + } + }.onStart { + callBack.onSearchStart() + } + + task?.invokeOnCompletion { + if (searchId == mSearchId) { + callBack.onSearchFinish() + } + } + } + + fun cancelSearch() { + task?.cancel() + mSearchId = 0 + callBack.onSearchCancel() + } + + fun close() { + task?.cancel() + mSearchId = 0 + searchPool.close() + } + + interface CallBack { + fun onSearchStart() + fun onSearchSuccess(searchBooks: ArrayList) + fun onSearchFinish() + fun onSearchCancel() + } + +} \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/model/WebBook.kt b/app/src/main/java/io/legado/app/model/WebBook.kt index 7d14ea8bc..cb1742132 100644 --- a/app/src/main/java/io/legado/app/model/WebBook.kt +++ b/app/src/main/java/io/legado/app/model/WebBook.kt @@ -27,13 +27,14 @@ class WebBook(val bookSource: BookSource) { page: Int? = 1, scope: CoroutineScope = Coroutine.DEFAULT, context: CoroutineContext = Dispatchers.IO - ): Coroutine> { + ): Coroutine> { return Coroutine.async(scope, context) { - searchBookSuspend(key, page) + searchBookSuspend(scope, key, page) } } suspend fun searchBookSuspend( + scope: CoroutineScope, key: String, page: Int? = 1 ): ArrayList { @@ -47,6 +48,7 @@ class WebBook(val bookSource: BookSource) { ) val res = analyzeUrl.getResponseAwait(bookSource.bookSourceUrl) return BookList.analyzeBookList( + scope, res.body, bookSource, analyzeUrl, @@ -75,6 +77,7 @@ class WebBook(val bookSource: BookSource) { ) val res = analyzeUrl.getResponseAwait(bookSource.bookSourceUrl) BookList.analyzeBookList( + scope, res.body, bookSource, analyzeUrl, diff --git a/app/src/main/java/io/legado/app/model/webBook/BookList.kt b/app/src/main/java/io/legado/app/model/webBook/BookList.kt index a205c950a..372a4eec6 100644 --- a/app/src/main/java/io/legado/app/model/webBook/BookList.kt +++ b/app/src/main/java/io/legado/app/model/webBook/BookList.kt @@ -9,11 +9,15 @@ import io.legado.app.model.Debug import io.legado.app.model.analyzeRule.AnalyzeRule import io.legado.app.model.analyzeRule.AnalyzeUrl import io.legado.app.utils.NetworkUtils +import kotlinx.coroutines.CancellationException +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.isActive object BookList { @Throws(Exception::class) fun analyzeBookList( + scope: CoroutineScope, body: String?, bookSource: BookSource, analyzeUrl: AnalyzeUrl, @@ -28,12 +32,13 @@ object BookList { ) ) Debug.log(bookSource.bookSourceUrl, "≡获取成功:${analyzeUrl.ruleUrl}") + if (!scope.isActive) throw CancellationException() val analyzeRule = AnalyzeRule(null) analyzeRule.setContent(body, baseUrl) bookSource.bookUrlPattern?.let { if (baseUrl.matches(it.toRegex())) { Debug.log(bookSource.bookSourceUrl, "≡链接为详情页") - getInfoItem(analyzeRule, bookSource, baseUrl)?.let { searchBook -> + getInfoItem(scope, analyzeRule, bookSource, baseUrl)?.let { searchBook -> searchBook.infoHtml = body bookList.add(searchBook) } @@ -59,7 +64,7 @@ object BookList { collections = analyzeRule.getElements(ruleList) if (collections.isEmpty() && bookSource.bookUrlPattern.isNullOrEmpty()) { Debug.log(bookSource.bookSourceUrl, "└列表为空,按详情页解析") - getInfoItem(analyzeRule, bookSource, baseUrl)?.let { searchBook -> + getInfoItem(scope, analyzeRule, bookSource, baseUrl)?.let { searchBook -> searchBook.infoHtml = body bookList.add(searchBook) } @@ -74,8 +79,9 @@ object BookList { val ruleWordCount = analyzeRule.splitSourceRule(bookListRule.wordCount) Debug.log(bookSource.bookSourceUrl, "└列表大小:${collections.size}") for ((index, item) in collections.withIndex()) { + if (!scope.isActive) throw CancellationException() getSearchItem( - item, analyzeRule, bookSource, baseUrl, index == 0, + scope, item, analyzeRule, bookSource, baseUrl, index == 0, ruleName = ruleName, ruleBookUrl = ruleBookUrl, ruleAuthor = ruleAuthor, ruleCoverUrl = ruleCoverUrl, ruleIntro = ruleIntro, ruleKind = ruleKind, ruleLastChapter = ruleLastChapter, ruleWordCount = ruleWordCount @@ -93,7 +99,9 @@ object BookList { return bookList } + @Throws(Exception::class) private fun getInfoItem( + scope: CoroutineScope, analyzeRule: AnalyzeRule, bookSource: BookSource, baseUrl: String @@ -108,29 +116,37 @@ object BookList { with(bookSource.getBookInfoRule()) { init?.let { if (it.isNotEmpty()) { + if (!scope.isActive) throw CancellationException() Debug.log(bookSource.bookSourceUrl, "≡执行详情页初始化规则") analyzeRule.setContent(analyzeRule.getElement(it)) } } + if (!scope.isActive) throw CancellationException() Debug.log(bookSource.bookSourceUrl, "┌获取书名") searchBook.name = analyzeRule.getString(name) Debug.log(bookSource.bookSourceUrl, "└${searchBook.name}") if (searchBook.name.isNotEmpty()) { + if (!scope.isActive) throw CancellationException() Debug.log(bookSource.bookSourceUrl, "┌获取作者") searchBook.author = BookHelp.formatAuthor(analyzeRule.getString(author)) Debug.log(bookSource.bookSourceUrl, "└${searchBook.author}") + if (!scope.isActive) throw CancellationException() Debug.log(bookSource.bookSourceUrl, "┌获取分类") searchBook.kind = analyzeRule.getStringList(kind)?.joinToString(",") Debug.log(bookSource.bookSourceUrl, "└${searchBook.kind}") + if (!scope.isActive) throw CancellationException() Debug.log(bookSource.bookSourceUrl, "┌获取字数") searchBook.wordCount = analyzeRule.getString(wordCount) Debug.log(bookSource.bookSourceUrl, "└${searchBook.wordCount}") + if (!scope.isActive) throw CancellationException() Debug.log(bookSource.bookSourceUrl, "┌获取最新章节") searchBook.latestChapterTitle = analyzeRule.getString(lastChapter) Debug.log(bookSource.bookSourceUrl, "└${searchBook.latestChapterTitle}") + if (!scope.isActive) throw CancellationException() Debug.log(bookSource.bookSourceUrl, "┌获取简介") searchBook.intro = analyzeRule.getString(intro) Debug.log(bookSource.bookSourceUrl, "└${searchBook.intro}", true) + if (!scope.isActive) throw CancellationException() Debug.log(bookSource.bookSourceUrl, "┌获取封面链接") searchBook.coverUrl = analyzeRule.getString(coverUrl, true) Debug.log(bookSource.bookSourceUrl, "└${searchBook.coverUrl}") @@ -140,7 +156,9 @@ object BookList { return null } + @Throws(Exception::class) private fun getSearchItem( + scope: CoroutineScope, item: Any, analyzeRule: AnalyzeRule, bookSource: BookSource, @@ -162,30 +180,38 @@ object BookList { searchBook.originOrder = bookSource.customOrder analyzeRule.book = searchBook analyzeRule.setContent(item) + if (!scope.isActive) throw CancellationException() Debug.log(bookSource.bookSourceUrl, "┌获取书名", log) searchBook.name = analyzeRule.getString(ruleName) Debug.log(bookSource.bookSourceUrl, "└${searchBook.name}", log) if (searchBook.name.isNotEmpty()) { + if (!scope.isActive) throw CancellationException() Debug.log(bookSource.bookSourceUrl, "┌获取作者", log) searchBook.author = BookHelp.formatAuthor(analyzeRule.getString(ruleAuthor)) Debug.log(bookSource.bookSourceUrl, "└${searchBook.author}", log) + if (!scope.isActive) throw CancellationException() Debug.log(bookSource.bookSourceUrl, "┌获取分类", log) searchBook.kind = analyzeRule.getStringList(ruleKind)?.joinToString(",") Debug.log(bookSource.bookSourceUrl, "└${searchBook.kind}", log) + if (!scope.isActive) throw CancellationException() Debug.log(bookSource.bookSourceUrl, "┌获取字数", log) searchBook.wordCount = analyzeRule.getString(ruleWordCount) Debug.log(bookSource.bookSourceUrl, "└${searchBook.wordCount}", log) + if (!scope.isActive) throw CancellationException() Debug.log(bookSource.bookSourceUrl, "┌获取最新章节", log) searchBook.latestChapterTitle = analyzeRule.getString(ruleLastChapter) Debug.log(bookSource.bookSourceUrl, "└${searchBook.latestChapterTitle}", log) + if (!scope.isActive) throw CancellationException() Debug.log(bookSource.bookSourceUrl, "┌获取简介", log) searchBook.intro = analyzeRule.getString(ruleIntro) Debug.log(bookSource.bookSourceUrl, "└${searchBook.intro}", log, true) + if (!scope.isActive) throw CancellationException() Debug.log(bookSource.bookSourceUrl, "┌获取封面链接", log) analyzeRule.getString(ruleCoverUrl).let { if (it.isNotEmpty()) searchBook.coverUrl = NetworkUtils.getAbsoluteURL(baseUrl, it) } Debug.log(bookSource.bookSourceUrl, "└${searchBook.coverUrl}", log) + if (!scope.isActive) throw CancellationException() Debug.log(bookSource.bookSourceUrl, "┌获取详情页链接", log) searchBook.bookUrl = analyzeRule.getString(ruleBookUrl, true) if (searchBook.bookUrl.isEmpty()) { 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 c165f3142..986e7c4ed 100644 --- a/app/src/main/java/io/legado/app/service/AudioPlayService.kt +++ b/app/src/main/java/io/legado/app/service/AudioPlayService.kt @@ -18,9 +18,9 @@ import androidx.core.app.NotificationCompat import io.legado.app.App import io.legado.app.R import io.legado.app.base.BaseService -import io.legado.app.constant.IntentAction import io.legado.app.constant.AppConst import io.legado.app.constant.EventBus +import io.legado.app.constant.IntentAction import io.legado.app.constant.Status import io.legado.app.data.entities.BookChapter import io.legado.app.help.BookHelp @@ -275,7 +275,7 @@ class AudioPlayService : BaseService(), AudioPlay.book?.let { book -> AudioPlay.webBook?.getContent(book, chapter, scope = this) ?.onSuccess(IO) { content -> - if (content.isNullOrEmpty()) { + if (content.isEmpty()) { withContext(Main) { toast("未获取到资源链接") } diff --git a/app/src/main/java/io/legado/app/service/DownloadService.kt b/app/src/main/java/io/legado/app/service/DownloadService.kt index 732506449..dd48933e8 100644 --- a/app/src/main/java/io/legado/app/service/DownloadService.kt +++ b/app/src/main/java/io/legado/app/service/DownloadService.kt @@ -130,10 +130,8 @@ class DownloadService : BaseService() { // notificationContent = "启动:" + chapter.title //} .onSuccess(IO) { content -> - content?.let { - downloadCount[entry.key]?.increaseSuccess() - BookHelp.saveContent(book, chapter, content) - } + downloadCount[entry.key]?.increaseSuccess() + BookHelp.saveContent(book, chapter, content) } .onFinally(IO) { synchronized(this@DownloadService) { diff --git a/app/src/main/java/io/legado/app/service/help/ReadBook.kt b/app/src/main/java/io/legado/app/service/help/ReadBook.kt index 68b1601ac..f48f13d11 100644 --- a/app/src/main/java/io/legado/app/service/help/ReadBook.kt +++ b/app/src/main/java/io/legado/app/service/help/ReadBook.kt @@ -64,6 +64,11 @@ object ReadBook { } } + fun upMsg(msg: String?) { + this.msg = msg + callBack?.upContent() + } + fun moveToNextPage() { durPageIndex++ callBack?.upContent() @@ -240,7 +245,7 @@ object ReadBook { book?.let { book -> webBook?.getContent(book, chapter) ?.onSuccess(Dispatchers.IO) { content -> - if (content.isNullOrEmpty()) { + if (content.isEmpty()) { contentLoadFinish( chapter, App.INSTANCE.getString(R.string.content_empty), diff --git a/app/src/main/java/io/legado/app/ui/audio/AudioPlayViewModel.kt b/app/src/main/java/io/legado/app/ui/audio/AudioPlayViewModel.kt index b5dd5bfba..892a99f41 100644 --- a/app/src/main/java/io/legado/app/ui/audio/AudioPlayViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/audio/AudioPlayViewModel.kt @@ -72,7 +72,7 @@ class AudioPlayViewModel(application: Application) : BaseViewModel(application) execute { AudioPlay.webBook?.getChapterList(book, this) ?.onSuccess(Dispatchers.IO) { cList -> - if (!cList.isNullOrEmpty()) { + if (cList.isNotEmpty()) { if (changeDruChapterIndex == null) { App.db.bookChapterDao().insert(*cList.toTypedArray()) AudioPlay.chapterSize = cList.size diff --git a/app/src/main/java/io/legado/app/ui/book/changecover/ChangeCoverViewModel.kt b/app/src/main/java/io/legado/app/ui/book/changecover/ChangeCoverViewModel.kt index 627bacc09..0c91fe0f9 100644 --- a/app/src/main/java/io/legado/app/ui/book/changecover/ChangeCoverViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/changecover/ChangeCoverViewModel.kt @@ -51,14 +51,13 @@ class ChangeCoverViewModel(application: Application) : BaseViewModel(application fun search() { task = execute { - searchStateData.postValue(true) val bookSourceList = App.db.bookSourceDao().allEnabled for (item in bookSourceList) { //task取消时自动取消 by (scope = this@execute) WebBook(item).searchBook(name, scope = this@execute, context = searchPool) .timeout(30000L) .onSuccess(Dispatchers.IO) { - if (it != null && it.isNotEmpty()) { + if (it.isNotEmpty()) { val searchBook = it[0] if (searchBook.name == name && searchBook.author == author && !searchBook.coverUrl.isNullOrEmpty() @@ -72,6 +71,10 @@ class ChangeCoverViewModel(application: Application) : BaseViewModel(application } } } + }.onStart { + searchStateData.postValue(true) + }.onCancel { + searchStateData.postValue(false) } task?.invokeOnCompletion { 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 e0800c0a1..b375aed11 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 @@ -72,14 +72,13 @@ class ChangeSourceViewModel(application: Application) : BaseViewModel(applicatio fun search() { task = execute { - searchStateData.postValue(true) val bookSourceList = App.db.bookSourceDao().allEnabled for (item in bookSourceList) { //task取消时自动取消 by (scope = this@execute) WebBook(item).searchBook(name, scope = this@execute, context = searchPool) .timeout(30000L) .onSuccess(IO) { - it?.forEach { searchBook -> + it.forEach { searchBook -> if (searchBook.name == name && searchBook.author == author) { if (context.getPrefBoolean(PreferKey.changeSourceLoadToc)) { if (searchBook.tocUrl.isEmpty()) { @@ -95,6 +94,10 @@ class ChangeSourceViewModel(application: Application) : BaseViewModel(applicatio } } } + }.onStart { + searchStateData.postValue(true) + }.onCancel { + searchStateData.postValue(false) } task?.invokeOnCompletion { @@ -107,7 +110,7 @@ class ChangeSourceViewModel(application: Application) : BaseViewModel(applicatio App.db.bookSourceDao().getBookSource(book.origin)?.let { bookSource -> WebBook(bookSource).getBookInfo(book, this) .onSuccess { - it?.let { loadChapter(it) } + loadChapter(it) }.onError { debug { context.getString(R.string.error_get_book_info) } } @@ -119,13 +122,11 @@ class ChangeSourceViewModel(application: Application) : BaseViewModel(applicatio execute { App.db.bookSourceDao().getBookSource(book.origin)?.let { bookSource -> WebBook(bookSource).getChapterList(book, this) - .onSuccess(IO) { - it?.let { chapters -> - if (chapters.isNotEmpty()) { - book.latestChapterTitle = chapters.last().title - val searchBook: SearchBook = book.toSearchBook() - searchFinish(searchBook) - } + .onSuccess(IO) { chapters -> + if (chapters.isNotEmpty()) { + book.latestChapterTitle = chapters.last().title + val searchBook: SearchBook = book.toSearchBook() + searchFinish(searchBook) } }.onError { debug { context.getString(R.string.error_get_chapter_list) } 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 d34e21916..bd22b3968 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 @@ -35,11 +35,9 @@ class ExploreShowViewModel(application: Application) : BaseViewModel(application WebBook(source).exploreBook(url, page, this) .timeout(30000L) .onSuccess(IO) { searchBooks -> - searchBooks?.let { - booksData.postValue(searchBooks) - App.db.searchBookDao().insert(*searchBooks.toTypedArray()) - page++ - } + booksData.postValue(searchBooks) + App.db.searchBookDao().insert(*searchBooks.toTypedArray()) + page++ } } } diff --git a/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt b/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt index 485d704ce..a8d8f59ef 100644 --- a/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt @@ -59,13 +59,11 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) { App.db.bookSourceDao().getBookSource(book.origin)?.let { bookSource -> WebBook(bookSource).getBookInfo(book, this) .onSuccess(IO) { - it?.let { - bookData.postValue(book) - if (inBookshelf) { - App.db.bookDao().update(book) - } - loadChapter(it, changeDruChapterIndex) + bookData.postValue(book) + if (inBookshelf) { + App.db.bookDao().update(book) } + loadChapter(it, changeDruChapterIndex) }.onError { toast(R.string.error_get_book_info) } @@ -92,20 +90,18 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) { App.db.bookSourceDao().getBookSource(book.origin)?.let { bookSource -> WebBook(bookSource).getChapterList(book, this) .onSuccess(IO) { - it?.let { - if (it.isNotEmpty()) { - if (inBookshelf) { - App.db.bookDao().update(book) - App.db.bookChapterDao().insert(*it.toTypedArray()) - } - if (changeDruChapterIndex == null) { - chapterListData.postValue(it) - } else { - changeDruChapterIndex(it) - } + if (it.isNotEmpty()) { + if (inBookshelf) { + App.db.bookDao().update(book) + App.db.bookChapterDao().insert(*it.toTypedArray()) + } + if (changeDruChapterIndex == null) { + chapterListData.postValue(it) } else { - toast(R.string.chapter_list_empty) + changeDruChapterIndex(it) } + } else { + toast(R.string.chapter_list_empty) } }.onError { chapterListData.postValue(null) diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt index 8cd1915cc..e81d7cad9 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt @@ -92,6 +92,7 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo override val headerHeight: Int get() = page_view.curPage.headerHeight override fun onCreate(savedInstanceState: Bundle?) { + ReadBook.msg = null Help.setOrientation(this) super.onCreate(savedInstanceState) } @@ -682,6 +683,7 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo mHandler.removeCallbacks(keepScreenRunnable) textActionMenu?.dismiss() page_view.onDestroy() + ReadBook.msg = null if (!BuildConfig.DEBUG) { SyncBookProgress.uploadBookProgress() Backup.autoBack(this) diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt index 90d559f8d..231f83e11 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt @@ -112,20 +112,21 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) { } else { ReadBook.webBook?.getChapterList(book, this) ?.onSuccess(IO) { cList -> - if (!cList.isNullOrEmpty()) { + if (cList.isNotEmpty()) { if (changeDruChapterIndex == null) { App.db.bookChapterDao().insert(*cList.toTypedArray()) App.db.bookDao().update(book) ReadBook.chapterSize = cList.size + ReadBook.upMsg(null) ReadBook.loadContent(resetPageOffset = true) } else { changeDruChapterIndex(cList) } } else { - toast(R.string.error_load_toc) + ReadBook.upMsg(context.getString(R.string.error_load_toc)) } }?.onError { - toast(R.string.error_load_toc) + ReadBook.upMsg(context.getString(R.string.error_load_toc)) } } } @@ -133,6 +134,7 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) { fun changeTo(book1: Book) { execute { + ReadBook.upMsg(null) ReadBook.book?.let { App.db.bookDao().delete(it) } @@ -159,7 +161,7 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) { execute { App.db.bookSourceDao().allTextEnabled.forEach { source -> try { - val searchBooks = WebBook(source).searchBookSuspend(name) + val searchBooks = WebBook(source).searchBookSuspend(this, name) searchBooks.getOrNull(0)?.let { if (it.name == name && (it.author == author || author == "")) { changeTo(it.toBook()) @@ -171,11 +173,9 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) { } } }.onStart { - ReadBook.msg = "正在自动换源" - ReadBook.callBack?.upContent() + ReadBook.upMsg("正在自动换源") }.onFinally { - ReadBook.msg = null - ReadBook.callBack?.upContent() + ReadBook.upMsg(null) } } diff --git a/app/src/main/java/io/legado/app/ui/book/search/DiffCallBack.kt b/app/src/main/java/io/legado/app/ui/book/search/DiffCallBack.kt index 07a3b16c5..b03e54fb7 100644 --- a/app/src/main/java/io/legado/app/ui/book/search/DiffCallBack.kt +++ b/app/src/main/java/io/legado/app/ui/book/search/DiffCallBack.kt @@ -49,9 +49,9 @@ class DiffCallBack(private val oldItems: List, private val newItems: } override fun getChangePayload(oldItemPosition: Int, newItemPosition: Int): Any? { - val oldItem = oldItems[oldItemPosition] - val newItem = newItems[newItemPosition] val payload = Bundle() + val newItem = newItems[newItemPosition] + val oldItem = oldItems[oldItemPosition] if (oldItem.name != newItem.name) { payload.putString("name", newItem.name) } @@ -73,6 +73,9 @@ class DiffCallBack(private val oldItems: List, private val newItems: if (oldItem.intro != newItem.intro) { payload.putString("intro", newItem.intro) } + if (payload.isEmpty) { + return null + } return payload } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt b/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt index 8de6a489c..e81545adc 100644 --- a/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt @@ -112,6 +112,7 @@ class SearchActivity : VMBaseActivity(R.layout.activity_book_se viewModel.saveSearchKey(query) viewModel.search(it) } + openOrCloseHistory(false) return true } @@ -128,6 +129,7 @@ class SearchActivity : VMBaseActivity(R.layout.activity_book_se openOrCloseHistory(hasFocus) } } + openOrCloseHistory(true) } private fun initRecyclerView() { 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 47671626d..ccfc5dd15 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 @@ -7,82 +7,62 @@ import io.legado.app.base.BaseViewModel import io.legado.app.constant.PreferKey import io.legado.app.data.entities.SearchBook import io.legado.app.data.entities.SearchKeyword -import io.legado.app.help.AppConfig -import io.legado.app.help.coroutine.Coroutine -import io.legado.app.model.WebBook +import io.legado.app.model.SearchBookModel import io.legado.app.utils.getPrefBoolean -import io.legado.app.utils.getPrefString -import kotlinx.coroutines.Dispatchers.IO -import kotlinx.coroutines.asCoroutineDispatcher -import java.util.concurrent.Executors +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.isActive -class SearchViewModel(application: Application) : BaseViewModel(application) { - private var searchPool = - Executors.newFixedThreadPool(AppConfig.threadCount).asCoroutineDispatcher() - private var task: Coroutine<*>? = null +class SearchViewModel(application: Application) : BaseViewModel(application) + , SearchBookModel.CallBack { + private val searchBookModel = SearchBookModel(this, this) var isSearchLiveData = MutableLiveData() var searchBookLiveData = MutableLiveData>() var searchKey: String = "" - var searchPage = 1 var isLoading = false var searchBooks = arrayListOf() + private var searchID = 0L /** * 开始搜索 */ fun search(key: String) { - task?.cancel() - if (key.isEmpty() && searchKey.isEmpty()) { - return - } else if (key.isEmpty()) { - isLoading = true - searchPage++ - } else if (key.isNotEmpty()) { - isLoading = true - searchPage = 1 - searchKey = key + if (searchKey != key && key.isNotEmpty()) { + searchBookModel.cancelSearch() searchBooks.clear() + searchBookLiveData.postValue(searchBooks) + searchID = System.currentTimeMillis() + searchKey = key } + searchBookModel.search(searchID, searchKey) + } + + override fun onSearchStart() { isSearchLiveData.postValue(true) - task = execute { - val searchGroup = context.getPrefString("searchGroup") ?: "" - val bookSourceList = if (searchGroup.isBlank()) { - App.db.bookSourceDao().allEnabled - } else { - App.db.bookSourceDao().getEnabledByGroup(searchGroup) - } - for (item in bookSourceList) { - //task取消时自动取消 by (scope = this@execute) - WebBook(item).searchBook( - searchKey, - searchPage, - scope = this@execute, - context = searchPool - ) - .timeout(30000L) - .onSuccess(IO) { - it?.let { list -> - if (context.getPrefBoolean(PreferKey.precisionSearch)) { - precisionSearch(list) - } else { - App.db.searchBookDao().insert(*list.toTypedArray()) - mergeItems(list) - } - } - } - } - } + } - task?.invokeOnCompletion { - isSearchLiveData.postValue(false) - isLoading = false + override fun onSearchSuccess(searchBooks: ArrayList) { + if (context.getPrefBoolean(PreferKey.precisionSearch)) { + precisionSearch(this, searchBooks) + } else { + App.db.searchBookDao().insert(*searchBooks.toTypedArray()) + mergeItems(this, searchBooks) } } + override fun onSearchFinish() { + isSearchLiveData.postValue(false) + isLoading = false + } + + override fun onSearchCancel() { + isSearchLiveData.postValue(false) + isLoading = false + } + /** * 精确搜索处理 */ - private fun precisionSearch(searchBooks: List) { + private fun precisionSearch(scope: CoroutineScope, searchBooks: List) { val books = arrayListOf() searchBooks.forEach { searchBook -> if (searchBook.name.contains(searchKey, true) @@ -90,14 +70,16 @@ class SearchViewModel(application: Application) : BaseViewModel(application) { ) books.add(searchBook) } App.db.searchBookDao().insert(*books.toTypedArray()) - mergeItems(books) + if (scope.isActive) { + mergeItems(scope, books) + } } /** * 合并搜索结果并排序 */ @Synchronized - private fun mergeItems(newDataS: List) { + private fun mergeItems(scope: CoroutineScope, newDataS: List) { if (newDataS.isNotEmpty()) { val copyDataS = ArrayList(searchBooks) val searchBooksAdd = ArrayList() @@ -141,6 +123,7 @@ class SearchViewModel(application: Application) : BaseViewModel(application) { } } } + if (!scope.isActive) return searchBooks.sortWith(Comparator { o1, o2 -> if (o1.name == searchKey && o2.name != searchKey) { 1 @@ -166,6 +149,7 @@ class SearchViewModel(application: Application) : BaseViewModel(application) { 0 } }) + if (!scope.isActive) return searchBooks = copyDataS searchBookLiveData.postValue(copyDataS) } @@ -175,7 +159,7 @@ class SearchViewModel(application: Application) : BaseViewModel(application) { * 停止搜索 */ fun stop() { - task?.cancel() + searchBookModel.cancelSearch() } /** @@ -211,7 +195,7 @@ class SearchViewModel(application: Application) : BaseViewModel(application) { override fun onCleared() { super.onCleared() - searchPool.close() + searchBookModel.close() } } diff --git a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceViewModel.kt b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceViewModel.kt index 85e3239bc..d44efd3ad 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceViewModel.kt @@ -211,7 +211,7 @@ class BookSourceViewModel(application: Application) : BaseViewModel(application) }.onError { finally(it.localizedMessage ?: "") }.onSuccess { - finally(it ?: "导入完成") + finally(it) } } 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 4fe57d758..61c951ae5 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 @@ -33,11 +33,9 @@ class MainViewModel(application: Application) : BaseViewModel(application) { updateList.remove(book.bookUrl) postEvent(EventBus.UP_BOOK, book.bookUrl) } - it?.let { - App.db.bookDao().update(book) - App.db.bookChapterDao().delByBook(book.bookUrl) - App.db.bookChapterDao().insert(*it.toTypedArray()) - } + App.db.bookDao().update(book) + App.db.bookChapterDao().delByBook(book.bookUrl) + App.db.bookChapterDao().insert(*it.toTypedArray()) } .onError { synchronized(this) { diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfViewModel.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfViewModel.kt index 87d2b3e06..2415db1be 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfViewModel.kt @@ -43,10 +43,8 @@ class BookshelfViewModel(application: Application) : BaseViewModel(application) ) WebBook(bookSource).getBookInfo(book, this) .onSuccess(IO) { - it?.let { book -> - App.db.bookDao().insert(book) - successCount++ - } + App.db.bookDao().insert(it) + successCount++ }.onError { throw Exception(it.localizedMessage) } diff --git a/app/src/main/java/io/legado/app/ui/main/explore/ExploreAdapter.kt b/app/src/main/java/io/legado/app/ui/main/explore/ExploreAdapter.kt index faf9cef8a..ccfa5bf82 100644 --- a/app/src/main/java/io/legado/app/ui/main/explore/ExploreAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/main/explore/ExploreAdapter.kt @@ -24,7 +24,7 @@ import org.jetbrains.anko.sdk27.listeners.onLongClick class ExploreAdapter(context: Context, private val scope: CoroutineScope, val callBack: CallBack) : SimpleRecyclerAdapter(context, R.layout.item_find_book) { - private var exIndex = 0 + private var exIndex = -1 private var scrollTo = -1 override fun convert(holder: ItemViewHolder, item: BookSource, payloads: MutableList) { 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 ccfff44df..61a2b14be 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 @@ -44,8 +44,8 @@ class RssArticlesViewModel(application: Application) : BaseViewModel(application rssSource?.let { rssSource -> Rss.getArticles(rssSource, null) .onSuccess(IO) { - nextPageUrl = it?.nextPageUrl - it?.articles?.let { list -> + nextPageUrl = it.nextPageUrl + it.articles.let { list -> list.forEach { rssArticle -> rssArticle.order = order-- } @@ -76,8 +76,8 @@ class RssArticlesViewModel(application: Application) : BaseViewModel(application if (source != null && !pageUrl.isNullOrEmpty()) { Rss.getArticles(source, pageUrl) .onSuccess(IO) { - nextPageUrl = it?.nextPageUrl - it?.articles?.let { list -> + nextPageUrl = it.nextPageUrl + it.articles.let { list -> if (list.isEmpty()) { callBack?.loadFinally(false) return@let diff --git a/app/src/main/java/io/legado/app/ui/rss/read/VisibleWebView.kt b/app/src/main/java/io/legado/app/ui/rss/read/VisibleWebView.kt new file mode 100644 index 000000000..0e6e1b40b --- /dev/null +++ b/app/src/main/java/io/legado/app/ui/rss/read/VisibleWebView.kt @@ -0,0 +1,17 @@ +package io.legado.app.ui.rss.read + +import android.content.Context +import android.util.AttributeSet +import android.view.View +import android.webkit.WebView + +class VisibleWebView( + context: Context, + attrs: AttributeSet? = null +) : WebView(context, attrs) { + + override fun onWindowVisibilityChanged(visibility: Int) { + super.onWindowVisibilityChanged(View.VISIBLE) + } + +} \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceViewModel.kt b/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceViewModel.kt index 9160155b3..82bad9584 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceViewModel.kt @@ -187,7 +187,7 @@ class RssSourceViewModel(application: Application) : BaseViewModel(application) }.onError { finally(it.localizedMessage ?: "") }.onSuccess { - finally(it ?: "导入完成") + finally(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 new file mode 100644 index 000000000..765a0a580 --- /dev/null +++ b/app/src/main/java/io/legado/app/ui/widget/SearchView.kt @@ -0,0 +1,110 @@ +package io.legado.app.ui.widget + +import android.app.SearchableInfo +import android.content.Context +import android.graphics.Canvas +import android.graphics.Paint +import android.graphics.drawable.Drawable +import android.text.Spannable +import android.text.SpannableStringBuilder +import android.text.style.ImageSpan +import android.util.AttributeSet +import android.util.TypedValue +import android.view.Gravity +import android.widget.TextView +import androidx.appcompat.widget.SearchView +import io.legado.app.R + +class SearchView : SearchView { + private var mSearchHintIcon: Drawable? = null + private var textView: TextView? = null + + constructor( + context: Context?, + attrs: AttributeSet? = null + ) : super(context, attrs) + + constructor( + context: Context?, + attrs: AttributeSet?, + defStyleAttr: Int + ) : super(context, attrs, defStyleAttr) + + override fun onLayout( + changed: Boolean, + left: Int, + top: Int, + right: Int, + bottom: Int + ) { + super.onLayout(changed, left, top, right, bottom) + try { + if (textView == null) { + textView = findViewById(androidx.appcompat.R.id.search_src_text) + mSearchHintIcon = this.context.getDrawable(R.drawable.ic_search_hint) + updateQueryHint() + } + // 改变字体 + textView!!.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14f) + textView!!.gravity = Gravity.CENTER_VERTICAL + } catch (e: Exception) { + e.printStackTrace() + } + } + + private fun getDecoratedHint(hintText: CharSequence): CharSequence { + // If the field is always expanded or we don't have a search hint icon, + // then don't add the search icon to the hint. + if (mSearchHintIcon == null) { + return hintText + } + val textSize = (textView!!.textSize * 0.8).toInt() + mSearchHintIcon!!.setBounds(0, 0, textSize, textSize) + val ssb = SpannableStringBuilder(" ") + ssb.setSpan(CenteredImageSpan(mSearchHintIcon), 1, 2, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE) + ssb.append(hintText) + return ssb + } + + private fun updateQueryHint() { + textView?.let { + it.hint = getDecoratedHint(queryHint ?: "") + } + } + + override fun setIconifiedByDefault(iconified: Boolean) { + super.setIconifiedByDefault(iconified) + updateQueryHint() + } + + override fun setSearchableInfo(searchable: SearchableInfo?) { + super.setSearchableInfo(searchable) + searchable?.let { + updateQueryHint() + } + } + + override fun setQueryHint(hint: CharSequence?) { + super.setQueryHint(hint) + updateQueryHint() + } + + internal class CenteredImageSpan(drawable: Drawable?) : ImageSpan(drawable!!) { + override fun draw( + canvas: Canvas, text: CharSequence, + start: Int, end: Int, x: Float, + top: Int, y: Int, bottom: Int, paint: Paint + ) { + // image to draw + val b = drawable + // font metrics of text to be replaced + val fm = paint.fontMetricsInt + val transY = ((y + fm.descent + y + fm.ascent) / 2 + - b.bounds.bottom / 2) + canvas.save() + canvas.translate(x, transY.toFloat()) + b.draw(canvas) + canvas.restore() + } + } +} diff --git a/app/src/main/java/io/legado/app/ui/widget/ShadowLayout.kt b/app/src/main/java/io/legado/app/ui/widget/ShadowLayout.kt new file mode 100644 index 000000000..0f6ad3200 --- /dev/null +++ b/app/src/main/java/io/legado/app/ui/widget/ShadowLayout.kt @@ -0,0 +1,185 @@ +package io.legado.app.ui.widget + +import android.content.Context +import android.graphics.Canvas +import android.graphics.Color +import android.graphics.Paint +import android.graphics.RectF +import android.util.AttributeSet +import android.view.View +import android.widget.RelativeLayout +import io.legado.app.R +import io.legado.app.utils.getCompatColor + +/** + * ShadowLayout.java + * + * + * Created by lijiankun on 17/8/11. + */ +class ShadowLayout( + context: Context, + attrs: AttributeSet? = null +) : RelativeLayout(context, attrs) { + private val mPaint = + Paint(Paint.ANTI_ALIAS_FLAG) + private val mRectF = RectF() + + /** + * 阴影的颜色 + */ + private var mShadowColor = Color.TRANSPARENT + + /** + * 阴影的大小范围 + */ + private var mShadowRadius = 0f + + /** + * 阴影 x 轴的偏移量 + */ + private var mShadowDx = 0f + + /** + * 阴影 y 轴的偏移量 + */ + private var mShadowDy = 0f + + /** + * 阴影显示的边界 + */ + private var mShadowSide = ALL + + /** + * 阴影的形状,圆形/矩形 + */ + private var mShadowShape = SHAPE_RECTANGLE + + + init { + setLayerType(View.LAYER_TYPE_SOFTWARE, null) // 关闭硬件加速 + setWillNotDraw(false) // 调用此方法后,才会执行 onDraw(Canvas) 方法 + val typedArray = + context.obtainStyledAttributes(attrs, R.styleable.ShadowLayout) + mShadowColor = typedArray.getColor( + R.styleable.ShadowLayout_shadowColor, + context.getCompatColor(android.R.color.black) + ) + mShadowRadius = + typedArray.getDimension(R.styleable.ShadowLayout_shadowRadius, dip2px(0f)) + mShadowDx = typedArray.getDimension(R.styleable.ShadowLayout_shadowDx, dip2px(0f)) + mShadowDy = typedArray.getDimension(R.styleable.ShadowLayout_shadowDy, dip2px(0f)) + mShadowSide = + typedArray.getInt(R.styleable.ShadowLayout_shadowSide, ALL) + mShadowShape = typedArray.getInt( + R.styleable.ShadowLayout_shadowShape, + SHAPE_RECTANGLE + ) + typedArray.recycle() + + setUpShadowPaint() + } + + override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) { + super.onMeasure(widthMeasureSpec, heightMeasureSpec) + val effect = mShadowRadius + dip2px(5f) + var rectLeft = 0f + var rectTop = 0f + var rectRight = this.measuredWidth.toFloat() + var rectBottom = this.measuredHeight.toFloat() + var paddingLeft = 0 + var paddingTop = 0 + var paddingRight = 0 + var paddingBottom = 0 + this.width + if (mShadowSide and LEFT == LEFT) { + rectLeft = effect + paddingLeft = effect.toInt() + } + if (mShadowSide and TOP == TOP) { + rectTop = effect + paddingTop = effect.toInt() + } + if (mShadowSide and RIGHT == RIGHT) { + rectRight = this.measuredWidth - effect + paddingRight = effect.toInt() + } + if (mShadowSide and BOTTOM == BOTTOM) { + rectBottom = this.measuredHeight - effect + paddingBottom = effect.toInt() + } + if (mShadowDy != 0.0f) { + rectBottom -= mShadowDy + paddingBottom += mShadowDy.toInt() + } + if (mShadowDx != 0.0f) { + rectRight -= mShadowDx + paddingRight += mShadowDx.toInt() + } + mRectF.left = rectLeft + mRectF.top = rectTop + mRectF.right = rectRight + mRectF.bottom = rectBottom + setPadding(paddingLeft, paddingTop, paddingRight, paddingBottom) + } + + /** + * 真正绘制阴影的方法 + */ + override fun onDraw(canvas: Canvas) { + super.onDraw(canvas) + setUpShadowPaint() + if (mShadowShape == SHAPE_RECTANGLE) { + canvas.drawRect(mRectF, mPaint) + } else if (mShadowShape == SHAPE_OVAL) { + canvas.drawCircle( + mRectF.centerX(), + mRectF.centerY(), + mRectF.width().coerceAtMost(mRectF.height()) / 2, + mPaint + ) + } + } + + fun setShadowColor(shadowColor: Int) { + mShadowColor = shadowColor + requestLayout() + postInvalidate() + } + + fun setShadowRadius(shadowRadius: Float) { + mShadowRadius = shadowRadius + requestLayout() + postInvalidate() + } + + private fun setUpShadowPaint() { + mPaint.reset() + mPaint.isAntiAlias = true + mPaint.color = Color.TRANSPARENT + mPaint.setShadowLayer(mShadowRadius, mShadowDx, mShadowDy, mShadowColor) + } + + /** + * dip2px dp 值转 px 值 + * + * @param dpValue dp 值 + * @return px 值 + */ + private fun dip2px(dpValue: Float): Float { + val dm = context.resources.displayMetrics + val scale = dm.density + return dpValue * scale + 0.5f + } + + companion object { + const val ALL = 0x1111 + const val LEFT = 0x0001 + const val TOP = 0x0010 + const val RIGHT = 0x0100 + const val BOTTOM = 0x1000 + const val SHAPE_RECTANGLE = 0x0001 + const val SHAPE_OVAL = 0x0010 + } + +} \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/widget/prefs/ColorPreference.kt b/app/src/main/java/io/legado/app/ui/widget/prefs/ColorPreference.kt index 6bea75a51..101b6678a 100644 --- a/app/src/main/java/io/legado/app/ui/widget/prefs/ColorPreference.kt +++ b/app/src/main/java/io/legado/app/ui/widget/prefs/ColorPreference.kt @@ -37,6 +37,8 @@ class ColorPreference(context: Context, attrs: AttributeSet) : Preference(contex init { isPersistent = true + layoutResource = io.legado.app.R.layout.view_preference + val a = context.obtainStyledAttributes(attrs, R.styleable.ColorPreference) showDialog = a.getBoolean(R.styleable.ColorPreference_cpv_showDialog, true) @@ -109,9 +111,12 @@ class ColorPreference(context: Context, attrs: AttributeSet) : Preference(contex } override fun onBindViewHolder(holder: PreferenceViewHolder) { + val v = io.legado.app.ui.widget.prefs.Preference.bindView(context, holder, icon, title, summary, widgetLayoutResource, + io.legado.app.R.id.cpv_preference_preview_color_panel, 30, 30) + if (v is ColorPanelView) { + v.color = color + } super.onBindViewHolder(holder) - val preview = holder.itemView.findViewById(R.id.cpv_preference_preview_color_panel) as ColorPanelView - preview.color = color } override fun onSetInitialValue(defaultValue: Any?) { diff --git a/app/src/main/java/io/legado/app/ui/widget/prefs/EditTextPreference.kt b/app/src/main/java/io/legado/app/ui/widget/prefs/EditTextPreference.kt new file mode 100644 index 000000000..8c0e39da3 --- /dev/null +++ b/app/src/main/java/io/legado/app/ui/widget/prefs/EditTextPreference.kt @@ -0,0 +1,21 @@ +package io.legado.app.ui.widget.prefs + +import android.content.Context +import android.util.AttributeSet +import android.widget.TextView +import androidx.preference.PreferenceViewHolder +import io.legado.app.R + +class EditTextPreference(context: Context, attrs: AttributeSet) : androidx.preference.EditTextPreference(context, attrs) { + + init { + // isPersistent = true + layoutResource = R.layout.view_preference + } + + override fun onBindViewHolder(holder: PreferenceViewHolder?) { + Preference.bindView(context, holder, icon, title, summary, null, null) + super.onBindViewHolder(holder) + } + +} diff --git a/app/src/main/java/io/legado/app/ui/widget/prefs/IconListPreference.kt b/app/src/main/java/io/legado/app/ui/widget/prefs/IconListPreference.kt index b295e5ad3..fa8b4eeb7 100644 --- a/app/src/main/java/io/legado/app/ui/widget/prefs/IconListPreference.kt +++ b/app/src/main/java/io/legado/app/ui/widget/prefs/IconListPreference.kt @@ -29,6 +29,7 @@ class IconListPreference(context: Context, attrs: AttributeSet) : ListPreference private val mEntryDrawables = arrayListOf() init { + layoutResource = R.layout.view_preference widgetLayoutResource = R.layout.view_icon val a = context.theme.obtainStyledAttributes(attrs, R.styleable.IconListPreference, 0, 0) @@ -52,11 +53,12 @@ class IconListPreference(context: Context, attrs: AttributeSet) : ListPreference override fun onBindViewHolder(holder: PreferenceViewHolder?) { super.onBindViewHolder(holder) - holder?.itemView?.findViewById(R.id.preview)?.let { + val v = Preference.bindView(context, holder, icon, title, summary, widgetLayoutResource, R.id.preview, 50, 50) + if (v is ImageView) { val selectedIndex = findIndexOfValue(value) if (selectedIndex >= 0) { val drawable = mEntryDrawables[selectedIndex] - it.setImageDrawable(drawable) + v.setImageDrawable(drawable) } } } diff --git a/app/src/main/java/io/legado/app/ui/widget/prefs/NameListPreference.kt b/app/src/main/java/io/legado/app/ui/widget/prefs/NameListPreference.kt index d8b51e90f..0763c8474 100644 --- a/app/src/main/java/io/legado/app/ui/widget/prefs/NameListPreference.kt +++ b/app/src/main/java/io/legado/app/ui/widget/prefs/NameListPreference.kt @@ -11,12 +11,15 @@ import io.legado.app.R class NameListPreference(context: Context, attrs: AttributeSet) : ListPreference(context, attrs) { init { + layoutResource = R.layout.view_preference widgetLayoutResource = R.layout.item_fillet_text } override fun onBindViewHolder(holder: PreferenceViewHolder?) { + val v = Preference.bindView(context, holder, icon, title, summary, widgetLayoutResource, R.id.text_view) + if (v is TextView) { + v.text = entry + } super.onBindViewHolder(holder) - val textView = holder?.itemView?.findViewById(R.id.text_view) - textView?.text = entry } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/widget/prefs/Preference.kt b/app/src/main/java/io/legado/app/ui/widget/prefs/Preference.kt new file mode 100644 index 000000000..0190dcd9f --- /dev/null +++ b/app/src/main/java/io/legado/app/ui/widget/prefs/Preference.kt @@ -0,0 +1,85 @@ +package io.legado.app.ui.widget.prefs + +import android.content.Context +import android.graphics.drawable.Drawable +import android.util.AttributeSet +import android.view.LayoutInflater +import android.view.View +import android.widget.FrameLayout +import android.widget.ImageView +import android.widget.TextView +import androidx.core.view.isVisible +import androidx.preference.PreferenceViewHolder +import io.legado.app.R +import io.legado.app.lib.theme.accentColor +import org.jetbrains.anko.layoutInflater +import kotlin.math.roundToInt + +class Preference(context: Context, attrs: AttributeSet) : androidx.preference.Preference(context, attrs) { + + init { + // isPersistent = true + layoutResource = R.layout.view_preference + } + + companion object { + + fun bindView(context: Context, it: PreferenceViewHolder?, icon: Drawable?, title: CharSequence?, summary: CharSequence?, weightLayoutRes: Int?, viewId: Int?, + weightWidth: Int = 0, weightHeight: Int = 0): T? { + if (it == null) return null + val view = it.findViewById(R.id.preference_title) + if (view is TextView) { + view.text = title + view.isVisible = title != null && title.isNotEmpty() + + val tvSummary = it.findViewById(R.id.preference_desc) + if (tvSummary is TextView) { + tvSummary.text = summary + tvSummary.isVisible = summary != null && summary.isNotEmpty() + } + + val iconView = it.findViewById(R.id.preference_icon) + if (iconView is ImageView) { + iconView.isVisible = icon != null && icon.isVisible + iconView.setImageDrawable(icon) + iconView.setColorFilter(context.accentColor) + } + } + + if (weightLayoutRes != null && weightLayoutRes != 0 && viewId != null && viewId != 0) { + val lay = it.findViewById(R.id.preference_widget) + if (lay is FrameLayout) { + var v = it.itemView.findViewById(viewId) + if (v == null) { + val inflater: LayoutInflater = context.layoutInflater + val childView = inflater.inflate(weightLayoutRes, null) + lay.removeAllViews() + lay.addView(childView) + lay.isVisible = true + v = lay.findViewById(viewId) + } + + if (weightWidth > 0 || weightHeight > 0) { + val lp = lay.layoutParams + if (weightHeight > 0) + lp.height = (context.resources.displayMetrics.density * weightHeight).roundToInt() + if (weightWidth > 0) + lp.width = (context.resources.displayMetrics.density * weightWidth).roundToInt() + lay.layoutParams = lp + } + + return v + } + } + + return null + } + + } + + override fun onBindViewHolder(holder: PreferenceViewHolder?) { + bindView(context, holder, icon, title, summary, null, null) + super.onBindViewHolder(holder) + } + +} diff --git a/app/src/main/java/io/legado/app/ui/widget/prefs/PreferenceCategory.kt b/app/src/main/java/io/legado/app/ui/widget/prefs/PreferenceCategory.kt index e1458b76e..a7dcd2e6c 100644 --- a/app/src/main/java/io/legado/app/ui/widget/prefs/PreferenceCategory.kt +++ b/app/src/main/java/io/legado/app/ui/widget/prefs/PreferenceCategory.kt @@ -1,22 +1,41 @@ package io.legado.app.ui.widget.prefs import android.content.Context +import android.graphics.Color import android.util.AttributeSet +import android.view.View import android.widget.TextView +import androidx.core.view.isVisible import androidx.preference.PreferenceCategory import androidx.preference.PreferenceViewHolder +import io.legado.app.R import io.legado.app.lib.theme.accentColor -class PreferenceCategory(context: Context, attrs: AttributeSet) : - PreferenceCategory(context, attrs) { +class PreferenceCategory(context: Context, attrs: AttributeSet) : PreferenceCategory(context, attrs) { + + init { + isPersistent = true + layoutResource = R.layout.view_preference_category + } override fun onBindViewHolder(holder: PreferenceViewHolder?) { super.onBindViewHolder(holder) holder?.let { - val view = it.findViewById(android.R.id.title) - if (view is TextView && !view.isInEditMode) { - view.setTextColor(context.accentColor)//设置title文本的颜色 + val view = it.findViewById(R.id.preference_title) + if (view is TextView) { // && !view.isInEditMode + view.text = title + view.setTextColor(context.accentColor) //设置title文本的颜色 + view.isVisible = title != null && title.isNotEmpty() + + val da = it.findViewById(R.id.preference_divider_above) + if (da is View) { + da.isVisible = it.isDividerAllowedAbove + } + val db = it.findViewById(R.id.preference_divider_below) + if (db is View) { + db.isVisible = it.isDividerAllowedBelow + } } } } diff --git a/app/src/main/java/io/legado/app/ui/widget/prefs/SwitchPreference.kt b/app/src/main/java/io/legado/app/ui/widget/prefs/SwitchPreference.kt index 4fe66af7b..2f6becfc2 100644 --- a/app/src/main/java/io/legado/app/ui/widget/prefs/SwitchPreference.kt +++ b/app/src/main/java/io/legado/app/ui/widget/prefs/SwitchPreference.kt @@ -12,14 +12,24 @@ import io.legado.app.lib.theme.accentColor class SwitchPreference(context: Context, attrs: AttributeSet) : SwitchPreferenceCompat(context, attrs) { + init { + layoutResource = R.layout.view_preference + } + override fun onBindViewHolder(holder: PreferenceViewHolder?) { - super.onBindViewHolder(holder) - holder?.let { - val view = it.findViewById(R.id.switchWidget) - if (view is SwitchCompat) { - ATH.setTint(view, context.accentColor) - } + val v = Preference.bindView( + context, + holder, + icon, + title, + summary, + widgetLayoutResource, + R.id.switchWidget + ) + if (v is SwitchCompat) { + ATH.setTint(v, context.accentColor) } + super.onBindViewHolder(holder) } } diff --git a/app/src/main/res/drawable/bg_prefs_color.xml b/app/src/main/res/drawable/bg_prefs_color.xml new file mode 100644 index 000000000..ff4a5de4e --- /dev/null +++ b/app/src/main/res/drawable/bg_prefs_color.xml @@ -0,0 +1,10 @@ + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_cfg_about.xml b/app/src/main/res/drawable/ic_cfg_about.xml new file mode 100644 index 000000000..42e3d30d3 --- /dev/null +++ b/app/src/main/res/drawable/ic_cfg_about.xml @@ -0,0 +1,15 @@ + + + + + diff --git a/app/src/main/res/drawable/ic_cfg_backup.xml b/app/src/main/res/drawable/ic_cfg_backup.xml new file mode 100644 index 000000000..9c647c009 --- /dev/null +++ b/app/src/main/res/drawable/ic_cfg_backup.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/ic_cfg_e_lnk.xml b/app/src/main/res/drawable/ic_cfg_e_lnk.xml new file mode 100644 index 000000000..b94a8eb4d --- /dev/null +++ b/app/src/main/res/drawable/ic_cfg_e_lnk.xml @@ -0,0 +1,5 @@ + + + + diff --git a/app/src/main/res/drawable/ic_cfg_jz.xml b/app/src/main/res/drawable/ic_cfg_jz.xml new file mode 100644 index 000000000..710bae7fd --- /dev/null +++ b/app/src/main/res/drawable/ic_cfg_jz.xml @@ -0,0 +1,12 @@ + + + + diff --git a/app/src/main/res/drawable/ic_cfg_other.xml b/app/src/main/res/drawable/ic_cfg_other.xml new file mode 100644 index 000000000..a3d26b642 --- /dev/null +++ b/app/src/main/res/drawable/ic_cfg_other.xml @@ -0,0 +1,12 @@ + + + + diff --git a/app/src/main/res/drawable/ic_cfg_replace.xml b/app/src/main/res/drawable/ic_cfg_replace.xml new file mode 100644 index 000000000..53c9d1d04 --- /dev/null +++ b/app/src/main/res/drawable/ic_cfg_replace.xml @@ -0,0 +1,12 @@ + + + + diff --git a/app/src/main/res/drawable/ic_cfg_source.xml b/app/src/main/res/drawable/ic_cfg_source.xml new file mode 100644 index 000000000..e71bb109d --- /dev/null +++ b/app/src/main/res/drawable/ic_cfg_source.xml @@ -0,0 +1,12 @@ + + + + diff --git a/app/src/main/res/drawable/ic_cfg_theme.xml b/app/src/main/res/drawable/ic_cfg_theme.xml new file mode 100644 index 000000000..2fe949d19 --- /dev/null +++ b/app/src/main/res/drawable/ic_cfg_theme.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/ic_cfg_web.xml b/app/src/main/res/drawable/ic_cfg_web.xml new file mode 100644 index 000000000..7a34ae004 --- /dev/null +++ b/app/src/main/res/drawable/ic_cfg_web.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/ic_help.xml b/app/src/main/res/drawable/ic_help.xml index 931a86bf6..d5ecd8235 100644 --- a/app/src/main/res/drawable/ic_help.xml +++ b/app/src/main/res/drawable/ic_help.xml @@ -1,15 +1,12 @@ - - - - - + + + + diff --git a/app/src/main/res/drawable/ic_launcher1_b.xml b/app/src/main/res/drawable/ic_launcher1_b.xml index 559d07c34..c5b40eb91 100644 --- a/app/src/main/res/drawable/ic_launcher1_b.xml +++ b/app/src/main/res/drawable/ic_launcher1_b.xml @@ -7,49 +7,49 @@ - + - - - + + - + android:fillColor="#f2f2f2" /> + - - - - - - + + + + + diff --git a/app/src/main/res/drawable/ic_search_hint.xml b/app/src/main/res/drawable/ic_search_hint.xml new file mode 100644 index 000000000..42de64c26 --- /dev/null +++ b/app/src/main/res/drawable/ic_search_hint.xml @@ -0,0 +1,8 @@ + + + + diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 77ed85415..701dea9b5 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -7,7 +7,7 @@ - diff --git a/app/src/main/res/layout/item_bookshelf_grid.xml b/app/src/main/res/layout/item_bookshelf_grid.xml index a038fa4fb..50bb20d12 100644 --- a/app/src/main/res/layout/item_bookshelf_grid.xml +++ b/app/src/main/res/layout/item_bookshelf_grid.xml @@ -4,64 +4,76 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="wrap_content" - android:padding="16dp" - android:clickable="true" - android:focusable="true" - tools:ignore="UnusedAttribute"> + android:paddingTop="2dp" + android:paddingRight="10dp" + android:paddingLeft="10dp"> - + app:shadowColor="#16000000" + app:shadowShape="rectangle" + app:shadowDx="1dp" + app:shadowDy="3dp" + app:shadowRadius="4dp" + app:shadowSide="all"> - + + + + - - + android:layout_gravity="right" + android:layout_margin="5dp" + android:includeFontPadding="false" + app:layout_constraintTop_toTopOf="@+id/bg_cover" + app:layout_constraintRight_toRightOf="@+id/bg_cover" + tools:ignore="RtlHardcoded" /> - - + \ No newline at end of file diff --git a/app/src/main/res/layout/view_preference.xml b/app/src/main/res/layout/view_preference.xml new file mode 100644 index 000000000..87b10ef5b --- /dev/null +++ b/app/src/main/res/layout/view_preference.xml @@ -0,0 +1,65 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/view_preference_category.xml b/app/src/main/res/layout/view_preference_category.xml new file mode 100644 index 000000000..28f4e73ff --- /dev/null +++ b/app/src/main/res/layout/view_preference_category.xml @@ -0,0 +1,29 @@ + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/view_search.xml b/app/src/main/res/layout/view_search.xml index 9b1d48efd..96ff311da 100644 --- a/app/src/main/res/layout/view_search.xml +++ b/app/src/main/res/layout/view_search.xml @@ -1,15 +1,17 @@ - \ No newline at end of file diff --git a/app/src/main/res/mipmap-hdpi/ic_launcher.png b/app/src/main/res/mipmap-hdpi/ic_launcher.png index 0fe58e361..d2c418293 100644 Binary files a/app/src/main/res/mipmap-hdpi/ic_launcher.png and b/app/src/main/res/mipmap-hdpi/ic_launcher.png differ diff --git a/app/src/main/res/mipmap-mdpi/ic_launcher.png b/app/src/main/res/mipmap-mdpi/ic_launcher.png index 59526eefd..2d18ac346 100644 Binary files a/app/src/main/res/mipmap-mdpi/ic_launcher.png and b/app/src/main/res/mipmap-mdpi/ic_launcher.png differ diff --git a/app/src/main/res/mipmap-xhdpi/ic_launcher.png b/app/src/main/res/mipmap-xhdpi/ic_launcher.png index 58b1e389a..4b44e0bba 100644 Binary files a/app/src/main/res/mipmap-xhdpi/ic_launcher.png and b/app/src/main/res/mipmap-xhdpi/ic_launcher.png differ diff --git a/app/src/main/res/mipmap-xxhdpi/ic_launcher.png b/app/src/main/res/mipmap-xxhdpi/ic_launcher.png index ea95882bd..df9bfebb8 100644 Binary files a/app/src/main/res/mipmap-xxhdpi/ic_launcher.png and b/app/src/main/res/mipmap-xxhdpi/ic_launcher.png differ diff --git a/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png b/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png index fe1be3fde..6d101d806 100644 Binary files a/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png and b/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png differ diff --git a/app/src/main/res/values-night/colors.xml b/app/src/main/res/values-night/colors.xml index 78d372bbd..8ac7aa66a 100644 --- a/app/src/main/res/values-night/colors.xml +++ b/app/src/main/res/values-night/colors.xml @@ -7,6 +7,7 @@ @color/md_grey_900 @color/md_grey_850 @color/md_grey_800 + #10303030 #69000000 diff --git a/app/src/main/res/values/attrs.xml b/app/src/main/res/values/attrs.xml index d5a4d11e1..9e920088b 100644 --- a/app/src/main/res/values/attrs.xml +++ b/app/src/main/res/values/attrs.xml @@ -173,4 +173,17 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index 58f27cdec..0fe64b7ca 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -16,6 +16,7 @@ @color/md_grey_50 @color/md_grey_100 @color/md_grey_200 + @color/md_grey_50 #00000000 #10000000 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 558e90cbe..bc219ab39 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -29,6 +29,7 @@ 删除 替换 替换净化 + 配置替换净化规则 暂无 启用 替换净化-搜索 @@ -58,6 +59,7 @@ 添加本地 书源 书源管理 + 新建/导入/编辑/管理书源 设置 主题设置 与界面/颜色相关的一些设置 @@ -80,6 +82,7 @@ 加载中… 重试 Web 服务 + 启用Web服务 web编辑书源 http://%1$s:%2$d 离线下载 @@ -442,6 +445,7 @@ 选中时点击可弹出菜单 主题 主题模式 + 选择主题模式 默认主题 恢复主题为默认配色 加入QQ群 @@ -457,6 +461,7 @@ 导入本地书籍需存储权限 夜间模式 E-Ink 模式 + 电子墨水屏模式 本软件需要存储权限来存储备份书籍信息 再按一次退出程序 导入本地书籍需存储权限 diff --git a/app/src/main/res/xml/about.xml b/app/src/main/res/xml/about.xml index 130e16e60..2970ab12b 100644 --- a/app/src/main/res/xml/about.xml +++ b/app/src/main/res/xml/about.xml @@ -2,68 +2,78 @@ - - - - - - - - - - diff --git a/app/src/main/res/xml/donate.xml b/app/src/main/res/xml/donate.xml index 13d448544..8732f864c 100644 --- a/app/src/main/res/xml/donate.xml +++ b/app/src/main/res/xml/donate.xml @@ -4,51 +4,64 @@ - - - - - - - - - - + - - - - diff --git a/app/src/main/res/xml/pref_config_other.xml b/app/src/main/res/xml/pref_config_other.xml index b049bcf22..560692986 100644 --- a/app/src/main/res/xml/pref_config_other.xml +++ b/app/src/main/res/xml/pref_config_other.xml @@ -4,6 +4,9 @@ - - - - diff --git a/app/src/main/res/xml/pref_config_theme.xml b/app/src/main/res/xml/pref_config_theme.xml index 2f34e86ec..bf90dd7ab 100644 --- a/app/src/main/res/xml/pref_config_theme.xml +++ b/app/src/main/res/xml/pref_config_theme.xml @@ -26,21 +26,26 @@ android:title="@string/navigation_bar_color_change" app:iconSpaceReserved="false" /> - - + xmlns:app="http://schemas.android.com/apk/res-auto" + android:divider="@color/transparent" + app:allowDividerBelow="false" + app:allowDividerAbove="false" + > - - + app:iconSpaceReserved="false" + app:allowDividerAbove="true" + app:allowDividerBelow="false" > - - - - -