diff --git a/app/build.gradle b/app/build.gradle index be8813009..37d539d83 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -193,6 +193,9 @@ dependencies { implementation 'org.apache.commons:commons-lang3:3.11' implementation 'org.apache.commons:commons-text:1.8' + //字符串比较 + implementation 'net.ricecode:string-similarity:1.0.0' + //MarkDown implementation 'ru.noties.markwon:core:3.1.0' @@ -205,8 +208,6 @@ dependencies { exclude group: 'xmlpull' } - //E-Ink 有些手机会出现重影 - //implementation 'fadeapp.widgets:scrollless-recyclerView:1.0.2' } apply plugin: 'com.google.gms.google-services' \ No newline at end of file diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index 33369c847..ec5355f22 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -3,6 +3,11 @@ * 关注合作公众号 **[小说拾遗]()** 获取好看的小说。 * 旧版数据导入教程:先在旧版阅读(2.x)中进行备份,然后在新版阅读(3.x)【我的】->【备份与恢复】,选择【导入旧版本数据】。 +**2020/10/18** +* 优化分组管理,默认分组可以重命名了 +* 修复书架空白的bug,是constraintlayout库新版本的bug +* 修复分组和崩溃bug + **2020/10/16** * 修复排版导入背景失败bug * 修改默认度逍遥per为5003,需要重新导入默认 diff --git a/app/src/main/java/io/legado/app/constant/AppConst.kt b/app/src/main/java/io/legado/app/constant/AppConst.kt index d6bb81302..b841ec595 100644 --- a/app/src/main/java/io/legado/app/constant/AppConst.kt +++ b/app/src/main/java/io/legado/app/constant/AppConst.kt @@ -1,9 +1,6 @@ package io.legado.app.constant import android.annotation.SuppressLint -import io.legado.app.App -import io.legado.app.R -import io.legado.app.data.entities.BookGroup import java.text.SimpleDateFormat import javax.script.ScriptEngine import javax.script.ScriptEngineManager @@ -47,10 +44,10 @@ object AppConst { ) } - val bookGroupAll = BookGroup(-1, App.INSTANCE.getString(R.string.all)) - val bookGroupLocal = BookGroup(-2, App.INSTANCE.getString(R.string.local)) - val bookGroupAudio = BookGroup(-3, App.INSTANCE.getString(R.string.audio)) - val bookGroupNone = BookGroup(-4, App.INSTANCE.getString(R.string.no_group)) + const val bookGroupAllId = -1L + const val bookGroupLocalId = -2L + const val bookGroupAudioId = -3L + const val bookGroupNoneId = -4L const val notificationIdRead = 1144771 const val notificationIdAudio = 1144772 diff --git a/app/src/main/java/io/legado/app/constant/AppPattern.kt b/app/src/main/java/io/legado/app/constant/AppPattern.kt index 19fa46a41..0866b42d4 100644 --- a/app/src/main/java/io/legado/app/constant/AppPattern.kt +++ b/app/src/main/java/io/legado/app/constant/AppPattern.kt @@ -2,6 +2,7 @@ package io.legado.app.constant import java.util.regex.Pattern +@Suppress("RegExpRedundantEscape") object AppPattern { val JS_PATTERN: Pattern = Pattern.compile("([\\w\\W]*?|@js:[\\w\\W]*$)", Pattern.CASE_INSENSITIVE) 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 a865f8d86..dc144493b 100644 --- a/app/src/main/java/io/legado/app/data/AppDatabase.kt +++ b/app/src/main/java/io/legado/app/data/AppDatabase.kt @@ -7,8 +7,10 @@ import androidx.room.RoomDatabase import androidx.room.migration.Migration import androidx.sqlite.db.SupportSQLiteDatabase import io.legado.app.App +import io.legado.app.constant.AppConst import io.legado.app.data.dao.* import io.legado.app.data.entities.* +import java.util.* @Database( @@ -16,7 +18,7 @@ import io.legado.app.data.entities.* ReplaceRule::class, SearchBook::class, SearchKeyword::class, Cookie::class, RssSource::class, Bookmark::class, RssArticle::class, RssReadRecord::class, RssStar::class, TxtTocRule::class, ReadRecord::class, HttpTTS::class], - version = 20, + version = 21, exportSchema = true ) abstract class AppDatabase: RoomDatabase() { @@ -37,12 +39,50 @@ abstract class AppDatabase: RoomDatabase() { migration_15_17, migration_17_18, migration_18_19, - migration_19_20 + migration_19_20, + migration_20_21 ) .allowMainThreadQueries() + .addCallback(dbCallback) .build() - - private val migration_10_11 = object: Migration(10, 11) { + + 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 + where not exists (select * from book_groups where groupId = ${AppConst.bookGroupAllId}) + """ + ) + db.execSQL( + """ + insert into book_groups(groupId, groupName, 'order', show) select ${AppConst.bookGroupLocalId}, '本地', -9, 1 + where not exists (select * from book_groups where groupId = ${AppConst.bookGroupLocalId}) + """ + ) + db.execSQL( + """ + insert into book_groups(groupId, groupName, 'order', show) select ${AppConst.bookGroupAudioId}, '音频', -8, 1 + where not exists (select * from book_groups where groupId = ${AppConst.bookGroupAudioId}) + """ + ) + db.execSQL( + """ + insert into book_groups(groupId, groupName, 'order', show) select ${AppConst.bookGroupNoneId}, '未分组', -7, 1 + where not exists (select * from book_groups where groupId = ${AppConst.bookGroupNoneId}) + """ + ) + } + } + + private val migration_10_11 = object : Migration(10, 11) { override fun migrate(database: SupportSQLiteDatabase) { database.execSQL("DROP TABLE txtTocRules") database.execSQL( @@ -112,11 +152,17 @@ abstract class AppDatabase: RoomDatabase() { database.execSQL("ALTER TABLE readRecordNew RENAME TO readRecord") } } - private val migration_19_20 = object: Migration(19, 20) { + private val migration_19_20 = object : Migration(19, 20) { override fun migrate(database: SupportSQLiteDatabase) { database.execSQL("ALTER TABLE book_sources ADD bookSourceComment TEXT") } } + + private val migration_20_21 = object : Migration(20, 21) { + override fun migrate(database: SupportSQLiteDatabase) { + database.execSQL("ALTER TABLE book_groups ADD show INTEGER NOT NULL DEFAULT 1") + } + } } abstract fun bookDao(): BookDao diff --git a/app/src/main/java/io/legado/app/data/dao/BookDao.kt b/app/src/main/java/io/legado/app/data/dao/BookDao.kt index a4ad1d736..b421c3ffa 100644 --- a/app/src/main/java/io/legado/app/data/dao/BookDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/BookDao.kt @@ -18,18 +18,22 @@ interface BookDao { @Query("SELECT * FROM books WHERE origin = '${BookType.local}'") fun observeLocal(): LiveData> + @Query( + """ + select * from books where ((SELECT sum(groupId) FROM book_groups where groupId > 0) & `group`) = 0 and type != ${BookType.audio} and origin != '${BookType.local}' + """ + ) + fun observeNoGroup(): LiveData> + + @Query("select count(bookUrl) from books where (SELECT sum(groupId) FROM book_groups where groupId > 0) & `group` = 0") + fun observeNoGroupSize(): LiveData + @Query("SELECT bookUrl FROM books WHERE origin = '${BookType.local}'") fun observeLocalUri(): LiveData> @Query("SELECT * FROM books WHERE (`group` & :group) > 0") fun observeByGroup(group: Long): LiveData> - @Query("select * from books where (SELECT sum(groupId) FROM book_groups) & `group` = 0") - fun observeNoGroup(): LiveData> - - @Query("select count(bookUrl) from books where (SELECT sum(groupId) FROM book_groups) & `group` = 0") - fun observeNoGroupSize(): LiveData - @Query("SELECT * FROM books WHERE name like '%'||:key||'%' or author like '%'||:key||'%'") fun liveDataSearch(key: String): LiveData> diff --git a/app/src/main/java/io/legado/app/data/dao/BookGroupDao.kt b/app/src/main/java/io/legado/app/data/dao/BookGroupDao.kt index 5f56d623f..9c362151e 100644 --- a/app/src/main/java/io/legado/app/data/dao/BookGroupDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/BookGroupDao.kt @@ -16,15 +16,27 @@ interface BookGroupDao { @Query("SELECT * FROM book_groups ORDER BY `order`") fun liveDataAll(): LiveData> - @get:Query("SELECT sum(groupId) FROM book_groups") + @Query("SELECT * FROM book_groups where show > 0 or groupId >= 0 ORDER BY `order`") + fun liveDataShow(): LiveData> + + @Query("SELECT * FROM book_groups where groupId >= 0 ORDER BY `order`") + fun liveDataSelect(): LiveData> + + @get:Query("SELECT sum(groupId) FROM book_groups where groupId >= 0") val idsSum: Long - @get:Query("SELECT MAX(`order`) FROM book_groups") + @get:Query("SELECT MAX(`order`) FROM book_groups where groupId >= 0") val maxOrder: Int @get:Query("SELECT * FROM book_groups ORDER BY `order`") val all: List + @Query("update book_groups set show = 1 where groupId = :groupId") + fun enableGroup(groupId: Long) + + @Query("select groupName from book_groups where groupId > 0 and (groupId & :id) > 0") + fun getGroupNames(id: Long): List + @Insert(onConflict = OnConflictStrategy.REPLACE) fun insert(vararg bookGroup: BookGroup) diff --git a/app/src/main/java/io/legado/app/data/dao/ReadRecordDao.kt b/app/src/main/java/io/legado/app/data/dao/ReadRecordDao.kt index 3e964ea73..9363e2a56 100644 --- a/app/src/main/java/io/legado/app/data/dao/ReadRecordDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/ReadRecordDao.kt @@ -10,7 +10,7 @@ interface ReadRecordDao { @get:Query("select * from readRecord") val all: List - @get:Query("select bookName, sum(readTime) as readTime from readRecord group by bookName order by bookName") + @get:Query("select bookName, sum(readTime) as readTime from readRecord group by bookName order by bookName collate localized") val allShow: List @get:Query("select sum(readTime) from readRecord") diff --git a/app/src/main/java/io/legado/app/data/entities/BookGroup.kt b/app/src/main/java/io/legado/app/data/entities/BookGroup.kt index 2d2c68698..5663f2e13 100644 --- a/app/src/main/java/io/legado/app/data/entities/BookGroup.kt +++ b/app/src/main/java/io/legado/app/data/entities/BookGroup.kt @@ -1,8 +1,11 @@ package io.legado.app.data.entities +import android.content.Context import android.os.Parcelable import androidx.room.Entity import androidx.room.PrimaryKey +import io.legado.app.R +import io.legado.app.constant.AppConst import kotlinx.android.parcel.Parcelize @Parcelize @@ -11,5 +14,18 @@ data class BookGroup( @PrimaryKey val groupId: Long = 0b1, var groupName: String, - var order: Int = 0 -) : Parcelable \ No newline at end of file + var order: Int = 0, + var show: Boolean = true +) : Parcelable { + + fun getManageName(context: Context): String { + return when (groupId) { + AppConst.bookGroupAllId -> "$groupName(${context.getString(R.string.all)})" + AppConst.bookGroupAudioId -> "$groupName(${context.getString(R.string.audio)})" + AppConst.bookGroupLocalId -> "$groupName(${context.getString(R.string.local)})" + AppConst.bookGroupNoneId -> "$groupName(${context.getString(R.string.no_group)})" + else -> groupName + } + } + +} \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/help/AppConfig.kt b/app/src/main/java/io/legado/app/help/AppConfig.kt index e2538e902..cb14298b0 100644 --- a/app/src/main/java/io/legado/app/help/AppConfig.kt +++ b/app/src/main/java/io/legado/app/help/AppConfig.kt @@ -97,30 +97,6 @@ object AppConfig { App.INSTANCE.putPrefInt(PreferKey.systemTypefaces, value) } - var bookGroupAllShow: Boolean - get() = App.INSTANCE.getPrefBoolean("bookGroupAll", true) - set(value) { - App.INSTANCE.putPrefBoolean("bookGroupAll", value) - } - - var bookGroupLocalShow: Boolean - get() = App.INSTANCE.getPrefBoolean("bookGroupLocal", false) - set(value) { - App.INSTANCE.putPrefBoolean("bookGroupLocal", value) - } - - var bookGroupAudioShow: Boolean - get() = App.INSTANCE.getPrefBoolean("bookGroupAudio", false) - set(value) { - App.INSTANCE.putPrefBoolean("bookGroupAudio", value) - } - - var bookGroupNoneShow: Boolean - get() = App.INSTANCE.getPrefBoolean("bookGroupNone", false) - set(value) { - App.INSTANCE.putPrefBoolean("bookGroupNone", value) - } - var elevation: Int @SuppressLint("PrivateResource") get() = App.INSTANCE.getPrefInt( 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 ae992e696..32d5262ce 100644 --- a/app/src/main/java/io/legado/app/help/BookHelp.kt +++ b/app/src/main/java/io/legado/app/help/BookHelp.kt @@ -15,10 +15,15 @@ import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.Dispatchers.Main import kotlinx.coroutines.delay import kotlinx.coroutines.withContext -import org.apache.commons.text.similarity.JaccardSimilarity +import net.ricecode.similarity.JaroWinklerStrategy +import net.ricecode.similarity.StringSimilarityServiceImpl import org.jetbrains.anko.toast import java.io.File import java.util.concurrent.CopyOnWriteArraySet +import java.util.regex.Matcher +import java.util.regex.Pattern +import kotlin.math.abs +import kotlin.math.max import kotlin.math.min object BookHelp { @@ -202,54 +207,88 @@ object BookHelp { } /** - * 找到相似度最高的章节 + * 根据目录名获取当前章节 */ - fun getDurChapterIndexByChapterTitle( - title: String?, - index: Int, - chapters: List, + fun getDurChapter( + oldDurChapterIndex: Int, + oldChapterListSize: Int, + oldDurChapterName: String?, + newChapterList: List ): Int { - if (title.isNullOrEmpty()) { - return min(index, chapters.lastIndex) - } - if (chapters.size > index && title == chapters[index].title) { - return index - } - + if (oldChapterListSize == 0) return 0 + val oldChapterNum = getChapterNum(oldDurChapterName) + val oldName = getPureChapterName(oldDurChapterName) + val newChapterSize = newChapterList.size + val min = max( + 0, + min( + oldDurChapterIndex, + oldDurChapterIndex - oldChapterListSize + newChapterSize + ) - 10 + ) + val max = min( + newChapterSize - 1, + max( + oldDurChapterIndex, + oldDurChapterIndex - oldChapterListSize + newChapterSize + ) + 10 + ) + var nameSim = 0.0 var newIndex = 0 - val jSimilarity = JaccardSimilarity() - var similarity = if (chapters.size > index) { - jSimilarity.apply(title, chapters[index].title) - } else 0.0 - if (similarity == 1.0) { - return index - } else { - for (i in 1..50) { - if (index - i in chapters.indices) { - jSimilarity.apply(title, chapters[index - i].title).let { - if (it > similarity) { - similarity = it - newIndex = index - i - if (similarity == 1.0) { - return newIndex - } - } - } + var newNum = 0 + if (oldName.isNotEmpty()) { + val service = StringSimilarityServiceImpl(JaroWinklerStrategy()) + for (i in min..max) { + val newName = getPureChapterName(newChapterList[i].title) + val temp = service.score(oldName, newName) + if (temp > nameSim) { + nameSim = temp + newIndex = i } - if (index + i in chapters.indices) { - jSimilarity.apply(title, chapters[index + i].title).let { - if (it > similarity) { - similarity = it - newIndex = index + i - if (similarity == 1.0) { - return newIndex - } - } - } + } + } + if (nameSim < 0.96 && oldChapterNum > 0) { + for (i in min..max) { + val temp = getChapterNum(newChapterList[i].title) + if (temp == oldChapterNum) { + newNum = temp + newIndex = i + break + } else if (abs(temp - oldChapterNum) < abs(newNum - oldChapterNum)) { + newNum = temp + newIndex = i } } } - return newIndex + return if (nameSim > 0.96 || abs(newNum - oldChapterNum) < 1) { + newIndex + } else { + min(max(0, newChapterList.size - 1), oldDurChapterIndex) + } + } + + private val chapterNamePattern = + Pattern.compile("^(.*?第([\\d零〇一二两三四五六七八九十百千万壹贰叁肆伍陆柒捌玖拾佰仟0-9\\s]+)[章节篇回集])[、,。 ::.\\s]*") + + private fun getChapterNum(chapterName: String?): Int { + if (chapterName != null) { + val matcher: Matcher = chapterNamePattern.matcher(chapterName) + if (matcher.find()) { + return StringUtils.stringToInt(matcher.group(2)) + } + } + return -1 + } + + private fun getPureChapterName(chapterName: String?): String { + // 所有非字母数字中日韩文字 CJK区+扩展A-F区 + 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(), + "" + ) } private var bookName: String? = null diff --git a/app/src/main/java/io/legado/app/help/storage/Restore.kt b/app/src/main/java/io/legado/app/help/storage/Restore.kt index 0ba5e4367..174367557 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 @@ -228,7 +228,6 @@ object Restore { LanguageUtils.setConfiguration(App.INSTANCE) App.INSTANCE.applyDayNight() postEvent(EventBus.SHOW_RSS, "") - postEvent(EventBus.RECREATE, "") } } diff --git a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt index cb8b9c6b9..8fb5e2c0f 100644 --- a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt +++ b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt @@ -20,7 +20,7 @@ import kotlin.collections.HashMap * 统一解析接口 */ @Keep -@Suppress("unused") +@Suppress("unused", "RegExpRedundantEscape") class AnalyzeRule(var book: BaseBook? = null) : JsExtensions { var chapter: BookChapter? = null private var content: Any? = null diff --git a/app/src/main/java/io/legado/app/model/rss/Result.kt b/app/src/main/java/io/legado/app/model/rss/Result.kt deleted file mode 100644 index 4d7f67c0a..000000000 --- a/app/src/main/java/io/legado/app/model/rss/Result.kt +++ /dev/null @@ -1,5 +0,0 @@ -package io.legado.app.model.rss - -import io.legado.app.data.entities.RssArticle - -data class Result(val articles: MutableList, val nextPageUrl: String?) \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/model/rss/Rss.kt b/app/src/main/java/io/legado/app/model/rss/Rss.kt index f9ea78195..830f72a80 100644 --- a/app/src/main/java/io/legado/app/model/rss/Rss.kt +++ b/app/src/main/java/io/legado/app/model/rss/Rss.kt @@ -5,8 +5,6 @@ import io.legado.app.data.entities.RssSource import io.legado.app.help.coroutine.Coroutine import io.legado.app.model.analyzeRule.AnalyzeRule import io.legado.app.model.analyzeRule.AnalyzeUrl -import io.legado.app.model.rss.Result -import io.legado.app.model.rss.RssParserByRule import io.legado.app.utils.NetworkUtils import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers @@ -21,7 +19,7 @@ object Rss { page: Int, scope: CoroutineScope = Coroutine.DEFAULT, context: CoroutineContext = Dispatchers.IO - ): Coroutine { + ): Coroutine { return Coroutine.async(scope, context) { val analyzeUrl = AnalyzeUrl( sortUrl, diff --git a/app/src/main/java/io/legado/app/model/rss/RssParserByRule.kt b/app/src/main/java/io/legado/app/model/rss/RssParserByRule.kt index 047d39459..82ab063ae 100644 --- a/app/src/main/java/io/legado/app/model/rss/RssParserByRule.kt +++ b/app/src/main/java/io/legado/app/model/rss/RssParserByRule.kt @@ -14,7 +14,12 @@ import java.util.* object RssParserByRule { @Throws(Exception::class) - fun parseXML(sortName: String, sortUrl: String, body: String?, rssSource: RssSource): Result { + fun parseXML( + sortName: String, + sortUrl: String, + body: String?, + rssSource: RssSource + ): RssResult { val sourceUrl = rssSource.sourceUrl var nextUrl: String? = null if (body.isNullOrBlank()) { @@ -29,7 +34,7 @@ object RssParserByRule { var ruleArticles = rssSource.ruleArticles if (ruleArticles.isNullOrBlank()) { Debug.log(sourceUrl, "⇒列表规则为空, 使用默认规则解析") - return RssParser.parseXML(sortName, body, sourceUrl) + return RssParserDefault.parseXML(sortName, body, sourceUrl) } else { val articleList = mutableListOf() val analyzeRule = AnalyzeRule() @@ -72,7 +77,7 @@ object RssParserByRule { if (reverse) { articleList.reverse() } - return Result(articleList, nextUrl) + return RssResult(articleList, nextUrl) } } diff --git a/app/src/main/java/io/legado/app/model/rss/RssParser.kt b/app/src/main/java/io/legado/app/model/rss/RssParserDefault.kt similarity index 98% rename from app/src/main/java/io/legado/app/model/rss/RssParser.kt rename to app/src/main/java/io/legado/app/model/rss/RssParserDefault.kt index e6667164e..2a02c2bdc 100644 --- a/app/src/main/java/io/legado/app/model/rss/RssParser.kt +++ b/app/src/main/java/io/legado/app/model/rss/RssParserDefault.kt @@ -8,10 +8,10 @@ import org.xmlpull.v1.XmlPullParserFactory import java.io.IOException import java.io.StringReader -object RssParser { +object RssParserDefault { @Throws(XmlPullParserException::class, IOException::class) - fun parseXML(sortName: String, xml: String, sourceUrl: String): Result { + fun parseXML(sortName: String, xml: String, sourceUrl: String): RssResult { val articleList = mutableListOf() var currentArticle = RssArticle() @@ -105,7 +105,7 @@ object RssParser { Debug.log(sourceUrl, "┌获取文章链接") Debug.log(sourceUrl, "└${it.link}") } - return Result(articleList, null) + return RssResult(articleList, null) } /** diff --git a/app/src/main/java/io/legado/app/model/rss/RssResult.kt b/app/src/main/java/io/legado/app/model/rss/RssResult.kt new file mode 100644 index 000000000..4074871ff --- /dev/null +++ b/app/src/main/java/io/legado/app/model/rss/RssResult.kt @@ -0,0 +1,5 @@ +package io.legado.app.model.rss + +import io.legado.app.data.entities.RssArticle + +data class RssResult(val articles: MutableList, val nextPageUrl: String?) \ No newline at end of file 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 4c1a5a85b..5225b21ff 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 @@ -89,7 +89,9 @@ class AudioPlayViewModel(application: Application) : BaseViewModel(application) fun changeTo(book1: Book) { execute { + var oldTocSize: Int = book1.totalChapterNum AudioPlay.book?.let { + oldTocSize = it.totalChapterNum book1.order = it.order App.db.bookDao().delete(it) } @@ -99,18 +101,23 @@ class AudioPlayViewModel(application: Application) : BaseViewModel(application) AudioPlay.webBook = WebBook(it) } if (book1.tocUrl.isEmpty()) { - loadBookInfo(book1) { upChangeDurChapterIndex(book1, it) } + loadBookInfo(book1) { upChangeDurChapterIndex(book1, oldTocSize, it) } } else { - loadChapterList(book1) { upChangeDurChapterIndex(book1, it) } + loadChapterList(book1) { upChangeDurChapterIndex(book1, oldTocSize, it) } } } } - private fun upChangeDurChapterIndex(book: Book, chapters: List) { + private fun upChangeDurChapterIndex( + book: Book, + oldTocSize: Int, + chapters: List + ) { execute { - AudioPlay.durChapterIndex = BookHelp.getDurChapterIndexByChapterTitle( - book.durChapterTitle, + AudioPlay.durChapterIndex = BookHelp.getDurChapter( book.durChapterIndex, + oldTocSize, + book.durChapterTitle, chapters ) book.durChapterIndex = AudioPlay.durChapterIndex diff --git a/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookActivity.kt b/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookActivity.kt index d2fedc183..af949ce68 100644 --- a/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookActivity.kt @@ -69,8 +69,7 @@ class ArrangeBookActivity : VMBaseActivity(R.layout.activi recycler_view.addItemDecoration(VerticalDivider(this)) adapter = ArrangeBookAdapter(this, this) recycler_view.adapter = adapter - val itemTouchCallback = ItemTouchCallback() - itemTouchCallback.onItemTouchCallbackListener = adapter + val itemTouchCallback = ItemTouchCallback(adapter) itemTouchCallback.isCanDrag = getPrefInt(PreferKey.bookshelfSort) == 3 val dragSelectTouchHelper: DragSelectTouchHelper = DragSelectTouchHelper(adapter.initDragSelectTouchHelperCallback()).setSlideArea(16, 50) @@ -112,10 +111,10 @@ class ArrangeBookActivity : VMBaseActivity(R.layout.activi booksLiveData?.removeObservers(this) booksLiveData = when (groupId) { - AppConst.bookGroupAll.groupId -> App.db.bookDao().observeAll() - AppConst.bookGroupLocal.groupId -> App.db.bookDao().observeLocal() - AppConst.bookGroupAudio.groupId -> App.db.bookDao().observeAudio() - AppConst.bookGroupNone.groupId -> App.db.bookDao().observeNoGroup() + AppConst.bookGroupAllId -> App.db.bookDao().observeAll() + AppConst.bookGroupLocalId -> App.db.bookDao().observeLocal() + AppConst.bookGroupAudioId -> App.db.bookDao().observeAudio() + AppConst.bookGroupNoneId -> App.db.bookDao().observeNoGroup() else -> App.db.bookDao().observeByGroup(groupId) } booksLiveData?.observe(this, { list -> @@ -134,26 +133,6 @@ class ArrangeBookActivity : VMBaseActivity(R.layout.activi when (item.itemId) { R.id.menu_group_manage -> GroupManageDialog() .show(supportFragmentManager, "groupManage") - R.id.menu_no_group -> { - title_bar.subtitle = getString(R.string.no_group) - groupId = AppConst.bookGroupNone.groupId - initBookData() - } - R.id.menu_all -> { - title_bar.subtitle = item.title - groupId = AppConst.bookGroupAll.groupId - initBookData() - } - R.id.menu_local -> { - title_bar.subtitle = item.title - groupId = AppConst.bookGroupLocal.groupId - initBookData() - } - R.id.menu_audio -> { - title_bar.subtitle = item.title - groupId = AppConst.bookGroupAudio.groupId - initBookData() - } else -> if (item.groupId == R.id.menu_group) { title_bar.subtitle = item.title groupId = App.db.bookGroupDao().getByName(item.title.toString())?.groupId ?: 0 diff --git a/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookAdapter.kt b/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookAdapter.kt index 62c28e766..2b05b7014 100644 --- a/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookAdapter.kt @@ -19,7 +19,7 @@ import java.util.* class ArrangeBookAdapter(context: Context, val callBack: CallBack) : SimpleRecyclerAdapter(context, R.layout.item_arrange_book), - ItemTouchCallback.OnItemTouchCallbackListener { + ItemTouchCallback.Callback { val groupRequestCode = 12 private val selectedBooks: HashSet = hashSetOf() var actionItem: Book? = null @@ -112,7 +112,7 @@ class ArrangeBookAdapter(context: Context, val callBack: CallBack) : private fun getGroupList(groupId: Long): List { val groupNames = arrayListOf() callBack.groupList.forEach { - if (it.groupId and groupId > 0) { + if (it.groupId > 0 && it.groupId and groupId > 0) { groupNames.add(it.groupName) } } diff --git a/app/src/main/java/io/legado/app/ui/book/cache/CacheActivity.kt b/app/src/main/java/io/legado/app/ui/book/cache/CacheActivity.kt index 0ae61f349..8aba5d38d 100644 --- a/app/src/main/java/io/legado/app/ui/book/cache/CacheActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/cache/CacheActivity.kt @@ -57,7 +57,7 @@ class CacheActivity : VMBaseActivity(R.layout.activity_download) } override fun onCompatCreateOptionsMenu(menu: Menu): Boolean { - menuInflater.inflate(R.menu.download, menu) + menuInflater.inflate(R.menu.book_cache, menu) return super.onCompatCreateOptionsMenu(menu) } @@ -95,16 +95,6 @@ class CacheActivity : VMBaseActivity(R.layout.activity_download) R.id.menu_log -> { TextListDialog.show(supportFragmentManager, getString(R.string.log), CacheBook.logs) } - R.id.menu_no_group -> { - title_bar.subtitle = getString(R.string.no_group) - groupId = AppConst.bookGroupNone.groupId - initBookData() - } - R.id.menu_all -> { - title_bar.subtitle = item.title - groupId = AppConst.bookGroupAll.groupId - initBookData() - } else -> if (item.groupId == R.id.menu_group) { title_bar.subtitle = item.title groupId = App.db.bookGroupDao().getByName(item.title.toString())?.groupId ?: 0 @@ -123,8 +113,10 @@ class CacheActivity : VMBaseActivity(R.layout.activity_download) private fun initBookData() { booksLiveData?.removeObservers(this) booksLiveData = when (groupId) { - AppConst.bookGroupAll.groupId -> App.db.bookDao().observeAll() - AppConst.bookGroupNone.groupId -> App.db.bookDao().observeNoGroup() + AppConst.bookGroupAllId -> App.db.bookDao().observeAll() + AppConst.bookGroupLocalId -> App.db.bookDao().observeLocal() + AppConst.bookGroupAudioId -> App.db.bookDao().observeAudio() + AppConst.bookGroupNoneId -> App.db.bookDao().observeNoGroup() else -> App.db.bookDao().observeByGroup(groupId) } booksLiveData?.observe(this, { list -> diff --git a/app/src/main/java/io/legado/app/ui/book/group/GroupManageDialog.kt b/app/src/main/java/io/legado/app/ui/book/group/GroupManageDialog.kt index 0782c7c39..8c768d6f5 100644 --- a/app/src/main/java/io/legado/app/ui/book/group/GroupManageDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/group/GroupManageDialog.kt @@ -10,6 +10,7 @@ import android.view.View import android.view.ViewGroup import android.widget.EditText import androidx.appcompat.widget.Toolbar +import androidx.core.view.isGone import androidx.recyclerview.widget.DiffUtil import androidx.recyclerview.widget.ItemTouchHelper import androidx.recyclerview.widget.LinearLayoutManager @@ -20,7 +21,6 @@ import io.legado.app.base.BaseDialogFragment import io.legado.app.base.adapter.ItemViewHolder import io.legado.app.base.adapter.SimpleRecyclerAdapter import io.legado.app.data.entities.BookGroup -import io.legado.app.help.AppConfig import io.legado.app.lib.dialogs.* import io.legado.app.lib.theme.accentColor import io.legado.app.lib.theme.backgroundColor @@ -41,7 +41,6 @@ import kotlin.collections.ArrayList class GroupManageDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener { private lateinit var viewModel: GroupViewModel private lateinit var adapter: GroupAdapter - private val callBack: CallBack? get() = parentFragment as? CallBack override fun onStart() { super.onStart() @@ -62,67 +61,41 @@ class GroupManageDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) { tool_bar.setBackgroundColor(primaryColor) tool_bar.title = getString(R.string.group_manage) + initView() initData() initMenu() } - private fun initData() { + private fun initView() { adapter = GroupAdapter(requireContext()) recycler_view.layoutManager = LinearLayoutManager(requireContext()) recycler_view.addItemDecoration(VerticalDivider(requireContext())) recycler_view.adapter = adapter + val itemTouchCallback = ItemTouchCallback(adapter) + itemTouchCallback.isCanDrag = true + ItemTouchHelper(itemTouchCallback).attachToRecyclerView(recycler_view) tv_ok.setTextColor(requireContext().accentColor) tv_ok.visible() tv_ok.onClick { dismiss() } + } + + private fun initData() { App.db.bookGroupDao().liveDataAll().observe(viewLifecycleOwner, { val diffResult = DiffUtil.calculateDiff(GroupDiffCallBack(ArrayList(adapter.getItems()), it)) adapter.setItems(it, diffResult) }) - val itemTouchCallback = ItemTouchCallback() - itemTouchCallback.onItemTouchCallbackListener = adapter - itemTouchCallback.isCanDrag = true - ItemTouchHelper(itemTouchCallback).attachToRecyclerView(recycler_view) } private fun initMenu() { tool_bar.setOnMenuItemClickListener(this) tool_bar.inflateMenu(R.menu.book_group_manage) - tool_bar.menu.let { - it.applyTint(requireContext()) - it.findItem(R.id.menu_group_all) - .isChecked = AppConfig.bookGroupAllShow - it.findItem(R.id.menu_group_local) - .isChecked = AppConfig.bookGroupLocalShow - it.findItem(R.id.menu_group_audio) - .isChecked = AppConfig.bookGroupAudioShow - it.findItem(R.id.menu_group_none) - .isChecked = AppConfig.bookGroupNoneShow - } + tool_bar.menu.applyTint(requireContext()) } override fun onMenuItemClick(item: MenuItem?): Boolean { when (item?.itemId) { R.id.menu_add -> addGroup() - R.id.menu_group_all -> { - item.isChecked = !item.isChecked - AppConfig.bookGroupAllShow = item.isChecked - callBack?.upGroup() - } - R.id.menu_group_local -> { - item.isChecked = !item.isChecked - AppConfig.bookGroupLocalShow = item.isChecked - callBack?.upGroup() - } - R.id.menu_group_audio -> { - item.isChecked = !item.isChecked - AppConfig.bookGroupAudioShow = item.isChecked - callBack?.upGroup() - } - R.id.menu_group_none -> { - item.isChecked = !item.isChecked - AppConfig.bookGroupNoneShow = item.isChecked - } } return true } @@ -134,7 +107,7 @@ class GroupManageDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener customView { layoutInflater.inflate(R.layout.dialog_edit_text, null).apply { editText = edit_view.apply { - hint = "分组名称" + setHint(R.string.group_name) } } } @@ -156,7 +129,7 @@ class GroupManageDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener customView { layoutInflater.inflate(R.layout.dialog_edit_text, null).apply { editText = edit_view.apply { - hint = "分组名称" + setHint(R.string.group_name) setText(bookGroup.groupName) } } @@ -191,27 +164,33 @@ class GroupManageDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener } override fun areItemsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean { - return true + val oldItem = oldItems[oldItemPosition] + val newItem = newItems[newItemPosition] + return oldItem.groupId == newItem.groupId } override fun areContentsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean { val oldItem = oldItems[oldItemPosition] val newItem = newItems[newItemPosition] return oldItem.groupName == newItem.groupName + && oldItem.show == newItem.show } } private inner class GroupAdapter(context: Context) : SimpleRecyclerAdapter(context, R.layout.item_group_manage), - ItemTouchCallback.OnItemTouchCallbackListener { + ItemTouchCallback.Callback { private var isMoved = false override fun convert(holder: ItemViewHolder, item: BookGroup, payloads: MutableList) { holder.itemView.apply { setBackgroundColor(context.backgroundColor) - tv_group.text = item.groupName + tv_group.text = item.getManageName(context) + sw_show.isChecked = item.show + tv_del.isGone = item.groupId < 0 + sw_show.isGone = item.groupId >= 0 } } @@ -219,6 +198,13 @@ class GroupManageDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener holder.itemView.apply { tv_edit.onClick { getItem(holder.layoutPosition)?.let { editGroup(it) } } tv_del.onClick { getItem(holder.layoutPosition)?.let { deleteGroup(it) } } + sw_show.setOnCheckedChangeListener { buttonView, isChecked -> + if (buttonView.isPressed) { + getItem(holder.layoutPosition)?.let { + viewModel.upGroup(it.copy(show = isChecked)) + } + } + } } } @@ -240,7 +226,4 @@ class GroupManageDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener } } - interface CallBack { - fun upGroup() - } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/book/group/GroupSelectDialog.kt b/app/src/main/java/io/legado/app/ui/book/group/GroupSelectDialog.kt index 4cc5333b9..059d31df0 100644 --- a/app/src/main/java/io/legado/app/ui/book/group/GroupSelectDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/group/GroupSelectDialog.kt @@ -93,13 +93,11 @@ class GroupSelectDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener tool_bar.inflateMenu(R.menu.book_group_manage) tool_bar.menu.applyTint(requireContext()) tool_bar.setOnMenuItemClickListener(this) - tool_bar.menu.setGroupVisible(R.id.menu_groups, false) adapter = GroupAdapter(requireContext()) recycler_view.layoutManager = LinearLayoutManager(requireContext()) recycler_view.addItemDecoration(VerticalDivider(requireContext())) recycler_view.adapter = adapter - val itemTouchCallback = ItemTouchCallback() - itemTouchCallback.onItemTouchCallbackListener = adapter + val itemTouchCallback = ItemTouchCallback(adapter) itemTouchCallback.isCanDrag = true ItemTouchHelper(itemTouchCallback).attachToRecyclerView(recycler_view) tv_cancel.onClick { dismiss() } @@ -111,7 +109,7 @@ class GroupSelectDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener } private fun initData() { - App.db.bookGroupDao().liveDataAll().observe(viewLifecycleOwner, { + App.db.bookGroupDao().liveDataSelect().observe(viewLifecycleOwner, { adapter.setItems(it) }) } @@ -130,7 +128,7 @@ class GroupSelectDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener customView { layoutInflater.inflate(R.layout.dialog_edit_text, null).apply { editText = edit_view.apply { - hint = "分组名称" + setHint(R.string.group_name) } } } @@ -152,7 +150,7 @@ class GroupSelectDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener customView { layoutInflater.inflate(R.layout.dialog_edit_text, null).apply { editText = edit_view.apply { - hint = "分组名称" + setHint(R.string.group_name) setText(bookGroup.groupName) } } @@ -166,7 +164,7 @@ class GroupSelectDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener private inner class GroupAdapter(context: Context) : SimpleRecyclerAdapter(context, R.layout.item_group_select), - ItemTouchCallback.OnItemTouchCallbackListener { + ItemTouchCallback.Callback { private var isMoved: Boolean = false 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 aa3c12557..141c690fb 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 @@ -119,13 +119,7 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) { fun loadGroup(groupId: Long, success: ((groupNames: String?) -> Unit)) { execute { - val groupNames = arrayListOf() - App.db.bookGroupDao().all.forEach { - if (groupId and it.groupId > 0) { - groupNames.add(it.groupName) - } - } - groupNames.joinToString(",") + App.db.bookGroupDao().getGroupNames(groupId).joinToString(",") }.onSuccess { success.invoke(it) } @@ -133,23 +127,36 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) { fun changeTo(newBook: Book) { execute { + var oldTocSize: Int = newBook.totalChapterNum if (inBookshelf) { - bookData.value?.changeTo(newBook) + bookData.value?.let { + oldTocSize = it.totalChapterNum + it.changeTo(newBook) + } } bookData.postValue(newBook) if (newBook.tocUrl.isEmpty()) { - loadBookInfo(newBook, false) { upChangeDurChapterIndex(newBook, it) } + loadBookInfo(newBook, false) { + upChangeDurChapterIndex(newBook, oldTocSize, it) + } } else { - loadChapter(newBook) { upChangeDurChapterIndex(newBook, it) } + loadChapter(newBook) { + upChangeDurChapterIndex(newBook, oldTocSize, it) + } } } } - private fun upChangeDurChapterIndex(book: Book, chapters: List) { + private fun upChangeDurChapterIndex( + book: Book, + oldTocSize: Int, + chapters: List + ) { execute { - book.durChapterIndex = BookHelp.getDurChapterIndexByChapterTitle( - book.durChapterTitle, + book.durChapterIndex = BookHelp.getDurChapter( book.durChapterIndex, + oldTocSize, + book.durChapterTitle, chapters ) book.durChapterTitle = chapters[book.durChapterIndex].title 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 1bf00e95a..648e9d483 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 @@ -157,8 +157,12 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) { fun changeTo(newBook: Book) { execute { + var oldTocSize: Int = newBook.totalChapterNum ReadBook.upMsg(null) - ReadBook.book?.changeTo(newBook) + ReadBook.book?.let { + oldTocSize = it.totalChapterNum + it.changeTo(newBook) + } ReadBook.book = newBook App.db.bookSourceDao().getBookSource(newBook.origin)?.let { ReadBook.webBook = WebBook(it) @@ -171,11 +175,11 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) { } if (newBook.tocUrl.isEmpty()) { loadBookInfo(newBook) { - upChangeDurChapterIndex(newBook, it) + upChangeDurChapterIndex(newBook, oldTocSize, it) } } else { loadChapterList(newBook) { - upChangeDurChapterIndex(newBook, it) + upChangeDurChapterIndex(newBook, oldTocSize, it) } } } @@ -208,11 +212,12 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) { } } - private fun upChangeDurChapterIndex(book: Book, chapters: List) { + private fun upChangeDurChapterIndex(book: Book, oldTocSize: Int, chapters: List) { execute { - ReadBook.durChapterIndex = BookHelp.getDurChapterIndexByChapterTitle( - book.durChapterTitle, + ReadBook.durChapterIndex = BookHelp.getDurChapter( book.durChapterIndex, + oldTocSize, + book.durChapterTitle, chapters ) book.durChapterIndex = ReadBook.durChapterIndex diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadMenu.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadMenu.kt index a532bac2a..277cde943 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadMenu.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadMenu.kt @@ -11,7 +11,6 @@ import android.widget.SeekBar import androidx.core.view.isVisible import io.legado.app.App import io.legado.app.R -import io.legado.app.constant.EventBus import io.legado.app.constant.PreferKey import io.legado.app.help.AppConfig import io.legado.app.help.ReadBookConfig @@ -193,7 +192,6 @@ class ReadMenu : FrameLayout { fabNightTheme.onClick { AppConfig.isNightTheme = !AppConfig.isNightTheme App.INSTANCE.applyDayNight() - postEvent(EventBus.RECREATE, "") } //上一章 diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/TocRegexDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/TocRegexDialog.kt index c0bed1512..3db0fd5c3 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/TocRegexDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/TocRegexDialog.kt @@ -81,8 +81,7 @@ class TocRegexDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener { recycler_view.layoutManager = LinearLayoutManager(requireContext()) recycler_view.addItemDecoration(VerticalDivider(requireContext())) recycler_view.adapter = adapter - val itemTouchCallback = ItemTouchCallback() - itemTouchCallback.onItemTouchCallbackListener = adapter + val itemTouchCallback = ItemTouchCallback(adapter) itemTouchCallback.isCanDrag = true ItemTouchHelper(itemTouchCallback).attachToRecyclerView(recycler_view) tv_cancel.onClick { @@ -199,7 +198,7 @@ class TocRegexDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener { inner class TocRegexAdapter(context: Context) : SimpleRecyclerAdapter(context, R.layout.item_toc_regex), - ItemTouchCallback.OnItemTouchCallbackListener { + ItemTouchCallback.Callback { override fun convert(holder: ItemViewHolder, item: TxtTocRule, payloads: MutableList) { holder.itemView.apply { diff --git a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt index d974431cd..e1310c6cf 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt @@ -166,8 +166,7 @@ class BookSourceActivity : VMBaseActivity(R.layout.activity recycler_view.addItemDecoration(VerticalDivider(this)) adapter = BookSourceAdapter(this, this) recycler_view.adapter = adapter - val itemTouchCallback = ItemTouchCallback() - itemTouchCallback.onItemTouchCallbackListener = adapter + val itemTouchCallback = ItemTouchCallback(adapter) itemTouchCallback.isCanDrag = true val dragSelectTouchHelper: DragSelectTouchHelper = DragSelectTouchHelper(adapter.initDragSelectTouchHelperCallback()).setSlideArea(16, 50) diff --git a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceAdapter.kt b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceAdapter.kt index a5177f443..9e9b4bb90 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceAdapter.kt @@ -14,7 +14,7 @@ import io.legado.app.base.adapter.SimpleRecyclerAdapter import io.legado.app.data.entities.BookSource import io.legado.app.lib.theme.backgroundColor import io.legado.app.ui.widget.recycler.DragSelectTouchHelper -import io.legado.app.ui.widget.recycler.ItemTouchCallback.OnItemTouchCallbackListener +import io.legado.app.ui.widget.recycler.ItemTouchCallback.Callback import io.legado.app.utils.invisible import io.legado.app.utils.visible import kotlinx.android.synthetic.main.item_book_source.view.* @@ -23,7 +23,7 @@ import java.util.* class BookSourceAdapter(context: Context, val callBack: CallBack) : SimpleRecyclerAdapter(context, R.layout.item_book_source), - OnItemTouchCallbackListener { + Callback { private val selected = linkedSetOf() diff --git a/app/src/main/java/io/legado/app/ui/filechooser/utils/ConvertUtils.kt b/app/src/main/java/io/legado/app/ui/filechooser/utils/ConvertUtils.kt index 17d2f15e7..e6ab2c13c 100644 --- a/app/src/main/java/io/legado/app/ui/filechooser/utils/ConvertUtils.kt +++ b/app/src/main/java/io/legado/app/ui/filechooser/utils/ConvertUtils.kt @@ -17,6 +17,7 @@ import java.text.DecimalFormat * @author 李玉江[QQ:1023694760] * @since 2014-4-18 */ +@Suppress("MemberVisibilityCanBePrivate") object ConvertUtils { const val GB: Long = 1073741824 const val MB: Long = 1048576 diff --git a/app/src/main/java/io/legado/app/ui/main/MainActivity.kt b/app/src/main/java/io/legado/app/ui/main/MainActivity.kt index 26879ae87..db221bede 100644 --- a/app/src/main/java/io/legado/app/ui/main/MainActivity.kt +++ b/app/src/main/java/io/legado/app/ui/main/MainActivity.kt @@ -178,48 +178,23 @@ class MainActivity : VMBaseActivity(R.layout.activity_main), private inner class TabFragmentPageAdapter(fm: FragmentManager) : FragmentStatePagerAdapter(fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT) { - val bookshelfFragment: Fragment - get() { - if (!fragmentMap.containsKey(0)) { - fragmentMap[0] = BookshelfFragment() - } - return fragmentMap.getValue(0) - } - - val exploreFragment: Fragment - get() { - if (!fragmentMap.containsKey(1)) { - fragmentMap[1] = ExploreFragment() - } - return fragmentMap.getValue(1) - } - - val rssFragment: Fragment - get() { - if (!fragmentMap.containsKey(2)) { - fragmentMap[2] = RssFragment() - } - return fragmentMap.getValue(2) - } - - val myFragment: Fragment - get() { - if (!fragmentMap.containsKey(3)) { - fragmentMap[3] = MyFragment() - } - return fragmentMap.getValue(3) + private fun getId(position: Int): Int { + return when (position) { + 2 -> if (AppConfig.isShowRSS) 2 else 3 + else -> position } + } override fun getItemPosition(`object`: Any): Int { return POSITION_NONE } override fun getItem(position: Int): Fragment { - return when (position) { - 0 -> bookshelfFragment - 1 -> exploreFragment - 2 -> if (AppConfig.isShowRSS) rssFragment else myFragment - else -> myFragment + return when (getId(position)) { + 0 -> BookshelfFragment() + 1 -> ExploreFragment() + 2 -> RssFragment() + else -> MyFragment() } } @@ -229,13 +204,7 @@ class MainActivity : VMBaseActivity(R.layout.activity_main), override fun instantiateItem(container: ViewGroup, position: Int): Any { val fragment = super.instantiateItem(container, position) as Fragment - val id = when (position) { - 2 -> if (AppConfig.isShowRSS) 2 else 3 - else -> position - } - if (!fragmentMap.containsKey(id)) { - fragmentMap[id] = fragment - } + fragmentMap[getId(position)] = fragment return fragment } diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt index af82c14f1..861e1025c 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt @@ -15,7 +15,6 @@ import io.legado.app.base.VMBaseFragment import io.legado.app.constant.AppConst import io.legado.app.constant.PreferKey import io.legado.app.data.entities.BookGroup -import io.legado.app.help.AppConfig import io.legado.app.lib.dialogs.alert import io.legado.app.lib.dialogs.customView import io.legado.app.lib.dialogs.noButton @@ -36,26 +35,22 @@ import kotlinx.android.synthetic.main.dialog_edit_text.view.* import kotlinx.android.synthetic.main.fragment_bookshelf.* import kotlinx.android.synthetic.main.view_tab_layout.* import kotlinx.android.synthetic.main.view_title_bar.* -import kotlinx.coroutines.Dispatchers.IO -import kotlinx.coroutines.launch -import kotlinx.coroutines.withContext -import org.jetbrains.anko.startActivity - +/** + * 书架界面 + */ class BookshelfFragment : VMBaseFragment(R.layout.fragment_bookshelf), TabLayout.OnTabSelectedListener, - SearchView.OnQueryTextListener, - GroupManageDialog.CallBack { + SearchView.OnQueryTextListener { override val viewModel: BookshelfViewModel get() = getViewModel(BookshelfViewModel::class.java) private val activityViewModel: MainViewModel get() = getViewModelOfActivity(MainViewModel::class.java) + private lateinit var adapter: FragmentStatePagerAdapter private var bookGroupLiveData: LiveData>? = null - private var noGroupLiveData: LiveData? = null private val bookGroups = mutableListOf() private val fragmentMap = hashMapOf() - private var showGroupNone = false override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) { setSupportToolbar(toolbar) @@ -104,63 +99,21 @@ class BookshelfFragment : VMBaseFragment(R.layout.fragment_b tab_layout.setSelectedTabIndicatorColor(requireContext().accentColor) tab_layout.setupWithViewPager(view_pager_bookshelf) view_pager_bookshelf.offscreenPageLimit = 1 - view_pager_bookshelf.adapter = TabFragmentPageAdapter(childFragmentManager) + adapter = TabFragmentPageAdapter(childFragmentManager) + view_pager_bookshelf.adapter = adapter } private fun initBookGroupData() { bookGroupLiveData?.removeObservers(viewLifecycleOwner) - bookGroupLiveData = App.db.bookGroupDao().liveDataAll() + bookGroupLiveData = App.db.bookGroupDao().liveDataShow() bookGroupLiveData?.observe(viewLifecycleOwner, { viewModel.checkGroup(it) - launch { - synchronized(this) { - tab_layout.removeOnTabSelectedListener(this@BookshelfFragment) - } - var noGroupSize = 0 - withContext(IO) { - if (AppConfig.bookGroupNoneShow) { - noGroupSize = App.db.bookDao().noGroupSize - } - } - synchronized(this@BookshelfFragment) { - bookGroups.clear() - if (AppConfig.bookGroupAllShow) { - bookGroups.add(AppConst.bookGroupAll) - } - if (AppConfig.bookGroupLocalShow) { - bookGroups.add(AppConst.bookGroupLocal) - } - if (AppConfig.bookGroupAudioShow) { - bookGroups.add(AppConst.bookGroupAudio) - } - showGroupNone = if (noGroupSize > 0 && it.isNotEmpty()) { - bookGroups.add(AppConst.bookGroupNone) - true - } else { - false - } - bookGroups.addAll(it) - view_pager_bookshelf.adapter?.notifyDataSetChanged() - tab_layout.getTabAt(getPrefInt(PreferKey.saveTabPosition, 0))?.select() - tab_layout.addOnTabSelectedListener(this@BookshelfFragment) - } - } - }) - noGroupLiveData?.removeObservers(viewLifecycleOwner) - noGroupLiveData = App.db.bookDao().observeNoGroupSize() - noGroupLiveData?.observe(viewLifecycleOwner, { - if (it > 0 && !showGroupNone && AppConfig.bookGroupNoneShow) { - showGroupNone = true - upGroup() - } else if (it == 0 && showGroupNone) { - showGroupNone = false - upGroup() - } + upGroup(it) }) } override fun onQueryTextSubmit(query: String?): Boolean { - context?.startActivity(Pair("key", query)) + startActivity(Pair("key", query)) return false } @@ -168,40 +121,25 @@ class BookshelfFragment : VMBaseFragment(R.layout.fragment_b return false } - override fun upGroup() { - launch { - var noGroupSize = 0 - withContext(IO) { - if (AppConfig.bookGroupNoneShow) { - noGroupSize = App.db.bookDao().noGroupSize - } - } - synchronized(this@BookshelfFragment) { - bookGroups.remove(AppConst.bookGroupAll) - bookGroups.remove(AppConst.bookGroupLocal) - bookGroups.remove(AppConst.bookGroupAudio) - bookGroups.remove(AppConst.bookGroupNone) - showGroupNone = - if (noGroupSize > 0 && bookGroups.isNotEmpty()) { - bookGroups.add(0, AppConst.bookGroupNone) - true - } else { - false - } - if (AppConfig.bookGroupAudioShow) { - bookGroups.add(0, AppConst.bookGroupAudio) - } - if (AppConfig.bookGroupLocalShow) { - bookGroups.add(0, AppConst.bookGroupLocal) - } - if (AppConfig.bookGroupAllShow) { - bookGroups.add(0, AppConst.bookGroupAll) - } - view_pager_bookshelf.adapter?.notifyDataSetChanged() - } + @Synchronized + private fun upGroup(data: List) { + if (data.isEmpty()) { + App.db.bookGroupDao().enableGroup(AppConst.bookGroupAllId) + } else { + bookGroups.clear() + bookGroups.addAll(data) + adapter.notifyDataSetChanged() + selectLastTab() } } + @Synchronized + private fun selectLastTab() { + tab_layout.removeOnTabSelectedListener(this) + tab_layout.getTabAt(getPrefInt(PreferKey.saveTabPosition, 0))?.select() + tab_layout.addOnTabSelectedListener(this) + } + @SuppressLint("InflateParams") private fun configBookshelf() { requireContext().alert(titleResource = R.string.bookshelf_layout) { @@ -252,14 +190,12 @@ class BookshelfFragment : VMBaseFragment(R.layout.fragment_b }.show().applyTint() } - override fun onTabReselected(tab: TabLayout.Tab?) = Unit + override fun onTabReselected(tab: TabLayout.Tab) = Unit - override fun onTabUnselected(tab: TabLayout.Tab?) = Unit + override fun onTabUnselected(tab: TabLayout.Tab) = Unit - override fun onTabSelected(tab: TabLayout.Tab?) { - tab?.position?.let { - putPrefInt(PreferKey.saveTabPosition, it) - } + override fun onTabSelected(tab: TabLayout.Tab) { + putPrefInt(PreferKey.saveTabPosition, tab.position) } fun gotoTop() { @@ -294,9 +230,7 @@ class BookshelfFragment : VMBaseFragment(R.layout.fragment_b override fun instantiateItem(container: ViewGroup, position: Int): Any { val fragment = super.instantiateItem(container, position) as BooksFragment val group = bookGroups[position] - if (!fragmentMap.containsKey(group.groupId)) { - fragmentMap[group.groupId] = fragment - } + fragmentMap[group.groupId] = fragment return fragment } 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 298b84cca..afd80af8e 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 @@ -63,18 +63,16 @@ class BookshelfViewModel(application: Application) : BaseViewModel(application) } fun checkGroup(groups: List) { - execute { - groups.forEach { group -> - if (group.groupId and (group.groupId - 1) != 0L) { - var id = 1L - val idsSum = App.db.bookGroupDao().idsSum - while (id and idsSum != 0L) { - id = id.shl(1) - } - App.db.bookGroupDao().delete(group) - App.db.bookGroupDao().insert(group.copy(groupId = id)) - App.db.bookDao().upGroup(group.groupId, id) + groups.forEach { group -> + if (group.groupId >= 0 && group.groupId and (group.groupId - 1) != 0L) { + var id = 1L + val idsSum = App.db.bookGroupDao().idsSum + while (id and idsSum != 0L) { + id = id.shl(1) } + App.db.bookGroupDao().delete(group) + App.db.bookGroupDao().insert(group.copy(groupId = id)) + App.db.bookDao().upGroup(group.groupId, id) } } } diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksFragment.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksFragment.kt index eec10578c..ebd3e8cad 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksFragment.kt @@ -29,7 +29,6 @@ import io.legado.app.utils.getViewModelOfActivity import io.legado.app.utils.observeEvent import io.legado.app.utils.startActivity import kotlinx.android.synthetic.main.fragment_books.* -import org.jetbrains.anko.startActivity import kotlin.math.max /** @@ -61,7 +60,6 @@ class BooksFragment : BaseFragment(R.layout.fragment_books), position = it.getInt("position", 0) groupId = it.getLong("groupId", -1) } - tv_empty_msg.setText(R.string.bookshelf_empty) initRecyclerView() upRecyclerData() } @@ -104,10 +102,10 @@ class BooksFragment : BaseFragment(R.layout.fragment_books), private fun upRecyclerData() { bookshelfLiveData?.removeObservers(this) bookshelfLiveData = when (groupId) { - AppConst.bookGroupAll.groupId -> App.db.bookDao().observeAll() - AppConst.bookGroupLocal.groupId -> App.db.bookDao().observeLocal() - AppConst.bookGroupAudio.groupId -> App.db.bookDao().observeAudio() - AppConst.bookGroupNone.groupId -> App.db.bookDao().observeNoGroup() + AppConst.bookGroupAllId -> App.db.bookDao().observeAll() + AppConst.bookGroupLocalId -> App.db.bookDao().observeLocal() + AppConst.bookGroupAudioId -> App.db.bookDao().observeAudio() + AppConst.bookGroupNoneId -> App.db.bookDao().observeNoGroup() else -> App.db.bookDao().observeByGroup(groupId) } bookshelfLiveData?.observe(this, { list -> @@ -139,8 +137,8 @@ class BooksFragment : BaseFragment(R.layout.fragment_books), override fun open(book: Book) { when (book.type) { BookType.audio -> - context?.startActivity(Pair("bookUrl", book.bookUrl)) - else -> context?.startActivity( + startActivity(Pair("bookUrl", book.bookUrl)) + else -> startActivity( Pair("bookUrl", book.bookUrl), Pair("key", IntentDataHelp.putData(book)) ) diff --git a/app/src/main/java/io/legado/app/ui/main/explore/ExploreFragment.kt b/app/src/main/java/io/legado/app/ui/main/explore/ExploreFragment.kt index e1fb1c814..ee9685145 100644 --- a/app/src/main/java/io/legado/app/ui/main/explore/ExploreFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/explore/ExploreFragment.kt @@ -24,7 +24,7 @@ import io.legado.app.ui.book.source.edit.BookSourceEditActivity import io.legado.app.utils.getViewModel import io.legado.app.utils.splitNotBlank import io.legado.app.utils.startActivity -import kotlinx.android.synthetic.main.fragment_find_book.* +import kotlinx.android.synthetic.main.fragment_explore.* import kotlinx.android.synthetic.main.view_search.* import kotlinx.android.synthetic.main.view_title_bar.* import java.text.Collator @@ -32,7 +32,7 @@ import java.text.Collator /** * 发现界面 */ -class ExploreFragment : VMBaseFragment(R.layout.fragment_find_book), +class ExploreFragment : VMBaseFragment(R.layout.fragment_explore), ExploreAdapter.CallBack { override val viewModel: ExploreViewModel get() = getViewModel(ExploreViewModel::class.java) @@ -46,7 +46,6 @@ class ExploreFragment : VMBaseFragment(R.layout.fragment_find_ override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) { setSupportToolbar(toolbar) - tv_empty_msg.setText(R.string.explore_empty) initSearchView() initRecyclerView() initGroupData() @@ -115,7 +114,7 @@ class ExploreFragment : VMBaseFragment(R.layout.fragment_find_ App.db.bookSourceDao().liveExplore("%$key%") } liveExplore?.observe(viewLifecycleOwner, { - tv_empty_msg.isGone = it.isNotEmpty() + tv_empty_msg.isGone = it.isNotEmpty() || search_view.query.isNotEmpty() val diffResult = DiffUtil .calculateDiff(ExploreDiffCallBack(ArrayList(adapter.getItems()), it)) adapter.setItems(it) diff --git a/app/src/main/java/io/legado/app/ui/main/rss/RssFragment.kt b/app/src/main/java/io/legado/app/ui/main/rss/RssFragment.kt index 34e9f0dc5..834c77121 100644 --- a/app/src/main/java/io/legado/app/ui/main/rss/RssFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/rss/RssFragment.kt @@ -34,7 +34,6 @@ class RssFragment : VMBaseFragment(R.layout.fragment_rss), override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) { setSupportToolbar(toolbar) - tv_empty_msg.setText(R.string.rss_source_empty) initRecyclerView() initData() } diff --git a/app/src/main/java/io/legado/app/ui/replace/ReplaceRuleActivity.kt b/app/src/main/java/io/legado/app/ui/replace/ReplaceRuleActivity.kt index 302c59b6d..3e091cded 100644 --- a/app/src/main/java/io/legado/app/ui/replace/ReplaceRuleActivity.kt +++ b/app/src/main/java/io/legado/app/ui/replace/ReplaceRuleActivity.kt @@ -87,8 +87,7 @@ class ReplaceRuleActivity : adapter = ReplaceRuleAdapter(this, this) recycler_view.adapter = adapter recycler_view.addItemDecoration(VerticalDivider(this)) - val itemTouchCallback = ItemTouchCallback() - itemTouchCallback.onItemTouchCallbackListener = adapter + val itemTouchCallback = ItemTouchCallback(adapter) itemTouchCallback.isCanDrag = true val dragSelectTouchHelper: DragSelectTouchHelper = DragSelectTouchHelper(adapter.initDragSelectTouchHelperCallback()).setSlideArea(16, 50) diff --git a/app/src/main/java/io/legado/app/ui/replace/ReplaceRuleAdapter.kt b/app/src/main/java/io/legado/app/ui/replace/ReplaceRuleAdapter.kt index 14c42568a..31d0eb59f 100644 --- a/app/src/main/java/io/legado/app/ui/replace/ReplaceRuleAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/replace/ReplaceRuleAdapter.kt @@ -20,7 +20,7 @@ import java.util.* class ReplaceRuleAdapter(context: Context, var callBack: CallBack) : SimpleRecyclerAdapter(context, R.layout.item_replace_rule), - ItemTouchCallback.OnItemTouchCallbackListener { + ItemTouchCallback.Callback { private val selected = linkedSetOf() diff --git a/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt b/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt index 05885d183..eae5f3457 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt @@ -114,8 +114,7 @@ class RssSourceActivity : VMBaseActivity(R.layout.activity_r recycler_view.addItemDecoration(VerticalDivider(this)) adapter = RssSourceAdapter(this, this) recycler_view.adapter = adapter - val itemTouchCallback = ItemTouchCallback() - itemTouchCallback.onItemTouchCallbackListener = adapter + val itemTouchCallback = ItemTouchCallback(adapter) itemTouchCallback.isCanDrag = true val dragSelectTouchHelper: DragSelectTouchHelper = DragSelectTouchHelper(adapter.initDragSelectTouchHelperCallback()).setSlideArea(16, 50) diff --git a/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceAdapter.kt b/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceAdapter.kt index 2652503b3..acd7aa723 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceAdapter.kt @@ -19,7 +19,7 @@ import java.util.* class RssSourceAdapter(context: Context, val callBack: CallBack) : SimpleRecyclerAdapter(context, R.layout.item_rss_source), - ItemTouchCallback.OnItemTouchCallbackListener { + ItemTouchCallback.Callback { private val selected = linkedSetOf() diff --git a/app/src/main/java/io/legado/app/ui/widget/LabelsBar.kt b/app/src/main/java/io/legado/app/ui/widget/LabelsBar.kt index a2f354772..4d51c5b80 100644 --- a/app/src/main/java/io/legado/app/ui/widget/LabelsBar.kt +++ b/app/src/main/java/io/legado/app/ui/widget/LabelsBar.kt @@ -7,7 +7,7 @@ import android.widget.TextView import io.legado.app.ui.widget.text.AccentBgTextView import io.legado.app.utils.dp -@Suppress("unused") +@Suppress("unused", "MemberVisibilityCanBePrivate") class LabelsBar(context: Context, attrs: AttributeSet?) : LinearLayout(context, attrs) { private val unUsedViews = arrayListOf() diff --git a/app/src/main/java/io/legado/app/ui/widget/SearchView.kt b/app/src/main/java/io/legado/app/ui/widget/SearchView.kt index 6d340c6d7..2f83c8594 100644 --- a/app/src/main/java/io/legado/app/ui/widget/SearchView.kt +++ b/app/src/main/java/io/legado/app/ui/widget/SearchView.kt @@ -1,5 +1,6 @@ package io.legado.app.ui.widget +import android.annotation.SuppressLint import android.app.SearchableInfo import android.content.Context import android.graphics.Canvas @@ -30,6 +31,7 @@ class SearchView : SearchView { defStyleAttr: Int ) : super(context, attrs, defStyleAttr) + @SuppressLint("UseCompatLoadingForDrawables") override fun onLayout( changed: Boolean, left: Int, diff --git a/app/src/main/java/io/legado/app/ui/widget/SelectActionBar.kt b/app/src/main/java/io/legado/app/ui/widget/SelectActionBar.kt index 7cba90778..fd478ae42 100644 --- a/app/src/main/java/io/legado/app/ui/widget/SelectActionBar.kt +++ b/app/src/main/java/io/legado/app/ui/widget/SelectActionBar.kt @@ -16,6 +16,7 @@ import io.legado.app.utils.visible import kotlinx.android.synthetic.main.view_select_action_bar.view.* import org.jetbrains.anko.sdk27.listeners.onClick +@Suppress("unused") class SelectActionBar(context: Context, attrs: AttributeSet?) : FrameLayout(context, attrs) { private var callBack: CallBack? = null private var selMenu: PopupMenu? = null 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 index 0f6ad3200..76668e772 100644 --- a/app/src/main/java/io/legado/app/ui/widget/ShadowLayout.kt +++ b/app/src/main/java/io/legado/app/ui/widget/ShadowLayout.kt @@ -17,6 +17,7 @@ import io.legado.app.utils.getCompatColor * * Created by lijiankun on 17/8/11. */ +@Suppress("unused") class ShadowLayout( context: Context, attrs: AttributeSet? = null diff --git a/app/src/main/java/io/legado/app/ui/widget/TitleBar.kt b/app/src/main/java/io/legado/app/ui/widget/TitleBar.kt index 2143b4e48..a30873671 100644 --- a/app/src/main/java/io/legado/app/ui/widget/TitleBar.kt +++ b/app/src/main/java/io/legado/app/ui/widget/TitleBar.kt @@ -21,6 +21,7 @@ import org.jetbrains.anko.backgroundColor import org.jetbrains.anko.bottomPadding import org.jetbrains.anko.topPadding +@Suppress("unused") class TitleBar(context: Context, attrs: AttributeSet?) : AppBarLayout(context, attrs) { val toolbar: Toolbar diff --git a/app/src/main/java/io/legado/app/ui/widget/anima/RefreshProgressBar.kt b/app/src/main/java/io/legado/app/ui/widget/anima/RefreshProgressBar.kt index df123bfcd..1791b3be7 100644 --- a/app/src/main/java/io/legado/app/ui/widget/anima/RefreshProgressBar.kt +++ b/app/src/main/java/io/legado/app/ui/widget/anima/RefreshProgressBar.kt @@ -11,6 +11,7 @@ import android.view.View import io.legado.app.R +@Suppress("unused", "MemberVisibilityCanBePrivate") class RefreshProgressBar @JvmOverloads constructor( context: Context, attrs: AttributeSet? = null, diff --git a/app/src/main/java/io/legado/app/ui/widget/anima/RotateLoading.kt b/app/src/main/java/io/legado/app/ui/widget/anima/RotateLoading.kt index 7a5e436c3..13c4f346d 100644 --- a/app/src/main/java/io/legado/app/ui/widget/anima/RotateLoading.kt +++ b/app/src/main/java/io/legado/app/ui/widget/anima/RotateLoading.kt @@ -17,6 +17,7 @@ import io.legado.app.utils.dp * RotateLoading * Created by Victor on 2015/4/28. */ +@Suppress("MemberVisibilityCanBePrivate") class RotateLoading : View { private lateinit var mPaint: Paint diff --git a/app/src/main/java/io/legado/app/ui/widget/anima/explosion_field/ExplosionAnimator.kt b/app/src/main/java/io/legado/app/ui/widget/anima/explosion_field/ExplosionAnimator.kt index 9b80b1825..6542ea55f 100644 --- a/app/src/main/java/io/legado/app/ui/widget/anima/explosion_field/ExplosionAnimator.kt +++ b/app/src/main/java/io/legado/app/ui/widget/anima/explosion_field/ExplosionAnimator.kt @@ -20,6 +20,7 @@ import android.graphics.* import android.view.View import android.view.animation.AccelerateInterpolator import java.util.* +import kotlin.math.pow class ExplosionAnimator(private val mContainer: View, bitmap: Bitmap, bound: Rect) : ValueAnimator() { @@ -99,20 +100,20 @@ class ExplosionAnimator(private val mContainer: View, bitmap: Bitmap, bound: Rec } private inner class Particle { - internal var alpha: Float = 0.toFloat() - internal var color: Int = 0 - internal var cx: Float = 0.toFloat() - internal var cy: Float = 0.toFloat() - internal var radius: Float = 0.toFloat() - internal var baseCx: Float = 0.toFloat() - internal var baseCy: Float = 0.toFloat() - internal var baseRadius: Float = 0.toFloat() - internal var top: Float = 0.toFloat() - internal var bottom: Float = 0.toFloat() - internal var mag: Float = 0.toFloat() - internal var neg: Float = 0.toFloat() - internal var life: Float = 0.toFloat() - internal var overflow: Float = 0.toFloat() + var alpha: Float = 0.toFloat() + var color: Int = 0 + var cx: Float = 0.toFloat() + var cy: Float = 0.toFloat() + var radius: Float = 0.toFloat() + var baseCx: Float = 0.toFloat() + var baseCy: Float = 0.toFloat() + var baseRadius: Float = 0.toFloat() + var top: Float = 0.toFloat() + var bottom: Float = 0.toFloat() + var mag: Float = 0.toFloat() + var neg: Float = 0.toFloat() + var life: Float = 0.toFloat() + var overflow: Float = 0.toFloat() fun advance(factor: Float) { @@ -130,7 +131,7 @@ class ExplosionAnimator(private val mContainer: View, bitmap: Bitmap, bound: Rec alpha = 1f - f f = bottom * f2 cx = baseCx + f - cy = (baseCy - this.neg * Math.pow(f.toDouble(), 2.0)).toFloat() - f * mag + cy = (baseCy - this.neg * f.toDouble().pow(2.0)).toFloat() - f * mag radius = V + (baseRadius - V) * f2 } } diff --git a/app/src/main/java/io/legado/app/ui/widget/anima/explosion_field/ExplosionView.kt b/app/src/main/java/io/legado/app/ui/widget/anima/explosion_field/ExplosionView.kt index c79695a51..9eef530f2 100644 --- a/app/src/main/java/io/legado/app/ui/widget/anima/explosion_field/ExplosionView.kt +++ b/app/src/main/java/io/legado/app/ui/widget/anima/explosion_field/ExplosionView.kt @@ -29,6 +29,7 @@ import android.view.View import java.util.* +@Suppress("unused") class ExplosionView : View { private var customDuration = ExplosionAnimator.DEFAULT_DURATION @@ -75,8 +76,8 @@ class ExplosionView : View { this.customDuration = customDuration } - fun addActionEvent(ievents: OnAnimatorListener) { - this.mZAnimatorListener = ievents + fun addActionEvent(iEvents: OnAnimatorListener) { + this.mZAnimatorListener = iEvents } diff --git a/app/src/main/java/io/legado/app/ui/widget/dynamiclayout/DynamicFrameLayout.kt b/app/src/main/java/io/legado/app/ui/widget/dynamiclayout/DynamicFrameLayout.kt index 99e0cd702..683cbc5d9 100644 --- a/app/src/main/java/io/legado/app/ui/widget/dynamiclayout/DynamicFrameLayout.kt +++ b/app/src/main/java/io/legado/app/ui/widget/dynamiclayout/DynamicFrameLayout.kt @@ -12,6 +12,7 @@ import androidx.appcompat.widget.AppCompatTextView import io.legado.app.R import kotlinx.android.synthetic.main.view_dynamic.view.* +@Suppress("unused") class DynamicFrameLayout(context: Context, attrs: AttributeSet?) : FrameLayout(context, attrs), ViewSwitcher { private var errorView: View? = null diff --git a/app/src/main/java/io/legado/app/ui/widget/image/CircleImageView.kt b/app/src/main/java/io/legado/app/ui/widget/image/CircleImageView.kt index 43e3f5506..b1d1a5376 100644 --- a/app/src/main/java/io/legado/app/ui/widget/image/CircleImageView.kt +++ b/app/src/main/java/io/legado/app/ui/widget/image/CircleImageView.kt @@ -24,6 +24,7 @@ import io.legado.app.utils.sp import kotlin.math.min import kotlin.math.pow +@Suppress("unused", "MemberVisibilityCanBePrivate") class CircleImageView(context: Context, attrs: AttributeSet) : AppCompatImageView( context, diff --git a/app/src/main/java/io/legado/app/ui/widget/image/CoverImageView.kt b/app/src/main/java/io/legado/app/ui/widget/image/CoverImageView.kt index f2b4373a4..52b0517c2 100644 --- a/app/src/main/java/io/legado/app/ui/widget/image/CoverImageView.kt +++ b/app/src/main/java/io/legado/app/ui/widget/image/CoverImageView.kt @@ -16,7 +16,10 @@ import io.legado.app.constant.PreferKey import io.legado.app.help.ImageLoader import io.legado.app.utils.getPrefString - +/** + * 封面 + */ +@Suppress("unused") class CoverImageView : androidx.appcompat.widget.AppCompatImageView { internal var width: Float = 0.toFloat() internal var height: Float = 0.toFloat() @@ -171,6 +174,7 @@ class CoverImageView : androidx.appcompat.widget.AppCompatImageView { upDefaultCover() } + @SuppressLint("UseCompatLoadingForDrawables") fun upDefaultCover() { val path = App.INSTANCE.getPrefString(PreferKey.defaultCover) var dw = Drawable.createFromPath(path) diff --git a/app/src/main/java/io/legado/app/ui/widget/image/PhotoView.kt b/app/src/main/java/io/legado/app/ui/widget/image/PhotoView.kt index 44f108e91..5a2c7588f 100644 --- a/app/src/main/java/io/legado/app/ui/widget/image/PhotoView.kt +++ b/app/src/main/java/io/legado/app/ui/widget/image/PhotoView.kt @@ -24,6 +24,7 @@ import kotlin.math.abs import kotlin.math.roundToInt +@Suppress("UNUSED_PARAMETER", "unused", "MemberVisibilityCanBePrivate") @SuppressLint("AppCompatCustomView") class PhotoView : ImageView { val MIN_ROTATE = 35 @@ -197,6 +198,7 @@ class PhotoView : ImageView { MAX_ANIM_FROM_WAITE = wait } + @SuppressLint("UseCompatLoadingForDrawables") override fun setImageResource(resId: Int) { var drawable: Drawable? = null try { @@ -832,7 +834,7 @@ class PhotoView : ImageView { } - private inner class Transform internal constructor() : Runnable { + private inner class Transform : Runnable { var isRunning = false var mTranslateScroller: OverScroller var mFlingScroller: OverScroller @@ -1230,7 +1232,7 @@ class PhotoView : ImageView { val scale = if (scaleX > scaleY) scaleX else scaleY mAnimMatrix.postRotate(mDegrees, mScaleCenter.x, mScaleCenter.y) mAnimMatrix.mapRect(mImgRect, mBaseRect) - mDegrees = mDegrees % 360 + mDegrees %= 360 mTranslate.withTranslate( 0, 0, diff --git a/app/src/main/java/io/legado/app/ui/widget/image/photo/Info.kt b/app/src/main/java/io/legado/app/ui/widget/image/photo/Info.kt index abd6f9080..6ce1adfc6 100644 --- a/app/src/main/java/io/legado/app/ui/widget/image/photo/Info.kt +++ b/app/src/main/java/io/legado/app/ui/widget/image/photo/Info.kt @@ -6,6 +6,7 @@ import android.graphics.RectF import android.widget.ImageView +@Suppress("MemberVisibilityCanBePrivate") class Info( rect: RectF, img: RectF, diff --git a/app/src/main/java/io/legado/app/ui/widget/image/photo/RotateGestureDetector.kt b/app/src/main/java/io/legado/app/ui/widget/image/photo/RotateGestureDetector.kt index 77c8c232d..7dddbebbf 100644 --- a/app/src/main/java/io/legado/app/ui/widget/image/photo/RotateGestureDetector.kt +++ b/app/src/main/java/io/legado/app/ui/widget/image/photo/RotateGestureDetector.kt @@ -26,26 +26,26 @@ class RotateGestureDetector(private val mListener: OnRotateListener) { MotionEvent.ACTION_MOVE -> if (event.pointerCount > 1) { mCurrSlope = calculateSlope(event) - val currDegrees = Math.toDegrees(atan(mCurrSlope.toDouble())); - val prevDegrees = Math.toDegrees(atan(mPrevSlope.toDouble())); + val currDegrees = Math.toDegrees(atan(mCurrSlope.toDouble())) + val prevDegrees = Math.toDegrees(atan(mPrevSlope.toDouble())) - val deltaSlope = currDegrees - prevDegrees; + val deltaSlope = currDegrees - prevDegrees if (abs(deltaSlope) <= MAX_DEGREES_STEP) { - mListener.onRotate(deltaSlope.toFloat(), (x2 + x1) / 2, (y2 + y1) / 2); + mListener.onRotate(deltaSlope.toFloat(), (x2 + x1) / 2, (y2 + y1) / 2) } - mPrevSlope = mCurrSlope; + mPrevSlope = mCurrSlope } } } private fun calculateSlope(event: MotionEvent): Float { - val x1 = event.getX(0); - val y1 = event.getY(0); - val x2 = event.getX(1); - val y2 = event.getY(1); - return (y2 - y1) / (x2 - x1); + val x1 = event.getX(0) + val y1 = event.getY(0) + val x2 = event.getX(1) + val y2 = event.getY(1) + return (y2 - y1) / (x2 - x1) } } diff --git a/app/src/main/java/io/legado/app/ui/widget/number/NumberPickerDialog.kt b/app/src/main/java/io/legado/app/ui/widget/number/NumberPickerDialog.kt index 3b4c8f5db..91dd8ffa3 100644 --- a/app/src/main/java/io/legado/app/ui/widget/number/NumberPickerDialog.kt +++ b/app/src/main/java/io/legado/app/ui/widget/number/NumberPickerDialog.kt @@ -48,7 +48,7 @@ class NumberPickerDialog(context: Context) { listener?.invoke() } } - return this; + return this } fun show(callBack: ((value: Int) -> Unit)?) { 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 8f293eebb..468f4ce71 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 @@ -16,6 +16,7 @@ import com.jaredrummler.android.colorpicker.* import io.legado.app.lib.theme.ATH import io.legado.app.utils.ColorUtils +@Suppress("MemberVisibilityCanBePrivate", "unused") class ColorPreference(context: Context, attrs: AttributeSet) : Preference(context, attrs), ColorPickerDialogListener { diff --git a/app/src/main/java/io/legado/app/ui/widget/recycler/DividerNoLast.kt b/app/src/main/java/io/legado/app/ui/widget/recycler/DividerNoLast.kt index 5c9e38e4d..92ac1a672 100644 --- a/app/src/main/java/io/legado/app/ui/widget/recycler/DividerNoLast.kt +++ b/app/src/main/java/io/legado/app/ui/widget/recycler/DividerNoLast.kt @@ -14,6 +14,7 @@ import kotlin.math.roundToInt /** * 不画最后一条分隔线 */ +@Suppress("MemberVisibilityCanBePrivate", "RedundantRequireNotNullCall", "unused") class DividerNoLast(context: Context, orientation: Int) : RecyclerView.ItemDecoration() { diff --git a/app/src/main/java/io/legado/app/ui/widget/recycler/DragSelectTouchHelper.kt b/app/src/main/java/io/legado/app/ui/widget/recycler/DragSelectTouchHelper.kt index 015595ec1..baa4645bb 100644 --- a/app/src/main/java/io/legado/app/ui/widget/recycler/DragSelectTouchHelper.kt +++ b/app/src/main/java/io/legado/app/ui/widget/recycler/DragSelectTouchHelper.kt @@ -51,7 +51,7 @@ import kotlin.math.min * | | ----------------------------------------------> | | * +-------------------+ +-----------------------+ */ -@Suppress("unused") +@Suppress("unused", "MemberVisibilityCanBePrivate") class DragSelectTouchHelper( /** * Developer callback which controls the behavior of DragSelectTouchHelper. diff --git a/app/src/main/java/io/legado/app/ui/widget/recycler/ItemTouchCallback.kt b/app/src/main/java/io/legado/app/ui/widget/recycler/ItemTouchCallback.kt index b015a0086..368fd8c36 100644 --- a/app/src/main/java/io/legado/app/ui/widget/recycler/ItemTouchCallback.kt +++ b/app/src/main/java/io/legado/app/ui/widget/recycler/ItemTouchCallback.kt @@ -12,20 +12,17 @@ import androidx.viewpager.widget.ViewPager * Created by GKF on 2018/3/16. */ -class ItemTouchCallback : ItemTouchHelper.Callback() { +@Suppress("MemberVisibilityCanBePrivate") +class ItemTouchCallback(private val callback: Callback) : ItemTouchHelper.Callback() { private var swipeRefreshLayout: SwipeRefreshLayout? = null private var viewPager: ViewPager? = null - /** - * Item操作的回调 - */ - var onItemTouchCallbackListener: OnItemTouchCallbackListener? = null - /** * 是否可以拖拽 */ var isCanDrag = false + /** * 是否可以被滑动 */ @@ -88,13 +85,11 @@ class ItemTouchCallback : ItemTouchHelper.Callback() { srcViewHolder: RecyclerView.ViewHolder, targetViewHolder: RecyclerView.ViewHolder ): Boolean { - return onItemTouchCallbackListener - ?.onMove(srcViewHolder.adapterPosition, targetViewHolder.adapterPosition) - ?: false + return callback.onMove(srcViewHolder.adapterPosition, targetViewHolder.adapterPosition) } override fun onSwiped(viewHolder: RecyclerView.ViewHolder, direction: Int) { - onItemTouchCallbackListener?.onSwiped(viewHolder.adapterPosition) + callback.onSwiped(viewHolder.adapterPosition) } override fun onSelectedChanged(viewHolder: RecyclerView.ViewHolder?, actionState: Int) { @@ -106,10 +101,10 @@ class ItemTouchCallback : ItemTouchHelper.Callback() { override fun clearView(recyclerView: RecyclerView, viewHolder: RecyclerView.ViewHolder) { super.clearView(recyclerView, viewHolder) - onItemTouchCallbackListener?.onClearView(recyclerView, viewHolder) + callback.onClearView(recyclerView, viewHolder) } - interface OnItemTouchCallbackListener { + interface Callback { /** * 当某个Item被滑动删除的时候 diff --git a/app/src/main/java/io/legado/app/ui/widget/recycler/LoadMoreView.kt b/app/src/main/java/io/legado/app/ui/widget/recycler/LoadMoreView.kt index a2437c0b4..01cb906cb 100644 --- a/app/src/main/java/io/legado/app/ui/widget/recycler/LoadMoreView.kt +++ b/app/src/main/java/io/legado/app/ui/widget/recycler/LoadMoreView.kt @@ -9,6 +9,7 @@ import io.legado.app.utils.invisible import io.legado.app.utils.visible import kotlinx.android.synthetic.main.view_load_more.view.* +@Suppress("unused") class LoadMoreView(context: Context) : FrameLayout(context) { var hasMore = true diff --git a/app/src/main/java/io/legado/app/ui/widget/recycler/UpLinearLayoutManager.kt b/app/src/main/java/io/legado/app/ui/widget/recycler/UpLinearLayoutManager.kt index 0af559c45..1dfd9ec9a 100644 --- a/app/src/main/java/io/legado/app/ui/widget/recycler/UpLinearLayoutManager.kt +++ b/app/src/main/java/io/legado/app/ui/widget/recycler/UpLinearLayoutManager.kt @@ -4,6 +4,7 @@ import android.content.Context import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearSmoothScroller +@Suppress("MemberVisibilityCanBePrivate", "unused") class UpLinearLayoutManager(val context: Context) : LinearLayoutManager(context) { fun smoothScrollToPosition(position: Int) { diff --git a/app/src/main/java/io/legado/app/ui/widget/recycler/scroller/FastScrollRecyclerView.kt b/app/src/main/java/io/legado/app/ui/widget/recycler/scroller/FastScrollRecyclerView.kt index f080f5cba..35623f5e2 100644 --- a/app/src/main/java/io/legado/app/ui/widget/recycler/scroller/FastScrollRecyclerView.kt +++ b/app/src/main/java/io/legado/app/ui/widget/recycler/scroller/FastScrollRecyclerView.kt @@ -7,6 +7,7 @@ import androidx.annotation.ColorInt import androidx.recyclerview.widget.RecyclerView import io.legado.app.R +@Suppress("MemberVisibilityCanBePrivate", "unused") class FastScrollRecyclerView : RecyclerView { private lateinit var mFastScroller: FastScroller diff --git a/app/src/main/java/io/legado/app/ui/widget/recycler/scroller/FastScroller.kt b/app/src/main/java/io/legado/app/ui/widget/recycler/scroller/FastScroller.kt index 7a66873d5..a8372689e 100644 --- a/app/src/main/java/io/legado/app/ui/widget/recycler/scroller/FastScroller.kt +++ b/app/src/main/java/io/legado/app/ui/widget/recycler/scroller/FastScroller.kt @@ -33,9 +33,11 @@ import kotlin.math.min import kotlin.math.roundToInt +@Suppress("SameParameterValue") class FastScroller : LinearLayout { @ColorInt private var mBubbleColor: Int = 0 + @ColorInt private var mHandleColor: Int = 0 private var mBubbleHeight: Int = 0 diff --git a/app/src/main/java/io/legado/app/ui/widget/seekbar/VerticalSeekBar.kt b/app/src/main/java/io/legado/app/ui/widget/seekbar/VerticalSeekBar.kt index f08e2b3c6..ab4509954 100644 --- a/app/src/main/java/io/legado/app/ui/widget/seekbar/VerticalSeekBar.kt +++ b/app/src/main/java/io/legado/app/ui/widget/seekbar/VerticalSeekBar.kt @@ -16,6 +16,7 @@ import io.legado.app.lib.theme.ThemeStore import java.lang.reflect.InvocationTargetException import java.lang.reflect.Method +@Suppress("SameParameterValue") class VerticalSeekBar : AppCompatSeekBar { private var mIsDragging: Boolean = false diff --git a/app/src/main/java/io/legado/app/utils/ACache.kt b/app/src/main/java/io/legado/app/utils/ACache.kt index 03a330d6a..6a0a0b9fb 100644 --- a/app/src/main/java/io/legado/app/utils/ACache.kt +++ b/app/src/main/java/io/legado/app/utils/ACache.kt @@ -22,7 +22,7 @@ import kotlin.math.min /** * 本地缓存 */ -@Suppress("unused") +@Suppress("unused", "MemberVisibilityCanBePrivate") class ACache private constructor(cacheDir: File, max_size: Long, max_count: Int) { companion object { @@ -543,6 +543,7 @@ class ACache private constructor(cacheDir: File, max_size: Long, max_count: Int) return null } + @Suppress("SameParameterValue") private fun indexOf(data: ByteArray, c: Char): Int { for (i in data.indices) { if (data[i] == c.toByte()) { diff --git a/app/src/main/java/io/legado/app/utils/BitmapUtils.kt b/app/src/main/java/io/legado/app/utils/BitmapUtils.kt index 7786bfed4..6be7ea2c3 100644 --- a/app/src/main/java/io/legado/app/utils/BitmapUtils.kt +++ b/app/src/main/java/io/legado/app/utils/BitmapUtils.kt @@ -16,7 +16,7 @@ import java.io.IOException import kotlin.math.* -@Suppress("unused", "WeakerAccess") +@Suppress("unused", "WeakerAccess", "MemberVisibilityCanBePrivate") object BitmapUtils { /** diff --git a/app/src/main/java/io/legado/app/utils/ColorUtils.kt b/app/src/main/java/io/legado/app/utils/ColorUtils.kt index 8a9a35052..800cd3c8b 100644 --- a/app/src/main/java/io/legado/app/utils/ColorUtils.kt +++ b/app/src/main/java/io/legado/app/utils/ColorUtils.kt @@ -7,7 +7,7 @@ import androidx.annotation.FloatRange import java.util.* import kotlin.math.* -@Suppress("unused") +@Suppress("unused", "MemberVisibilityCanBePrivate") object ColorUtils { fun intToString(intColor: Int): String { diff --git a/app/src/main/java/io/legado/app/utils/ConstraintUtil.kt b/app/src/main/java/io/legado/app/utils/ConstraintUtil.kt index b7ef740cc..bb2cc7bad 100644 --- a/app/src/main/java/io/legado/app/utils/ConstraintUtil.kt +++ b/app/src/main/java/io/legado/app/utils/ConstraintUtil.kt @@ -6,6 +6,7 @@ import androidx.constraintlayout.widget.ConstraintSet import androidx.transition.TransitionManager +@Suppress("MemberVisibilityCanBePrivate", "unused") class ConstraintUtil(private val constraintLayout: ConstraintLayout) { private var begin: ConstraintBegin? = null @@ -55,6 +56,7 @@ class ConstraintUtil(private val constraintLayout: ConstraintLayout) { } +@Suppress("unused", "MemberVisibilityCanBePrivate") class ConstraintBegin( private val constraintLayout: ConstraintLayout, private val applyConstraintSet: ConstraintSet diff --git a/app/src/main/java/io/legado/app/utils/DocumentUtils.kt b/app/src/main/java/io/legado/app/utils/DocumentUtils.kt index 041189c7f..64bc9e233 100644 --- a/app/src/main/java/io/legado/app/utils/DocumentUtils.kt +++ b/app/src/main/java/io/legado/app/utils/DocumentUtils.kt @@ -8,6 +8,7 @@ import androidx.documentfile.provider.DocumentFile import java.util.* +@Suppress("MemberVisibilityCanBePrivate") object DocumentUtils { fun exists(root: DocumentFile, fileName: String, vararg subDirs: String): Boolean { diff --git a/app/src/main/java/io/legado/app/utils/EventBusExtensions.kt b/app/src/main/java/io/legado/app/utils/EventBusExtensions.kt index 0d9473a3c..c0aedf8b3 100644 --- a/app/src/main/java/io/legado/app/utils/EventBusExtensions.kt +++ b/app/src/main/java/io/legado/app/utils/EventBusExtensions.kt @@ -1,3 +1,5 @@ +@file:Suppress("unused") + package io.legado.app.utils import androidx.appcompat.app.AppCompatActivity diff --git a/app/src/main/java/io/legado/app/utils/FileUtils.kt b/app/src/main/java/io/legado/app/utils/FileUtils.kt index ef67fab8b..ecb22f244 100644 --- a/app/src/main/java/io/legado/app/utils/FileUtils.kt +++ b/app/src/main/java/io/legado/app/utils/FileUtils.kt @@ -11,7 +11,7 @@ import java.text.SimpleDateFormat import java.util.* import java.util.regex.Pattern -@Suppress("unused") +@Suppress("unused", "MemberVisibilityCanBePrivate") object FileUtils { fun exists(root: File, vararg subDirFiles: String): Boolean { @@ -489,11 +489,10 @@ object FileUtils { */ @JvmOverloads fun writeText(filepath: String, content: String, charset: String = "utf-8"): Boolean { - try { + return try { writeBytes(filepath, content.toByteArray(charset(charset))) - return true } catch (e: UnsupportedEncodingException) { - return false + false } } @@ -569,15 +568,15 @@ object FileUtils { * 获取文件名(不包括扩展名) */ fun getNameExcludeExtension(path: String): String { - try { + return try { var fileName = File(path).name val lastIndexOf = fileName.lastIndexOf(".") if (lastIndexOf != -1) { fileName = fileName.substring(0, lastIndexOf) } - return fileName + fileName } catch (e: Exception) { - return "" + "" } } diff --git a/app/src/main/java/io/legado/app/utils/FloatExtensions.kt b/app/src/main/java/io/legado/app/utils/FloatExtensions.kt index 4e3c7f9ed..ab5178cd6 100644 --- a/app/src/main/java/io/legado/app/utils/FloatExtensions.kt +++ b/app/src/main/java/io/legado/app/utils/FloatExtensions.kt @@ -1,3 +1,5 @@ +@file:Suppress("unused") + package io.legado.app.utils import android.content.res.Resources @@ -7,7 +9,6 @@ val Float.dp: Float android.util.TypedValue.COMPLEX_UNIT_DIP, this, Resources.getSystem().displayMetrics ) - val Float.sp: Float get() = android.util.TypedValue.applyDimension( android.util.TypedValue.COMPLEX_UNIT_SP, this, Resources.getSystem().displayMetrics diff --git a/app/src/main/java/io/legado/app/utils/FragmentExtensions.kt b/app/src/main/java/io/legado/app/utils/FragmentExtensions.kt index de7f10b96..2e812a241 100644 --- a/app/src/main/java/io/legado/app/utils/FragmentExtensions.kt +++ b/app/src/main/java/io/legado/app/utils/FragmentExtensions.kt @@ -1,3 +1,5 @@ +@file:Suppress("unused") + package io.legado.app.utils import android.app.Activity @@ -14,7 +16,8 @@ import org.jetbrains.anko.defaultSharedPreferences import org.jetbrains.anko.internals.AnkoInternals @Suppress("DEPRECATION") -fun Fragment.isOnline() = requireContext().connectivityManager.activeNetworkInfo?.isConnected == true +fun Fragment.isOnline() = + requireContext().connectivityManager.activeNetworkInfo?.isConnected == true fun Fragment.getPrefBoolean(key: String, defValue: Boolean = false) = requireContext().defaultSharedPreferences.getBoolean(key, defValue) @@ -40,7 +43,10 @@ fun Fragment.getPrefString(key: String, defValue: String? = null) = fun Fragment.putPrefString(key: String, value: String) = requireContext().defaultSharedPreferences.edit { putString(key, value) } -fun Fragment.getPrefStringSet(key: String, defValue: MutableSet? = null) = +fun Fragment.getPrefStringSet( + key: String, + defValue: MutableSet? = null +): MutableSet? = requireContext().defaultSharedPreferences.getStringSet(key, defValue) fun Fragment.putPrefStringSet(key: String, value: MutableSet) = @@ -51,15 +57,23 @@ fun Fragment.removePref(key: String) = fun Fragment.getCompatColor(@ColorRes id: Int): Int = requireContext().getCompatColor(id) -fun Fragment.getCompatDrawable(@DrawableRes id: Int): Drawable? = requireContext().getCompatDrawable(id) +fun Fragment.getCompatDrawable(@DrawableRes id: Int): Drawable? = + requireContext().getCompatDrawable(id) -fun Fragment.getCompatColorStateList(@ColorRes id: Int): ColorStateList? = requireContext().getCompatColorStateList(id) +fun Fragment.getCompatColorStateList(@ColorRes id: Int): ColorStateList? = + requireContext().getCompatColorStateList(id) inline fun Fragment.startActivity(vararg params: Pair) = AnkoInternals.internalStartActivity(requireActivity(), T::class.java, params) -inline fun Fragment.startActivityForResult(requestCode: Int, vararg params: Pair) = - startActivityForResult(AnkoInternals.createIntent(requireActivity(), T::class.java, params), requestCode) +inline fun Fragment.startActivityForResult( + requestCode: Int, + vararg params: Pair +) = + startActivityForResult( + AnkoInternals.createIntent(requireActivity(), T::class.java, params), + requestCode + ) inline fun Fragment.startService(vararg params: Pair) = AnkoInternals.internalStartService(requireActivity(), T::class.java, params) diff --git a/app/src/main/java/io/legado/app/utils/JsoupExtensions.kt b/app/src/main/java/io/legado/app/utils/JsoupExtensions.kt index 3f347e4a1..2c9829ddd 100644 --- a/app/src/main/java/io/legado/app/utils/JsoupExtensions.kt +++ b/app/src/main/java/io/legado/app/utils/JsoupExtensions.kt @@ -10,41 +10,38 @@ import org.jsoup.select.NodeVisitor fun Element.textArray(): Array { - val accum = StringUtil.borrowBuilder() + val sb = StringUtil.borrowBuilder() NodeTraversor.traverse(object : NodeVisitor { override fun head(node: Node, depth: Int) { if (node is TextNode) { - appendNormalisedText(accum, node) + appendNormalisedText(sb, node) } else if (node is Element) { - if (accum.isNotEmpty() && + if (sb.isNotEmpty() && (node.isBlock || node.tag().name == "br") && - !lastCharIsWhitespace(accum) - ) accum.append("\n") + !lastCharIsWhitespace(sb) + ) sb.append("\n") } } override fun tail(node: Node, depth: Int) { if (node is Element) { - if (node.isBlock && node.nextSibling() is TextNode && !lastCharIsWhitespace( - accum - ) - ) accum.append("\n") + if (node.isBlock && node.nextSibling() is TextNode + && !lastCharIsWhitespace(sb) + ) { + sb.append("\n") + } } } }, this) - val text = StringUtil.releaseBuilder(accum).trim { it <= ' ' } + val text = StringUtil.releaseBuilder(sb).trim { it <= ' ' } return text.splitNotBlank("\n") } -private fun appendNormalisedText(accum: StringBuilder, textNode: TextNode) { +private fun appendNormalisedText(sb: StringBuilder, textNode: TextNode) { val text = textNode.wholeText if (preserveWhitespace(textNode.parentNode()) || textNode is CDataNode) - accum.append(text) - else StringUtil.appendNormalisedWhitespace( - accum, - text, - lastCharIsWhitespace(accum) - ) + sb.append(text) + else StringUtil.appendNormalisedWhitespace(sb, text, lastCharIsWhitespace(sb)) } private fun preserveWhitespace(node: Node?): Boolean { diff --git a/app/src/main/java/io/legado/app/utils/LanguageUtils.kt b/app/src/main/java/io/legado/app/utils/LanguageUtils.kt index def23e1e8..7a8572ded 100644 --- a/app/src/main/java/io/legado/app/utils/LanguageUtils.kt +++ b/app/src/main/java/io/legado/app/utils/LanguageUtils.kt @@ -72,14 +72,6 @@ object LanguageUtils { @Suppress("DEPRECATION") locale = context.resources.configuration.locale } - /* - Log.d("h11128", "displayName " + locale.displayName) - Log.d("h11128", "displayCountry " + locale.displayCountry) - Log.d("h11128", "displayLanguage " + locale.displayLanguage) - Log.d("h11128", "Language " + locale.language) - Log.d("h11128", "Country " + locale.country) - - */ return locale } diff --git a/app/src/main/java/io/legado/app/utils/NetworkUtils.kt b/app/src/main/java/io/legado/app/utils/NetworkUtils.kt index 4a3e236cb..40ec8edc6 100644 --- a/app/src/main/java/io/legado/app/utils/NetworkUtils.kt +++ b/app/src/main/java/io/legado/app/utils/NetworkUtils.kt @@ -8,7 +8,7 @@ import java.net.URL import java.util.* import java.util.regex.Pattern -@Suppress("unused") +@Suppress("unused", "MemberVisibilityCanBePrivate") object NetworkUtils { fun getUrl(response: Response<*>): String { val networkResponse = response.raw().networkResponse() diff --git a/app/src/main/java/io/legado/app/utils/StringUtils.kt b/app/src/main/java/io/legado/app/utils/StringUtils.kt index 4ee24ba2a..8ee17662d 100644 --- a/app/src/main/java/io/legado/app/utils/StringUtils.kt +++ b/app/src/main/java/io/legado/app/utils/StringUtils.kt @@ -12,7 +12,7 @@ import kotlin.math.abs import kotlin.math.log10 import kotlin.math.pow -@Suppress("unused") +@Suppress("unused", "MemberVisibilityCanBePrivate") object StringUtils { private const val HOUR_OF_DAY = 24 private const val DAY_OF_YESTERDAY = 2 diff --git a/app/src/main/java/io/legado/app/utils/ViewExtensions.kt b/app/src/main/java/io/legado/app/utils/ViewExtensions.kt index 7ed6d8cd6..122f814a0 100644 --- a/app/src/main/java/io/legado/app/utils/ViewExtensions.kt +++ b/app/src/main/java/io/legado/app/utils/ViewExtensions.kt @@ -7,7 +7,6 @@ import android.graphics.Canvas import android.os.Build import android.view.View import android.view.View.* -import android.view.ViewGroup import android.view.inputmethod.InputMethodManager import android.widget.RadioGroup import android.widget.SeekBar @@ -80,13 +79,6 @@ fun View.screenshot(): Bitmap? { }.getOrNull() } -fun View.setMargin(left: Int, top: Int, right: Int, bottom: Int) { - if (layoutParams is ViewGroup.MarginLayoutParams) { - (layoutParams as ViewGroup.MarginLayoutParams).setMargins(left, top, right, bottom) - requestLayout() - } -} - fun SeekBar.progressAdd(int: Int) { progress += int } diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 107f32f54..a387ecb36 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -1,15 +1,15 @@ - + android:layout_height="match_parent" + android:orientation="vertical"> + android:layout_weight="1" /> + app:menu="@menu/main_bnv" /> - \ No newline at end of file + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_books.xml b/app/src/main/res/layout/fragment_books.xml index 9ad51b407..8da85f913 100644 --- a/app/src/main/res/layout/fragment_books.xml +++ b/app/src/main/res/layout/fragment_books.xml @@ -25,6 +25,7 @@ android:gravity="center" android:layout_gravity="center" android:visibility="gone" + android:text="@string/bookshelf_empty" tools:text="TextView" /> diff --git a/app/src/main/res/layout/fragment_bookshelf.xml b/app/src/main/res/layout/fragment_bookshelf.xml index ea0a9ab40..4fbff35c3 100644 --- a/app/src/main/res/layout/fragment_bookshelf.xml +++ b/app/src/main/res/layout/fragment_bookshelf.xml @@ -1,5 +1,5 @@ - + app:contentLayout="@layout/view_tab_layout_min" /> + android:layout_height="match_parent" /> - \ No newline at end of file + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_find_book.xml b/app/src/main/res/layout/fragment_explore.xml similarity index 94% rename from app/src/main/res/layout/fragment_find_book.xml rename to app/src/main/res/layout/fragment_explore.xml index 826d713ad..45b4292e3 100644 --- a/app/src/main/res/layout/fragment_find_book.xml +++ b/app/src/main/res/layout/fragment_explore.xml @@ -30,6 +30,7 @@ android:layout_margin="16dp" android:gravity="center" android:visibility="gone" + android:text="@string/explore_empty" app:layout_constraintTop_toBottomOf="@+id/title_bar" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintLeft_toLeftOf="parent" diff --git a/app/src/main/res/layout/fragment_rss.xml b/app/src/main/res/layout/fragment_rss.xml index 6d4bfdeeb..49456ce20 100644 --- a/app/src/main/res/layout/fragment_rss.xml +++ b/app/src/main/res/layout/fragment_rss.xml @@ -31,6 +31,7 @@ android:layout_margin="16dp" android:gravity="center" android:visibility="gone" + android:text="@string/rss_source_empty" app:layout_constraintTop_toBottomOf="@+id/title_bar" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintLeft_toLeftOf="parent" diff --git a/app/src/main/res/layout/item_bookshelf_grid.xml b/app/src/main/res/layout/item_bookshelf_grid.xml index 73c9b616a..0816a9a83 100644 --- a/app/src/main/res/layout/item_bookshelf_grid.xml +++ b/app/src/main/res/layout/item_bookshelf_grid.xml @@ -1,63 +1,67 @@ - + android:paddingRight="8dp"> - - - - - + android:layout_height="wrap_content"> + + + + + + + + - \ No newline at end of file + + + diff --git a/app/src/main/res/layout/item_group_manage.xml b/app/src/main/res/layout/item_group_manage.xml index 763a19acd..9aa18e82a 100644 --- a/app/src/main/res/layout/item_group_manage.xml +++ b/app/src/main/res/layout/item_group_manage.xml @@ -29,4 +29,10 @@ android:padding="8dp" android:text="@string/delete" /> + + \ No newline at end of file diff --git a/app/src/main/res/layout/item_rss.xml b/app/src/main/res/layout/item_rss.xml index 3911221d6..448710b37 100644 --- a/app/src/main/res/layout/item_rss.xml +++ b/app/src/main/res/layout/item_rss.xml @@ -25,6 +25,7 @@ android:gravity="top|center_horizontal" android:lines="2" android:ellipsize="end" + android:textColor="@color/secondaryText" tools:text="RSS" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" diff --git a/app/src/main/res/menu/arrange_book.xml b/app/src/main/res/menu/arrange_book.xml index 4eb85fb8e..625bbbfe5 100644 --- a/app/src/main/res/menu/arrange_book.xml +++ b/app/src/main/res/menu/arrange_book.xml @@ -14,22 +14,6 @@ android:id="@+id/menu_group_manage" android:title="@string/group_manage" /> - - - - - - - - diff --git a/app/src/main/res/menu/download.xml b/app/src/main/res/menu/book_cache.xml similarity index 73% rename from app/src/main/res/menu/download.xml rename to app/src/main/res/menu/book_cache.xml index 6303b5b9d..689fc54ae 100644 --- a/app/src/main/res/menu/download.xml +++ b/app/src/main/res/menu/book_cache.xml @@ -16,17 +16,7 @@ android:icon="@drawable/ic_groups" app:showAsAction="always"> - - - - - - - + diff --git a/app/src/main/res/menu/book_group_manage.xml b/app/src/main/res/menu/book_group_manage.xml index 8c65f9f8d..6c558b1e9 100644 --- a/app/src/main/res/menu/book_group_manage.xml +++ b/app/src/main/res/menu/book_group_manage.xml @@ -10,36 +10,4 @@ app:showAsAction="always" tools:ignore="AlwaysShowAction" /> - - - - - - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index 33b1da7fe..e30d9bddf 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -45,7 +45,7 @@ 最近閱讀 最後閱讀 更新日誌 - 書架還空著,先去搜索書籍或從發現裏添加吧!\n如果初次使用請先關註公眾號[開源閱讀]獲取書源! + 書架還空著,先去搜尋書籍或從發現裡添加吧!\n如果初次使用請先關注公眾號[开源阅读]獲取書源! 搜尋 下載 列表 @@ -767,7 +767,7 @@ 分享選中書源 時間排序 全文搜尋 - 关注公众号[开源阅读]获取订阅源! - 当前没有发现源,关注公众号[开源阅读]添加带发现的书源! + 關注公眾號[开源阅读]獲取訂閱源! + 目前沒有發現源,關注公眾號[开源阅读]添加包含發現的書源!