forked from AChep/keyguard-app
-
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.
feat: Hide accounts from the Main screens AChep#35
- Loading branch information
Showing
28 changed files
with
374 additions
and
85 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
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
5 changes: 5 additions & 0 deletions
5
common/src/commonMain/kotlin/com/artemchep/keyguard/common/model/PutProfileHiddenRequest.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,5 @@ | ||
package com.artemchep.keyguard.common.model | ||
|
||
data class PutProfileHiddenRequest( | ||
val patch: Map<String, Boolean>, | ||
) |
76 changes: 76 additions & 0 deletions
76
common/src/commonMain/kotlin/com/artemchep/keyguard/common/usecase/GetCiphers.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 |
---|---|---|
@@ -1,10 +1,86 @@ | ||
package com.artemchep.keyguard.common.usecase | ||
|
||
import com.artemchep.keyguard.common.model.DFilter | ||
import com.artemchep.keyguard.common.model.DSecret | ||
import com.artemchep.keyguard.common.model.DSend | ||
import com.artemchep.keyguard.common.model.DSendFilter | ||
import kotlinx.collections.immutable.toPersistentSet | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.combine | ||
import kotlinx.coroutines.flow.distinctUntilChanged | ||
import kotlinx.coroutines.flow.map | ||
|
||
/** | ||
* Provides a list of all available on the | ||
* device accounts. | ||
*/ | ||
interface GetCiphers : () -> Flow<List<DSecret>> | ||
|
||
fun filterHiddenProfiles( | ||
getCiphers: GetCiphers, | ||
getProfiles: GetProfiles, | ||
filter: DFilter? = null, | ||
): Flow<List<DSecret>> { | ||
val shouldFilter = filter | ||
?.let { f -> | ||
// If we have a pre-set filter that specifies an | ||
// identifier of the folder or collection or account etc, | ||
// then we ignore the hidden account setting. | ||
DFilter.findOne<DFilter.ById>(f) { true } == null | ||
} | ||
?: true | ||
return if (shouldFilter) { | ||
_filterHiddenProfiles( | ||
getItems = getCiphers, | ||
getProfiles = getProfiles, | ||
getAccount = { it.accountId }, | ||
) | ||
} else { | ||
getCiphers() | ||
} | ||
} | ||
|
||
fun filterHiddenProfiles( | ||
getSends: GetSends, | ||
getProfiles: GetProfiles, | ||
filter: DSendFilter? = null, | ||
): Flow<List<DSend>> { | ||
val shouldFilter = filter | ||
?.let { f -> | ||
// If we have a pre-set filter that specifies an | ||
// identifier of the folder or collection or account etc, | ||
// then we ignore the hidden account setting. | ||
DSendFilter.findOne<DSendFilter.ById>(f) { true } == null | ||
} | ||
?: true | ||
return if (shouldFilter) { | ||
_filterHiddenProfiles( | ||
getItems = getSends, | ||
getProfiles = getProfiles, | ||
getAccount = { it.accountId }, | ||
) | ||
} else { | ||
getSends() | ||
} | ||
} | ||
|
||
private inline fun <T> _filterHiddenProfiles( | ||
getItems: () -> Flow<List<T>>, | ||
getProfiles: GetProfiles, | ||
crossinline getAccount: (T) -> String, | ||
): Flow<List<T>> { | ||
val ccc = getProfiles() | ||
.map { profiles -> | ||
profiles | ||
.asSequence() | ||
.filter { it.hidden } | ||
.map { it.accountId } | ||
.toPersistentSet() | ||
} | ||
.distinctUntilChanged() | ||
return getItems() | ||
.combine(ccc) { items, hiddenAccountIds -> | ||
items | ||
.filter { getAccount(it) !in hiddenAccountIds } | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
common/src/commonMain/kotlin/com/artemchep/keyguard/common/usecase/PutProfileHidden.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,8 @@ | ||
package com.artemchep.keyguard.common.usecase | ||
|
||
import com.artemchep.keyguard.common.io.IO | ||
import com.artemchep.keyguard.common.model.PutProfileHiddenRequest | ||
|
||
interface PutProfileHidden : ( | ||
PutProfileHiddenRequest, | ||
) -> IO<Boolean> |
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
Oops, something went wrong.