-
-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
eacf86c
commit 0de0de6
Showing
7 changed files
with
476 additions
and
230 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
app/src/main/java/com/aritra/notify/components/actions/LayoutToggleButton.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,32 @@ | ||
package com.aritra.notify.components.actions | ||
import androidx.compose.foundation.Image | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.material3.Icon | ||
import androidx.compose.material3.IconButton | ||
import androidx.compose.material3.LocalContentColor | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.graphics.ColorFilter | ||
import androidx.compose.ui.res.painterResource | ||
import androidx.compose.ui.unit.dp | ||
import com.aritra.notify.R | ||
|
||
@Composable | ||
fun LayoutToggleButton( | ||
isGridView: Boolean, | ||
onToggleClick: () -> Unit | ||
) { | ||
val customGridViewImage = painterResource(R.drawable.grid_icon) | ||
val customAgendaViewImage = painterResource(R.drawable.list_icon) | ||
|
||
val imageToShow = if (isGridView) customGridViewImage else customAgendaViewImage | ||
|
||
val tint = LocalContentColor.current | ||
|
||
IconButton( | ||
onClick = onToggleClick, | ||
modifier = Modifier.padding(4.dp) | ||
) { | ||
Image(imageToShow, contentDescription = null, colorFilter = ColorFilter.tint(tint)) | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
app/src/main/java/com/aritra/notify/components/actions/SwipeDelete.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,64 @@ | ||
package com.aritra.notify.components.actions | ||
|
||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.material3.Icon | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.res.painterResource | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.compose.ui.unit.dp | ||
import com.aritra.notify.R | ||
import com.aritra.notify.components.dialog.TextDialog | ||
import com.aritra.notify.components.note.NotesCard | ||
import com.aritra.notify.data.models.Note | ||
import com.aritra.notify.ui.screens.notes.homeScreen.HomeScreenViewModel | ||
import me.saket.swipe.SwipeAction | ||
import me.saket.swipe.SwipeableActionsBox | ||
|
||
@Composable | ||
fun SwipeDelete( | ||
notesModel: Note, | ||
viewModel: HomeScreenViewModel, | ||
navigateToUpdateNoteScreen: (noteId: Int) -> Unit | ||
) { | ||
|
||
val deleteDialogVisible = remember { mutableStateOf(false) } | ||
|
||
val delete = SwipeAction( | ||
onSwipe = { | ||
deleteDialogVisible.value = true | ||
}, | ||
icon = { | ||
Icon( | ||
modifier = Modifier.padding(12.dp), | ||
painter = painterResource(R.drawable.ic_delete), | ||
contentDescription = null, | ||
tint = Color.White | ||
) | ||
}, | ||
background = Color.Red, | ||
) | ||
|
||
SwipeableActionsBox( | ||
modifier = Modifier.padding(10.dp), | ||
swipeThreshold = 100.dp, | ||
endActions = listOf(delete) | ||
) { | ||
NotesCard(notesModel, navigateToUpdateNoteScreen) | ||
} | ||
if (deleteDialogVisible.value) { | ||
TextDialog( | ||
title = stringResource(R.string.warning), | ||
description = stringResource(R.string.are_you_sure_want_to_delete_these_items_it_cannot_be_recovered), | ||
isOpened = deleteDialogVisible.value, | ||
onDismissCallback = { deleteDialogVisible.value = false }, | ||
onConfirmCallback = { | ||
viewModel.deleteNote(notesModel) | ||
deleteDialogVisible.value = false | ||
} | ||
) | ||
} | ||
} |
131 changes: 131 additions & 0 deletions
131
app/src/main/java/com/aritra/notify/components/note/GridNoteCard.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,131 @@ | ||
package com.aritra.notify.components.note | ||
|
||
import androidx.compose.foundation.clickable | ||
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.shape.RoundedCornerShape | ||
import androidx.compose.material.icons.Icons | ||
import androidx.compose.material.icons.filled.MoreVert | ||
import androidx.compose.material.icons.outlined.Delete | ||
import androidx.compose.material3.Card | ||
import androidx.compose.material3.CardDefaults | ||
import androidx.compose.material3.DropdownMenu | ||
import androidx.compose.material3.DropdownMenuItem | ||
import androidx.compose.material3.Icon | ||
import androidx.compose.material3.IconButton | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.runtime.setValue | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.compose.ui.text.font.Font | ||
import androidx.compose.ui.text.font.FontFamily | ||
import androidx.compose.ui.unit.dp | ||
import androidx.compose.ui.unit.sp | ||
import com.aritra.notify.R | ||
import com.aritra.notify.components.dialog.TextDialog | ||
import com.aritra.notify.data.models.Note | ||
import com.aritra.notify.ui.screens.notes.homeScreen.HomeScreenViewModel | ||
import com.aritra.notify.utils.Const | ||
import java.text.SimpleDateFormat | ||
import java.util.Locale | ||
|
||
@Composable | ||
fun GridNoteCard( | ||
notesModel: Note, | ||
viewModel: HomeScreenViewModel, | ||
navigateToUpdateNoteScreen: (noteId: Int) -> Unit, | ||
isGridView: Boolean | ||
) { | ||
var expanded by remember { mutableStateOf(false) } | ||
val deleteDialogVisible = remember { mutableStateOf(false) } | ||
|
||
Card( | ||
modifier = Modifier | ||
.padding(10.dp) | ||
.fillMaxWidth() | ||
.clickable { navigateToUpdateNoteScreen(notesModel.id) }, | ||
elevation = CardDefaults.cardElevation(3.dp), | ||
shape = RoundedCornerShape(8.dp) | ||
) { | ||
Column( | ||
modifier = Modifier.padding(12.dp).fillMaxWidth() | ||
) { | ||
Row( | ||
horizontalArrangement = Arrangement.End, | ||
modifier = Modifier.fillMaxWidth() | ||
) { | ||
if (isGridView) { | ||
IconButton( | ||
onClick = { expanded = true } | ||
) { | ||
Icon(Icons.Default.MoreVert, "Options") | ||
} | ||
DropdownMenu( | ||
expanded = expanded, | ||
onDismissRequest = { expanded = false }, | ||
) { | ||
DropdownMenuItem( | ||
text = { Text("Delete") }, | ||
onClick = { | ||
deleteDialogVisible.value = true | ||
expanded = false | ||
}, | ||
leadingIcon = { | ||
Icon( | ||
modifier = Modifier.padding(12.dp), | ||
imageVector = Icons.Outlined.Delete, | ||
contentDescription = null | ||
) | ||
} | ||
) | ||
} | ||
if (deleteDialogVisible.value) { | ||
TextDialog( | ||
title = stringResource(R.string.warning), | ||
description = stringResource(R.string.are_you_sure_want_to_delete_these_items_it_cannot_be_recovered), | ||
isOpened = deleteDialogVisible.value, | ||
onDismissCallback = { deleteDialogVisible.value = false }, | ||
onConfirmCallback = { | ||
viewModel.deleteNote(notesModel) | ||
deleteDialogVisible.value = false | ||
} | ||
) | ||
} | ||
} | ||
} | ||
Text( | ||
text = notesModel.title, | ||
fontSize = 20.sp, | ||
fontFamily = FontFamily(Font(R.font.poppins_semibold)) | ||
) | ||
Spacer(modifier = Modifier.height(10.dp)) | ||
Text( | ||
text = notesModel.note, | ||
fontSize = 18.sp, | ||
fontFamily = FontFamily(Font(R.font.poppins_light)) | ||
) | ||
Spacer(modifier = Modifier.height(10.dp)) | ||
val formattedDateTime = | ||
SimpleDateFormat( | ||
Const.DATE_TIME_FORMAT, | ||
Locale.getDefault() | ||
).format(notesModel.dateTime) | ||
Text( | ||
text = formattedDateTime, | ||
fontSize = 14.sp, | ||
fontFamily = FontFamily(Font(R.font.poppins_medium)), | ||
color = Color.Gray | ||
) | ||
} | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
app/src/main/java/com/aritra/notify/components/note/NoteCard.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,71 @@ | ||
package com.aritra.notify.components.note | ||
|
||
import androidx.compose.foundation.clickable | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.Spacer | ||
import androidx.compose.foundation.layout.fillMaxHeight | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.height | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.foundation.shape.RoundedCornerShape | ||
import androidx.compose.material3.Card | ||
import androidx.compose.material3.CardDefaults | ||
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.text.font.Font | ||
import androidx.compose.ui.text.font.FontFamily | ||
import androidx.compose.ui.unit.dp | ||
import androidx.compose.ui.unit.sp | ||
import com.aritra.notify.R | ||
import com.aritra.notify.data.models.Note | ||
import com.aritra.notify.utils.Const | ||
import java.text.SimpleDateFormat | ||
import java.util.Locale | ||
|
||
@Composable | ||
fun NotesCard( | ||
noteModel: Note, | ||
navigateToUpdateNoteScreen: (noteId: Int) -> Unit | ||
) { | ||
|
||
Card( | ||
modifier = Modifier | ||
.padding(2.dp) | ||
.fillMaxHeight() | ||
.clickable { navigateToUpdateNoteScreen(noteModel.id) }, | ||
elevation = CardDefaults.cardElevation(3.dp), | ||
shape = RoundedCornerShape(8.dp), | ||
) { | ||
Column( | ||
modifier = Modifier | ||
.fillMaxWidth() | ||
.padding(12.dp) | ||
) { | ||
Text( | ||
text = noteModel.title, | ||
fontSize = 20.sp, | ||
fontFamily = FontFamily(Font(R.font.poppins_semibold)) | ||
) | ||
Spacer(modifier = Modifier.height(10.dp)) | ||
Text( | ||
text = noteModel.note, | ||
fontSize = 18.sp, | ||
fontFamily = FontFamily(Font(R.font.poppins_light)) | ||
) | ||
Spacer(modifier = Modifier.height(10.dp)) | ||
val formattedDateTime = | ||
SimpleDateFormat( | ||
Const.DATE_TIME_FORMAT, | ||
Locale.getDefault() | ||
).format(noteModel.dateTime) | ||
Text( | ||
text = formattedDateTime, | ||
fontSize = 14.sp, | ||
fontFamily = FontFamily(Font(R.font.poppins_medium)), | ||
color = Color.Gray | ||
) | ||
} | ||
} | ||
} |
Oops, something went wrong.