更新界面
This commit is contained in:
@@ -85,6 +85,9 @@ interface BookGroupDao {
|
||||
@Delete
|
||||
fun delete(vararg bookGroup: BookGroup)
|
||||
|
||||
@Query("UPDATE book_groups SET cover = NULL WHERE groupId = :groupId")
|
||||
fun clearCover(groupId: Long)
|
||||
|
||||
fun isInRules(id: Long): Boolean {
|
||||
if (id < 0) {
|
||||
return true
|
||||
|
||||
@@ -18,7 +18,6 @@ class NameListPreference(context: Context, attrs: AttributeSet) : ListPreference
|
||||
|
||||
init {
|
||||
layoutResource = R.layout.view_preference
|
||||
widgetLayoutResource = R.layout.item_fillet_text
|
||||
context.withStyledAttributes(attrs, R.styleable.Preference) {
|
||||
isBottomBackground = getBoolean(R.styleable.Preference_isBottomBackground, false)
|
||||
}
|
||||
@@ -26,16 +25,16 @@ class NameListPreference(context: Context, attrs: AttributeSet) : ListPreference
|
||||
|
||||
override fun onBindViewHolder(holder: PreferenceViewHolder) {
|
||||
val v = Preference.bindView<TextView>(
|
||||
context, holder, icon, title, summary, widgetLayoutResource,
|
||||
context, holder, icon, title, entry,
|
||||
R.id.text_view, isBottomBackground = isBottomBackground
|
||||
)
|
||||
if (v is TextView) {
|
||||
v.text = entry
|
||||
if (isBottomBackground) {
|
||||
// if (isBottomBackground) {
|
||||
// val bgColor = context.bottomBackground
|
||||
// val pTextColor = context.getPrimaryTextColor(ColorUtils.isColorLight(bgColor))
|
||||
//v.setTextColor(pTextColor)
|
||||
}
|
||||
// val pTextColor = context.getPrimaryTextColor(ColorUtils.isColorLight(bgColor))
|
||||
// //v.setTextColor(pTextColor)
|
||||
// }
|
||||
}
|
||||
super.onBindViewHolder(holder)
|
||||
}
|
||||
|
||||
@@ -67,7 +67,8 @@ class GroupEditDialog() : BaseBottomSheetDialogFragment(R.layout.dialog_book_gro
|
||||
bookGroup?.let {
|
||||
binding.btnDelete.visible(it.groupId > 0 || it.groupId == Long.MIN_VALUE)
|
||||
binding.tieGroupName.setText(it.groupName)
|
||||
binding.ivCover.load(it.cover)
|
||||
if (bookGroup?.cover != null)
|
||||
binding.ivCover.load(it.cover)
|
||||
binding.spSort.setSelection(it.bookSort + 1)
|
||||
binding.cbEnableRefresh.isChecked = it.enableRefresh
|
||||
} ?: let {
|
||||
@@ -79,6 +80,14 @@ class GroupEditDialog() : BaseBottomSheetDialogFragment(R.layout.dialog_book_gro
|
||||
ivCover.onClick {
|
||||
selectImage.launch()
|
||||
}
|
||||
btnReset.onClick {
|
||||
bookGroup?.let {
|
||||
viewModel.clearCover(it) {
|
||||
toastOnUi("封面已重置")
|
||||
dismiss()
|
||||
}
|
||||
}
|
||||
}
|
||||
btnCancel.onClick {
|
||||
dismiss()
|
||||
}
|
||||
|
||||
@@ -48,5 +48,12 @@ class GroupViewModel(application: Application) : BaseViewModel(application) {
|
||||
}
|
||||
}
|
||||
|
||||
fun clearCover(bookGroup: BookGroup, finally: () -> Unit) {
|
||||
execute {
|
||||
appDb.bookGroupDao.clearCover(bookGroup.groupId)
|
||||
}.onFinally {
|
||||
finally()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -4,7 +4,6 @@ import android.annotation.SuppressLint
|
||||
import android.content.Context
|
||||
import android.graphics.drawable.GradientDrawable
|
||||
import android.util.AttributeSet
|
||||
import android.util.Log
|
||||
import android.view.LayoutInflater
|
||||
import android.view.WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_NONE
|
||||
import android.view.animation.Animation
|
||||
@@ -19,19 +18,10 @@ import io.legato.kazusa.constant.PreferKey
|
||||
import io.legato.kazusa.databinding.ViewReadMenuBinding
|
||||
import io.legato.kazusa.help.config.AppConfig
|
||||
import io.legato.kazusa.help.config.LocalConfig
|
||||
import io.legato.kazusa.help.config.ReadBookConfig
|
||||
import io.legato.kazusa.help.config.ThemeConfig
|
||||
import io.legato.kazusa.help.coroutine.Coroutine
|
||||
import io.legato.kazusa.help.source.getSourceType
|
||||
import io.legato.kazusa.lib.dialogs.alert
|
||||
//import io.legado.app.lib.theme.accentColor
|
||||
//import io.legado.app.lib.theme.bottomBackground
|
||||
//import io.legado.app.lib.theme.buttonDisabledColor
|
||||
//import io.legado.app.lib.theme.getPrimaryTextColor
|
||||
//import io.legado.app.lib.theme.primaryColor
|
||||
//import io.legado.app.lib.theme.primaryTextColor
|
||||
import io.legato.kazusa.model.ReadBook
|
||||
import io.legato.kazusa.ui.book.read.config.MoreConfigDialog
|
||||
import io.legato.kazusa.ui.browser.WebViewActivity
|
||||
import io.legato.kazusa.ui.widget.seekbar.SeekBarChangeListener
|
||||
import io.legato.kazusa.utils.ConstraintModify
|
||||
@@ -45,7 +35,6 @@ import io.legato.kazusa.utils.loadAnimation
|
||||
import io.legato.kazusa.utils.modifyBegin
|
||||
import io.legato.kazusa.utils.openUrl
|
||||
import io.legato.kazusa.utils.putPrefBoolean
|
||||
import io.legato.kazusa.utils.showDialogFragment
|
||||
import io.legato.kazusa.utils.startActivity
|
||||
import io.legato.kazusa.utils.visible
|
||||
import splitties.views.onClick
|
||||
@@ -75,8 +64,8 @@ class ReadMenu @JvmOverloads constructor(
|
||||
private val menuBottomOut: Animation by lazy {
|
||||
loadAnimation(context, R.anim.anim_readbook_bottom_out)
|
||||
}
|
||||
private val immersiveMenu: Boolean
|
||||
get() = AppConfig.readBarStyleFollowPage && ReadBookConfig.durConfig.curBgType() == 0
|
||||
// private val immersiveMenu: Boolean
|
||||
// get() = AppConfig.readBarStyleFollowPage && ReadBookConfig.durConfig.curBgType() == 0
|
||||
// private var bgColor: Int = if (immersiveMenu) {
|
||||
// kotlin.runCatching {
|
||||
// ReadBookConfig.durConfig.curBgStr().toColorInt()
|
||||
@@ -160,29 +149,29 @@ class ReadMenu @JvmOverloads constructor(
|
||||
bindEvent()
|
||||
}
|
||||
|
||||
private fun initView(reset: Boolean = false) = binding.run {
|
||||
private fun initView() = binding.run {
|
||||
// if (AppConfig.isNightTheme) {
|
||||
// fabNightTheme.setIconResource(R.drawable.ic_daytime)
|
||||
// } else {
|
||||
// fabNightTheme.setIconResource(R.drawable.ic_brightness)
|
||||
// }
|
||||
initAnimation()
|
||||
if (immersiveMenu) {
|
||||
// val lightTextColor = ColorUtils.withAlpha(ColorUtils.lightenColor(textColor), 0.75f)
|
||||
// titleBar.setTextColor(textColor)
|
||||
// titleBar.setBackgroundColor(bgColor)
|
||||
// titleBar.setColorFilter(textColor)
|
||||
// tvChapterName.setTextColor(lightTextColor)
|
||||
// tvChapterUrl.setTextColor(lightTextColor)
|
||||
} else if (reset) {
|
||||
// val bgColor = context.primaryColor
|
||||
// val textColor = context.primaryTextColor
|
||||
// titleBar.setTextColor(textColor)
|
||||
// titleBar.setBackgroundColor(bgColor)
|
||||
// titleBar.setColorFilter(textColor)
|
||||
// tvChapterName.setTextColor(textColor)
|
||||
// tvChapterUrl.setTextColor(textColor)
|
||||
}
|
||||
// if (immersiveMenu) {
|
||||
//// val lightTextColor = ColorUtils.withAlpha(ColorUtils.lightenColor(textColor), 0.75f)
|
||||
//// titleBar.setTextColor(textColor)
|
||||
//// titleBar.setBackgroundColor(bgColor)
|
||||
//// titleBar.setColorFilter(textColor)
|
||||
//// tvChapterName.setTextColor(lightTextColor)
|
||||
//// tvChapterUrl.setTextColor(lightTextColor)
|
||||
// } else if (reset) {
|
||||
//// val bgColor = context.primaryColor
|
||||
//// val textColor = context.primaryTextColor
|
||||
//// titleBar.setTextColor(textColor)
|
||||
//// titleBar.setBackgroundColor(bgColor)
|
||||
//// titleBar.setColorFilter(textColor)
|
||||
//// tvChapterName.setTextColor(textColor)
|
||||
//// tvChapterUrl.setTextColor(textColor)
|
||||
// }
|
||||
val brightnessBackground = GradientDrawable()
|
||||
brightnessBackground.cornerRadius = 5F.dpToPx()
|
||||
//brightnessBackground.setColor(ColorUtils.adjustAlpha(bgColor, 0.5f))
|
||||
@@ -230,13 +219,13 @@ class ReadMenu @JvmOverloads constructor(
|
||||
|
||||
fun reset() {
|
||||
upColorConfig()
|
||||
initView(true)
|
||||
initView()
|
||||
}
|
||||
|
||||
fun refreshMenuColorFilter() {
|
||||
if (immersiveMenu) {
|
||||
//binding.titleBar.setColorFilter(textColor)
|
||||
}
|
||||
// if (immersiveMenu) {
|
||||
// //binding.titleBar.setColorFilter(textColor)
|
||||
// }
|
||||
}
|
||||
|
||||
private fun upColorConfig() {
|
||||
@@ -514,8 +503,6 @@ class ReadMenu @JvmOverloads constructor(
|
||||
|
||||
fun upSeekBar() {
|
||||
binding.seekReadPage.apply {
|
||||
Log.d("SliderDebug", "durPageIndex: ${ReadBook.durPageIndex}, pageSize: ${ReadBook.curTextChapter?.pageSize}")
|
||||
Log.d("SliderDebug", "durChapterIndex: ${ReadBook.durChapterIndex}, simulatedChapterSize: ${ReadBook.simulatedChapterSize}")
|
||||
when (AppConfig.progressBarBehavior) {
|
||||
"page" -> {
|
||||
ReadBook.curTextChapter?.let { chapter ->
|
||||
|
||||
@@ -9,7 +9,6 @@ import android.view.MenuItem
|
||||
import android.view.MotionEvent
|
||||
import android.view.ViewGroup
|
||||
import androidx.activity.addCallback
|
||||
import androidx.activity.enableEdgeToEdge
|
||||
import androidx.activity.viewModels
|
||||
import androidx.core.view.postDelayed
|
||||
import androidx.fragment.app.Fragment
|
||||
@@ -33,7 +32,6 @@ import io.legato.kazusa.help.config.LocalConfig
|
||||
import io.legato.kazusa.help.coroutine.Coroutine
|
||||
import io.legato.kazusa.help.storage.Backup
|
||||
import io.legato.kazusa.lib.dialogs.alert
|
||||
//import io.legado.app.lib.theme.primaryColor
|
||||
import io.legato.kazusa.service.BaseReadAloudService
|
||||
import io.legato.kazusa.ui.about.CrashLogsDialog
|
||||
import io.legato.kazusa.ui.main.bookshelf.BaseBookshelfFragment
|
||||
@@ -45,9 +43,7 @@ import io.legato.kazusa.ui.main.rss.RssFragment
|
||||
import io.legato.kazusa.ui.widget.dialog.TextDialog
|
||||
import io.legato.kazusa.utils.hideSoftInput
|
||||
import io.legato.kazusa.utils.isCreated
|
||||
import io.legato.kazusa.utils.navigationBarHeight
|
||||
import io.legato.kazusa.utils.observeEvent
|
||||
import io.legato.kazusa.utils.setOnApplyWindowInsetsListenerCompat
|
||||
import io.legato.kazusa.utils.shouldHideSoftInput
|
||||
import io.legato.kazusa.utils.showDialogFragment
|
||||
import io.legato.kazusa.utils.toastOnUi
|
||||
@@ -55,14 +51,11 @@ import io.legato.kazusa.utils.viewbindingdelegate.viewBinding
|
||||
import kotlinx.coroutines.Dispatchers.IO
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import splitties.views.bottomPadding
|
||||
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.welcome.WelcomeActivity
|
||||
import io.legato.kazusa.utils.applyNavigationBarPadding
|
||||
import io.legato.kazusa.utils.applyStatusBarPadding
|
||||
import io.legato.kazusa.ui.main.bookshelf.style1.BookshelfFragment3
|
||||
|
||||
/**
|
||||
* 主界面
|
||||
@@ -76,6 +69,7 @@ class MainActivity : VMBaseActivity<ActivityMainBinding, MainViewModel>(),
|
||||
private val idBookshelf = 0
|
||||
private val idBookshelf1 = 11
|
||||
private val idBookshelf2 = 12
|
||||
private val idBookshelf3 = 13
|
||||
private val idExplore = 1
|
||||
private val idRss = 2
|
||||
private val idMy = 3
|
||||
@@ -424,11 +418,17 @@ class MainActivity : VMBaseActivity<ActivityMainBinding, MainViewModel>(),
|
||||
private fun getFragmentId(position: Int): Int {
|
||||
val id = realPositions[position]
|
||||
if (id == idBookshelf) {
|
||||
return if (AppConfig.bookGroupStyle == 1) idBookshelf2 else idBookshelf1
|
||||
return when (AppConfig.bookGroupStyle) {
|
||||
0 -> idBookshelf1
|
||||
1 -> idBookshelf2
|
||||
2 -> idBookshelf3
|
||||
else -> idBookshelf1
|
||||
}
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
|
||||
private inner class PageChangeCallback : ViewPager.SimpleOnPageChangeListener() {
|
||||
|
||||
override fun onPageSelected(position: Int) {
|
||||
@@ -447,24 +447,28 @@ class MainActivity : VMBaseActivity<ActivityMainBinding, MainViewModel>(),
|
||||
}
|
||||
|
||||
override fun getItemPosition(any: Any): Int {
|
||||
val position = (any as MainFragmentInterface).position
|
||||
?: return POSITION_NONE
|
||||
val position = (any as? MainFragmentInterface)?.position ?: return POSITION_NONE
|
||||
val fragmentId = getId(position)
|
||||
if ((fragmentId == idBookshelf1 && any is BookshelfFragment1)
|
||||
|| (fragmentId == idBookshelf2 && any is BookshelfFragment2)
|
||||
|| (fragmentId == idExplore && any is ExploreFragment)
|
||||
|| (fragmentId == idRss && any is RssFragment)
|
||||
|| (fragmentId == idMy && any is MyFragment)
|
||||
|
||||
if (
|
||||
(fragmentId == idBookshelf1 && any is BookshelfFragment1) ||
|
||||
(fragmentId == idBookshelf2 && any is BookshelfFragment2) ||
|
||||
(fragmentId == idBookshelf3 && any is BookshelfFragment3) ||
|
||||
(fragmentId == idExplore && any is ExploreFragment) ||
|
||||
(fragmentId == idRss && any is RssFragment) ||
|
||||
(fragmentId == idMy && any is MyFragment)
|
||||
) {
|
||||
return POSITION_UNCHANGED
|
||||
}
|
||||
return POSITION_NONE
|
||||
}
|
||||
|
||||
|
||||
override fun getItem(position: Int): Fragment {
|
||||
return when (getId(position)) {
|
||||
idBookshelf1 -> BookshelfFragment1(position)
|
||||
idBookshelf2 -> BookshelfFragment2(position)
|
||||
idBookshelf3 -> BookshelfFragment3(position)
|
||||
idExplore -> ExploreFragment(position)
|
||||
idRss -> RssFragment(position)
|
||||
else -> MyFragment(position)
|
||||
|
||||
@@ -4,10 +4,12 @@ import android.annotation.SuppressLint
|
||||
import android.content.res.Configuration
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
import android.view.View
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.fragment.app.activityViewModels
|
||||
import androidx.fragment.app.viewModels
|
||||
import androidx.lifecycle.LiveData
|
||||
import com.google.android.material.chip.Chip
|
||||
import io.legato.kazusa.R
|
||||
import io.legato.kazusa.base.VMBaseFragment
|
||||
import io.legato.kazusa.constant.EventBus
|
||||
@@ -30,9 +32,6 @@ import io.legato.kazusa.ui.file.HandleFileContract
|
||||
import io.legato.kazusa.ui.main.MainFragmentInterface
|
||||
import io.legato.kazusa.ui.main.MainViewModel
|
||||
import io.legato.kazusa.ui.widget.dialog.WaitDialog
|
||||
import io.legato.kazusa.utils.bookshelfLayout
|
||||
import io.legato.kazusa.utils.checkByIndex
|
||||
import io.legato.kazusa.utils.getCheckedIndex
|
||||
import io.legato.kazusa.utils.isAbsUrl
|
||||
import io.legato.kazusa.utils.postEvent
|
||||
import io.legato.kazusa.utils.readText
|
||||
@@ -166,7 +165,7 @@ abstract class BaseBookshelfFragment(layoutId: Int) : VMBaseFragment<BookshelfVi
|
||||
|
||||
@SuppressLint("InflateParams")
|
||||
fun configBookshelf() {
|
||||
alert(titleResource = R.string.bookshelf_layout) {
|
||||
alert {
|
||||
|
||||
val orientation = requireContext().resources.configuration.orientation
|
||||
val bookshelfLayout = if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
|
||||
@@ -182,20 +181,53 @@ abstract class BaseBookshelfFragment(layoutId: Int) : VMBaseFragment<BookshelfVi
|
||||
val alertBinding =
|
||||
DialogBookshelfConfigBinding.inflate(layoutInflater)
|
||||
.apply {
|
||||
spGroupStyle.setSelection(AppConfig.bookGroupStyle)
|
||||
|
||||
val groupStyleArray = resources.getStringArray(R.array.group_style)
|
||||
val chipGroupStyle = chipGroupStyle
|
||||
|
||||
groupStyleArray.forEachIndexed { index, label ->
|
||||
val chip = Chip(context).apply {
|
||||
text = label
|
||||
isCheckable = true
|
||||
isClickable = true
|
||||
id = View.generateViewId()
|
||||
}
|
||||
chipGroupStyle.addView(chip)
|
||||
if (index == AppConfig.bookGroupStyle) {
|
||||
chipGroupStyle.check(chip.id)
|
||||
}
|
||||
}
|
||||
|
||||
val sortArray = resources.getStringArray(R.array.bookshelf_px_array)
|
||||
val chipGroupSort = chipGroupSort
|
||||
|
||||
sortArray.forEachIndexed { index, label ->
|
||||
val chip = Chip(context).apply {
|
||||
text = label
|
||||
isCheckable = true
|
||||
isClickable = true
|
||||
id = View.generateViewId()
|
||||
}
|
||||
chipGroupSort.addView(chip)
|
||||
if (index == AppConfig.bookshelfSort) {
|
||||
chipGroupSort.check(chip.id)
|
||||
}
|
||||
}
|
||||
|
||||
swShowUnread.isChecked = AppConfig.showUnread
|
||||
swShowLastUpdateTime.isChecked = AppConfig.showLastUpdateTime
|
||||
swShowWaitUpBooks.isChecked = AppConfig.showWaitUpCount
|
||||
swShowBookshelfFastScroller.isChecked = AppConfig.showBookshelfFastScroller
|
||||
rgSort.checkByIndex(bookshelfSort)
|
||||
|
||||
chipList.isChecked = !isGrid
|
||||
chipGrid.isChecked = isGrid
|
||||
llGridSlider.isVisible = isGrid
|
||||
sliderText.isVisible = isGrid
|
||||
sliderGridCount.isVisible = isGrid
|
||||
sliderGridCount.value = columnCount.toFloat()
|
||||
|
||||
chipGroupLayout.setOnCheckedChangeListener { _, checkedId ->
|
||||
llGridSlider.isVisible = checkedId == R.id.chip_grid
|
||||
chipGroupLayout.setOnCheckedStateChangeListener { group, checkedIds ->
|
||||
sliderText.isVisible = checkedIds.firstOrNull() == R.id.chip_grid
|
||||
sliderGridCount.isVisible = checkedIds.firstOrNull() == R.id.chip_grid
|
||||
}
|
||||
|
||||
}
|
||||
@@ -205,10 +237,12 @@ abstract class BaseBookshelfFragment(layoutId: Int) : VMBaseFragment<BookshelfVi
|
||||
alertBinding.apply {
|
||||
var notifyMain = false
|
||||
var recreate = false
|
||||
if (AppConfig.bookGroupStyle != spGroupStyle.selectedItemPosition) {
|
||||
AppConfig.bookGroupStyle = spGroupStyle.selectedItemPosition
|
||||
|
||||
if (AppConfig.bookGroupStyle != chipGroupStyle.checkedChipId) {
|
||||
AppConfig.bookGroupStyle = chipGroupStyle.indexOfChild(chipGroupStyle.findViewById(chipGroupStyle.checkedChipId))
|
||||
notifyMain = true
|
||||
}
|
||||
|
||||
if (AppConfig.showUnread != swShowUnread.isChecked) {
|
||||
AppConfig.showUnread = swShowUnread.isChecked
|
||||
postEvent(EventBus.BOOKSHELF_REFRESH, "")
|
||||
@@ -225,8 +259,8 @@ abstract class BaseBookshelfFragment(layoutId: Int) : VMBaseFragment<BookshelfVi
|
||||
AppConfig.showBookshelfFastScroller = swShowBookshelfFastScroller.isChecked
|
||||
postEvent(EventBus.BOOKSHELF_REFRESH, "")
|
||||
}
|
||||
if (bookshelfSort != rgSort.getCheckedIndex()) {
|
||||
AppConfig.bookshelfSort = rgSort.getCheckedIndex()
|
||||
if (bookshelfSort != chipGroupSort.indexOfChild(chipGroupSort.findViewById(chipGroupSort.checkedChipId))) {
|
||||
AppConfig.bookshelfSort = chipGroupSort.indexOfChild(chipGroupSort.findViewById(chipGroupSort.checkedChipId))
|
||||
upSort()
|
||||
}
|
||||
|
||||
|
||||
@@ -5,11 +5,8 @@ package io.legato.kazusa.ui.main.bookshelf.style1
|
||||
import android.annotation.SuppressLint
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.appcompat.widget.SearchView
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.FragmentManager
|
||||
import androidx.fragment.app.FragmentStatePagerAdapter
|
||||
import androidx.viewpager2.adapter.FragmentStateAdapter
|
||||
import com.google.android.material.tabs.TabLayout
|
||||
import com.google.android.material.tabs.TabLayoutMediator
|
||||
@@ -19,13 +16,10 @@ import io.legato.kazusa.data.entities.Book
|
||||
import io.legato.kazusa.data.entities.BookGroup
|
||||
import io.legato.kazusa.databinding.FragmentBookshelf1Binding
|
||||
import io.legato.kazusa.help.config.AppConfig
|
||||
//import io.legado.app.lib.theme.accentColor
|
||||
//import io.legado.app.lib.theme.primaryColor
|
||||
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.isCreated
|
||||
import io.legato.kazusa.utils.showDialogFragment
|
||||
import io.legato.kazusa.utils.toastOnUi
|
||||
import io.legato.kazusa.utils.viewbindingdelegate.viewBinding
|
||||
@@ -45,9 +39,7 @@ class BookshelfFragment1() : BaseBookshelfFragment(R.layout.fragment_bookshelf1)
|
||||
}
|
||||
|
||||
private val binding by viewBinding(FragmentBookshelf1Binding::bind)
|
||||
private val tabLayout: TabLayout by lazy {
|
||||
binding.tabLayout.findViewById(R.id.tab_layout)
|
||||
}
|
||||
|
||||
private val bookGroups = mutableListOf<BookGroup>()
|
||||
private val fragmentMap = hashMapOf<Long, BooksFragment>()
|
||||
override val groupId: Long get() = selectedGroup?.groupId ?: 0
|
||||
|
||||
@@ -0,0 +1,144 @@
|
||||
@file:Suppress("DEPRECATION")
|
||||
|
||||
package io.legato.kazusa.ui.main.bookshelf.style1
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import androidx.appcompat.widget.SearchView
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.viewpager2.adapter.FragmentStateAdapter
|
||||
import androidx.viewpager2.widget.ViewPager2
|
||||
import com.google.android.material.tabs.TabLayout
|
||||
import io.legato.kazusa.R
|
||||
import io.legato.kazusa.data.appDb
|
||||
import io.legato.kazusa.data.entities.Book
|
||||
import io.legato.kazusa.data.entities.BookGroup
|
||||
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
|
||||
|
||||
/**
|
||||
* 书架界面
|
||||
*/
|
||||
class BookshelfFragment3() : BaseBookshelfFragment(R.layout.fragment_bookshelf3),
|
||||
TabLayout.OnTabSelectedListener,
|
||||
SearchView.OnQueryTextListener {
|
||||
|
||||
constructor(position: Int) : this() {
|
||||
val bundle = Bundle()
|
||||
bundle.putInt("position", position)
|
||||
arguments = bundle
|
||||
}
|
||||
|
||||
private val binding by viewBinding(FragmentBookshelf3Binding::bind)
|
||||
|
||||
private val bookGroups = mutableListOf<BookGroup>()
|
||||
private val fragmentMap = hashMapOf<Long, BooksFragment>()
|
||||
override val groupId: Long get() = selectedGroup?.groupId ?: 0
|
||||
|
||||
private lateinit var adapter: TabFragmentPageAdapter
|
||||
|
||||
override val books: List<Book>
|
||||
get() {
|
||||
val fragment = fragmentMap[groupId]
|
||||
return fragment?.getBooks() ?: emptyList()
|
||||
}
|
||||
|
||||
override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) {
|
||||
setSupportToolbar(binding.topBar)
|
||||
initView()
|
||||
initBookGroupData()
|
||||
}
|
||||
|
||||
private val selectedGroup: BookGroup?
|
||||
get() = bookGroups.getOrNull(binding.viewPagerBookshelf.currentItem)
|
||||
|
||||
private fun initView() {
|
||||
adapter = TabFragmentPageAdapter(this)
|
||||
binding.viewPagerBookshelf.adapter = adapter
|
||||
binding.viewPagerBookshelf.offscreenPageLimit = 1
|
||||
|
||||
binding.viewPagerBookshelf.registerOnPageChangeCallback(object : ViewPager2.OnPageChangeCallback() {
|
||||
override fun onPageSelected(position: Int) {
|
||||
super.onPageSelected(position)
|
||||
updateToolbarTitle(position)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
private fun updateToolbarTitle(position: Int) {
|
||||
if (bookGroups.isNotEmpty() && position in 0 until bookGroups.size) {
|
||||
binding.collTopBar.title = bookGroups[position].groupName
|
||||
}
|
||||
}
|
||||
|
||||
override fun onQueryTextSubmit(query: String?): Boolean {
|
||||
SearchActivity.start(requireContext(), query)
|
||||
return false
|
||||
}
|
||||
|
||||
override fun onQueryTextChange(newText: String?): Boolean {
|
||||
return false
|
||||
}
|
||||
|
||||
@SuppressLint("NotifyDataSetChanged")
|
||||
@Synchronized
|
||||
override fun upGroup(data: List<BookGroup>) {
|
||||
if (data.isEmpty()) {
|
||||
appDb.bookGroupDao.enableGroup(BookGroup.IdAll)
|
||||
} else {
|
||||
if (data != bookGroups) {
|
||||
bookGroups.clear()
|
||||
bookGroups.addAll(data)
|
||||
adapter.notifyDataSetChanged()
|
||||
adapter = TabFragmentPageAdapter(this)
|
||||
binding.viewPagerBookshelf.adapter = adapter
|
||||
|
||||
updateToolbarTitle(binding.viewPagerBookshelf.currentItem)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun upSort() {
|
||||
childFragmentManager.fragments.forEach {
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onTabReselected(tab: TabLayout.Tab) {
|
||||
}
|
||||
|
||||
override fun onTabUnselected(tab: TabLayout.Tab) = Unit
|
||||
|
||||
override fun onTabSelected(tab: TabLayout.Tab) {
|
||||
AppConfig.saveTabPosition = tab.position
|
||||
}
|
||||
|
||||
override fun gotoTop() {
|
||||
fragmentMap[groupId]?.gotoTop()
|
||||
}
|
||||
|
||||
private inner class TabFragmentPageAdapter(fragment: Fragment) : FragmentStateAdapter(fragment) {
|
||||
override fun getItemCount(): Int = bookGroups.size
|
||||
|
||||
override fun createFragment(position: Int): Fragment {
|
||||
val group = bookGroups[position]
|
||||
val fragment = BooksFragment(position, group)
|
||||
fragmentMap[group.groupId] = fragment
|
||||
return fragment
|
||||
}
|
||||
}
|
||||
}
|
||||
+10
-9
@@ -3,6 +3,7 @@ package io.legato.kazusa.ui.main.bookshelf.style1.books
|
||||
import android.content.Context
|
||||
import android.os.Bundle
|
||||
import android.view.ViewGroup
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.lifecycle.Lifecycle
|
||||
import io.legato.kazusa.base.adapter.ItemViewHolder
|
||||
@@ -10,7 +11,6 @@ import io.legato.kazusa.data.entities.Book
|
||||
import io.legato.kazusa.databinding.ItemBookshelfListBinding
|
||||
import io.legato.kazusa.help.book.isLocal
|
||||
import io.legato.kazusa.help.config.AppConfig
|
||||
import io.legato.kazusa.utils.invisible
|
||||
import io.legato.kazusa.utils.toTimeAgo
|
||||
import splitties.views.onLongClick
|
||||
|
||||
@@ -68,15 +68,16 @@ class BooksAdapterList(
|
||||
|
||||
private fun upRefresh(binding: ItemBookshelfListBinding, item: Book) {
|
||||
if (!item.isLocal && callBack.isUpdate(item.bookUrl)) {
|
||||
binding.bvUnread.invisible()
|
||||
binding.rlLoading.visible()
|
||||
binding.tvUnread.isVisible = false
|
||||
binding.rlLoading.isVisible = true
|
||||
} else {
|
||||
binding.rlLoading.gone()
|
||||
binding.rlLoading.isVisible = false
|
||||
if (AppConfig.showUnread) {
|
||||
binding.bvUnread.setHighlight(item.lastCheckCount > 0)
|
||||
binding.bvUnread.setBadgeCount(item.getUnreadChapterNum())
|
||||
//binding.tvUnread.setHighlight(item.lastCheckCount > 0)
|
||||
binding.tvUnread.isVisible = true
|
||||
binding.tvUnread.text = item.getUnreadChapterNum().toString()
|
||||
} else {
|
||||
binding.bvUnread.invisible()
|
||||
binding.tvUnread.isVisible = false
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -94,13 +95,13 @@ class BooksAdapterList(
|
||||
|
||||
override fun registerListener(holder: ItemViewHolder, binding: ItemBookshelfListBinding) {
|
||||
holder.itemView.apply {
|
||||
setOnClickListener {
|
||||
binding.cvContent.setOnClickListener {
|
||||
getItem(holder.layoutPosition)?.let {
|
||||
callBack.open(it)
|
||||
}
|
||||
}
|
||||
|
||||
onLongClick {
|
||||
binding.cvContent.onLongClick {
|
||||
getItem(holder.layoutPosition)?.let {
|
||||
callBack.openBookInfo(it)
|
||||
}
|
||||
|
||||
@@ -46,10 +46,7 @@ abstract class BaseBooksAdapter<VH : RecyclerView.ViewHolder>(
|
||||
oldItem.getUnreadChapterNum() == newItem.getUnreadChapterNum()
|
||||
}
|
||||
|
||||
oldItem is BookGroup && newItem is BookGroup -> {
|
||||
oldItem.groupName == newItem.groupName &&
|
||||
oldItem.cover == newItem.cover
|
||||
}
|
||||
oldItem is BookGroup && newItem is BookGroup -> false
|
||||
|
||||
else -> false
|
||||
}
|
||||
@@ -120,6 +117,12 @@ abstract class BaseBooksAdapter<VH : RecyclerView.ViewHolder>(
|
||||
|
||||
fun getItem(position: Int) = getItems().getOrNull(position)
|
||||
|
||||
internal var allBooks: List<Book> = emptyList()
|
||||
|
||||
fun setAllBooks(all: List<Book>) {
|
||||
this.allBooks = all
|
||||
}
|
||||
|
||||
override fun getItemCount(): Int {
|
||||
return getItems().size
|
||||
}
|
||||
|
||||
@@ -4,13 +4,16 @@ import android.content.Context
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import io.legato.kazusa.R
|
||||
import io.legato.kazusa.data.entities.Book
|
||||
import io.legato.kazusa.data.entities.BookGroup
|
||||
import io.legato.kazusa.databinding.ItemBookshelfGridBinding
|
||||
import io.legato.kazusa.databinding.ItemBookshelfGridGroupBinding
|
||||
import io.legato.kazusa.help.book.isLocal
|
||||
import io.legato.kazusa.help.config.AppConfig
|
||||
import io.legato.kazusa.utils.gone
|
||||
import splitties.views.onLongClick
|
||||
|
||||
@Suppress("UNUSED_PARAMETER")
|
||||
@@ -32,31 +35,40 @@ class BooksAdapterGrid(context: Context, callBack: CallBack) :
|
||||
position: Int,
|
||||
payloads: MutableList<Any>
|
||||
) {
|
||||
|
||||
when (holder) {
|
||||
is BookViewHolder -> (getItem(position) as? Book)?.let {
|
||||
holder.registerListener(it)
|
||||
holder.onBind(it, position, payloads)
|
||||
holder.onBind(it, payloads)
|
||||
}
|
||||
|
||||
is GroupViewHolder -> (getItem(position) as? BookGroup)?.let {
|
||||
holder.registerListener(it)
|
||||
holder.onBind(it, position, payloads)
|
||||
holder.onBind(it, payloads)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun getBooksForGroup(group: BookGroup): List<Book> {
|
||||
return if (group.groupId == -1L) {
|
||||
allBooks.take(4)
|
||||
} else {
|
||||
allBooks.filter { (it.group and group.groupId) != 0L }.take(4)
|
||||
}
|
||||
}
|
||||
|
||||
inner class BookViewHolder(val binding: ItemBookshelfGridBinding) :
|
||||
RecyclerView.ViewHolder(binding.root) {
|
||||
|
||||
fun onBind(item: Book, position: Int) = binding.run {
|
||||
fun onBind(item: Book) = binding.run {
|
||||
tvName.text = item.name
|
||||
ivCover.load(item.getDisplayCover(), item.name, item.author, false, item.origin)
|
||||
upRefresh(this, item)
|
||||
}
|
||||
|
||||
fun onBind(item: Book, position: Int, payloads: MutableList<Any>) = binding.run {
|
||||
fun onBind(item: Book, payloads: MutableList<Any>) = binding.run {
|
||||
if (payloads.isEmpty()) {
|
||||
onBind(item, position)
|
||||
onBind(item)
|
||||
} else {
|
||||
for (i in payloads.indices) {
|
||||
val bundle = payloads[i] as Bundle
|
||||
@@ -79,10 +91,10 @@ class BooksAdapterGrid(context: Context, callBack: CallBack) :
|
||||
}
|
||||
|
||||
fun registerListener(item: Any) {
|
||||
binding.root.setOnClickListener {
|
||||
binding.cvContent.setOnClickListener {
|
||||
callBack.onItemClick(item)
|
||||
}
|
||||
binding.root.onLongClick {
|
||||
binding.cvContent.onLongClick {
|
||||
callBack.onItemLongClick(item)
|
||||
}
|
||||
}
|
||||
@@ -113,21 +125,22 @@ class BooksAdapterGrid(context: Context, callBack: CallBack) :
|
||||
inner class GroupViewHolder(val binding: ItemBookshelfGridGroupBinding) :
|
||||
RecyclerView.ViewHolder(binding.root) {
|
||||
|
||||
fun onBind(item: BookGroup, position: Int) = binding.run {
|
||||
fun onBind(item: BookGroup) = binding.run {
|
||||
tvName.text = item.groupName
|
||||
ivCover.load(item.cover)
|
||||
loadGroupCover(item)
|
||||
cdUnread.gone()
|
||||
}
|
||||
|
||||
fun onBind(item: BookGroup, position: Int, payloads: MutableList<Any>) = binding.run {
|
||||
fun onBind(item: BookGroup, payloads: MutableList<Any>) = binding.run {
|
||||
if (payloads.isEmpty()) {
|
||||
onBind(item, position)
|
||||
onBind(item)
|
||||
} else {
|
||||
for (i in payloads.indices) {
|
||||
val bundle = payloads[i] as Bundle
|
||||
bundle.keySet().forEach {
|
||||
when (it) {
|
||||
"groupName" -> tvName.text = item.groupName
|
||||
"cover" -> ivCover.load(item.cover)
|
||||
"cover" -> loadGroupCover(item)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -143,6 +156,28 @@ class BooksAdapterGrid(context: Context, callBack: CallBack) :
|
||||
}
|
||||
}
|
||||
|
||||
private fun loadGroupCover(item: BookGroup) = binding.run {
|
||||
|
||||
binding.ivCover.setImageDrawable(
|
||||
ContextCompat.getDrawable(binding.root.context, R.drawable.bg_surface_variant)
|
||||
)
|
||||
binding.ivCover1.setImageDrawable(null)
|
||||
binding.ivCover2.setImageDrawable(null)
|
||||
binding.ivCover3.setImageDrawable(null)
|
||||
binding.ivCover4.setImageDrawable(null)
|
||||
if (!item.cover.isNullOrEmpty()) {
|
||||
ivCover.load(item.cover)
|
||||
} else {
|
||||
|
||||
val books = getBooksForGroup(item)
|
||||
|
||||
if (books.size > 0) binding.ivCover1.load(books[0].getDisplayCover())
|
||||
if (books.size > 1) binding.ivCover2.load(books[1].getDisplayCover())
|
||||
if (books.size > 2) binding.ivCover3.load(books[2].getDisplayCover())
|
||||
if (books.size > 3) binding.ivCover4.load(books[3].getDisplayCover())
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,7 +3,10 @@ package io.legato.kazusa.ui.main.bookshelf.style2
|
||||
import android.content.Context
|
||||
import android.os.Bundle
|
||||
import android.view.ViewGroup
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import io.legato.kazusa.R
|
||||
import io.legato.kazusa.data.entities.Book
|
||||
import io.legato.kazusa.data.entities.BookGroup
|
||||
import io.legato.kazusa.databinding.ItemBookshelfListBinding
|
||||
@@ -11,7 +14,7 @@ import io.legato.kazusa.databinding.ItemBookshelfListGroupBinding
|
||||
import io.legato.kazusa.help.book.isLocal
|
||||
import io.legato.kazusa.help.config.AppConfig
|
||||
import io.legato.kazusa.utils.gone
|
||||
import io.legato.kazusa.utils.invisible
|
||||
import io.legato.kazusa.utils.toTimeAgo
|
||||
import io.legato.kazusa.utils.visible
|
||||
import splitties.views.onLongClick
|
||||
|
||||
@@ -34,35 +37,44 @@ class BooksAdapterList(context: Context, callBack: CallBack) :
|
||||
when (holder) {
|
||||
is BookViewHolder -> (getItem(position) as? Book)?.let {
|
||||
holder.registerListener(it)
|
||||
holder.onBind(it, position, payloads)
|
||||
holder.onBind(it, payloads)
|
||||
}
|
||||
|
||||
is GroupViewHolder -> (getItem(position) as? BookGroup)?.let {
|
||||
holder.registerListener(it)
|
||||
holder.onBind(it, position, payloads)
|
||||
holder.onBind(it, payloads)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun getBooksForGroup(group: BookGroup): List<Book> {
|
||||
return if (group.groupId == -1L) {
|
||||
allBooks.take(4)
|
||||
} else {
|
||||
allBooks.filter { (it.group and group.groupId) != 0L }.take(4)
|
||||
}
|
||||
}
|
||||
|
||||
inner class BookViewHolder(val binding: ItemBookshelfListBinding) :
|
||||
RecyclerView.ViewHolder(binding.root) {
|
||||
|
||||
fun onBind(item: Book, position: Int) = binding.run {
|
||||
fun onBind(item: Book) = binding.run {
|
||||
tvName.text = item.name
|
||||
tvAuthor.text = item.author
|
||||
tvRead.text = item.durChapterTitle
|
||||
tvLast.text = item.latestChapterTitle
|
||||
ivCover.load(item.getDisplayCover(), item.name, item.author, false, item.origin)
|
||||
flHasNew.visible()
|
||||
cdUnread.visible()
|
||||
ivAuthor.visible()
|
||||
ivLast.visible()
|
||||
ivRead.visible()
|
||||
upRefresh(this, item)
|
||||
upLastUpdateTime(binding, item)
|
||||
}
|
||||
|
||||
fun onBind(item: Book, position: Int, payloads: MutableList<Any>) = binding.run {
|
||||
fun onBind(item: Book, payloads: MutableList<Any>) = binding.run {
|
||||
if (payloads.isEmpty()) {
|
||||
onBind(item, position)
|
||||
onBind(item)
|
||||
} else {
|
||||
for (i in payloads.indices) {
|
||||
val bundle = payloads[i] as Bundle
|
||||
@@ -81,32 +93,45 @@ class BooksAdapterList(context: Context, callBack: CallBack) :
|
||||
)
|
||||
|
||||
"refresh" -> upRefresh(this, item)
|
||||
"lastUpdateTime" -> upLastUpdateTime(binding, item)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun upLastUpdateTime(binding: ItemBookshelfListBinding, item: Book) {
|
||||
if (AppConfig.showLastUpdateTime && !item.isLocal) {
|
||||
val time = item.latestChapterTime.toTimeAgo()
|
||||
if (binding.tvLastUpdateTime.text != time) {
|
||||
binding.tvLastUpdateTime.text = time
|
||||
}
|
||||
} else {
|
||||
binding.tvLastUpdateTime.text = ""
|
||||
}
|
||||
}
|
||||
|
||||
fun registerListener(item: Any) {
|
||||
binding.root.setOnClickListener {
|
||||
binding.cvContent.setOnClickListener {
|
||||
callBack.onItemClick(item)
|
||||
}
|
||||
binding.root.onLongClick {
|
||||
binding.cvContent.onLongClick {
|
||||
callBack.onItemLongClick(item)
|
||||
}
|
||||
}
|
||||
|
||||
private fun upRefresh(binding: ItemBookshelfListBinding, item: Book) {
|
||||
if (!item.isLocal && callBack.isUpdate(item.bookUrl)) {
|
||||
binding.bvUnread.invisible()
|
||||
binding.rlLoading.visible()
|
||||
binding.tvUnread.isVisible = false
|
||||
binding.rlLoading.isVisible = true
|
||||
} else {
|
||||
binding.rlLoading.gone()
|
||||
binding.rlLoading.isVisible = false
|
||||
if (AppConfig.showUnread) {
|
||||
binding.bvUnread.setHighlight(item.lastCheckCount > 0)
|
||||
binding.bvUnread.setBadgeCount(item.getUnreadChapterNum())
|
||||
//binding.tvUnread.setHighlight(item.lastCheckCount > 0)
|
||||
binding.tvUnread.isVisible = true
|
||||
binding.tvUnread.text = item.getUnreadChapterNum().toString()
|
||||
} else {
|
||||
binding.bvUnread.invisible()
|
||||
binding.tvUnread.isVisible = false
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -116,28 +141,23 @@ class BooksAdapterList(context: Context, callBack: CallBack) :
|
||||
inner class GroupViewHolder(val binding: ItemBookshelfListGroupBinding) :
|
||||
RecyclerView.ViewHolder(binding.root) {
|
||||
|
||||
fun onBind(item: BookGroup, position: Int) = binding.run {
|
||||
fun onBind(item: BookGroup) = binding.run {
|
||||
tvName.text = item.groupName
|
||||
ivCover.load(item.cover)
|
||||
flHasNew.gone()
|
||||
ivAuthor.gone()
|
||||
ivLast.gone()
|
||||
ivRead.gone()
|
||||
tvAuthor.gone()
|
||||
tvLast.gone()
|
||||
tvRead.gone()
|
||||
loadGroupCover(item)
|
||||
cdUnread.gone()
|
||||
}
|
||||
|
||||
fun onBind(item: BookGroup, position: Int, payloads: MutableList<Any>) = binding.run {
|
||||
|
||||
fun onBind(item: BookGroup, payloads: MutableList<Any>) = binding.run {
|
||||
if (payloads.isEmpty()) {
|
||||
onBind(item, position)
|
||||
onBind(item)
|
||||
} else {
|
||||
for (i in payloads.indices) {
|
||||
val bundle = payloads[i] as Bundle
|
||||
bundle.keySet().forEach {
|
||||
when (it) {
|
||||
"groupName" -> tvName.text = item.groupName
|
||||
"cover" -> ivCover.load(item.cover)
|
||||
"cover" -> loadGroupCover(item)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -145,14 +165,36 @@ class BooksAdapterList(context: Context, callBack: CallBack) :
|
||||
}
|
||||
|
||||
fun registerListener(item: Any) {
|
||||
binding.root.setOnClickListener {
|
||||
binding.cvContent.setOnClickListener {
|
||||
callBack.onItemClick(item)
|
||||
}
|
||||
binding.root.onLongClick {
|
||||
binding.cvContent.onLongClick {
|
||||
callBack.onItemLongClick(item)
|
||||
}
|
||||
}
|
||||
|
||||
private fun loadGroupCover(item: BookGroup) = binding.run {
|
||||
|
||||
binding.ivCover.setImageDrawable(
|
||||
ContextCompat.getDrawable(binding.root.context, R.drawable.bg_surface_variant)
|
||||
)
|
||||
binding.ivCover1.setImageDrawable(null)
|
||||
binding.ivCover2.setImageDrawable(null)
|
||||
binding.ivCover3.setImageDrawable(null)
|
||||
binding.ivCover4.setImageDrawable(null)
|
||||
if (!item.cover.isNullOrEmpty()) {
|
||||
ivCover.load(item.cover)
|
||||
} else {
|
||||
|
||||
val books = getBooksForGroup(item)
|
||||
|
||||
if (books.size > 0) binding.ivCover1.load(books[0].getDisplayCover())
|
||||
if (books.size > 1) binding.ivCover2.load(books[1].getDisplayCover())
|
||||
if (books.size > 2) binding.ivCover3.load(books[2].getDisplayCover())
|
||||
if (books.size > 3) binding.ivCover4.load(books[3].getDisplayCover())
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import androidx.appcompat.widget.SearchView
|
||||
import androidx.core.view.isGone
|
||||
import androidx.lifecycle.Lifecycle
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.recyclerview.widget.DefaultItemAnimator
|
||||
import androidx.recyclerview.widget.GridLayoutManager
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
@@ -19,8 +20,6 @@ import io.legato.kazusa.data.entities.Book
|
||||
import io.legato.kazusa.data.entities.BookGroup
|
||||
import io.legato.kazusa.databinding.FragmentBookshelf2Binding
|
||||
import io.legato.kazusa.help.config.AppConfig
|
||||
//import io.legado.app.lib.theme.accentColor
|
||||
//import io.legado.app.lib.theme.primaryColor
|
||||
import io.legato.kazusa.ui.book.group.GroupEditDialog
|
||||
import io.legato.kazusa.ui.book.info.BookInfoActivity
|
||||
import io.legato.kazusa.ui.book.search.SearchActivity
|
||||
@@ -35,7 +34,6 @@ import io.legato.kazusa.utils.startActivityForBook
|
||||
import io.legato.kazusa.utils.viewbindingdelegate.viewBinding
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.flow.catch
|
||||
import kotlinx.coroutines.flow.conflate
|
||||
import kotlinx.coroutines.flow.flowOn
|
||||
@@ -67,9 +65,11 @@ class BookshelfFragment2() : BaseBookshelfFragment(R.layout.fragment_bookshelf2)
|
||||
BooksAdapterGrid(requireContext(), this)
|
||||
}
|
||||
}
|
||||
|
||||
private var bookGroups: List<BookGroup> = emptyList()
|
||||
private var booksFlowJob: Job? = null
|
||||
override var groupId = BookGroup.IdRoot
|
||||
private var allBooks: List<Book> = emptyList()
|
||||
override var books: List<Book> = emptyList()
|
||||
private var enableRefresh = true
|
||||
|
||||
@@ -77,12 +77,11 @@ class BookshelfFragment2() : BaseBookshelfFragment(R.layout.fragment_bookshelf2)
|
||||
setSupportToolbar(binding.titleBar.toolbar)
|
||||
initRecyclerView()
|
||||
initBookGroupData()
|
||||
initAllBooksData()
|
||||
initBooksData()
|
||||
}
|
||||
|
||||
private fun initRecyclerView() {
|
||||
// binding.rvBookshelf.setEdgeEffectColor(primaryColor)
|
||||
// binding.refreshLayout.setColorSchemeColors(accentColor)
|
||||
binding.refreshLayout.setOnRefreshListener {
|
||||
binding.refreshLayout.isRefreshing = false
|
||||
activityViewModel.upToc(books)
|
||||
@@ -111,6 +110,7 @@ class BookshelfFragment2() : BaseBookshelfFragment(R.layout.fragment_bookshelf2)
|
||||
}
|
||||
}
|
||||
})
|
||||
binding.rvBookshelf.itemAnimator = DefaultItemAnimator()
|
||||
}
|
||||
|
||||
override fun upGroup(data: List<BookGroup>) {
|
||||
@@ -123,9 +123,37 @@ class BookshelfFragment2() : BaseBookshelfFragment(R.layout.fragment_bookshelf2)
|
||||
}
|
||||
|
||||
override fun upSort() {
|
||||
initAllBooksData()
|
||||
initBooksData()
|
||||
}
|
||||
|
||||
private var allBooksFlowJob: Job? = null
|
||||
|
||||
private fun initAllBooksData() {
|
||||
allBooksFlowJob?.cancel()
|
||||
allBooksFlowJob = viewLifecycleOwner.lifecycleScope.launch {
|
||||
appDb.bookDao.flowAll().map { list ->
|
||||
when (AppConfig.getBookSortByGroupId(BookGroup.IdRoot)) {
|
||||
1 -> list.sortedByDescending { it.latestChapterTime }
|
||||
2 -> list.sortedWith { o1, o2 -> o1.name.cnCompare(o2.name) }
|
||||
3 -> list.sortedBy { it.order }
|
||||
4 -> list.sortedByDescending { max(it.latestChapterTime, it.durChapterTime) }
|
||||
else -> list.sortedByDescending { it.durChapterTime }
|
||||
}
|
||||
}.flowWithLifecycleAndDatabaseChangeFirst(
|
||||
viewLifecycleOwner.lifecycle,
|
||||
Lifecycle.State.RESUMED,
|
||||
AppDatabase.BOOK_TABLE_NAME
|
||||
).catch {
|
||||
AppLog.put("所有书籍更新出错", it)
|
||||
}.conflate().flowOn(Dispatchers.Default).collect { list ->
|
||||
allBooks = list
|
||||
booksAdapter.setAllBooks(allBooks)
|
||||
booksAdapter.updateItems()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun initBooksData() {
|
||||
if (groupId == BookGroup.IdRoot) {
|
||||
if (isAdded) {
|
||||
@@ -137,14 +165,16 @@ class BookshelfFragment2() : BaseBookshelfFragment(R.layout.fragment_bookshelf2)
|
||||
bookGroups.firstOrNull {
|
||||
groupId == it.groupId
|
||||
}?.let {
|
||||
binding.titleBar.title = "${getString(R.string.bookshelf)}(${it.groupName})"
|
||||
binding.titleBar.title = it.groupName
|
||||
binding.refreshLayout.isEnabled = it.enableRefresh
|
||||
enableRefresh = it.enableRefresh
|
||||
}
|
||||
}
|
||||
booksFlowJob?.cancel()
|
||||
booksFlowJob = viewLifecycleOwner.lifecycleScope.launch {
|
||||
|
||||
appDb.bookDao.flowByGroup(groupId).map { list ->
|
||||
|
||||
//排序
|
||||
when (AppConfig.getBookSortByGroupId(groupId)) {
|
||||
1 -> list.sortedByDescending {
|
||||
@@ -178,7 +208,6 @@ class BookshelfFragment2() : BaseBookshelfFragment(R.layout.fragment_bookshelf2)
|
||||
booksAdapter.updateItems()
|
||||
binding.tvEmptyMsg.isGone = getItemCount() > 0
|
||||
binding.refreshLayout.isEnabled = enableRefresh && getItemCount() > 0
|
||||
delay(100)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -244,12 +273,14 @@ class BookshelfFragment2() : BaseBookshelfFragment(R.layout.fragment_bookshelf2)
|
||||
}
|
||||
|
||||
override fun getItems(): List<Any> {
|
||||
if (groupId != BookGroup.IdRoot) {
|
||||
return books
|
||||
return if (groupId == BookGroup.IdRoot) {
|
||||
bookGroups + books
|
||||
} else {
|
||||
books
|
||||
}
|
||||
return bookGroups + books
|
||||
}
|
||||
|
||||
|
||||
@SuppressLint("NotifyDataSetChanged")
|
||||
override fun observeLiveBus() {
|
||||
super.observeLiveBus()
|
||||
|
||||
@@ -2,11 +2,10 @@ package io.legato.kazusa.ui.widget
|
||||
|
||||
import android.content.Context
|
||||
import android.content.res.ColorStateList
|
||||
import android.graphics.Color
|
||||
import android.util.AttributeSet
|
||||
import com.google.android.material.chip.Chip
|
||||
import com.google.android.material.chip.ChipGroup
|
||||
import com.google.android.material.color.MaterialColors
|
||||
import io.legato.kazusa.utils.themeColor
|
||||
|
||||
@Suppress("unused", "MemberVisibilityCanBePrivate")
|
||||
class LabelsBar @JvmOverloads constructor(
|
||||
@@ -44,10 +43,9 @@ class LabelsBar @JvmOverloads constructor(
|
||||
chipStrokeWidth = 0f
|
||||
|
||||
chipBackgroundColor = ColorStateList.valueOf(
|
||||
MaterialColors.getColor(this, com.google.android.material.R.attr.colorPrimaryContainer, Color.LTGRAY)
|
||||
context.themeColor(com.google.android.material.R.attr.colorPrimaryContainer)
|
||||
)
|
||||
|
||||
|
||||
usedChips.add(this)
|
||||
}
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user