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

Moves media player related functionalities to Media Widget class #2817

Merged
merged 16 commits into from
Feb 8, 2019

Conversation

shobhitagarwal1612
Copy link
Contributor

@shobhitagarwal1612 shobhitagarwal1612 commented Jan 23, 2019

Closes #1640

What has been done to verify that this works as intended?

Tested manually on Redmi Note 4 and compared the All-Widgets and Birds forms before and after the changes.

Tests performed:

  • Swiping next while the audio is running stops the audio
  • Text color changes to tint color (blue) when playing audio
  • Minimizing the app while the audio is running stops the audio
  • Select Widget / Grid Widget / Grid Multi Widget and Audio Widgets are functioning properly

Why is this the best possible solution? Were any other approaches considered?

This PR is aimed at moving all of the media player related functionalities into an abstract class MediaWidget. This also performs minor refactors such as conversion of anonymous inner classes into lambda and minor code cleanup. This reduces the size of QuestionWidget by 100 lines.

How does this change affect users? Describe intentional changes to behavior and behavior that could have accidentally been affected by code changes. In other words, what are the regression risks?

This PR changes the way layout which contains the question text and other media (audio, video, image) is initialized and the methods controlling media are moved to another class. So, all of the changes must be closely reviewed in order to prevent any regressions.

Do we need any specific form for testing your changes? If so, please attach one.

I tested using the All-Widgets and Birds form

Does this change require updates to documentation? If so, please file an issue here and include the link below.

No

Before submitting this PR, please make sure you have:

  • run ./gradlew checkAll and confirmed all checks still pass OR confirm CircleCI build passes and run ./gradlew connectedDebugAndroidTest locally.
  • verified that any code or assets from external sources are properly credited in comments and/or in the about file.
  • verified that any new UI elements use theme colors. UI Components Style guidelines

The purpose of this class would be to pull out all functionality related
to media player
Audio, grid, grid-multi and select widgets require media player. So the
plan is to extend MediaWidget in these classes and in later commits,
start moving the media related methods and fields into MediaWidget
The super call is redundant as of now, but it is better than removing
the method from QuestionWidget class
Additionally, a check had to be added to ODKView to check if the widget
is of type MediaWidget before performing autoplay during loading of the
widget
1. Adds autoplay parameter to playAllPromptText()
2. Removes separate methods for playing audio/video and uses the above
parameter to distinguish between type of autoplay

Since the name of method playAllPromptText() is generic, so it should
behave in a generic manner as well. Until now, it was only concerned
with autoplaying audio, while giving an impression that it is common
method for all kinds of prompts (audio/video)
Remove unused getter. Since the member variable is only being used
within the same class, so the getters can be dropped

Annotate methods of GuidanceHint as @nonnull to remove nullable warning.
Since it is an enum & the default value of GuidanceHint should be 'No'
instread of 'null', so it is safe to return 'No' and mark method as @nonnull
@grzesiek2010
Copy link
Member

grzesiek2010 commented Feb 5, 2019

I reviewed and tested your changes since I want to continue work on #2521 and it would be better to merge this pr firs.

I have a problem with the autoplay option... did you test it? If not here is a form:
https://drive.google.com/file/d/14Pcu8hdE7gBqmFXpbPi6KW5779InmiWP/view?usp=sharing

it crashes:

    java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.media.MediaPlayer.isPlaying()' on a null object reference
        at org.odk.collect.android.views.AudioButton.onClick(AudioButton.java:77)
        at org.odk.collect.android.views.MediaLayout.playAudio(MediaLayout.java:114)
        at org.odk.collect.android.widgets.MediaWidget.playAllPromptText(MediaWidget.java:112)
        at org.odk.collect.android.widgets.SelectWidget.playAllPromptText(SelectWidget.java:98)
        at org.odk.collect.android.views.ODKView.lambda$new$0$ODKView(ODKView.java:226)
        at org.odk.collect.android.views.ODKView$$Lambda$0.run(Unknown Source)
        at android.os.Handler.handleCallback(Handler.java:739)
        at android.os.Handler.dispatchMessage(Handler.java:95)
        at android.os.Looper.loop(Looper.java:145)
        at android.app.ActivityThread.main(ActivityThread.java:5951)
        at java.lang.reflect.Method.invoke(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:372)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1400)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1195)

but it's not your fault since it crashes on master branch as well and on older versions too...
We have no crash reports from Firebase and no reports from real users what indicates it's completely useless. Can we just get rid of that option @yanokwa @shobhitagarwal1612
it doesn't make sense to me...

