Skip to content

Commit

Permalink
Add onclick actions and fix statusbar icon colors on theme change
Browse files Browse the repository at this point in the history
Signed-off-by: starry-shivam <[email protected]>
  • Loading branch information
starry-shivam committed May 7, 2024
1 parent ae03244 commit 75e7166
Show file tree
Hide file tree
Showing 17 changed files with 237 additions and 90 deletions.
8 changes: 8 additions & 0 deletions .idea/deploymentTargetSelector.xml

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

2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ android {
minSdk 24
targetSdk 34
versionCode 350
versionName "3.5.0"
versionName "3.6.0-dev"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
Expand Down
9 changes: 5 additions & 4 deletions app/src/main/java/com/starry/greenstash/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ import androidx.navigation.compose.rememberNavController
import com.starry.greenstash.ui.navigation.NavGraph
import com.starry.greenstash.ui.screens.other.AppLockedScreen
import com.starry.greenstash.ui.screens.settings.SettingsViewModel
import com.starry.greenstash.ui.screens.settings.ThemeMode
import com.starry.greenstash.ui.theme.FixStatusBarIconsOnDarkTheme
import com.starry.greenstash.ui.theme.AdjustEdgeToEdge
import com.starry.greenstash.ui.theme.GreenStashTheme
import com.starry.greenstash.utils.Utils
import com.starry.greenstash.utils.toToast
Expand Down Expand Up @@ -140,10 +139,12 @@ class MainActivity : AppCompatActivity() {
private fun setAppContents(showAppContents: State<Boolean>) {
setContent {
GreenStashTheme(settingsViewModel = settingsViewModel) {
FixStatusBarIconsOnDarkTheme(
darkTheme = settingsViewModel.getCurrentTheme() == ThemeMode.Dark,
// fix status bar icon color in dark mode.
AdjustEdgeToEdge(
activity = this,
themeState = settingsViewModel.getCurrentTheme()
)

Surface(
modifier = Modifier.fillMaxSize(),
color = MaterialTheme.colorScheme.background
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@

package com.starry.greenstash.ui.screens.home.composables

import android.content.ActivityNotFoundException
import android.content.Context
import android.content.Intent
import android.net.Uri
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Row
Expand Down Expand Up @@ -54,6 +58,7 @@ import androidx.compose.runtime.rememberCoroutineScope
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
Expand All @@ -67,7 +72,9 @@ import coil.compose.AsyncImage
import com.starry.greenstash.R
import com.starry.greenstash.ui.navigation.DrawerScreens
import com.starry.greenstash.ui.screens.settings.ThemeMode
import com.starry.greenstash.ui.screens.settings.composables.AboutLinks
import com.starry.greenstash.ui.theme.greenstashFont
import com.starry.greenstash.utils.Utils
import com.starry.greenstash.utils.weakHapticFeedback
import kotlinx.coroutines.launch

Expand All @@ -78,6 +85,7 @@ fun HomeDrawer(drawerState: DrawerState, navController: NavController, themeMode
val selectedItem = remember { mutableStateOf(items[0]) }

val view = LocalView.current
val context = LocalContext.current
val coroutineScope = rememberCoroutineScope()

ModalDrawerSheet(
Expand All @@ -97,7 +105,7 @@ fun HomeDrawer(drawerState: DrawerState, navController: NavController, themeMode
.size(60.dp)
.background(
color = if (themeMode == ThemeMode.Light) MaterialTheme.colorScheme.onSurface
else MaterialTheme.colorScheme.surface,
else MaterialTheme.colorScheme.onSurface.copy(alpha = 0.15f),
shape = CircleShape
)
) {
Expand All @@ -123,7 +131,7 @@ fun HomeDrawer(drawerState: DrawerState, navController: NavController, themeMode
.fillMaxWidth()
.padding(bottom = 16.dp),
thickness = 0.5.dp,
color = MaterialTheme.colorScheme.onSurface.copy(alpha = 0.2f)
color = MaterialTheme.colorScheme.onSurface.copy(alpha = 0.4f)
)

items.forEach { item ->
Expand Down Expand Up @@ -160,15 +168,20 @@ fun HomeDrawer(drawerState: DrawerState, navController: NavController, themeMode
.fillMaxWidth()
.padding(top = 14.dp, bottom = 14.dp),
thickness = 0.5.dp,
color = MaterialTheme.colorScheme.onSurface.copy(alpha = 0.2f)
color = MaterialTheme.colorScheme.onSurface.copy(alpha = 0.4f)
)

// Non-navigational items in the drawer ========================================

NavigationDrawerItem(
modifier = Modifier
.width(280.dp)
.padding(NavigationDrawerItemDefaults.ItemPadding),
selected = false,
onClick = { view.weakHapticFeedback() },
onClick = {
view.weakHapticFeedback()
onRatingClick(context)
},
icon = {
Icon(
imageVector = ImageVector.vectorResource(id = R.drawable.ic_nav_rating),
Expand All @@ -188,7 +201,10 @@ fun HomeDrawer(drawerState: DrawerState, navController: NavController, themeMode
.width(280.dp)
.padding(NavigationDrawerItemDefaults.ItemPadding),
selected = false,
onClick = { view.weakHapticFeedback() },
onClick = {
view.weakHapticFeedback()
onShareClick(context)
},
icon = {
Icon(
imageVector = ImageVector.vectorResource(id = R.drawable.ic_nav_share),
Expand All @@ -208,7 +224,10 @@ fun HomeDrawer(drawerState: DrawerState, navController: NavController, themeMode
.width(280.dp)
.padding(NavigationDrawerItemDefaults.ItemPadding),
selected = false,
onClick = { view.weakHapticFeedback() },
onClick = {
view.weakHapticFeedback()
onPrivacyClick(context)
},
icon = {
Icon(
imageVector = ImageVector.vectorResource(id = R.drawable.ic_nav_privacy),
Expand Down Expand Up @@ -238,6 +257,42 @@ fun HomeDrawer(drawerState: DrawerState, navController: NavController, themeMode
}
}

private fun onRatingClick(context: Context) {
try {
context.startActivity(
Intent(
Intent.ACTION_VIEW,
Uri.parse("market://details?id=${context.packageName}")
)
)
} catch (e: ActivityNotFoundException) {
Utils.openWebLink(
context = context,
url = "https://play.google.com/store/apps/details?id=${context.packageName}"
)
}
}

private fun onShareClick(context: Context) {
val shareMessage =
context.getString(
R.string.drawer_share_message,
"https://play.google.com/store/apps/details?id=${context.packageName}"
).trimIndent()
val shareIntent = Intent(Intent.ACTION_SEND).apply {
type = "text/plain"
putExtra(Intent.EXTRA_TEXT, shareMessage)
}
context.startActivity(Intent.createChooser(shareIntent, null))
}

private fun onPrivacyClick(context: Context) {
Utils.openWebLink(
context = context,
url = AboutLinks.PrivacyPolicy.url
)
}

@Preview
@Composable
private fun HomeDrawerPV() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,26 @@

package com.starry.greenstash.ui.screens.info.composables

import androidx.compose.foundation.layout.Arrangement
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.selection.selectableGroup
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Check
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.OutlinedCard
import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.OutlinedTextFieldDefaults
import androidx.compose.material3.RadioButton
import androidx.compose.material3.SegmentedButton
import androidx.compose.material3.SegmentedButtonDefaults
import androidx.compose.material3.SingleChoiceSegmentedButtonRow
import androidx.compose.material3.Text
import androidx.compose.material3.rememberModalBottomSheetState
import androidx.compose.runtime.Composable
Expand All @@ -52,7 +53,6 @@ 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.vector.ImageVector
import androidx.compose.ui.platform.LocalContext
Expand Down Expand Up @@ -132,39 +132,59 @@ fun EditTransactionSheet(
.fillMaxWidth()
.padding(8.dp)
) {
OutlinedCard(
SingleChoiceSegmentedButtonRow(
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 18.dp, vertical = 6.dp)
) {
Row(
modifier = Modifier
.fillMaxWidth()
.selectableGroup(),
horizontalArrangement = Arrangement.SpaceEvenly,
) {
Row(verticalAlignment = Alignment.CenterVertically) {
RadioButton(
selected = selectedTransactionType == TransactionType.Deposit.name,
onClick = { onTransactionTypeSelected(TransactionType.Deposit.name) },
)
SegmentedButton(
selected = selectedTransactionType == TransactionType.Deposit.name,
onClick = { onTransactionTypeSelected(TransactionType.Deposit.name) },
shape = RoundedCornerShape(topStart = 14.dp, bottomStart = 14.dp),
label = {
Text(
text = TransactionType.Deposit.name,
fontFamily = greenstashFont
text = TransactionType.Deposit.name, fontFamily = greenstashFont
)
}
},
icon = {
if (selectedTransactionType == TransactionType.Deposit.name) {
Icon(
imageVector = Icons.Filled.Check,
contentDescription = null,
modifier = Modifier.size(16.dp)
)
}
},
colors = SegmentedButtonDefaults.colors(
activeContentColor = MaterialTheme.colorScheme.onPrimary,
activeContainerColor = MaterialTheme.colorScheme.primary,
)
)

Row(verticalAlignment = Alignment.CenterVertically) {
RadioButton(
selected = selectedTransactionType == TransactionType.Withdraw.name,
onClick = { onTransactionTypeSelected(TransactionType.Withdraw.name) },
)
SegmentedButton(
selected = selectedTransactionType == TransactionType.Withdraw.name,
onClick = { onTransactionTypeSelected(TransactionType.Withdraw.name) },
shape = RoundedCornerShape(topEnd = 14.dp, bottomEnd = 14.dp),
label = {
Text(
text = TransactionType.Withdraw.name,
fontFamily = greenstashFont
)
}
}
},
icon = {
if (selectedTransactionType == TransactionType.Withdraw.name) {
Icon(
imageVector = Icons.Filled.Check,
contentDescription = null,
modifier = Modifier.size(16.dp)
)
}
},
colors = SegmentedButtonDefaults.colors(
activeContentColor = MaterialTheme.colorScheme.onPrimary,
activeContainerColor = MaterialTheme.colorScheme.primary,
)
)
}

DateTimeCard(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ fun InputScreen(editGoalId: String?, navController: NavController) {

GoalPriorityMenu(
selectedPriority = viewModel.state.priority,
obPriorityChanged = { newValue ->
onPriorityChanged = { newValue ->
viewModel.updatePriority(newValue)
}
)
Expand Down Expand Up @@ -630,7 +630,7 @@ private fun IconPickerCard(

@OptIn(ExperimentalMaterial3Api::class)
@Composable
private fun GoalPriorityMenu(selectedPriority: String, obPriorityChanged: (String) -> Unit) {
private fun GoalPriorityMenu(selectedPriority: String, onPriorityChanged: (String) -> Unit) {
Card(
modifier = Modifier.fillMaxWidth(0.86f), colors = CardDefaults.cardColors(
containerColor = MaterialTheme.colorScheme.primaryContainer
Expand Down Expand Up @@ -658,7 +658,7 @@ private fun GoalPriorityMenu(selectedPriority: String, obPriorityChanged: (Strin
) {
SegmentedButton(
selected = selectedPriority == GoalPriority.High.name,
onClick = { obPriorityChanged(GoalPriority.High.name) },
onClick = { onPriorityChanged(GoalPriority.High.name) },
shape = RoundedCornerShape(topStart = 14.dp, bottomStart = 14.dp),
label = {
Text(
Expand All @@ -684,7 +684,7 @@ private fun GoalPriorityMenu(selectedPriority: String, obPriorityChanged: (Strin

SegmentedButton(
selected = selectedPriority == GoalPriority.Normal.name,
onClick = { obPriorityChanged(GoalPriority.Normal.name) },
onClick = { onPriorityChanged(GoalPriority.Normal.name) },
shape = RectangleShape,
label = {
Text(
Expand All @@ -710,7 +710,7 @@ private fun GoalPriorityMenu(selectedPriority: String, obPriorityChanged: (Strin

SegmentedButton(
selected = selectedPriority == GoalPriority.Low.name,
onClick = { obPriorityChanged(GoalPriority.Low.name) },
onClick = { onPriorityChanged(GoalPriority.Low.name) },
shape = RoundedCornerShape(topEnd = 14.dp, bottomEnd = 14.dp),
label = {
Text(
Expand Down
Loading

0 comments on commit 75e7166

Please sign in to comment.