Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GSoC'24] New Multimedia UI #16673

Merged
merged 2 commits into from
Jul 20, 2024
Merged

[GSoC'24] New Multimedia UI #16673

merged 2 commits into from
Jul 20, 2024

Conversation

criticalAY
Copy link
Contributor

@criticalAY criticalAY commented Jun 29, 2024

Purpose / Description

This PR sets the new multimedia UI as developer option and handles the image options - Gallery and Camera

Fixes

How Has This Been Tested?

Tested on Oneplus Nord CE

image
image
image

Checklist

Please, go through these checks before submitting the PR.

  • You have a descriptive commit message with a short title (first line, max 50 chars).
  • You have commented your code, particularly in hard-to-understand areas
  • You have performed a self-review of your own code
  • UI changes: include screenshots of all affected screens (in particular showing any new or changed strings)
  • UI Changes: You have tested your change using the Google Accessibility Scanner

Copy link
Contributor

Message to maintainers, this PR contains strings changes.

  1. Before merging this PR, it is best to run the "Sync Translations" GitHub action, then make and merge a PR from the i18n_sync branch to get translations cleaned out.
  2. Then merge this PR, and immediately do another translation PR so the huge change made by this PR's key changes are all by themselves.

Read more about updating strings on the wiki,

@criticalAY criticalAY force-pushed the multimedia-ui branch 2 times, most recently from c8ca7ed to b24d818 Compare June 29, 2024 07:43
@criticalAY criticalAY added Needs Review GSoC Pull requests authored by a Google Summer of Code participant [Candidate/Selected], for GSoC mentors labels Jun 29, 2024
Copy link
Member

@lukstbit lukstbit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had a quick look and left some notes.
Also:

  • versus the previous implementation(tested on the emulator), I choose gallery -> got to the gallery screen -> get stuck on it even if I click up(toolbar) or BACK. Seems to exit if I click fast enough. Does it work for you?
  • in the above scenario, after I come back, the UI is not responsive: clicking up in the toolbar or done doesn't work and doesn't close the screen(BACK seems to work however). I also don't see any menu items.
  • choosing camera doesn't work as well. I create the picture but when I want to go back I again get sent to the camera app and the app crashes as there's a leak for crop dialog:
android.view.WindowLeaked: Activity com.ichi2.anki.multimedia.MultimediaActivity has leaked window DecorView@c071bb8[MultimediaActivity] that was originally added here
        at android.view.ViewRootImpl.<init>(ViewRootImpl.java:1009)
        at android.view.ViewRootImpl.<init>(ViewRootImpl.java:997)
        at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:397)
        at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:150)
        at android.app.Dialog.show(Dialog.java:352)
        at androidx.appcompat.app.AlertDialog$Builder.show(AlertDialog.java:1008)
        at com.ichi2.anki.multimedia.MultimediaImageFragment.showCropDialog(MultimediaImageFragment.kt:451)
        at com.ichi2.anki.multimedia.MultimediaImageFragment.handleTakePictureResult(MultimediaImageFragment.kt:209)
        at com.ichi2.anki.multimedia.MultimediaImageFragment.registerLauncher$lambda$3(MultimediaImageFragment.kt:153)

@criticalAY
Copy link
Contributor Author

Had a quick look and left some notes.

@lukstbit I tested it on my own device and emulator both but I can't reproduce the started issue of the menu not respoding

AnkiDroid/src/main/java/com/ichi2/anki/NoteEditor.kt Outdated Show resolved Hide resolved
AnkiDroid/src/main/java/com/ichi2/anki/NoteEditor.kt Outdated Show resolved Hide resolved
AnkiDroid/src/main/java/com/ichi2/anki/NoteEditor.kt Outdated Show resolved Hide resolved
AnkiDroid/src/main/java/com/ichi2/anki/NoteEditor.kt Outdated Show resolved Hide resolved
AnkiDroid/src/main/java/com/ichi2/anki/NoteEditor.kt Outdated Show resolved Hide resolved
AnkiDroid/src/main/java/com/ichi2/anki/NoteEditor.kt Outdated Show resolved Hide resolved
@@ -73,4 +73,7 @@
<string name="activity_result_unexpected">App returned an unexpected value. You may need to use a different app</string>
<string name="audio_recording_field_list" comment="Displays a list of the field data in the note editor while audio recording is taking place">Field Contents</string>

<string name="no_image_preview">No image selected. Click restart to add an image</string>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change this to either accept 'restart' as a parameter, or reword

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have reworded the sentence, /open to discussion/

@lukstbit lukstbit added Needs Author Reply Waiting for a reply from the original author and removed Needs Review labels Jul 3, 2024
* @param field The `IField` object representing the media file and its details.
* @throws IllegalStateException if the currently edited multimedia note cannot be retrieved.
*/
private fun addMediaFileToField(index: Int, field: IField) = lifecycleScope.launch {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you want addMediaFileToField to return a job?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doing it as we are using withCol instead of getColUnsafe

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But why does it need to return the job?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will change it

return view
}

