Skip to content

Commit 8b5e1d5

Browse files
committed
Move "Camera" and "Gallery" actions out of the "Select image" submenu
Probably, most users come to the "Add" screen of Image Occlusion note type screen just in order to use the "Camera" or the "Gallery" feature; moving these actions from the submenu to the top screen of the note editor is practical. Not only from the pragmatic point of view, but also from a theoretical standpoint, "Gallery" is equivalent to "Select image" in the desktop version, so "Camera" should be a separate option on the same level with "Gallery" and "Paste image from clipboard". In fact, in AnkiMobile, the three options are placed in the same hierarchy. (Besides, there is more than enough space on the current "Add" screen for Image Occlusion note type (the screen doesn't show deck selector, tag field, toolbar, and keyboard); adding more parts will rather improve the visual balance.)
1 parent 4c812de commit 8b5e1d5

File tree

5 files changed

+68
-175
lines changed

5 files changed

+68
-175
lines changed

AnkiDroid/src/main/java/com/ichi2/anki/NoteEditorFragment.kt

Lines changed: 19 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ import com.ichi2.anki.OnContextAndLongClickListener.Companion.setOnContextAndLon
9191
import com.ichi2.anki.android.input.ShortcutGroup
9292
import com.ichi2.anki.android.input.ShortcutGroupProvider
9393
import com.ichi2.anki.android.input.shortcut
94-
import com.ichi2.anki.bottomsheet.ImageOcclusionBottomSheetFragment
9594
import com.ichi2.anki.common.annotations.NeedsTest
9695
import com.ichi2.anki.common.utils.annotation.KotlinCleanup
9796
import com.ichi2.anki.dialogs.ConfirmationDialog
@@ -241,8 +240,10 @@ class NoteEditorFragment :
241240
internal var noteTypeSpinner: Spinner? = null
242241
private var deckSpinnerSelection: DeckSpinnerSelection? = null
243242
private var imageOcclusionButtonsContainer: LinearLayout? = null
244-
private var selectImageForOcclusionButton: Button? = null
245243
private var editOcclusionsButton: Button? = null
244+
private var imageSelectionForOcclusionContainer: LinearLayout? = null
245+
private var cameraForOcclusionButton: Button? = null
246+
private var galleryForOcclusionButton: Button? = null
246247
private var pasteOcclusionImageButton: Button? = null
247248

248249
// non-null after onCollectionLoaded
@@ -702,7 +703,9 @@ class NoteEditorFragment :
702703
}
703704
imageOcclusionButtonsContainer = requireView().findViewById(R.id.ImageOcclusionButtonsLayout)
704705
editOcclusionsButton = requireView().findViewById(R.id.EditOcclusionsButton)
705-
selectImageForOcclusionButton = requireView().findViewById(R.id.SelectImageForOcclusionButton)
706+
imageSelectionForOcclusionContainer = requireView().findViewById(R.id.ImageSelectionForOcclusionContainer)
707+
cameraForOcclusionButton = requireView().findViewById<Button>(R.id.CameraForOcclusionButton)
708+
galleryForOcclusionButton = requireView().findViewById<Button>(R.id.GalleryForOcclusionButton)
706709
pasteOcclusionImageButton = requireView().findViewById(R.id.PasteImageForOcclusionButton)
707710

708711
try {
@@ -761,33 +764,21 @@ class NoteEditorFragment :
761764

762765
if (addNote) {
763766
editOcclusionsButton?.visibility = View.GONE
764-
selectImageForOcclusionButton?.setOnClickListener {
765-
Timber.i("selecting image for occlusion")
766-
val imageOcclusionBottomSheet = ImageOcclusionBottomSheetFragment()
767-
imageOcclusionBottomSheet.listener =
768-
object : ImageOcclusionBottomSheetFragment.ImagePickerListener {
769-
override fun onCameraClicked() {
770-
Timber.i("onCameraClicked")
771-
dispatchCameraEvent()
772-
}
773767

774-
override fun onGalleryClicked() {
775-
Timber.i("onGalleryClicked")
776-
try {
777-
ioEditorLauncher.launch("image/*")
778-
} catch (_: ActivityNotFoundException) {
779-
Timber.w("No app found to handle onGalleryClicked request")
780-
activity?.showSnackbar(R.string.activity_start_failed)
781-
}
782-
}
783-
}
784-
imageOcclusionBottomSheet.show(
785-
parentFragmentManager,
786-
"ImageOcclusionBottomSheetFragment",
787-
)
768+
cameraForOcclusionButton?.setOnClickListener {
769+
Timber.i("Camera button clicked")
770+
dispatchCameraEvent()
788771
}
789772

790-
pasteOcclusionImageButton?.text = TR.notetypesIoPasteImageFromClipboard()
773+
galleryForOcclusionButton?.setOnClickListener {
774+
Timber.i("Gallery button clicked")
775+
try {
776+
ioEditorLauncher.launch("image/*")
777+
} catch (_: ActivityNotFoundException) {
778+
Timber.w("No app found to handle onGalleryClicked request")
779+
activity?.showSnackbar(R.string.activity_start_failed)
780+
}
781+
}
791782
pasteOcclusionImageButton?.setOnClickListener {
792783
// TODO: Support all extensions
793784
// See https://github.com/ankitects/anki/blob/6f3550464d37aee1b8b784e431cbfce8382d3ce7/rslib/src/image_occlusion/imagedata.rs#L154
@@ -806,8 +797,7 @@ class NoteEditorFragment :
806797
}
807798
}
808799
} else {
809-
selectImageForOcclusionButton?.visibility = View.GONE
810-
pasteOcclusionImageButton?.visibility = View.GONE
800+
imageSelectionForOcclusionContainer?.visibility = View.GONE
811801
editOcclusionsButton?.visibility = View.VISIBLE
812802
editOcclusionsButton?.text = resources.getString(R.string.edit_occlusions)
813803
editOcclusionsButton?.setOnClickListener {

AnkiDroid/src/main/java/com/ichi2/anki/bottomsheet/ImageOcclusionBottomSheetFragment.kt

Lines changed: 0 additions & 61 deletions
This file was deleted.

AnkiDroid/src/main/res/layout/image_occlusion_options_layout.xml

Lines changed: 0 additions & 73 deletions
This file was deleted.

AnkiDroid/src/main/res/layout/note_editor_fragment.xml

Lines changed: 47 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -92,22 +92,57 @@
9292
android:layout_height="wrap_content"
9393
android:text="@string/edit_occlusions" />
9494

95-
<com.google.android.material.button.MaterialButton
96-
android:id="@+id/SelectImageForOcclusionButton"
95+
<LinearLayout
96+
android:id="@+id/ImageSelectionForOcclusionContainer"
9797
android:layout_width="match_parent"
9898
android:layout_height="wrap_content"
99-
app:icon="@drawable/ic_add"
100-
app:iconGravity="textStart"
101-
android:text="@string/choose_an_image" />
99+
android:orientation="vertical">
100+
<LinearLayout
101+
android:layout_width="match_parent"
102+
android:layout_height="wrap_content"
103+
android:orientation="horizontal"
104+
android:paddingTop="14dp">
102105

103-
<com.google.android.material.button.MaterialButton
104-
android:id="@+id/PasteImageForOcclusionButton"
105-
android:layout_width="match_parent"
106-
android:layout_height="wrap_content"
107-
tools:text="Paste Image from Clipboard"
108-
app:icon="@drawable/ic_paste"
109-
app:iconGravity="textStart"/>
106+
<com.ichi2.ui.FixedTextView
107+
android:id="@+id/ImageSelectionForOcclusionLabel"
108+
android:layout_width="wrap_content"
109+
android:layout_height="wrap_content"
110+
android:layout_gravity="center"
111+
android:layout_marginLeft="8dip"
112+
android:layout_marginRight="8dip"
113+
android:clickable="false"
114+
android:gravity="start|center_vertical"
115+
android:textStyle="bold"
116+
android:text="@string/imageSelectionForOcclusionLabel" />
117+
</LinearLayout>
118+
119+
<com.google.android.material.button.MaterialButton
120+
android:id="@+id/GalleryForOcclusionButton"
121+
android:layout_width="match_parent"
122+
android:layout_height="wrap_content"
123+
android:layout_marginHorizontal="15dp"
124+
android:text="@string/pick_image_gallery"
125+
app:icon="@drawable/ic_gallery"
126+
app:iconGravity="textStart" />
110127

128+
<com.google.android.material.button.MaterialButton
129+
android:id="@+id/CameraForOcclusionButton"
130+
android:layout_width="match_parent"
131+
android:layout_height="wrap_content"
132+
android:layout_marginHorizontal="15dp"
133+
app:icon="@drawable/ic_camera"
134+
app:iconGravity="textStart"
135+
android:text="@string/pick_image_camera" />
136+
137+
<com.google.android.material.button.MaterialButton
138+
android:id="@+id/PasteImageForOcclusionButton"
139+
android:layout_width="match_parent"
140+
android:layout_height="wrap_content"
141+
android:layout_marginHorizontal="15dp"
142+
app:icon="@drawable/ic_paste"
143+
app:iconGravity="textStart"
144+
android:text="@string/clipboard_for_occlusions" />
145+
</LinearLayout>
111146
</LinearLayout>
112147

113148
<androidx.appcompat.widget.AppCompatButton

AnkiDroid/src/main/res/values/02-strings.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,12 @@
2525
<string name="note_message">Note saved</string>
2626
<string name="CardEditorCardDeck">Card deck:</string>
2727
<string name="CardEditorNoteDeck">Deck:</string>
28+
<string name="imageSelectionForOcclusionLabel">Image:</string>
2829
<string name="CardEditorModel">Type:</string>
2930
<string name="CardEditorTags">Tags: %1$s</string>
3031
<string name="CardEditorCards">Cards: %1$s</string>
3132
<string name="edit_occlusions">Edit Occlusions</string>
33+
<string name="clipboard_for_occlusions" comment="Button's label for pasting image from clipboard in Image Occlusion note type's Add screen" maxLength="28">Paste from clipboard</string>
3234

3335
<string name="tag_name">Tag name</string>
3436
<string name="add_new_filter_tags">Add/filter tags</string>

0 commit comments

Comments
 (0)