diff --git a/app/src/main/java/com/hadiyarajesh/notex/repository/folder/FolderRepository.kt b/app/src/main/java/com/hadiyarajesh/notex/repository/folder/FolderRepository.kt index af35fc4..667b635 100644 --- a/app/src/main/java/com/hadiyarajesh/notex/repository/folder/FolderRepository.kt +++ b/app/src/main/java/com/hadiyarajesh/notex/repository/folder/FolderRepository.kt @@ -1,8 +1,14 @@ package com.hadiyarajesh.notex.repository.folder +import androidx.paging.Pager +import androidx.paging.PagingConfig +import androidx.paging.PagingData import com.hadiyarajesh.notex.database.dao.FolderDao import com.hadiyarajesh.notex.database.entity.Folder import com.hadiyarajesh.notex.database.model.FolderType +import com.hadiyarajesh.notex.database.model.NoteFolder +import com.hadiyarajesh.notex.database.model.ReminderFolder +import kotlinx.coroutines.flow.Flow import java.time.Instant import javax.inject.Inject import javax.inject.Singleton @@ -26,4 +32,16 @@ class FolderRepository @Inject constructor( ) ) } + + fun getAllNoteFolders(): Flow> = Pager( + config = PagingConfig(pageSize = 8)//since we want a maximum of 8 folders in one screen + ){ + folderDao.getAllNoteFolders(FolderType.NoteFolder) + }.flow + + fun getAllReminderFolders(): Flow> = Pager( + config = PagingConfig(pageSize = 8)//since we want a maximum of 8 folders in one screen + ){ + folderDao.getAllReminderFolders(FolderType.ReminderFolder) + }.flow } diff --git a/app/src/main/java/com/hadiyarajesh/notex/ui/folders/FoldersScreen.kt b/app/src/main/java/com/hadiyarajesh/notex/ui/folders/FoldersScreen.kt new file mode 100644 index 0000000..1a35d03 --- /dev/null +++ b/app/src/main/java/com/hadiyarajesh/notex/ui/folders/FoldersScreen.kt @@ -0,0 +1,77 @@ +package com.hadiyarajesh.notex.ui.folders + +import androidx.compose.foundation.layout.* +import androidx.compose.material3.ExperimentalMaterial3Api +import androidx.compose.material3.Scaffold +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.platform.LocalContext +import androidx.compose.ui.tooling.preview.Devices +import androidx.compose.ui.tooling.preview.Preview +import androidx.compose.ui.unit.dp +import androidx.navigation.NavController +import androidx.paging.compose.LazyPagingItems +import androidx.paging.compose.collectAsLazyPagingItems +import com.hadiyarajesh.notex.database.entity.Folder +import com.hadiyarajesh.notex.database.model.NoteFolder +import com.hadiyarajesh.notex.database.model.ReminderFolder + + +@OptIn(ExperimentalMaterial3Api::class) +@Composable +fun FoldersScreen( + navController: NavController, + foldersViewModel: FoldersViewModel +) { + val scope = rememberCoroutineScope() + val context = LocalContext.current + val notesFolders = remember { foldersViewModel.noteFolders }.collectAsLazyPagingItems() + val reminderFolders = remember { foldersViewModel.reminderFolders }.collectAsLazyPagingItems() + + Scaffold { innerPadding -> + Column( + modifier = Modifier + .fillMaxSize() + .padding(innerPadding), + horizontalAlignment = Alignment.CenterHorizontally, + verticalArrangement = Arrangement.Center + ) { + AllFoldersView(onClick = {}) + } + + } + +} + + + +@Composable +private fun AllFoldersView( + modifier: Modifier = Modifier, + noteFolders: LazyPagingItems? = null, + reminderFolder: LazyPagingItems? = null, + onClick: (Folder) -> Unit +) { + Column(modifier = Modifier.padding(16.dp)) { + Text( + text = "Folders Screen", + modifier = Modifier.fillMaxWidth() + ) + + } +} + +@Preview( + name = "All Folders Preview", + showBackground = true, + showSystemUi = true, + device = Devices.PIXEL_2_XL +) +@Composable +fun AllFoldersViewPreview(){ + AllFoldersView(onClick = {}) +} \ No newline at end of file diff --git a/app/src/main/java/com/hadiyarajesh/notex/ui/folders/FoldersViewModel.kt b/app/src/main/java/com/hadiyarajesh/notex/ui/folders/FoldersViewModel.kt new file mode 100644 index 0000000..3efc80a --- /dev/null +++ b/app/src/main/java/com/hadiyarajesh/notex/ui/folders/FoldersViewModel.kt @@ -0,0 +1,38 @@ +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.entity.Folder +import com.hadiyarajesh.notex.database.model.FolderType +import com.hadiyarajesh.notex.database.model.NoteFolder +import com.hadiyarajesh.notex.database.model.ReminderFolder +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 FoldersViewModel @Inject constructor( + private val folderRepository: FolderRepository +) : ViewModel() { + + val noteFolders: Flow> = + folderRepository.getAllNoteFolders().cachedIn(viewModelScope) + + val reminderFolders : Flow> = + folderRepository.getAllReminderFolders().cachedIn(viewModelScope) + + + fun createFolder( + name: String, + description: String?, + folderType: FolderType + ) = viewModelScope.launch { + folderRepository.createFolder( + name, description, folderType + ) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/hadiyarajesh/notex/ui/navigation/NoteXNavigation.kt b/app/src/main/java/com/hadiyarajesh/notex/ui/navigation/NoteXNavigation.kt index 70550bf..5878d0b 100644 --- a/app/src/main/java/com/hadiyarajesh/notex/ui/navigation/NoteXNavigation.kt +++ b/app/src/main/java/com/hadiyarajesh/notex/ui/navigation/NoteXNavigation.kt @@ -18,6 +18,8 @@ import androidx.navigation.NavHostController 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 com.hadiyarajesh.notex.ui.note.NotesScreen import com.hadiyarajesh.notex.ui.note.NotesViewModel import com.hadiyarajesh.notex.ui.note.add.AddNoteScreen @@ -60,6 +62,17 @@ fun NoteXNavigation( ) } + composable(route = Screens.Folders.route) { + bottomBarState.value = true + val foldersViewModel = hiltViewModel() + + FoldersScreen( + navController = navController, + foldersViewModel = foldersViewModel + ) + + } + composable(route = Screens.Settings.route) { bottomBarState.value = false } diff --git a/app/src/main/java/com/hadiyarajesh/notex/ui/navigation/Screens.kt b/app/src/main/java/com/hadiyarajesh/notex/ui/navigation/Screens.kt index aa36039..aae96c3 100644 --- a/app/src/main/java/com/hadiyarajesh/notex/ui/navigation/Screens.kt +++ b/app/src/main/java/com/hadiyarajesh/notex/ui/navigation/Screens.kt @@ -20,6 +20,12 @@ sealed class Screens( selectedIcon = R.drawable.ic_note_filled ) + object Folders:Screens( + route = "Folders", + icon = R.drawable.ic_baseline_folder_open, + selectedIcon = R.drawable.ic_baseline_folder + ) + object Reminders : Screens( route = "Reminders", icon = R.drawable.ic_task_outlined, @@ -44,5 +50,6 @@ sealed class Screens( val bottomNavItems = listOf( Screens.Notes, - Screens.Reminders + Screens.Reminders, + Screens.Folders ) \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_baseline_folder.xml b/app/src/main/res/drawable/ic_baseline_folder.xml new file mode 100644 index 0000000..5e930a2 --- /dev/null +++ b/app/src/main/res/drawable/ic_baseline_folder.xml @@ -0,0 +1,5 @@ + + + diff --git a/app/src/main/res/drawable/ic_baseline_folder_open.xml b/app/src/main/res/drawable/ic_baseline_folder_open.xml new file mode 100644 index 0000000..7ea2999 --- /dev/null +++ b/app/src/main/res/drawable/ic_baseline_folder_open.xml @@ -0,0 +1,5 @@ + + +