Skip to content

Commit

Permalink
refactor(nav): remove duplicate string
Browse files Browse the repository at this point in the history
```
back_pressed_once -> Press back again to exit
back_pressed_once_reviewer -> Press back again to return
```

Issue 14558
  • Loading branch information
david-allison committed Jan 16, 2025
1 parent f0ad34f commit 1358b41
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ abstract class AbstractFlashcardViewer :

override fun setupBackPressedCallbacks() {
onBackPressedDispatcher.addCallback(this, defaultOnBackCallback)
onBackPressedDispatcher.addCallback(this, exitViaDoubleTapBackCallback(R.string.back_pressed_once_reviewer))
onBackPressedDispatcher.addCallback(this, exitViaDoubleTapBackCallback())
super.setupBackPressedCallbacks()
}

Expand Down
2 changes: 1 addition & 1 deletion AnkiDroid/src/main/java/com/ichi2/anki/DeckPicker.kt
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,7 @@ open class DeckPicker :

override fun setupBackPressedCallbacks() {
onBackPressedDispatcher.addCallback(this, exitAndSyncBackCallback)
onBackPressedDispatcher.addCallback(this, exitViaDoubleTapBackCallback(R.string.back_pressed_once))
onBackPressedDispatcher.addCallback(this, exitViaDoubleTapBackCallback())
onBackPressedDispatcher.addCallback(this, closeFloatingActionBarBackPressCallback)
super.setupBackPressedCallbacks()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ package com.ichi2.anki.android.back

import android.content.SharedPreferences.OnSharedPreferenceChangeListener
import androidx.activity.OnBackPressedCallback
import androidx.annotation.StringRes
import androidx.preference.PreferenceManager
import com.google.android.material.snackbar.Snackbar
import com.ichi2.anki.AnkiActivity
import com.ichi2.anki.AnkiDroidApp
import com.ichi2.anki.R
import com.ichi2.anki.snackbar.showSnackbar
import com.ichi2.libanki.Consts
import com.ichi2.utils.HandlerUtils
Expand All @@ -33,14 +33,12 @@ import timber.log.Timber
* [AnkiActivity.showedActivityFailedScreen]
*/
// TODO: Convert this to a class when context parameters are usable
fun AnkiActivity.exitViaDoubleTapBackCallback(
@StringRes stringRes: Int,
): OnBackPressedCallback =
fun AnkiActivity.exitViaDoubleTapBackCallback(): OnBackPressedCallback =
object : OnBackPressedCallback(enabled = exitViaDoubleTapBack) {
lateinit var strongListenerReference: OnSharedPreferenceChangeListener

override fun handleOnBackPressed() {
showSnackbar(stringRes, Snackbar.LENGTH_SHORT)
showSnackbar(R.string.back_pressed_once, Snackbar.LENGTH_SHORT)
this.isEnabled = false
HandlerUtils.executeFunctionWithDelay(Consts.SHORT_TOAST_DURATION) {
this.isEnabled = true
Expand Down
1 change: 0 additions & 1 deletion AnkiDroid/src/main/res/values/02-strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,6 @@
<string name="password_empty">Password is required</string>

<string name="back_pressed_once">Press back again to exit</string>
<string name="back_pressed_once_reviewer">Press back again to return</string>

<!-- %% is required to display % symbol. Reference: https://stackoverflow.com/a/16834358 -->
<string name="percentage">%s%%</string>
Expand Down

0 comments on commit 1358b41

Please sign in to comment.