Skip to content

Commit

Permalink
feat(deck-options): add redundant 'save' button
Browse files Browse the repository at this point in the history
It's more 'standard' Android UI to use a menu

This may be removed once we fix accessibility
 on the deck options

Fixes 14438
  • Loading branch information
david-allison committed Feb 15, 2024
1 parent fa7ebae commit 7537307
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
24 changes: 24 additions & 0 deletions AnkiDroid/src/main/java/com/ichi2/anki/pages/DeckOptions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,13 @@ package com.ichi2.anki.pages
import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.view.KeyEvent
import android.view.View
import android.webkit.WebView
import androidx.activity.OnBackPressedCallback
import androidx.fragment.app.FragmentActivity
import anki.collection.OpChanges
import com.google.android.material.appbar.MaterialToolbar
import com.ichi2.anki.CollectionManager
import com.ichi2.anki.OnPageFinishedCallback
import com.ichi2.anki.R
Expand Down Expand Up @@ -61,6 +64,19 @@ class DeckOptions : PageFragment() {
}
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
view.findViewById<MaterialToolbar>(R.id.toolbar)?.apply {
inflateMenu(R.menu.deck_options)
setOnMenuItemClickListener { item ->
if (item.itemId == R.id.save_deck_options) {
saveAndExit()
}
true
}
}
}

override fun onCreateWebViewClient(savedInstanceState: Bundle?): PageWebViewClient {
val deckId = arguments?.getLong(ARG_DECK_ID)
?: throw Exception("missing deck ID")
Expand All @@ -75,6 +91,14 @@ class DeckOptions : PageFragment() {
}
}

private fun saveAndExit() {
// dispatch Ctrl+Enter
val downEvent = KeyEvent(0, 0, KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_ENTER, 0, KeyEvent.META_CTRL_ON)
val upEvent = KeyEvent(0, 0, KeyEvent.ACTION_UP, KeyEvent.KEYCODE_ENTER, 0, KeyEvent.META_CTRL_ON)
webView.dispatchKeyEvent(downEvent)
webView.dispatchKeyEvent(upEvent)
}

class DeckOptionsWebClient(val deckId: Long) : PageWebViewClient() {
override val promiseToWaitFor: String
get() = "\$deckOptions"
Expand Down
25 changes: 25 additions & 0 deletions AnkiDroid/src/main/res/menu/deck_options.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (c) 2024 David Allison <[email protected]>
~
~ This program is free software; you can redistribute it and/or modify it under
~ the terms of the GNU General Public License as published by the Free Software
~ Foundation; either version 3 of the License, or (at your option) any later
~ version.
~
~ This program is distributed in the hope that it will be useful, but WITHOUT ANY
~ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
~ PARTICULAR PURPOSE. See the GNU General Public License for more details.
~
~ You should have received a copy of the GNU General Public License along with
~ this program. If not, see <http://www.gnu.org/licenses/>.
-->
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">

<item
android:id="@+id/save_deck_options"
android:title="@string/save"
android:icon="@drawable/ic_save_white"
app:showAsAction="ifRoom"/>
</menu>

0 comments on commit 7537307

Please sign in to comment.