Glimpse: Use DisplayAwareGridLayoutManager for album thumbnails
Change-Id: I252d2d52f947b1bba35c20c9385e05eaf87f70d9
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 f234706..cd36644 100644
--- a/app/src/main/java/org/lineageos/glimpse/fragments/AlbumsFragment.kt
+++ b/app/src/main/java/org/lineageos/glimpse/fragments/AlbumsFragment.kt
@@ -5,6 +5,7 @@
package org.lineageos.glimpse.fragments
+import android.content.res.Configuration
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
@@ -21,7 +22,6 @@
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle
import androidx.navigation.fragment.findNavController
-import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.google.android.material.appbar.AppBarLayout
import com.google.android.material.appbar.MaterialToolbar
@@ -29,8 +29,9 @@
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.launch
import org.lineageos.glimpse.R
-import org.lineageos.glimpse.ext.getViewProperty
+import org.lineageos.glimpse.ext.*
import org.lineageos.glimpse.recyclerview.AlbumThumbnailAdapter
+import org.lineageos.glimpse.recyclerview.AlbumThumbnailLayoutManager
import org.lineageos.glimpse.utils.PermissionsGatedCallback
import org.lineageos.glimpse.viewmodels.MediaViewModel
@@ -79,7 +80,7 @@
appBarLayout.statusBarForeground = MaterialShapeDrawable.createWithElevationOverlay(context)
- albumsRecyclerView.layoutManager = GridLayoutManager(context, 2)
+ albumsRecyclerView.layoutManager = AlbumThumbnailLayoutManager(context)
albumsRecyclerView.adapter = albumThumbnailAdapter
ViewCompat.setOnApplyWindowInsetsListener(view) { _, windowInsets ->
@@ -97,6 +98,12 @@
permissionsGatedCallback.runAfterPermissionsCheck()
}
+ override fun onConfigurationChanged(newConfig: Configuration) {
+ super.onConfigurationChanged(newConfig)
+
+ albumsRecyclerView.layoutManager = AlbumThumbnailLayoutManager(requireContext())
+ }
+
companion object {
private fun createBundle() = bundleOf()
diff --git a/app/src/main/java/org/lineageos/glimpse/recyclerview/AlbumThumbnailLayoutManager.kt b/app/src/main/java/org/lineageos/glimpse/recyclerview/AlbumThumbnailLayoutManager.kt
new file mode 100644
index 0000000..eac1e9a
--- /dev/null
+++ b/app/src/main/java/org/lineageos/glimpse/recyclerview/AlbumThumbnailLayoutManager.kt
@@ -0,0 +1,13 @@
+/*
+ * SPDX-FileCopyrightText: 2023 The LineageOS Project
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+package org.lineageos.glimpse.recyclerview
+
+import android.content.Context
+import org.lineageos.glimpse.ext.px
+
+class AlbumThumbnailLayoutManager(
+ context: Context,
+) : DisplayAwareGridLayoutManager(context, 2, 24.px)