Glimpse: Cleanup toolbar menus
Also add empty trash button
Change-Id: Ia99bf9fac4209549d7bffa4f04174b850d631a6e
diff --git a/app/src/main/java/org/lineageos/glimpse/fragments/AlbumViewerFragment.kt b/app/src/main/java/org/lineageos/glimpse/fragments/AlbumViewerFragment.kt
index 520304a..216e11b 100644
--- a/app/src/main/java/org/lineageos/glimpse/fragments/AlbumViewerFragment.kt
+++ b/app/src/main/java/org/lineageos/glimpse/fragments/AlbumViewerFragment.kt
@@ -56,6 +56,7 @@
import org.lineageos.glimpse.viewmodels.AlbumViewerViewModel
import org.lineageos.glimpse.viewmodels.QueryResult.Data
import org.lineageos.glimpse.viewmodels.QueryResult.Empty
+import kotlin.reflect.safeCast
/**
* A fragment showing a list of media from a specific album with thumbnails.
@@ -332,6 +333,50 @@
val appBarConfiguration = AppBarConfiguration(navController.graph)
toolbar.setupWithNavController(navController, appBarConfiguration)
+ when (album?.id) {
+ MediaStoreBuckets.MEDIA_STORE_BUCKET_TRASH.id ->
+ R.menu.fragment_album_viewer_toolbar_trash
+ else -> null
+ }?.let {
+ toolbar.inflateMenu(it)
+ }
+
+ toolbar.setOnMenuItemClickListener { menuItem ->
+ when (menuItem.itemId) {
+ R.id.emptyTrash -> {
+ val selection = thumbnailAdapter.currentList.mapNotNull {
+ AlbumViewerViewModel.DataType.Thumbnail::class.safeCast(it)?.media
+ }
+ val count = selection.size
+
+ if (count > 0) {
+ MaterialAlertDialogBuilder(requireContext())
+ .setTitle(R.string.file_action_delete_forever)
+ .setMessage(
+ resources.getQuantityString(
+ R.plurals.delete_file_forever_confirm_message, count, count
+ )
+ ).setPositiveButton(android.R.string.ok) { _, _ ->
+ deleteForeverContract.launch(
+ requireContext().contentResolver.createDeleteRequest(
+ *selection.mapNotNull { media ->
+ MediaStoreMedia::class.safeCast(media)?.uri
+ }.toTypedArray()
+ )
+ )
+ }
+ .setNegativeButton(android.R.string.cancel) { _, _ ->
+ // Do nothing
+ }
+ .show()
+ }
+
+ true
+ }
+ else -> false
+ }
+ }
+
recyclerView.layoutManager = ThumbnailLayoutManager(
requireContext(), thumbnailAdapter
)
diff --git a/app/src/main/res/drawable/ic_delete_sweep.xml b/app/src/main/res/drawable/ic_delete_sweep.xml
new file mode 100644
index 0000000..2ff2e9c
--- /dev/null
+++ b/app/src/main/res/drawable/ic_delete_sweep.xml
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ SPDX-FileCopyrightText: Material Design Authors / Google LLC
+ SPDX-License-Identifier: Apache-2.0
+-->
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="24dp"
+ android:height="24dp"
+ android:tint="#000000"
+ android:viewportWidth="24"
+ android:viewportHeight="24">
+ <path
+ android:fillColor="@android:color/white"
+ android:pathData="M15,16h4v2h-4zM15,8h7v2h-7zM15,12h6v2h-6zM3,18c0,1.1 0.9,2 2,2h6c1.1,0 2,-0.9 2,-2L13,8L3,8v10zM5,10h6v8L5,18v-8zM10,4L6,4L5,5L2,5v2h12L14,5h-3z" />
+</vector>
diff --git a/app/src/main/res/layout/fragment_album_viewer.xml b/app/src/main/res/layout/fragment_album_viewer.xml
index 9562818..beceea1 100644
--- a/app/src/main/res/layout/fragment_album_viewer.xml
+++ b/app/src/main/res/layout/fragment_album_viewer.xml
@@ -21,8 +21,7 @@
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
- app:layout_scrollFlags="scroll|enterAlways|snap"
- app:menu="@menu/top_app_bar" />
+ app:layout_scrollFlags="scroll|enterAlways|snap" />
</com.google.android.material.appbar.AppBarLayout>
diff --git a/app/src/main/res/layout/fragment_albums.xml b/app/src/main/res/layout/fragment_albums.xml
index 3699e70..a719143 100644
--- a/app/src/main/res/layout/fragment_albums.xml
+++ b/app/src/main/res/layout/fragment_albums.xml
@@ -22,7 +22,6 @@
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_scrollFlags="scroll|enterAlways|snap"
- app:menu="@menu/top_app_bar"
app:title="@string/albums_title" />
</com.google.android.material.appbar.AppBarLayout>
diff --git a/app/src/main/res/layout/fragment_main.xml b/app/src/main/res/layout/fragment_main.xml
index e1243cb..e16013e 100644
--- a/app/src/main/res/layout/fragment_main.xml
+++ b/app/src/main/res/layout/fragment_main.xml
@@ -30,6 +30,6 @@
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
- app:menu="@menu/bottom_app_bar" />
+ app:menu="@menu/fragment_main_bottom_app_bar" />
</androidx.constraintlayout.widget.ConstraintLayout>
diff --git a/app/src/main/res/menu/top_app_bar.xml b/app/src/main/res/menu/fragment_album_viewer_toolbar_trash.xml
similarity index 60%
rename from app/src/main/res/menu/top_app_bar.xml
rename to app/src/main/res/menu/fragment_album_viewer_toolbar_trash.xml
index 002fdda..6b327ca 100644
--- a/app/src/main/res/menu/top_app_bar.xml
+++ b/app/src/main/res/menu/fragment_album_viewer_toolbar_trash.xml
@@ -8,10 +8,10 @@
<item
style="@style/Theme.Glimpse.TopAppBarOption"
- android:id="@+id/select"
- android:icon="@drawable/ic_edit"
- android:title="@string/top_app_bar_select"
- android:contentDescription="@string/top_app_bar_select"
- app:showAsAction="never" />
+ android:id="@+id/emptyTrash"
+ android:icon="@drawable/ic_delete_sweep"
+ android:title="@string/empty_trash"
+ android:contentDescription="@string/empty_trash"
+ app:showAsAction="ifRoom" />
</menu>
diff --git a/app/src/main/res/menu/bottom_app_bar.xml b/app/src/main/res/menu/fragment_main_bottom_app_bar.xml
similarity index 100%
rename from app/src/main/res/menu/bottom_app_bar.xml
rename to app/src/main/res/menu/fragment_main_bottom_app_bar.xml
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index fde668a..e8f99cc 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -9,9 +9,6 @@
<!-- Toast messages -->
<string name="app_permissions_toast">Permissions not granted by the user.</string>
- <!-- Top app bar -->
- <string name="top_app_bar_select">Select</string>
-
<!-- Titles -->
<string name="reels_title">Reels</string>
<string name="albums_title">Albums</string>
@@ -102,4 +99,7 @@
<!-- Selection -->
<string name="thumbnail_selection_count">%d selected</string>
+
+ <!-- Empty trash -->
+ <string name="empty_trash">Empty trash</string>
</resources>