Skip to content

Commit

Permalink
Allowing to navigate back
Browse files Browse the repository at this point in the history
  • Loading branch information
leandroBorgesFerreira committed Jul 5, 2023
1 parent 740df6e commit 648eb20
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,13 @@ fun NavigationGraph() {
)

NoteDetailsScreen(

noteId.takeIf { it != "null" },
noteTitle.takeIf { it != "null" },
noteDetailsViewModel
noteDetailsViewModel,
navigateBack = {
navController.navigateUp()
}
)
} else {
throw IllegalArgumentException("Wrong route!")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import androidx.compose.animation.slideInVertically
import androidx.compose.animation.slideOutVertically
import androidx.compose.animation.with
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.ColumnScope
Expand All @@ -17,9 +18,13 @@ import androidx.compose.foundation.layout.imePadding
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyListState
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.CornerSize
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.ArrowBack
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
Expand All @@ -38,6 +43,7 @@ import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleEventObserver
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.navigation.compose.rememberNavController
import br.com.leandroferreira.app_sample.R
import br.com.leandroferreira.app_sample.screens.note.input.InputScreen
import br.com.leandroferreira.app_sample.theme.BACKGROUND_VARIATION
Expand All @@ -53,8 +59,11 @@ import java.util.UUID
fun NoteDetailsScreen(
documentId: String?,
title: String?,
noteDetailsViewModel: NoteDetailsViewModel
noteDetailsViewModel: NoteDetailsViewModel,
navigateBack: () -> Unit,
) {
val navController = rememberNavController()

if (documentId != null) {
noteDetailsViewModel.requestDocumentContent(documentId)
} else {
Expand All @@ -64,14 +73,30 @@ fun NoteDetailsScreen(
)
}

Scaffold(topBar = {
TopAppBar(title = {
Text(
text = title?.takeIf { it.isNotBlank() } ?: stringResource(id = R.string.note),
color = MaterialTheme.colorScheme.onPrimary
Scaffold(
topBar = {
TopAppBar(
title = {
Text(
text = title?.takeIf { it.isNotBlank() }
?: stringResource(id = R.string.note),
color = MaterialTheme.colorScheme.onPrimary
)
},
navigationIcon = {
Icon(
modifier = Modifier
.clip(CircleShape)
.clickable(onClick = navigateBack)
.padding(10.dp),
imageVector = Icons.Filled.ArrowBack,
contentDescription = stringResource(R.string.back),
tint = MaterialTheme.colorScheme.onPrimary
)
}
)
})
}) { paddingValues ->
},
) { paddingValues ->
Column(
modifier = Modifier
.padding(top = paddingValues.calculateTopPadding())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package br.com.leandroferreira.app_sample.screens.note

import android.util.Log
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.viewModelScope
Expand Down Expand Up @@ -99,7 +98,6 @@ class NoteDetailsViewModel(
)

if (stories.noContent()) {
Log.d()
documentRepository.deleteDocument(document)
} else {
documentRepository.saveDocument(
Expand Down
1 change: 1 addition & 0 deletions app_sample/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@
<string name="last_created">Create</string>
<string name="name">Name</string>
<string name="add_note">Add note</string>
<string name="back">Back</string>
</resources>

0 comments on commit 648eb20

Please sign in to comment.