diff --git a/examples/llama.android/app/src/main/java/com/example/llama/revamp/data/local/AppDatabase.kt b/examples/llama.android/app/src/main/java/com/example/llama/revamp/data/local/AppDatabase.kt index 39e887ab38..711db848ee 100644 --- a/examples/llama.android/app/src/main/java/com/example/llama/revamp/data/local/AppDatabase.kt +++ b/examples/llama.android/app/src/main/java/com/example/llama/revamp/data/local/AppDatabase.kt @@ -4,10 +4,12 @@ import android.content.Context import androidx.room.Database import androidx.room.Room import androidx.room.RoomDatabase +import javax.inject.Singleton /** * Main database for the application. */ +@Singleton @Database(entities = [SystemPromptEntity::class], version = 1, exportSchema = false) abstract class AppDatabase : RoomDatabase() { diff --git a/examples/llama.android/app/src/main/java/com/example/llama/revamp/data/preferences/UserPreferences.kt b/examples/llama.android/app/src/main/java/com/example/llama/revamp/data/preferences/UserPreferences.kt index 2b034de459..fc4eeed65c 100644 --- a/examples/llama.android/app/src/main/java/com/example/llama/revamp/data/preferences/UserPreferences.kt +++ b/examples/llama.android/app/src/main/java/com/example/llama/revamp/data/preferences/UserPreferences.kt @@ -7,13 +7,19 @@ import androidx.datastore.preferences.core.booleanPreferencesKey import androidx.datastore.preferences.core.edit import androidx.datastore.preferences.core.longPreferencesKey import androidx.datastore.preferences.preferencesDataStore +import dagger.hilt.android.qualifiers.ApplicationContext import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.map +import javax.inject.Inject +import javax.inject.Singleton /** * Manages user preferences for the application. */ -class UserPreferences(private val context: Context) { +@Singleton +class UserPreferences @Inject constructor ( + @ApplicationContext private val context: Context +) { companion object { private val Context.dataStore: DataStore by preferencesDataStore(name = "settings") diff --git a/examples/llama.android/app/src/main/java/com/example/llama/revamp/data/repository/SystemPromptRepository.kt b/examples/llama.android/app/src/main/java/com/example/llama/revamp/data/repository/SystemPromptRepository.kt index 7958a8355f..394e349f31 100644 --- a/examples/llama.android/app/src/main/java/com/example/llama/revamp/data/repository/SystemPromptRepository.kt +++ b/examples/llama.android/app/src/main/java/com/example/llama/revamp/data/repository/SystemPromptRepository.kt @@ -1,20 +1,22 @@ package com.example.llama.revamp.data.repository -import android.content.Context -import com.example.llama.revamp.data.local.AppDatabase +import com.example.llama.revamp.data.local.SystemPromptDao import com.example.llama.revamp.data.local.SystemPromptEntity import com.example.llama.revamp.data.model.SystemPrompt import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.first import kotlinx.coroutines.flow.map import java.util.UUID +import javax.inject.Inject +import javax.inject.Singleton /** * Repository for managing system prompts. */ -class SystemPromptRepository(context: Context) { - - private val systemPromptDao = AppDatabase.getDatabase(context).systemPromptDao() +@Singleton +class SystemPromptRepository @Inject constructor( + private val systemPromptDao: SystemPromptDao, +) { /** * Get all preset prompts. diff --git a/examples/llama.android/app/src/main/java/com/example/llama/revamp/di/AppModule.kt b/examples/llama.android/app/src/main/java/com/example/llama/revamp/di/AppModule.kt index e4c2a687b9..af4073e496 100644 --- a/examples/llama.android/app/src/main/java/com/example/llama/revamp/di/AppModule.kt +++ b/examples/llama.android/app/src/main/java/com/example/llama/revamp/di/AppModule.kt @@ -1,8 +1,7 @@ package com.example.llama.revamp.di import android.content.Context -import com.example.llama.revamp.data.preferences.UserPreferences -import com.example.llama.revamp.data.repository.SystemPromptRepository +import com.example.llama.revamp.data.local.AppDatabase import com.example.llama.revamp.engine.InferenceEngine import com.example.llama.revamp.monitoring.PerformanceMonitor import dagger.Module @@ -15,6 +14,7 @@ import javax.inject.Singleton @Module @InstallIn(SingletonComponent::class) object AppModule { + @Provides @Singleton fun provideInferenceEngine() = InferenceEngine() @@ -24,10 +24,8 @@ object AppModule { fun providePerformanceMonitor(@ApplicationContext context: Context) = PerformanceMonitor(context) @Provides - @Singleton - fun provideUserPreferences(@ApplicationContext context: Context) = UserPreferences(context) + fun provideAppDatabase(@ApplicationContext context: Context) = AppDatabase.getDatabase(context) @Provides - @Singleton - fun provideSystemPromptRepository(@ApplicationContext context: Context) = SystemPromptRepository(context) + fun providesSystemPromptDao(appDatabase: AppDatabase) = appDatabase.systemPromptDao() }