Skip to content

Commit

Permalink
Improve onboarding process
Browse files Browse the repository at this point in the history
Signed-off-by: starry-shivam <[email protected]>
  • Loading branch information
starry-shivam committed Mar 29, 2024
1 parent 10e927c commit 21b3f83
Show file tree
Hide file tree
Showing 17 changed files with 744 additions and 426 deletions.
11 changes: 10 additions & 1 deletion app/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,13 @@
-keep class * implements com.google.gson.JsonDeserializer

# Prevent R8 from removing icons used in goal icon picker.
-keep class androidx.compose.material.icons.filled.** { *; }
-keep class androidx.compose.material.icons.filled.** { *; }

# remove Log statements in release builds
-assumenosideeffects class android.util.Log {
public static *** d(...);
public static *** v(...);
public static *** i(...);
public static *** w(...);
public static *** e(...);
}
2 changes: 1 addition & 1 deletion app/src/main/java/com/starry/greenstash/MainViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class MainViewModel @Inject constructor(
_startDestination.value = Screens.WelcomeScreen.route
}

delay(100)
delay(150)
_isLoading.value = false
}
}
Expand Down
180 changes: 180 additions & 0 deletions app/src/main/java/com/starry/greenstash/ui/common/CurrencyPicker.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
/**
* MIT License
*
* Copyright (c) [2022 - Present] Stɑrry Shivɑm
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/


package com.starry.greenstash.ui.common

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.selection.selectable
import androidx.compose.foundation.selection.selectableGroup
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Search
import androidx.compose.material3.Button
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.ModalBottomSheet
import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.RadioButton
import androidx.compose.material3.RadioButtonDefaults
import androidx.compose.material3.Text
import androidx.compose.material3.rememberModalBottomSheetState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.semantics.Role
import androidx.compose.ui.unit.dp
import com.starry.greenstash.R
import com.starry.greenstash.ui.theme.greenstashFont
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext

@ExperimentalMaterial3Api
@Composable
fun CurrencyPicker(
defaultCurrencyValue: String,
currencyNames: Array<String>,
currencyValues: Array<String>,
showBottomSheet: MutableState<Boolean>,
onCurrencySelected: (String) -> Unit
) {
val defaultCurrencyEntry = currencyNames[currencyValues.indexOf(defaultCurrencyValue)]
val (selectedCurrencyOption, onCurrencyOptionSelected) = remember {
mutableStateOf(defaultCurrencyEntry)
}
val (searchText, onSearchTextChanged) = remember { mutableStateOf("") }
val filteredCurrencies = currencyNames.filter { it.contains(searchText, ignoreCase = true) }

val coroutineScope = rememberCoroutineScope()
val sheetState = rememberModalBottomSheetState()

if (showBottomSheet.value) {
ModalBottomSheet(
sheetState = sheetState,
onDismissRequest = {
coroutineScope.launch {
sheetState.hide()
delay(300)
withContext(Dispatchers.Main) {
showBottomSheet.value = false
val choice = currencyValues[currencyNames.indexOf(selectedCurrencyOption)]
onCurrencySelected(choice)
}
}
},
content = {
Column {
OutlinedTextField(
value = searchText,
onValueChange = onSearchTextChanged,
modifier = Modifier
.fillMaxWidth()
.padding(16.dp),
placeholder = { Text("Search currency") },
leadingIcon = {
Icon(
imageVector = Icons.Default.Search,
contentDescription = "Search"
)
}, shape = RoundedCornerShape(12.dp)
)
Column(
modifier = Modifier
.selectableGroup()
.verticalScroll(rememberScrollState())
) {
filteredCurrencies.forEach { text ->
Row(
modifier = Modifier
.fillMaxWidth()
.height(46.dp)
.selectable(
selected = (text == selectedCurrencyOption),
onClick = {
onCurrencyOptionSelected(text)
},
role = Role.RadioButton
),
verticalAlignment = Alignment.CenterVertically
) {
Row(modifier = Modifier.padding(horizontal = 18.dp)) {
RadioButton(
selected = (text == selectedCurrencyOption),
onClick = null,
colors = RadioButtonDefaults.colors(
selectedColor = MaterialTheme.colorScheme.primary,
unselectedColor = MaterialTheme.colorScheme.inversePrimary,
disabledSelectedColor = Color.Black,
disabledUnselectedColor = Color.Black
)
)
Text(
text = text,
modifier = Modifier.padding(start = 16.dp),
color = MaterialTheme.colorScheme.onSurface,
fontFamily = greenstashFont
)
}
}
}
}
}
Button(
modifier = Modifier
.fillMaxWidth()
.padding(16.dp),
onClick = {
coroutineScope.launch {
sheetState.hide()
delay(300)
withContext(Dispatchers.Main) {
showBottomSheet.value = false
val choice =
currencyValues[currencyNames.indexOf(selectedCurrencyOption)]
onCurrencySelected(choice)
}
}
}
) {
Text(stringResource(id = R.string.confirm), fontFamily = greenstashFont)
}
}
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,10 @@ import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.hapticfeedback.HapticFeedbackType
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.platform.LocalHapticFeedback
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.res.vectorResource
import androidx.compose.ui.text.font.FontWeight
Expand Down Expand Up @@ -538,13 +540,18 @@ fun FilterButton(text: String, isSelected: Boolean, onClick: () -> Unit) {
textColor = MaterialTheme.colorScheme.onSecondaryContainer
}

val haptic = LocalHapticFeedback.current

Card(
modifier = Modifier
.height(60.dp)
.padding(6.dp),
colors = CardDefaults.cardColors(containerColor = buttonColor),
shape = RoundedCornerShape(14.dp),
onClick = onClick
onClick = {
haptic.performHapticFeedback(HapticFeedbackType.LongPress)
onClick()
}
) {
Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
Text(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ class HomeViewModel @Inject constructor(

private val _showOnboardingTapTargets: MutableState<Boolean> = mutableStateOf(
value = preferenceUtil.getBoolean(
PreferenceUtil.SHOW_ONBOARDING_TAP_TARGETS_BOOL,
PreferenceUtil.HOME_SCREEN_ONBOARDING_BOOL,
true
)
)
Expand Down Expand Up @@ -163,7 +163,7 @@ class HomeViewModel @Inject constructor(
}

fun onboardingTapTargetsShown() {
preferenceUtil.putBoolean(PreferenceUtil.SHOW_ONBOARDING_TAP_TARGETS_BOOL, false)
preferenceUtil.putBoolean(PreferenceUtil.HOME_SCREEN_ONBOARDING_BOOL, false)
_showOnboardingTapTargets.value = false
}

Expand Down
Loading

0 comments on commit 21b3f83

Please sign in to comment.