From 8e406386065534efef4d22698b59112a9ec16e6f Mon Sep 17 00:00:00 2001 From: T8RIN Date: Wed, 23 Mar 2022 09:25:12 +0300 Subject: [PATCH] changed packages signature and made code more readable --- .idea/gradle.xml | 1 - app/build.gradle.kts | 21 -- .../tech/firenote/ExampleInstrumentedTest.kt | 22 -- .../firenote/ui/composable/app/FirenoteApp.kt | 34 +-- .../ui/composable/navigation/Navigation.kt | 38 +-- .../ui/composable/screen/auth/AuthScreen.kt | 2 +- .../screen/auth/ForgotPasswordScreen.kt | 2 +- .../ui/composable/screen/auth/LoginScreen.kt | 4 +- .../screen/auth/RegistrationScreen.kt | 4 +- .../screen/creation/CreationContainer.kt | 61 ++--- .../screen/creation/GoalCreationScreen.kt | 4 +- .../screen/creation/NoteCreationScreen.kt | 4 +- .../{base => navigation}/GoalListScreen.kt | 31 +-- .../{base => navigation}/NoteListScreen.kt | 31 +-- .../{base => navigation}/ProfileScreen.kt | 10 +- .../ui/composable/single/FirenoteScaffold.kt | 224 ------------------ .../ui/composable/single/bar/AppBarActions.kt | 4 +- .../single/bar/BottomNavigationBar.kt | 2 +- .../ui/composable/single/bar/SearchBar.kt | 53 +++++ .../single/{ => dialog}/MaterialDialog.kt | 50 +--- .../single/placeholder/Placeholder.kt | 26 ++ .../single/scaffold/FirenoteScaffold.kt | 156 ++++++++++++ .../ui/composable/single/{ => toast}/Toast.kt | 2 +- .../java/ru/tech/firenote/ui/route/Screen.kt | 37 +-- .../java/ru/tech/firenote/ui/theme/Color.kt | 83 +++---- .../viewModel/{ => auth}/AuthViewModel.kt | 2 +- .../{ => creation}/GoalCreationViewModel.kt | 2 +- .../{ => creation}/NoteCreationViewModel.kt | 2 +- .../viewModel/{ => main}/MainViewModel.kt | 20 +- .../{ => navigation}/GoalListViewModel.kt | 2 +- .../{ => navigation}/NoteListViewModel.kt | 2 +- .../{ => navigation}/ProfileViewModel.kt | 2 +- .../java/ru/tech/firenote/ExampleUnitTest.kt | 16 -- build.gradle.kts | 4 + 34 files changed, 421 insertions(+), 537 deletions(-) delete mode 100644 app/src/androidTest/java/ru/tech/firenote/ExampleInstrumentedTest.kt rename app/src/main/java/ru/tech/firenote/ui/composable/screen/{base => navigation}/GoalListScreen.kt (84%) rename app/src/main/java/ru/tech/firenote/ui/composable/screen/{base => navigation}/NoteListScreen.kt (82%) rename app/src/main/java/ru/tech/firenote/ui/composable/screen/{base => navigation}/ProfileScreen.kt (98%) delete mode 100644 app/src/main/java/ru/tech/firenote/ui/composable/single/FirenoteScaffold.kt create mode 100644 app/src/main/java/ru/tech/firenote/ui/composable/single/bar/SearchBar.kt rename app/src/main/java/ru/tech/firenote/ui/composable/single/{ => dialog}/MaterialDialog.kt (57%) create mode 100644 app/src/main/java/ru/tech/firenote/ui/composable/single/placeholder/Placeholder.kt create mode 100644 app/src/main/java/ru/tech/firenote/ui/composable/single/scaffold/FirenoteScaffold.kt rename app/src/main/java/ru/tech/firenote/ui/composable/single/{ => toast}/Toast.kt (92%) rename app/src/main/java/ru/tech/firenote/viewModel/{ => auth}/AuthViewModel.kt (98%) rename app/src/main/java/ru/tech/firenote/viewModel/{ => creation}/GoalCreationViewModel.kt (98%) rename app/src/main/java/ru/tech/firenote/viewModel/{ => creation}/NoteCreationViewModel.kt (97%) rename app/src/main/java/ru/tech/firenote/viewModel/{ => main}/MainViewModel.kt (85%) rename app/src/main/java/ru/tech/firenote/viewModel/{ => navigation}/GoalListViewModel.kt (97%) rename app/src/main/java/ru/tech/firenote/viewModel/{ => navigation}/NoteListViewModel.kt (97%) rename app/src/main/java/ru/tech/firenote/viewModel/{ => navigation}/ProfileViewModel.kt (99%) delete mode 100644 app/src/test/java/ru/tech/firenote/ExampleUnitTest.kt diff --git a/.idea/gradle.xml b/.idea/gradle.xml index 35ffc65..a0de2a1 100644 --- a/.idea/gradle.xml +++ b/.idea/gradle.xml @@ -14,7 +14,6 @@ - diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 0a76a11..0614b31 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -117,25 +117,4 @@ dependencies { implementation("com.google.firebase:firebase-crashlytics-ktx:18.2.9") implementation("com.google.firebase:firebase-analytics-ktx:20.1.1") - -// //DataStore -// implementation("androidx.datastore:datastore-preferences:1.0.0") -// implementation("androidx.datastore:datastore-preferences-core:1.0.0") -// //Retrofit -// implementation("com.squareup.retrofit2:retrofit:2.9.0") -// implementation("com.squareup.retrofit2:converter-gson:2.9.0") -// implementation("com.squareup.okhttp3:okhttp:4.9.3") -// implementation("com.squareup.okhttp3:logging-interceptor:4.9.2") -// -// Koin -// implementation("io.insert-koin:koin-android:3.1.5") -// implementation("io.insert-koin:koin-androidx-workmanager:3.1.5") -// implementation("io.insert-koin:koin-androidx-navigation:3.1.5") -// implementation("io.insert-koin:koin-androidx-compose:3.1.5") -// -// //WorkManager -// implementation("androidx.work:work-runtime-ktx:2.7.1") -// androidTestImplementation("androidx.work:work-testing:2.7.1") -// implementation("androidx.work:work-multiprocess:2.7.1") - } \ No newline at end of file diff --git a/app/src/androidTest/java/ru/tech/firenote/ExampleInstrumentedTest.kt b/app/src/androidTest/java/ru/tech/firenote/ExampleInstrumentedTest.kt deleted file mode 100644 index c2f2ea0..0000000 --- a/app/src/androidTest/java/ru/tech/firenote/ExampleInstrumentedTest.kt +++ /dev/null @@ -1,22 +0,0 @@ -package ru.tech.firenote - -import androidx.test.ext.junit.runners.AndroidJUnit4 -import androidx.test.platform.app.InstrumentationRegistry -import org.junit.Assert.assertEquals -import org.junit.Test -import org.junit.runner.RunWith - -/** - * Instrumented test, which will execute on an Android device. - * - * See [testing documentation](http://d.android.com/tools/testing). - */ -@RunWith(AndroidJUnit4::class) -class ExampleInstrumentedTest { - @Test - fun useAppContext() { - // Context of the app under test. - val appContext = InstrumentationRegistry.getInstrumentation().targetContext - assertEquals("ru.tech.firenote", appContext.packageName) - } -} \ No newline at end of file diff --git a/app/src/main/java/ru/tech/firenote/ui/composable/app/FirenoteApp.kt b/app/src/main/java/ru/tech/firenote/ui/composable/app/FirenoteApp.kt index 60abcf3..7a5850b 100644 --- a/app/src/main/java/ru/tech/firenote/ui/composable/app/FirenoteApp.kt +++ b/app/src/main/java/ru/tech/firenote/ui/composable/app/FirenoteApp.kt @@ -21,11 +21,11 @@ import ru.tech.firenote.ui.composable.provider.LocalSnackbarHost import ru.tech.firenote.ui.composable.provider.LocalWindowSize import ru.tech.firenote.ui.composable.screen.auth.AuthScreen import ru.tech.firenote.ui.composable.screen.creation.CreationContainer -import ru.tech.firenote.ui.composable.single.FirenoteScaffold -import ru.tech.firenote.ui.composable.single.MaterialDialog +import ru.tech.firenote.ui.composable.single.dialog.MaterialDialog +import ru.tech.firenote.ui.composable.single.scaffold.FirenoteScaffold import ru.tech.firenote.ui.composable.utils.WindowSize import ru.tech.firenote.ui.theme.FirenoteTheme -import ru.tech.firenote.viewModel.MainViewModel +import ru.tech.firenote.viewModel.main.MainViewModel @SuppressLint("SourceLockedOrientationActivity") @OptIn(ExperimentalMaterial3Api::class) @@ -35,14 +35,14 @@ fun FirenoteApp( windowSize: WindowSize, splitScreen: Boolean, navController: NavHostController, - mainViewModel: MainViewModel = viewModel() + viewModel: MainViewModel = viewModel() ) { val isScaffoldVisible by derivedStateOf { - !mainViewModel.showNoteCreation.currentState - || !mainViewModel.showNoteCreation.targetState - || !mainViewModel.showGoalCreation.currentState - || !mainViewModel.showGoalCreation.targetState + !viewModel.showNoteCreation.currentState + || !viewModel.showNoteCreation.targetState + || !viewModel.showGoalCreation.currentState + || !viewModel.showGoalCreation.targetState } FirenoteTheme { @@ -55,9 +55,9 @@ fun FirenoteApp( dismissText = R.string.close, dismissAction = { context.finishAffinity() } ) - if (mainViewModel.searchMode.value) BackHandler { - mainViewModel.searchMode.value = false - mainViewModel.searchString.value = "" + if (viewModel.searchMode.value) BackHandler { + viewModel.searchMode.value = false + viewModel.updateSearch() } @@ -66,8 +66,8 @@ fun FirenoteApp( LocalSnackbarHost provides snackbarHostState, LocalWindowSize provides windowSize ) { - if (mainViewModel.isAuth.value) { - AuthScreen(mainViewModel.isAuth) + if (viewModel.isAuth.value) { + AuthScreen(viewModel.isAuth) context.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT } else { context.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED @@ -75,22 +75,22 @@ fun FirenoteApp( Row { FirenoteScaffold( modifier = Modifier.weight(1f), - mainViewModel = mainViewModel, + viewModel = viewModel, navController = navController, context = context ) Surface(modifier = Modifier.weight(1.5f)) { - CreationContainer(mainViewModel, splitScreen) + CreationContainer(viewModel, splitScreen) } } } else { FirenoteScaffold( modifier = Modifier.alpha(if (isScaffoldVisible) 1f else 0f), - mainViewModel = mainViewModel, + viewModel = viewModel, navController = navController, context = context ) - CreationContainer(mainViewModel, splitScreen) + CreationContainer(viewModel, splitScreen) } } } diff --git a/app/src/main/java/ru/tech/firenote/ui/composable/navigation/Navigation.kt b/app/src/main/java/ru/tech/firenote/ui/composable/navigation/Navigation.kt index a9f7cca..2eb805e 100644 --- a/app/src/main/java/ru/tech/firenote/ui/composable/navigation/Navigation.kt +++ b/app/src/main/java/ru/tech/firenote/ui/composable/navigation/Navigation.kt @@ -7,17 +7,17 @@ import androidx.compose.ui.Modifier import androidx.navigation.NavHostController import androidx.navigation.compose.NavHost import androidx.navigation.compose.composable -import ru.tech.firenote.ui.composable.screen.base.GoalListScreen -import ru.tech.firenote.ui.composable.screen.base.NoteListScreen -import ru.tech.firenote.ui.composable.screen.base.ProfileScreen +import ru.tech.firenote.ui.composable.screen.navigation.GoalListScreen +import ru.tech.firenote.ui.composable.screen.navigation.NoteListScreen +import ru.tech.firenote.ui.composable.screen.navigation.ProfileScreen import ru.tech.firenote.ui.route.Screen -import ru.tech.firenote.viewModel.MainViewModel +import ru.tech.firenote.viewModel.main.MainViewModel @Composable fun Navigation( navController: NavHostController, contentPadding: PaddingValues, - mainViewModel: MainViewModel, + viewModel: MainViewModel, ) { NavHost( navController = navController, @@ -26,29 +26,29 @@ fun Navigation( ) { composable(Screen.NoteListScreen.route) { NoteListScreen( - mainViewModel.showNoteCreation, - mainViewModel.globalNote, - mainViewModel.filterType, - mainViewModel.isDescendingFilter, - mainViewModel.searchString + viewModel.showNoteCreation, + viewModel.globalNote, + viewModel.filterType, + viewModel.isDescendingFilter, + viewModel.searchString ) } composable(Screen.GoalsScreen.route) { GoalListScreen( - mainViewModel.showGoalCreation, - mainViewModel.globalGoal, - mainViewModel.filterType, - mainViewModel.isDescendingFilter, - mainViewModel.searchString + viewModel.showGoalCreation, + viewModel.globalGoal, + viewModel.filterType, + viewModel.isDescendingFilter, + viewModel.searchString ) } composable(Screen.ProfileScreen.route) { ProfileScreen( navController, - mainViewModel.selectedItem, - mainViewModel.resultLauncher, - mainViewModel.profileTitle, - mainViewModel.showUsernameDialog + viewModel.selectedItem, + viewModel.resultLauncher, + viewModel.profileTitle, + viewModel.showUsernameDialog ) } } diff --git a/app/src/main/java/ru/tech/firenote/ui/composable/screen/auth/AuthScreen.kt b/app/src/main/java/ru/tech/firenote/ui/composable/screen/auth/AuthScreen.kt index edeac42..f730f99 100644 --- a/app/src/main/java/ru/tech/firenote/ui/composable/screen/auth/AuthScreen.kt +++ b/app/src/main/java/ru/tech/firenote/ui/composable/screen/auth/AuthScreen.kt @@ -19,7 +19,7 @@ import ru.tech.firenote.R import ru.tech.firenote.ui.composable.provider.LocalWindowSize import ru.tech.firenote.ui.composable.utils.WindowSize import ru.tech.firenote.ui.route.Screen -import ru.tech.firenote.viewModel.AuthViewModel +import ru.tech.firenote.viewModel.auth.AuthViewModel @OptIn(ExperimentalMaterial3Api::class) @Composable diff --git a/app/src/main/java/ru/tech/firenote/ui/composable/screen/auth/ForgotPasswordScreen.kt b/app/src/main/java/ru/tech/firenote/ui/composable/screen/auth/ForgotPasswordScreen.kt index 3d96117..43d2424 100644 --- a/app/src/main/java/ru/tech/firenote/ui/composable/screen/auth/ForgotPasswordScreen.kt +++ b/app/src/main/java/ru/tech/firenote/ui/composable/screen/auth/ForgotPasswordScreen.kt @@ -24,7 +24,7 @@ import androidx.compose.ui.unit.sp import ru.tech.firenote.R import ru.tech.firenote.ui.composable.single.text.MaterialTextField import ru.tech.firenote.ui.route.Screen -import ru.tech.firenote.viewModel.AuthViewModel +import ru.tech.firenote.viewModel.auth.AuthViewModel @OptIn(ExperimentalMaterial3Api::class) @Composable diff --git a/app/src/main/java/ru/tech/firenote/ui/composable/screen/auth/LoginScreen.kt b/app/src/main/java/ru/tech/firenote/ui/composable/screen/auth/LoginScreen.kt index f694ae7..745bd54 100644 --- a/app/src/main/java/ru/tech/firenote/ui/composable/screen/auth/LoginScreen.kt +++ b/app/src/main/java/ru/tech/firenote/ui/composable/screen/auth/LoginScreen.kt @@ -27,10 +27,10 @@ import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import ru.tech.firenote.R import ru.tech.firenote.ui.composable.single.text.MaterialTextField -import ru.tech.firenote.ui.composable.single.Toast +import ru.tech.firenote.ui.composable.single.toast.Toast import ru.tech.firenote.ui.route.Screen import ru.tech.firenote.ui.state.UIState -import ru.tech.firenote.viewModel.AuthViewModel +import ru.tech.firenote.viewModel.auth.AuthViewModel @OptIn(ExperimentalMaterial3Api::class) diff --git a/app/src/main/java/ru/tech/firenote/ui/composable/screen/auth/RegistrationScreen.kt b/app/src/main/java/ru/tech/firenote/ui/composable/screen/auth/RegistrationScreen.kt index a73197f..fd4ba81 100644 --- a/app/src/main/java/ru/tech/firenote/ui/composable/screen/auth/RegistrationScreen.kt +++ b/app/src/main/java/ru/tech/firenote/ui/composable/screen/auth/RegistrationScreen.kt @@ -25,10 +25,10 @@ import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import ru.tech.firenote.R import ru.tech.firenote.ui.composable.single.text.MaterialTextField -import ru.tech.firenote.ui.composable.single.Toast +import ru.tech.firenote.ui.composable.single.toast.Toast import ru.tech.firenote.ui.route.Screen import ru.tech.firenote.ui.state.UIState -import ru.tech.firenote.viewModel.AuthViewModel +import ru.tech.firenote.viewModel.auth.AuthViewModel @OptIn(ExperimentalMaterial3Api::class) diff --git a/app/src/main/java/ru/tech/firenote/ui/composable/screen/creation/CreationContainer.kt b/app/src/main/java/ru/tech/firenote/ui/composable/screen/creation/CreationContainer.kt index 08e5510..533d5d4 100644 --- a/app/src/main/java/ru/tech/firenote/ui/composable/screen/creation/CreationContainer.kt +++ b/app/src/main/java/ru/tech/firenote/ui/composable/screen/creation/CreationContainer.kt @@ -4,76 +4,61 @@ import androidx.activity.compose.BackHandler import androidx.compose.animation.AnimatedVisibility import androidx.compose.animation.fadeIn import androidx.compose.animation.fadeOut -import androidx.compose.foundation.layout.* +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.fillMaxHeight +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.width import androidx.compose.material.icons.Icons import androidx.compose.material.icons.twotone.FactCheck import androidx.compose.material.icons.twotone.StickyNote2 import androidx.compose.material3.Divider -import androidx.compose.material3.Icon -import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier -import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.dp import ru.tech.firenote.R -import ru.tech.firenote.viewModel.MainViewModel +import ru.tech.firenote.ui.composable.single.placeholder.Placeholder +import ru.tech.firenote.viewModel.main.MainViewModel @Composable -fun CreationContainer(mainViewModel: MainViewModel, splitScreen: Boolean) { +fun CreationContainer(viewModel: MainViewModel, splitScreen: Boolean) { Box(Modifier.fillMaxSize()) { - if (!mainViewModel.showNoteCreation.currentState) { - mainViewModel.globalNote.value = null - if (splitScreen && mainViewModel.selectedItem.value == 0) { - Column( - modifier = Modifier - .fillMaxSize(), - verticalArrangement = Arrangement.Center, - horizontalAlignment = Alignment.CenterHorizontally - ) { - Icon(Icons.TwoTone.StickyNote2, null, modifier = Modifier.fillMaxSize(0.3f)) - Text(stringResource(R.string.selectNote)) - } + if (!viewModel.showNoteCreation.currentState) { + viewModel.clearGlobalNote() + if (splitScreen && viewModel.selectedItem.value == 0) { + Placeholder(icon = Icons.TwoTone.StickyNote2, textRes = R.string.selectNote) } } - if (!mainViewModel.showGoalCreation.currentState) { - mainViewModel.globalGoal.value = null - if (splitScreen && mainViewModel.selectedItem.value in 1..2) { - Column( - modifier = Modifier - .fillMaxSize(), - verticalArrangement = Arrangement.Center, - horizontalAlignment = Alignment.CenterHorizontally - ) { - Icon(Icons.TwoTone.FactCheck, null, modifier = Modifier.fillMaxSize(0.3f)) - Text(stringResource(R.string.selectGoal)) - } + if (!viewModel.showGoalCreation.currentState) { + viewModel.clearGlobalGoal() + if (splitScreen && viewModel.selectedItem.value in 1..2) { + Placeholder(icon = Icons.TwoTone.FactCheck, textRes = R.string.selectGoal) } } AnimatedVisibility( - visibleState = mainViewModel.showNoteCreation, + visibleState = viewModel.showNoteCreation, enter = fadeIn(), exit = fadeOut() ) { - BackHandler { mainViewModel.showNoteCreation.targetState = false } + BackHandler { viewModel.showNoteCreation.targetState = false } NoteCreationScreen( - state = mainViewModel.showNoteCreation, - globalNote = mainViewModel.globalNote + state = viewModel.showNoteCreation, + globalNote = viewModel.globalNote ) } AnimatedVisibility( - visibleState = mainViewModel.showGoalCreation, + visibleState = viewModel.showGoalCreation, enter = fadeIn(), exit = fadeOut() ) { - BackHandler { mainViewModel.showGoalCreation.targetState = false } + BackHandler { viewModel.showGoalCreation.targetState = false } GoalCreationScreen( - state = mainViewModel.showGoalCreation, - globalGoal = mainViewModel.globalGoal + state = viewModel.showGoalCreation, + globalGoal = viewModel.globalGoal ) } diff --git a/app/src/main/java/ru/tech/firenote/ui/composable/screen/creation/GoalCreationScreen.kt b/app/src/main/java/ru/tech/firenote/ui/composable/screen/creation/GoalCreationScreen.kt index 06e0657..4dd14b1 100644 --- a/app/src/main/java/ru/tech/firenote/ui/composable/screen/creation/GoalCreationScreen.kt +++ b/app/src/main/java/ru/tech/firenote/ui/composable/screen/creation/GoalCreationScreen.kt @@ -40,11 +40,11 @@ import kotlinx.coroutines.launch import ru.tech.firenote.R import ru.tech.firenote.model.Goal import ru.tech.firenote.model.GoalData -import ru.tech.firenote.ui.composable.single.MaterialDialog import ru.tech.firenote.ui.composable.single.bar.EditableAppBar +import ru.tech.firenote.ui.composable.single.dialog.MaterialDialog import ru.tech.firenote.ui.theme.goalColors import ru.tech.firenote.utils.GlobalUtils.blend -import ru.tech.firenote.viewModel.GoalCreationViewModel +import ru.tech.firenote.viewModel.creation.GoalCreationViewModel @OptIn(ExperimentalMaterial3Api::class) @Composable diff --git a/app/src/main/java/ru/tech/firenote/ui/composable/screen/creation/NoteCreationScreen.kt b/app/src/main/java/ru/tech/firenote/ui/composable/screen/creation/NoteCreationScreen.kt index 6845959..e6a3707 100644 --- a/app/src/main/java/ru/tech/firenote/ui/composable/screen/creation/NoteCreationScreen.kt +++ b/app/src/main/java/ru/tech/firenote/ui/composable/screen/creation/NoteCreationScreen.kt @@ -30,12 +30,12 @@ import androidx.lifecycle.viewmodel.compose.viewModel import kotlinx.coroutines.launch import ru.tech.firenote.R import ru.tech.firenote.model.Note -import ru.tech.firenote.ui.composable.single.MaterialDialog import ru.tech.firenote.ui.composable.single.bar.EditableAppBar +import ru.tech.firenote.ui.composable.single.dialog.MaterialDialog import ru.tech.firenote.ui.composable.single.text.EditText import ru.tech.firenote.ui.theme.noteColors import ru.tech.firenote.utils.GlobalUtils.blend -import ru.tech.firenote.viewModel.NoteCreationViewModel +import ru.tech.firenote.viewModel.creation.NoteCreationViewModel @OptIn(ExperimentalMaterial3Api::class) @Composable diff --git a/app/src/main/java/ru/tech/firenote/ui/composable/screen/base/GoalListScreen.kt b/app/src/main/java/ru/tech/firenote/ui/composable/screen/navigation/GoalListScreen.kt similarity index 84% rename from app/src/main/java/ru/tech/firenote/ui/composable/screen/base/GoalListScreen.kt rename to app/src/main/java/ru/tech/firenote/ui/composable/screen/navigation/GoalListScreen.kt index b87d76f..c6dde5e 100644 --- a/app/src/main/java/ru/tech/firenote/ui/composable/screen/base/GoalListScreen.kt +++ b/app/src/main/java/ru/tech/firenote/ui/composable/screen/navigation/GoalListScreen.kt @@ -1,4 +1,4 @@ -package ru.tech.firenote.ui.composable.screen.base +package ru.tech.firenote.ui.composable.screen.navigation import androidx.compose.animation.core.MutableTransitionState import androidx.compose.foundation.clickable @@ -13,9 +13,7 @@ import androidx.compose.material.icons.outlined.Delete import androidx.compose.material.icons.twotone.Cloud import androidx.compose.material.icons.twotone.FindInPage import androidx.compose.material3.CircularProgressIndicator -import androidx.compose.material3.Icon import androidx.compose.material3.SnackbarResult -import androidx.compose.material3.Text import androidx.compose.runtime.* import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier @@ -26,12 +24,13 @@ import ru.tech.firenote.R import ru.tech.firenote.model.Goal import ru.tech.firenote.ui.composable.provider.LocalSnackbarHost import ru.tech.firenote.ui.composable.provider.showSnackbar +import ru.tech.firenote.ui.composable.single.dialog.MaterialDialog import ru.tech.firenote.ui.composable.single.lazyitem.GoalItem -import ru.tech.firenote.ui.composable.single.MaterialDialog -import ru.tech.firenote.ui.composable.single.Toast +import ru.tech.firenote.ui.composable.single.placeholder.Placeholder +import ru.tech.firenote.ui.composable.single.toast.Toast import ru.tech.firenote.ui.state.UIState import ru.tech.firenote.ui.theme.priorityGoal -import ru.tech.firenote.viewModel.GoalListViewModel +import ru.tech.firenote.viewModel.navigation.GoalListViewModel @Suppress("UNCHECKED_CAST") @Composable @@ -107,15 +106,7 @@ fun GoalListScreen( statement1 or statement2 } if (data.isEmpty()) { - Column( - modifier = Modifier - .fillMaxSize(), - verticalArrangement = Arrangement.Center, - horizontalAlignment = Alignment.CenterHorizontally - ) { - Icon(Icons.TwoTone.FindInPage, null, modifier = Modifier.fillMaxSize(0.3f)) - Text(stringResource(R.string.nothingFound)) - } + Placeholder(icon = Icons.TwoTone.FindInPage, textRes = R.string.nothingFound) } } @@ -142,15 +133,7 @@ fun GoalListScreen( } is UIState.Empty -> { state.message?.let { Toast(it) } - Column( - modifier = Modifier - .fillMaxSize(), - verticalArrangement = Arrangement.Center, - horizontalAlignment = Alignment.CenterHorizontally - ) { - Icon(Icons.TwoTone.Cloud, null, modifier = Modifier.fillMaxSize(0.3f)) - Text(stringResource(R.string.noGoals)) - } + Placeholder(icon = Icons.TwoTone.Cloud, textRes = R.string.noGoals) } } diff --git a/app/src/main/java/ru/tech/firenote/ui/composable/screen/base/NoteListScreen.kt b/app/src/main/java/ru/tech/firenote/ui/composable/screen/navigation/NoteListScreen.kt similarity index 82% rename from app/src/main/java/ru/tech/firenote/ui/composable/screen/base/NoteListScreen.kt rename to app/src/main/java/ru/tech/firenote/ui/composable/screen/navigation/NoteListScreen.kt index 93d428f..51076af 100644 --- a/app/src/main/java/ru/tech/firenote/ui/composable/screen/base/NoteListScreen.kt +++ b/app/src/main/java/ru/tech/firenote/ui/composable/screen/navigation/NoteListScreen.kt @@ -1,4 +1,4 @@ -package ru.tech.firenote.ui.composable.screen.base +package ru.tech.firenote.ui.composable.screen.navigation import androidx.compose.animation.core.MutableTransitionState import androidx.compose.foundation.ExperimentalFoundationApi @@ -14,9 +14,7 @@ import androidx.compose.material.icons.outlined.Delete import androidx.compose.material.icons.twotone.Cloud import androidx.compose.material.icons.twotone.FindInPage import androidx.compose.material3.CircularProgressIndicator -import androidx.compose.material3.Icon import androidx.compose.material3.SnackbarResult -import androidx.compose.material3.Text import androidx.compose.runtime.* import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier @@ -27,12 +25,13 @@ import ru.tech.firenote.R import ru.tech.firenote.model.Note import ru.tech.firenote.ui.composable.provider.LocalSnackbarHost import ru.tech.firenote.ui.composable.provider.showSnackbar -import ru.tech.firenote.ui.composable.single.MaterialDialog +import ru.tech.firenote.ui.composable.single.dialog.MaterialDialog import ru.tech.firenote.ui.composable.single.lazyitem.NoteItem -import ru.tech.firenote.ui.composable.single.Toast +import ru.tech.firenote.ui.composable.single.placeholder.Placeholder +import ru.tech.firenote.ui.composable.single.toast.Toast import ru.tech.firenote.ui.state.UIState import ru.tech.firenote.ui.theme.priority -import ru.tech.firenote.viewModel.NoteListViewModel +import ru.tech.firenote.viewModel.navigation.NoteListViewModel @Suppress("UNCHECKED_CAST") @OptIn(ExperimentalFoundationApi::class) @@ -89,15 +88,7 @@ fun NoteListScreen( ) ?: false } if (data.isEmpty()) { - Column( - modifier = Modifier - .fillMaxSize(), - verticalArrangement = Arrangement.Center, - horizontalAlignment = Alignment.CenterHorizontally - ) { - Icon(Icons.TwoTone.FindInPage, null, modifier = Modifier.fillMaxSize(0.3f)) - Text(stringResource(R.string.nothingFound)) - } + Placeholder(icon = Icons.TwoTone.FindInPage, textRes = R.string.nothingFound) } } @@ -124,15 +115,7 @@ fun NoteListScreen( } is UIState.Empty -> { state.message?.let { Toast(it) } - Column( - modifier = Modifier - .fillMaxSize(), - verticalArrangement = Arrangement.Center, - horizontalAlignment = Alignment.CenterHorizontally - ) { - Icon(Icons.TwoTone.Cloud, null, modifier = Modifier.fillMaxSize(0.3f)) - Text(stringResource(R.string.noNotes)) - } + Placeholder(icon = Icons.TwoTone.Cloud, textRes = R.string.noNotes) } } diff --git a/app/src/main/java/ru/tech/firenote/ui/composable/screen/base/ProfileScreen.kt b/app/src/main/java/ru/tech/firenote/ui/composable/screen/navigation/ProfileScreen.kt similarity index 98% rename from app/src/main/java/ru/tech/firenote/ui/composable/screen/base/ProfileScreen.kt rename to app/src/main/java/ru/tech/firenote/ui/composable/screen/navigation/ProfileScreen.kt index f5a308b..8a289e5 100644 --- a/app/src/main/java/ru/tech/firenote/ui/composable/screen/base/ProfileScreen.kt +++ b/app/src/main/java/ru/tech/firenote/ui/composable/screen/navigation/ProfileScreen.kt @@ -1,4 +1,4 @@ -package ru.tech.firenote.ui.composable.screen.base +package ru.tech.firenote.ui.composable.screen.navigation import android.net.Uri import android.widget.Toast.LENGTH_LONG @@ -51,15 +51,15 @@ import com.google.accompanist.flowlayout.FlowRow import ru.tech.firenote.R import ru.tech.firenote.ui.composable.provider.LocalWindowSize import ru.tech.firenote.ui.composable.screen.auth.isValid -import ru.tech.firenote.ui.composable.single.MaterialDialog -import ru.tech.firenote.ui.composable.single.text.MaterialTextField +import ru.tech.firenote.ui.composable.single.dialog.MaterialDialog import ru.tech.firenote.ui.composable.single.lazyitem.ProfileNoteItem -import ru.tech.firenote.ui.composable.single.Toast +import ru.tech.firenote.ui.composable.single.text.MaterialTextField +import ru.tech.firenote.ui.composable.single.toast.Toast import ru.tech.firenote.ui.composable.utils.WindowSize import ru.tech.firenote.ui.route.Screen import ru.tech.firenote.ui.state.UIState import ru.tech.firenote.ui.theme.noteColors -import ru.tech.firenote.viewModel.ProfileViewModel +import ru.tech.firenote.viewModel.navigation.ProfileViewModel @Suppress("UNCHECKED_CAST") @Composable diff --git a/app/src/main/java/ru/tech/firenote/ui/composable/single/FirenoteScaffold.kt b/app/src/main/java/ru/tech/firenote/ui/composable/single/FirenoteScaffold.kt deleted file mode 100644 index 31a045d..0000000 --- a/app/src/main/java/ru/tech/firenote/ui/composable/single/FirenoteScaffold.kt +++ /dev/null @@ -1,224 +0,0 @@ -package ru.tech.firenote.ui.composable.single - -import android.content.Context -import androidx.compose.foundation.layout.fillMaxWidth -import androidx.compose.foundation.layout.padding -import androidx.compose.foundation.text.BasicTextField -import androidx.compose.foundation.text.KeyboardActions -import androidx.compose.material.icons.Icons -import androidx.compose.material.icons.outlined.AddTask -import androidx.compose.material.icons.outlined.Edit -import androidx.compose.material.icons.outlined.Image -import androidx.compose.material.icons.rounded.ArrowBack -import androidx.compose.material.icons.rounded.Close -import androidx.compose.material.icons.rounded.Search -import androidx.compose.material3.* -import androidx.compose.runtime.Composable -import androidx.compose.ui.Modifier -import androidx.compose.ui.graphics.SolidColor -import androidx.compose.ui.input.nestedscroll.nestedScroll -import androidx.compose.ui.platform.LocalFocusManager -import androidx.compose.ui.res.stringResource -import androidx.compose.ui.text.TextStyle -import androidx.compose.ui.text.style.TextAlign -import androidx.compose.ui.text.style.TextOverflow -import androidx.compose.ui.unit.dp -import androidx.compose.ui.unit.sp -import androidx.navigation.NavHostController -import ru.tech.firenote.R -import ru.tech.firenote.ui.composable.navigation.Navigation -import ru.tech.firenote.ui.composable.provider.LocalSnackbarHost -import ru.tech.firenote.ui.composable.single.bar.* -import ru.tech.firenote.ui.route.Screen -import ru.tech.firenote.viewModel.MainViewModel - -@OptIn(ExperimentalMaterial3Api::class) -@Composable -fun FirenoteScaffold( - modifier: Modifier = Modifier, - mainViewModel: MainViewModel, - navController: NavHostController, - context: Context -) { - Scaffold( - topBar = { - AppBarWithInsets( - type = APP_BAR_CENTER, - navigationIcon = { - when (mainViewModel.selectedItem.value) { - 0 -> { - if (!mainViewModel.searchMode.value) { - IconButton(onClick = { - mainViewModel.searchMode - .value = true - mainViewModel.searchString.value = - "" - - }) { - Icon(Icons.Rounded.Search, null) - } - } else { - IconButton(onClick = { - mainViewModel.searchMode - .value = false - mainViewModel.searchString.value = - "" - }) { - Icon(Icons.Rounded.ArrowBack, null) - } - } - } - 1 -> { - if (!mainViewModel.searchMode.value) { - IconButton(onClick = { - mainViewModel.searchMode - .value = true - mainViewModel.searchString.value = - "" - - }) { - Icon(Icons.Rounded.Search, null) - } - } else { - IconButton(onClick = { - mainViewModel.searchMode - .value = false - mainViewModel.searchString.value = - "" - }) { - Icon(Icons.Rounded.ArrowBack, null) - } - } - } - 2 -> { - IconButton(onClick = { - mainViewModel.showUsernameDialog.value = - true - }) { - Icon(Icons.Outlined.Edit, null) - } - } - } - }, - scrollBehavior = mainViewModel.scrollBehavior.value, - title = { - if (!mainViewModel.searchMode.value) { - Text( - text = if (mainViewModel.selectedItem.value == 2) mainViewModel.profileTitle.value - else stringResource(mainViewModel.title.value), - maxLines = 1, - overflow = TextOverflow.Ellipsis - ) - } else { - val localFocusManager = - LocalFocusManager.current - BasicTextField( - modifier = Modifier.fillMaxWidth(), - value = mainViewModel.searchString.value, - textStyle = TextStyle( - fontSize = 22.sp, - color = MaterialTheme.colorScheme.onBackground, - textAlign = TextAlign.Start, - ), - keyboardActions = KeyboardActions( - onDone = { localFocusManager.clearFocus() } - ), - singleLine = true, - cursorBrush = SolidColor(MaterialTheme.colorScheme.onBackground), - onValueChange = { - mainViewModel.searchString.value = it - }) - if (mainViewModel.searchString.value.isEmpty()) { - Text( - text = stringResource(R.string.searchHere), - modifier = Modifier - .fillMaxWidth() - .padding(start = 12.dp), - style = TextStyle( - fontSize = 22.sp, - color = MaterialTheme.colorScheme.outline, - textAlign = TextAlign.Start, - ) - ) - } - } - }, - actions = { - if (!mainViewModel.searchMode.value) { - when (mainViewModel.selectedItem.value) { - 0 -> NoteActions(mainViewModel) - 1 -> GoalActions(mainViewModel) - 2 -> ProfileActions { - navController.navigate(Screen.NoteListScreen.route) { - navController.popBackStack() - launchSingleTop = true - } - android.widget.Toast.makeText( - context, - R.string.seeYouAgain, - android.widget.Toast.LENGTH_SHORT - ).show() - - mainViewModel.signOut() - } - } - } else { - IconButton(onClick = { - mainViewModel.searchString.value = "" - }) { - Icon(Icons.Rounded.Close, null) - } - } - } - ) - }, - floatingActionButton = { - ExtendedFloatingActionButton(onClick = { - when (mainViewModel.selectedItem.value) { - 0 -> { - mainViewModel.showNoteCreation.targetState = - true - mainViewModel.globalNote.value = null - } - 1 -> { - mainViewModel.showGoalCreation.targetState = - true - mainViewModel.globalGoal.value = null - } - 2 -> mainViewModel.resultLauncher.value?.launch("image/*") - } - }, icon = { - when (mainViewModel.selectedItem.value) { - 0 -> Icon(Icons.Outlined.Edit, null) - 1 -> Icon(Icons.Outlined.AddTask, null) - 2 -> Icon(Icons.Outlined.Image, null) - } - }, text = { - when (mainViewModel.selectedItem.value) { - 0 -> Text(stringResource(R.string.addNote)) - 1 -> Text(stringResource(R.string.makeGoal)) - 2 -> Text(stringResource(R.string.pickImage)) - } - }) - }, - bottomBar = { - BottomNavigationBar( - title = mainViewModel.title, - selectedItem = mainViewModel.selectedItem, - searchMode = mainViewModel.searchMode, - searchString = mainViewModel.searchString, - navController = navController, - items = listOf( - Screen.NoteListScreen, - Screen.GoalsScreen, - Screen.ProfileScreen - ), - alwaysShowLabel = false - ) - }, - snackbarHost = { SnackbarHost(LocalSnackbarHost.current) }, - modifier = modifier.nestedScroll(mainViewModel.scrollBehavior.value.nestedScrollConnection) - ) { contentPadding -> - Navigation(navController, contentPadding, mainViewModel) - } -} \ No newline at end of file diff --git a/app/src/main/java/ru/tech/firenote/ui/composable/single/bar/AppBarActions.kt b/app/src/main/java/ru/tech/firenote/ui/composable/single/bar/AppBarActions.kt index 452abfd..5eef4e5 100644 --- a/app/src/main/java/ru/tech/firenote/ui/composable/single/bar/AppBarActions.kt +++ b/app/src/main/java/ru/tech/firenote/ui/composable/single/bar/AppBarActions.kt @@ -20,9 +20,9 @@ import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.dp import ru.tech.firenote.R -import ru.tech.firenote.ui.composable.single.MaterialDialog +import ru.tech.firenote.ui.composable.single.dialog.MaterialDialog import ru.tech.firenote.utils.GlobalUtils.isOnline -import ru.tech.firenote.viewModel.MainViewModel +import ru.tech.firenote.viewModel.main.MainViewModel @Composable fun NoteActions( diff --git a/app/src/main/java/ru/tech/firenote/ui/composable/single/bar/BottomNavigationBar.kt b/app/src/main/java/ru/tech/firenote/ui/composable/single/bar/BottomNavigationBar.kt index f99f9e6..cd9fa5c 100644 --- a/app/src/main/java/ru/tech/firenote/ui/composable/single/bar/BottomNavigationBar.kt +++ b/app/src/main/java/ru/tech/firenote/ui/composable/single/bar/BottomNavigationBar.kt @@ -29,7 +29,7 @@ fun BottomNavigationBar( NavigationBarItem( icon = { Icon( - if (selectedItem.value == index) screen.selectedIcon else screen.icon, + if (selectedItem.value == index) screen.selectedIcon else screen.baseIcon, null ) }, diff --git a/app/src/main/java/ru/tech/firenote/ui/composable/single/bar/SearchBar.kt b/app/src/main/java/ru/tech/firenote/ui/composable/single/bar/SearchBar.kt new file mode 100644 index 0000000..f1919a8 --- /dev/null +++ b/app/src/main/java/ru/tech/firenote/ui/composable/single/bar/SearchBar.kt @@ -0,0 +1,53 @@ +package ru.tech.firenote.ui.composable.single.bar + +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.text.BasicTextField +import androidx.compose.foundation.text.KeyboardActions +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.SolidColor +import androidx.compose.ui.platform.LocalFocusManager +import androidx.compose.ui.res.stringResource +import androidx.compose.ui.text.TextStyle +import androidx.compose.ui.text.style.TextAlign +import androidx.compose.ui.unit.dp +import androidx.compose.ui.unit.sp +import ru.tech.firenote.R + +@Composable +fun SearchBar(searchString: String, onValueChange: (String) -> Unit) { + val localFocusManager = + LocalFocusManager.current + BasicTextField( + modifier = Modifier.fillMaxWidth(), + value = searchString, + textStyle = TextStyle( + fontSize = 22.sp, + color = MaterialTheme.colorScheme.onBackground, + textAlign = TextAlign.Start, + ), + keyboardActions = KeyboardActions( + onDone = { localFocusManager.clearFocus() } + ), + singleLine = true, + cursorBrush = SolidColor(MaterialTheme.colorScheme.onBackground), + onValueChange = { + onValueChange(it) + }) + if (searchString.isEmpty()) { + Text( + text = stringResource(R.string.searchHere), + modifier = Modifier + .fillMaxWidth() + .padding(start = 12.dp), + style = TextStyle( + fontSize = 22.sp, + color = MaterialTheme.colorScheme.outline, + textAlign = TextAlign.Start, + ) + ) + } +} \ No newline at end of file diff --git a/app/src/main/java/ru/tech/firenote/ui/composable/single/MaterialDialog.kt b/app/src/main/java/ru/tech/firenote/ui/composable/single/dialog/MaterialDialog.kt similarity index 57% rename from app/src/main/java/ru/tech/firenote/ui/composable/single/MaterialDialog.kt rename to app/src/main/java/ru/tech/firenote/ui/composable/single/dialog/MaterialDialog.kt index ceee751..489c7d1 100644 --- a/app/src/main/java/ru/tech/firenote/ui/composable/single/MaterialDialog.kt +++ b/app/src/main/java/ru/tech/firenote/ui/composable/single/dialog/MaterialDialog.kt @@ -1,4 +1,4 @@ -package ru.tech.firenote.ui.composable.single +package ru.tech.firenote.ui.composable.single.dialog import androidx.activity.compose.BackHandler import androidx.annotation.StringRes @@ -14,50 +14,6 @@ import androidx.compose.ui.graphics.vector.ImageVector import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.style.TextAlign -@Composable -fun MaterialDialog( - showDialog: MutableState = mutableStateOf(false), - icon: ImageVector, - title: String, - message: String, - confirmText: String, - confirmAction: () -> Unit = {}, - dismissText: String, - dismissAction: () -> Unit = {}, - onDismiss: () -> Unit = {}, - backHandler: @Composable () -> Unit = { BackHandler { showDialog.value = true } } -) { - if (showDialog.value) { - AlertDialog( - icon = { Icon(icon, null) }, - title = { Text(title) }, - text = { Text(message, textAlign = TextAlign.Center) }, - confirmButton = { - TextButton(onClick = { - confirmAction() - showDialog.value = false - }) { - Text(confirmText) - } - }, - dismissButton = { - TextButton(onClick = { - dismissAction() - showDialog.value = false - }) { - Text(dismissText) - } - }, - onDismissRequest = { showDialog.value = false } - ) - } else { - LaunchedEffect(Unit) { onDismiss() } - } - - backHandler() - -} - @Composable fun MaterialDialog( showDialog: MutableState = mutableStateOf(false), @@ -95,9 +51,7 @@ fun MaterialDialog( }, onDismissRequest = { showDialog.value = false } ) - } else { - LaunchedEffect(Unit) { onDismiss() } - } + } else LaunchedEffect(Unit) { onDismiss() } backHandler() } \ No newline at end of file diff --git a/app/src/main/java/ru/tech/firenote/ui/composable/single/placeholder/Placeholder.kt b/app/src/main/java/ru/tech/firenote/ui/composable/single/placeholder/Placeholder.kt new file mode 100644 index 0000000..479d41a --- /dev/null +++ b/app/src/main/java/ru/tech/firenote/ui/composable/single/placeholder/Placeholder.kt @@ -0,0 +1,26 @@ +package ru.tech.firenote.ui.composable.single.placeholder + +import androidx.annotation.StringRes +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.material3.Icon +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.vector.ImageVector +import androidx.compose.ui.res.stringResource + +@Composable +fun Placeholder(icon: ImageVector, @StringRes textRes: Int) { + Column( + modifier = Modifier + .fillMaxSize(), + verticalArrangement = Arrangement.Center, + horizontalAlignment = Alignment.CenterHorizontally + ) { + Icon(icon, null, modifier = Modifier.fillMaxSize(0.3f)) + Text(stringResource(textRes)) + } +} \ No newline at end of file diff --git a/app/src/main/java/ru/tech/firenote/ui/composable/single/scaffold/FirenoteScaffold.kt b/app/src/main/java/ru/tech/firenote/ui/composable/single/scaffold/FirenoteScaffold.kt new file mode 100644 index 0000000..39d5768 --- /dev/null +++ b/app/src/main/java/ru/tech/firenote/ui/composable/single/scaffold/FirenoteScaffold.kt @@ -0,0 +1,156 @@ +package ru.tech.firenote.ui.composable.single.scaffold + +import android.content.Context +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.outlined.AddTask +import androidx.compose.material.icons.outlined.Edit +import androidx.compose.material.icons.outlined.Error +import androidx.compose.material.icons.outlined.Image +import androidx.compose.material.icons.rounded.ArrowBack +import androidx.compose.material.icons.rounded.Close +import androidx.compose.material.icons.rounded.Search +import androidx.compose.material3.* +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.input.nestedscroll.nestedScroll +import androidx.compose.ui.res.stringResource +import androidx.compose.ui.text.style.TextOverflow +import androidx.navigation.NavHostController +import ru.tech.firenote.R +import ru.tech.firenote.ui.composable.navigation.Navigation +import ru.tech.firenote.ui.composable.provider.LocalSnackbarHost +import ru.tech.firenote.ui.composable.single.bar.* +import ru.tech.firenote.ui.route.Screen +import ru.tech.firenote.viewModel.main.MainViewModel + +@OptIn(ExperimentalMaterial3Api::class) +@Composable +fun FirenoteScaffold( + modifier: Modifier = Modifier, + viewModel: MainViewModel, + navController: NavHostController, + context: Context +) { + Scaffold( + topBar = { + AppBarWithInsets( + type = APP_BAR_CENTER, + navigationIcon = { + when (viewModel.selectedItem.value) { + in 0..1 -> { + IconButton(onClick = { + viewModel.dispatchSearch() + }) { + Icon( + if (!viewModel.searchMode.value) Icons.Rounded.Search else Icons.Rounded.ArrowBack, + null + ) + } + } + 2 -> { + IconButton(onClick = { + viewModel.showUsernameDialog.value = true + }) { + Icon(Icons.Outlined.Edit, null) + } + } + } + }, + scrollBehavior = viewModel.scrollBehavior.value, + title = { + if (!viewModel.searchMode.value) { + Text( + text = if (viewModel.selectedItem.value == 2) viewModel.profileTitle.value + else stringResource(viewModel.title.value), + maxLines = 1, + overflow = TextOverflow.Ellipsis + ) + } else { + SearchBar(searchString = viewModel.searchString.value) { + viewModel.updateSearch(it) + } + } + }, + actions = { + if (!viewModel.searchMode.value) { + when (viewModel.selectedItem.value) { + 0 -> NoteActions(viewModel) + 1 -> GoalActions(viewModel) + 2 -> ProfileActions { + navController.navigate(Screen.NoteListScreen.route) { + navController.popBackStack() + launchSingleTop = true + } + android.widget.Toast.makeText( + context, + R.string.seeYouAgain, + android.widget.Toast.LENGTH_SHORT + ).show() + + viewModel.signOut() + } + } + } else { + IconButton(onClick = { + viewModel.updateSearch() + }) { + Icon(Icons.Rounded.Close, null) + } + } + } + ) + }, + floatingActionButton = { + ExtendedFloatingActionButton(onClick = { + when (viewModel.selectedItem.value) { + 0 -> { + viewModel.showNoteCreation.targetState = true + viewModel.clearGlobalNote() + } + 1 -> { + viewModel.showGoalCreation.targetState = true + viewModel.clearGlobalGoal() + } + 2 -> viewModel.resultLauncher.value?.launch("image/*") + } + }, icon = { + Icon( + when (viewModel.selectedItem.value) { + 0 -> Icons.Outlined.Edit + 1 -> Icons.Outlined.AddTask + 2 -> Icons.Outlined.Image + else -> Icons.Outlined.Error + }, null + ) + }, text = { + Text( + when (viewModel.selectedItem.value) { + 0 -> stringResource(R.string.addNote) + 1 -> stringResource(R.string.makeGoal) + 2 -> stringResource(R.string.pickImage) + else -> "" + } + ) + }) + }, + bottomBar = { + BottomNavigationBar( + title = viewModel.title, + selectedItem = viewModel.selectedItem, + searchMode = viewModel.searchMode, + searchString = viewModel.searchString, + navController = navController, + items = listOf( + Screen.NoteListScreen, + Screen.GoalsScreen, + Screen.ProfileScreen + ), + alwaysShowLabel = false + ) + }, + snackbarHost = { SnackbarHost(LocalSnackbarHost.current) }, + modifier = modifier.nestedScroll(viewModel.scrollBehavior.value.nestedScrollConnection) + ) { contentPadding -> + Navigation(navController, contentPadding, viewModel) + } +} \ No newline at end of file diff --git a/app/src/main/java/ru/tech/firenote/ui/composable/single/Toast.kt b/app/src/main/java/ru/tech/firenote/ui/composable/single/toast/Toast.kt similarity index 92% rename from app/src/main/java/ru/tech/firenote/ui/composable/single/Toast.kt rename to app/src/main/java/ru/tech/firenote/ui/composable/single/toast/Toast.kt index b01906b..f307dbd 100644 --- a/app/src/main/java/ru/tech/firenote/ui/composable/single/Toast.kt +++ b/app/src/main/java/ru/tech/firenote/ui/composable/single/toast/Toast.kt @@ -1,4 +1,4 @@ -package ru.tech.firenote.ui.composable.single +package ru.tech.firenote.ui.composable.single.toast import android.widget.Toast import androidx.annotation.StringRes diff --git a/app/src/main/java/ru/tech/firenote/ui/route/Screen.kt b/app/src/main/java/ru/tech/firenote/ui/route/Screen.kt index 4611946..1ac34cd 100644 --- a/app/src/main/java/ru/tech/firenote/ui/route/Screen.kt +++ b/app/src/main/java/ru/tech/firenote/ui/route/Screen.kt @@ -4,39 +4,44 @@ import androidx.annotation.StringRes import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.AccountCircle import androidx.compose.material.icons.filled.FactCheck -import androidx.compose.material.icons.filled.PhoneAndroid import androidx.compose.material.icons.filled.StickyNote2 import androidx.compose.material.icons.outlined.AccountCircle import androidx.compose.material.icons.outlined.FactCheck +import androidx.compose.material.icons.outlined.PhoneAndroid import androidx.compose.material.icons.outlined.StickyNote2 +import androidx.compose.material.icons.rounded.PhoneAndroid import androidx.compose.ui.graphics.vector.ImageVector import ru.tech.firenote.R sealed class Screen( val route: String, @StringRes val resourceId: Int = R.string.app_name, - val icon: ImageVector = Icons.Default.PhoneAndroid, - val selectedIcon: ImageVector = Icons.Default.PhoneAndroid + val baseIcon: ImageVector = Icons.Outlined.PhoneAndroid, + val selectedIcon: ImageVector = Icons.Rounded.PhoneAndroid ) { - object NoteListScreen : - Screen("notes", R.string.notes, Icons.Outlined.StickyNote2, Icons.Filled.StickyNote2) + object NoteListScreen : Screen( + route = "notes", + resourceId = R.string.notes, + baseIcon = Icons.Outlined.StickyNote2, + selectedIcon = Icons.Filled.StickyNote2 + ) object GoalsScreen : Screen( - "goals", - R.string.goals, - Icons.Outlined.FactCheck, - Icons.Filled.FactCheck + route = "goals", + resourceId = R.string.goals, + baseIcon = Icons.Outlined.FactCheck, + selectedIcon = Icons.Filled.FactCheck ) object ProfileScreen : Screen( - "profile", - R.string.profile, - Icons.Outlined.AccountCircle, - Icons.Filled.AccountCircle + route = "profile", + resourceId = R.string.profile, + baseIcon = Icons.Outlined.AccountCircle, + selectedIcon = Icons.Filled.AccountCircle ) - object LoginScreen : Screen("login") - object RegistrationScreen : Screen("register") - object ForgotPasswordScreen : Screen("forgot") + object LoginScreen : Screen(route = "login") + object RegistrationScreen : Screen(route = "register") + object ForgotPasswordScreen : Screen(route = "forgot") } diff --git a/app/src/main/java/ru/tech/firenote/ui/theme/Color.kt b/app/src/main/java/ru/tech/firenote/ui/theme/Color.kt index bd87b04..9a30886 100644 --- a/app/src/main/java/ru/tech/firenote/ui/theme/Color.kt +++ b/app/src/main/java/ru/tech/firenote/ui/theme/Color.kt @@ -17,46 +17,6 @@ val GoalGreen = Color(0xFF92CC77) val GoalCarrot = Color(0xFFBBA05A) val GoalRed = Color(0xFFD57171) -val noteColors = - listOf( - NoteYellow, - NoteGreen, - NoteMint, - NoteBlue, - NoteIndigo, - NoteViolet, - NoteOrange, - NoteRed, - NotePink - ) - -val goalColors = - listOf( - GoalGreen, - GoalCarrot, - GoalRed - ) - -val Int.priority - get() = when (this) { - NoteYellow.toArgb() -> 0 - NoteGreen.toArgb() -> 1 - NoteMint.toArgb() -> 2 - NoteBlue.toArgb() -> 3 - NoteIndigo.toArgb() -> 4 - NoteViolet.toArgb() -> 5 - NoteOrange.toArgb() -> 6 - NoteRed.toArgb() -> 7 - else -> 8 - } - -val Int.priorityGoal - get() = when (this) { - GoalGreen.toArgb() -> 0 - GoalCarrot.toArgb() -> 1 - else -> 2 - } - val md_theme_light_primary = Color(0xFF984065) val md_theme_light_onPrimary = Color(0xFFffffff) val md_theme_light_primaryContainer = Color(0xFFffd8e5) @@ -109,4 +69,45 @@ val md_theme_dark_onSurfaceVariant = Color(0xFFd5c1c6) val md_theme_dark_outline = Color(0xFF9d8c90) val md_theme_dark_inverseOnSurface = Color(0xFF1f1a1b) val md_theme_dark_inverseSurface = Color(0xFFebdfe1) -val md_theme_dark_inversePrimary = Color(0xFF984065) \ No newline at end of file +val md_theme_dark_inversePrimary = Color(0xFF984065) + + +val noteColors = + listOf( + NoteYellow, + NoteGreen, + NoteMint, + NoteBlue, + NoteIndigo, + NoteViolet, + NoteOrange, + NoteRed, + NotePink + ) + +val goalColors = + listOf( + GoalGreen, + GoalCarrot, + GoalRed + ) + +val Int.priority + get() = when (this) { + NoteYellow.toArgb() -> 0 + NoteGreen.toArgb() -> 1 + NoteMint.toArgb() -> 2 + NoteBlue.toArgb() -> 3 + NoteIndigo.toArgb() -> 4 + NoteViolet.toArgb() -> 5 + NoteOrange.toArgb() -> 6 + NoteRed.toArgb() -> 7 + else -> 8 + } + +val Int.priorityGoal + get() = when (this) { + GoalGreen.toArgb() -> 0 + GoalCarrot.toArgb() -> 1 + else -> 2 + } \ No newline at end of file diff --git a/app/src/main/java/ru/tech/firenote/viewModel/AuthViewModel.kt b/app/src/main/java/ru/tech/firenote/viewModel/auth/AuthViewModel.kt similarity index 98% rename from app/src/main/java/ru/tech/firenote/viewModel/AuthViewModel.kt rename to app/src/main/java/ru/tech/firenote/viewModel/auth/AuthViewModel.kt index 14131d7..c8f7620 100644 --- a/app/src/main/java/ru/tech/firenote/viewModel/AuthViewModel.kt +++ b/app/src/main/java/ru/tech/firenote/viewModel/auth/AuthViewModel.kt @@ -1,4 +1,4 @@ -package ru.tech.firenote.viewModel +package ru.tech.firenote.viewModel.auth import androidx.compose.animation.core.MutableTransitionState import androidx.compose.runtime.mutableStateOf diff --git a/app/src/main/java/ru/tech/firenote/viewModel/GoalCreationViewModel.kt b/app/src/main/java/ru/tech/firenote/viewModel/creation/GoalCreationViewModel.kt similarity index 98% rename from app/src/main/java/ru/tech/firenote/viewModel/GoalCreationViewModel.kt rename to app/src/main/java/ru/tech/firenote/viewModel/creation/GoalCreationViewModel.kt index cdbb4f0..906a289 100644 --- a/app/src/main/java/ru/tech/firenote/viewModel/GoalCreationViewModel.kt +++ b/app/src/main/java/ru/tech/firenote/viewModel/creation/GoalCreationViewModel.kt @@ -1,4 +1,4 @@ -package ru.tech.firenote.viewModel +package ru.tech.firenote.viewModel.creation import androidx.compose.runtime.mutableStateOf import androidx.compose.ui.graphics.toArgb diff --git a/app/src/main/java/ru/tech/firenote/viewModel/NoteCreationViewModel.kt b/app/src/main/java/ru/tech/firenote/viewModel/creation/NoteCreationViewModel.kt similarity index 97% rename from app/src/main/java/ru/tech/firenote/viewModel/NoteCreationViewModel.kt rename to app/src/main/java/ru/tech/firenote/viewModel/creation/NoteCreationViewModel.kt index e8d32bf..9cc86ab 100644 --- a/app/src/main/java/ru/tech/firenote/viewModel/NoteCreationViewModel.kt +++ b/app/src/main/java/ru/tech/firenote/viewModel/creation/NoteCreationViewModel.kt @@ -1,4 +1,4 @@ -package ru.tech.firenote.viewModel +package ru.tech.firenote.viewModel.creation import androidx.compose.runtime.mutableStateOf import androidx.compose.ui.graphics.toArgb diff --git a/app/src/main/java/ru/tech/firenote/viewModel/MainViewModel.kt b/app/src/main/java/ru/tech/firenote/viewModel/main/MainViewModel.kt similarity index 85% rename from app/src/main/java/ru/tech/firenote/viewModel/MainViewModel.kt rename to app/src/main/java/ru/tech/firenote/viewModel/main/MainViewModel.kt index fec40e1..0df9355 100644 --- a/app/src/main/java/ru/tech/firenote/viewModel/MainViewModel.kt +++ b/app/src/main/java/ru/tech/firenote/viewModel/main/MainViewModel.kt @@ -1,4 +1,4 @@ -package ru.tech.firenote.viewModel +package ru.tech.firenote.viewModel.main import android.net.Uri import androidx.activity.compose.ManagedActivityResultLauncher @@ -65,4 +65,22 @@ class MainViewModel @Inject constructor( repository.auth.signOut() } + fun dispatchSearch() { + searchMode.value = !searchMode.value + updateSearch() + } + + fun updateSearch(newValue: String = "") { + searchString.value = newValue + } + + fun clearGlobalGoal() { + globalGoal.value = null + + } + + fun clearGlobalNote() { + globalNote.value = null + } + } \ No newline at end of file diff --git a/app/src/main/java/ru/tech/firenote/viewModel/GoalListViewModel.kt b/app/src/main/java/ru/tech/firenote/viewModel/navigation/GoalListViewModel.kt similarity index 97% rename from app/src/main/java/ru/tech/firenote/viewModel/GoalListViewModel.kt rename to app/src/main/java/ru/tech/firenote/viewModel/navigation/GoalListViewModel.kt index 5e82e66..c64b62a 100644 --- a/app/src/main/java/ru/tech/firenote/viewModel/GoalListViewModel.kt +++ b/app/src/main/java/ru/tech/firenote/viewModel/navigation/GoalListViewModel.kt @@ -1,4 +1,4 @@ -package ru.tech.firenote.viewModel +package ru.tech.firenote.viewModel.navigation import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope diff --git a/app/src/main/java/ru/tech/firenote/viewModel/NoteListViewModel.kt b/app/src/main/java/ru/tech/firenote/viewModel/navigation/NoteListViewModel.kt similarity index 97% rename from app/src/main/java/ru/tech/firenote/viewModel/NoteListViewModel.kt rename to app/src/main/java/ru/tech/firenote/viewModel/navigation/NoteListViewModel.kt index f419bf2..89bba34 100644 --- a/app/src/main/java/ru/tech/firenote/viewModel/NoteListViewModel.kt +++ b/app/src/main/java/ru/tech/firenote/viewModel/navigation/NoteListViewModel.kt @@ -1,4 +1,4 @@ -package ru.tech.firenote.viewModel +package ru.tech.firenote.viewModel.navigation import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope diff --git a/app/src/main/java/ru/tech/firenote/viewModel/ProfileViewModel.kt b/app/src/main/java/ru/tech/firenote/viewModel/navigation/ProfileViewModel.kt similarity index 99% rename from app/src/main/java/ru/tech/firenote/viewModel/ProfileViewModel.kt rename to app/src/main/java/ru/tech/firenote/viewModel/navigation/ProfileViewModel.kt index a1baec0..5a47065 100644 --- a/app/src/main/java/ru/tech/firenote/viewModel/ProfileViewModel.kt +++ b/app/src/main/java/ru/tech/firenote/viewModel/navigation/ProfileViewModel.kt @@ -1,4 +1,4 @@ -package ru.tech.firenote.viewModel +package ru.tech.firenote.viewModel.navigation import android.net.Uri import androidx.lifecycle.ViewModel diff --git a/app/src/test/java/ru/tech/firenote/ExampleUnitTest.kt b/app/src/test/java/ru/tech/firenote/ExampleUnitTest.kt deleted file mode 100644 index 1398ac4..0000000 --- a/app/src/test/java/ru/tech/firenote/ExampleUnitTest.kt +++ /dev/null @@ -1,16 +0,0 @@ -package ru.tech.firenote - -import org.junit.Assert.assertEquals -import org.junit.Test - -/** - * Example local unit test, which will execute on the development machine (host). - * - * See [testing documentation](http://d.android.com/tools/testing). - */ -class ExampleUnitTest { - @Test - fun addition_isCorrect() { - assertEquals(4, 2 + 2) - } -} \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts index 7c16a7f..92e47dd 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -15,4 +15,8 @@ buildscript { tasks.register("clean", Delete::class) { delete(rootProject.buildDir) +} + +tasks.withType().configureEach { + kotlinOptions.freeCompilerArgs += "-opt-in=kotlin.RequiresOptIn" } \ No newline at end of file