Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into package-id-change
Browse files Browse the repository at this point in the history
# Conflicts:
#	app/src/main/kotlin/com/bitwarden/authenticator/ui/authenticator/feature/itemlisting/ItemListingScreen.kt
#	app/src/main/res/xml/backup_rules.xml
  • Loading branch information
SaintPatrck committed Apr 17, 2024
2 parents 1ab67c4 + 1867669 commit c938700
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package com.bitwarden.authenticator.ui.authenticator.feature.itemlisting

import android.Manifest
import android.content.Intent
import android.net.Uri
import android.provider.Settings
import android.widget.Toast
import androidx.compose.foundation.Image
import androidx.compose.foundation.clickable
Expand All @@ -21,7 +25,10 @@ import androidx.compose.material3.pulltorefresh.rememberPullToRefreshState
import androidx.compose.material3.rememberTopAppBarState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.input.nestedscroll.nestedScroll
Expand Down Expand Up @@ -54,6 +61,10 @@ import com.bitwarden.authenticator.ui.platform.components.icon.BitwardenIcon
import com.bitwarden.authenticator.ui.platform.components.model.IconData
import com.bitwarden.authenticator.ui.platform.components.model.IconResource
import com.bitwarden.authenticator.ui.platform.components.scaffold.BitwardenScaffold
import com.bitwarden.authenticator.ui.platform.manager.intent.IntentManager
import com.bitwarden.authenticator.ui.platform.manager.permissions.PermissionsManager
import com.bitwarden.authenticator.ui.platform.theme.LocalIntentManager
import com.bitwarden.authenticator.ui.platform.theme.LocalPermissionsManager
import com.bitwarden.authenticator.ui.platform.theme.Typography

/**
Expand All @@ -63,6 +74,8 @@ import com.bitwarden.authenticator.ui.platform.theme.Typography
@Composable
fun ItemListingScreen(
viewModel: ItemListingViewModel = hiltViewModel(),
intentManager: IntentManager = LocalIntentManager.current,
permissionsManager: PermissionsManager = LocalPermissionsManager.current,
onNavigateBack: () -> Unit,
onNavigateToSearch: () -> Unit,
onNavigateToQrCodeScanner: () -> Unit,
Expand All @@ -75,6 +88,14 @@ fun ItemListingScreen(
val scrollBehavior = TopAppBarDefaults.pinnedScrollBehavior(rememberTopAppBarState())
val pullToRefreshState = rememberPullToRefreshState()
val context = LocalContext.current
var shouldShowPermissionDialog by rememberSaveable { mutableStateOf(false) }
val launcher = permissionsManager.getLauncher { isGranted ->
if (isGranted) {
viewModel.trySendAction(ItemListingAction.ScanQrCodeClick)
} else {
shouldShowPermissionDialog = true
}
}

EventsEffect(viewModel = viewModel) { event ->
when (event) {
Expand All @@ -94,9 +115,29 @@ fun ItemListingScreen(
}

is ItemListingEvent.NavigateToEditItem -> onNavigateToEditItemScreen(event.id)
is ItemListingEvent.NavigateToAppSettings -> {
val intent = Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS)
intent.data = Uri.parse("package:" + context.packageName)

intentManager.startActivity(intent = intent)
}
}
}

if (shouldShowPermissionDialog) {
BitwardenTwoButtonDialog(
message = stringResource(id = R.string.enable_camera_permission_to_use_the_scanner),
confirmButtonText = stringResource(id = R.string.settings),
dismissButtonText = stringResource(id = R.string.no_thanks),
onConfirmClick = remember(viewModel) {
{ viewModel.trySendAction(ItemListingAction.SettingsClick) }
},
onDismissClick = { shouldShowPermissionDialog = false },
onDismissRequest = { shouldShowPermissionDialog = false },
title = null,
)
}

ItemListingDialogs(
dialog = state.dialog,
onDismissRequest = remember(viewModel) {
Expand Down Expand Up @@ -152,7 +193,7 @@ fun ItemListingScreen(
testTag = "ScanQRCodeButton",
),
onScanQrCodeClick = {
viewModel.trySendAction(ItemListingAction.ScanQrCodeClick)
launcher.launch(Manifest.permission.CAMERA)
}
),
ItemListingExpandableFabAction.EnterSetupKey(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,20 @@ class ItemListingViewModel @Inject constructor(
handleDialogDismiss()
}

is ItemListingAction.SettingsClick -> {
handleSettingsClick()
}

is ItemListingAction.Internal -> {
handleInternalAction(action)
}
}
}

private fun handleSettingsClick() {
sendEvent(ItemListingEvent.NavigateToAppSettings)
}

private fun handleItemClick(action: ItemListingAction.ItemClick) {
clipboardManager.setText(action.authCode)
sendEvent(
Expand Down Expand Up @@ -533,6 +541,11 @@ sealed class ItemListingEvent {
val id: String,
) : ItemListingEvent()

/**
* Navigate to the app settings.
*/
data object NavigateToAppSettings : ItemListingEvent()

/**
* Show a Toast with [message].
*/
Expand Down Expand Up @@ -582,6 +595,11 @@ sealed class ItemListingAction {
*/
data object DialogDismiss : ItemListingAction()

/**
* The user has clicked the settings button
*/
data object SettingsClick : ItemListingAction()

/**
* Models actions that [ItemListingScreen] itself may send.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ private fun HelpSettings(
label = stringResource(id = R.string.help)
)
BitwardenTextRow(
text = stringResource(id = R.string.tutorial),
text = stringResource(id = R.string.launch_tutorial),
onClick = onTutorialClick,
modifier = modifier,
)
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
<string name="get_started">Get started</string>
<string name="unique_codes">Uniqe codes</string>
<string name="help">Help</string>
<string name="tutorial">Tutorial</string>
<string name="launch_tutorial">Launch tutorial</string>
<string name="value_has_been_copied">%1$s copied</string>
<string name="delete_item">Delete item</string>
<string name="item_deleted">Item deleted</string>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/xml/backup_rules.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<include
domain="sharedpref"
path="com.bitwarden.authenticator_preferences.xml" />
<exclude
<include
domain="database"
path="."
tools:ignore="FullBackupContent" />
Expand Down

0 comments on commit c938700

Please sign in to comment.