Skip to content

Commit

Permalink
music: dont inject contentresolver
Browse files Browse the repository at this point in the history
I don't know why, but I can't inject it without causing errors.
  • Loading branch information
OxygenCobalt committed Dec 20, 2023
1 parent e553744 commit 2195431
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@

package org.oxycblt.auxio.music.external

import android.content.ContentResolver
import android.content.Context
import android.net.Uri
import dagger.hilt.android.qualifiers.ApplicationContext
import javax.inject.Inject
import org.oxycblt.auxio.music.fs.ContentPathResolver
import org.oxycblt.auxio.music.fs.Path
import org.oxycblt.auxio.music.fs.contentResolverSafe

interface PlaylistImporter {
suspend fun import(uri: Uri): ImportedPlaylist?
Expand All @@ -34,13 +35,13 @@ data class ImportedPlaylist(val name: String?, val paths: List<Path>)
class PlaylistImporterImpl
@Inject
constructor(
@ApplicationContext private val contentResolver: ContentResolver,
@ApplicationContext private val context: Context,
private val contentPathResolver: ContentPathResolver,
private val m3u: M3U
) : PlaylistImporter {
override suspend fun import(uri: Uri): ImportedPlaylist? {
val workingDirectory = contentPathResolver.resolve(uri) ?: return null
return contentResolver.openInputStream(uri)?.use {
return context.contentResolverSafe.openInputStream(uri)?.use {
val paths = m3u.read(it, workingDirectory) ?: return null
return ImportedPlaylist(null, paths)
}
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/java/org/oxycblt/auxio/music/fs/FsModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

package org.oxycblt.auxio.music.fs

import android.content.ContentResolver
import android.content.Context
import android.os.storage.StorageManager
import dagger.Module
Expand All @@ -41,4 +42,8 @@ class FsModule {
@Provides
fun contentPathResolver(@ApplicationContext context: Context, volumeManager: VolumeManager) =
ContentPathResolver.from(context, volumeManager)

@Provides
fun contentResolver(@ApplicationContext context: Context): ContentResolver =
context.contentResolverSafe
}

0 comments on commit 2195431

Please sign in to comment.