Glimpse: Also show "No media" in album fragments
Change-Id: I51fc2191e0c910e6b77ca82e6650df0ea7cdc634
diff --git a/app/src/main/java/org/lineageos/glimpse/fragments/AlbumsFragment.kt b/app/src/main/java/org/lineageos/glimpse/fragments/AlbumsFragment.kt
index 0fd8ead..8d47c11 100644
--- a/app/src/main/java/org/lineageos/glimpse/fragments/AlbumsFragment.kt
+++ b/app/src/main/java/org/lineageos/glimpse/fragments/AlbumsFragment.kt
@@ -11,9 +11,11 @@
import android.view.View
import android.view.ViewGroup
import android.view.ViewGroup.MarginLayoutParams
+import android.widget.LinearLayout
import androidx.core.os.bundleOf
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
+import androidx.core.view.isVisible
import androidx.core.view.updateLayoutParams
import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels
@@ -49,6 +51,7 @@
// Views
private val albumsRecyclerView by getViewProperty<RecyclerView>(R.id.albumsRecyclerView)
private val appBarLayout by getViewProperty<AppBarLayout>(R.id.appBarLayout)
+ private val noMediaLinearLayout by getViewProperty<LinearLayout>(R.id.noMediaLinearLayout)
// Fragments
private val parentNavController by lazy {
@@ -61,7 +64,14 @@
viewLifecycleOwner.repeatOnLifecycle(Lifecycle.State.STARTED) {
albumsViewModel.albums.collectLatest {
when (it) {
- is Data -> albumThumbnailAdapter.submitList(it.values)
+ is Data -> {
+ albumThumbnailAdapter.submitList(it.values)
+
+ val noMedia = it.values.isEmpty()
+ albumsRecyclerView.isVisible = !noMedia
+ noMediaLinearLayout.isVisible = noMedia
+ }
+
is Empty -> Unit
}
}
diff --git a/app/src/main/java/org/lineageos/glimpse/fragments/picker/AlbumSelectorFragment.kt b/app/src/main/java/org/lineageos/glimpse/fragments/picker/AlbumSelectorFragment.kt
index 8298d8e..e98196d 100644
--- a/app/src/main/java/org/lineageos/glimpse/fragments/picker/AlbumSelectorFragment.kt
+++ b/app/src/main/java/org/lineageos/glimpse/fragments/picker/AlbumSelectorFragment.kt
@@ -8,8 +8,10 @@
import android.os.Bundle
import android.view.View
import android.view.ViewGroup
+import android.widget.LinearLayout
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
+import androidx.core.view.isVisible
import androidx.core.view.updateLayoutParams
import androidx.core.view.updatePadding
import androidx.fragment.app.Fragment
@@ -41,6 +43,7 @@
// Views
private val albumsRecyclerView by getViewProperty<RecyclerView>(R.id.albumsRecyclerView)
+ private val noMediaLinearLayout by getViewProperty<LinearLayout>(R.id.noMediaLinearLayout)
// Intent data
private val mimeType by lazy { PickerUtils.translateMimeType(activity?.intent) }
@@ -63,6 +66,10 @@
when (it) {
is QueryResult.Data -> {
albumThumbnailAdapter.submitList(it.values)
+
+ val noMedia = it.values.isEmpty()
+ albumsRecyclerView.isVisible = !noMedia
+ noMediaLinearLayout.isVisible = noMedia
}
is QueryResult.Empty -> Unit
diff --git a/app/src/main/res/layout/fragment_albums.xml b/app/src/main/res/layout/fragment_albums.xml
index a719143..4f33847 100644
--- a/app/src/main/res/layout/fragment_albums.xml
+++ b/app/src/main/res/layout/fragment_albums.xml
@@ -26,6 +26,30 @@
</com.google.android.material.appbar.AppBarLayout>
+ <LinearLayout
+ android:id="@+id/noMediaLinearLayout"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:gravity="center"
+ android:orientation="vertical"
+ android:visibility="gone">
+
+ <ImageView
+ android:layout_width="72dp"
+ android:layout_height="72dp"
+ android:contentDescription="@string/no_media"
+ android:padding="12dp"
+ android:src="@drawable/ic_no_photography"
+ app:tint="?attr/colorOnBackground" />
+
+ <TextView
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="@string/no_media"
+ android:textAppearance="?attr/textAppearanceBodyLarge" />
+
+ </LinearLayout>
+
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/albumsRecyclerView"
android:layout_width="match_parent"
diff --git a/app/src/main/res/layout/fragment_picker_album_selector.xml b/app/src/main/res/layout/fragment_picker_album_selector.xml
index e220a61..8289273 100644
--- a/app/src/main/res/layout/fragment_picker_album_selector.xml
+++ b/app/src/main/res/layout/fragment_picker_album_selector.xml
@@ -3,11 +3,42 @@
SPDX-FileCopyrightText: 2024 The LineageOS Project
SPDX-License-Identifier: Apache-2.0
-->
-<androidx.recyclerview.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
+<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:id="@+id/albumsRecyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
- android:clipToPadding="false"
- android:scrollbars="vertical"
- tools:context=".fragments.picker.AlbumSelectorFragment" />
+ tools:context=".fragments.picker.AlbumSelectorFragment">
+
+ <LinearLayout
+ android:id="@+id/noMediaLinearLayout"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:gravity="center"
+ android:orientation="vertical"
+ android:visibility="gone">
+
+ <ImageView
+ android:layout_width="72dp"
+ android:layout_height="72dp"
+ android:contentDescription="@string/no_media"
+ android:padding="12dp"
+ android:src="@drawable/ic_no_photography"
+ app:tint="?attr/colorOnBackground" />
+
+ <TextView
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="@string/no_media"
+ android:textAppearance="?attr/textAppearanceBodyLarge" />
+
+ </LinearLayout>
+
+ <androidx.recyclerview.widget.RecyclerView
+ android:id="@+id/albumsRecyclerView"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:clipToPadding="false"
+ android:scrollbars="vertical" />
+
+</androidx.coordinatorlayout.widget.CoordinatorLayout>