主页动画

This commit is contained in:
HapeLee
2025-11-13 20:34:24 +08:00
parent e36c6c180d
commit 4f0fe47c07
6 changed files with 28 additions and 19 deletions
@@ -10,6 +10,7 @@ import android.view.ViewConfiguration
import androidx.core.app.ActivityOptionsCompat
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.core.view.doOnPreDraw
import androidx.core.view.isGone
import androidx.fragment.app.activityViewModels
import androidx.lifecycle.Lifecycle
@@ -115,6 +116,10 @@ class BooksFragment() : BaseFragment(R.layout.fragment_books),
private var enableRefresh = true
override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) {
postponeEnterTransition()
view.doOnPreDraw {
startPostponedEnterTransition()
}
arguments?.let {
position = it.getInt("position", 0)
groupId = it.getLong("groupId", -1)
@@ -243,10 +248,11 @@ class BooksFragment() : BaseFragment(R.layout.fragment_books),
).catch {
AppLog.put("书架更新出错", it)
}.conflate().flowOn(Dispatchers.Default).collect { list ->
if (view == null) return@collect
binding.emptyView.isGone = list.isNotEmpty()
binding.refreshLayout.isEnabled = enableRefresh && list.isNotEmpty()
booksAdapter.setItems(list)
delay(100)
delay(500)
}
}
}
@@ -11,6 +11,7 @@ import androidx.appcompat.widget.SearchView
import androidx.core.app.ActivityOptionsCompat
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.core.view.doOnPreDraw
import androidx.core.view.isGone
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.lifecycleScope
@@ -51,6 +52,7 @@ import io.legado.app.utils.showDialogFragment
import io.legado.app.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
@@ -118,6 +120,10 @@ class BookshelfFragment2() : BaseBookshelfFragment(R.layout.fragment_bookshelf2)
override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) {
setSupportToolbar(binding.topBar)
postponeEnterTransition()
view.doOnPreDraw {
startPostponedEnterTransition()
}
initRecyclerView()
initBookGroupData()
initAllBooksData()
@@ -205,7 +211,7 @@ class BookshelfFragment2() : BaseBookshelfFragment(R.layout.fragment_bookshelf2)
if (data != bookGroups) {
bookGroups = data
booksAdapter.updateItems()
binding.tvEmptyMsg.isGone = getItemCount() > 0
binding.emptyView.isGone = getItemCount() > 0
binding.refreshLayout.isEnabled = enableRefresh && getItemCount() > 0
}
}
@@ -299,10 +305,11 @@ class BookshelfFragment2() : BaseBookshelfFragment(R.layout.fragment_bookshelf2)
).catch {
AppLog.put("书架更新出错", it)
}.conflate().flowOn(Dispatchers.Default).collect { list ->
books = list
if (view == null) return@collect
binding.emptyView.isGone = list.isNotEmpty()
binding.refreshLayout.isEnabled = enableRefresh && list.isNotEmpty()
booksAdapter.updateItems()
binding.tvEmptyMsg.isGone = getItemCount() > 0
binding.refreshLayout.isEnabled = enableRefresh && getItemCount() > 0
delay(500)
}
}
}
@@ -104,13 +104,13 @@ class BooksAdapterList(
holder.itemView.apply {
binding.cvContent.setOnClickListener {
getItem(holder.layoutPosition)?.let {
callBack.open(it, binding.cvContent)
callBack.open(it, binding.cdCover)
}
}
binding.cvContent.onLongClick {
getItem(holder.layoutPosition)?.let {
callBack.openBookInfo(it, binding.cvContent)
callBack.openBookInfo(it, binding.cdCover)
}
}
}
@@ -92,10 +92,10 @@ class BooksAdapterGrid(context: Context, callBack: CallBack) :
fun registerListener(item: Any) {
binding.cvContent.setOnClickListener {
callBack.onItemClick(item, binding.ivCover)
callBack.onItemClick(item, binding.cvContent)
}
binding.cvContent.onLongClick {
callBack.onItemLongClick(item, binding.ivCover)
callBack.onItemLongClick(item, binding.cvContent)
}
}
@@ -113,10 +113,10 @@ class BooksAdapterList(context: Context, callBack: CallBack) :
fun registerListener(item: Any) {
binding.cvContent.setOnClickListener {
callBack.onItemClick(item, binding.cvContent)
callBack.onItemClick(item, binding.cdCover)
}
binding.cvContent.onLongClick {
callBack.onItemLongClick(item, binding.cvContent)
callBack.onItemLongClick(item, binding.cdCover)
}
}