Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Unverified Commit 22c11f98 authored by Sebastiano Barezzi's avatar Sebastiano Barezzi Committed by Luca Stefani
Browse files

Twelve: Rename local provider to MediaStore

It now deserves this name

Change-Id: I4b9bdfc6b5b83f86ae0cca3bbb6fab7c84902575
parent 480ecc72
Loading
Loading
Loading
Loading
+5 −5
Original line number Diff line number Diff line
@@ -21,7 +21,7 @@ import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.flow.mapLatest
import org.lineageos.twelve.R
import org.lineageos.twelve.database.TwelveDatabase
import org.lineageos.twelve.datasources.local.MediaStoreAudioUri
import org.lineageos.twelve.datasources.mediastore.MediaStoreAudioUri
import org.lineageos.twelve.ext.isRelativeTo
import org.lineageos.twelve.ext.mapEachRow
import org.lineageos.twelve.ext.queryFlow
@@ -64,13 +64,13 @@ import kotlin.random.Random
 * [MediaStore.Audio] backed data source.
 */
@OptIn(ExperimentalCoroutinesApi::class)
class LocalDataSource(
class MediaStoreDataSource(
    private val contentResolver: ContentResolver,
    coroutineScope: CoroutineScope,
    providersRepository: ProvidersRepository,
    private val database: TwelveDatabase,
) : MediaDataSource {
    private inner class LocalInstance(
    private inner class MediaStoreInstance(
        private val volumeName: String,
    ) : ProvidersManager.Instance {
        val albumsUri by lazy { getAlbumsUri(volumeName) }
@@ -138,11 +138,11 @@ class LocalDataSource(
    private val providersManager = ProvidersManager(
        coroutineScope,
        providersRepository,
        ProviderType.LOCAL,
        ProviderType.MEDIASTORE,
    ) { _, arguments ->
        val volumeName = arguments.requireArgument(ARG_VOLUME_NAME)

        LocalInstance(volumeName)
        MediaStoreInstance(volumeName)
    }

    override fun status(providerIdentifier: ProviderIdentifier) = flowOf(
+1 −1
Original line number Diff line number Diff line
@@ -3,7 +3,7 @@
 * SPDX-License-Identifier: Apache-2.0
 */

package org.lineageos.twelve.datasources.local
package org.lineageos.twelve.datasources.mediastore

import android.content.ContentResolver
import android.net.Uri
+2 −2
Original line number Diff line number Diff line
@@ -29,9 +29,9 @@ enum class ProviderType(
    val canBeManaged: Boolean,
) {
    /**
     * Local provider.
     * MediaStore provider.
     */
    LOCAL(
    MEDIASTORE(
        R.string.provider_type_local,
        R.drawable.ic_smartphone,
        listOf(),
+6 −6
Original line number Diff line number Diff line
@@ -27,8 +27,8 @@ import kotlinx.coroutines.launch
import okhttp3.Cache
import org.lineageos.twelve.database.TwelveDatabase
import org.lineageos.twelve.datasources.JellyfinDataSource
import org.lineageos.twelve.datasources.LocalDataSource
import org.lineageos.twelve.datasources.MediaDataSource
import org.lineageos.twelve.datasources.MediaStoreDataSource
import org.lineageos.twelve.datasources.SubsonicDataSource
import org.lineageos.twelve.ext.DEFAULT_PROVIDER_KEY
import org.lineageos.twelve.ext.defaultProvider
@@ -67,9 +67,9 @@ class MediaRepository(
    private val cache = Cache(context.cacheDir, 50 * 1024 * 1024)

    /**
     * Local data source.
     * MediaStore data source.
     */
    private val localDataSource = LocalDataSource(
    private val mediaStoreDataSource = MediaStoreDataSource(
        context.contentResolver,
        scope,
        providersRepository,
@@ -99,7 +99,7 @@ class MediaRepository(

    private val allDataSources = MutableStateFlow(
        listOf(
            localDataSource,
            mediaStoreDataSource,
            subsonicDataSource,
            jellyfinDataSource,
        )
@@ -338,7 +338,7 @@ class MediaRepository(
    private fun getDataSource(
        providerIdentifier: ProviderIdentifier,
    ) = when (providerIdentifier.type) {
        ProviderType.LOCAL -> localDataSource
        ProviderType.MEDIASTORE -> mediaStoreDataSource
        ProviderType.SUBSONIC -> subsonicDataSource
        ProviderType.JELLYFIN -> jellyfinDataSource
    }
@@ -424,7 +424,7 @@ class MediaRepository(
    private suspend fun gcLocalMediaStats() {
        val statsDao = database.getLocalMediaStatsProviderDao()
        val allStats = statsDao.getAll()
        val inSource = localDataSource.audios().mapLatest { it }.first()
        val inSource = mediaStoreDataSource.audios().mapLatest { it }.first()

        val removedMedia = allStats.mapNotNull {
            val notPresent = inSource.none { audio ->
+11 −11
Original line number Diff line number Diff line
@@ -25,7 +25,7 @@ import kotlinx.coroutines.flow.mapLatest
import kotlinx.coroutines.flow.shareIn
import org.lineageos.twelve.database.TwelveDatabase
import org.lineageos.twelve.datasources.JellyfinDataSource
import org.lineageos.twelve.datasources.LocalDataSource
import org.lineageos.twelve.datasources.MediaStoreDataSource
import org.lineageos.twelve.datasources.SubsonicDataSource
import org.lineageos.twelve.ext.SPLIT_LOCAL_DEVICES_KEY
import org.lineageos.twelve.ext.preferenceFlow
@@ -47,7 +47,7 @@ class ProvidersRepository(
     */
    private val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context)

    // Local
    // MediaStore
    private val storageManager = context.getSystemService(StorageManager::class.java)

    private val mediaStoreVolumes = storageManager.storageVolumesFlow()
@@ -59,7 +59,7 @@ class ProvidersRepository(
        }
        .distinctUntilChanged()

    private val localProviders = combine(
    private val mediaStoreProviders = combine(
        sharedPreferences.preferenceFlow(
            SPLIT_LOCAL_DEVICES_KEY,
            getter = SharedPreferences::splitLocalDevices,
@@ -71,22 +71,22 @@ class ProvidersRepository(
                true -> mediaStoreVolumes.forEach {
                    add(
                        Provider(
                            ProviderType.LOCAL,
                            ProviderType.MEDIASTORE,
                            it.mediaStoreVolumeName.hashCode().toLong(),
                            it.getDescription(context),
                        ) to bundleOf(
                            LocalDataSource.ARG_VOLUME_NAME.key to it.mediaStoreVolumeName,
                            MediaStoreDataSource.ARG_VOLUME_NAME.key to it.mediaStoreVolumeName,
                        )
                    )
                }

                false -> add(
                    Provider(
                        ProviderType.LOCAL,
                        ProviderType.MEDIASTORE,
                        0L,
                        Build.MODEL,
                    ) to bundleOf(
                        LocalDataSource.ARG_VOLUME_NAME.key to MediaStore.VOLUME_EXTERNAL,
                        MediaStoreDataSource.ARG_VOLUME_NAME.key to MediaStore.VOLUME_EXTERNAL,
                    )
                )
            }
@@ -129,7 +129,7 @@ class ProvidersRepository(

    // All providers
    val allProvidersToArguments = combine(
        localProviders,
        mediaStoreProviders,
        subsonicProviders,
        jellyfinProviders,
    ) { it ->
@@ -190,7 +190,7 @@ class ProvidersRepository(
    suspend fun addProvider(
        providerType: ProviderType, name: String, arguments: Bundle
    ) = when (providerType) {
        ProviderType.LOCAL -> throw Exception("Cannot create local providers")
        ProviderType.MEDIASTORE -> throw Exception("Cannot create MediaStore providers")

        ProviderType.SUBSONIC -> {
            val server = arguments.requireArgument(SubsonicDataSource.ARG_SERVER)
@@ -233,7 +233,7 @@ class ProvidersRepository(
        arguments: Bundle
    ) {
        when (providerIdentifier.type) {
            ProviderType.LOCAL -> throw Exception("Cannot update local providers")
            ProviderType.MEDIASTORE -> throw Exception("Cannot update MediaStore providers")

            ProviderType.SUBSONIC -> {
                val server = arguments.requireArgument(SubsonicDataSource.ARG_SERVER)
@@ -276,7 +276,7 @@ class ProvidersRepository(
     */
    suspend fun deleteProvider(providerIdentifier: ProviderIdentifier) {
        when (providerIdentifier.type) {
            ProviderType.LOCAL -> throw Exception("Cannot delete local providers")
            ProviderType.MEDIASTORE -> throw Exception("Cannot delete MediaStore providers")

            ProviderType.SUBSONIC -> database.getSubsonicProviderDao().delete(
                providerIdentifier.typeId