Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Haptic feedback and improve tip UI #111

Merged
merged 1 commit into from
May 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 1 addition & 14 deletions .idea/deploymentTargetDropDown.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions app/src/main/java/com/starry/greenstash/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -152,16 +152,17 @@ class MainActivity : AppCompatActivity() {
modifier = Modifier.fillMaxSize(),
color = MaterialTheme.colorScheme.background
) {
val navController = rememberNavController()
val startDestination by mainViewModel.startDestination

Crossfade(
targetState = showAppContents,
label = "AppLockCrossFade",
animationSpec = tween(500)
) { showAppContents ->
// show app contents only if user has authenticated.
if (showAppContents.value) {
val navController = rememberNavController()
val screen by mainViewModel.startDestination
NavGraph(navController = navController, screen)
NavGraph(navController = navController, startDestination)
} else {
// show app locked screen if user has not authenticated.
AppLockedScreen(onAuthRequest = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,15 @@ import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.platform.LocalView
import androidx.compose.ui.res.vectorResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.starry.greenstash.R
import com.starry.greenstash.ui.screens.settings.DateStyle
import com.starry.greenstash.ui.theme.greenstashFont
import com.starry.greenstash.utils.weakHapticFeedback
import java.time.LocalDateTime
import java.time.format.DateTimeFormatter

Expand All @@ -55,11 +57,15 @@ fun DateTimeCard(
dateTimeStyle: () -> DateStyle,
onClick: () -> Unit
) {
val view = LocalView.current
Card(
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 18.dp, vertical = 8.dp)
.clickable { onClick() }
.clickable {
view.weakHapticFeedback()
onClick()
}
) {
Row(
modifier = Modifier
Expand Down
125 changes: 125 additions & 0 deletions app/src/main/java/com/starry/greenstash/ui/common/TipCard.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
/**
* 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.animateContentSize
import androidx.compose.animation.expandVertically
import androidx.compose.animation.shrinkVertically
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Lightbulb
import androidx.compose.material3.Button
import androidx.compose.material3.Card
import androidx.compose.material3.CardDefaults
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.starry.greenstash.ui.theme.greenstashFont

@Composable
fun TipCard(
modifier: Modifier = Modifier,
icon: ImageVector = Icons.Filled.Lightbulb,
description: String,
showTipCard: Boolean,
onDismissRequest: () -> Unit
) {
Column(
modifier = Modifier
.fillMaxWidth()
.animateContentSize(),
horizontalAlignment = Alignment.CenterHorizontally
) {
AnimatedVisibility(
visible = showTipCard,
enter = expandVertically(),
exit = shrinkVertically()
) {
Card(
modifier = modifier
.fillMaxWidth()
.padding(bottom = 10.dp),
shape = RoundedCornerShape(16.dp),
colors = CardDefaults.cardColors(
containerColor = MaterialTheme.colorScheme.secondaryContainer
)
) {
Column(
modifier = Modifier.padding(16.dp)
) {
Row(
modifier = Modifier.fillMaxWidth(),
verticalAlignment = Alignment.CenterVertically
) {
Icon(
imageVector = icon,
contentDescription = null,
modifier = Modifier.size(32.dp)
)
Spacer(modifier = Modifier.width(16.dp))
Text(
text = description,
style = MaterialTheme.typography.titleSmall,
fontFamily = greenstashFont,
)
}
Spacer(modifier = Modifier.height(16.dp))
Button(
onClick = { onDismissRequest() },
modifier = Modifier.align(Alignment.End)
) {
Text(text = "OK")
}
}
}
}
}
}

@Preview
@Composable
private fun TipCardPV() {
TipCard(
description = "This is a tip",
showTipCard = true,
onDismissRequest = {}
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalView
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
Expand All @@ -73,6 +74,7 @@ import coil.compose.AsyncImage
import com.starry.greenstash.R
import com.starry.greenstash.ui.screens.backups.BackupViewModel
import com.starry.greenstash.ui.theme.greenstashFont
import com.starry.greenstash.utils.weakHapticFeedback
import kotlinx.coroutines.launch
import java.io.InputStreamReader
import java.io.Reader
Expand All @@ -82,6 +84,7 @@ import java.nio.charset.StandardCharsets
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun BackupScreen(navController: NavController) {
val view = LocalView.current
val context = LocalContext.current
val viewModel = hiltViewModel<BackupViewModel>()

Expand All @@ -102,7 +105,10 @@ fun BackupScreen(navController: NavController) {
fontFamily = greenstashFont
)
}, navigationIcon = {
IconButton(onClick = { navController.navigateUp() }) {
IconButton(onClick = {
view.weakHapticFeedback()
navController.navigateUp()
}) {
Icon(
imageVector = Icons.AutoMirrored.Filled.ArrowBack,
contentDescription = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalView
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.res.vectorResource
import androidx.compose.ui.text.font.FontWeight
Expand Down Expand Up @@ -88,6 +89,7 @@ import com.starry.greenstash.ui.screens.dwscreen.DWViewModel
import com.starry.greenstash.ui.theme.greenstashFont
import com.starry.greenstash.utils.Utils
import com.starry.greenstash.utils.validateAmount
import com.starry.greenstash.utils.weakHapticFeedback
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
Expand All @@ -99,6 +101,7 @@ import java.time.LocalDateTime
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun DWScreen(goalId: String, transactionTypeName: String, navController: NavController) {
val view = LocalView.current
val context = LocalContext.current
val viewModel: DWViewModel = hiltViewModel()

Expand Down Expand Up @@ -141,7 +144,10 @@ fun DWScreen(goalId: String, transactionTypeName: String, navController: NavCont
fontFamily = greenstashFont
)
}, navigationIcon = {
IconButton(onClick = { navController.navigateUp() }) {
IconButton(onClick = {
view.weakHapticFeedback()
navController.navigateUp()
}) {
Icon(
imageVector = Icons.AutoMirrored.Filled.ArrowBack,
contentDescription = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalView
import androidx.compose.ui.unit.dp
import androidx.navigation.NavController
import com.starry.greenstash.MainActivity
Expand All @@ -50,6 +51,8 @@ import com.starry.greenstash.utils.GoalTextUtils
import com.starry.greenstash.utils.ImageUtils
import com.starry.greenstash.utils.Utils
import com.starry.greenstash.utils.getActivity
import com.starry.greenstash.utils.strongHapticFeedback
import com.starry.greenstash.utils.weakHapticFeedback
import kotlinx.coroutines.launch


Expand All @@ -71,6 +74,7 @@ fun GoalLazyColumnItem(
}

val openDeleteDialog = remember { mutableStateOf(false) }
val localView = LocalView.current

when (goalCardStyle) {
GoalCardStyle.Classic -> {
Expand All @@ -90,6 +94,7 @@ fun GoalLazyColumnItem(
goalProgress = progressPercent.toFloat() / 100,
goalImage = item.goal.goalImage,
onDepositClicked = {
localView.weakHapticFeedback()
if (item.getCurrentlySavedAmount() >= item.goal.targetAmount) {
coroutineScope.launch {
snackBarHostState.showSnackbar(context.getString(R.string.goal_already_achieved))
Expand All @@ -104,6 +109,7 @@ fun GoalLazyColumnItem(
}
},
onWithdrawClicked = {
localView.weakHapticFeedback()
if (item.getCurrentlySavedAmount() == 0f.toDouble()) {
coroutineScope.launch {
snackBarHostState.showSnackbar(context.getString(R.string.withdraw_button_error))
Expand All @@ -118,20 +124,25 @@ fun GoalLazyColumnItem(
}
},
onInfoClicked = {
localView.weakHapticFeedback()
navController.navigate(
Screens.GoalInfoScreen.withGoalId(
goalId = item.goal.goalId.toString()
)
)
},
onEditClicked = {
localView.weakHapticFeedback()
navController.navigate(
Screens.InputScreen.withGoalToEdit(
goalId = item.goal.goalId.toString()
)
)
},
onDeleteClicked = { openDeleteDialog.value = true }
onDeleteClicked = {
localView.strongHapticFeedback()
openDeleteDialog.value = true
}
)

}
Expand Down Expand Up @@ -162,6 +173,7 @@ fun GoalLazyColumnItem(
goalProgress = progressPercent.toFloat() / 100,
goalIcon = goalIcon,
onDepositClicked = {
localView.weakHapticFeedback()
if (item.getCurrentlySavedAmount() >= item.goal.targetAmount) {
coroutineScope.launch {
snackBarHostState.showSnackbar(context.getString(R.string.goal_already_achieved))
Expand All @@ -176,6 +188,7 @@ fun GoalLazyColumnItem(
}
},
onWithdrawClicked = {
localView.weakHapticFeedback()
if (item.getCurrentlySavedAmount() == 0f.toDouble()) {
coroutineScope.launch {
snackBarHostState.showSnackbar(context.getString(R.string.withdraw_button_error))
Expand All @@ -190,20 +203,23 @@ fun GoalLazyColumnItem(
}
},
onInfoClicked = {
localView.weakHapticFeedback()
navController.navigate(
Screens.GoalInfoScreen.withGoalId(
goalId = item.goal.goalId.toString()
)
)
},
onEditClicked = {
localView.weakHapticFeedback()
navController.navigate(
Screens.InputScreen.withGoalToEdit(
goalId = item.goal.goalId.toString()
)
)
},
onDeleteClicked = {
localView.strongHapticFeedback()
openDeleteDialog.value = true
}
)
Expand Down
Loading
Loading