Skip to content

Commit

Permalink
Improve Discard Changes Dialog strings (#15597)
Browse files Browse the repository at this point in the history
Co-authored-by: David Allison <[email protected]>
  • Loading branch information
Giyutomioka-SS and david-allison authored Feb 20, 2024
1 parent 1bfef1b commit baf1c38
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ class CardTemplateBrowserAppearanceEditor : AnkiActivity() {
}

private fun showDiscardChangesDialog() {
DiscardChangesDialog.showDialog(this, ::discardChangesAndClose)
DiscardChangesDialog.showDialog(this) {
discardChangesAndClose()
}
}

private fun showRestoreDefaultDialog() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,23 @@ package com.ichi2.anki.dialogs

import android.content.Context
import androidx.appcompat.app.AlertDialog
import com.ichi2.anki.CollectionManager
import com.ichi2.anki.R
import com.ichi2.utils.message
import com.ichi2.utils.negativeButton
import com.ichi2.utils.positiveButton
import com.ichi2.utils.show

class DiscardChangesDialog {
companion object {
fun showDialog(
context: Context,
positiveMethod: () -> Unit
) = AlertDialog.Builder(context).show {
message(R.string.discard_unsaved_changes)
positiveButton(R.string.dialog_ok) { positiveMethod() }
negativeButton(R.string.dialog_cancel)
}
object DiscardChangesDialog {
fun showDialog(
context: Context,
positiveButtonText: String = context.getString(R.string.discard),
negativeButtonText: String = CollectionManager.TR.addingKeepEditing(),
message: String = CollectionManager.TR.addingDiscardCurrentInput(),
positiveMethod: () -> Unit
) = AlertDialog.Builder(context).show {
message(text = message)
positiveButton(text = positiveButtonText) { positiveMethod() }
negativeButton(text = negativeButtonText)
}
}
2 changes: 1 addition & 1 deletion AnkiDroid/src/main/res/values/02-strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@

<!-- Card editor -->
<string name="cardeditor_title_edit_card">Edit note</string>
<string name="discard_unsaved_changes">Close and lose current input?</string>
<string name="discard">Discard</string>
<string name="note_editor_no_cards_created">No cards created. Please fill in more fields</string>
<string name="note_editor_no_first_field">The first field is empty</string>
<string name="note_editor_no_cloze_delations">This note type must contain cloze deletions</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,14 @@ class CardTemplateEditorTest : RobolectricTest() {
// Make sure we get a confirmation dialog if we hit the back button
assertTrue("Unable to click?", shadowTestEditor.clickMenuItem(android.R.id.home))
advanceRobolectricLooperWithSleep()
assertEquals("Wrong dialog shown?", getAlertDialogText(true), getResourceString(R.string.discard_unsaved_changes))
assertEquals("Wrong dialog shown?", getAlertDialogText(true), "Discard current input?")
clickAlertDialogButton(DialogInterface.BUTTON_NEGATIVE, false)
advanceRobolectricLooperWithSleep()
assertTrue("model change not preserved despite canceling back button?", testEditor.modelHasChanged())

// Make sure we things are cleared out after a cancel
assertTrue("Unable to click?", shadowTestEditor.clickMenuItem(android.R.id.home))
assertEquals("Wrong dialog shown?", getAlertDialogText(true), getResourceString(R.string.discard_unsaved_changes))
assertEquals("Wrong dialog shown?", getAlertDialogText(true), "Discard current input?")
clickAlertDialogButton(DialogInterface.BUTTON_POSITIVE, false)
advanceRobolectricLooperWithSleep()
assertFalse("model change not cleared despite discarding changes?", testEditor.modelHasChanged())
Expand Down

0 comments on commit baf1c38

Please sign in to comment.