diff --git a/app/src/main/java/org/lineageos/glimpse/fragments/AlbumFragment.kt b/app/src/main/java/org/lineageos/glimpse/fragments/AlbumFragment.kt index 2fb8eab..2d14cf2 100644 --- a/app/src/main/java/org/lineageos/glimpse/fragments/AlbumFragment.kt +++ b/app/src/main/java/org/lineageos/glimpse/fragments/AlbumFragment.kt @@ -35,6 +35,7 @@ import org.lineageos.glimpse.ext.getViewProperty import org.lineageos.glimpse.models.Album import org.lineageos.glimpse.thumbnail.ThumbnailAdapter import org.lineageos.glimpse.thumbnail.ThumbnailLayoutManager +import org.lineageos.glimpse.utils.MediaStoreBuckets import org.lineageos.glimpse.utils.MediaStoreRequests import org.lineageos.glimpse.utils.PermissionsUtils @@ -148,9 +149,14 @@ class AlbumFragment : Fragment(R.layout.fragment_album), LoaderManager.LoaderCal }) append(")") append(" AND ") - append(MediaStore.Files.FileColumns.BUCKET_ID) - append(" = ") - append(album.id) + if (album.id == MediaStoreBuckets.MEDIA_STORE_BUCKET_FAVORITES.id) { + append(MediaStore.Files.FileColumns.IS_FAVORITE) + append(" = 1") + } else { + append(MediaStore.Files.FileColumns.BUCKET_ID) + append(" = ") + append(album.id) + } } CursorLoader( requireContext(), 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 070c6e7..accb2c5 100644 --- a/app/src/main/java/org/lineageos/glimpse/fragments/AlbumsFragment.kt +++ b/app/src/main/java/org/lineageos/glimpse/fragments/AlbumsFragment.kt @@ -30,6 +30,7 @@ import org.lineageos.glimpse.R import org.lineageos.glimpse.ext.getViewProperty import org.lineageos.glimpse.models.Album import org.lineageos.glimpse.thumbnail.AlbumThumbnailAdapter +import org.lineageos.glimpse.utils.MediaStoreBuckets import org.lineageos.glimpse.utils.MediaStoreRequests /** @@ -128,6 +129,7 @@ class AlbumsFragment : Fragment(), LoaderManager.LoaderCallbacks { } val idIndex = cursor.getColumnIndex(MediaStore.Files.FileColumns._ID) + val isFavoriteIndex = cursor.getColumnIndex(MediaStore.Files.FileColumns.IS_FAVORITE) val mediaTypeIndex = cursor.getColumnIndex(MediaStore.Files.FileColumns.MEDIA_TYPE) val bucketIdIndex = cursor.getColumnIndex(MediaStore.Files.FileColumns.BUCKET_ID) val bucketDisplayNameIndex = @@ -146,16 +148,27 @@ class AlbumsFragment : Fragment(), LoaderManager.LoaderCallbacks { else -> return@let } - val bucketId = cursor.getInt(bucketIdIndex) + val bucketIds = listOfNotNull( + cursor.getInt(bucketIdIndex), + MediaStoreBuckets.MEDIA_STORE_BUCKET_FAVORITES.id.takeIf { + cursor.getInt(isFavoriteIndex) == 1 + } + ) - albums[bucketId]?.also { - it.size += 1 - } ?: run { - albums[bucketId] = Album( - bucketId, - cursor.getString(bucketDisplayNameIndex) ?: Build.MODEL, - ContentUris.withAppendedId(contentUri, cursor.getLong(idIndex)), - ).apply { size += 1 } + for (bucketId in bucketIds) { + albums[bucketId]?.also { + it.size += 1 + } ?: run { + albums[bucketId] = Album( + bucketId, + if (bucketId == MediaStoreBuckets.MEDIA_STORE_BUCKET_FAVORITES.id) { + getString(R.string.album_favorites) + } else { + cursor.getString(bucketDisplayNameIndex) ?: Build.MODEL + }, + ContentUris.withAppendedId(contentUri, cursor.getLong(idIndex)), + ).apply { size += 1 } + } } cursor.moveToNext() diff --git a/app/src/main/java/org/lineageos/glimpse/fragments/MediaViewerFragment.kt b/app/src/main/java/org/lineageos/glimpse/fragments/MediaViewerFragment.kt index 2c31de8..33f57c8 100644 --- a/app/src/main/java/org/lineageos/glimpse/fragments/MediaViewerFragment.kt +++ b/app/src/main/java/org/lineageos/glimpse/fragments/MediaViewerFragment.kt @@ -41,6 +41,7 @@ import org.lineageos.glimpse.models.Album import org.lineageos.glimpse.models.Media import org.lineageos.glimpse.models.MediaType import org.lineageos.glimpse.thumbnail.MediaViewerAdapter +import org.lineageos.glimpse.utils.MediaStoreBuckets import org.lineageos.glimpse.utils.MediaStoreRequests import org.lineageos.glimpse.utils.PermissionsUtils import java.text.SimpleDateFormat @@ -276,9 +277,15 @@ class MediaViewerFragment : Fragment( album?.let { append( buildString { - append(" AND ") - append(MediaStore.Files.FileColumns.BUCKET_ID) - append(" = ?") + if (it.id == MediaStoreBuckets.MEDIA_STORE_BUCKET_FAVORITES.id) { + append(" AND ") + append(MediaStore.Files.FileColumns.IS_FAVORITE) + append(" = 1") + } else { + append(" AND ") + append(MediaStore.Files.FileColumns.BUCKET_ID) + append(" = ?") + } } ) } @@ -288,7 +295,9 @@ class MediaViewerFragment : Fragment( MediaStore.Files.getContentUri("external"), projection, selection, - album?.let { arrayOf(it.id.toString()) }, + album?.takeIf { + it.id != MediaStoreBuckets.MEDIA_STORE_BUCKET_FAVORITES.id + }?.let { arrayOf(it.id.toString()) }, MediaStore.Files.FileColumns.DATE_ADDED + " DESC" ) } diff --git a/app/src/main/java/org/lineageos/glimpse/utils/MediaStoreBuckets.kt b/app/src/main/java/org/lineageos/glimpse/utils/MediaStoreBuckets.kt new file mode 100644 index 0000000..6dea0d9 --- /dev/null +++ b/app/src/main/java/org/lineageos/glimpse/utils/MediaStoreBuckets.kt @@ -0,0 +1,10 @@ +/* + * SPDX-FileCopyrightText: 2023 The LineageOS Project + * SPDX-License-Identifier: Apache-2.0 + */ + +package org.lineageos.glimpse.utils + +enum class MediaStoreBuckets(val id: Int) { + MEDIA_STORE_BUCKET_FAVORITES(-0x0001DEAD), +} diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 52c90b4..8623714 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -15,6 +15,9 @@ Albums Search + + Favorites + %d item