Skip to content

Commit 51ffa84

Browse files
Merge pull request #74 from CodandoTV/feature/20-mecanismo-de-favoritar
[ISSUE - 20] feat - Mecanismo de favoritar
2 parents 4767412 + b8a115e commit 51ffa84

File tree

27 files changed

+273
-17
lines changed

27 files changed

+273
-17
lines changed

app/build.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@ plugins {
66

77
dependencies {
88

9+
implementation(projects.featureFavorites)
910
implementation(projects.featureListStreams)
1011
implementation(projects.coreShared)
1112
implementation(projects.coreSharedUi)
1213
implementation(projects.coreNavigation)
1314
implementation(projects.coreNetworking)
15+
implementation(projects.coreLocalStorage)
1416

1517
implementation(platform(libs.compose.bom))
1618
androidTestImplementation(platform(libs.compose.bom))
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
package com.codandotv.streamplayerapp.di
22

33
import android.content.res.Resources
4+
import com.codandotv.streamplayerapp.core_local_storage.di.LocalStorageModule
45
import com.codandotv.streamplayerapp.core_networking.di.NetworkModule
56
import com.codandotv.streamplayerapp.core_shared.qualifier.QualifierDispatcherIO
67
import kotlinx.coroutines.Dispatchers
78
import org.koin.android.ext.koin.androidContext
8-
import org.koin.core.qualifier.named
99
import org.koin.dsl.module
1010

1111
object AppModule {
1212
private val module = module {
1313
single<Resources> { androidContext().resources }
1414
single(QualifierDispatcherIO) { Dispatchers.IO }
1515
}
16-
val list = module + NetworkModule.module
16+
val list = module + NetworkModule.module + LocalStorageModule.module
1717
}

build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ plugins {
55
alias(libs.plugins.android.application) apply false
66
alias(libs.plugins.android.library) apply false
77
alias(libs.plugins.kotlin.android) apply false
8+
alias(libs.plugins.ksp) apply false
89
}
910

1011
tasks.register("clean", Delete::class) {

core-local-storage/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
plugins {
2+
id("com.streamplayer.android-library")
3+
id("com.google.devtools.ksp")
4+
}
5+
6+
dependencies {
7+
8+
ksp(libs.roomCompiler)
9+
implementation(libs.bundles.room)
10+
implementation(libs.bundles.kotlin)
11+
implementation(libs.bundles.koin)
12+
testImplementation(libs.bundles.test)
13+
}

core-local-storage/consumer-rules.pro

Whitespace-only changes.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Add project specific ProGuard rules here.
2+
# You can control the set of applied configuration files using the
3+
# proguardFiles setting in build.gradle.
4+
#
5+
# For more details, see
6+
# http://developer.android.com/guide/developing/tools/proguard.html
7+
8+
# If your project uses WebView with JS, uncomment the following
9+
# and specify the fully qualified class name to the JavaScript interface
10+
# class:
11+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12+
# public *;
13+
#}
14+
15+
# Uncomment this to preserve the line number information for
16+
# debugging stack traces.
17+
#-keepattributes SourceFile,LineNumberTable
18+
19+
# If you keep the line number information, uncomment this to
20+
# hide the original source file name.
21+
#-renamesourcefileattribute SourceFile
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.codandotv.streamplayerapp.core_local_storage.data.dao
2+
3+
import androidx.room.Dao
4+
import androidx.room.Insert
5+
import androidx.room.OnConflictStrategy
6+
import androidx.room.Query
7+
import com.codandotv.streamplayerapp.core_local_storage.domain.model.MovieEntity
8+
9+
@Dao
10+
interface FavoriteDao {
11+
12+
@Query("SELECT * FROM movie")
13+
suspend fun fetchAll(): List<MovieEntity>
14+
15+
@Insert(onConflict = OnConflictStrategy.REPLACE)
16+
suspend fun insert(favoriteMovie: MovieEntity)
17+
18+
@Query("""DELETE FROM movie WHERE id = :favoriteMovie""")
19+
suspend fun delete(favoriteMovie: String)
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.codandotv.streamplayerapp.core_local_storage.data.database
2+
3+
import android.content.Context
4+
import androidx.room.Database
5+
import androidx.room.Room
6+
import androidx.room.RoomDatabase
7+
import com.codandotv.streamplayerapp.core_local_storage.data.dao.FavoriteDao
8+
import com.codandotv.streamplayerapp.core_local_storage.domain.model.MovieEntity
9+
10+
@Database(entities = [MovieEntity::class], version = 1)
11+
abstract class StreamPlayerAppDatabase : RoomDatabase() {
12+
13+
abstract fun favoriteDao(): FavoriteDao
14+
15+
companion object {
16+
17+
private var instance: StreamPlayerAppDatabase? = null
18+
19+
fun getInstance(context: Context): StreamPlayerAppDatabase {
20+
if (instance == null) {
21+
synchronized(this) {
22+
instance = Room.databaseBuilder(
23+
context.applicationContext,
24+
StreamPlayerAppDatabase::class.java,
25+
DATABASE_NAME
26+
).build()
27+
}
28+
}
29+
return instance!!
30+
}
31+
32+
const val DATABASE_NAME = "app-database.db"
33+
}
34+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.codandotv.streamplayerapp.core_local_storage.di
2+
3+
import androidx.room.Room
4+
import com.codandotv.streamplayerapp.core_local_storage.data.database.StreamPlayerAppDatabase
5+
import com.codandotv.streamplayerapp.core_local_storage.data.database.StreamPlayerAppDatabase.Companion.DATABASE_NAME
6+
import org.koin.android.ext.koin.androidContext
7+
import org.koin.dsl.module
8+
9+
object LocalStorageModule {
10+
val module = module {
11+
single { Room.databaseBuilder(androidContext(), StreamPlayerAppDatabase::class.java, DATABASE_NAME).build() }
12+
single { StreamPlayerAppDatabase.getInstance(get()) }
13+
single { get<StreamPlayerAppDatabase>().favoriteDao() }
14+
}
15+
}

0 commit comments

Comments
 (0)