Skip to content

Conversation

@ShivamPokhriyal
Copy link
Contributor

@ShivamPokhriyal ShivamPokhriyal commented Sep 3, 2020

Breaking Change.

An attempt to fix the UI change caused by #2243 probably this (Inline Video View is really shrinked with a lot of white spaces See screenshot)
Screenshot_2020-08-31-15-48-46-984_org commcare dalvik debug

I've moved the layout logic to it's own xml which also avoids the redundant nested view groups.

PS: Follow up later with #2339

TODO:

  • Allow multiple missing media views to be present when the question contains multiple missing media.
    • Seems like we only show inline-video view when both inline-video view and image are present in the question.
  • Fix showImageAboveText.
  • Fix video view visiiblilty issue once the video is downloaded(using missing media UI)
  • Add a background color to the missing media view.
  • Show missing media view for invalid image reference.
  • Check ResizingImageView, it was showing some error in the layout editor.
  • Validate this new change doesn't break any existing UI. Possibly through screenshot-tests Setup Screenshot tests #2339

@ShivamPokhriyal ShivamPokhriyal changed the title Inflate MediaLayout using xml Inflate MediaLayout using xml [WIP] Sep 3, 2020
@ShivamPokhriyal ShivamPokhriyal marked this pull request as ready for review September 3, 2020 14:57
@ShivamPokhriyal ShivamPokhriyal added this to the 2.50 milestone Sep 3, 2020
Copy link
Contributor Author

@ShivamPokhriyal ShivamPokhriyal Sep 3, 2020

Choose a reason for hiding this comment

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

Same, do we need to show something here as well just like we do for videoView?

Copy link
Contributor

Choose a reason for hiding this comment

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

we can follow the same pattern as videoView.

@shubham1g5
Copy link
Contributor

@ShivamPokhriyal Wondering if you are seeing a different behaviour on the currently released Playstore version. To me both the released and master video playback behaves exactly same with same amount of whitespace.

@ShivamPokhriyal
Copy link
Contributor Author

@ShivamPokhriyal Wondering if you are seeing a different behaviour on the currently released Playstore version. To me both the released and master video playback behaves exactly same with same amount of whitespace.

Yeah. the master build shows a lot of space to me, while the released version doesn't. You can try this app.

@shubham1g5
Copy link
Contributor

Got it. I can repro using your app. I was using a portrait video and possibly the bug doesn't surface with those. Would be good for you to test your solution with this app maybe so that we make sure we are not breaking anything.

Also the diff link in the PR description doesn't point me to anything specific but the PR and it seems like you were trying to point to something specific which broke this. Can you maybe try relinking the code point where it breaks.

@ShivamPokhriyal
Copy link
Contributor Author

Can you maybe try relinking the code point where it breaks.

Sure, I think this https://github.com/dimagi/commcare-android/blob/master/app/src/org/commcare/views/media/MediaLayout.java#L160-L162 code adds the unwanted space and shrinks the videoview.

@shubham1g5
Copy link
Contributor

@ShivamPokhriyal Sounds good. Let me know when it's ready to review again as we would want to get this in soon given the code freeze on Friday.

@ShivamPokhriyal
Copy link
Contributor Author

@shubham1g5 While carrying out the todo for showImageAboveText I realised that this layout hierarchy doesn't consider multiple missing medias.
Also, I'm really afraid that this change might break a lot of UI(paddings/margins). So I was thinking of setting up the screenshot tests to validate that this change doesn't break anything. So I guess it's gonna take a lot more time.

I've also edited the description of the PR with a list of TODOs.

@shubham1g5
Copy link
Contributor

@ShivamPokhriyal moving this to 2.51 in that case.

@shubham1g5 shubham1g5 modified the milestones: 2.50, 2.51 Sep 9, 2020
@shubham1g5
Copy link
Contributor

@ShivamPokhriyal I just noticed that the showImageAboveText is also breaking in master which makes it critical for us to fix this in 2.50. Wondering how do you feel about completing it for 2.50 without the screenshot tests (QA should be able to take care of that). If it's not likely I can attempt to fix these issues separately without xml layout in 2.50

@ShivamPokhriyal
Copy link
Contributor Author

@ShivamPokhriyal I just noticed that the showImageAboveText is also breaking in master which makes it critical for us to fix this in 2.50. Wondering how do you feel about completing it for 2.50 without the screenshot tests (QA should be able to take care of that). If it's not likely I can attempt to fix these issues separately without xml layout in 2.50

TBH I'm not really confident with this change😅. Though the only thing remaining in this PR is the video view visibility issue which is really tricky and I haven't been able to figure it out yet. If you think QA can take care of testing this change then I can definitely try fixing the video view issue and get it merged before QA starts.

params.width = maxBounds[0];
params.height = maxBounds[1];
params.width = metrics.widthPixels;
params.height = metrics.heightPixels;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

the reason why videoView doesn't appear after download completion was this maxBounds[1]. In my case, the textView had a really long text and I had to scroll down to see the videoView.

The getMaxCenterViewBounds method subtracts the text height from the total height
maxHeight = maxHeight - textViewContainer.getChildAt(0).getHeight(); making this maxBounds[1] to be 0.

Since, videoView will automatically configure itself with the min height possible, we're good to give it max height here.

Copy link
Contributor

Choose a reason for hiding this comment

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

nice find.

Log.e(TAG, "invalid video reference exception");
ire.printStackTrace();
return getMissingMediaView(inlineVideoURI, "Invalid reference: " + ire.getReferenceString(), false);
showMissingMediaView(inlineVideoURI, "Invalid reference: " + ire.getReferenceString(), false, null);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@shubham1g5 Do we need to localize this text?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also the information here isn't really informative imo. Would it be better if we say: Can't show media due to: ?

