Glimpse: Implement "Favorites" album
Change-Id: Ia8fc129f6dfab06ce96fea39d0e3b526e300391c
This commit is contained in:
parent
f6b8998442
commit
71b46b0dad
|
@ -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(),
|
||||
|
|
|
@ -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<Cursor> {
|
|||
}
|
||||
|
||||
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<Cursor> {
|
|||
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()
|
||||
|
|
|
@ -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"
|
||||
)
|
||||
}
|
||||
|
|
|
@ -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),
|
||||
}
|
|
@ -15,6 +15,9 @@
|
|||
<string name="albums_title">Albums</string>
|
||||
<string name="search_title">Search</string>
|
||||
|
||||
<!-- Album favorites -->
|
||||
<string name="album_favorites">Favorites</string>
|
||||
|
||||
<!-- Album thumbnail -->
|
||||
<plurals name="album_thumbnail_items">
|
||||
<item quantity="one">%d item</item>
|
||||
|
|
Loading…
Reference in New Issue