Skip to content

Commit d8089d0

Browse files
snowtimeglasslukstbit
authored andcommitted
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 a260c4f commit d8089d0

File tree

5 files changed

+70
-175
lines changed

5 files changed

+70
-175
lines changed

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

Lines changed: 23 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ import com.ichi2.anki.OnContextAndLongClickListener.Companion.setOnContextAndLon
9090
import com.ichi2.anki.android.input.ShortcutGroup
9191
import com.ichi2.anki.android.input.ShortcutGroupProvider
9292
import com.ichi2.anki.android.input.shortcut
93-
import com.ichi2.anki.bottomsheet.ImageOcclusionBottomSheetFragment
9493
import com.ichi2.anki.common.annotations.NeedsTest
9594
import com.ichi2.anki.common.utils.annotation.KotlinCleanup
9695
import com.ichi2.anki.dialogs.ConfirmationDialog
@@ -239,8 +238,11 @@ class NoteEditorFragment :
239238
@VisibleForTesting
240239
internal var noteTypeSpinner: Spinner? = null
241240
private var imageOcclusionButtonsContainer: LinearLayout? = null
242-
private var selectImageForOcclusionButton: Button? = null
243241
private var editOcclusionsButton: Button? = null
242+
private var imageSelectionForOcclusionContainer: LinearLayout? = null
243+
private var imageSelectionForOcclusionLabel: TextView? = null
244+
private var cameraForOcclusionButton: Button? = null
245+
private var galleryForOcclusionButton: Button? = null
244246
private var pasteOcclusionImageButton: Button? = null
245247

246248
// non-null after onCollectionLoaded
@@ -696,7 +698,10 @@ class NoteEditorFragment :
696698
}
697699
imageOcclusionButtonsContainer = requireView().findViewById(R.id.ImageOcclusionButtonsLayout)
698700
editOcclusionsButton = requireView().findViewById(R.id.EditOcclusionsButton)
699-
selectImageForOcclusionButton = requireView().findViewById(R.id.SelectImageForOcclusionButton)
701+
imageSelectionForOcclusionContainer = requireView().findViewById(R.id.ImageSelectionForOcclusionContainer)
702+
imageSelectionForOcclusionLabel = requireView().findViewById(R.id.ImageSelectionForOcclusionLabel)
703+
cameraForOcclusionButton = requireView().findViewById<Button>(R.id.CameraForOcclusionButton)
704+
galleryForOcclusionButton = requireView().findViewById<Button>(R.id.GalleryForOcclusionButton)
700705
pasteOcclusionImageButton = requireView().findViewById(R.id.PasteImageForOcclusionButton)
701706

