-
Notifications
You must be signed in to change notification settings - Fork 136
[WOOMOB-1347] - Booking details note - new screen to manage the note #14799
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
f0f3c2c
Create BookingNoteFragment and show it on note tap
AdamGrzybkowski 8a4fa2e
Load booking and show the note
AdamGrzybkowski 0c8fd4c
Show Done button with progress indicator
AdamGrzybkowski 300fa3c
Introduce BookingUpdatePayload to update booking via API
AdamGrzybkowski 736f555
Trigger booking update on Done button tap in VM
AdamGrzybkowski c8771f8
Fix NoteTextField cursor position
AdamGrzybkowski c558209
Add tests for BookingNoteViewModel
AdamGrzybkowski 4689f0a
Use BookingDao.getBooking directly
AdamGrzybkowski d66ec63
Adjust BookingNoteViewModelTest
AdamGrzybkowski File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
WooCommerce/src/main/kotlin/com/woocommerce/android/ui/bookings/note/BookingNoteFragment.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| package com.woocommerce.android.ui.bookings.note | ||
|
|
||
| import android.os.Bundle | ||
| import android.view.LayoutInflater | ||
| import android.view.View | ||
| import android.view.ViewGroup | ||
| import androidx.fragment.app.viewModels | ||
| import androidx.navigation.fragment.findNavController | ||
| import com.woocommerce.android.ui.base.BaseFragment | ||
| import com.woocommerce.android.ui.base.UIMessageResolver | ||
| import com.woocommerce.android.ui.compose.composeView | ||
| import com.woocommerce.android.ui.main.AppBarStatus | ||
| import com.woocommerce.android.viewmodel.MultiLiveEvent | ||
| import dagger.hilt.android.AndroidEntryPoint | ||
| import javax.inject.Inject | ||
|
|
||
| @AndroidEntryPoint | ||
| class BookingNoteFragment : BaseFragment() { | ||
|
|
||
| @Inject | ||
| lateinit var uiMessageResolver: UIMessageResolver | ||
|
|
||
| private val viewModel: BookingNoteViewModel by viewModels() | ||
|
|
||
| override val activityAppBarStatus: AppBarStatus | ||
| get() = AppBarStatus.Hidden | ||
|
|
||
| override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View { | ||
| return composeView { | ||
| BookingNoteScreen( | ||
| viewModel = viewModel, | ||
| onBack = { findNavController().popBackStack() }, | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
| super.onViewCreated(view, savedInstanceState) | ||
| handleEvents() | ||
| } | ||
|
|
||
| private fun handleEvents() { | ||
| viewModel.event.observe(viewLifecycleOwner) { event -> | ||
| when (event) { | ||
| is MultiLiveEvent.Event.ShowSnackbar -> { | ||
| uiMessageResolver.showSnack(event.message) | ||
| } | ||
| is MultiLiveEvent.Event.Exit -> { | ||
| findNavController().navigateUp() | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } |
146 changes: 146 additions & 0 deletions
146
WooCommerce/src/main/kotlin/com/woocommerce/android/ui/bookings/note/BookingNoteScreen.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,146 @@ | ||
| package com.woocommerce.android.ui.bookings.note | ||
|
|
||
| import androidx.compose.foundation.background | ||
| import androidx.compose.foundation.layout.Box | ||
| import androidx.compose.foundation.layout.fillMaxSize | ||
| import androidx.compose.foundation.layout.padding | ||
| import androidx.compose.foundation.layout.size | ||
| import androidx.compose.foundation.text.BasicTextField | ||
| import androidx.compose.material3.CircularProgressIndicator | ||
| import androidx.compose.material3.MaterialTheme | ||
| import androidx.compose.material3.Scaffold | ||
| import androidx.compose.material3.Text | ||
| import androidx.compose.runtime.Composable | ||
| import androidx.compose.runtime.LaunchedEffect | ||
| import androidx.compose.runtime.getValue | ||
| import androidx.compose.runtime.livedata.observeAsState | ||
| import androidx.compose.runtime.mutableStateOf | ||
| import androidx.compose.runtime.remember | ||
| import androidx.compose.runtime.rememberUpdatedState | ||
| import androidx.compose.runtime.saveable.rememberSaveable | ||
| import androidx.compose.runtime.setValue | ||
| import androidx.compose.ui.Modifier | ||
| import androidx.compose.ui.draw.shadow | ||
| import androidx.compose.ui.focus.FocusRequester | ||
| import androidx.compose.ui.focus.focusRequester | ||
| import androidx.compose.ui.graphics.SolidColor | ||
| import androidx.compose.ui.res.stringResource | ||
| import androidx.compose.ui.text.TextRange | ||
| import androidx.compose.ui.text.input.TextFieldValue | ||
| import androidx.compose.ui.unit.dp | ||
| import com.woocommerce.android.R | ||
| import com.woocommerce.android.ui.compose.component.Toolbar | ||
| import com.woocommerce.android.ui.compose.component.WCTextButton | ||
|
|
||
| @Composable | ||
| fun BookingNoteScreen( | ||
| viewModel: BookingNoteViewModel, | ||
| onBack: () -> Unit, | ||
| ) { | ||
| val viewState by viewModel.state.observeAsState() | ||
| viewState?.let { | ||
| BookingNoteScreen( | ||
| viewState = it, | ||
| onBack = onBack, | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| @Composable | ||
| fun BookingNoteScreen( | ||
| viewState: BookingNoteViewState, | ||
| onBack: () -> Unit, | ||
| ) { | ||
| val focusRequester = remember { FocusRequester() } | ||
|
|
||
| // Request focus only after the note is available in the composition | ||
| LaunchedEffect(viewState.editedNote != null) { | ||
| focusRequester.requestFocus() | ||
| } | ||
|
|
||
| Scaffold( | ||
| topBar = { | ||
| Toolbar( | ||
| title = stringResource(R.string.booking_note_screen_title), | ||
| onNavigationButtonClick = onBack, | ||
| actions = { | ||
| if (viewState.isSaveVisible) { | ||
| WCTextButton( | ||
| onClick = viewState.onSaveClicked, | ||
| enabled = viewState.isSaveEnabled, | ||
| ) { | ||
| when (viewState.noteSaveStatus) { | ||
| is NoteSaveStatus.Idle -> { | ||
| Text(stringResource(R.string.booking_note_screen_done)) | ||
| } | ||
|
|
||
| is NoteSaveStatus.InProgress -> { | ||
| CircularProgressIndicator( | ||
| modifier = Modifier.size(24.dp) | ||
| ) | ||
| } | ||
| } | ||
| } | ||
| } | ||
| }, | ||
| modifier = Modifier.shadow(4.dp) | ||
| ) | ||
| } | ||
| ) { innerPadding -> | ||
| Box( | ||
| modifier = Modifier | ||
| .background(MaterialTheme.colorScheme.surface) | ||
| .padding(top = innerPadding.calculateTopPadding()) | ||
| ) { | ||
| viewState.editedNote?.let { | ||
| NoteTextField( | ||
| value = it, | ||
| onValueChange = viewState.onNoteChange, | ||
| enabled = viewState.noteEditable, | ||
| modifier = Modifier | ||
| .fillMaxSize() | ||
| .padding(horizontal = 16.dp, vertical = 12.dp) | ||
| .focusRequester(focusRequester) | ||
| ) | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @Composable | ||
| private fun NoteTextField( | ||
| value: String, | ||
| onValueChange: (String) -> Unit, | ||
| enabled: Boolean, | ||
| modifier: Modifier = Modifier, | ||
| ) { | ||
| var textFieldValueState by rememberSaveable(stateSaver = TextFieldValue.Saver) { | ||
| mutableStateOf( | ||
| TextFieldValue( | ||
| text = value, | ||
| selection = TextRange(value.length) | ||
| ) | ||
| ) | ||
| } | ||
|
|
||
| val textFieldValue = textFieldValueState.copy(text = value) | ||
|
|
||
| val lastValue by rememberUpdatedState(value) | ||
|
|
||
| BasicTextField( | ||
| value = textFieldValue, | ||
| onValueChange = { | ||
| textFieldValueState = it | ||
| if (it.text != lastValue) { | ||
| // Update external value when changed | ||
| onValueChange(it.text) | ||
| } | ||
| }, | ||
| enabled = enabled, | ||
| modifier = modifier, | ||
| textStyle = MaterialTheme.typography.bodyLarge.copy( | ||
| color = MaterialTheme.colorScheme.onSurface | ||
| ), | ||
| cursorBrush = SolidColor(MaterialTheme.colorScheme.primary) | ||
| ) | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.