Skip to content

Commit 68c5af1

Browse files
author
achint2093
committed
Ui improved, update note,
transitions added
1 parent 70c8a77 commit 68c5af1

File tree

8 files changed

+192
-81
lines changed

8 files changed

+192
-81
lines changed

app/src/main/AndroidManifest.xml

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
android:name=".MainActivity"
1818
android:exported="true"
1919
android:label="@string/app_name"
20-
android:theme="@style/Theme.Notes">
20+
android:theme="@style/Theme.Notes"
21+
android:windowSoftInputMode="adjustResize">
2122
<intent-filter>
2223
<action android:name="android.intent.action.MAIN" />
2324

app/src/main/java/com/techuntried/notes/MainActivity.kt

+36-37
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ package com.techuntried.notes
33
import android.os.Bundle
44
import androidx.activity.ComponentActivity
55
import androidx.activity.compose.setContent
6+
import androidx.compose.animation.AnimatedContentTransitionScope
7+
import androidx.compose.animation.core.tween
8+
import androidx.compose.animation.fadeIn
69
import androidx.compose.material3.ExperimentalMaterial3Api
710
import androidx.compose.runtime.Composable
811
import androidx.navigation.NavHostController
@@ -19,7 +22,6 @@ import dagger.hilt.android.AndroidEntryPoint
1922

