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
Simba/feature/note folder screen UI #49
Merged
hadiyarajesh
merged 16 commits into
hadiyarajesh:branch_hadiyarajesh
from
Simba-97:Simba/feature/NoteFolderScreenUI
Oct 17, 2022
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
ec0a163
Merge branch 'NoteXCommunity:branch_hadiyarajesh' into branch_hadiyar…
Simba-97 9fe9039
Merge branch 'NoteXCommunity:branch_hadiyarajesh' into branch_hadiyar…
Simba-97 e6a0be5
Merge branch 'NoteXCommunity:branch_hadiyarajesh' into branch_hadiyar…
Simba-97 4a17906
Merge branch 'NoteXCommunity:branch_hadiyarajesh' into branch_hadiyar…
Simba-97 7714eea
Merge branch 'NoteXCommunity:branch_hadiyarajesh' into branch_hadiyar…
Simba-97 28ee98b
Adding more UI changes
Simba-97 c0104e7
Working on NoteFolder UI section
Simba-97 c9e209a
Update NoteFolderScreen.kt
Simba-97 6f1afd3
Undid changes
Simba-97 9c72b28
Fixed spacing between two row elems
Simba-97 9ce6b06
Added viewModel & minor changes to FolderRepository
Simba-97 4920284
Added routes and deleted redundant data classes
Simba-97 b19c457
Added folder icon and minor changes
Simba-97 46fc61b
Added spacing and string resources
Simba-97 b21c960
Resolved merge conflicts
Simba-97 d7c1044
Merge branch 'branch_hadiyarajesh' into Simba/feature/NoteFolderScreenUI
hadiyarajesh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
266 changes: 266 additions & 0 deletions
266
app/src/main/java/com/hadiyarajesh/notex/ui/folders/NoteFolderScreen.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,266 @@ | ||
package com.hadiyarajesh.notex.ui.folders | ||
|
||
import androidx.compose.foundation.background | ||
import androidx.compose.foundation.clickable | ||
import androidx.compose.foundation.layout.* | ||
import androidx.compose.foundation.lazy.grid.GridCells | ||
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid | ||
import androidx.compose.foundation.lazy.grid.items | ||
import androidx.compose.foundation.lazy.grid.rememberLazyGridState | ||
import androidx.compose.foundation.shape.RoundedCornerShape | ||
import androidx.compose.material3.Icon | ||
import androidx.compose.material3.MaterialTheme | ||
import androidx.compose.material3.Surface | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.runtime.rememberCoroutineScope | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.draw.clip | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.platform.LocalContext | ||
import androidx.compose.ui.res.painterResource | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.compose.ui.text.font.FontWeight | ||
import androidx.compose.ui.tooling.preview.Preview | ||
import androidx.compose.ui.unit.dp | ||
import androidx.navigation.NavController | ||
import androidx.paging.compose.collectAsLazyPagingItems | ||
import com.hadiyarajesh.notex.R | ||
import com.hadiyarajesh.notex.database.entity.Folder | ||
import com.hadiyarajesh.notex.database.model.FolderType.NoteFolder | ||
import com.hadiyarajesh.notex.ui.navigation.Screens | ||
import java.time.Instant | ||
|
||
@Composable | ||
fun NoteFolderScreen( | ||
modifier: Modifier = Modifier, | ||
navController: NavController, | ||
folderViewModel: NoteFolderViewModel | ||
) { | ||
val scope = rememberCoroutineScope() | ||
val context = LocalContext.current | ||
val folders = remember { folderViewModel.getFolders() }.collectAsLazyPagingItems() | ||
|
||
val data = listOf( | ||
Folder( | ||
folderId = 12345, | ||
title = "Android", | ||
description = "Android Notes", | ||
folderType = NoteFolder, | ||
createdOn = Instant.now(), | ||
updatedOn = Instant.now() | ||
), | ||
Folder( | ||
folderId = 12346, | ||
title = "Android1", | ||
description = "Android Notes", | ||
folderType = NoteFolder, | ||
createdOn = Instant.now(), | ||
updatedOn = Instant.now() | ||
), | ||
Folder( | ||
folderId = 12347, | ||
title = "Android2", | ||
description = "Android Notes", | ||
folderType = NoteFolder, | ||
createdOn = Instant.now(), | ||
updatedOn = Instant.now() | ||
), | ||
Folder( | ||
folderId = 12348, | ||
title = "Android3", | ||
description = "Android Notes", | ||
folderType = NoteFolder, | ||
createdOn = Instant.now(), | ||
updatedOn = Instant.now() | ||
), | ||
Folder( | ||
folderId = 12349, | ||
title = "Android4", | ||
description = "Android Notes", | ||
folderType = NoteFolder, | ||
createdOn = Instant.now(), | ||
updatedOn = Instant.now() | ||
) | ||
) | ||
val state = rememberLazyGridState() | ||
Surface { | ||
Column( | ||
modifier = modifier.fillMaxSize() | ||
) { | ||
Row( | ||
modifier = modifier | ||
.fillMaxWidth() | ||
.padding(10.dp), | ||
horizontalArrangement = Arrangement.SpaceBetween, | ||
verticalAlignment = Alignment.CenterVertically, | ||
) { | ||
Text( | ||
text = stringResource(id = R.string.categories), | ||
style = MaterialTheme.typography.headlineMedium, | ||
modifier = modifier.padding(start = 120.dp) | ||
) | ||
Icon( | ||
painter = painterResource(id = R.drawable.ic_add_circle_outline), | ||
contentDescription = "add_note", | ||
modifier = modifier | ||
.padding(end = 10.dp) | ||
.clickable { | ||
navController.navigate(Screens.AddNote.route) | ||
} | ||
) | ||
|
||
} | ||
|
||
Row( | ||
modifier = Modifier | ||
.fillMaxWidth() | ||
.padding(20.dp), | ||
horizontalArrangement = Arrangement.SpaceBetween, | ||
verticalAlignment = Alignment.CenterVertically | ||
) { | ||
Text( | ||
text = stringResource(id = R.string.list_categories), | ||
style = MaterialTheme.typography.bodyMedium | ||
) | ||
} | ||
|
||
LazyVerticalGrid( | ||
modifier = modifier.padding(8.dp), | ||
columns = GridCells.Fixed(2), | ||
verticalArrangement = Arrangement.spacedBy(8.dp), | ||
horizontalArrangement = Arrangement.spacedBy(8.dp), | ||
state = state, | ||
) { | ||
items( | ||
items = data, | ||
key = { | ||
it.title | ||
} | ||
) { noteItem -> | ||
NoteFolderItemUI(onClick = {}, folder = noteItem) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
@Composable | ||
fun NoteFolderItemUI( | ||
modifier: Modifier = Modifier, | ||
onClick: () -> Unit, | ||
folder: Folder, | ||
) { | ||
Box( | ||
modifier = modifier | ||
.padding(8.dp) | ||
.aspectRatio(1f) | ||
.clip(RoundedCornerShape(8.dp)) | ||
.background(Color.LightGray), | ||
contentAlignment = Alignment.Center | ||
) { | ||
Column( | ||
modifier = modifier.fillMaxWidth(), | ||
horizontalAlignment = Alignment.CenterHorizontally | ||
) { | ||
Icon(painterResource(id = R.drawable.ic_folder_filled), contentDescription = null) | ||
|
||
Text( | ||
text = "Item ${folder.title}", | ||
style = MaterialTheme.typography.bodyLarge, | ||
fontWeight = FontWeight.Bold | ||
) | ||
|
||
Text( | ||
text = "${folder.description}", | ||
style = MaterialTheme.typography.bodyMedium | ||
) | ||
} | ||
} | ||
} | ||
|
||
@Preview | ||
@Composable | ||
private fun NoteFolderScreenPreview() { | ||
val state = rememberLazyGridState() | ||
Surface { | ||
Column( | ||
modifier = Modifier.fillMaxSize() | ||
) { | ||
Row( | ||
modifier = Modifier | ||
.fillMaxWidth() | ||
.padding(10.dp), | ||
horizontalArrangement = Arrangement.SpaceBetween, | ||
verticalAlignment = Alignment.CenterVertically | ||
) { | ||
Text( | ||
text = stringResource(id = R.string.categories), | ||
style = MaterialTheme.typography.headlineMedium, | ||
modifier = Modifier.padding(start = 130.dp) | ||
) | ||
|
||
Icon( | ||
painter = painterResource(id = R.drawable.ic_add_circle_outline), | ||
contentDescription = "add_note", | ||
modifier = Modifier | ||
.padding(end = 10.dp) | ||
) | ||
} | ||
|
||
Row( | ||
modifier = Modifier | ||
.fillMaxWidth() | ||
.padding(10.dp), | ||
horizontalArrangement = Arrangement.SpaceBetween, | ||
verticalAlignment = Alignment.CenterVertically | ||
) { | ||
Text( | ||
text = stringResource(id = R.string.list_categories), | ||
style = MaterialTheme.typography.bodyMedium | ||
) | ||
} | ||
|
||
LazyVerticalGrid( | ||
Simba-97 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
columns = GridCells.Fixed(2), | ||
verticalArrangement = Arrangement.spacedBy(8.dp), | ||
horizontalArrangement = Arrangement.spacedBy(8.dp), | ||
state = state | ||
) { | ||
items(100) { noteFolderItems -> | ||
Box( | ||
modifier = Modifier | ||
.padding(8.dp) | ||
.aspectRatio(1f) | ||
.clip(RoundedCornerShape(8.dp)) | ||
.background(Color.LightGray), | ||
contentAlignment = Alignment.Center | ||
) { | ||
Column( | ||
modifier = Modifier.fillMaxWidth(), | ||
horizontalAlignment = Alignment.CenterHorizontally | ||
) { | ||
Icon( | ||
painterResource(id = R.drawable.ic_folder_filled), | ||
contentDescription = null | ||
) | ||
|
||
Text( | ||
text = "Item $noteFolderItems", | ||
style = MaterialTheme.typography.bodyLarge, | ||
fontWeight = FontWeight.Bold | ||
) | ||
|
||
Text( | ||
text = "$noteFolderItems item description", | ||
style = MaterialTheme.typography.bodyMedium | ||
) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
app/src/main/java/com/hadiyarajesh/notex/ui/folders/NoteFolderViewModel.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,34 @@ | ||
package com.hadiyarajesh.notex.ui.folders | ||
|
||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.viewModelScope | ||
import androidx.paging.PagingData | ||
import androidx.paging.cachedIn | ||
import com.hadiyarajesh.notex.database.model.FolderType | ||
import com.hadiyarajesh.notex.database.model.NoteFolder | ||
import com.hadiyarajesh.notex.repository.folder.FolderRepository | ||
import dagger.hilt.android.lifecycle.HiltViewModel | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.launch | ||
import javax.inject.Inject | ||
|
||
@HiltViewModel | ||
class NoteFolderViewModel @Inject constructor( | ||
private val folderRepository: FolderRepository | ||
) : ViewModel() { | ||
fun createFolder( | ||
name: String, | ||
description: String?, | ||
folderType: FolderType | ||
) = viewModelScope.launch { | ||
folderRepository.createFolder( | ||
name = name, | ||
description = description, | ||
folderType = folderType | ||
) | ||
} | ||
|
||
fun getFolders(): Flow<PagingData<NoteFolder>> { | ||
return folderRepository.getAllNoteFolders().cachedIn(viewModelScope) | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<vector android:height="24dp" android:tint="#000000" | ||
android:viewportHeight="24" android:viewportWidth="24" | ||
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<path android:fillColor="@android:color/white" android:pathData="M13,7h-2v4L7,11v2h4v4h2v-4h4v-2h-4L13,7zM12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM12,20c-4.41,0 -8,-3.59 -8,-8s3.59,-8 8,-8 8,3.59 8,8 -3.59,8 -8,8z"/> | ||
</vector> |
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,5 @@ | ||
<vector android:height="24dp" android:tint="#000000" | ||
android:viewportHeight="24" android:viewportWidth="24" | ||
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<path android:fillColor="@android:color/white" android:pathData="M10,4H4c-1.1,0 -1.99,0.9 -1.99,2L2,18c0,1.1 0.9,2 2,2h16c1.1,0 2,-0.9 2,-2V8c0,-1.1 -0.9,-2 -2,-2h-8l-2,-2z"/> | ||
</vector> |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fetch data from actual db, not static ones.
If you need to test the UI, create your local branch an test but the code you push here should contains only relavant code.