Skip to content

Fixes #4329 "Back button in edit categories triggers back of media details." #4346

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

Merged
merged 4 commits into from
Apr 19, 2021

Conversation

4D17Y4
Copy link
Contributor

@4D17Y4 4D17Y4 commented Apr 10, 2021

Description (required)

Fixes #4329

What changes did you make and why?

Added onKey listener to the fragment view.

Tests performed (required)

Tested BetaDebug on Nokia 6.1+ with API level 29.

@4D17Y4
Copy link
Contributor Author

4D17Y4 commented Apr 10, 2021

Up for review @nicolas-raoul , @neslihanturan .

Copy link
Collaborator

@neslihanturan neslihanturan left a comment

Choose a reason for hiding this comment

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

Hey @4D17Y4 , thanks the logic seems okay to me, however I frequently get this error when I am testing this PR. Do you think if this is related?

USER_COMMENT=
APP_VERSION_CODE=876
APP_VERSION_NAME=3.0.0-debug-4D17Y4-backbutton
ANDROID_VERSION=10
PHONE_MODEL=Redmi Note 8
STACK_TRACE=java.lang.IllegalStateException: The application's PagerAdapter changed the adapter's contents without calling PagerAdapter#notifyDataSetChanged! Expected adapter item count: 240, found: 260 Pager id: fr.free.nrw.commons.beta:id/mediaDetailsPager Pager class: class androidx.viewpager.widget.ViewPager Problematic adapter: class fr.free.nrw.commons.media.MediaDetailPagerFragment$MediaDetailAdapter
	at androidx.viewpager.widget.ViewPager.populate(ViewPager.java:1143)
	at androidx.viewpager.widget.ViewPager.populate(ViewPager.java:1092)
	at androidx.viewpager.widget.ViewPager.onMeasure(ViewPager.java:1622)
	at android.view.View.measure(View.java:25086)
	at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6872)
	at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1552)
	at android.widget.LinearLayout.measureVertical(LinearLayout.java:842)
	at android.widget.LinearLayout.onMeasure(LinearLayout.java:721)
	at android.view.View.measure(View.java:25086)
	at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6872)
	at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
	at android.view.View.measure(View.java:25086)
	at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6872)
	at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1552)
	at android.widget.LinearLayout.measureVertical(LinearLayout.java:842)
	at android.widget.LinearLayout.onMeasure(LinearLayout.java:721)
	at android.view.View.measure(View.java:25086)
	at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6872)
	at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
	at android.view.View.measure(View.java:25086)
	at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:735)
	at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:481)
	at android.view.View.measure(View.java:25086)
	at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6872)
	at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1552)
	at android.widget.LinearLayout.measureVertical(LinearLayout.java:842)
	at android.widget.LinearLayout.onMeasure(LinearLayout.java:721)
	at android.view.View.measure(View.java:25086)
	at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6872)
	at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
	at androidx.appcompat.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:143)
	at android.view.View.measure(View.java:25086)
	at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6872)
	at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1552)
	at android.widget.LinearLayout.measureVertical(LinearLayout.java:842)
	at android.widget.LinearLayout.onMeasure(LinearLayout.java:721)
	at android.view.View.measure(View.java:25086)
	at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6872)
	at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
	at android.view.View.measure(View.java:25086)
	at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6872)
	at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1552)
	at android.widget.LinearLayout.measureVertical(LinearLayout.java:842)
	at android.widget.LinearLayout.onMeasure(LinearLayout.java:721)
	at android.view.View.measure(View.java:25086)
	at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6872)
	at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
	at com.android.internal.policy.DecorView.onMeasure(DecorView.java:742)
	at android.view.View.measure(View.java:25086)
	at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:3083)
	at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1857)
	at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2146)
	at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1745)
	at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7768)
	at android.view.Choreographer$CallbackRecord.run(Choreographer.java:967)
	at android.view.Choreographer.doCallbacks(Choreographer.java:791)
	at android.view.Choreographer.doFrame(Choreographer.java:726)
	at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:952)
	at android.os.Handler.handleCallback(Handler.java:883)
	at android.os.Handler.dispatchMessage(Handler.java:100)
	at android.os.Looper.loop(Looper.java:214)
	at android.app.ActivityThread.main(ActivityThread.java:7356)
	at java.lang.reflect.Method.invoke(Native Method)
	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:491)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:940)

IS_SILENT=false

@4D17Y4
Copy link
Contributor Author

