Skip to content

Commit 47e6f39

Browse files
committed
Added gesture swapping
1 parent 2d0e28c commit 47e6f39

10 files changed

Lines changed: 89 additions & 51 deletions

File tree

app/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ android {
2525
minSdk = 33
2626
targetSdk = 36
2727
versionCode = 1
28-
versionName = "1.0.0"
28+
versionName = "1.0.1"
2929

3030
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
3131
}

app/src/main/kotlin/at/mcbabo/authenticator/data/store/Preferences.kt

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,17 @@ enum class SortType {
1515
ID
1616
}
1717

18+
enum class GestureType(val displayName: String) {
19+
TAP_TO_COPY("Tap to copy"),
20+
LONG_PRESS_TO_COPY("Long press to copy"),
21+
}
22+
1823
object PreferencesKeys {
1924
val USE_DYNAMIC_COLORS = booleanPreferencesKey("use_dynamic_colors")
2025
val FIRST_LAUNCH = booleanPreferencesKey("first_launch")
2126
val SORT_TYPE = stringPreferencesKey("sort_type")
2227
val LOCK_ENABLED = booleanPreferencesKey("lock_enabled")
28+
val GESTURE_TYPE = stringPreferencesKey("gesture_type")
2329
}
2430

2531
class UserPreferences(private val context: Context) {
@@ -35,6 +41,9 @@ class UserPreferences(private val context: Context) {
3541
val lockEnabled: Flow<Boolean> = context.dataStore.data
3642
.map { it[PreferencesKeys.LOCK_ENABLED] ?: false }
3743

44+
val gestureType: Flow<GestureType> = context.dataStore.data
45+
.map { enumValueOf<GestureType>(it[PreferencesKeys.GESTURE_TYPE] ?: GestureType.TAP_TO_COPY.name) }
46+
3847
suspend fun setUseDynamicColors(enabled: Boolean) {
3948
context.dataStore.edit { prefs ->
4049
prefs[PreferencesKeys.USE_DYNAMIC_COLORS] = enabled
@@ -58,4 +67,10 @@ class UserPreferences(private val context: Context) {
5867
prefs[PreferencesKeys.LOCK_ENABLED] = enabled
5968
}
6069
}
61-
}
70+
71+
suspend fun setGestureType(gestureType: GestureType) {
72+
context.dataStore.edit { prefs ->
73+
prefs[PreferencesKeys.GESTURE_TYPE] = gestureType.name
74+
}
75+
}
76+
}

app/src/main/kotlin/at/mcbabo/authenticator/ui/components/OTPAccountItem.kt

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,37 @@ import androidx.compose.ui.res.stringResource
1919
import androidx.compose.ui.text.style.TextOverflow
2020
import androidx.compose.ui.unit.dp
2121
import at.mcbabo.authenticator.R
22+
import at.mcbabo.authenticator.data.store.GestureType
2223
import at.mcbabo.authenticator.internal.crypto.AuthType
2324
import at.mcbabo.authenticator.ui.viewmodel.OtpAccountWithCode
2425

2526
@Composable
2627
fun OTPAccountItem(
2728
modifier: Modifier,
2829
account: OtpAccountWithCode,
30+
gestureType: GestureType,
2931
onClick: () -> Unit,
3032
onLongClick: () -> Unit,
3133
onHOTPClick: () -> Unit = {}
3234
) {
35+
val gestureModifier = when (gestureType) {
36+
GestureType.LONG_PRESS_TO_COPY -> Modifier
37+
.combinedClickable(
38+
onClick = onClick,
39+
onLongClick = onLongClick
40+
)
41+
42+
GestureType.TAP_TO_COPY -> Modifier
43+
.combinedClickable(
44+
onClick = onLongClick,
45+
onLongClick = onClick
46+
)
47+
}
48+
3349
Row(
3450
modifier = modifier
3551
.fillMaxWidth()
36-
.combinedClickable(
37-
onClick = { onClick() },
38-
onLongClick = { onLongClick() }
39-
)
52+
.then(gestureModifier)
4053
.padding(16.dp),
4154
horizontalArrangement = Arrangement.SpaceBetween,
4255
verticalAlignment = Alignment.CenterVertically

app/src/main/kotlin/at/mcbabo/authenticator/ui/components/OTPAccountList.kt

Lines changed: 0 additions & 39 deletions
This file was deleted.

app/src/main/kotlin/at/mcbabo/authenticator/ui/screen/SettingsScreen.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import androidx.compose.ui.platform.LocalContext
2222
import androidx.compose.ui.res.stringResource
2323
import androidx.hilt.lifecycle.viewmodel.compose.hiltViewModel
2424
import at.mcbabo.authenticator.R
25+
import at.mcbabo.authenticator.data.store.GestureType
2526
import at.mcbabo.authenticator.internal.BiometricAuthManager
2627
import at.mcbabo.authenticator.ui.components.PreferenceSubtitle
2728
import at.mcbabo.authenticator.ui.components.PreferenceSwitch
@@ -37,6 +38,7 @@ fun SettingsScreen(
3738

3839
val useDynamicColors by viewModel.useDynamicColors.collectAsState()
3940
val lockEnabled by viewModel.lockEnabled.collectAsState()
41+
val gestureType by viewModel.gestureType.collectAsState()
4042

4143
val context = LocalContext.current
4244
val activity = LocalActivity.current as AppCompatActivity
@@ -84,6 +86,16 @@ fun SettingsScreen(
8486
description = stringResource(R.string.dynamic_color_desc),
8587
isChecked = useDynamicColors,
8688
) { viewModel.setUseDynamicColors(!useDynamicColors) }
89+
PreferenceSwitch(
90+
title = stringResource(R.string.choose_tap_gesture),
91+
description = stringResource(R.string.currently, gestureType.displayName),
92+
isChecked = gestureType == GestureType.LONG_PRESS_TO_COPY,
93+
) {
94+
when (gestureType) {
95+
GestureType.TAP_TO_COPY -> viewModel.setGestureType(GestureType.LONG_PRESS_TO_COPY)
96+
GestureType.LONG_PRESS_TO_COPY -> viewModel.setGestureType(GestureType.TAP_TO_COPY)
97+
}
98+
}
8799
}
88100

89101
item {

app/src/main/kotlin/at/mcbabo/authenticator/ui/screen/ViewOTPScreen.kt

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ fun ViewOTPScreen(
7979
val searchQuery by viewModel.searchQuery.collectAsState()
8080
val sortType by viewModel.sortType.collectAsState()
8181

82+
val gestureType by viewModel.gestureType.collectAsState()
83+
8284
val context = LocalContext.current
8385
val coroutineScope = rememberCoroutineScope()
8486
val clipboardManager = LocalClipboard.current
@@ -185,7 +187,10 @@ fun ViewOTPScreen(
185187
OTPAccountItem(
186188
modifier = Modifier,
187189
account = accountWithCode,
188-
onClick = { onAccountClick(accountWithCode.account.id) },
190+
gestureType = gestureType,
191+
onClick = {
192+
onAccountClick(accountWithCode.account.id)
193+
},
189194
onLongClick = {
190195
coroutineScope.launch {
191196
if (!accountWithCode.currentCode.isNullOrEmpty()) {
@@ -264,14 +269,18 @@ fun ViewOTPScreen(
264269
OTPAccountItem(
265270
modifier = Modifier,
266271
account = accountWithCode,
267-
onClick = { onAccountClick(accountWithCode.account.id) },
272+
gestureType = gestureType,
273+
onClick = {
274+
onAccountClick(accountWithCode.account.id)
275+
},
268276
onLongClick = {
269277
coroutineScope.launch {
270278
if (!accountWithCode.currentCode.isNullOrEmpty()) {
271-
val clipData = ClipData.newPlainText(
272-
context.getString(R.string.otp_code),
273-
accountWithCode.currentCode
274-
)
279+
val clipData =
280+
ClipData.newPlainText(
281+
context.getString(R.string.otp_code),
282+
accountWithCode.currentCode
283+
)
275284
coroutineScope.launch {
276285
clipboardManager.setClipEntry(
277286
clipData.toClipEntry()

app/src/main/kotlin/at/mcbabo/authenticator/ui/viewmodel/PreferenceViewModel.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package at.mcbabo.authenticator.ui.viewmodel
22

33
import androidx.lifecycle.ViewModel
44
import androidx.lifecycle.viewModelScope
5+
import at.mcbabo.authenticator.data.store.GestureType
56
import at.mcbabo.authenticator.data.store.SortType
67
import at.mcbabo.authenticator.data.store.UserPreferences
78
import dagger.hilt.android.lifecycle.HiltViewModel
@@ -27,6 +28,9 @@ class PreferenceViewModel @Inject constructor(
2728
val lockEnabled: StateFlow<Boolean> =
2829
userPreferences.lockEnabled.stateIn(viewModelScope, SharingStarted.Eagerly, false)
2930

31+
val gestureType: StateFlow<GestureType> =
32+
userPreferences.gestureType.stateIn(viewModelScope, SharingStarted.Eagerly, GestureType.TAP_TO_COPY)
33+
3034
fun setUseDynamicColors(enabled: Boolean) {
3135
viewModelScope.launch {
3236
userPreferences.setUseDynamicColors(enabled)
@@ -50,4 +54,10 @@ class PreferenceViewModel @Inject constructor(
5054
userPreferences.setLockEnabled(enabled)
5155
}
5256
}
57+
58+
fun setGestureType(gestureType: GestureType) {
59+
viewModelScope.launch {
60+
userPreferences.setGestureType(gestureType)
61+
}
62+
}
5363
}

app/src/main/kotlin/at/mcbabo/authenticator/ui/viewmodel/ViewOTPViewModel.kt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import androidx.lifecycle.ViewModel
55
import androidx.lifecycle.viewModelScope
66
import at.mcbabo.authenticator.data.db.OtpAccount
77
import at.mcbabo.authenticator.data.repository.OtpAccountRepository
8+
import at.mcbabo.authenticator.data.store.GestureType
89
import at.mcbabo.authenticator.data.store.SortType
910
import at.mcbabo.authenticator.data.store.UserPreferences
1011
import at.mcbabo.authenticator.internal.crypto.AuthType
@@ -63,13 +64,19 @@ class ViewOTPViewModel @Inject constructor(
6364
private val _sortType = MutableStateFlow(SortType.ISSUER)
6465
val sortType: StateFlow<SortType> = _sortType.asStateFlow()
6566

67+
private val _gestureType = MutableStateFlow(GestureType.TAP_TO_COPY)
68+
val gestureType: StateFlow<GestureType> = _gestureType.asStateFlow()
69+
6670
init {
6771
startUpdater()
6872
observeSearchQuery()
6973
viewModelScope.launch {
7074
userPreferences.sortType.collect {
7175
_sortType.value = it
7276
}
77+
userPreferences.gestureType.collect {
78+
_gestureType.value = it
79+
}
7380
}
7481
}
7582

@@ -80,6 +87,13 @@ class ViewOTPViewModel @Inject constructor(
8087
_sortType.value = type
8188
}
8289

90+
fun setGestureType(type: GestureType) {
91+
viewModelScope.launch {
92+
userPreferences.setGestureType(type)
93+
}
94+
_gestureType.value = type
95+
}
96+
8397
fun searchAccounts(query: String) {
8498
_searchQuery.value = query
8599
}

app/src/main/res/values-de/strings.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,6 @@
3737
<string name="privacy_feature_desc">Authentifizierung beim Öffnen der App erforderlich</string>
3838
<string name="appearance">Darstellung</string>
3939
<string name="security">Sicherheit</string>
40+
<string name="choose_tap_gesture">Wähle Tippgeste</string>
41+
<string name="currently">Derzeit: %1$s</string>
4042
</resources>

app/src/main/res/values/strings.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,6 @@
3636
<string name="privacy_feature_desc">Require authentication when opening the app</string>
3737
<string name="appearance">Appearance</string>
3838
<string name="security">Security</string>
39+
<string name="choose_tap_gesture">Choose tap gesture</string>
40+
<string name="currently">Currently: %1$s</string>
3941
</resources>

0 commit comments

Comments
 (0)