Skip to content

Commit

Permalink
Merge pull request #76 from klee0kai/feature/autofill
Browse files Browse the repository at this point in the history
Feature/autofill
  • Loading branch information
klee0kai committed Jun 14, 2024
2 parents 23bc8f6 + 35ea441 commit 0f375d4
Show file tree
Hide file tree
Showing 163 changed files with 3,368 additions and 1,095 deletions.
3 changes: 3 additions & 0 deletions app_mobile/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ brooklyn {
android {
appDefaults(appGroup, project)
dynamicFeatures += setOf(":dynamic_qrcodescanner")
if (Commercial.isCommercialAvailable) {
dynamicFeatures += setOf(":private:dynamic_autofill")
}

defaultConfig {
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
Expand Down
9 changes: 9 additions & 0 deletions app_mobile/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
android:name=".ui.MainActivity"
android:configChanges="orientation|keyboard|keyboardHidden|screenLayout|screenSize"
android:exported="true"
android:launchMode="singleTask"
android:theme="@style/Theme.TheKey"
android:windowSoftInputMode="adjustResize">
<intent-filter>
Expand All @@ -28,6 +29,14 @@
</intent-filter>
</activity>

<activity
android:name=".ui.MainTranparentActivity"
android:configChanges="orientation|keyboard|keyboardHidden|screenLayout|screenSize"
android:launchMode="singleTask"
android:theme="@style/Theme.TheKey.Transparent"
android:windowSoftInputMode="adjustResize" />


<!-- fix crash https://stackoverflow.com/questions/68153515 -->
<provider
android:name="com.google.mlkit.common.internal.MlKitInitProvider"
Expand Down
8 changes: 8 additions & 0 deletions app_mobile/src/main/cpp/find-storages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,11 @@ void JvmFindStorageEngine::findStorages(const std::string &folder, const JvmFind
});
}

int JvmFindStorageEngine::storageVersion(const std::string &path) {
auto storage = thekey::storage(path);
if (storage) {
return storage->storageVersion;
} else {
return 0;
}
}
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
)
}

This file was deleted.

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()

}
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)
}

}

This file was deleted.

This file was deleted.

Loading

0 comments on commit 0f375d4

Please sign in to comment.