From 9912d7f87c5dceb6f48c7f436a808f02e368f874 Mon Sep 17 00:00:00 2001 From: david082321 <7046617+david082321@users.noreply.github.com> Date: Fri, 16 Oct 2020 19:16:02 +0800 Subject: [PATCH 01/39] =?UTF-8?q?=E6=9B=B4=E6=96=B0zh-rTW=E8=AF=AD?= =?UTF-8?q?=E8=A8=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/res/values-zh-rTW/strings.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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 @@ 分享選中書源 時間排序 全文搜尋 - 关注公众号[开源阅读]获取订阅源! - 当前没有发现源,关注公众号[开源阅读]添加带发现的书源! + 關注公眾號[开源阅读]獲取訂閱源! + 目前沒有發現源,關注公眾號[开源阅读]添加包含發現的書源! From 70ce0535b6e1dbe7efdc2f5726f3cb3bddb81798 Mon Sep 17 00:00:00 2001 From: gedoor Date: Fri, 16 Oct 2020 22:28:10 +0800 Subject: [PATCH 02/39] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/ui/main/bookshelf/books/BooksFragment.kt | 6 ++---- .../java/io/legado/app/ui/main/explore/ExploreFragment.kt | 1 - app/src/main/java/io/legado/app/ui/main/rss/RssFragment.kt | 1 - app/src/main/res/layout/fragment_books.xml | 1 + app/src/main/res/layout/fragment_find_book.xml | 1 + app/src/main/res/layout/fragment_rss.xml | 1 + 6 files changed, 5 insertions(+), 6 deletions(-) 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..64aac5e6e 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() } @@ -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..2ae13605d 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 @@ -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() 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/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_find_book.xml b/app/src/main/res/layout/fragment_find_book.xml index 826d713ad..45b4292e3 100644 --- a/app/src/main/res/layout/fragment_find_book.xml +++ b/app/src/main/res/layout/fragment_find_book.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" From 8bc251c105338c88f8e1835c947da1cb4545982d Mon Sep 17 00:00:00 2001 From: gedoor Date: Fri, 16 Oct 2020 23:07:06 +0800 Subject: [PATCH 03/39] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/build.gradle | 3 + .../main/java/io/legado/app/help/BookHelp.kt | 123 ++++++++++++------ .../legado/app/ui/audio/AudioPlayViewModel.kt | 17 ++- .../app/ui/book/info/BookInfoViewModel.kt | 25 +++- .../app/ui/book/read/ReadBookViewModel.kt | 17 ++- 5 files changed, 126 insertions(+), 59 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index be8813009..5db9de98b 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' 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/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/info/BookInfoViewModel.kt b/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt index aa3c12557..c4f60e92b 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 @@ -133,23 +133,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 From 50f9c61887b5342a6e7d125d291b5c147586bca7 Mon Sep 17 00:00:00 2001 From: gedoor Date: Sat, 17 Oct 2020 00:20:22 +0800 Subject: [PATCH 04/39] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/io/legado/app/ui/main/explore/ExploreFragment.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 2ae13605d..9cdfdbad5 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 @@ -114,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) From 1dba9063d1f7043dbd71dbf8962f1e96892637d5 Mon Sep 17 00:00:00 2001 From: gedoor Date: Sat, 17 Oct 2020 00:53:35 +0800 Subject: [PATCH 05/39] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ui/main/bookshelf/BookshelfFragment.kt | 60 ++++++------------- .../ui/main/bookshelf/BookshelfViewModel.kt | 20 +++---- 2 files changed, 28 insertions(+), 52 deletions(-) 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..56bf439f6 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 @@ -51,6 +51,7 @@ class BookshelfFragment : VMBaseFragment(R.layout.fragment_b 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() @@ -104,7 +105,8 @@ 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() { @@ -112,39 +114,9 @@ class BookshelfFragment : VMBaseFragment(R.layout.fragment_b bookGroupLiveData = App.db.bookGroupDao().liveDataAll() 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) - } - } + bookGroups.clear() + bookGroups.addAll(it) + upGroup() }) noGroupLiveData?.removeObservers(viewLifecycleOwner) noGroupLiveData = App.db.bookDao().observeNoGroupSize() @@ -197,11 +169,19 @@ class BookshelfFragment : VMBaseFragment(R.layout.fragment_b if (AppConfig.bookGroupAllShow) { bookGroups.add(0, AppConst.bookGroupAll) } - view_pager_bookshelf.adapter?.notifyDataSetChanged() + 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 +232,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() { 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..e9fb4cd4c 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 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) } } } From 8121fc7cc9f4e33de43e9970152c29da81c0c5cb Mon Sep 17 00:00:00 2001 From: gedoor Date: Sat, 17 Oct 2020 00:56:38 +0800 Subject: [PATCH 06/39] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) 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 56bf439f6..cc1677f61 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 @@ -39,7 +39,6 @@ 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), @@ -132,7 +131,7 @@ class BookshelfFragment : VMBaseFragment(R.layout.fragment_b } override fun onQueryTextSubmit(query: String?): Boolean { - context?.startActivity(Pair("key", query)) + startActivity(Pair("key", query)) return false } From 39d824b9f1e30c5b6bf87299beaf2ce1fd40c3d8 Mon Sep 17 00:00:00 2001 From: gedoor Date: Sat, 17 Oct 2020 19:07:27 +0800 Subject: [PATCH 07/39] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/constant/EventBus.kt | 1 + .../java/io/legado/app/data/AppDatabase.kt | 11 ++- .../ui/book/arrange/ArrangeBookActivity.kt | 3 +- .../app/ui/book/arrange/ArrangeBookAdapter.kt | 2 +- .../app/ui/book/group/GroupManageDialog.kt | 60 ++++-------- .../app/ui/book/group/GroupSelectDialog.kt | 6 +- .../app/ui/book/read/config/TocRegexDialog.kt | 5 +- .../book/source/manage/BookSourceActivity.kt | 3 +- .../book/source/manage/BookSourceAdapter.kt | 4 +- .../ui/main/bookshelf/BookshelfFragment.kt | 83 ++++++---------- .../app/ui/replace/ReplaceRuleActivity.kt | 3 +- .../app/ui/replace/ReplaceRuleAdapter.kt | 2 +- .../ui/rss/source/manage/RssSourceActivity.kt | 3 +- .../ui/rss/source/manage/RssSourceAdapter.kt | 2 +- .../ui/widget/recycler/ItemTouchCallback.kt | 18 ++-- .../main/res/layout/item_bookshelf_grid.xml | 94 ++++++++++--------- app/src/main/res/menu/book_group_manage.xml | 32 ------- 17 files changed, 125 insertions(+), 207 deletions(-) diff --git a/app/src/main/java/io/legado/app/constant/EventBus.kt b/app/src/main/java/io/legado/app/constant/EventBus.kt index 8fe6df384..f8f1541a8 100644 --- a/app/src/main/java/io/legado/app/constant/EventBus.kt +++ b/app/src/main/java/io/legado/app/constant/EventBus.kt @@ -4,6 +4,7 @@ object EventBus { const val MEDIA_BUTTON = "mediaButton" const val RECREATE = "RECREATE" const val UP_BOOK = "upBookToc" + const val UP_BOOK_GROUP = "upBookGroup" const val ALOUD_STATE = "aloud_state" const val TTS_PROGRESS = "ttsStart" const val TTS_DS = "ttsDs" 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..781d59057 100644 --- a/app/src/main/java/io/legado/app/data/AppDatabase.kt +++ b/app/src/main/java/io/legado/app/data/AppDatabase.kt @@ -40,9 +40,16 @@ abstract class AppDatabase: RoomDatabase() { migration_19_20 ) .allowMainThreadQueries() + .addCallback(dbCallback) .build() - - private val migration_10_11 = object: Migration(10, 11) { + + private val dbCallback = object : Callback() { + override fun onOpen(db: SupportSQLiteDatabase) { + + } + } + + private val migration_10_11 = object : Migration(10, 11) { override fun migrate(database: SupportSQLiteDatabase) { database.execSQL("DROP TABLE txtTocRules") database.execSQL( 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..d850b2f36 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) 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..b6a98cb62 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 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..c3421e136 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 @@ -20,7 +20,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 +40,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 +60,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 } @@ -204,7 +176,7 @@ class GroupManageDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener private inner class GroupAdapter(context: Context) : SimpleRecyclerAdapter(context, R.layout.item_group_manage), - ItemTouchCallback.OnItemTouchCallbackListener { + ItemTouchCallback.Callback { private var isMoved = false @@ -223,7 +195,14 @@ class GroupManageDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener } override fun onMove(srcPosition: Int, targetPosition: Int): Boolean { - Collections.swap(getItems(), srcPosition, targetPosition) + if (srcPosition < 4 || targetPosition < 4) { + return true + } + Collections.swap( + getItems(), + srcPosition - getHeaderCount(), + targetPosition - getHeaderCount() + ) notifyItemMoved(srcPosition, targetPosition) isMoved = true return true @@ -240,7 +219,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..9cf7b8ac1 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() } @@ -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/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/main/bookshelf/BookshelfFragment.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt index cc1677f61..e66699b0e 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 @@ -13,6 +13,7 @@ import io.legado.app.App import io.legado.app.R import io.legado.app.base.VMBaseFragment import io.legado.app.constant.AppConst +import io.legado.app.constant.EventBus import io.legado.app.constant.PreferKey import io.legado.app.data.entities.BookGroup import io.legado.app.help.AppConfig @@ -36,15 +37,13 @@ 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 - +/** + * 书架界面 + */ class BookshelfFragment : VMBaseFragment(R.layout.fragment_bookshelf), TabLayout.OnTabSelectedListener, - SearchView.OnQueryTextListener, - GroupManageDialog.CallBack { + SearchView.OnQueryTextListener { override val viewModel: BookshelfViewModel get() = getViewModel(BookshelfViewModel::class.java) @@ -52,10 +51,8 @@ class BookshelfFragment : VMBaseFragment(R.layout.fragment_b 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) @@ -113,20 +110,7 @@ class BookshelfFragment : VMBaseFragment(R.layout.fragment_b bookGroupLiveData = App.db.bookGroupDao().liveDataAll() bookGroupLiveData?.observe(viewLifecycleOwner, { viewModel.checkGroup(it) - bookGroups.clear() - bookGroups.addAll(it) - upGroup() - }) - 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) }) } @@ -139,39 +123,24 @@ 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) - } - adapter.notifyDataSetChanged() - selectLastTab() - } + @Synchronized + private fun upGroup(data: List) { + bookGroups.clear() + if (AppConfig.bookGroupAllShow) { + bookGroups.add(AppConst.bookGroupAll) + } + if (AppConfig.bookGroupLocalShow) { + bookGroups.add(AppConst.bookGroupLocal) + } + if (AppConfig.bookGroupAudioShow) { + bookGroups.add(AppConst.bookGroupAudio) } + if (AppConfig.bookGroupNoneShow) { + bookGroups.add(AppConst.bookGroupNone) + } + bookGroups.addAll(data) + adapter.notifyDataSetChanged() + selectLastTab() } @Synchronized @@ -243,6 +212,12 @@ class BookshelfFragment : VMBaseFragment(R.layout.fragment_b fragmentMap[selectedGroup?.groupId]?.gotoTop() } + override fun observeLiveBus() { + observeEvent>(EventBus.UP_BOOK_GROUP) { + upGroup(it) + } + } + private inner class TabFragmentPageAdapter(fm: FragmentManager) : FragmentStatePagerAdapter(fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT) { 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/recycler/ItemTouchCallback.kt b/app/src/main/java/io/legado/app/ui/widget/recycler/ItemTouchCallback.kt index b015a0086..a68ac72f4 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,16 @@ import androidx.viewpager.widget.ViewPager * Created by GKF on 2018/3/16. */ -class ItemTouchCallback : ItemTouchHelper.Callback() { +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 +84,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 +100,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/res/layout/item_bookshelf_grid.xml b/app/src/main/res/layout/item_bookshelf_grid.xml index 73c9b616a..17290949e 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:orientation="vertical" + android:padding="8dp"> - - - - - + android:layout_height="wrap_content"> + + + + + + + + - \ No newline at end of file + + + 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 From b2d6249cfc3472b8f53a748a29a67fb6d917472b Mon Sep 17 00:00:00 2001 From: gedoor Date: Sat, 17 Oct 2020 19:35:16 +0800 Subject: [PATCH 08/39] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/data/AppDatabase.kt | 25 ++++++++++++++++++- .../app/ui/book/group/GroupManageDialog.kt | 9 +------ .../ui/main/bookshelf/BookshelfFragment.kt | 14 ----------- .../ui/main/bookshelf/BookshelfViewModel.kt | 2 +- 4 files changed, 26 insertions(+), 24 deletions(-) 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 781d59057..262fe014d 100644 --- a/app/src/main/java/io/legado/app/data/AppDatabase.kt +++ b/app/src/main/java/io/legado/app/data/AppDatabase.kt @@ -45,7 +45,30 @@ abstract class AppDatabase: RoomDatabase() { private val dbCallback = object : Callback() { override fun onOpen(db: SupportSQLiteDatabase) { - + db.execSQL( + """ + insert into book_groups(groupId, groupName, 'order') select -1, '全部', -10 + where not exists (select * from book_groups where groupId = -1) + """ + ) + db.execSQL( + """ + insert into book_groups(groupId, groupName, 'order') select -2, '本地', -9 + where not exists (select * from book_groups where groupId = -2) + """ + ) + db.execSQL( + """ + insert into book_groups(groupId, groupName, 'order') select -3, '音频', -8 + where not exists (select * from book_groups where groupId = -3) + """ + ) + db.execSQL( + """ + insert into book_groups(groupId, groupName, 'order') select -4, '未分组', -7 + where not exists (select * from book_groups where groupId = -4) + """ + ) } } 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 c3421e136..6eac527d4 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 @@ -195,14 +195,7 @@ class GroupManageDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener } override fun onMove(srcPosition: Int, targetPosition: Int): Boolean { - if (srcPosition < 4 || targetPosition < 4) { - return true - } - Collections.swap( - getItems(), - srcPosition - getHeaderCount(), - targetPosition - getHeaderCount() - ) + Collections.swap(getItems(), srcPosition, targetPosition) notifyItemMoved(srcPosition, targetPosition) isMoved = true return true 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 e66699b0e..1647f5a86 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 @@ -12,11 +12,9 @@ import com.google.android.material.tabs.TabLayout import io.legado.app.App import io.legado.app.R import io.legado.app.base.VMBaseFragment -import io.legado.app.constant.AppConst import io.legado.app.constant.EventBus 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 @@ -126,18 +124,6 @@ class BookshelfFragment : VMBaseFragment(R.layout.fragment_b @Synchronized private fun upGroup(data: List) { bookGroups.clear() - if (AppConfig.bookGroupAllShow) { - bookGroups.add(AppConst.bookGroupAll) - } - if (AppConfig.bookGroupLocalShow) { - bookGroups.add(AppConst.bookGroupLocal) - } - if (AppConfig.bookGroupAudioShow) { - bookGroups.add(AppConst.bookGroupAudio) - } - if (AppConfig.bookGroupNoneShow) { - bookGroups.add(AppConst.bookGroupNone) - } bookGroups.addAll(data) adapter.notifyDataSetChanged() selectLastTab() 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 e9fb4cd4c..ae14b99f9 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 @@ -64,7 +64,7 @@ class BookshelfViewModel(application: Application) : BaseViewModel(application) fun checkGroup(groups: List) { groups.forEach { group -> - if (group.groupId and (group.groupId - 1) != 0L) { + 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) { From 51a6275a04aa8ec6ef39e9908d7415504edeef34 Mon Sep 17 00:00:00 2001 From: gedoor Date: Sat, 17 Oct 2020 19:42:29 +0800 Subject: [PATCH 09/39] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/constant/AppConst.kt | 11 ++++------- .../main/java/io/legado/app/data/AppDatabase.kt | 17 +++++++++-------- .../app/ui/book/arrange/ArrangeBookActivity.kt | 16 ++++++++-------- .../legado/app/ui/book/cache/CacheActivity.kt | 8 ++++---- .../ui/main/bookshelf/books/BooksFragment.kt | 8 ++++---- 5 files changed, 29 insertions(+), 31 deletions(-) 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/data/AppDatabase.kt b/app/src/main/java/io/legado/app/data/AppDatabase.kt index 262fe014d..af4b1fb7a 100644 --- a/app/src/main/java/io/legado/app/data/AppDatabase.kt +++ b/app/src/main/java/io/legado/app/data/AppDatabase.kt @@ -7,6 +7,7 @@ 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.* @@ -47,26 +48,26 @@ abstract class AppDatabase: RoomDatabase() { override fun onOpen(db: SupportSQLiteDatabase) { db.execSQL( """ - insert into book_groups(groupId, groupName, 'order') select -1, '全部', -10 - where not exists (select * from book_groups where groupId = -1) + insert into book_groups(groupId, groupName, 'order') select ${AppConst.bookGroupAllId}, '全部', -10 + where not exists (select * from book_groups where groupId = ${AppConst.bookGroupAllId}) """ ) db.execSQL( """ - insert into book_groups(groupId, groupName, 'order') select -2, '本地', -9 - where not exists (select * from book_groups where groupId = -2) + insert into book_groups(groupId, groupName, 'order') select ${AppConst.bookGroupLocalId}, '本地', -9 + where not exists (select * from book_groups where groupId = ${AppConst.bookGroupLocalId}) """ ) db.execSQL( """ - insert into book_groups(groupId, groupName, 'order') select -3, '音频', -8 - where not exists (select * from book_groups where groupId = -3) + insert into book_groups(groupId, groupName, 'order') select ${AppConst.bookGroupAudioId}, '音频', -8 + where not exists (select * from book_groups where groupId = ${AppConst.bookGroupAudioId}) """ ) db.execSQL( """ - insert into book_groups(groupId, groupName, 'order') select -4, '未分组', -7 - where not exists (select * from book_groups where groupId = -4) + insert into book_groups(groupId, groupName, 'order') select ${AppConst.bookGroupNoneId}, '未分组', -7 + where not exists (select * from book_groups where groupId = ${AppConst.bookGroupNoneId}) """ ) } 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 d850b2f36..c980fe30c 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 @@ -111,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 -> @@ -135,22 +135,22 @@ class ArrangeBookActivity : VMBaseActivity(R.layout.activi .show(supportFragmentManager, "groupManage") R.id.menu_no_group -> { title_bar.subtitle = getString(R.string.no_group) - groupId = AppConst.bookGroupNone.groupId + groupId = AppConst.bookGroupNoneId initBookData() } R.id.menu_all -> { title_bar.subtitle = item.title - groupId = AppConst.bookGroupAll.groupId + groupId = AppConst.bookGroupAllId initBookData() } R.id.menu_local -> { title_bar.subtitle = item.title - groupId = AppConst.bookGroupLocal.groupId + groupId = AppConst.bookGroupLocalId initBookData() } R.id.menu_audio -> { title_bar.subtitle = item.title - groupId = AppConst.bookGroupAudio.groupId + groupId = AppConst.bookGroupAudioId initBookData() } else -> if (item.groupId == R.id.menu_group) { 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..97a16813c 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 @@ -97,12 +97,12 @@ class CacheActivity : VMBaseActivity(R.layout.activity_download) } R.id.menu_no_group -> { title_bar.subtitle = getString(R.string.no_group) - groupId = AppConst.bookGroupNone.groupId + groupId = AppConst.bookGroupNoneId initBookData() } R.id.menu_all -> { title_bar.subtitle = item.title - groupId = AppConst.bookGroupAll.groupId + groupId = AppConst.bookGroupAllId initBookData() } else -> if (item.groupId == R.id.menu_group) { @@ -123,8 +123,8 @@ 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.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/main/bookshelf/books/BooksFragment.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksFragment.kt index 64aac5e6e..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 @@ -102,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 -> From e38e52b683f454414c3d24dddc8eed28379ac0e5 Mon Sep 17 00:00:00 2001 From: gedoor Date: Sat, 17 Oct 2020 19:45:58 +0800 Subject: [PATCH 10/39] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/res/layout/item_bookshelf_grid.xml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/src/main/res/layout/item_bookshelf_grid.xml b/app/src/main/res/layout/item_bookshelf_grid.xml index 17290949e..618dc8c1f 100644 --- a/app/src/main/res/layout/item_bookshelf_grid.xml +++ b/app/src/main/res/layout/item_bookshelf_grid.xml @@ -5,7 +5,9 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" - android:padding="8dp"> + android:paddingTop="8dp" + android:paddingLeft="8dp" + android:paddingRight="8dp"> Date: Sat, 17 Oct 2020 19:50:39 +0800 Subject: [PATCH 11/39] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/io/legado/app/data/dao/BookGroupDao.kt | 3 +++ .../main/java/io/legado/app/ui/book/group/GroupSelectDialog.kt | 2 +- .../java/io/legado/app/ui/main/bookshelf/BookshelfViewModel.kt | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) 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..815c6cbda 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,6 +16,9 @@ interface BookGroupDao { @Query("SELECT * FROM book_groups ORDER BY `order`") fun liveDataAll(): LiveData> + @Query("SELECT * FROM book_groups where groupId >= 0 ORDER BY `order`") + fun liveDataSelect(): LiveData> + @get:Query("SELECT sum(groupId) FROM book_groups") val idsSum: Long 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 9cf7b8ac1..f648527cb 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 @@ -109,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) }) } 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 ae14b99f9..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 @@ -64,7 +64,7 @@ class BookshelfViewModel(application: Application) : BaseViewModel(application) fun checkGroup(groups: List) { groups.forEach { group -> - if (group.groupId > 0 && group.groupId and (group.groupId - 1) != 0L) { + 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) { From 1c957e9627c8205eba2a1ad86c496d84012c8e4d Mon Sep 17 00:00:00 2001 From: gedoor Date: Sat, 17 Oct 2020 20:34:28 +0800 Subject: [PATCH 12/39] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/io/legado/app/data/AppDatabase.kt | 13 ++++++++++--- .../java/io/legado/app/data/dao/BookGroupDao.kt | 3 +++ .../java/io/legado/app/data/entities/BookGroup.kt | 3 ++- .../legado/app/ui/book/group/GroupManageDialog.kt | 11 +++++++++++ .../app/ui/main/bookshelf/BookshelfFragment.kt | 2 +- app/src/main/res/layout/item_group_manage.xml | 6 ++++++ 6 files changed, 33 insertions(+), 5 deletions(-) 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 af4b1fb7a..82407528f 100644 --- a/app/src/main/java/io/legado/app/data/AppDatabase.kt +++ b/app/src/main/java/io/legado/app/data/AppDatabase.kt @@ -17,7 +17,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() { @@ -38,7 +38,8 @@ 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) @@ -143,11 +144,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/BookGroupDao.kt b/app/src/main/java/io/legado/app/data/dao/BookGroupDao.kt index 815c6cbda..a7d29d750 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,6 +16,9 @@ interface BookGroupDao { @Query("SELECT * FROM book_groups ORDER BY `order`") fun liveDataAll(): LiveData> + @Query("SELECT * FROM book_groups where show > 0 ORDER BY `order`") + fun liveDataShow(): LiveData> + @Query("SELECT * FROM book_groups where groupId >= 0 ORDER BY `order`") fun liveDataSelect(): LiveData> 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..20a8263a3 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 @@ -11,5 +11,6 @@ data class BookGroup( @PrimaryKey val groupId: Long = 0b1, var groupName: String, - var order: Int = 0 + var order: Int = 0, + var show: Boolean = true ) : Parcelable \ No newline at end of file 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 6eac527d4..66fb7ebec 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 @@ -184,6 +185,9 @@ class GroupManageDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener holder.itemView.apply { setBackgroundColor(context.backgroundColor) tv_group.text = item.groupName + sw_show.isChecked = item.show + tv_del.isGone = item.groupId < 0 + sw_show.isGone = item.groupId >= 0 } } @@ -191,6 +195,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)) + } + } + } } } 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 1647f5a86..cd967ad33 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 @@ -105,7 +105,7 @@ class BookshelfFragment : VMBaseFragment(R.layout.fragment_b private fun initBookGroupData() { bookGroupLiveData?.removeObservers(viewLifecycleOwner) - bookGroupLiveData = App.db.bookGroupDao().liveDataAll() + bookGroupLiveData = App.db.bookGroupDao().liveDataShow() bookGroupLiveData?.observe(viewLifecycleOwner, { viewModel.checkGroup(it) upGroup(it) 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 From 15c8fef42491d5f985a16edcf586ee1b1b940196 Mon Sep 17 00:00:00 2001 From: gedoor Date: Sat, 17 Oct 2020 21:14:27 +0800 Subject: [PATCH 13/39] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/io/legado/app/help/storage/Restore.kt | 1 - app/src/main/java/io/legado/app/ui/book/read/ReadMenu.kt | 2 -- 2 files changed, 3 deletions(-) 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/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, "") } //上一章 From 3d530ca191d833fe5540a50bdb3b7269a0e89950 Mon Sep 17 00:00:00 2001 From: gedoor Date: Sat, 17 Oct 2020 22:03:30 +0800 Subject: [PATCH 14/39] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/ui/main/MainActivity.kt | 53 ++++--------------- .../ui/main/bookshelf/BookshelfFragment.kt | 4 +- 2 files changed, 12 insertions(+), 45 deletions(-) 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 cd967ad33..1a0dfec74 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 @@ -232,9 +232,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 } From 8d67962f361e912164afaf1cc4309ea050667a42 Mon Sep 17 00:00:00 2001 From: gedoor Date: Sat, 17 Oct 2020 22:32:02 +0800 Subject: [PATCH 15/39] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/build.gradle | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/build.gradle b/app/build.gradle index 5db9de98b..7a9abe65e 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -129,7 +129,8 @@ dependencies { implementation 'androidx.appcompat:appcompat:1.2.0' implementation 'androidx.media:media:1.2.0' implementation 'androidx.preference:preference-ktx:1.1.1' - implementation 'androidx.constraintlayout:constraintlayout:2.0.2' + //2.02有bug,暂时不要升级 + implementation 'androidx.constraintlayout:constraintlayout:2.0.1' implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0' implementation 'androidx.viewpager2:viewpager2:1.0.0' implementation 'com.google.android.material:material:1.2.1' From ea73c34f5d60d8e5741f80799337bcf27cf0c806 Mon Sep 17 00:00:00 2001 From: gedoor Date: Sat, 17 Oct 2020 22:43:05 +0800 Subject: [PATCH 16/39] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/data/dao/BookGroupDao.kt | 3 +++ .../legado/app/ui/book/group/GroupManageDialog.kt | 5 ++++- .../app/ui/main/bookshelf/BookshelfFragment.kt | 13 +++++++++---- 3 files changed, 16 insertions(+), 5 deletions(-) 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 a7d29d750..4f65a751c 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 @@ -31,6 +31,9 @@ interface BookGroupDao { @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) + @Insert(onConflict = OnConflictStrategy.REPLACE) fun insert(vararg bookGroup: BookGroup) 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 66fb7ebec..c39924f09 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 @@ -164,13 +164,16 @@ 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 } } 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 1a0dfec74..33ac4ee78 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 @@ -12,6 +12,7 @@ import com.google.android.material.tabs.TabLayout import io.legado.app.App import io.legado.app.R import io.legado.app.base.VMBaseFragment +import io.legado.app.constant.AppConst import io.legado.app.constant.EventBus import io.legado.app.constant.PreferKey import io.legado.app.data.entities.BookGroup @@ -123,10 +124,14 @@ class BookshelfFragment : VMBaseFragment(R.layout.fragment_b @Synchronized private fun upGroup(data: List) { - bookGroups.clear() - bookGroups.addAll(data) - adapter.notifyDataSetChanged() - selectLastTab() + if (data.isEmpty()) { + App.db.bookGroupDao().enableGroup(AppConst.bookGroupAllId) + } else { + bookGroups.clear() + bookGroups.addAll(data) + adapter.notifyDataSetChanged() + selectLastTab() + } } @Synchronized From 14858b4d76af90528a1bf8e09a8f71219cdeaf92 Mon Sep 17 00:00:00 2001 From: gedoor Date: Sat, 17 Oct 2020 22:44:54 +0800 Subject: [PATCH 17/39] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/assets/updateLog.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index 33369c847..4a213ec4d 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -3,6 +3,10 @@ * 关注合作公众号 **[小说拾遗]()** 获取好看的小说。 * 旧版数据导入教程:先在旧版阅读(2.x)中进行备份,然后在新版阅读(3.x)【我的】->【备份与恢复】,选择【导入旧版本数据】。 +**2020/10/17** +* 优化分组管理,默认分组可以重命名了 +* 修复书架空白的bug,是constraintlayout库新版本的bug + **2020/10/16** * 修复排版导入背景失败bug * 修改默认度逍遥per为5003,需要重新导入默认 From 15a8a506f03cdd0bbc02fbbe689bfdbac37ae808 Mon Sep 17 00:00:00 2001 From: gedoor Date: Sat, 17 Oct 2020 23:58:39 +0800 Subject: [PATCH 18/39] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/io/legado/app/data/dao/BookGroupDao.kt | 3 +++ .../java/io/legado/app/ui/book/info/BookInfoViewModel.kt | 8 +------- 2 files changed, 4 insertions(+), 7 deletions(-) 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 4f65a751c..84b2cdc6e 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 @@ -34,6 +34,9 @@ interface BookGroupDao { @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/ui/book/info/BookInfoViewModel.kt b/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt index c4f60e92b..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) } From 273402df5d7335b06560e30df61451073d132b1f Mon Sep 17 00:00:00 2001 From: gedoor Date: Sun, 18 Oct 2020 00:07:10 +0800 Subject: [PATCH 19/39] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ui/book/arrange/ArrangeBookActivity.kt | 20 ------------------- .../app/ui/book/arrange/ArrangeBookAdapter.kt | 2 +- app/src/main/res/menu/arrange_book.xml | 16 --------------- 3 files changed, 1 insertion(+), 37 deletions(-) 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 c980fe30c..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 @@ -133,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.bookGroupNoneId - initBookData() - } - R.id.menu_all -> { - title_bar.subtitle = item.title - groupId = AppConst.bookGroupAllId - initBookData() - } - R.id.menu_local -> { - title_bar.subtitle = item.title - groupId = AppConst.bookGroupLocalId - initBookData() - } - R.id.menu_audio -> { - title_bar.subtitle = item.title - groupId = AppConst.bookGroupAudioId - 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 b6a98cb62..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 @@ -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/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" /> - - - - - - - - From 279f9d4b62b4716466839bc69fc7b769a93561d5 Mon Sep 17 00:00:00 2001 From: gedoor Date: Sun, 18 Oct 2020 06:57:43 +0800 Subject: [PATCH 20/39] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=96=B0=E5=AE=89?= =?UTF-8?q?=E8=A3=85=E5=B4=A9=E6=BA=83bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/io/legado/app/data/AppDatabase.kt | 8 ++++---- app/src/main/java/io/legado/app/data/dao/BookGroupDao.kt | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) 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 82407528f..7e8acb854 100644 --- a/app/src/main/java/io/legado/app/data/AppDatabase.kt +++ b/app/src/main/java/io/legado/app/data/AppDatabase.kt @@ -49,25 +49,25 @@ abstract class AppDatabase: RoomDatabase() { override fun onOpen(db: SupportSQLiteDatabase) { db.execSQL( """ - insert into book_groups(groupId, groupName, 'order') select ${AppConst.bookGroupAllId}, '全部', -10 + 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') select ${AppConst.bookGroupLocalId}, '本地', -9 + 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') select ${AppConst.bookGroupAudioId}, '音频', -8 + 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') select ${AppConst.bookGroupNoneId}, '未分组', -7 + insert into book_groups(groupId, groupName, 'order', show) select ${AppConst.bookGroupNoneId}, '未分组', -7, 1 where not exists (select * from book_groups where groupId = ${AppConst.bookGroupNoneId}) """ ) 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 84b2cdc6e..e0ffea726 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,7 +16,7 @@ interface BookGroupDao { @Query("SELECT * FROM book_groups ORDER BY `order`") fun liveDataAll(): LiveData> - @Query("SELECT * FROM book_groups where show > 0 ORDER BY `order`") + @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`") From 274cf4057652ac0543f3e2c8c945a48b77ccbd48 Mon Sep 17 00:00:00 2001 From: gedoor Date: Sun, 18 Oct 2020 07:04:29 +0800 Subject: [PATCH 21/39] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=96=B0=E5=AE=89?= =?UTF-8?q?=E8=A3=85=E5=B4=A9=E6=BA=83bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/assets/updateLog.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index 4a213ec4d..ec5355f22 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -3,9 +3,10 @@ * 关注合作公众号 **[小说拾遗]()** 获取好看的小说。 * 旧版数据导入教程:先在旧版阅读(2.x)中进行备份,然后在新版阅读(3.x)【我的】->【备份与恢复】,选择【导入旧版本数据】。 -**2020/10/17** +**2020/10/18** * 优化分组管理,默认分组可以重命名了 * 修复书架空白的bug,是constraintlayout库新版本的bug +* 修复分组和崩溃bug **2020/10/16** * 修复排版导入背景失败bug From b0b7b1b0d84e96dd6a3e8e12e2846dcda3e53f5b Mon Sep 17 00:00:00 2001 From: gedoor Date: Sun, 18 Oct 2020 07:24:17 +0800 Subject: [PATCH 22/39] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=88=86=E7=BB=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/io/legado/app/data/dao/BookGroupDao.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 e0ffea726..453a45f3e 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 @@ -22,7 +22,7 @@ interface BookGroupDao { @Query("SELECT * FROM book_groups where groupId >= 0 ORDER BY `order`") fun liveDataSelect(): LiveData> - @get:Query("SELECT sum(groupId) FROM book_groups") + @get:Query("SELECT sum(groupId) FROM book_groups where groupId >= 0") val idsSum: Long @get:Query("SELECT MAX(`order`) FROM book_groups") From 7518c094b59959582b6fade360aed7a5b15bbd41 Mon Sep 17 00:00:00 2001 From: gedoor Date: Sun, 18 Oct 2020 07:26:16 +0800 Subject: [PATCH 23/39] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=88=86=E7=BB=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/io/legado/app/data/dao/BookGroupDao.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 453a45f3e..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 @@ -25,7 +25,7 @@ interface BookGroupDao { @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`") From 86b69908fa74779b6dc18c0879a12daf13ecd079 Mon Sep 17 00:00:00 2001 From: gedoor Date: Sun, 18 Oct 2020 07:46:40 +0800 Subject: [PATCH 24/39] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=88=86=E7=BB=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/io/legado/app/data/dao/BookDao.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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..cbb1ec990 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 @@ -24,10 +24,10 @@ interface BookDao { @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") + @Query("select * from books where (SELECT sum(groupId) FROM book_groups where groupId > 0) & `group` = 0") fun observeNoGroup(): LiveData> - @Query("select count(bookUrl) from books where (SELECT sum(groupId) FROM book_groups) & `group` = 0") + @Query("select count(bookUrl) from books where (SELECT sum(groupId) FROM book_groups where groupId > 0) & `group` = 0") fun observeNoGroupSize(): LiveData @Query("SELECT * FROM books WHERE name like '%'||:key||'%' or author like '%'||:key||'%'") From a349326ad3cad0db91054246f73de169b3f9b105 Mon Sep 17 00:00:00 2001 From: gedoor Date: Sun, 18 Oct 2020 07:54:56 +0800 Subject: [PATCH 25/39] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=88=86=E7=BB=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/io/legado/app/constant/EventBus.kt | 1 - .../io/legado/app/ui/main/bookshelf/BookshelfFragment.kt | 7 ------- 2 files changed, 8 deletions(-) diff --git a/app/src/main/java/io/legado/app/constant/EventBus.kt b/app/src/main/java/io/legado/app/constant/EventBus.kt index f8f1541a8..8fe6df384 100644 --- a/app/src/main/java/io/legado/app/constant/EventBus.kt +++ b/app/src/main/java/io/legado/app/constant/EventBus.kt @@ -4,7 +4,6 @@ object EventBus { const val MEDIA_BUTTON = "mediaButton" const val RECREATE = "RECREATE" const val UP_BOOK = "upBookToc" - const val UP_BOOK_GROUP = "upBookGroup" const val ALOUD_STATE = "aloud_state" const val TTS_PROGRESS = "ttsStart" const val TTS_DS = "ttsDs" 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 33ac4ee78..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 @@ -13,7 +13,6 @@ import io.legado.app.App import io.legado.app.R import io.legado.app.base.VMBaseFragment import io.legado.app.constant.AppConst -import io.legado.app.constant.EventBus import io.legado.app.constant.PreferKey import io.legado.app.data.entities.BookGroup import io.legado.app.lib.dialogs.alert @@ -203,12 +202,6 @@ class BookshelfFragment : VMBaseFragment(R.layout.fragment_b fragmentMap[selectedGroup?.groupId]?.gotoTop() } - override fun observeLiveBus() { - observeEvent>(EventBus.UP_BOOK_GROUP) { - upGroup(it) - } - } - private inner class TabFragmentPageAdapter(fm: FragmentManager) : FragmentStatePagerAdapter(fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT) { From a1ce3797e3da2590872b32ca2ab4864e1869ddf8 Mon Sep 17 00:00:00 2001 From: gedoor Date: Sun, 18 Oct 2020 09:06:45 +0800 Subject: [PATCH 26/39] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/ui/widget/image/CoverImageView.kt | 6 +++++- app/src/main/res/layout/item_bookshelf_grid.xml | 4 +--- 2 files changed, 6 insertions(+), 4 deletions(-) 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/res/layout/item_bookshelf_grid.xml b/app/src/main/res/layout/item_bookshelf_grid.xml index 618dc8c1f..0816a9a83 100644 --- a/app/src/main/res/layout/item_bookshelf_grid.xml +++ b/app/src/main/res/layout/item_bookshelf_grid.xml @@ -52,13 +52,11 @@ android:id="@+id/tv_name" android:layout_width="match_parent" android:layout_height="wrap_content" - android:layout_marginTop="8dp" + android:layout_marginTop="6dp" android:ellipsize="end" android:gravity="top|center_horizontal" android:includeFontPadding="false" android:lines="2" - android:paddingLeft="4dp" - android:paddingRight="4dp" android:text="@string/book_name" android:textColor="@color/primaryText" android:textSize="12sp" From ce64e6269e249009a4665a1792da5f7569301456 Mon Sep 17 00:00:00 2001 From: gedoor Date: Sun, 18 Oct 2020 09:26:48 +0800 Subject: [PATCH 27/39] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/build.gradle | 3 +-- .../legado/app/ui/main/explore/ExploreFragment.kt | 4 ++-- app/src/main/res/layout/activity_main.xml | 13 ++++++------- app/src/main/res/layout/fragment_bookshelf.xml | 11 ++++------- ...{fragment_find_book.xml => fragment_explore.xml} | 0 5 files changed, 13 insertions(+), 18 deletions(-) rename app/src/main/res/layout/{fragment_find_book.xml => fragment_explore.xml} (100%) diff --git a/app/build.gradle b/app/build.gradle index 7a9abe65e..5db9de98b 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -129,8 +129,7 @@ dependencies { implementation 'androidx.appcompat:appcompat:1.2.0' implementation 'androidx.media:media:1.2.0' implementation 'androidx.preference:preference-ktx:1.1.1' - //2.02有bug,暂时不要升级 - implementation 'androidx.constraintlayout:constraintlayout:2.0.1' + implementation 'androidx.constraintlayout:constraintlayout:2.0.2' implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0' implementation 'androidx.viewpager2:viewpager2:1.0.0' implementation 'com.google.android.material:material:1.2.1' 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 9cdfdbad5..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) 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_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 100% rename from app/src/main/res/layout/fragment_find_book.xml rename to app/src/main/res/layout/fragment_explore.xml From 991fa025d530d4eb9f5a23d4c142f28699e26e47 Mon Sep 17 00:00:00 2001 From: gedoor Date: Sun, 18 Oct 2020 09:29:00 +0800 Subject: [PATCH 28/39] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/build.gradle | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 5db9de98b..37d539d83 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -208,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 From eabc8a2d922263fc756eee2eede918c5c10ed5cc Mon Sep 17 00:00:00 2001 From: gedoor Date: Sun, 18 Oct 2020 09:30:41 +0800 Subject: [PATCH 29/39] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/io/legado/app/help/AppConfig.kt | 24 ------------------- 1 file changed, 24 deletions(-) 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( From 9f63cff7f45403f2487b2b5e8fb7bf1e3b82c878 Mon Sep 17 00:00:00 2001 From: gedoor Date: Sun, 18 Oct 2020 09:36:04 +0800 Subject: [PATCH 30/39] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/io/legado/app/model/rss/Result.kt | 5 ----- app/src/main/java/io/legado/app/model/rss/Rss.kt | 4 +--- .../java/io/legado/app/model/rss/RssParserByRule.kt | 11 ++++++++--- .../model/rss/{RssParser.kt => RssParserDefault.kt} | 6 +++--- .../main/java/io/legado/app/model/rss/RssResult.kt | 5 +++++ 5 files changed, 17 insertions(+), 14 deletions(-) delete mode 100644 app/src/main/java/io/legado/app/model/rss/Result.kt rename app/src/main/java/io/legado/app/model/rss/{RssParser.kt => RssParserDefault.kt} (98%) create mode 100644 app/src/main/java/io/legado/app/model/rss/RssResult.kt 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 From 4eab3b92a092b659c7c98f4f51b762b03e18210d Mon Sep 17 00:00:00 2001 From: gedoor Date: Sun, 18 Oct 2020 16:19:21 +0800 Subject: [PATCH 31/39] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/ui/book/cache/CacheActivity.kt | 12 ++---------- app/src/main/res/menu/download.xml | 16 +--------------- 2 files changed, 3 insertions(+), 25 deletions(-) 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 97a16813c..504c17f2f 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 @@ -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.bookGroupNoneId - initBookData() - } - R.id.menu_all -> { - title_bar.subtitle = item.title - groupId = AppConst.bookGroupAllId - initBookData() - } else -> if (item.groupId == R.id.menu_group) { title_bar.subtitle = item.title groupId = App.db.bookGroupDao().getByName(item.title.toString())?.groupId ?: 0 @@ -124,6 +114,8 @@ class CacheActivity : VMBaseActivity(R.layout.activity_download) booksLiveData?.removeObservers(this) booksLiveData = when (groupId) { 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) } diff --git a/app/src/main/res/menu/download.xml b/app/src/main/res/menu/download.xml index 6303b5b9d..2f50268d9 100644 --- a/app/src/main/res/menu/download.xml +++ b/app/src/main/res/menu/download.xml @@ -14,21 +14,7 @@ android:id="@+id/menu_book_group" android:title="@string/group" android:icon="@drawable/ic_groups" - app:showAsAction="always"> - - - - - - - - - - + app:showAsAction="always" /> Date: Sun, 18 Oct 2020 16:28:49 +0800 Subject: [PATCH 32/39] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/io/legado/app/ui/book/cache/CacheActivity.kt | 2 +- app/src/main/res/layout/item_rss.xml | 1 + app/src/main/res/menu/{download.xml => book_cache.xml} | 6 +++++- 3 files changed, 7 insertions(+), 2 deletions(-) rename app/src/main/res/menu/{download.xml => book_cache.xml} (90%) 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 504c17f2f..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) } 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/download.xml b/app/src/main/res/menu/book_cache.xml similarity index 90% rename from app/src/main/res/menu/download.xml rename to app/src/main/res/menu/book_cache.xml index 2f50268d9..689fc54ae 100644 --- a/app/src/main/res/menu/download.xml +++ b/app/src/main/res/menu/book_cache.xml @@ -14,7 +14,11 @@ android:id="@+id/menu_book_group" android:title="@string/group" android:icon="@drawable/ic_groups" - app:showAsAction="always" /> + app:showAsAction="always"> + + + + Date: Sun, 18 Oct 2020 16:52:36 +0800 Subject: [PATCH 33/39] =?UTF-8?q?=E6=9C=AA=E5=88=86=E7=BB=84=E6=8E=92?= =?UTF-8?q?=E9=99=A4=E6=9C=AC=E5=9C=B0=E5=92=8C=E9=9F=B3=E9=A2=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/io/legado/app/data/dao/BookDao.kt | 16 ++++++++++------ .../io/legado/app/data/entities/BookGroup.kt | 17 ++++++++++++++++- 2 files changed, 26 insertions(+), 7 deletions(-) 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 cbb1ec990..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 where groupId > 0) & `group` = 0") - 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 * 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/entities/BookGroup.kt b/app/src/main/java/io/legado/app/data/entities/BookGroup.kt index 20a8263a3..4a24e9acb 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 @@ -13,4 +16,16 @@ data class BookGroup( var groupName: String, var order: Int = 0, var show: Boolean = true -) : Parcelable \ No newline at end of file +) : Parcelable { + + fun getDefaultName(context: Context): String { + return when (groupId) { + AppConst.bookGroupAllId -> context.getString(R.string.all) + AppConst.bookGroupAudioId -> context.getString(R.string.audio) + AppConst.bookGroupLocalId -> context.getString(R.string.local) + AppConst.bookGroupNoneId -> context.getString(R.string.no_group) + else -> groupName + } + } + +} \ No newline at end of file From 6a10d276f15222fb5cf577fb32076fb86e2638a7 Mon Sep 17 00:00:00 2001 From: gedoor Date: Sun, 18 Oct 2020 17:52:53 +0800 Subject: [PATCH 34/39] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=98=85=E8=AF=BB?= =?UTF-8?q?=E8=AE=B0=E5=BD=95=E6=8E=92=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/io/legado/app/data/AppDatabase.kt | 8 ++++++++ app/src/main/java/io/legado/app/data/dao/ReadRecordDao.kt | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) 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 7e8acb854..dc144493b 100644 --- a/app/src/main/java/io/legado/app/data/AppDatabase.kt +++ b/app/src/main/java/io/legado/app/data/AppDatabase.kt @@ -10,6 +10,7 @@ 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( @@ -46,7 +47,14 @@ abstract class AppDatabase: RoomDatabase() { .build() private val dbCallback = object : Callback() { + + override fun onCreate(db: SupportSQLiteDatabase) { + super.onCreate(db) + db.setLocale(Locale.CHINESE) + } + override fun onOpen(db: SupportSQLiteDatabase) { + db.setLocale(Locale.CHINESE) db.execSQL( """ insert into book_groups(groupId, groupName, 'order', show) select ${AppConst.bookGroupAllId}, '全部', -10, 1 diff --git a/app/src/main/java/io/legado/app/data/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") From a0ebd3d0003ee1cef7f98ed104dc73c6aa4bbe1e Mon Sep 17 00:00:00 2001 From: gedoor Date: Sun, 18 Oct 2020 18:05:06 +0800 Subject: [PATCH 35/39] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=88=86=E7=BB=84?= =?UTF-8?q?=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/io/legado/app/data/entities/BookGroup.kt | 10 +++++----- .../io/legado/app/ui/book/group/GroupManageDialog.kt | 6 +++--- .../io/legado/app/ui/book/group/GroupSelectDialog.kt | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) 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 4a24e9acb..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 @@ -18,12 +18,12 @@ data class BookGroup( var show: Boolean = true ) : Parcelable { - fun getDefaultName(context: Context): String { + fun getManageName(context: Context): String { return when (groupId) { - AppConst.bookGroupAllId -> context.getString(R.string.all) - AppConst.bookGroupAudioId -> context.getString(R.string.audio) - AppConst.bookGroupLocalId -> context.getString(R.string.local) - AppConst.bookGroupNoneId -> context.getString(R.string.no_group) + 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 } } 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 c39924f09..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 @@ -107,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) } } } @@ -129,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) } } @@ -187,7 +187,7 @@ class GroupManageDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener 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 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 f648527cb..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 @@ -128,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) } } } @@ -150,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) } } From 2c40f3c06b53b1878e9c47cbc1bb73070f44bb89 Mon Sep 17 00:00:00 2001 From: gedoor Date: Sun, 18 Oct 2020 18:13:34 +0800 Subject: [PATCH 36/39] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=88=86=E7=BB=84?= =?UTF-8?q?=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/io/legado/app/ui/filechooser/utils/ConvertUtils.kt | 1 + 1 file changed, 1 insertion(+) 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 From 8383ffe63c849607fe3b97126ca38aef3efdbae9 Mon Sep 17 00:00:00 2001 From: gedoor Date: Sun, 18 Oct 2020 18:23:02 +0800 Subject: [PATCH 37/39] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/constant/AppPattern.kt | 1 + .../app/model/analyzeRule/AnalyzeRule.kt | 2 +- .../legado/app/ui/widget/image/PhotoView.kt | 6 ++++-- .../legado/app/ui/widget/image/photo/Info.kt | 1 + .../image/photo/RotateGestureDetector.kt | 20 +++++++++---------- .../main/java/io/legado/app/utils/ACache.kt | 3 ++- 6 files changed, 19 insertions(+), 14 deletions(-) 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/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/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/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()) { From 3891fadc64f4261eecc88455d56fffd5862d4645 Mon Sep 17 00:00:00 2001 From: gedoor Date: Sun, 18 Oct 2020 18:43:57 +0800 Subject: [PATCH 38/39] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/ui/widget/LabelsBar.kt | 2 +- .../io/legado/app/ui/widget/SearchView.kt | 2 ++ .../legado/app/ui/widget/SelectActionBar.kt | 1 + .../io/legado/app/ui/widget/ShadowLayout.kt | 1 + .../java/io/legado/app/ui/widget/TitleBar.kt | 1 + .../app/ui/widget/anima/RefreshProgressBar.kt | 1 + .../app/ui/widget/anima/RotateLoading.kt | 1 + .../explosion_field/ExplosionAnimator.kt | 31 ++++++++++--------- .../anima/explosion_field/ExplosionView.kt | 5 +-- .../app/ui/widget/image/CircleImageView.kt | 1 + .../java/io/legado/app/utils/BitmapUtils.kt | 2 +- .../java/io/legado/app/utils/ColorUtils.kt | 2 +- .../io/legado/app/utils/ConstraintUtil.kt | 2 ++ .../java/io/legado/app/utils/DocumentUtils.kt | 1 + .../io/legado/app/utils/EventBusExtensions.kt | 2 ++ .../java/io/legado/app/utils/FileUtils.kt | 13 ++++---- .../io/legado/app/utils/FragmentExtensions.kt | 26 ++++++++++++---- .../io/legado/app/utils/JsoupExtensions.kt | 31 +++++++++---------- .../java/io/legado/app/utils/LanguageUtils.kt | 8 ----- .../java/io/legado/app/utils/StringUtils.kt | 2 +- .../io/legado/app/utils/ViewExtensions.kt | 8 ----- 21 files changed, 76 insertions(+), 67 deletions(-) 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/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/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/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/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 } From 34e61195b3a4435fbd11fe52fa7ccf3a8bfcbd0f Mon Sep 17 00:00:00 2001 From: gedoor Date: Sun, 18 Oct 2020 19:10:21 +0800 Subject: [PATCH 39/39] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../legado/app/ui/widget/dynamiclayout/DynamicFrameLayout.kt | 1 + .../java/io/legado/app/ui/widget/number/NumberPickerDialog.kt | 2 +- .../main/java/io/legado/app/ui/widget/prefs/ColorPreference.kt | 1 + .../java/io/legado/app/ui/widget/recycler/DividerNoLast.kt | 1 + .../io/legado/app/ui/widget/recycler/DragSelectTouchHelper.kt | 2 +- .../java/io/legado/app/ui/widget/recycler/ItemTouchCallback.kt | 1 + .../main/java/io/legado/app/ui/widget/recycler/LoadMoreView.kt | 1 + .../io/legado/app/ui/widget/recycler/UpLinearLayoutManager.kt | 1 + .../app/ui/widget/recycler/scroller/FastScrollRecyclerView.kt | 1 + .../io/legado/app/ui/widget/recycler/scroller/FastScroller.kt | 2 ++ .../java/io/legado/app/ui/widget/seekbar/VerticalSeekBar.kt | 1 + app/src/main/java/io/legado/app/utils/FloatExtensions.kt | 3 ++- app/src/main/java/io/legado/app/utils/NetworkUtils.kt | 2 +- 13 files changed, 15 insertions(+), 4 deletions(-) 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/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 a68ac72f4..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,6 +12,7 @@ import androidx.viewpager.widget.ViewPager * Created by GKF on 2018/3/16. */ +@Suppress("MemberVisibilityCanBePrivate") class ItemTouchCallback(private val callback: Callback) : ItemTouchHelper.Callback() { private var swipeRefreshLayout: SwipeRefreshLayout? = null 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/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/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()