@shobhitagarwal1612
Copy link
Contributor Author

@grzesiek2010 No, I didn't. I have listed down all of the tests performed manually in the PR description.

});
// plays the question text
super.playAllPromptText();
public void playAllPromptText(String playOption) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Hi Shobhit. Did you consider using an enum for playOption?

public MediaWidget(Context context, FormEntryPrompt prompt) {
super(context, prompt);

String imageURI = this instanceof SelectImageMapWidget ? null : prompt.getImageText();
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure, but I think we’re using the convention that initialisms (like URI) are capitalized like uri or imageUri. I have an audio clip of Josh Bloch himself recommending this.

try {
playColor = Color.parseColor(playColorString);
} catch (IllegalArgumentException e) {
Timber.e(e, "Argument %s is incorrect", playColorString);
Copy link
Contributor

@dcbriccetti dcbriccetti Feb 6, 2019

Choose a reason for hiding this comment

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

Argument %s to Color.parseColor is incorrect might be more helpful.

Copy link
Contributor

Choose a reason for hiding this comment

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

I see you didn’t create, but just moved this code, so disregard the above if you like.


expanded = new AtomicBoolean(false);

if (getState() != null) {
if (getState().containsKey(GUIDANCE_EXPANDED_STATE + getFormEntryPrompt().getIndex())) {
Boolean result = getState().getBoolean(GUIDANCE_EXPANDED_STATE + getFormEntryPrompt().getIndex());
boolean result = getState().getBoolean(GUIDANCE_EXPANDED_STATE + getFormEntryPrompt().getIndex());
expanded = new AtomicBoolean(result);
Copy link
Contributor

Choose a reason for hiding this comment

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

I’m suspicious of an AtomicBoolean that’s recreated rather than set. I didn’t study this closely though.

@yanokwa
Copy link
Member

yanokwa commented Feb 6, 2019

Autoplay seems to be in use: see https://forum.opendatakit.org/search?q=autoplay%20order%3Alatest). I also think it's useful for ACASI surveys. @grzesiek2010 Can you file an issue so we can discuss what the current behavior is and how we can fix and document it?

@mmarciniak90
Copy link
Contributor

Tested with success

Verified on Android: 4.2, 4.4, 5.1, 6.0, 7.0, 8.1
I did not notice regression.

Verified cases:

  • all audio widgets in All widgets form
  • all video widgets in All widgets form
  • all image widgets in All widgets form
  • Birds form
  • widgets on one page
  • permissions

@opendatakit-bot unlabel "needs testing"
@opendatakit-bot label "behavior verified"

@grzesiek2010 grzesiek2010 merged commit 8db197e into getodk:master Feb 8, 2019
@grzesiek2010 grzesiek2010 added this to the v1.20 milestone Feb 8, 2019
@shobhitagarwal1612 shobhitagarwal1612 deleted the issue-1640 branch February 8, 2019 11:41
@grzesiek2010
Copy link
Member

grzesiek2010 commented Feb 11, 2019

Ohhhh I feel ashamed that I didn't catch it before but of course, all widgets can have media attached to a question text... @shobhitagarwal1612 your changes brake that option what shows this form:
form.zip

are you able to come up with any reasonable solution because I think reverting all changes might be the best solution here?

Yes since all widgets can have media files the whole issue was wrong...

@yanokwa
Copy link
Member

yanokwa commented Feb 12, 2019

I discussed this a bit with @grzesiek2010 and wanted to document some of the gaps so we can get better.

  1. @dcbriccetti's issue was a little misleading. Perhaps there could have been more details in said issue.
  2. @shobhitagarwal1612 was probably not aware that question text had media. Perhaps a closer look at ODKView would have helped.
  3. Grzegorz might have caught it during review, but Dave approved the changes before and so Grzegorz didn't go back to review.
  4. @mmarciniak90 might have caught it during testing, but didn't think to test those.
  5. @yanokwa commented on the PR, but didn't carefully read the tests performed. There was a big hint there in the Shobhit's list.

I think one thing that we can all do going forward is to let PRs sit a little bit before going into testing. My hope here is that more time will give more people a chance to review. Another thing we can do is to aim for having two people give the go ahead on a merge.

Do these two adjustments sound reasonable for preventing this kind of problem?

@seadowg seadowg mentioned this pull request Jul 23, 2019
17 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Move MediaPlayer field from QuestionWidget
6 participants