all: reformat
This commit is contained in:
parent
7906867a96
commit
216d9802ef
5 changed files with 48 additions and 27 deletions
|
@ -26,18 +26,15 @@ import android.database.Cursor
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.os.ParcelFileDescriptor
|
import android.os.ParcelFileDescriptor
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
|
import javax.inject.Inject
|
||||||
import kotlinx.coroutines.runBlocking
|
import kotlinx.coroutines.runBlocking
|
||||||
import org.oxycblt.auxio.BuildConfig
|
import org.oxycblt.auxio.BuildConfig
|
||||||
import org.oxycblt.auxio.image.covers.SettingCovers
|
import org.oxycblt.auxio.image.covers.SettingCovers
|
||||||
import org.oxycblt.auxio.image.covers.SiloedCoverId
|
|
||||||
import org.oxycblt.auxio.image.covers.SiloedCovers
|
|
||||||
import org.oxycblt.musikr.cover.CoverResult
|
import org.oxycblt.musikr.cover.CoverResult
|
||||||
import javax.inject.Inject
|
|
||||||
|
|
||||||
@AndroidEntryPoint
|
@AndroidEntryPoint
|
||||||
class CoverProvider @Inject constructor(
|
class CoverProvider @Inject constructor(private val settingCovers: SettingCovers) :
|
||||||
private val settingCovers: SettingCovers
|
ContentProvider() {
|
||||||
) : ContentProvider() {
|
|
||||||
override fun onCreate(): Boolean = true
|
override fun onCreate(): Boolean = true
|
||||||
|
|
||||||
override fun openFile(uri: Uri, mode: String): ParcelFileDescriptor? {
|
override fun openFile(uri: Uri, mode: String): ParcelFileDescriptor? {
|
||||||
|
|
|
@ -1,5 +1,22 @@
|
||||||
package org.oxycblt.auxio.image.covers
|
/*
|
||||||
|
* Copyright (c) 2025 Auxio Project
|
||||||
|
* CompatCovers.kt is part of Auxio.
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.oxycblt.auxio.image.covers
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
|
@ -16,7 +33,8 @@ import org.oxycblt.musikr.cover.MutableCovers
|
||||||
import org.oxycblt.musikr.fs.DeviceFile
|
import org.oxycblt.musikr.fs.DeviceFile
|
||||||
import org.oxycblt.musikr.metadata.Metadata
|
import org.oxycblt.musikr.metadata.Metadata
|
||||||
|
|
||||||
open class CompatCovers(private val context: Context, private val inner: Covers<FileCover>) : Covers<FileCover> {
|
open class CompatCovers(private val context: Context, private val inner: Covers<FileCover>) :
|
||||||
|
Covers<FileCover> {
|
||||||
override suspend fun obtain(id: String): CoverResult<FileCover> {
|
override suspend fun obtain(id: String): CoverResult<FileCover> {
|
||||||
when (val innerResult = inner.obtain(id)) {
|
when (val innerResult = inner.obtain(id)) {
|
||||||
is CoverResult.Hit -> return CoverResult.Hit(innerResult.cover)
|
is CoverResult.Hit -> return CoverResult.Hit(innerResult.cover)
|
||||||
|
@ -29,7 +47,10 @@ open class CompatCovers(private val context: Context, private val inner: Covers<
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class MutableCompatCovers(private val context: Context, private val inner: MutableCovers<FileCover>) : CompatCovers(context, inner), MutableCovers<FileCover> {
|
class MutableCompatCovers(
|
||||||
|
private val context: Context,
|
||||||
|
private val inner: MutableCovers<FileCover>
|
||||||
|
) : CompatCovers(context, inner), MutableCovers<FileCover> {
|
||||||
override suspend fun create(file: DeviceFile, metadata: Metadata): CoverResult<FileCover> {
|
override suspend fun create(file: DeviceFile, metadata: Metadata): CoverResult<FileCover> {
|
||||||
when (val innerResult = inner.create(file, metadata)) {
|
when (val innerResult = inner.create(file, metadata)) {
|
||||||
is CoverResult.Hit -> return CoverResult.Hit(innerResult.cover)
|
is CoverResult.Hit -> return CoverResult.Hit(innerResult.cover)
|
||||||
|
@ -37,20 +58,22 @@ class MutableCompatCovers(private val context: Context, private val inner: Mutab
|
||||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) {
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) {
|
||||||
return CoverResult.Miss()
|
return CoverResult.Miss()
|
||||||
}
|
}
|
||||||
val mediaStoreUri = MediaStore.getMediaUri(context, file.uri) ?: return CoverResult.Miss()
|
val mediaStoreUri =
|
||||||
|
MediaStore.getMediaUri(context, file.uri) ?: return CoverResult.Miss()
|
||||||
val proj = arrayOf(MediaStore.MediaColumns._ID)
|
val proj = arrayOf(MediaStore.MediaColumns._ID)
|
||||||
val cursor = context.contentResolver.query(mediaStoreUri, proj, null, null, null)
|
val cursor = context.contentResolver.query(mediaStoreUri, proj, null, null, null)
|
||||||
val uri = cursor.use {
|
val uri =
|
||||||
if (it == null || !it.moveToFirst()) {
|
cursor.use {
|
||||||
return CoverResult.Miss()
|
if (it == null || !it.moveToFirst()) {
|
||||||
|
return CoverResult.Miss()
|
||||||
|
}
|
||||||
|
val id = it.getLong(it.getColumnIndexOrThrow(MediaStore.MediaColumns._ID))
|
||||||
|
MediaStore.Audio.Media.EXTERNAL_CONTENT_URI.buildUpon().run {
|
||||||
|
appendPath(id.toString())
|
||||||
|
appendPath("albumart")
|
||||||
|
build()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
val id = it.getLong(it.getColumnIndexOrThrow(MediaStore.MediaColumns._ID))
|
|
||||||
MediaStore.Audio.Media.EXTERNAL_CONTENT_URI.buildUpon().run {
|
|
||||||
appendPath(id.toString())
|
|
||||||
appendPath("albumart")
|
|
||||||
build()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return CoverResult.Hit(CompatCover(context, uri))
|
return CoverResult.Hit(CompatCover(context, uri))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -66,7 +89,6 @@ class CompatCover(private val context: Context, private val uri: Uri) : FileCove
|
||||||
return context.contentResolver.openFileDescriptor(uri, "r")
|
return context.contentResolver.openFileDescriptor(uri, "r")
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun open() = withContext(Dispatchers.IO) {
|
override suspend fun open() =
|
||||||
context.contentResolver.openInputStream(uri)
|
withContext(Dispatchers.IO) { context.contentResolver.openInputStream(uri) }
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -19,7 +19,6 @@
|
||||||
package org.oxycblt.auxio.image.covers
|
package org.oxycblt.auxio.image.covers
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import org.apache.commons.lang3.ObjectUtils.Null
|
|
||||||
import org.oxycblt.musikr.cover.Cover
|
import org.oxycblt.musikr.cover.Cover
|
||||||
import org.oxycblt.musikr.cover.CoverResult
|
import org.oxycblt.musikr.cover.CoverResult
|
||||||
import org.oxycblt.musikr.cover.MutableCovers
|
import org.oxycblt.musikr.cover.MutableCovers
|
||||||
|
|
|
@ -32,6 +32,7 @@ import org.oxycblt.musikr.cover.MutableCovers
|
||||||
|
|
||||||
interface SettingCovers {
|
interface SettingCovers {
|
||||||
suspend fun obtain(context: Context, id: String): CoverResult<FileCover>
|
suspend fun obtain(context: Context, id: String): CoverResult<FileCover>
|
||||||
|
|
||||||
suspend fun mutate(context: Context, revision: UUID): MutableCovers<out Cover>
|
suspend fun mutate(context: Context, revision: UUID): MutableCovers<out Cover>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,5 +56,6 @@ constructor(private val imageSettings: ImageSettings, private val identifier: Co
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun siloedCovers(context: Context, revision: UUID, with: CoverParams) =
|
private suspend fun siloedCovers(context: Context, revision: UUID, with: CoverParams) =
|
||||||
MutableCompatCovers(context, MutableSiloedCovers.from(context, CoverSilo(revision, with), identifier))
|
MutableCompatCovers(
|
||||||
|
context, MutableSiloedCovers.from(context, CoverSilo(revision, with), identifier))
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,7 +35,8 @@ import org.oxycblt.musikr.fs.DeviceFile
|
||||||
import org.oxycblt.musikr.fs.app.AppFiles
|
import org.oxycblt.musikr.fs.app.AppFiles
|
||||||
import org.oxycblt.musikr.metadata.Metadata
|
import org.oxycblt.musikr.metadata.Metadata
|
||||||
|
|
||||||
open class SiloedCovers(private val silo: CoverSilo, private val fileCovers: FileCovers) : Covers<FileCover> {
|
open class SiloedCovers(private val silo: CoverSilo, private val fileCovers: FileCovers) :
|
||||||
|
Covers<FileCover> {
|
||||||
override suspend fun obtain(id: String): CoverResult<FileCover> {
|
override suspend fun obtain(id: String): CoverResult<FileCover> {
|
||||||
val coverId = SiloedCoverId.parse(id) ?: return CoverResult.Miss()
|
val coverId = SiloedCoverId.parse(id) ?: return CoverResult.Miss()
|
||||||
if (coverId.silo != silo) return CoverResult.Miss()
|
if (coverId.silo != silo) return CoverResult.Miss()
|
||||||
|
|
Loading…
Reference in a new issue