This repository has been archived by the owner on May 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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
1 parent
e832b3e
commit e7d1eb7
Showing
14 changed files
with
357 additions
and
23 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,3 +20,4 @@ data class Note( | |
val updatedOn: Instant, | ||
val parentFolderId: Long? = null, | ||
) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
app/src/main/java/com/hadiyarajesh/notex/ui/component/BorderLessTextField.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
183 changes: 170 additions & 13 deletions
183
app/src/main/java/com/hadiyarajesh/notex/ui/note/add/AddNoteScreen.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) | ||
} |
Oops, something went wrong.