4D17Y4 commented Apr 12, 2021

I think its another issue #4283
I'll check and confirm if this commit has something to do with it.

@4D17Y4
Copy link
Contributor Author

4D17Y4 commented Apr 18, 2021

The mentioned issue is resolved.
This should not create a problem now.

Copy link
Member

@nicolas-raoul nicolas-raoul left a comment

Choose a reason for hiding this comment

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

It fixes the issue in the case:
Tap picture, Tap pencil, Tap Back

I wonder if fixing this case would also be possible? (I know it is not described in the issue but very close) :
Tap picture, Tap pencil, Tap search icon, Tap Back (keyboard disappears), Tap Back (now back to contributions instead of back to media details)

@codecov-commenter
Copy link

codecov-commenter commented Apr 18, 2021

Codecov Report

Merging #4346 (40f67c5) into master (b939db9) will decrease coverage by 0.08%.
The diff coverage is 0.00%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master    #4346      +/-   ##
============================================
- Coverage     10.30%   10.21%   -0.09%     
+ Complexity      471      469       -2     
============================================
  Files           342      342              
  Lines         13145    13104      -41     
  Branches       1063     1072       +9     
============================================
- Hits           1354     1338      -16     
+ Misses        11723    11698      -25     
  Partials         68       68              
Impacted Files Coverage Δ Complexity Δ
...r/free/nrw/commons/bookmarks/BookmarkFragment.java 0.00% <0.00%> (ø) 0.00 <0.00> (ø)
...rw/commons/bookmarks/BookmarkListRootFragment.java 8.65% <0.00%> (-0.17%) 1.00 <0.00> (ø)
.../nrw/commons/category/CategoryDetailsActivity.java 0.00% <0.00%> (ø) 0.00 <0.00> (ø)
...w/commons/contributions/ContributionsFragment.java 0.00% <ø> (ø) 0.00 <0.00> (ø)
...a/fr/free/nrw/commons/explore/ExploreFragment.java 0.00% <0.00%> (ø) 0.00 <0.00> (ø)
...e/nrw/commons/explore/ExploreListRootFragment.java 0.00% <0.00%> (ø) 0.00 <0.00> (ø)
...va/fr/free/nrw/commons/explore/SearchActivity.java 0.00% <0.00%> (ø) 0.00 <0.00> (ø)
...xplore/depictions/WikidataItemDetailsActivity.java 0.00% <0.00%> (ø) 0.00 <0.00> (ø)
...fr/free/nrw/commons/media/MediaDetailFragment.java 0.00% <0.00%> (ø) 0.00 <0.00> (ø)
...ee/nrw/commons/media/MediaDetailPagerFragment.java 0.00% <0.00%> (ø) 0.00 <0.00> (ø)
... and 27 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b939db9...40f67c5. Read the comment docs.

@4D17Y4
Copy link
Contributor Author

4D17Y4 commented Apr 18, 2021

Removed the focus logic as it needed much modification to track every event on the fragment and was not the best way.

Used other logic to check if the mediaDetails is closed or open.

  • Added a parameter and function to store the present fragment as we need to access it to get the mediaDetails state.
  • Used this instance to check if media details is open or not.
  • Using the functions return value identified when to close the fragment.

I've modified every instance of the Pager fragment to keep it consistent on each mediaDetails.
This handles each and every case and also the case @nicolas-raoul pointed out.

Need confirmation on the function name.

Let me know if I missed something.

Up for review @nicolas-raoul , @neslihanturan ,
Thanks

Copy link
Member

@nicolas-raoul nicolas-raoul left a comment

Choose a reason for hiding this comment

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

I tested the changes on many activities, it works great!
The source code looks good too, I only request very minors changes.

Copy link
Collaborator

@neslihanturan neslihanturan left a comment

Choose a reason for hiding this comment

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

Works great, we can merge it as soon as @nicolas-raoul 's reviews are done :)

@4D17Y4
Copy link
Contributor Author

4D17Y4 commented Apr 19, 2021

Done @neslihanturan, Thanks.

@neslihanturan
Copy link
Collaborator

Merging as @nicolas-raoul 's reviews are done, thanks @4D17Y4 :)

@neslihanturan neslihanturan merged commit f8a8f92 into commons-app:master Apr 19, 2021
@4D17Y4 4D17Y4 deleted the backbutton branch April 20, 2021 10:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Back button in edit categories triggers back of media details.
4 participants