Skip to content
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

fix: instant note editor to restore text when orientation changes #17935

Merged
merged 1 commit into from
Feb 9, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ class InstantNoteEditorActivity :
private val editMode: EditMode
get() = viewModel.editorMode.value

private val updatedTextKey = "updatedText"

private lateinit var editModeButton: MaterialButton

private var editFieldsLayout: LinearLayout? = null
Expand Down Expand Up @@ -128,7 +130,10 @@ class InstantNoteEditorActivity :
return
}

handleSharedText(intent)
viewModel.setClozeFieldText(
savedInstanceState?.getString(updatedTextKey) ?: getSharedIntentText(intent),
)

setupErrorListeners()
prepareEditorDialog()
}
Expand Down Expand Up @@ -180,12 +185,8 @@ class InstantNoteEditorActivity :
}
}

/** Handles the shared text received through an Intent. **/
private fun handleSharedText(receivedIntent: Intent) {
val sharedText = receivedIntent.getStringExtra(Intent.EXTRA_TEXT) ?: return
Timber.d("Setting cloze field text to $sharedText")
viewModel.setClozeFieldText(sharedText)
}
/** Gets the shared text received through an Intent. **/
private fun getSharedIntentText(receivedIntent: Intent): String? = receivedIntent.getStringExtra(Intent.EXTRA_TEXT)

private fun openNoteEditor() {
val sharedText = clozeEditTextField.text.toString()
Expand Down Expand Up @@ -251,6 +252,11 @@ class InstantNoteEditorActivity :
)
}

override fun onSaveInstanceState(outState: Bundle) {
super.onSaveInstanceState(outState)
if (intentTextChanged()) outState.putString(updatedTextKey, clozeFieldText)
}

@KotlinCleanup("notetypeJson -> non-null")
private fun createEditFields(
context: Context,
Expand Down