-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
[GSoC'24] New Multimedia UI #16673
Conversation
Message to maintainers, this PR contains strings changes.
Read more about updating strings on the wiki, |
c8ca7ed
to
b24d818
Compare
cceb1b1
to
4509c70
Compare
There was a problem hiding this 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)
AnkiDroid/src/main/java/com/ichi2/anki/multimedia/MultimediaViewModel.kt
Show resolved
Hide resolved
AnkiDroid/src/main/java/com/ichi2/anki/multimedia/MultimediaBottomSheet.kt
Outdated
Show resolved
Hide resolved
@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/multimedia/MultimediaActivity.kt
Outdated
Show resolved
Hide resolved
AnkiDroid/src/main/java/com/ichi2/anki/multimedia/MultimediaActivity.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> |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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/
* @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 { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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?
AnkiDroid/src/main/java/com/ichi2/anki/multimedia/MultimediaBottomSheet.kt
Outdated
Show resolved
Hide resolved
val imageIntent = MultimediaImageFragment.getIntent( | ||
this@NoteEditor, | ||
MultimediaEditFieldActivityExtra(index, field, note), | ||
MultimediaEditFieldActivityExtra(index, ImageField(), note), |
There was a problem hiding this comment.
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?
There was a problem hiding this 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!
multimediaViewModel.multimediaAction.take(1).onEach { action -> | ||
when (action) { | ||
MultimediaBottomSheet.MultimediaAction.SELECT_IMAGE_FILE -> { | ||
note.setField(index, ImageField()) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
|
||
val note: MultimediaEditableNote = getCurrentMultimediaEditableNote() ?: return | ||
|
||
multimediaViewModel.multimediaAction.take(1).onEach { action -> |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
ImageOptions.GALLERY -> { | ||
Timber.d("Registering image result launcher") | ||
pickImageLauncher = | ||
registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result -> |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
AnkiDroid/src/main/java/com/ichi2/anki/multimedia/MultimediaImageFragment.kt
Outdated
Show resolved
Hide resolved
AnkiDroid/src/main/java/com/ichi2/anki/multimedia/MultimediaImageFragment.kt
Outdated
Show resolved
Hide resolved
AnkiDroid/src/main/java/com/ichi2/anki/multimedia/MultimediaActivity.kt
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Initial impression: LGTM
AnkiDroid/src/main/java/com/ichi2/anki/multimedia/MultimediaImageFragment.kt
Outdated
Show resolved
Hide resolved
AnkiDroid/src/main/java/com/ichi2/anki/multimedia/MultimediaActivity.kt
Outdated
Show resolved
Hide resolved
AnkiDroid/src/main/java/com/ichi2/anki/multimedia/MultimediaBottomSheet.kt
Outdated
Show resolved
Hide resolved
AnkiDroid/src/main/java/com/ichi2/anki/multimedia/MultimediaImageFragment.kt
Show resolved
Hide resolved
ImageOptions.GALLERY -> { | ||
Timber.d("Registering image result launcher") | ||
pickImageLauncher = | ||
registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result -> |
There was a problem hiding this comment.
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
AnkiDroid/src/main/java/com/ichi2/anki/multimedia/MultimediaImageFragment.kt
Outdated
Show resolved
Hide resolved
AnkiDroid/src/main/java/com/ichi2/anki/multimedia/MultimediaImageFragment.kt
Outdated
Show resolved
Hide resolved
d154ba9
to
3bff668
Compare
There was a problem hiding this 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
* Handles an intent containing an image from the user's gallery or the internet, | ||
* specifically for creating a new card. |
There was a problem hiding this comment.
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
AnkiDroid/src/main/java/com/ichi2/anki/multimedia/MultimediaFragment.kt
Outdated
Show resolved
Hide resolved
AnkiDroid/src/main/java/com/ichi2/anki/multimedia/MultimediaImageFragment.kt
Outdated
Show resolved
Hide resolved
AnkiDroid/src/main/java/com/ichi2/anki/multimedia/MultimediaImageFragment.kt
Show resolved
Hide resolved
AnkiDroid/src/main/java/com/ichi2/anki/multimedia/MultimediaImageFragment.kt
Outdated
Show resolved
Hide resolved
33bbf51
to
f04fb6d
Compare
AnkiDroid/src/main/java/com/ichi2/anki/multimedia/MultimediaImageFragment.kt
Show resolved
Hide resolved
add8542
to
3913667
Compare
* feat: added multimedia activity and base fragment * enhancement: setup the gallery and camera options
3913667
to
4a6b94a
Compare
Everything(that's implemented) seems to work and I don't see the issue I mentioned on another emulator so we can merge this. |
Maintainers: Please Sync Translations to produce a commit with only the automated changes from this PR. Read more about updating strings on the wiki, |
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
Checklist
Please, go through these checks before submitting the PR.