Это мой источник данных:
Код: Выделить всё
class LocalDataSourceImpl(private val noteDao: NoteDao) : LocalDataSource {
private val mutex = Mutex()
override suspend fun getAllNotes(categoryId: Int?): List = mutex.withLock {
return if (categoryId == 1) noteDao.getAllNotes().toModel() else noteDao.getNotes(
categoryId
).first().toModel()
}
override suspend fun upsertNote(note: NoteEntity) = mutex.withLock {
noteDao.upsertNote(note)
}
override suspend fun deleteNote(noteId: String): Int = mutex.withLock {
noteDao.deleteById(noteId)
}
override suspend fun completeNote(noteId: String) = mutex.withLock {
noteDao.updateCompleted(noteId = noteId, completed = true)
}
override suspend fun activateNote(noteId: String) = mutex.withLock {
noteDao.updateCompleted(noteId = noteId, completed = false)
}
override suspend fun getNoteById(noteId: String): NoteEntity? = mutex.withLock {
return noteDao.getNoteById(noteId = noteId).first()
}
override suspend fun clearCompletedNotes(): Int = mutex.withLock {
noteDao.deleteCompleted()
}
}
Код: Выделить всё
fun appModule() = module {
factory { SavedStateHandle() }
single {
LocalDataSourceImpl(get())
}
single {
NotesRepositoryImpl(get(), get())
}
}
Код: Выделить всё
@Composable
internal fun App() {
KoinApplication(application = {
modules(appModule())
}) {
AppTheme {
App()
}
}
}
Код: Выделить всё
expect class Factory {
fun createRoomDatabase(): AppDatabase
}
actual class Factory(private val app: Application) {
actual fun createRoomDatabase(): AppDatabase {
val dbFile = app.getDatabasePath(dbFileName)
return Room.databaseBuilder(app, dbFile.absolutePath)
.setDriver(BundledSQLiteDriver())
.setQueryCoroutineContext(Dispatchers.IO)
.build()
}
}
actual class Factory {
actual fun createRoomDatabase(): AppDatabase {
val dbFile = "${fileDirectory()}/$dbFileName"
return Room.databaseBuilder(
name = dbFile,
factory = { AppDatabase::class.instantiateImpl() }
).setDriver(BundledSQLiteDriver())
.setQueryCoroutineContext(Dispatchers.IO)
.build()
}
@OptIn(ExperimentalForeignApi::class)
private fun fileDirectory(): String {
val documentDirectory: NSURL? = NSFileManager.defaultManager.URLForDirectory(
directory = NSDocumentDirectory,
inDomain = NSUserDomainMask,
appropriateForURL = null,
create = false,
error = null,
)
return requireNotNull(documentDirectory).path!!
}
}
и почему я получаю эту ошибку:
Причина: org.koin.core.error.NoBeanDefFoundException: Нет найдено определение для типа «database.NoteDao». Проверьте конфигурацию своих модулей и добавьте отсутствующий тип и/или квалификатор!
как это исправить?
Подробнее здесь: https://stackoverflow.com/questions/784 ... tiplatform
Мобильная версия