Copy link
Contributor

Choose a reason for hiding this comment

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

yes, we should localize anything we display on UI. I think the prefix you mentioned is redundant in Invalid ... but would not really mind us adding that.

Copy link
Contributor

@shubham1g5 shubham1g5 left a comment

Choose a reason for hiding this comment

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

Looks quite good to me. Left some very minor points for you to consider. On testing it's regressions, we should check the 2.50 test plan and see if our current tests have testcases for 1. QR view setup in the image 2. Missing Media (these would definitely need to get added) 3. showImageAboveText usecases.

app:layout_constraintTop_toBottomOf="@id/question_barrier" />

<!--
Missing media view
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: comments formatting seems off, should be single lined

@@ -0,0 +1,178 @@
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android"
Copy link
Contributor

Choose a reason for hiding this comment

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

Good use of merge to avoid layout hierarchy.

app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@id/audio_button" />

<androidx.constraintlayout.widget.Barrier
Copy link
Contributor

Choose a reason for hiding this comment

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

Read about Barrier a bit and seems like a real useful addition to the set of Android views. Thanks for finding about these.

android:id="@+id/buttons_barrier"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:barrierDirection="left"
Copy link
Contributor

Choose a reason for hiding this comment

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

should be start to not break RTL languages.

Log.e(TAG, "invalid video reference exception");
ire.printStackTrace();
return getMissingMediaView(inlineVideoURI, "Invalid reference: " + ire.getReferenceString(), false);
showMissingMediaView(inlineVideoURI, "Invalid reference: " + ire.getReferenceString(), false, null);
Copy link
Contributor

Choose a reason for hiding this comment

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

yes, we should localize anything we display on UI. I think the prefix you mentioned is redundant in Invalid ... but would not really mind us adding that.

params.width = maxBounds[0];
params.height = maxBounds[1];
params.width = metrics.widthPixels;
params.height = metrics.heightPixels;
Copy link
Contributor

Choose a reason for hiding this comment

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

nice find.

View downloadIcon = missingMediaView.findViewById(R.id.download_media_icon);
private void showMissingMediaView(String mediaUri, String errorMessage, boolean allowDownload, @Nullable Runnable completion) {
missingMediaBackground.setVisibility(VISIBLE);
missingMediaText.setText(errorMessage);
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: missingMediaText -> missingMediaStatus

true);
true,
() -> {
hideMissingMediaView();
Copy link
Contributor

Choose a reason for hiding this comment

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

stylistic point that you can ignore: hideMissingMediaView can be called from showMissingMediaView to DRY the completion logic further.

return;
}
addView(v, dividerParams);
private void resetView() {
Copy link
Contributor

Choose a reason for hiding this comment

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

this method can be avoided by setting the initial visibility of all views as gone in xml layout itself.

@shubham1g5 shubham1g5 modified the milestones: 2.51, 2.50 Sep 13, 2020
Copy link
Contributor

@shubham1g5 shubham1g5 left a comment

Choose a reason for hiding this comment

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

left Couple questions, though build seems to be failing on this one.

// Next align the text, audiobutton and videoButton below mediaView.
// Next align the text, audiobutton below mediaView.
alignTextContainerBelowMediaView(audioButton);
alignTextContainerBelowMediaView(videoButton);
Copy link
Contributor

Choose a reason for hiding this comment

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

confused why did we remove videoButton from 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.

videoButton has a constraint which places it below audioButton. So we only need to align audioButton top constraint while shifting it below media view.

}

private void initView(Context context) {
setId(AndroidUtil.generateViewId());
Copy link
Contributor

Choose a reason for hiding this comment

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

why is this required ?

Copy link
Contributor Author

@ShivamPokhriyal ShivamPokhriyal Sep 14, 2020

Choose a reason for hiding this comment

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

If not set, this.getId() call above returns -1 which is the same as LayoutParams.UNSET.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ahh Makes sense.

@ShivamPokhriyal
Copy link
Contributor Author

@damagatchi retest this please

android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
tools:visibility="gone"
Copy link
Contributor

Choose a reason for hiding this comment

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

tools:visibility should be visible while keeping the android:visibility as gone

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ahh Damn, silly me! I thought it behaves the same as android:visibility

initView(context);
}

public static MediaLayout buildAudioImageLayout(Context context, TextView text, String audioURI, String imageURI) {
Copy link
Contributor

Choose a reason for hiding this comment

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

this seems ununsed and can be removed.


addAudioVideoButtonsToView(questionTextPane);
// Next align the text, audiobutton below mediaView.
alignTextContainerBelowMediaView(audioButton);
Copy link
Contributor

Choose a reason for hiding this comment

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

Wondering if it's possible to avoid multiple calls of alignTextContainerBelowMediaView as well and instead use barrier/guideline mechanism to shift these views ?

Copy link
Contributor

@shubham1g5 shubham1g5 left a comment

Choose a reason for hiding this comment

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

Looks great! Kudos 🎆

@ShivamPokhriyal ShivamPokhriyal merged commit a4f075a into master Sep 14, 2020
@ShivamPokhriyal ShivamPokhriyal deleted the revamp-media-layout branch September 14, 2020 08:50
@ShivamPokhriyal ShivamPokhriyal changed the title Inflate MediaLayout using xml [WIP] Inflate MediaLayout using xml Sep 14, 2020
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.

3 participants