Glimpse: Move info and useAs actions to toolbar

Also tweak colors

Change-Id: I3e69e38f846de7d71e938c17560fbfb2aa06d82b
Signed-off-by: Aayush Gupta <aayushgupta219@gmail.com>
diff --git a/app/src/main/java/org/lineageos/glimpse/ViewActivity.kt b/app/src/main/java/org/lineageos/glimpse/ViewActivity.kt
index c0178a0..2b77017 100644
--- a/app/src/main/java/org/lineageos/glimpse/ViewActivity.kt
+++ b/app/src/main/java/org/lineageos/glimpse/ViewActivity.kt
@@ -14,15 +14,11 @@
 import android.provider.MediaStore
 import android.view.View
 import android.webkit.MimeTypeMap
-import android.widget.HorizontalScrollView
-import android.widget.ImageButton
 import android.widget.LinearLayout
-import android.widget.TextView
 import android.widget.Toast
 import androidx.activity.result.contract.ActivityResultContracts
 import androidx.activity.viewModels
 import androidx.appcompat.app.AppCompatActivity
-import androidx.constraintlayout.widget.ConstraintLayout
 import androidx.core.os.bundleOf
 import androidx.core.view.ViewCompat
 import androidx.core.view.WindowCompat
@@ -37,6 +33,8 @@
 import androidx.media3.common.Player
 import androidx.media3.exoplayer.ExoPlayer
 import androidx.viewpager2.widget.ViewPager2
+import com.google.android.material.appbar.AppBarLayout
+import com.google.android.material.appbar.MaterialToolbar
 import com.google.android.material.button.MaterialButton
 import kotlinx.coroutines.CoroutineScope
 import kotlinx.coroutines.Dispatchers
@@ -80,18 +78,15 @@
 
     // Views
     private val adjustButton by lazy { findViewById<MaterialButton>(R.id.adjustButton) }
-    private val backButton by lazy { findViewById<ImageButton>(R.id.backButton) }
+    private val appBarLayout by lazy { findViewById<AppBarLayout>(R.id.appBarLayout) }
     private val bottomSheetLinearLayout by lazy { findViewById<LinearLayout>(R.id.bottomSheetLinearLayout) }
-    private val bottomSheetHorizontalScrollView by lazy { findViewById<HorizontalScrollView>(R.id.bottomSheetHorizontalScrollView) }
     private val contentView by lazy { findViewById<View>(android.R.id.content) }
-    private val dateTextView by lazy { findViewById<TextView>(R.id.dateTextView) }
     private val deleteButton by lazy { findViewById<MaterialButton>(R.id.deleteButton) }
     private val favoriteButton by lazy { findViewById<MaterialButton>(R.id.favoriteButton) }
-    private val infoButton by lazy { findViewById<MaterialButton>(R.id.infoButton) }
+    private val infoButton by lazy { toolbar.menu.findItem(R.id.info) }
     private val shareButton by lazy { findViewById<MaterialButton>(R.id.shareButton) }
-    private val timeTextView by lazy { findViewById<TextView>(R.id.timeTextView) }
-    private val topSheetConstraintLayout by lazy { findViewById<ConstraintLayout>(R.id.topSheetConstraintLayout) }
-    private val useAsButton by lazy { findViewById<MaterialButton>(R.id.useAsButton) }
+    private val toolbar by lazy { findViewById<MaterialToolbar>(R.id.toolbar) }
+    private val useAsButton by lazy { toolbar.menu.findItem(R.id.useAs) }
     private val viewPager by lazy { findViewById<ViewPager2>(R.id.viewPager) }
 
     // System services
@@ -155,9 +150,9 @@
 
             MediaDialogsUtils.showDeleteForeverResultSnackbar(
                 this,
-                bottomSheetHorizontalScrollView,
+                bottomSheetLinearLayout,
                 succeeded, 1,
-                bottomSheetHorizontalScrollView,
+                bottomSheetLinearLayout,
             )
         }
 
