Skip to content

Commit

Permalink
Added repository functions to access database
Browse files Browse the repository at this point in the history
  • Loading branch information
judahben149 committed Sep 9, 2023
1 parent f92337d commit 1f90b84
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,34 @@ package com.judahben149.serenade.data.repository
import android.content.Context
import android.graphics.Bitmap
import android.net.Uri
import com.judahben149.serenade.data.sources.local.SerenadeDatabase
import com.judahben149.serenade.data.sources.local.entity.TrackEntity
import com.judahben149.serenade.domain.TrackRepository
import com.judahben149.serenade.utils.MusicContentHelper
import com.judahben149.serenade.utils.resourceUtils.MusicContentHelper
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.withContext
import javax.inject.Inject


class TrackRepositoryImpl @Inject constructor(
private val context: Context,
private val musicContentHelper: MusicContentHelper
): TrackRepository {
private val database: SerenadeDatabase,
private val musicContentHelper: MusicContentHelper,
) : TrackRepository {

override suspend fun loadCoverBitmap(uri: Uri): Bitmap? {
return withContext(Dispatchers.IO) {
musicContentHelper.getAlbumArt(context, uri)
}
}

override suspend fun saveTracks(trackEntity: TrackEntity) {
database.trackDao().saveTracks(trackEntity)
}

override suspend fun getAllTracks(): Flow<List<TrackEntity>> {
return database.trackDao().getAllTracks()
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
package com.judahben149.serenade.domain

import android.content.Context
import android.graphics.Bitmap
import android.net.Uri
import com.judahben149.serenade.data.sources.local.entity.TrackEntity
import kotlinx.coroutines.flow.Flow

interface TrackRepository {

suspend fun loadCoverBitmap(uri: Uri): Bitmap?

suspend fun saveTracks(trackEntity: TrackEntity)

suspend fun getAllTracks(): Flow<List<TrackEntity>>
}

0 comments on commit 1f90b84

Please sign in to comment.