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

Commit

Permalink
Narendra ju/feature/folders setup (#45)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
5 people authored Oct 14, 2022
1 parent 1b9e220 commit 4f6b1fe
Show file tree
Hide file tree
Showing 7 changed files with 164 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -26,4 +32,16 @@ class FolderRepository @Inject constructor(
)
)
}

fun getAllNoteFolders(): Flow<PagingData<NoteFolder>> = Pager(
config = PagingConfig(pageSize = 8)//since we want a maximum of 8 folders in one screen
){
folderDao.getAllNoteFolders(FolderType.NoteFolder)
}.flow

fun getAllReminderFolders(): Flow<PagingData<ReminderFolder>> = Pager(
config = PagingConfig(pageSize = 8)//since we want a maximum of 8 folders in one screen
){
folderDao.getAllReminderFolders(FolderType.ReminderFolder)
}.flow
}
Original file line number Diff line number Diff line change
@@ -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<NoteFolder>? = null,
reminderFolder: LazyPagingItems<ReminderFolder>? = 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 = {})
}
Original file line number Diff line number Diff line change
@@ -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<PagingData<NoteFolder>> =
folderRepository.getAllNoteFolders().cachedIn(viewModelScope)

val reminderFolders : Flow<PagingData<ReminderFolder>> =
folderRepository.getAllReminderFolders().cachedIn(viewModelScope)


fun createFolder(
name: String,
description: String?,
folderType: FolderType
) = viewModelScope.launch {
folderRepository.createFolder(
name, description, folderType
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -60,6 +62,17 @@ fun NoteXNavigation(
)
}

composable(route = Screens.Folders.route) {
bottomBarState.value = true
val foldersViewModel = hiltViewModel<FoldersViewModel>()

FoldersScreen(
navController = navController,
foldersViewModel = foldersViewModel
)

}

composable(route = Screens.Settings.route) {
bottomBarState.value = false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -44,5 +50,6 @@ sealed class Screens(

val bottomNavItems = listOf(
Screens.Notes,
Screens.Reminders
Screens.Reminders,
Screens.Folders
)
5 changes: 5 additions & 0 deletions app/src/main/res/drawable/ic_baseline_folder.xml
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>
5 changes: 5 additions & 0 deletions app/src/main/res/drawable/ic_baseline_folder_open.xml
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="M20,6h-8l-2,-2L4,4c-1.1,0 -1.99,0.9 -1.99,2L2,18c0,1.1 0.9,2 2,2h16c1.1,0 2,-0.9 2,-2L22,8c0,-1.1 -0.9,-2 -2,-2zM20,18L4,18L4,8h16v10z"/>
</vector>

0 comments on commit 4f6b1fe

Please sign in to comment.