@@ -167,9 +162,9 @@
 
             MediaDialogsUtils.showMoveToTrashResultSnackbar(
                 this,
-                bottomSheetHorizontalScrollView,
+                bottomSheetLinearLayout,
                 succeeded, 1,
-                bottomSheetHorizontalScrollView,
+                bottomSheetLinearLayout,
                 lastProcessedMedia?.let { trashedMedia ->
                     { trashMedia(trashedMedia, false) }
                 },
@@ -184,9 +179,9 @@
 
             MediaDialogsUtils.showRestoreFromTrashResultSnackbar(
                 this,
-                bottomSheetHorizontalScrollView,
+                bottomSheetLinearLayout,
                 succeeded, 1,
-                bottomSheetHorizontalScrollView,
+                bottomSheetLinearLayout,
                 lastProcessedMedia?.let { trashedMedia ->
                     { trashMedia(trashedMedia, true) }
                 },
@@ -267,8 +262,8 @@
 
         // Observe fullscreen mode
         uiModel.fullscreenModeLiveData.observe(this@ViewActivity) { fullscreenMode ->
-            topSheetConstraintLayout.fade(!fullscreenMode)
-            bottomSheetHorizontalScrollView.fade(!fullscreenMode)
+            appBarLayout.fade(!fullscreenMode)
+            bottomSheetLinearLayout.fade(!fullscreenMode)
 
             window.setBarsVisibility(systemBars = !fullscreenMode)
 
@@ -283,11 +278,12 @@
             val mediaStoreMedia = MediaStoreMedia::class.safeCast(displayedMedia)
 
             // Update date and time text
-            dateTextView.isVisible = mediaStoreMedia != null
-            timeTextView.isVisible = mediaStoreMedia != null
             mediaStoreMedia?.let {
-                dateTextView.text = dateFormatter.format(it.dateAdded)
-                timeTextView.text = timeFormatter.format(it.dateAdded)
+                toolbar.title = dateFormatter.format(it.dateAdded)
+                toolbar.subtitle = timeFormatter.format(it.dateAdded)
+            } ?: run {
+                toolbar.title = ""
+                toolbar.subtitle = ""
             }
 
             // Update favorite button
@@ -346,17 +342,10 @@
             // Once the system bars will be made visible again, this function
             // will be called again.
             if (uiModel.fullscreenModeLiveData.value != true) {
-                topSheetConstraintLayout.updatePadding(
-                    left = insets.left,
-                    right = insets.right,
-                    top = insets.top,
-                )
                 bottomSheetLinearLayout.updatePadding(
                     left = insets.left,
                     right = insets.right,
-                )
-                bottomSheetHorizontalScrollView.updatePadding(
-                    bottom = insets.bottom,
+                    bottom = insets.bottom
                 )
 
                 updateSheetsHeight()
@@ -365,7 +354,29 @@
             windowInsets
         }
 
-        backButton.setOnClickListener {
+        toolbar.setOnMenuItemClickListener { menuItem ->
+            when (menuItem.itemId) {
+                R.id.info -> {
+                    MediaStoreMedia::class.safeCast(uiModel.displayedMedia.value)?.let {
+                        MediaInfoBottomSheetDialog(
+                            this@ViewActivity, it, mediaInfoBottomSheetDialogCallbacks, secure
+                        ).show()
+                    }
+                    true
+                }
+
+                R.id.useAs -> {
+                    uiModel.displayedMedia.value?.let {
+                        startActivity(Intent.createChooser(buildUseAsIntent(it), null))
+                    }
+                    true
+                }
+
+                else -> false
+            }
+        }
+
+        toolbar.setNavigationOnClickListener {
             finish()
         }
 
@@ -390,25 +401,6 @@
             }
         }
 
-        useAsButton.setOnClickListener {
-            uiModel.displayedMedia.value?.let {
-                startActivity(
-                    Intent.createChooser(
-                        buildUseAsIntent(it),
-                        null
-                    )
-                )
-            }
-        }
-
-        infoButton.setOnClickListener {
-            MediaStoreMedia::class.safeCast(uiModel.displayedMedia.value)?.let {
-                MediaInfoBottomSheetDialog(
-                    this, it, mediaInfoBottomSheetDialogCallbacks, secure
-                ).show()
-            }
-        }
-
         adjustButton.setOnClickListener {
             uiModel.displayedMedia.value?.let {
                 startActivity(
@@ -530,14 +522,14 @@
     }
 
     private fun updateSheetsHeight() {
-        topSheetConstraintLayout.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED)
-        bottomSheetHorizontalScrollView.measure(
+        appBarLayout.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED)
+        bottomSheetLinearLayout.measure(
             View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED
         )
 
         uiModel.sheetsHeightLiveData.value = Pair(
-            topSheetConstraintLayout.measuredHeight,
-            bottomSheetHorizontalScrollView.measuredHeight,
+            appBarLayout.measuredHeight,
+            bottomSheetLinearLayout.measuredHeight,
         )
     }
 
diff --git a/app/src/main/res/drawable/bg_media_viewer_bottom_sheet.xml b/app/src/main/res/drawable/bg_media_viewer_bottom_sheet.xml
index 19a4eaa..c3ef816 100644
--- a/app/src/main/res/drawable/bg_media_viewer_bottom_sheet.xml
+++ b/app/src/main/res/drawable/bg_media_viewer_bottom_sheet.xml
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="utf-8"?>
 <!--
-     SPDX-FileCopyrightText: 2023 The LineageOS Project
+     SPDX-FileCopyrightText: 2023-2024 The LineageOS Project
      SPDX-License-Identifier: Apache-2.0
 -->
 <selector xmlns:android="http://schemas.android.com/apk/res/android">
@@ -8,7 +8,7 @@
         <shape>
             <gradient
                 android:angle="270"
-                android:endColor="@android:color/black"
+                android:endColor="#DD000000"
                 android:startColor="@android:color/transparent"
                 android:type="linear" />
         </shape>
diff --git a/app/src/main/res/drawable/bg_media_viewer_top_sheet.xml b/app/src/main/res/drawable/bg_media_viewer_top_sheet.xml
index 9c1799c..c4a5090 100644
--- a/app/src/main/res/drawable/bg_media_viewer_top_sheet.xml
+++ b/app/src/main/res/drawable/bg_media_viewer_top_sheet.xml
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="utf-8"?>
 <!--
-     SPDX-FileCopyrightText: 2023 The LineageOS Project
+     SPDX-FileCopyrightText: 2023-2024 The LineageOS Project
      SPDX-License-Identifier: Apache-2.0
 -->
 <selector xmlns:android="http://schemas.android.com/apk/res/android">
@@ -9,7 +9,7 @@
             <gradient
                 android:angle="270"
                 android:endColor="@android:color/transparent"
-                android:startColor="@android:color/black"
+                android:startColor="#DD000000"
                 android:type="linear" />
         </shape>
     </item>
diff --git a/app/src/main/res/layout/activity_view.xml b/app/src/main/res/layout/activity_view.xml
index f9ee1ac..3e02376 100644
--- a/app/src/main/res/layout/activity_view.xml
+++ b/app/src/main/res/layout/activity_view.xml
@@ -3,7 +3,7 @@
      SPDX-FileCopyrightText: 2023-2024 The LineageOS Project
      SPDX-License-Identifier: Apache-2.0
 -->
-<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
+<FrameLayout 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"
@@ -13,124 +13,76 @@
 
     <androidx.viewpager2.widget.ViewPager2
         android:id="@+id/viewPager"
-        android:layout_width="0dp"
-        android:layout_height="0dp"
-        app:layout_constraintBottom_toBottomOf="parent"
-        app:layout_constraintEnd_toEndOf="parent"
-        app:layout_constraintStart_toStartOf="parent"
-        app:layout_constraintTop_toTopOf="parent" />
+        android:layout_width="match_parent"
+        android:layout_height="match_parent" />
 
-    <androidx.constraintlayout.widget.ConstraintLayout
-        android:id="@+id/topSheetConstraintLayout"
-        android:layout_width="0dp"
+    <com.google.android.material.appbar.AppBarLayout
+        android:id="@+id/appBarLayout"
+        android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:background="@drawable/bg_media_viewer_top_sheet"
-        app:layout_constraintEnd_toEndOf="parent"
-        app:layout_constraintStart_toStartOf="parent"
-        app:layout_constraintTop_toTopOf="parent">
+        android:fitsSystemWindows="true">
 
-        <ImageButton
-            android:id="@+id/backButton"
-            style="@style/Theme.Glimpse.MediaViewer.TopSheet.Button"
-            android:layout_width="wrap_content"
+        <com.google.android.material.appbar.MaterialToolbar
+            android:id="@+id/toolbar"
+            android:layout_width="match_parent"
             android:layout_height="wrap_content"
-            android:layout_marginTop="12dp"
-            android:layout_marginBottom="12dp"
-            android:layout_marginStart="8dp"
-            android:src="@drawable/ic_back"
-            app:layout_constraintBottom_toBottomOf="parent"
-            app:layout_constraintStart_toStartOf="parent"
-            app:layout_constraintTop_toTopOf="parent" />
+            app:menu="@menu/activity_view_toolbar"
+            app:navigationIcon="@drawable/ic_back"
+            app:navigationIconTint="@android:color/white"
+            app:subtitleTextAppearance="?attr/textAppearanceTitleSmall"
+            app:subtitleTextColor="@android:color/white"
+            app:titleTextAppearance="?attr/textAppearanceTitleSmall"
+            app:titleTextColor="@android:color/white" />
 
-        <TextView
-            android:id="@+id/dateTextView"
-            style="@style/Theme.Glimpse.MediaViewer.DateTimeText"
-            android:layout_marginEnd="24dp"
-            android:layout_marginTop="16dp"
-            app:layout_constraintEnd_toEndOf="parent"
-            app:layout_constraintTop_toTopOf="parent" />
+    </com.google.android.material.appbar.AppBarLayout>
 
-        <TextView
-            android:id="@+id/timeTextView"
-            style="@style/Theme.Glimpse.MediaViewer.DateTimeText"
-            android:layout_marginBottom="16dp"
-            android:layout_marginEnd="24dp"
-            app:layout_constraintBottom_toBottomOf="parent"
-            app:layout_constraintEnd_toEndOf="parent"
-            app:layout_constraintTop_toBottomOf="@+id/dateTextView" />
-    </androidx.constraintlayout.widget.ConstraintLayout>
-
-    <HorizontalScrollView
-        android:id="@+id/bottomSheetHorizontalScrollView"
-        android:layout_width="0dp"
+    <LinearLayout
+        android:id="@+id/bottomSheetLinearLayout"
+        android:layout_width="match_parent"
         android:layout_height="wrap_content"
+        android:layout_gravity="bottom"
         android:background="@drawable/bg_media_viewer_bottom_sheet"
-        android:fillViewport="true"
-        app:layout_constraintBottom_toBottomOf="parent"
-        app:layout_constraintEnd_toEndOf="parent"
-        app:layout_constraintStart_toStartOf="parent">
+        android:gravity="top|center">
 
-        <LinearLayout
-            android:id="@+id/bottomSheetLinearLayout"
-            android:layout_width="0dp"
-            android:layout_height="wrap_content"
-            android:layout_marginVertical="8dp"
-            android:gravity="top|center">
+        <!-- Cannot mess with fixed padding from here because of insets -->
+        <Space
+            android:layout_width="16dp"
+            android:layout_height="match_parent" />
 
-            <!-- Cannot mess with fixed padding from here because of insets -->
-            <Space
-                android:layout_width="16dp"
-                android:layout_height="match_parent" />
+        <com.google.android.material.button.MaterialButton
+            android:id="@+id/favoriteButton"
+            style="@style/Theme.Glimpse.MediaViewer.BottomSheet.Button"
+            android:contentDescription="@string/file_action_add_to_favorites"
+            android:drawableTop="@drawable/ic_star_toggle"
+            android:text="@string/file_action_add_to_favorites" />
 
-            <com.google.android.material.button.MaterialButton
-                android:id="@+id/favoriteButton"
-                style="@style/Theme.Glimpse.MediaViewer.BottomSheet.Button"
-                android:contentDescription="@string/file_action_add_to_favorites"
-                android:drawableTop="@drawable/ic_star_toggle"
-                android:text="@string/file_action_add_to_favorites" />
+        <com.google.android.material.button.MaterialButton
+            android:id="@+id/shareButton"
+            style="@style/Theme.Glimpse.MediaViewer.BottomSheet.Button"
+            android:contentDescription="@string/file_action_share"
+            android:drawableTop="@drawable/ic_share"
+            android:text="@string/file_action_share" />
 
-            <com.google.android.material.button.MaterialButton
-                android:id="@+id/shareButton"
-                style="@style/Theme.Glimpse.MediaViewer.BottomSheet.Button"
-                android:contentDescription="@string/file_action_share"
-                android:drawableTop="@drawable/ic_share"
-                android:text="@string/file_action_share" />
+        <com.google.android.material.button.MaterialButton
+            android:id="@+id/adjustButton"
+            style="@style/Theme.Glimpse.MediaViewer.BottomSheet.Button"
+            android:contentDescription="@string/file_action_edit"
+            android:drawableTop="@drawable/ic_edit"
+            android:text="@string/file_action_edit" />
 
-            <com.google.android.material.button.MaterialButton
-                android:id="@+id/useAsButton"
-                style="@style/Theme.Glimpse.MediaViewer.BottomSheet.Button"
-                android:contentDescription="@string/file_action_use_as"
-                android:drawableTop="@drawable/ic_contact_page"
-                android:text="@string/file_action_use_as" />
+        <com.google.android.material.button.MaterialButton
+            android:id="@+id/deleteButton"
+            style="@style/Theme.Glimpse.MediaViewer.BottomSheet.Button"
+            android:contentDescription="@string/file_action_move_to_trash"
+            android:drawableTop="@drawable/ic_delete"
+            android:text="@string/file_action_move_to_trash" />
 
-            <com.google.android.material.button.MaterialButton
-                android:id="@+id/infoButton"
-                style="@style/Theme.Glimpse.MediaViewer.BottomSheet.Button"
-                android:contentDescription="@string/file_action_information"
-                android:drawableTop="@drawable/ic_info"
-                android:text="@string/file_action_information" />
+        <!-- Cannot mess with fixed padding from here because of insets -->
+        <Space
+            android:layout_width="16dp"
+            android:layout_height="match_parent" />
 
-            <com.google.android.material.button.MaterialButton
-                android:id="@+id/adjustButton"
-                style="@style/Theme.Glimpse.MediaViewer.BottomSheet.Button"
-                android:contentDescription="@string/file_action_edit"
-                android:drawableTop="@drawable/ic_edit"
-                android:text="@string/file_action_edit" />
+    </LinearLayout>
 
-            <com.google.android.material.button.MaterialButton
-                android:id="@+id/deleteButton"
-                style="@style/Theme.Glimpse.MediaViewer.BottomSheet.Button"
-                android:contentDescription="@string/file_action_move_to_trash"
-                android:drawableTop="@drawable/ic_delete"
-                android:text="@string/file_action_move_to_trash" />
-
-            <!-- Cannot mess with fixed padding from here because of insets -->
-            <Space
-                android:layout_width="16dp"
-                android:layout_height="match_parent" />
-
-        </LinearLayout>
-
-    </HorizontalScrollView>
-
-</androidx.constraintlayout.widget.ConstraintLayout>
+</FrameLayout>
diff --git a/app/src/main/res/menu/activity_view_toolbar.xml b/app/src/main/res/menu/activity_view_toolbar.xml
new file mode 100644
index 0000000..67dfbc9
--- /dev/null
+++ b/app/src/main/res/menu/activity_view_toolbar.xml
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+     SPDX-FileCopyrightText: 2024 The LineageOS Project
+     SPDX-License-Identifier: Apache-2.0
+-->
+<menu xmlns:android="http://schemas.android.com/apk/res/android">
+
+    <item
+        style="@style/Theme.Glimpse.TopAppBarOption"
+        android:id="@+id/useAs"
+        android:icon="@drawable/ic_contact_page"
+        android:title="@string/file_action_use_as"
+        android:contentDescription="@string/file_action_use_as" />
+
+    <item
+        style="@style/Theme.Glimpse.TopAppBarOption"
+        android:id="@+id/info"
+        android:icon="@drawable/ic_info"
+        android:title="@string/file_action_information"
+        android:contentDescription="@string/file_action_information" />
+
+</menu>
diff --git a/app/src/main/res/values/themes.xml b/app/src/main/res/values/themes.xml
index fd0b120..930a991 100644
--- a/app/src/main/res/values/themes.xml
+++ b/app/src/main/res/values/themes.xml
@@ -44,42 +44,21 @@
         <item name="android:windowLightStatusBar">?attr/isLightTheme</item>
     </style>
 
-    <!-- Media viewer top sheet -->
-    <style name="Theme.Glimpse.MediaViewer.TopSheet" />
-
-    <!-- Media viewer top sheet buttons -->
-    <style name="Theme.Glimpse.MediaViewer.TopSheet.Button">
-        <item name="android:layout_width">wrap_content</item>
-        <item name="android:layout_height">wrap_content</item>
-        <item name="android:background">?attr/selectableItemBackgroundBorderless</item>
-        <item name="android:padding">8dp</item>
-        <item name="tint">?attr/colorOnSurface</item>
-    </style>
-
-    <!-- Media viewer top sheet date/time text -->
-    <style name="Theme.Glimpse.MediaViewer.DateTimeText">
-        <item name="android:layout_width">wrap_content</item>
-        <item name="android:layout_height">wrap_content</item>
-        <item name="android:textAllCaps">true</item>
-        <item name="android:textColor">?attr/colorOnSurface</item>
-        <item name="android:textSize">11sp</item>
-        <item name="android:letterSpacing">0.05</item>
-        <item name="android:typeface">monospace</item>
-    </style>
-
     <!-- Media viewer bottom sheet -->
     <style name="Theme.Glimpse.MediaViewer.BottomSheet" />
 
     <!-- Media viewer bottom sheet buttons -->
     <style name="Theme.Glimpse.MediaViewer.BottomSheet.Button">
-        <item name="android:layout_width">96dp</item>
+        <item name="android:layout_width">0dp</item>
         <item name="android:layout_height">wrap_content</item>
-        <item name="android:drawableTint">?attr/colorOnSurface</item>
+        <item name="android:layout_weight">1</item>
+        <item name="android:drawableTint">@android:color/white</item>
         <item name="android:hyphenationFrequency">normal</item>
         <item name="android:maxLines">3</item>
+        <item name="android:maxWidth">320dp</item>
         <item name="android:padding">8dp</item>
         <item name="android:textAppearance">?attr/textAppearanceCaption</item>
-        <item name="android:textColor">?attr/colorOnSurface</item>
+        <item name="android:textColor">@android:color/white</item>
         <item name="backgroundTint">@android:color/transparent</item>
         <item name="rippleColor">?attr/colorControlHighlight</item>
     </style>