Adding empty view for recents

This commit is contained in:
Jays2Kings 2021-04-08 00:30:20 -04:00
parent c5e922334c
commit 2c4ddcd555
7 changed files with 127 additions and 29 deletions

View File

@ -135,8 +135,16 @@ class RecentsController(bundle: Bundle? = null) :
includeTabView = true,
afterInsets = {
headerHeight = it.systemWindowInsetTop + appBarHeight + 48.dpToPx
binding.recycler.updatePaddingRelative(bottom = activityBinding?.bottomNav?.height ?: 0)
binding.downloadBottomSheet.dlRecycler.updatePaddingRelative(bottom = activityBinding?.bottomNav?.height ?: 0)
binding.recycler.updatePaddingRelative(
bottom = activityBinding?.bottomNav?.height ?: 0
)
binding.downloadBottomSheet.dlRecycler.updatePaddingRelative(
bottom = activityBinding?.bottomNav?.height ?: 0
)
binding.recentsEmptyView.updateLayoutParams<ViewGroup.MarginLayoutParams> {
topMargin = headerHeight
bottomMargin = activityBinding?.bottomNav?.height ?: 0
}
},
onBottomNavUpdate = {
setBottomPadding()
@ -145,7 +153,9 @@ class RecentsController(bundle: Bundle? = null) :
activityBinding?.bottomNav?.post {
binding.recycler.updatePaddingRelative(bottom = activityBinding?.bottomNav?.height ?: 0)
binding.downloadBottomSheet.dlRecycler.updatePaddingRelative(bottom = activityBinding?.bottomNav?.height ?: 0)
binding.downloadBottomSheet.dlRecycler.updatePaddingRelative(
bottom = activityBinding?.bottomNav?.height ?: 0
)
activityBinding?.tabsFrameLayout?.isVisible = !binding.downloadBottomSheet.root.sheetBehavior.isExpanded()
}
@ -167,7 +177,8 @@ class RecentsController(bundle: Bundle? = null) :
override fun onSlide(bottomSheet: View, progress: Float) {
binding.shadow2.alpha = (1 - abs(progress)) * 0.25f
binding.shadow.alpha = (1 - abs(progress)) * 0.5f
val height = binding.root.height - binding.downloadBottomSheet.dlRecycler.paddingTop
val height =
binding.root.height - binding.downloadBottomSheet.dlRecycler.paddingTop
// Doing some fun math to hide the tab bar just as the title text of the
// dl sheet is under the toolbar
val cap = height * (1 / 12600f) + 479f / 700
@ -176,7 +187,10 @@ class RecentsController(bundle: Bundle? = null) :
if (binding.recycler.canScrollVertically(-1)) 15f else 0f
).coerceIn(0f, 15f)
binding.downloadBottomSheet.sheetLayout.alpha = 1 - max(0f, progress / cap)
activityBinding?.appBar?.y = max(activityBinding!!.appBar.y, -headerHeight * (1 - progress))
activityBinding?.appBar?.y = max(
activityBinding!!.appBar.y,
-headerHeight * (1 - progress)
)
activityBinding?.tabsFrameLayout?.let { tabs ->
tabs.alpha = 1 - max(0f, progress / cap)
if (tabs.alpha <= 0 && tabs.isVisible) {
@ -204,30 +218,41 @@ class RecentsController(bundle: Bundle? = null) :
activity?.invalidateOptionsMenu()
}
activityBinding?.tabsFrameLayout?.isVisible = state != BottomSheetBehavior.STATE_EXPANDED
activityBinding?.tabsFrameLayout?.isVisible =
state != BottomSheetBehavior.STATE_EXPANDED
if (state == BottomSheetBehavior.STATE_COLLAPSED) {
if (hasQueue()) {
binding.downloadBottomSheet.dlBottomSheet.sheetBehavior?.isHideable = false
binding.downloadBottomSheet.dlBottomSheet.sheetBehavior?.isHideable =
false
} else {
binding.downloadBottomSheet.dlBottomSheet.sheetBehavior?.isHideable = true
binding.downloadBottomSheet.dlBottomSheet.sheetBehavior?.state = BottomSheetBehavior.STATE_HIDDEN
binding.downloadBottomSheet.dlBottomSheet.sheetBehavior?.isHideable =
true
binding.downloadBottomSheet.dlBottomSheet.sheetBehavior?.state =
BottomSheetBehavior.STATE_HIDDEN
}
} else if (state == BottomSheetBehavior.STATE_HIDDEN) {
if (!hasQueue()) {
binding.downloadBottomSheet.dlBottomSheet.sheetBehavior?.skipCollapsed = true
binding.downloadBottomSheet.dlBottomSheet.sheetBehavior?.skipCollapsed =
true
} else {
binding.downloadBottomSheet.dlBottomSheet.sheetBehavior?.skipCollapsed = false
binding.downloadBottomSheet.dlBottomSheet.sheetBehavior?.state = BottomSheetBehavior.STATE_COLLAPSED
binding.downloadBottomSheet.dlBottomSheet.sheetBehavior?.skipCollapsed =
false
binding.downloadBottomSheet.dlBottomSheet.sheetBehavior?.state =
BottomSheetBehavior.STATE_COLLAPSED
}
}
if (state == BottomSheetBehavior.STATE_HIDDEN || state == BottomSheetBehavior.STATE_COLLAPSED) {
binding.shadow2.alpha = if (state == BottomSheetBehavior.STATE_COLLAPSED) 0.25f else 0f
binding.shadow.alpha = if (state == BottomSheetBehavior.STATE_COLLAPSED) 0.5f else 0f
binding.shadow2.alpha =
if (state == BottomSheetBehavior.STATE_COLLAPSED) 0.25f else 0f
binding.shadow.alpha =
if (state == BottomSheetBehavior.STATE_COLLAPSED) 0.5f else 0f
}
binding.downloadBottomSheet.sheetLayout.isClickable = state == BottomSheetBehavior.STATE_COLLAPSED
binding.downloadBottomSheet.sheetLayout.isFocusable = state == BottomSheetBehavior.STATE_COLLAPSED
binding.downloadBottomSheet.sheetLayout.isClickable =
state == BottomSheetBehavior.STATE_COLLAPSED
binding.downloadBottomSheet.sheetLayout.isFocusable =
state == BottomSheetBehavior.STATE_COLLAPSED
setPadding(binding.downloadBottomSheet.dlBottomSheet.sheetBehavior?.isHideable == true)
}
}
@ -313,7 +338,11 @@ class RecentsController(bundle: Bundle? = null) :
fun refresh() = presenter.getRecents()
fun showLists(recents: List<RecentMangaItem>, hasNewItems: Boolean, shouldMoveToTop: Boolean = false) {
fun showLists(
recents: List<RecentMangaItem>,
hasNewItems: Boolean,
shouldMoveToTop: Boolean = false
) {
if (view == null) return
binding.swipeRefresh.isRefreshing = LibraryUpdateService.isRunning()
adapter.removeAllScrollableHeaders()
@ -326,6 +355,20 @@ class RecentsController(bundle: Bundle? = null) :
} else if (hasNewItems && presenter.viewType != RecentsPresenter.VIEW_TYPE_GROUP_ALL && presenter.query.isEmpty()) {
resetProgressItem()
}
if (recents.isEmpty()) {
binding.recentsEmptyView.show(
if (presenter.query.isEmpty()) R.drawable.ic_history_off_24dp
else R.drawable.ic_search_off_24dp,
if (presenter.query.isNotEmpty()) R.string.no_results_found
else when (presenter.viewType) {
RecentsPresenter.VIEW_TYPE_ONLY_UPDATES -> R.string.no_recent_chapters
RecentsPresenter.VIEW_TYPE_ONLY_HISTORY -> R.string.no_recently_read_manga
else -> R.string.no_recent_read_updated_manga
}
)
} else {
binding.recentsEmptyView.hide()
}
if (shouldMoveToTop) {
binding.recycler.scrollToPosition(0)
}

View File

@ -224,8 +224,7 @@ class RecentsPresenter(
it.second,
newChaptersHeader
)
} +
RecentMangaItem(header = newChaptersHeader)
}.toMutableList()
val cReadingItems =
pairs.filter { it.first.history.id != null }.take(9 - nChaptersItems.size).map {
RecentMangaItem(
@ -233,7 +232,13 @@ class RecentsPresenter(
it.second,
continueReadingHeader
)
} + RecentMangaItem(header = continueReadingHeader)
}.toMutableList()
if (nChaptersItems.isNotEmpty()) {
nChaptersItems.add(RecentMangaItem(header = newChaptersHeader))
}
if (cReadingItems.isNotEmpty()) {
cReadingItems.add(RecentMangaItem(header = continueReadingHeader))
}
val nAdditionsItems = pairs.filter { it.first.chapter.id == null }.take(4)
.map { RecentMangaItem(it.first, it.second, newAdditionsHeader) }
listOf(nChaptersItems, cReadingItems, nAdditionsItems).sortedByDescending {

View File

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M15.1,19.37l1,1.74c-0.96,0.44 -2.01,0.73 -3.1,0.84v-2.02C13.74,19.84 14.44,19.65 15.1,19.37zM4.07,13H2.05c0.11,1.1 0.4,2.14 0.84,3.1l1.74,-1C4.35,14.44 4.16,13.74 4.07,13zM15.1,4.63l1,-1.74C15.14,2.45 14.1,2.16 13,2.05v2.02C13.74,4.16 14.44,4.35 15.1,4.63zM19.93,11h2.02c-0.11,-1.1 -0.4,-2.14 -0.84,-3.1l-1.74,1C19.65,9.56 19.84,10.26 19.93,11zM8.9,19.37l-1,1.74c0.96,0.44 2.01,0.73 3.1,0.84v-2.02C10.26,19.84 9.56,19.65 8.9,19.37zM11,4.07V2.05c-1.1,0.11 -2.14,0.4 -3.1,0.84l1,1.74C9.56,4.35 10.26,4.16 11,4.07zM18.36,7.17l1.74,-1.01c-0.63,-0.87 -1.4,-1.64 -2.27,-2.27l-1.01,1.74C17.41,6.08 17.92,6.59 18.36,7.17zM4.63,8.9l-1.74,-1C2.45,8.86 2.16,9.9 2.05,11h2.02C4.16,10.26 4.35,9.56 4.63,8.9zM19.93,13c-0.09,0.74 -0.28,1.44 -0.56,2.1l1.74,1c0.44,-0.96 0.73,-2.01 0.84,-3.1H19.93zM16.83,18.36l1.01,1.74c0.87,-0.63 1.64,-1.4 2.27,-2.27l-1.74,-1.01C17.92,17.41 17.41,17.92 16.83,18.36zM7.17,5.64L6.17,3.89C5.29,4.53 4.53,5.29 3.9,6.17l1.74,1.01C6.08,6.59 6.59,6.08 7.17,5.64zM5.64,16.83L3.9,17.83c0.63,0.87 1.4,1.64 2.27,2.27l1.01,-1.74C6.59,17.92 6.08,17.41 5.64,16.83zM13,7h-2v5.41l4.29,4.29l1.41,-1.41L13,11.59V7z"/>
</vector>

View File

@ -0,0 +1,13 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M15.5,14h-0.79l-0.28,-0.27C15.41,12.59 16,11.11 16,9.5C16,5.91 13.09,3 9.5,3C6.08,3 3.28,5.64 3.03,9h2.02C5.3,6.75 7.18,5 9.5,5C11.99,5 14,7.01 14,9.5S11.99,14 9.5,14c-0.17,0 -0.33,-0.03 -0.5,-0.05v2.02C9.17,15.99 9.33,16 9.5,16c1.61,0 3.09,-0.59 4.23,-1.57L14,14.71v0.79l5,4.99L20.49,19L15.5,14z"/>
<path
android:fillColor="@android:color/white"
android:pathData="M6.47,10.82l-2.47,2.47l-2.47,-2.47l-0.71,0.71l2.47,2.47l-2.47,2.47l0.71,0.71l2.47,-2.47l2.47,2.47l0.71,-0.71l-2.47,-2.47l2.47,-2.47z"/>
</vector>

View File

@ -1,17 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.constraintlayout.widget.ConstraintLayout 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="wrap_content"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
android:padding="16dp">
android:orientation="vertical">
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/image_view"
android:layout_width="128dp"
android:layout_height="128dp"
tools:src="@drawable/ic_file_download_24dp"/>
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginTop="16dp"
app:layout_constraintBottom_toTopOf="@id/text_label"
app:layout_constraintDimensionRatio="h,1:1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHeight_max="128dp"
app:layout_constraintHeight_min="24dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_chainStyle="packed"
app:layout_constraintWidth_max="128dp"
app:layout_constraintWidth_min="24dp"
tools:src="@drawable/ic_file_download_24dp" />
<TextView
android:id="@+id/text_label"
@ -20,6 +31,10 @@
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:gravity="center"
app:layout_constraintBottom_toTopOf="@id/actions_container"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/image_view"
tools:text="Label" />
<LinearLayout
@ -27,6 +42,10 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical" />
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/text_label" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -28,6 +28,13 @@
</FrameLayout>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
<eu.kanade.tachiyomi.widget.EmptyView
android:id="@+id/recents_empty_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:visibility="gone"/>
<View
android:id="@+id/shadow"
android:layout_width="match_parent"

View File

@ -222,6 +222,7 @@
<string name="view_history">View history</string>
<string name="view_all_updates">View all updates</string>
<string name="search_recents">Search recents…</string>
<string name="no_recent_read_updated_manga">No recently read or updated manga</string>
<string name="no_recent_chapters">No recent chapters</string>
<string name="no_recently_read_manga">No recently read manga</string>
<string name="group_all">Group all</string>