702707
try {
@@ -755,33 +760,23 @@ class NoteEditorFragment :
755760

756761
if (addNote) {
757762
editOcclusionsButton?.visibility = View.GONE
758-
selectImageForOcclusionButton?.setOnClickListener {
759-
Timber.i("selecting image for occlusion")
760-
val imageOcclusionBottomSheet = ImageOcclusionBottomSheetFragment()
761-
imageOcclusionBottomSheet.listener =
762-
object : ImageOcclusionBottomSheetFragment.ImagePickerListener {
763-
override fun onCameraClicked() {
764-
Timber.i("onCameraClicked")
765-
dispatchCameraEvent()
766-
}
767763

768-
override fun onGalleryClicked() {
769-
Timber.i("onGalleryClicked")
770-
try {
771-
ioEditorLauncher.launch("image/*")
772-
} catch (_: ActivityNotFoundException) {
773-
Timber.w("No app found to handle onGalleryClicked request")
774-
activity?.showSnackbar(R.string.activity_start_failed)
775-
}
776-
}
777-
}
778-
imageOcclusionBottomSheet.show(
779-
parentFragmentManager,
780-
"ImageOcclusionBottomSheetFragment",
781-
)
764+
imageSelectionForOcclusionLabel?.text = TR.notetypesImage() + ":"
765+
766+
cameraForOcclusionButton?.setOnClickListener {
767+
Timber.i("Camera button clicked")
768+
dispatchCameraEvent()
782769
}
783770

784-
pasteOcclusionImageButton?.text = TR.notetypesIoPasteImageFromClipboard()
771+
galleryForOcclusionButton?.setOnClickListener {
772+
Timber.i("Gallery button clicked")
773+
try {
774+
ioEditorLauncher.launch("image/*")
775+
} catch (_: ActivityNotFoundException) {
776+
Timber.w("No app found to handle onGalleryClicked request")
777+
activity?.showSnackbar(R.string.activity_start_failed)
778+
}
779+
}
785780
pasteOcclusionImageButton?.setOnClickListener {
786781
// TODO: Support all extensions
787782
// See https://github.com/ankitects/anki/blob/6f3550464d37aee1b8b784e431cbfce8382d3ce7/rslib/src/image_occlusion/imagedata.rs#L154
@@ -800,8 +795,7 @@ class NoteEditorFragment :
800795
}
801796
}
802797
} else {
803-
selectImageForOcclusionButton?.visibility = View.GONE
804-
pasteOcclusionImageButton?.visibility = View.GONE
798+
imageSelectionForOcclusionContainer?.visibility = View.GONE
805799
editOcclusionsButton?.visibility = View.VISIBLE
806800
editOcclusionsButton?.text = resources.getString(R.string.edit_occlusions)
807801
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: 43 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -100,22 +100,53 @@
100100
android:layout_height="wrap_content"
101101
android:text="@string/edit_occlusions" />
102102

103-
<com.google.android.material.button.MaterialButton
104-
android:id="@+id/SelectImageForOcclusionButton"
103+
<LinearLayout
104+
android:id="@+id/ImageSelectionForOcclusionContainer"
105105
android:layout_width="match_parent"
106106
android:layout_height="wrap_content"
107-
app:icon="@drawable/ic_add"
108-
app:iconGravity="textStart"
109-
android:text="@string/choose_an_image" />
107+
android:orientation="vertical"
108+
android:paddingTop="14dp">
110109

111-
<com.google.android.material.button.MaterialButton
112-
android:id="@+id/PasteImageForOcclusionButton"
113-
android:layout_width="match_parent"
114-
android:layout_height="wrap_content"
115-
tools:text="Paste Image from Clipboard"
116-
app:icon="@drawable/ic_paste"
117-
app:iconGravity="textStart"/>
110+
<com.ichi2.ui.FixedTextView
111+
android:id="@+id/ImageSelectionForOcclusionLabel"
112+
android:layout_width="wrap_content"
113+
android:layout_height="wrap_content"
114+
android:layout_gravity="start"
115+
android:layout_marginLeft="8dip"
116+
android:layout_marginRight="8dip"
117+
android:layout_marginBottom="4dip"
118+
android:clickable="false"
119+
android:gravity="start|center_vertical"
120+
android:textStyle="bold"
121+
tools:text="Image:"/>
122+
123+
<com.google.android.material.button.MaterialButton
124+
android:id="@+id/GalleryForOcclusionButton"
125+
android:layout_width="match_parent"
126+
android:layout_height="wrap_content"
127+
android:layout_marginHorizontal="15dp"
128+
android:text="@string/multimedia_editor_image_field_editing_galery"
129+
app:icon="@drawable/ic_gallery"
130+
app:iconGravity="textStart" />
118131

132+
<com.google.android.material.button.MaterialButton
133+
android:id="@+id/CameraForOcclusionButton"
134+
android:layout_width="match_parent"
135+
android:layout_height="wrap_content"
136+
android:layout_marginHorizontal="15dp"
137+
app:icon="@drawable/ic_camera"
138+
app:iconGravity="textStart"
139+
android:text="@string/multimedia_editor_image_field_editing_photo" />
140+
141+
<com.google.android.material.button.MaterialButton
142+
android:id="@+id/PasteImageForOcclusionButton"
143+
android:layout_width="match_parent"
144+
android:layout_height="wrap_content"
145+
android:layout_marginHorizontal="15dp"
146+
app:icon="@drawable/ic_paste"
147+
app:iconGravity="textStart"
148+
android:text="@string/paste_from_clipboard" />
149+
</LinearLayout>
119150
</LinearLayout>
120151

121152
<androidx.appcompat.widget.AppCompatButton

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,17 @@
2222
<!-- Navigation drawer strings -->
2323
<string name="drawer_open">Open drawer</string>
2424
<string name="drawer_close">Close drawer</string>
25+
2526
<string name="note_message">Note saved</string>
27+
28+
<!-- Note editor screen -->
2629
<string name="CardEditorCardDeck">Card deck:</string>
2730
<string name="CardEditorNoteDeck">Deck:</string>
2831
<string name="CardEditorModel">Type:</string>
2932
<string name="CardEditorTags">Tags: %1$s</string>
3033
<string name="CardEditorCards">Cards: %1$s</string>
3134
<string name="edit_occlusions">Edit Occlusions</string>
35+
<string name="paste_from_clipboard" maxLength="28">Paste from clipboard</string>
3236

3337
<string name="tag_name">Tag name</string>
3438
<string name="add_new_filter_tags">Add/filter tags</string>

0 commit comments

Comments
 (0)