Skip to content

Commit

Permalink
Break down large composables in homescreen
Browse files Browse the repository at this point in the history
And some other UI improvements

Signed-off-by: starry-shivam <[email protected]>
  • Loading branch information
starry-shivam committed Apr 24, 2024
1 parent 80293d7 commit c57e789
Show file tree
Hide file tree
Showing 9 changed files with 8,722 additions and 14,202 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class BackupManager(private val context: Context, private val goalDao: GoalDao)
)

log("Creating backup json file inside cache directory...")
val fileName = "Greenstash-Backup (${LocalDateTime.now()}).json"
val fileName = "GreenStash-Backup (${LocalDateTime.now()}).json"
val file = File(context.cacheDir, fileName)
file.updateText(jsonString)
val uri = FileProvider.getUriForFile(context, FILE_PROVIDER_AUTHORITY, file)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ package com.starry.greenstash.ui.screens.home.composables
import androidx.compose.animation.Crossfade
import androidx.compose.animation.core.tween
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.shape.RoundedCornerShape
import androidx.compose.foundation.text.KeyboardActions
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.material.icons.Icons
Expand All @@ -40,9 +41,9 @@ import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.material3.TextField
import androidx.compose.material3.TextFieldDefaults
import androidx.compose.material3.TopAppBar
import androidx.compose.runtime.Composable
Expand Down Expand Up @@ -147,17 +148,15 @@ private fun SearchAppBar(
onSearchClicked: (String) -> Unit,
) {
Surface(
modifier = Modifier
.fillMaxWidth()
.height(56.dp),
modifier = Modifier.fillMaxWidth(),
color = MaterialTheme.colorScheme.surface
) {
TextField(modifier = Modifier
.fillMaxWidth(),
OutlinedTextField(
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 14.dp, vertical = 4.dp),
value = text,
onValueChange = {
onTextChange(it)
},
onValueChange = { onTextChange(it) },
placeholder = {
Text(
text = stringResource(id = R.string.home_search_label),
Expand Down Expand Up @@ -204,9 +203,10 @@ private fun SearchAppBar(
),
colors = TextFieldDefaults.colors(
focusedContainerColor = Color.Transparent,
unfocusedContainerColor = Color.Transparent,
unfocusedContainerColor = MaterialTheme.colorScheme.primaryContainer.copy(0.3f),
disabledContainerColor = Color.Transparent,
cursorColor = MaterialTheme.colorScheme.onSurface.copy(alpha = 0.8f),
))
),
shape = RoundedCornerShape(24.dp))
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
/**
* 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.screens.home.composables

import androidx.compose.foundation.layout.Box
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.width
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.DrawerState
import androidx.compose.material3.HorizontalDivider
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.ModalDrawerSheet
import androidx.compose.material3.NavigationDrawerItem
import androidx.compose.material3.NavigationDrawerItemDefaults
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
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.res.stringResource
import androidx.compose.ui.res.vectorResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.navigation.NavController
import com.starry.greenstash.R
import com.starry.greenstash.ui.navigation.DrawerScreens
import com.starry.greenstash.ui.theme.greenstashFont
import com.starry.greenstash.utils.Utils
import kotlinx.coroutines.launch

@Composable
fun HomeDrawer(drawerState: DrawerState, navController: NavController) {
val items = listOf(DrawerScreens.Home, DrawerScreens.Backups, DrawerScreens.Settings)
val selectedItem = remember { mutableStateOf(items[0]) }
val coroutineScope = rememberCoroutineScope()
ModalDrawerSheet(
modifier = Modifier.width(280.dp),
drawerShape = RoundedCornerShape(4.dp)
) {
Spacer(Modifier.height(14.dp))

Text(
text = Utils.getGreeting(),
modifier = Modifier.padding(start = 16.dp, top = 12.dp),
fontSize = 24.sp,
fontWeight = FontWeight.SemiBold,
fontFamily = greenstashFont,
color = MaterialTheme.colorScheme.onSurface
)

HorizontalDivider(
modifier = Modifier
.fillMaxWidth()
.padding(top = 16.dp, bottom = 16.dp),
thickness = 0.5.dp,
color = MaterialTheme.colorScheme.onSurface.copy(alpha = 0.2f)
)

items.forEach { item ->
NavigationDrawerItem(
icon = {
Icon(
imageVector = ImageVector.vectorResource(id = item.iconResId),
contentDescription = null
)
},
label = {
Text(
text = stringResource(id = item.nameResId),
fontFamily = greenstashFont
)
},
selected = item == selectedItem.value,
onClick = {
selectedItem.value = item
coroutineScope.launch {
drawerState.close()
navController.navigate(item.route)
}
},
modifier = Modifier
.width(280.dp)
.padding(NavigationDrawerItemDefaults.ItemPadding)
)
Spacer(modifier = Modifier.height(4.dp))
}

Spacer(Modifier.weight(1f))

Box(modifier = Modifier.fillMaxWidth(), contentAlignment = Alignment.Center) {
Text(
text = stringResource(id = R.string.drawer_footer_text),
modifier = Modifier.padding(bottom = 18.dp),
fontSize = 12.sp,
fontFamily = greenstashFont,
color = MaterialTheme.colorScheme.onSurface.copy(alpha = 0.8f)
)
}

}
}
Loading

0 comments on commit c57e789

Please sign in to comment.