Skip to content

Commit

Permalink
Fix sorting order and add a tip about swipe functionality
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 30, 2024
1 parent 20be0f3 commit d70ef5f
Show file tree
Hide file tree
Showing 11 changed files with 108 additions and 30 deletions.
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 }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ fun EditTransactionSheet(
shape = RoundedCornerShape(12.dp),
) {
Text(
text = stringResource(id = R.string.edit_transaction_button),
text = stringResource(id = R.string.info_edit_transaction_button),
fontFamily = greenstashFont
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,18 @@ import androidx.compose.material3.IconButton
import androidx.compose.material3.LinearProgressIndicator
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Scaffold
import androidx.compose.material3.SnackbarDuration
import androidx.compose.material3.SnackbarHost
import androidx.compose.material3.SnackbarHostState
import androidx.compose.material3.SnackbarResult
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBar
import androidx.compose.material3.surfaceColorAtElevation
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
Expand Down Expand Up @@ -111,26 +116,32 @@ fun GoalInfoScreen(goalId: String, navController: NavController) {
val state = viewModel.state
val context = LocalContext.current

val snackBarHostState = remember { SnackbarHostState() }

LaunchedEffect(key1 = true, block = { viewModel.loadGoalData(goalId.toLong()) })

Scaffold(modifier = Modifier.fillMaxSize(), topBar = {
TopAppBar(
modifier = Modifier.fillMaxWidth(),
title = {
Text(
text = stringResource(id = R.string.info_screen_header),
maxLines = 1,
overflow = TextOverflow.Ellipsis,
fontFamily = greenstashFont
)
}, navigationIcon = {
IconButton(onClick = { navController.navigateUp() }) {
Icon(
imageVector = Icons.AutoMirrored.Filled.ArrowBack, contentDescription = null
Scaffold(
modifier = Modifier.fillMaxSize(),
snackbarHost = { SnackbarHost(snackBarHostState) },
topBar = {
TopAppBar(
modifier = Modifier.fillMaxWidth(),
title = {
Text(
text = stringResource(id = R.string.info_screen_header),
maxLines = 1,
overflow = TextOverflow.Ellipsis,
fontFamily = greenstashFont
)
}
})
}) {
}, navigationIcon = {
IconButton(onClick = { navController.navigateUp() }) {
Icon(
imageVector = Icons.AutoMirrored.Filled.ArrowBack,
contentDescription = null
)
}
})
}) {
Column(
modifier = Modifier
.fillMaxSize()
Expand Down Expand Up @@ -175,7 +186,25 @@ fun GoalInfoScreen(goalId: String, navController: NavController) {
Spacer(modifier = Modifier.height(6.dp))
}
if (goalData.transactions.isNotEmpty()) {
TransactionItem(goalData.transactions.reversed(), currencySymbol, viewModel)
TransactionItem(goalData.getOrderedTransactions(), currencySymbol, viewModel)
// Show tooltip for library screen.
LaunchedEffect(key1 = true) {
if (viewModel.shouldShowTransactionTip()) {
val result = snackBarHostState.showSnackbar(
message = context.getString(R.string.info_transaction_onboarding_tip),
actionLabel = context.getString(R.string.ok),
duration = SnackbarDuration.Indefinite
)

when (result) {
SnackbarResult.ActionPerformed -> {
viewModel.transactionTipDismissed()
}

SnackbarResult.Dismissed -> {}
}
}
}
} else {
Column(
modifier = Modifier.fillMaxWidth(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,6 @@ class InfoViewModel @Inject constructor(
)
}

fun getDateStyleValue() = preferenceUtil.getString(
PreferenceUtil.DATE_FORMAT_STR, DateStyle.DateMonthYear.pattern
)

fun deleteTransaction(transaction: Transaction) {
viewModelScope.launch(Dispatchers.IO) {
transactionDao.deleteTransaction(transaction)
Expand All @@ -112,4 +108,17 @@ class InfoViewModel @Inject constructor(
fun getDefaultCurrencyValue() = preferenceUtil.getString(
PreferenceUtil.DEFAULT_CURRENCY_STR, "$"
)!!

fun getDateStyleValue() = preferenceUtil.getString(
PreferenceUtil.DATE_FORMAT_STR, DateStyle.DateMonthYear.pattern
)

fun shouldShowTransactionTip() = preferenceUtil.getBoolean(
PreferenceUtil.INFO_TRANSACTION_SWIPE_TIP_BOOL, true
)

fun transactionTipDismissed() = preferenceUtil.putBoolean(
PreferenceUtil.INFO_TRANSACTION_SWIPE_TIP_BOOL, false
)

}
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ import androidx.compose.foundation.verticalScroll
import androidx.compose.material.ExperimentalMaterialApi
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.ArrowBack
import androidx.compose.material.icons.filled.Check
import androidx.compose.material.icons.filled.Image
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.Button
Expand All @@ -78,6 +79,7 @@ import androidx.compose.material3.SnackbarHost
import androidx.compose.material3.SnackbarHostState
import androidx.compose.material3.SnackbarResult
import androidx.compose.material3.Switch
import androidx.compose.material3.SwitchDefaults
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.material3.TopAppBar
Expand Down Expand Up @@ -834,6 +836,17 @@ fun GoalReminderMenu(
launcher.launch(Manifest.permission.POST_NOTIFICATIONS)
}
},
thumbContent = if (viewModel.state.reminder) {
{
Icon(
imageVector = Icons.Filled.Check,
contentDescription = null,
modifier = Modifier.size(SwitchDefaults.IconSize),
)
}
} else {
null
},
modifier = modifier
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,12 @@ import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Check
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Switch
import androidx.compose.material3.SwitchDefaults
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.MutableState
Expand All @@ -50,8 +53,8 @@ fun SettingsItem(title: String, description: String, icon: ImageVector, onClick:
Row(
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 8.dp, vertical = 14.dp)
.clickable { onClick() },
.clickable { onClick() }
.padding(horizontal = 8.dp, vertical = 14.dp),
verticalAlignment = Alignment.CenterVertically,
) {
Icon(
Expand Down Expand Up @@ -133,6 +136,17 @@ fun SettingsItem(
haptic.performHapticFeedback(HapticFeedbackType.LongPress)
onCheckChange(it)
},
thumbContent = if (switchState.value) {
{
Icon(
imageVector = Icons.Filled.Check,
contentDescription = null,
modifier = Modifier.size(SwitchDefaults.IconSize),
)
}
} else {
null
},
modifier = Modifier.padding(start = 12.dp, end = 12.dp)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class PreferenceUtil(context: Context) {
// Onboarding preferences
const val HOME_SCREEN_ONBOARDING_BOOL = "show_home_screen_onboarding"
const val INPUT_SCREEN_ONBOARDING_BOOL = "show_input_onboarding"
const val INFO_TRANSACTION_SWIPE_TIP_BOOL = "show_info_transaction_swipe_tip"
}

private var prefs: SharedPreferences
Expand Down
4 changes: 3 additions & 1 deletion app/src/main/res/values-es/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<!-- Other Strings -->
<string name="confirm">Confirmar</string>
<string name="cancel">Cancelar</string>
<string name="ok">Aceptar</string>
<string name="unknown_error">¡Vaya! Algo salió mal.</string>

<!-- Navigation Drawer -->
Expand Down Expand Up @@ -89,7 +90,8 @@
<string name="info_reminder_status_off">Los recordatorios están desactivados</string>
<string name="info_notes_card_title">Notas</string>
<string name="info_goal_no_transactions">Sin transacciones aún.</string>
<string name="edit_transaction_button">Actualizar Transacción</string>
<string name="info_edit_transaction_button">Actualizar Transacción</string>
<string name="info_transaction_onboarding_tip">Consejo: Desliza las transacciones hacia la izquierda o hacia la derecha para editarlas o eliminarlas.</string>

<!-- Input (New/Edit Goal) Screen -->
<string name="input_screen_header">¡Es momento de ahorrar!</string>
Expand Down
4 changes: 3 additions & 1 deletion app/src/main/res/values-tr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<!-- Other Strings -->
<string name="confirm">Onayla</string>
<string name="cancel">İptal</string>
<string name="ok">Tamam</string>
<string name="unknown_error">Hoop! bir şeyler yanlış gitti.</string>

<!-- Navigation Drawer -->
Expand Down Expand Up @@ -89,7 +90,8 @@
<string name="info_reminder_status_off">Hatırlatıcılar devre dışı</string>
<string name="info_notes_card_title">Notlar</string>
<string name="info_goal_no_transactions">Henüz İşlem Yok.</string>
<string name="edit_transaction_button">İşlemi Güncelle</string>
<string name="info_edit_transaction_button">İşlemi Güncelle</string>
<string name="info_transaction_onboarding_tip">İpucu: İşlemleri düzenlemek veya silmek için sola veya sağa kaydırın.</string>

<!-- Input (New/Edit Goal) Screen -->
<string name="input_screen_header">Birikim yapma zamanı!</string>
Expand Down
4 changes: 3 additions & 1 deletion app/src/main/res/values-zh-rCN/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<!-- Other Strings -->
<string name="confirm">确认</string>
<string name="cancel">取消</string>
<string name="ok">确定</string>
<string name="unknown_error">糟糕!出了点问题。</string>

<!-- Navigation Drawer -->
Expand Down Expand Up @@ -89,7 +90,8 @@
<string name="info_reminder_status_off">提醒已禁用</string>
<string name="info_notes_card_title">备注</string>
<string name="info_goal_no_transactions">尚无收支。</string>
<string name="edit_transaction_button">更新交易</string>
<string name="info_edit_transaction_button">更新交易</string>
<string name="info_transaction_onboarding_tip">提示:左右滑动交易以编辑或删除它们。</string>

<!-- Input (New/Edit Goal) Screen -->
<string name="input_screen_header">省钱时间到!</string>
Expand Down
6 changes: 4 additions & 2 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<!-- Other Strings -->
<string name="confirm">Confirm</string>
<string name="cancel">Cancel</string>
<string name="ok" >OK</string>
<string name="unknown_error">Oops! something went wrong.</string>

<!-- Navigation Drawer -->
Expand Down Expand Up @@ -89,7 +90,8 @@
<string name="info_reminder_status_off">Reminders are disabled</string>
<string name="info_notes_card_title">Notes</string>
<string name="info_goal_no_transactions">No Transactions Yet.</string>
<string name="edit_transaction_button">Update Transaction</string>
<string name="info_edit_transaction_button">Update Transaction</string>
<string name="info_transaction_onboarding_tip">Tip: Swipe transactions left or right to edit or delete them.</string>

<!-- Input (New/Edit Goal) Screen -->
<string name="input_screen_header">It\'s time to save!</string>
Expand All @@ -102,7 +104,7 @@
<string name="input_pick_image_onboarding_title">Add images to your goals to give them a personalized look!</string>
<string name="input_pick_image_onboarding_desc">Click on the floating action button to add an image to your goal.</string>
<string name="input_page_quote" translatable="false">You don’t have to see the whole staircase, just take the first step. – Martin Luther King, Jr. </string>
<string name="input_goal_priority">Select priority for this goal.</string>
<string name="input_goal_priority">Select priority for your goal.</string>
<string name="input_goal_reminder">Saving Reminders</string>
<string name="input_goal_reminders_onboarding_title">Enable Reminders to Stay Updated on Your Goals!</string>
<string name="input_goal_reminders_onboarding_desc">Reminders will be sent daily, semiweekly, or weekly, depending on goal priority.</string>
Expand Down

0 comments on commit d70ef5f

Please sign in to comment.