2023
@AndroidEntryPoint
2124
class MainActivity : ComponentActivity() {
22-
@OptIn(ExperimentalMaterial3Api::class)
2325
override fun onCreate(savedInstanceState: Bundle?) {
2426
super.onCreate(savedInstanceState)
2527
setContent {
@@ -31,37 +33,24 @@ class MainActivity : ComponentActivity() {
3133
}
3234
}
3335

34-
//@OptIn(ExperimentalMaterial3Api::class)
35-
//@Composable
36-
//fun Toolbar(navController: NavHostController) {
37-
// val destination: NavDestination? =
38-
// navController.currentBackStackEntryAsState().value?.destination
39-
// val route = destination?.route
40-
// val title = when (route) {
41-
// Screens.HomeScreen.route -> "Home"
42-
// Screens.NoteScreen.route -> "Add note"
43-
// else -> ""
44-
// }
45-
// val context = LocalContext.current
46-
// TopAppBar(
47-
// title = { Text(text = title) },
48-
// actions = {
49-
// if (route == Screens.NoteScreen.route) {
50-
// IconButton(
51-
// onClick = {})
52-
// {
53-
// Icon(Icons.Default.Delete, "")
54-
// }
55-
// }
56-
//
57-
// }
58-
// )
59-
//}
60-
6136
@Composable
6237
fun App(navController: NavHostController) {
6338
NavHost(navController = navController, startDestination = Screens.HomeScreen.route) {
64-
composable(Screens.HomeScreen.route) {
39+
composable(Screens.HomeScreen.route,
40+
enterTransition = {
41+
return@composable fadeIn(tween(1000))
42+
},
43+
exitTransition = {
44+
return@composable slideOutOfContainer(
45+
AnimatedContentTransitionScope.SlideDirection.Start, tween(700)
46+
)
47+
}, popEnterTransition = {
48+
return@composable slideIntoContainer(
49+
AnimatedContentTransitionScope.SlideDirection.End, tween(700)
50+
)
51+
}
52+
)
53+
{
6554
HomeScreen(
6655
onAddClick =
6756
{
@@ -74,14 +63,24 @@ fun App(navController: NavHostController) {
7463
)
7564
}
7665

77-
composable(Screens.NoteScreen.route, arguments = listOf(
78-
navArgument("id") {
79-
type = NavType.LongType
80-
defaultValue = -1L
81-
}
82-
)) {
66+
composable(Screens.NoteScreen.route,
67+
enterTransition = {
68+
return@composable slideIntoContainer(
69+
AnimatedContentTransitionScope.SlideDirection.Start, tween(700)
70+
)
71+
},
72+
popExitTransition = {
73+
return@composable slideOutOfContainer(
74+
AnimatedContentTransitionScope.SlideDirection.End, tween(700)
75+
)
76+
},
77+
arguments = listOf(
78+
navArgument("id") {
79+
type = NavType.LongType
80+
defaultValue = -1L
81+
}
82+
)) {
8383
NoteScreen { navController.popBackStack() }
8484
}
8585
}
86-
}
87-
86+
}

app/src/main/java/com/techuntried/notes/database/NoteDao.kt

+3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import com.techuntried.notes.model.NoteEntity
55
import androidx.room.Dao
66
import androidx.room.Insert
77
import androidx.room.Query
8+
import androidx.room.Update
89
import kotlinx.coroutines.flow.Flow
910

1011

@@ -21,6 +22,8 @@ interface NoteDao {
2122

2223
@Query("SELECT * FROM notes where id=:id")
2324
suspend fun getNoteById(id: Long): NoteEntity
25+
@Update
26+
suspend fun updateNote(noteEntity: NoteEntity)
2427

2528
}
2629

app/src/main/java/com/techuntried/notes/model/NoteEntity.kt

+4-1
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,8 @@ data class NoteEntity(
99
@PrimaryKey(autoGenerate = true)
1010
val id:Long,
1111
@ColumnInfo("title")
12-
val title:String
12+
val title:String,
13+
@ColumnInfo("description")
14+
val description:String,
15+
1316
)

app/src/main/java/com/techuntried/notes/repository/NotesRepository.kt

+4
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,9 @@ class NotesRepository @Inject constructor(private val noteDao: NoteDao) {
2626
noteDao.deleteNote(id)
2727
}
2828

29+
suspend fun updateNote(noteEntity: NoteEntity) {
30+
noteDao.updateNote(noteEntity)
31+
}
32+
2933
}
3034

app/src/main/java/com/techuntried/notes/screens/home/HomeScreen.kt

+52-13
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,17 @@ import androidx.compose.foundation.background
55
import androidx.compose.foundation.clickable
66
import androidx.compose.foundation.layout.Arrangement
77
import androidx.compose.foundation.layout.Box
8+
import androidx.compose.foundation.layout.Column
89
import androidx.compose.foundation.layout.PaddingValues
10+
import androidx.compose.foundation.layout.fillMaxHeight
911
import androidx.compose.foundation.layout.fillMaxSize
1012
import androidx.compose.foundation.layout.fillMaxWidth
1113
import androidx.compose.foundation.layout.height
1214
import androidx.compose.foundation.layout.padding
1315
import androidx.compose.foundation.lazy.staggeredgrid.LazyVerticalStaggeredGrid
1416
import androidx.compose.foundation.lazy.staggeredgrid.StaggeredGridCells
1517
import androidx.compose.foundation.lazy.staggeredgrid.items
18+
import androidx.compose.foundation.lazy.staggeredgrid.itemsIndexed
1619
import androidx.compose.foundation.shape.RoundedCornerShape
1720
import androidx.compose.material.icons.Icons
1821
import androidx.compose.material.icons.filled.Add
@@ -31,14 +34,17 @@ import androidx.compose.ui.Modifier
3134
import androidx.compose.ui.draw.clip
3235
import androidx.compose.ui.graphics.Color
3336
import androidx.compose.ui.platform.LocalContext
37+
import androidx.compose.ui.text.capitalize
3438
import androidx.compose.ui.text.font.FontWeight
39+
import androidx.compose.ui.tooling.preview.Preview
3540
import androidx.compose.ui.unit.dp
3641
import androidx.compose.ui.unit.sp
3742
import androidx.hilt.navigation.compose.hiltViewModel
3843
import androidx.navigation.NavDestination
3944
import androidx.navigation.NavHostController
4045
import com.techuntried.notes.model.NoteEntity
4146
import com.techuntried.notes.navigation.Screens
47+
import java.util.Locale
4248

4349
@OptIn(ExperimentalMaterial3Api::class)
4450
@Composable
@@ -51,14 +57,26 @@ fun HomeScreen(onAddClick: () -> Unit, onNoteClick: (id: Long) -> Unit) {
5157
.fillMaxSize()
5258
.padding(it)
5359
) {
60+
val pastelLightColors = listOf(
61+
Color(0xFFF5BB00), // Pastel Yellow
62+
Color(0xFFEC9A29), // Pastel Orange
63+
Color(0xFF8FD6BD), // Pastel Green
64+
Color(0xFF6FA0A5), // Pastel Cyan
65+
Color(0xFFC8A2C8), // Pastel Purple
66+
Color(0xFFE0BBE4), // Pastel Lavender
67+
Color(0xFFF4CEE3), // Pastel Pink
68+
Color(0xFFA3D5D1), // Pastel Blue
69+
Color(0xFFE9D0C3) // Pastel Peach
70+
)
5471
LazyVerticalStaggeredGrid(
5572
columns = StaggeredGridCells.Fixed(2),
5673
contentPadding = PaddingValues(8.dp),
5774
horizontalArrangement = Arrangement.spacedBy(8.dp),
5875
verticalItemSpacing = 8.dp
5976
) {
60-
items(notes.value) {
61-
NoteItem(noteEntity = it, onNoteClick)
77+
itemsIndexed(notes.value) { index, item ->
78+
val color = pastelLightColors[index % pastelLightColors.size]
79+
NoteItem(noteEntity = item, color, onNoteClick)
6280
}
6381
}
6482
FloatingActionButton(
@@ -78,22 +96,43 @@ fun HomeScreen(onAddClick: () -> Unit, onNoteClick: (id: Long) -> Unit) {
7896
@Composable
7997
fun Toolbar() {
8098
TopAppBar(
81-
title = { Text(text = "Home") },
82-
83-
)
99+
title = {
100+
Text(text = "Home")
101+
},
102+
)
84103
}
85104

86105
@Composable
87-
fun NoteItem(noteEntity: NoteEntity, onNoteClick: (id: Long) -> Unit) {
88-
Box(
106+
fun NoteItem(noteEntity: NoteEntity, color: Color, onNoteClick: (id: Long) -> Unit) {
107+
Column(
89108
modifier = Modifier
90-
.fillMaxWidth()
91-
.height(100.dp)
92109
.clip(RoundedCornerShape(12.dp))
93-
.background(Color.Black)
94-
.clickable { onNoteClick(noteEntity.id) },
95-
contentAlignment = Alignment.Center
110+
.background(color)
111+
.clickable { onNoteClick(noteEntity.id) }
112+
.padding(16.dp),
113+
horizontalAlignment = Alignment.Start
96114
) {
97-
Text(text = noteEntity.title, fontSize = 18.sp, fontWeight = FontWeight.Bold)
115+
if (noteEntity.title.isNotBlank()) {
116+
Text(
117+
modifier = Modifier.padding(bottom = 8.dp),
118+
text = noteEntity.title.take(50)
119+
.replaceFirstChar { if (it.isLowerCase()) it.titlecase(Locale.getDefault()) else it.toString() },
120+
fontSize = 18.sp,
121+
fontWeight = FontWeight.Bold,
122+
color = Color.White,
123+
)
124+
}
125+
126+
if (noteEntity.description.isNotBlank()) {
127+
Text(
128+
text = noteEntity.description.take(100),
129+
fontSize = 16.sp,
130+
fontWeight = FontWeight.Normal,
131+
color = Color.White
132+
)
133+
}
134+
98135
}
99136
}
137+
138+

0 commit comments

Comments
 (0)