Skip to content
This repository has been archived by the owner on May 19, 2023. It is now read-only.

Commit

Permalink
Branch sajalsj (#62)
Browse files Browse the repository at this point in the history
* 1. view model added for Add note screen
2. UI WIP for add note screen

* 1. view model added for Add note screen
2. Add and edit screen UI complete

* Made changes written in PR

* Narendra ju/feature/folders setup (#45)

* Added CODEOWNERS files (#33)

* Adding CONTRIBUTING.md

* Added CONTRIBUTING.md and squashed commits

* Updated branch naming convention

Updated branch naming convention with github-username

* 1. Added database schema (entity)
2. Added database functions (dao)
3. Added how to fetch paging data
4. Added LazyColumn UI with paging data with different states like loading, success, error

Signed-off-by: Rajesh Hadiya <[email protected]>

* Added CODEOWNERS files. (#19)

* Adding CODEOWNERS files.

Still needed to add the Default reviewer for the two teams.

* Update CODEOWNERS

* fix the validation issues on GitHub.

* updated owners for all the branches.

* updated the Wrong branch combinations.

Signed-off-by: Rajesh Hadiya <[email protected]>
Co-authored-by: Hritik Kumar Singh <[email protected]>
Co-authored-by: Abhinav Suman <[email protected]>

* Create main.yml

* Update main.yml

* Update main.yml

* Added PR template + Updated .gitignore files (#42)

Added the PR Templates +  .gitignore

* added the groundwork for the folders section in NoteX App

Signed-off-by: Rajesh Hadiya <[email protected]>
Co-authored-by: Rajesh Hadiya <[email protected]>
Co-authored-by: Hritik Kumar Singh <[email protected]>
Co-authored-by: Abhinav Suman <[email protected]>
Co-authored-by: Rajesh Hadiya <[email protected]>

* Repository and ViewModel implementation for all notes screen. Issue #16 (#61)

* 1. view model added for Add note screen
2. UI WIP for add note screen

* 1. view model added for Add note screen
2. Add and edit screen UI complete

* Made changes written in PR

Signed-off-by: Rajesh Hadiya <[email protected]>
Co-authored-by: sajal jain <[email protected]>
Co-authored-by: Narendra Nath Chatterjee <[email protected]>
Co-authored-by: Rajesh Hadiya <[email protected]>
Co-authored-by: Hritik Kumar Singh <[email protected]>
Co-authored-by: Abhinav Suman <[email protected]>
Co-authored-by: Rajesh Hadiya <[email protected]>
Co-authored-by: virunarala <[email protected]>
  • Loading branch information
8 people authored Oct 17, 2022
1 parent e832b3e commit e7d1eb7
Show file tree
Hide file tree
Showing 14 changed files with 357 additions and 23 deletions.
1 change: 1 addition & 0 deletions .idea/gradle.xml

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

Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ data class Note(
val updatedOn: Instant,
val parentFolderId: Long? = null,
)

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.hadiyarajesh.notex.ui.component

import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Card
Expand All @@ -16,12 +17,12 @@ import com.hadiyarajesh.notex.database.entity.Note
import java.time.Instant

@Composable
fun NoteCard(note: Note) {
fun NoteCard(note: Note, onClick: (Note) -> Unit) {
Card(
elevation = CardDefaults.cardElevation(),
modifier = Modifier
.fillMaxWidth()
.padding(start = 16.dp, end = 16.dp, top = 16.dp),
.padding(start = 16.dp, end = 16.dp, top = 16.dp).clickable { onClick(note)},
shape = RoundedCornerShape(16.dp)
) {
Column(
Expand Down Expand Up @@ -83,6 +84,7 @@ fun NoteCardPrev() {
archived = false,
createdOn = Instant.now(),
updatedOn = Instant.now()
)
),
onClick = {}
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.hadiyarajesh.notex.ui.component

import androidx.compose.animation.AnimatedVisibility
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.text.BasicTextField
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.SolidColor
import androidx.compose.ui.text.TextStyle
import com.hadiyarajesh.notex.ui.theme.hintColor

@Composable
fun BorderLessTextField(
text: String,
hint: String,
onValueChange: (String) -> Unit,
textStyle: TextStyle = TextStyle(),
maxLines: Int = Int.MAX_VALUE,
) {
BasicTextField(
value = text,
onValueChange = onValueChange,
maxLines = maxLines,
textStyle = textStyle,
cursorBrush = SolidColor(hintColor),
modifier = Modifier
.fillMaxWidth(),
decorationBox = { inlineTextField ->
AnimatedVisibility(visible = text.isBlank()) {
Text(
text = hint,
color = hintColor,
style = textStyle
)
}
inlineTextField()
}
)

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.hadiyarajesh.notex.ui.navigation

import android.util.Log
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.outlined.Add
import androidx.compose.material3.BottomAppBar
Expand All @@ -15,16 +16,21 @@ import androidx.hilt.navigation.compose.hiltViewModel
import androidx.navigation.NavController
import androidx.navigation.NavGraph.Companion.findStartDestination
import androidx.navigation.NavHostController
import androidx.navigation.NavType
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.currentBackStackEntryAsState
import com.hadiyarajesh.notex.ui.folders.FoldersScreen
import com.hadiyarajesh.notex.ui.folders.FoldersViewModel
import androidx.navigation.navArgument
import androidx.navigation.navArgument
import com.hadiyarajesh.notex.ui.note.NotesScreen
import com.hadiyarajesh.notex.ui.note.NotesViewModel
import com.hadiyarajesh.notex.ui.note.add.AddNoteScreen
import com.hadiyarajesh.notex.ui.note.add.AddNotesViewModel
import com.hadiyarajesh.notex.ui.reminders.RemindersScreen
import com.hadiyarajesh.notex.ui.reminders.RemindersViewModel
import com.hadiyarajesh.notex.utility.TAG

@Composable
fun NoteXNavigation(
Expand All @@ -47,9 +53,19 @@ fun NoteXNavigation(
)
}

composable(route = Screens.AddNote.route) {
composable(route = Screens.AddNote.route + "?noteId={noteId}", arguments = listOf(
navArgument(
name = "noteId"
) {
type = NavType.LongType
defaultValue = -1
}
)
) {
bottomBarState.value = false
AddNoteScreen(navController = navController)
val noteId = it.arguments?.getLong("noteId") ?: -1
val addNotesViewModel = hiltViewModel<AddNotesViewModel>()
AddNoteScreen(navController = navController, addNotesViewModel = addNotesViewModel, noteId = if (noteId.compareTo(-1) == 0) null else noteId)
}

composable(route = Screens.Reminders.route) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import com.hadiyarajesh.notex.ui.component.EmptyView
import com.hadiyarajesh.notex.ui.component.LoadingProgressBar
import com.hadiyarajesh.notex.ui.component.NoteCard
import com.hadiyarajesh.notex.ui.component.RetryItem
import com.hadiyarajesh.notex.ui.navigation.Screens
import java.time.Instant

@OptIn(ExperimentalMaterial3Api::class)
Expand All @@ -52,7 +53,7 @@ fun NotesScreen(
AllNotesView(
notes = notes,
onClick = { note ->

navController.navigate(Screens.AddNote.route + "?noteId=${note.noteId}")
}
)
}
Expand All @@ -68,7 +69,7 @@ private fun AllNotesView(
LazyColumn(modifier = modifier) {
items(notes) { item ->
item?.let { note ->
NoteCard(note = note)
NoteCard(note = note, onClick)
}
}

Expand Down
183 changes: 170 additions & 13 deletions app/src/main/java/com/hadiyarajesh/notex/ui/note/add/AddNoteScreen.kt
Original file line number Diff line number Diff line change
@@ -1,31 +1,188 @@
package com.hadiyarajesh.notex.ui.note.add

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.activity.compose.BackHandler
import androidx.compose.animation.Animatable
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.core.Animatable
import androidx.compose.animation.core.AnimationVector4D
import androidx.compose.animation.core.tween
import androidx.compose.foundation.*
import androidx.compose.foundation.layout.*
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.ArrowBack
import androidx.compose.material3.*
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.draw.shadow
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.RectangleShape
import androidx.compose.ui.graphics.toArgb
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import androidx.navigation.NavController
import com.hadiyarajesh.notex.R
import com.hadiyarajesh.notex.ui.component.BorderLessTextField
import com.hadiyarajesh.notex.ui.component.VerticalSpacer
import com.hadiyarajesh.notex.ui.note.add.NoteState.Companion.noteColors
import kotlinx.coroutines.launch

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun AddNoteScreen(
navController: NavController
navController: NavController, addNotesViewModel: AddNotesViewModel,
noteId: Long?
) {
Scaffold { innerPadding ->
val state = remember {
mutableStateOf(NoteState())
}

val noteBackground = remember {
Animatable(
Color(state.value.color.value)
)
}
LaunchedEffect(key1 = true) {
noteId?.let { id ->
val note = addNotesViewModel.getNote(id)
state.value.apply {
title.value = note.title ?: ""
noteDesc.value = note.content ?: ""
color.value = Color(android.graphics.Color.parseColor(note.color)).toArgb()
}

noteBackground.animateTo(
targetValue = Color(state.value.color.value),
animationSpec = tween(
durationMillis = 400
)
)
}
}

BackHandler {
if (checkNoteIsNotEmpty(noteState = state.value)){
addNotesViewModel.saveNote(state.value, noteId)
}
navController.navigateUp()
}

Scaffold(bottomBar = {
BottomAppBar(containerColor = noteBackground.value, modifier = Modifier.height(40.dp)) {
ShowColor(state = state, noteBackground)
}
}) { innerPadding ->
Column(
modifier = Modifier
.fillMaxSize()
.background(noteBackground.value)
.padding(innerPadding),
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.Center
) {
Text(text = "Add some notes here")
verticalArrangement = Arrangement.Top,

) {

Row(Modifier.fillMaxWidth()) {
IconButton(onClick = {
navController.navigateUp()
}) {
Icon(
imageVector = Icons.Default.ArrowBack,
contentDescription = stringResource(R.string.cd_back)
)
}
Spacer(Modifier.weight(1f))
IconButton(onClick = {
if (checkNoteIsNotEmpty(noteState = state.value)){
addNotesViewModel.saveNote(state.value, noteId)
}
navController.navigateUp()

}) {
AnimatedVisibility(visible = checkNoteIsNotEmpty(state.value)) {
Icon(
painter = painterResource(id = R.drawable.ic_save_note),
contentDescription = stringResource(R.string.cd_save)
)
}
}
}

Column(
modifier = Modifier.padding(
start = 16.dp,
end = 16.dp,
top = 10.dp,
bottom = 1.dp
)
) {
BorderLessTextField(
text = state.value.title.value,
hint = stringResource(id = R.string.hint_note_title),
onValueChange = {
state.value.title.value = it
},
maxLines = 1,
textStyle = MaterialTheme.typography.headlineMedium
)
VerticalSpacer(size = 16)
BorderLessTextField(
text = state.value.noteDesc.value,
hint = stringResource(id = R.string.hint_note_description),
onValueChange = {
state.value.noteDesc.value = it
},
textStyle = MaterialTheme.typography.headlineSmall
)
}
}
}
}

@Composable
private fun ShowColor(
state: MutableState<NoteState>,
noteBackground: Animatable<Color, AnimationVector4D>
) {
val scope = rememberCoroutineScope()
Row(
modifier = Modifier
.fillMaxWidth(),
horizontalArrangement = Arrangement.SpaceAround
) {
noteColors.forEach { color ->
val colorInt = color.toArgb()
Box(
modifier = Modifier
.size(30.dp)
.shadow(5.dp, RectangleShape)
.clip(RectangleShape)
.background(color)
.border(
width = 1.dp,
color = if (state.value.color.value == colorInt) {
Color.DarkGray
} else Color.Transparent,
shape = RectangleShape,
)
.clickable {
scope.launch {
noteBackground.animateTo(
targetValue = Color(colorInt),
animationSpec = tween(
durationMillis = 400
)
)
}
state.value.color.value = colorInt

}
)
}
}
}
fun checkNoteIsNotEmpty(noteState: NoteState) : Boolean {
return (noteState.title.value.isNotBlank() && noteState.noteDesc.value.isNotBlank())
}
Loading

0 comments on commit e7d1eb7

Please sign in to comment.