mirror of
https://github.com/CatimaLoyalty/Android.git
synced 2026-07-31 02:08:42 -04:00
Merge pull request #3219 from KamiDaga/feature/overflow-menu-to-image-gallery
Added overflow menu to open card image in image gallery
This commit is contained in:
@@ -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
|
||||
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
|
||||
|
||||
@@ -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
|
||||
)
|
||||
}
|
||||
@@ -353,4 +353,5 @@
|
||||
<string name="nfc_blocked_while_viewing_card">NFC is paused</string>
|
||||
<string name="change_settings">Change settings</string>
|
||||
<string name="nfc_block_system_error">Failed to pause NFC</string>
|
||||
<string name="open_in_gallery">Open in image gallery</string>
|
||||
</resources>
|
||||
|
||||
Reference in New Issue
Block a user