Skip to content

Commit

Permalink
Complete app-wide UI / UX overhaul (#82)
Browse files Browse the repository at this point in the history
--------
Signed-off-by: starry-shivam <[email protected]>
  • Loading branch information
starry-shivam authored Mar 30, 2024
1 parent 6971d97 commit b825973
Show file tree
Hide file tree
Showing 60 changed files with 22,856 additions and 115,017 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ dependencies {
implementation 'com.maxkeppeler.sheets-compose-dialogs:core:1.3.0'
implementation 'com.maxkeppeler.sheets-compose-dialogs:calendar:1.3.0'
implementation 'com.maxkeppeler.sheets-compose-dialogs:date-time:1.3.0'
// Swipe actions.
implementation "me.saket.swipe:swipe:1.2.0"
// Taptarget compose.
implementation "com.pierfrancescosoffritti.taptargetcompose:core:1.1.0"
// Lottie animations.
implementation "com.airbnb.android:lottie-compose:4.1.0"
// Bio-metric authentication.
Expand Down
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(...);
}
10 changes: 1 addition & 9 deletions app/src/main/java/com/starry/greenstash/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,9 @@ import androidx.compose.material.ExperimentalMaterialApi
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.surfaceColorAtElevation
import androidx.compose.runtime.getValue
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import androidx.core.content.ContextCompat
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
import androidx.lifecycle.ViewModelProvider
Expand Down Expand Up @@ -78,12 +76,6 @@ class MainActivity : AppCompatActivity() {
settingsViewModel = ViewModelProvider(this)[SettingsViewModel::class.java]
mainViewModel = ViewModelProvider(this)[MainViewModel::class.java]

// Setup app theme according to user's settings.
ThemeMode.entries.find { it.ordinal == settingsViewModel.getThemeValue() }
?.let { settingsViewModel.setTheme(it) }
settingsViewModel.setMaterialYou(settingsViewModel.getMaterialYouValue())


// show splash screen until we figure out start nav destination.
installSplashScreen().setKeepOnScreenCondition {
mainViewModel.isLoading.value
Expand Down Expand Up @@ -150,7 +142,7 @@ class MainActivity : AppCompatActivity() {
)

systemUiController.setStatusBarColor(
color = MaterialTheme.colorScheme.surfaceColorAtElevation(4.dp),
color = MaterialTheme.colorScheme.surface,
darkIcons = settingsViewModel.getCurrentTheme() == ThemeMode.Light
)

Expand Down
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
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,8 @@ data class GoalWithTransactions(
}
}
}

fun getOrderedTransactions(): List<Transaction> {
return transactions.sortedByDescending { it.timeStamp }
}
}
23 changes: 23 additions & 0 deletions app/src/main/java/com/starry/greenstash/other/WelcomeDataStore.kt
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class WelcomeDataStore(context: Context) {

private object PreferencesKey {
val onBoardingKey = booleanPreferencesKey(name = "on_boarding_completed")
val newGoalTapTargetKey = booleanPreferencesKey(name = "new_goal_tap_target")
}

suspend fun saveOnBoardingState(completed: Boolean) {
Expand All @@ -66,4 +67,26 @@ class WelcomeDataStore(context: Context) {
onBoardingState
}
}

suspend fun saveNewGoalTapTargetState(completed: Boolean) {
dataStore.edit { preferences ->
preferences[PreferencesKey.newGoalTapTargetKey] = completed
}
}

fun readNewGoalTapTargetState(): Flow<Boolean> {
return dataStore.data
.catch { exception ->
if (exception is IOException) {
emit(emptyPreferences())
} else {
throw exception
}
}
.map { preferences ->
val newGoalTapTargetState = preferences[PreferencesKey.newGoalTapTargetKey] ?: false
newGoalTapTargetState
}
}

}
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 @@ -23,6 +23,7 @@ import androidx.compose.ui.draw.clip
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.starry.greenstash.ui.theme.greenstashFont

@Composable
fun SelectableChipGroup(
Expand Down Expand Up @@ -81,7 +82,8 @@ fun Chip(
Text(
text = title,
color = MaterialTheme.colorScheme.onPrimary,
fontSize = 16.sp
fontSize = 16.sp,
fontFamily = greenstashFont
)

}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/**
* 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.animation.AnimatedVisibility
import androidx.compose.animation.expandVertically
import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
import androidx.compose.animation.shrinkVertically
import androidx.compose.animation.slideInVertically
import androidx.compose.animation.slideOutVertically
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import kotlinx.coroutines.delay

@Composable
fun SlideInAnimatedContainer(
initialDelay: Long, content:
@Composable () -> Unit
) {
val showContent = remember { mutableStateOf(false) }
LaunchedEffect(key1 = true) {
delay(initialDelay)
showContent.value = true
}

AnimatedVisibility(
visible = showContent.value,
enter = slideInVertically { it / 2 } + expandVertically(expandFrom = Alignment.Top) + fadeIn(
initialAlpha = 0.3f
),
exit = slideOutVertically() + shrinkVertically() + fadeOut(),
) {
content()
}
}
Loading

0 comments on commit b825973

Please sign in to comment.