diff --git a/app/src/main/java/protect/card_locker/cardimageview/LoyaltyCardImageViewActivity.kt b/app/src/main/java/protect/card_locker/cardimageview/LoyaltyCardImageViewActivity.kt index 84f671da2..bc78df3ce 100644 --- a/app/src/main/java/protect/card_locker/cardimageview/LoyaltyCardImageViewActivity.kt +++ b/app/src/main/java/protect/card_locker/cardimageview/LoyaltyCardImageViewActivity.kt @@ -2,6 +2,7 @@ package protect.card_locker.cardimageview import android.content.Context import android.content.Intent +import android.content.Intent.FLAG_GRANT_READ_URI_PERMISSION import android.graphics.Bitmap import android.os.Bundle import android.view.WindowManager @@ -17,8 +18,15 @@ import androidx.compose.foundation.gestures.transformable import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.padding +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.filled.MoreVert +import androidx.compose.material3.DropdownMenu +import androidx.compose.material3.DropdownMenuItem +import androidx.compose.material3.Icon +import androidx.compose.material3.IconButton import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Scaffold +import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableFloatStateOf @@ -32,9 +40,11 @@ import androidx.compose.ui.graphics.graphicsLayer import androidx.compose.ui.input.pointer.pointerInput import androidx.compose.ui.layout.ContentScale import androidx.compose.ui.layout.onSizeChanged +import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.testTag import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.IntSize +import androidx.core.content.FileProvider import protect.card_locker.CatimaComponentActivity import protect.card_locker.ImageLocationType import protect.card_locker.R @@ -68,6 +78,8 @@ class LoyaltyCardImageViewActivity : CatimaComponentActivity() { CatimaTheme { LoyaltyCardImageViewScreen( bitmap = bitmap, + imageLocationType = imageLocationType, + cardId = loyaltyCardId, contentDescriptionRes = imageLocationType.descriptionRes(), onBackPressedDispatcher = onBackPressedDispatcher ) @@ -124,9 +136,12 @@ class LoyaltyCardImageViewActivity : CatimaComponentActivity() { @Composable fun LoyaltyCardImageViewScreen( bitmap: Bitmap, + imageLocationType: ImageLocationType, + cardId: Int, @StringRes contentDescriptionRes: Int, onBackPressedDispatcher: OnBackPressedDispatcher, ) { + val context = LocalContext.current var scale by remember { mutableFloatStateOf(1F) } var offset by remember { mutableStateOf(Offset.Zero) } var size by remember { mutableStateOf(IntSize.Zero) } @@ -144,7 +159,24 @@ fun LoyaltyCardImageViewScreen( topBar = { CatimaTopAppBar( title = stringResource(contentDescriptionRes), - onBackPressedDispatcher = onBackPressedDispatcher + onBackPressedDispatcher = onBackPressedDispatcher, + actions = { + var expanded by remember { mutableStateOf(false) } + IconButton(onClick = { expanded = !expanded }) { + Icon( + imageVector = Icons.Filled.MoreVert, + contentDescription = stringResource(R.string.action_more_options) + ) + } + DropdownMenu( + expanded = expanded, + onDismissRequest = { expanded = false } + ) { + DropdownMenuItem(onClick = { openInImageGallery(context, cardId, imageLocationType) }, + text = { Text(stringResource(R.string.open_in_gallery)) }, + ) + } + } ) } ) { innerPadding -> @@ -196,4 +228,13 @@ private fun Offset.clampTo(size: IntSize, scale: Float): Offset { ) } -private const val MAX_IMAGE_SCALE = 5F \ No newline at end of file +private fun openInImageGallery(context: Context, cardId: Int, imageLocationType: ImageLocationType){ + val imagePath = Utils.getCardImageFileName(cardId, imageLocationType) + val viewInGalleryIntent = Intent(Intent.ACTION_VIEW).apply { + setDataAndType(FileProvider.getUriForFile(context, context.packageName, context.getFileStreamPath(imagePath)), "image/*") + flags = FLAG_GRANT_READ_URI_PERMISSION + } + context.startActivity(viewInGalleryIntent) +} + +private const val MAX_IMAGE_SCALE = 5F diff --git a/app/src/main/java/protect/card_locker/compose/Catima.kt b/app/src/main/java/protect/card_locker/compose/Catima.kt index 3f9506d92..727f3a904 100644 --- a/app/src/main/java/protect/card_locker/compose/Catima.kt +++ b/app/src/main/java/protect/card_locker/compose/Catima.kt @@ -3,6 +3,7 @@ package protect.card_locker.compose import androidx.activity.OnBackPressedDispatcher import androidx.appcompat.app.AppCompatDelegate import androidx.compose.foundation.isSystemInDarkTheme +import androidx.compose.foundation.layout.RowScope import androidx.compose.material.icons.Icons import androidx.compose.material.icons.automirrored.filled.ArrowBack import androidx.compose.material3.ExperimentalMaterial3Api @@ -22,7 +23,9 @@ import protect.card_locker.preferences.Settings @OptIn(ExperimentalMaterial3Api::class) @Composable -fun CatimaTopAppBar(title: String, onBackPressedDispatcher: OnBackPressedDispatcher?) { +fun CatimaTopAppBar(title: String, + onBackPressedDispatcher: OnBackPressedDispatcher?, + actions : @Composable RowScope.() -> Unit = {}) { // Use pure black in OLED theme val context = LocalContext.current val settings = Settings(context) @@ -51,6 +54,7 @@ fun CatimaTopAppBar(title: String, onBackPressedDispatcher: OnBackPressedDispatc ) } } - } + }, + actions = actions ) } \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 05d24b8d8..e8f07b45e 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -353,4 +353,5 @@ NFC is paused Change settings Failed to pause NFC + Open in image gallery