更新界面
This commit is contained in:
@@ -2,11 +2,13 @@ package io.legato.kazusa.base
|
||||
|
||||
import android.content.DialogInterface
|
||||
import android.content.DialogInterface.OnDismissListener
|
||||
import android.content.res.Configuration
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import androidx.annotation.LayoutRes
|
||||
import androidx.fragment.app.FragmentManager
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import com.google.android.material.bottomsheet.BottomSheetDialog
|
||||
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
|
||||
import io.legato.kazusa.constant.AppLog
|
||||
import io.legato.kazusa.help.coroutine.Coroutine
|
||||
@@ -24,11 +26,14 @@ abstract class BaseBottomSheetDialogFragment(
|
||||
this.onDismissListener = onDismissListener
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
// if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.N) {
|
||||
// setStyle(STYLE_NO_TITLE, 0)
|
||||
// }
|
||||
override fun onStart() {
|
||||
super.onStart()
|
||||
if (resources.configuration.orientation == Configuration.ORIENTATION_LANDSCAPE) {
|
||||
val screenHeight = resources.displayMetrics.heightPixels
|
||||
(dialog as? BottomSheetDialog)?.behavior?.apply {
|
||||
peekHeight = (screenHeight * 0.7f).toInt()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
|
||||
@@ -35,8 +35,8 @@ import io.legato.kazusa.lib.dialogs.alert
|
||||
import io.legato.kazusa.service.BaseReadAloudService
|
||||
import io.legato.kazusa.ui.about.CrashLogsDialog
|
||||
import io.legato.kazusa.ui.main.bookshelf.BaseBookshelfFragment
|
||||
import io.legato.kazusa.ui.main.bookshelf.style1.BookshelfFragment1
|
||||
import io.legato.kazusa.ui.main.bookshelf.style2.BookshelfFragment2
|
||||
import io.legato.kazusa.ui.main.bookshelf.books.BookshelfFragment1
|
||||
import io.legato.kazusa.ui.main.bookshelf.books.BookshelfFragment2
|
||||
import io.legato.kazusa.ui.main.explore.ExploreFragment
|
||||
import io.legato.kazusa.ui.main.my.MyFragment
|
||||
import io.legato.kazusa.ui.main.rss.RssFragment
|
||||
@@ -55,7 +55,7 @@ import kotlin.coroutines.resume
|
||||
import kotlin.coroutines.suspendCoroutine
|
||||
import androidx.core.view.get
|
||||
import com.google.android.material.navigation.NavigationBarView
|
||||
import io.legato.kazusa.ui.main.bookshelf.style1.BookshelfFragment3
|
||||
import io.legato.kazusa.ui.main.bookshelf.books.BookshelfFragment3
|
||||
|
||||
/**
|
||||
* 主界面
|
||||
@@ -92,7 +92,6 @@ class MainActivity : VMBaseActivity<ActivityMainBinding, MainViewModel>(),
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
// 绑定返回键逻辑
|
||||
onBackPressedDispatcher.addCallback(this) {
|
||||
if (pagePosition != 0) {
|
||||
binding.viewPagerMain.currentItem = 0
|
||||
|
||||
+35
-22
@@ -1,7 +1,6 @@
|
||||
package io.legato.kazusa.ui.main.bookshelf.style1.books
|
||||
package io.legato.kazusa.ui.main.bookshelf.books
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.res.Configuration
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import android.view.ViewConfiguration
|
||||
@@ -28,6 +27,9 @@ import io.legato.kazusa.help.config.AppConfig
|
||||
//import io.legado.app.lib.theme.primaryColor
|
||||
import io.legato.kazusa.ui.book.info.BookInfoActivity
|
||||
import io.legato.kazusa.ui.main.MainViewModel
|
||||
import io.legato.kazusa.ui.main.bookshelf.books.styleDefalut.BaseBooksAdapter
|
||||
import io.legato.kazusa.ui.main.bookshelf.books.styleDefalut.BooksAdapterGrid
|
||||
import io.legato.kazusa.ui.main.bookshelf.books.styleDefalut.BooksAdapterList
|
||||
import io.legato.kazusa.utils.bookshelfLayout
|
||||
import io.legato.kazusa.utils.cnCompare
|
||||
import io.legato.kazusa.utils.flowWithLifecycleAndDatabaseChangeFirst
|
||||
@@ -147,12 +149,12 @@ class BooksFragment() : BaseFragment(R.layout.fragment_books),
|
||||
}
|
||||
}
|
||||
|
||||
fun upBookSort(sort: Int) {
|
||||
binding.root.post {
|
||||
arguments?.putInt("bookSort", sort)
|
||||
bookSort = sort
|
||||
fun upBookSort() {
|
||||
// binding.root.post {
|
||||
// arguments?.putInt("bookSort", sort)
|
||||
// bookSort = sort
|
||||
upRecyclerData()
|
||||
}
|
||||
// }
|
||||
}
|
||||
|
||||
fun setEnableRefresh(enable: Boolean) {
|
||||
@@ -168,24 +170,36 @@ class BooksFragment() : BaseFragment(R.layout.fragment_books),
|
||||
booksFlowJob = viewLifecycleOwner.lifecycleScope.launch {
|
||||
appDb.bookDao.flowByGroup(groupId).map { list ->
|
||||
//排序
|
||||
|
||||
val isDescending = AppConfig.bookshelfSortOrder == 1
|
||||
|
||||
when (bookSort) {
|
||||
1 -> list.sortedByDescending { it.latestChapterTime }
|
||||
2 -> list.sortedWith { o1, o2 ->
|
||||
o1.name.cnCompare(o2.name)
|
||||
}
|
||||
1 -> if (isDescending) list.sortedByDescending { it.latestChapterTime }
|
||||
else list.sortedBy { it.latestChapterTime }
|
||||
|
||||
3 -> list.sortedBy { it.order }
|
||||
2 -> if (isDescending)
|
||||
list.sortedWith { o1, o2 -> o2.name.cnCompare(o1.name) }
|
||||
else
|
||||
list.sortedWith { o1, o2 -> o1.name.cnCompare(o2.name) }
|
||||
|
||||
// 综合排序 issue #3192
|
||||
4 -> list.sortedByDescending {
|
||||
max(it.latestChapterTime, it.durChapterTime)
|
||||
}
|
||||
// 按作者排序
|
||||
5 -> list.sortedWith { o1, o2 ->
|
||||
o1.author.cnCompare(o2.author)
|
||||
}
|
||||
3 -> if (isDescending) list.sortedByDescending { it.order }
|
||||
else list.sortedBy { it.order }
|
||||
|
||||
else -> list.sortedByDescending { it.durChapterTime }
|
||||
4 -> if (isDescending) list.sortedByDescending {
|
||||
max(
|
||||
it.latestChapterTime,
|
||||
it.durChapterTime
|
||||
)
|
||||
}
|
||||
else list.sortedBy { max(it.latestChapterTime, it.durChapterTime) }
|
||||
|
||||
5 -> if (isDescending)
|
||||
list.sortedWith { o1, o2 -> o2.author.cnCompare(o1.author) }
|
||||
else
|
||||
list.sortedWith { o1, o2 -> o1.author.cnCompare(o2.author) }
|
||||
|
||||
else -> if (isDescending) list.sortedByDescending { it.durChapterTime }
|
||||
else list.sortedBy { it.durChapterTime }
|
||||
}
|
||||
}.flowWithLifecycleAndDatabaseChangeFirst(
|
||||
viewLifecycleOwner.lifecycle,
|
||||
@@ -197,7 +211,6 @@ class BooksFragment() : BaseFragment(R.layout.fragment_books),
|
||||
binding.tvEmptyMsg.isGone = list.isNotEmpty()
|
||||
binding.refreshLayout.isEnabled = enableRefresh && list.isNotEmpty()
|
||||
booksAdapter.setItems(list)
|
||||
delay(100)
|
||||
}
|
||||
}
|
||||
}
|
||||
+2
-6
@@ -1,6 +1,6 @@
|
||||
@file:Suppress("DEPRECATION")
|
||||
|
||||
package io.legato.kazusa.ui.main.bookshelf.style1
|
||||
package io.legato.kazusa.ui.main.bookshelf.books
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.os.Bundle
|
||||
@@ -19,7 +19,6 @@ import io.legato.kazusa.help.config.AppConfig
|
||||
import io.legato.kazusa.ui.book.group.GroupEditDialog
|
||||
import io.legato.kazusa.ui.book.search.SearchActivity
|
||||
import io.legato.kazusa.ui.main.bookshelf.BaseBookshelfFragment
|
||||
import io.legato.kazusa.ui.main.bookshelf.style1.books.BooksFragment
|
||||
import io.legato.kazusa.utils.showDialogFragment
|
||||
import io.legato.kazusa.utils.toastOnUi
|
||||
import io.legato.kazusa.utils.viewbindingdelegate.viewBinding
|
||||
@@ -116,11 +115,8 @@ class BookshelfFragment1() : BaseBookshelfFragment(R.layout.fragment_bookshelf1)
|
||||
if (it is BooksFragment) {
|
||||
val position = it.position
|
||||
val group = bookGroups.getOrNull(position) ?: return@forEach
|
||||
val newSort = group.getRealBookSort()
|
||||
it.setEnableRefresh(group.enableRefresh)
|
||||
if (it.bookSort != newSort) {
|
||||
it.upBookSort(newSort)
|
||||
}
|
||||
it.upBookSort()
|
||||
}
|
||||
}
|
||||
}
|
||||
+29
-21
@@ -1,4 +1,4 @@
|
||||
package io.legato.kazusa.ui.main.bookshelf.style2
|
||||
package io.legato.kazusa.ui.main.bookshelf.books
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.os.Bundle
|
||||
@@ -24,6 +24,9 @@ import io.legato.kazusa.ui.book.group.GroupEditDialog
|
||||
import io.legato.kazusa.ui.book.info.BookInfoActivity
|
||||
import io.legato.kazusa.ui.book.search.SearchActivity
|
||||
import io.legato.kazusa.ui.main.bookshelf.BaseBookshelfFragment
|
||||
import io.legato.kazusa.ui.main.bookshelf.books.styleFold.BaseBooksAdapter
|
||||
import io.legato.kazusa.ui.main.bookshelf.books.styleFold.BooksAdapterGrid
|
||||
import io.legato.kazusa.ui.main.bookshelf.books.styleFold.BooksAdapterList
|
||||
import io.legato.kazusa.utils.bookshelfLayout
|
||||
import io.legato.kazusa.utils.cnCompare
|
||||
import io.legato.kazusa.utils.flowWithLifecycleAndDatabaseChangeFirst
|
||||
@@ -39,7 +42,6 @@ import kotlinx.coroutines.flow.conflate
|
||||
import kotlinx.coroutines.flow.flowOn
|
||||
import kotlinx.coroutines.flow.map
|
||||
import kotlinx.coroutines.launch
|
||||
import java.util.Locale
|
||||
import kotlin.math.max
|
||||
|
||||
/**
|
||||
@@ -69,7 +71,7 @@ class BookshelfFragment2() : BaseBookshelfFragment(R.layout.fragment_bookshelf2)
|
||||
|
||||
private var bookGroups: List<BookGroup> = emptyList()
|
||||
private var booksFlowJob: Job? = null
|
||||
override var groupId = BookGroup.IdRoot
|
||||
override var groupId = BookGroup.Companion.IdRoot
|
||||
private var allBooks: List<Book> = emptyList()
|
||||
override var books: List<Book> = emptyList()
|
||||
private var enableRefresh = true
|
||||
@@ -134,7 +136,7 @@ class BookshelfFragment2() : BaseBookshelfFragment(R.layout.fragment_bookshelf2)
|
||||
allBooksFlowJob?.cancel()
|
||||
allBooksFlowJob = viewLifecycleOwner.lifecycleScope.launch {
|
||||
appDb.bookDao.flowAll().map { list ->
|
||||
when (AppConfig.getBookSortByGroupId(BookGroup.IdRoot)) {
|
||||
when (AppConfig.getBookSortByGroupId(BookGroup.Companion.IdRoot)) {
|
||||
1 -> list.sortedByDescending { it.latestChapterTime }
|
||||
2 -> list.sortedWith { o1, o2 -> o1.name.cnCompare(o2.name) }
|
||||
3 -> list.sortedBy { it.order }
|
||||
@@ -144,7 +146,7 @@ class BookshelfFragment2() : BaseBookshelfFragment(R.layout.fragment_bookshelf2)
|
||||
}.flowWithLifecycleAndDatabaseChangeFirst(
|
||||
viewLifecycleOwner.lifecycle,
|
||||
Lifecycle.State.RESUMED,
|
||||
AppDatabase.BOOK_TABLE_NAME
|
||||
AppDatabase.Companion.BOOK_TABLE_NAME
|
||||
).catch {
|
||||
AppLog.put("所有书籍更新出错", it)
|
||||
}.conflate().flowOn(Dispatchers.Default).collect { list ->
|
||||
@@ -156,7 +158,7 @@ class BookshelfFragment2() : BaseBookshelfFragment(R.layout.fragment_bookshelf2)
|
||||
}
|
||||
|
||||
private fun initBooksData() {
|
||||
if (groupId == BookGroup.IdRoot) {
|
||||
if (groupId == BookGroup.Companion.IdRoot) {
|
||||
if (isAdded) {
|
||||
binding.titleBar.title = getString(R.string.bookshelf)
|
||||
binding.refreshLayout.isEnabled = true
|
||||
@@ -173,9 +175,7 @@ class BookshelfFragment2() : BaseBookshelfFragment(R.layout.fragment_bookshelf2)
|
||||
}
|
||||
booksFlowJob?.cancel()
|
||||
booksFlowJob = viewLifecycleOwner.lifecycleScope.launch {
|
||||
|
||||
appDb.bookDao.flowByGroup(groupId).map { list ->
|
||||
|
||||
//排序
|
||||
val isDescending = AppConfig.bookshelfSortOrder == 1
|
||||
|
||||
@@ -183,15 +183,27 @@ class BookshelfFragment2() : BaseBookshelfFragment(R.layout.fragment_bookshelf2)
|
||||
1 -> if (isDescending) list.sortedByDescending { it.latestChapterTime }
|
||||
else list.sortedBy { it.latestChapterTime }
|
||||
|
||||
2 -> if (isDescending) list.sortedWith(compareByDescending { it.name.cnCompareKey() })
|
||||
else list.sortedWith(compareBy { it.name.cnCompareKey() })
|
||||
2 -> if (isDescending)
|
||||
list.sortedWith { o1, o2 -> o2.name.cnCompare(o1.name) }
|
||||
else
|
||||
list.sortedWith { o1, o2 -> o1.name.cnCompare(o2.name) }
|
||||
|
||||
3 -> if (isDescending) list.sortedByDescending { it.order }
|
||||
else list.sortedBy { it.order }
|
||||
|
||||
4 -> if (isDescending) list.sortedByDescending { max(it.latestChapterTime, it.durChapterTime) }
|
||||
4 -> if (isDescending) list.sortedByDescending {
|
||||
max(
|
||||
it.latestChapterTime,
|
||||
it.durChapterTime
|
||||
)
|
||||
}
|
||||
else list.sortedBy { max(it.latestChapterTime, it.durChapterTime) }
|
||||
|
||||
5 -> if (isDescending)
|
||||
list.sortedWith { o1, o2 -> o2.author.cnCompare(o1.author) }
|
||||
else
|
||||
list.sortedWith { o1, o2 -> o1.author.cnCompare(o2.author) }
|
||||
|
||||
else -> if (isDescending) list.sortedByDescending { it.durChapterTime }
|
||||
else list.sortedBy { it.durChapterTime }
|
||||
}
|
||||
@@ -199,7 +211,7 @@ class BookshelfFragment2() : BaseBookshelfFragment(R.layout.fragment_bookshelf2)
|
||||
}.flowWithLifecycleAndDatabaseChangeFirst(
|
||||
viewLifecycleOwner.lifecycle,
|
||||
Lifecycle.State.RESUMED,
|
||||
AppDatabase.BOOK_TABLE_NAME
|
||||
AppDatabase.Companion.BOOK_TABLE_NAME
|
||||
).catch {
|
||||
AppLog.put("书架更新出错", it)
|
||||
}.conflate().flowOn(Dispatchers.Default).collect { list ->
|
||||
@@ -211,13 +223,9 @@ class BookshelfFragment2() : BaseBookshelfFragment(R.layout.fragment_bookshelf2)
|
||||
}
|
||||
}
|
||||
|
||||
fun String.cnCompareKey(): String {
|
||||
return this.trim().lowercase(Locale.getDefault())
|
||||
}
|
||||
|
||||
fun back(): Boolean {
|
||||
if (groupId != BookGroup.IdRoot) {
|
||||
groupId = BookGroup.IdRoot
|
||||
if (groupId != BookGroup.Companion.IdRoot) {
|
||||
groupId = BookGroup.Companion.IdRoot
|
||||
initBooksData()
|
||||
return true
|
||||
}
|
||||
@@ -225,7 +233,7 @@ class BookshelfFragment2() : BaseBookshelfFragment(R.layout.fragment_bookshelf2)
|
||||
}
|
||||
|
||||
override fun onQueryTextSubmit(query: String?): Boolean {
|
||||
SearchActivity.start(requireContext(), query)
|
||||
SearchActivity.Companion.start(requireContext(), query)
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -268,7 +276,7 @@ class BookshelfFragment2() : BaseBookshelfFragment(R.layout.fragment_bookshelf2)
|
||||
}
|
||||
|
||||
fun getItemCount(): Int {
|
||||
return if (groupId == BookGroup.IdRoot) {
|
||||
return if (groupId == BookGroup.Companion.IdRoot) {
|
||||
bookGroups.size + books.size
|
||||
} else {
|
||||
books.size
|
||||
@@ -276,7 +284,7 @@ class BookshelfFragment2() : BaseBookshelfFragment(R.layout.fragment_bookshelf2)
|
||||
}
|
||||
|
||||
override fun getItems(): List<Any> {
|
||||
return if (groupId == BookGroup.IdRoot) {
|
||||
return if (groupId == BookGroup.Companion.IdRoot) {
|
||||
bookGroups + books
|
||||
} else {
|
||||
books
|
||||
+2
-6
@@ -1,6 +1,6 @@
|
||||
@file:Suppress("DEPRECATION")
|
||||
|
||||
package io.legato.kazusa.ui.main.bookshelf.style1
|
||||
package io.legato.kazusa.ui.main.bookshelf.books
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.os.Bundle
|
||||
@@ -18,7 +18,6 @@ import io.legato.kazusa.databinding.FragmentBookshelf3Binding
|
||||
import io.legato.kazusa.help.config.AppConfig
|
||||
import io.legato.kazusa.ui.book.search.SearchActivity
|
||||
import io.legato.kazusa.ui.main.bookshelf.BaseBookshelfFragment
|
||||
import io.legato.kazusa.ui.main.bookshelf.style1.books.BooksFragment
|
||||
import io.legato.kazusa.utils.viewbindingdelegate.viewBinding
|
||||
import kotlin.collections.set
|
||||
|
||||
@@ -109,11 +108,8 @@ class BookshelfFragment3() : BaseBookshelfFragment(R.layout.fragment_bookshelf3)
|
||||
if (it is BooksFragment) {
|
||||
val position = it.position
|
||||
val group = bookGroups.getOrNull(position) ?: return@forEach
|
||||
val newSort = group.getRealBookSort()
|
||||
it.setEnableRefresh(group.enableRefresh)
|
||||
if (it.bookSort != newSort) {
|
||||
it.upBookSort(newSort)
|
||||
}
|
||||
it.upBookSort()
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package io.legato.kazusa.ui.main.bookshelf.style1.books
|
||||
package io.legato.kazusa.ui.main.bookshelf.books.styleDefalut
|
||||
|
||||
import android.content.Context
|
||||
import androidx.core.os.bundleOf
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package io.legato.kazusa.ui.main.bookshelf.style1.books
|
||||
package io.legato.kazusa.ui.main.bookshelf.books.styleDefalut
|
||||
|
||||
import android.content.Context
|
||||
import android.os.Bundle
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package io.legato.kazusa.ui.main.bookshelf.style1.books
|
||||
package io.legato.kazusa.ui.main.bookshelf.books.styleDefalut
|
||||
|
||||
import android.content.Context
|
||||
import android.os.Bundle
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package io.legato.kazusa.ui.main.bookshelf.style2
|
||||
package io.legato.kazusa.ui.main.bookshelf.books.styleFold
|
||||
|
||||
import android.content.Context
|
||||
import android.view.LayoutInflater
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package io.legato.kazusa.ui.main.bookshelf.style2
|
||||
package io.legato.kazusa.ui.main.bookshelf.books.styleFold
|
||||
|
||||
import android.content.Context
|
||||
import android.os.Bundle
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package io.legato.kazusa.ui.main.bookshelf.style2
|
||||
package io.legato.kazusa.ui.main.bookshelf.books.styleFold
|
||||
|
||||
import android.content.Context
|
||||
import android.os.Bundle
|
||||
Reference in New Issue
Block a user