主页动画
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
@@ -62,15 +61,12 @@
|
||||
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
|
||||
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_empty_msg"
|
||||
<io.legado.app.ui.widget.EmptyMessageView
|
||||
android:id="@+id/emptyView"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:visibility="visible"
|
||||
android:layout_gravity="center"
|
||||
android:layout_margin="16dp"
|
||||
android:gravity="center"
|
||||
android:text="@string/bookshelf_empty"
|
||||
android:visibility="gone"
|
||||
tools:text="TextView" />
|
||||
app:messageText="@string/bookshelf_empty"/>
|
||||
|
||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
||||
|
||||
Reference in New Issue
Block a user