Skip to content

Commit

Permalink
Display no items content when user has no items saved (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
SaintPatrck authored Apr 3, 2024
1 parent 6a226f2 commit 9aa0918
Show file tree
Hide file tree
Showing 11 changed files with 449 additions and 232 deletions.
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
package com.x8bit.bitwarden.authenticator.data.authenticator.datasource.disk

import com.bitwarden.core.CipherRepromptType
import com.bitwarden.core.CipherType
import com.bitwarden.core.CipherView
import com.bitwarden.core.DateTime
import com.bitwarden.core.LoginView
import com.x8bit.bitwarden.authenticator.data.platform.repository.util.bufferedMutableSharedFlow
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flowOf
import javax.inject.Inject

class AuthenticatorDiskSourceImpl @Inject constructor() : AuthenticatorDiskSource {

private val ciphers = STATIC_CIPHER_CACHE.toMutableList()
private val mutableCiphersFlow = bufferedMutableSharedFlow<List<CipherView>>()

override suspend fun saveCipher(cipher: CipherView) {
ciphers.add(cipher)
mutableCiphersFlow.tryEmit(ciphers)
}

override fun getCiphers(): Flow<List<CipherView>> {
Expand All @@ -23,76 +22,78 @@ class AuthenticatorDiskSourceImpl @Inject constructor() : AuthenticatorDiskSourc

override suspend fun deleteCipher(cipherId: String) {
ciphers.removeIf { it.id == cipherId }
mutableCiphersFlow.tryEmit(ciphers)
}
}

private val STATIC_CIPHER_CACHE = listOf(
CipherView(
id = "1",
organizationId = null,
folderId = null,
collectionIds = emptyList(),
key = null,
name = "TOTP test 1",
notes = null,
type = CipherType.LOGIN,
login = LoginView(
null,
null,
null,
null,
"JBSWY3DPEHPK3PXP",
null,
null
),
identity = null,
card = null,
secureNote = null,
favorite = true,
reprompt = CipherRepromptType.NONE,
organizationUseTotp = false,
edit = false,
viewPassword = true,
localData = null,
attachments = null,
fields = null,
passwordHistory = null,
creationDate = DateTime.now(),
deletedDate = null,
revisionDate = DateTime.now()
),
CipherView(
id = "2",
organizationId = null,
folderId = null,
collectionIds = emptyList(),
key = null,
name = "TOTP test 2",
notes = null,
type = CipherType.LOGIN,
login = LoginView(
null,
null,
null,
null,
"JBSWY3DPEHPK3PXP",
null,
null
),
identity = null,
card = null,
secureNote = null,
favorite = true,
reprompt = CipherRepromptType.NONE,
organizationUseTotp = false,
edit = false,
viewPassword = true,
localData = null,
attachments = null,
fields = null,
passwordHistory = null,
creationDate = DateTime.now(),
deletedDate = null,
revisionDate = DateTime.now()
)
)
private val STATIC_CIPHER_CACHE = emptyList<CipherView>()
// listOf(
// CipherView(
// id = "1",
// organizationId = null,
// folderId = null,
// collectionIds = emptyList(),
// key = null,
// name = "TOTP test 1",
// notes = null,
// type = CipherType.LOGIN,
// login = LoginView(
// null,
// null,
// null,
// null,
// "JBSWY3DPEHPK3PXP",
// null,
// null
// ),
// identity = null,
// card = null,
// secureNote = null,
// favorite = true,
// reprompt = CipherRepromptType.NONE,
// organizationUseTotp = false,
// edit = false,
// viewPassword = true,
// localData = null,
// attachments = null,
// fields = null,
// passwordHistory = null,
// creationDate = DateTime.now(),
// deletedDate = null,
// revisionDate = DateTime.now()
// ),
// CipherView(
// id = "2",
// organizationId = null,
// folderId = null,
// collectionIds = emptyList(),
// key = null,
// name = "TOTP test 2",
// notes = null,
// type = CipherType.LOGIN,
// login = LoginView(
// null,
// null,
// null,
// null,
// "JBSWY3DPEHPK3PXP",
// null,
// null
// ),
// identity = null,
// card = null,
// secureNote = null,
// favorite = true,
// reprompt = CipherRepromptType.NONE,
// organizationUseTotp = false,
// edit = false,
// viewPassword = true,
// localData = null,
// attachments = null,
// fields = null,
// passwordHistory = null,
// creationDate = DateTime.now(),
// deletedDate = null,
// revisionDate = DateTime.now()
// )
//)
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import javax.inject.Inject
* A "stop timeout delay" in milliseconds used to let a shared coroutine continue to run for the
* specified period of time after it no longer has subscribers.
*/
private const val STOP_TIMEOUT_DELAY_MS: Long = 1_000L
private const val STOP_TIMEOUT_DELAY_MS: Long = 5_000L

class AuthenticatorRepositoryImpl @Inject constructor(
private val authenticatorDiskSource: AuthenticatorDiskSource,
Expand All @@ -57,7 +57,6 @@ class AuthenticatorRepositoryImpl @Inject constructor(

override val authenticatorDataFlow: StateFlow<DataState<AuthenticatorData>> =
ciphersStateFlow.map { cipherDataState ->

when (cipherDataState) {
is DataState.Error -> {
DataState.Error(
Expand Down Expand Up @@ -114,7 +113,7 @@ class AuthenticatorRepositoryImpl @Inject constructor(
}
.stateIn(
scope = unconfinedScope,
started = SharingStarted.Lazily,
started = SharingStarted.WhileSubscribed(STOP_TIMEOUT_DELAY_MS),
initialValue = DataState.Loading,
)

Expand All @@ -139,7 +138,7 @@ class AuthenticatorRepositoryImpl @Inject constructor(
}
.stateIn(
scope = unconfinedScope,
started = SharingStarted.WhileSubscribed(),
started = SharingStarted.WhileSubscribed(STOP_TIMEOUT_DELAY_MS),
initialValue = DataState.Loading,
)
}
Expand Down Expand Up @@ -177,7 +176,7 @@ class AuthenticatorRepositoryImpl @Inject constructor(
}
.stateIn(
scope = unconfinedScope,
started = SharingStarted.WhileSubscribed(),
started = SharingStarted.WhileSubscribed(STOP_TIMEOUT_DELAY_MS),
initialValue = DataState.Loading,
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ fun NavGraphBuilder.itemListingGraph(
onNavigateToItemScreen = { navController.navigateToItem(itemId = it) },
onNavigateToEditItemScreen = { /*navController.navigateToEditItem(itemId = it)*/ },
onNavigateToManualKeyEntry = { navController.navigateToManualCodeEntryScreen() },
onNavigateToSyncWithBitwardenScreen = {
/*navController.navigateToSyncWithBitwardenScreen()*/
},
onNavigateToImportScreen = { /*navController.navigateToImportScreen()*/ }
)
itemDestination(
onNavigateBack = { navController.popBackStack() },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ fun NavGraphBuilder.itemListingDestination(
onNavigateToManualKeyEntry: () -> Unit = { },
onNavigateToItemScreen: (id: String) -> Unit = { },
onNavigateToEditItemScreen: (id: String) -> Unit = { },
onNavigateToSyncWithBitwardenScreen: () -> Unit = { },
onNavigateToImportScreen: () -> Unit = { },
) {
composableWithPushTransitions(
route = ITEM_LIST_ROUTE,
Expand All @@ -23,7 +25,9 @@ fun NavGraphBuilder.itemListingDestination(
onNavigateToQrCodeScanner = onNavigateToQrCodeScanner,
onNavigateToManualKeyEntry = onNavigateToManualKeyEntry,
onNavigateToItemScreen = onNavigateToItemScreen,
onNavigateToEditItemScreen = onNavigateToEditItemScreen
onNavigateToEditItemScreen = onNavigateToEditItemScreen,
onNavigateToSyncWithBitwardenScreen = onNavigateToSyncWithBitwardenScreen,
onNavigateToImportScreen = onNavigateToImportScreen
)
}
}
Loading

0 comments on commit 9aa0918

Please sign in to comment.