-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #76 from klee0kai/feature/autofill
Feature/autofill
- Loading branch information
Showing
163 changed files
with
3,368 additions
and
1,095 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
...mobile/src/main/kotlin/com/github/klee0kai/thekey/app/data/mapping/StorageModelMapping.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.github.klee0kai.thekey.app.data.mapping | ||
|
||
import com.github.klee0kai.thekey.app.domain.model.ColoredStorage | ||
import com.github.klee0kai.thekey.app.engine.model.Storage | ||
import com.github.klee0kai.thekey.core.data.room.entry.StorageFileEntry | ||
import com.github.klee0kai.thekey.core.domain.ColorGroup | ||
|
||
|
||
fun StorageFileEntry.toStorage(): Storage = this.run { | ||
Storage(path, name, description) | ||
} | ||
|
||
fun Storage.toStorageEntry( | ||
id: Long? = null | ||
): StorageFileEntry = this.run { | ||
StorageFileEntry(id = id ?: 0, path = path, name = name, description = description) | ||
} | ||
|
||
fun StorageFileEntry.toColoredStorage(): ColoredStorage = this.run { | ||
ColoredStorage(path = path, name = name, description = description, colorGroup = ColorGroup(id = coloredGroupId)) | ||
} | ||
|
||
|
||
fun ColoredStorage.toStorageEntry( | ||
id: Long? = null | ||
): StorageFileEntry = this.run { | ||
StorageFileEntry( | ||
id = id ?: 0, | ||
path = path, | ||
name = name, | ||
description = description, | ||
coloredGroupId = colorGroup?.id ?: 0 | ||
) | ||
} |
51 changes: 0 additions & 51 deletions
51
...c/main/kotlin/com/github/klee0kai/thekey/app/data/repositories/FoundStoragesRepository.kt
This file was deleted.
Oops, something went wrong.
26 changes: 26 additions & 0 deletions
26
...in/kotlin/com/github/klee0kai/thekey/app/data/repositories/storages/StoragesRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.github.klee0kai.thekey.app.data.repositories.storages | ||
|
||
import com.github.klee0kai.thekey.app.domain.model.ColoredStorage | ||
import com.github.klee0kai.thekey.core.domain.ColorGroup | ||
import com.github.klee0kai.thekey.core.utils.coroutine.completeAsync | ||
import com.github.klee0kai.thekey.core.utils.coroutine.emptyJob | ||
import kotlinx.coroutines.Deferred | ||
import kotlinx.coroutines.Job | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.emptyFlow | ||
|
||
interface StoragesRepository { | ||
|
||
val allColorGroups: Flow<List<ColorGroup>> get() = emptyFlow() | ||
val allStorages: Flow<List<ColoredStorage>> get() = emptyFlow() | ||
|
||
fun findStorage(path: String): Deferred<ColoredStorage?> = completeAsync(null) | ||
fun setStorage(storage: ColoredStorage): Job = emptyJob() | ||
fun setStoragesGroup(storagePaths: List<String>, groupId: Long): Job = emptyJob() | ||
fun deleteStorage(path: String): Job = emptyJob() | ||
|
||
|
||
fun setColorGroup(colorGroup: ColorGroup): Deferred<ColorGroup> = completeAsync(ColorGroup()) | ||
fun deleteColorGroup(id: Long): Job = emptyJob() | ||
|
||
} |
90 changes: 90 additions & 0 deletions
90
...otlin/com/github/klee0kai/thekey/app/data/repositories/storages/StoragesRepositoryImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package com.github.klee0kai.thekey.app.data.repositories.storages | ||
|
||
import com.github.klee0kai.thekey.app.data.mapping.toColoredStorage | ||
import com.github.klee0kai.thekey.app.data.mapping.toStorageEntry | ||
import com.github.klee0kai.thekey.app.di.DI | ||
import com.github.klee0kai.thekey.app.domain.model.ColoredStorage | ||
import com.github.klee0kai.thekey.core.data.room.entry.toColorGroup | ||
import com.github.klee0kai.thekey.core.data.room.entry.toColorGroupEntry | ||
import com.github.klee0kai.thekey.core.domain.ColorGroup | ||
import com.github.klee0kai.thekey.core.utils.coroutine.onTicks | ||
import kotlinx.coroutines.Job | ||
import kotlinx.coroutines.async | ||
import kotlinx.coroutines.flow.MutableSharedFlow | ||
import kotlinx.coroutines.flow.flow | ||
import kotlinx.coroutines.flow.flowOn | ||
import kotlinx.coroutines.launch | ||
import timber.log.Timber | ||
import java.io.File | ||
|
||
class StoragesRepositoryImpl : StoragesRepository { | ||
|
||
private val storagesDao = DI.storageDaoLazy() | ||
private val colorGroupsDao = DI.colorGroupDaoLazy() | ||
private val scope = DI.ioThreadScope() | ||
|
||
private val updateTicker = MutableSharedFlow<Unit>() | ||
|
||
override val allColorGroups = flow { | ||
updateTicker.onTicks { | ||
colorGroupsDao() | ||
.getAll() | ||
.map { it.toColorGroup() } | ||
.also { emit(it) } | ||
} | ||
}.flowOn(DI.ioDispatcher()) | ||
|
||
override val allStorages = flow { | ||
updateTicker.onTicks { | ||
val allColorGroups = colorGroupsDao() | ||
.getAll() | ||
.map { it.toColorGroup() } | ||
|
||
storagesDao() | ||
.getAll() | ||
.map { entry -> | ||
entry.toColoredStorage() | ||
.copy(colorGroup = allColorGroups.firstOrNull { group -> entry.coloredGroupId == group.id }) | ||
} | ||
.also { emit(it) } | ||
} | ||
}.flowOn(DI.ioDispatcher()) | ||
|
||
override fun setColorGroup(colorGroup: ColorGroup) = scope.async { | ||
val id = colorGroupsDao().update(colorGroup.toColorGroupEntry()) | ||
updateTicker.emit(Unit) | ||
colorGroupsDao()[id]?.toColorGroup() ?: ColorGroup() | ||
} | ||
|
||
override fun deleteColorGroup(id: Long): Job = scope.launch { | ||
colorGroupsDao().delete(id) | ||
updateTicker.emit(Unit) | ||
} | ||
|
||
override fun findStorage(path: String) = scope.async { | ||
storagesDao().get(path)?.toColoredStorage() | ||
} | ||
|
||
override fun setStorage(storage: ColoredStorage): Job = scope.launch { | ||
if (storage.version <= 0) Timber.e("incorrect storage version ${storage.version}") | ||
|
||
val cachedStorage = storagesDao().get(storage.path) | ||
storagesDao().update(storage.toStorageEntry(id = cachedStorage?.id)) | ||
updateTicker.emit(Unit) | ||
} | ||
|
||
override fun setStoragesGroup(storagePaths: List<String>, groupId: Long) = scope.launch { | ||
storagePaths.forEach { path -> | ||
val cachedStorage = storagesDao().get(path) ?: return@forEach | ||
storagesDao().update(cachedStorage.copy(coloredGroupId = groupId)) | ||
} | ||
updateTicker.emit(Unit) | ||
} | ||
|
||
override fun deleteStorage(path: String): Job = scope.launch { | ||
File(path).deleteOnExit() | ||
storagesDao().delete(path) | ||
updateTicker.emit(Unit) | ||
} | ||
|
||
} |
38 changes: 0 additions & 38 deletions
38
app_mobile/src/main/kotlin/com/github/klee0kai/thekey/app/data/room/KeyDatabase.kt
This file was deleted.
Oops, something went wrong.
46 changes: 0 additions & 46 deletions
46
...mobile/src/main/kotlin/com/github/klee0kai/thekey/app/data/room/entry/StorageFileEntry.kt
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.