Skip to content

Commit

Permalink
changed packages and removed deprecated accompanist insets library
Browse files Browse the repository at this point in the history
  • Loading branch information
T8RIN committed Mar 22, 2022
1 parent 6d61eb2 commit 2a1a252
Show file tree
Hide file tree
Showing 20 changed files with 445 additions and 636 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,10 @@ dependencies {
implementation("androidx.lifecycle:lifecycle-viewmodel-compose:2.5.0-alpha04")
implementation("androidx.navigation:navigation-compose:2.5.0-alpha03")
implementation("androidx.constraintlayout:constraintlayout-compose:1.0.0")
implementation("androidx.compose.foundation:foundation:1.2.0-alpha05")

//Accompanist
implementation("com.google.accompanist:accompanist-systemuicontroller:0.24.2-alpha")
implementation("com.google.accompanist:accompanist-insets:0.24.2-alpha")
implementation("com.google.accompanist:accompanist-flowlayout:0.24.2-alpha")

//Tests
Expand Down
562 changes: 7 additions & 555 deletions app/src/main/java/ru/tech/firenote/MainActivity.kt

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions app/src/main/java/ru/tech/firenote/di/AppModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ object AppModule {
fun provideNoteRepository(
database: DatabaseReference,
storage: StorageReference
): NoteRepository =
NoteRepositoryImpl(database, storage)
): NoteRepository = NoteRepositoryImpl(database, storage)

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
package ru.tech.firenote.ui.composable.app

import android.annotation.SuppressLint
import android.content.pm.ActivityInfo
import androidx.activity.ComponentActivity
import androidx.activity.compose.BackHandler
import androidx.compose.foundation.layout.Row
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.ExitToApp
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.SnackbarHostState
import androidx.compose.material3.Surface
import androidx.compose.runtime.*
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.alpha
import androidx.lifecycle.viewmodel.compose.viewModel
import androidx.navigation.NavHostController
import ru.tech.firenote.R
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.utils.WindowSize
import ru.tech.firenote.ui.theme.FirenoteTheme
import ru.tech.firenote.viewModel.MainViewModel

@SuppressLint("SourceLockedOrientationActivity")
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun FirenoteApp(
context: ComponentActivity,
windowSize: WindowSize,
splitScreen: Boolean,
navController: NavHostController,
mainViewModel: MainViewModel = viewModel()
) {

val isScaffoldVisible by derivedStateOf {
!mainViewModel.showNoteCreation.currentState
|| !mainViewModel.showNoteCreation.targetState
|| !mainViewModel.showGoalCreation.currentState
|| !mainViewModel.showGoalCreation.targetState
}

FirenoteTheme {
MaterialDialog(
showDialog = rememberSaveable { mutableStateOf(false) },
icon = Icons.Filled.ExitToApp,
title = R.string.exitApp,
message = R.string.exitAppMessage,
confirmText = R.string.stay,
dismissText = R.string.close,
dismissAction = { context.finishAffinity() }
)
if (mainViewModel.searchMode.value) BackHandler {
mainViewModel.searchMode.value = false
mainViewModel.searchString.value = ""
}


val snackbarHostState = remember { SnackbarHostState() }
CompositionLocalProvider(
LocalSnackbarHost provides snackbarHostState,
LocalWindowSize provides windowSize
) {
if (mainViewModel.isAuth.value) {
AuthScreen(mainViewModel.isAuth)
context.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
} else {
context.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
if (splitScreen) {
Row {
FirenoteScaffold(
modifier = Modifier.weight(1f),
mainViewModel = mainViewModel,
navController = navController,
context = context
)
Surface(modifier = Modifier.weight(1.5f)) {
CreationContainer(mainViewModel, splitScreen)
}
}
} else {
FirenoteScaffold(
modifier = Modifier.alpha(if (isScaffoldVisible) 1f else 0f),
mainViewModel = mainViewModel,
navController = navController,
context = context
)
CreationContainer(mainViewModel, splitScreen)
}
}
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package ru.tech.firenote.ui.composable.screen.creation

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.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

@Composable
fun CreationContainer(mainViewModel: 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 (!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))
}
}
}

AnimatedVisibility(
visibleState = mainViewModel.showNoteCreation,
enter = fadeIn(),
exit = fadeOut()
) {
BackHandler { mainViewModel.showNoteCreation.targetState = false }

NoteCreationScreen(
state = mainViewModel.showNoteCreation,
globalNote = mainViewModel.globalNote
)
}

AnimatedVisibility(
visibleState = mainViewModel.showGoalCreation,
enter = fadeIn(),
exit = fadeOut()
) {
BackHandler { mainViewModel.showGoalCreation.targetState = false }

GoalCreationScreen(
state = mainViewModel.showGoalCreation,
globalGoal = mainViewModel.globalGoal
)
}

if (splitScreen) {
Divider(
Modifier
.fillMaxHeight()
.width(1.dp)
.align(Alignment.CenterStart)
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,14 @@ import androidx.compose.ui.text.style.TextDecoration
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.lifecycle.viewmodel.compose.viewModel
import com.google.accompanist.insets.navigationBarsPadding
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.bar.EditableAppBar
import ru.tech.firenote.ui.composable.single.MaterialDialog
import ru.tech.firenote.ui.composable.single.bar.EditableAppBar
import ru.tech.firenote.ui.theme.goalColors
import ru.tech.firenote.utils.Utils.blend
import ru.tech.firenote.utils.GlobalUtils.blend
import ru.tech.firenote.viewModel.GoalCreationViewModel

@OptIn(ExperimentalMaterial3Api::class)
Expand Down Expand Up @@ -298,7 +297,10 @@ fun GoalCreationScreen(
.weight(1f)
.padding(top = 12.dp)
.clickable(remember { MutableInteractionSource() }, null) {
viewModel.updateDone(index, !(viewModel.goalContent.value[index].done ?: false))
viewModel.updateDone(
index,
!(viewModel.goalContent.value[index].done ?: false)
)
},
style = TextStyle(
fontSize = 22.sp,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,14 @@ import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import androidx.lifecycle.viewmodel.compose.viewModel
import com.google.accompanist.insets.navigationBarsPadding
import kotlinx.coroutines.launch
import ru.tech.firenote.R
import ru.tech.firenote.model.Note
import ru.tech.firenote.ui.composable.single.text.EditText
import ru.tech.firenote.ui.composable.single.bar.EditableAppBar
import ru.tech.firenote.ui.composable.single.MaterialDialog
import ru.tech.firenote.ui.composable.single.bar.EditableAppBar
import ru.tech.firenote.ui.composable.single.text.EditText
import ru.tech.firenote.ui.theme.noteColors
import ru.tech.firenote.utils.Utils.blend
import ru.tech.firenote.utils.GlobalUtils.blend
import ru.tech.firenote.viewModel.NoteCreationViewModel

@OptIn(ExperimentalMaterial3Api::class)
Expand Down
Loading

0 comments on commit 2a1a252

Please sign in to comment.