private fun setMultimediaAction(action: MultimediaAction) = lifecycleScope.launch {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you want setMultimediaAction to return a job?

val imageIntent = MultimediaImageFragment.getIntent(
this@NoteEditor,
MultimediaEditFieldActivityExtra(index, field, note),
MultimediaEditFieldActivityExtra(index, ImageField(), note),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would lead to a new instance of ImageField. Is that what you expect?

Copy link
Member

@david-allison david-allison left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initial impression: looks good, thanks!

AnkiDroid/src/main/java/com/ichi2/anki/NoteEditor.kt Outdated Show resolved Hide resolved
AnkiDroid/src/main/java/com/ichi2/anki/NoteEditor.kt Outdated Show resolved Hide resolved
multimediaViewModel.multimediaAction.take(1).onEach { action ->
when (action) {
MultimediaBottomSheet.MultimediaAction.SELECT_IMAGE_FILE -> {
note.setField(index, ImageField())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you planning on moving away from ImageField etc...? I don't think anyone in the project likes this implementation, and we can do better here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not directly connected to to the multimedia activity hence I will do it at last, it concerns with the data that is being sent to the noteeditor i.e. tell it what to do

AnkiDroid/src/main/java/com/ichi2/anki/NoteEditor.kt Outdated Show resolved Hide resolved

val note: MultimediaEditableNote = getCurrentMultimediaEditableNote() ?: return

multimediaViewModel.multimediaAction.take(1).onEach { action ->
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

multimediaViewModel.multimediaAction.take(1).onEach doesn't read well, what are you trying to do here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will make the selected option to be executed only once, when the user clicks it otherwise if we observe it it will recursively launch the media option after successfully adding media to the field.

AnkiDroid/src/main/java/com/ichi2/anki/NoteEditor.kt Outdated Show resolved Hide resolved
ImageOptions.GALLERY -> {
Timber.d("Registering image result launcher")
pickImageLauncher =
registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

registerForActivityResult

This must be called unconditionally, as part of initialization path, typically as a field initializer of an Activity or Fragment.

https://developer.android.com/reference/androidx/activity/result/ActivityResultCaller#public-methods_1

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Meaning it should not be placed in when?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally in onCreate, make it obvious that registration for all activities is guaranteed to be called on all paths

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I misspoke - just register them as variables

Copy link
Member

@david-allison david-allison left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initial impression: LGTM

@david-allison david-allison added Needs Review and removed Needs Author Reply Waiting for a reply from the original author labels Jul 9, 2024
@criticalAY criticalAY requested review from lukstbit, ShridharGoel and david-allison and removed request for lukstbit July 9, 2024 20:11
AnkiDroid/src/main/java/com/ichi2/anki/NoteEditor.kt Outdated Show resolved Hide resolved
AnkiDroid/src/main/java/com/ichi2/anki/NoteEditor.kt Outdated Show resolved Hide resolved
AnkiDroid/src/main/java/com/ichi2/anki/NoteEditor.kt Outdated Show resolved Hide resolved
ImageOptions.GALLERY -> {
Timber.d("Registering image result launcher")
pickImageLauncher =
registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I misspoke - just register them as variables

Copy link
Member

@david-allison david-allison left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm happy, I don't feel any of my comments are blocking, especially as this is behind a dev setting

This will want a rebase onto main once #16754 is in

Comment on lines 509 to 510
* Handles an intent containing an image from the user's gallery or the internet,
* specifically for creating a new card.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this wants to be renamed, I feel the description should list the outcome (opening a screen) more explicitly

@criticalAY criticalAY force-pushed the multimedia-ui branch 2 times, most recently from 33bbf51 to f04fb6d Compare July 18, 2024 16:33
@criticalAY criticalAY force-pushed the multimedia-ui branch 2 times, most recently from add8542 to 3913667 Compare July 19, 2024 17:19
@criticalAY criticalAY added Needs Second Approval Has one approval, one more approval to merge and removed Needs Review Has Conflicts labels Jul 19, 2024
* feat: added multimedia activity and base fragment
* enhancement: setup the gallery and camera options
@david-allison david-allison added Pending Merge Things with approval that are waiting future merge (e.g. targets a future release, CI wait, etc) and removed Needs Second Approval Has one approval, one more approval to merge labels Jul 19, 2024
@lukstbit
Copy link
Member

Everything(that's implemented) seems to work and I don't see the issue I mentioned on another emulator so we can merge this.

@lukstbit lukstbit added this pull request to the merge queue Jul 20, 2024
Merged via the queue into ankidroid:main with commit bb85307 Jul 20, 2024
8 checks passed
Copy link
Contributor

Maintainers: Please Sync Translations to produce a commit with only the automated changes from this PR.

Read more about updating strings on the wiki,

@github-actions github-actions bot removed the Pending Merge Things with approval that are waiting future merge (e.g. targets a future release, CI wait, etc) label Jul 20, 2024
@github-actions github-actions bot added this to the 2.19 release milestone Jul 20, 2024
@criticalAY criticalAY deleted the multimedia-ui branch July 20, 2024 08:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
GSoC Pull requests authored by a Google Summer of Code participant [Candidate/Selected], for GSoC mentors Strings
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants