Skip to content

Refactor uploads #2981

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 10 commits into from
Jun 13, 2019
Merged

Refactor uploads #2981

merged 10 commits into from
Jun 13, 2019

Conversation

ashishkumar468
Copy link
Collaborator

@ashishkumar468 ashishkumar468 commented Jun 2, 2019

Refactor Upload Activities
Optimised UploadActivity, added fragments for various stages of upload, switched to MVP
Fixes #2886
To be tested
Uploads:

  • Camera upload

  • Camera nearby upload with successful wikidata edit

  • Single gallery upload

  • Google Photos upload

  • Multiple gallery upload

  • Gallery upload with successful wikidata edit - upload is successful but Wikidata edit is not. The toast is not even triggered.

  • Image taken date is correct

  • Suffixes are added if same title is used

In the current ShareActivity:

  • Tooltips for title, desc, license fields - tooltip not present for title

  • Language selector for desc

  • Prefilling of title and desc when upload initiated via Nearby

  • License selector

  • Link to license and Commons policies - works, but crashes app

  • Zoom in (and back out)

  • Open location of image on maps

  • Copy previous title/desc

Category suggestions/selection:

  • When search text field is empty, display:-Recent categories - does not work

  • Location-based category suggestions (if image has geolocation) - does not work

  • Title-based category suggestions - does not work

  • Wikidata item category (if image is uploaded via Nearby and if that Wikidata item has a category) - does not work

  • When user types in search text field:

Check for categories shortly after typing stops, repeatedly

  • Display exact matches at the top

  • Categories selected via both of these suggestion types need to be added to the list of category selections

  • BUG: Categories are not saved with multiple uploads, the final product in Commons is missing categories

Warnings:

  • If image is too dark

  • If image already exists in Commons (via hash check)

  • If user tries to submit empty title (do not allow to proceed)

  • If user does not select any categories

Image templates:

  • Ensure the same templates are added (not sure if this will be an issue if backend has not changed, but make sure you check)

* Fix duplicate param information (#2515)

* Bug fix issue #2476 (#2526)

* Added wikidataEntityID in all db versions, handled db.execSql via method runQuery

* Versioning and changelog for v2.10.2 (#2531)

* Update changelog.md

* Versioning for v2.10.2

* Update changelog.md

* Bugfix/issue 2580 (#2584)

* Corrected string placedholders in certain string files

* Corrected string placedholders in certain string files[Bug fix #2580]

* Bug Fix #2585 (#2647)

* Bug Fix #2585
* Added null checks on view in SearchImageFragment when updating views from external sources
* Disposed the disposables in SearchActivity and SearchImageFragment when no longer in active lifecycle

* use FragmentUtils to verify fragment active state

* Bug Fix issue #2648 (#2678)

* Bug Fix issue #2648
* Handled external storage permission before file download

* * Removed redudant check for permission in MediaDetailPagerFragment (Dexter already does that)
* Removed duplicate code in PermissionUtil$checkPermissionsAndPerformAction, used the existing function with conditional extra parameters

* string name typo correction

* BugFix issue #2652 (#2706)

* Addded null check on bookmark before operating on it

* BugFix issue #2711 (#2712)

* Added null checks in OkHttpJsonApiClient$searchImages MwQueryResponse

* BugFix #2718 (#2719)

* Handled null auth cookies

* Fix #2791: NPE when nominating for deletion and leaving screen (#2792)

* Bug Fix issue #2789 (#2790)

* Handled Illegal State Exception for non existent appropriate view parents in ViewUtils$showShortSnackbar

* BugFix #2720 (#2831)

BugFix deprecated licenes #2720

* ui fixes, wip, upload

* *Issue #2886, BugFix #2832[wip]
* updated UploadActivity code
* modified ui
* Updated UploadPresenterTest

* * updated interfaces names to follow names suffixed with Contract
* added test cases

* card view elevation

* view pager disabled swipe

* bug fix, duplicate image

* used existing non-swipable view pager

* Avoid image view resize with keyboard, added adjustPan and stateVisible as softinputMode for UploadActivity

* retain UploadBaseFragment instances on orientation changes

* * Added test cases for UploadMediaPresenter
* Injected io and main thread schedulers

* categories presenter test cased wip

* Added CategoriesPresenter test

* * Added the logic to show open map (with to be uploaded image's coordinates while uploading image)

* codacy suggested changes * added java docs

* Added travis_wait fot android-wait-for-emulator

* ranamed interface onResponseCallback to Callback

* * Added api to delete picture in UploadModel
* cleanUp in UploadModel. once upload has been initiated
* Removed unused methods from UploadModel and the corresponding test class

* * Added tests for UploadPresenter
* Travis suggested changes
* Addded copy previous title and description

* * Made the upload add descriptions visible when keyboard visible
* add description request focus only when user manually requests it

* Added JavaDocs, review suggested changes

* Fix dagger injection

* use DialogUtil to show info in descriptions

* use activity context for DialogUtil

* Minor changes
Copy link

@pullrequest pullrequest bot left a comment

Choose a reason for hiding this comment

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

✅ A review job has been created and sent to the PullRequest network.


Check the status or cancel PullRequest code review here.

@ashishkumar468
Copy link
Collaborator Author

ashishkumar468 commented Jun 2, 2019

Attaching screenshots for the test performed (if applicable)
Dark Image Warning
device-2019-06-02-214236
No Categories Selected Warning
device-2019-06-02-214554
Next Button Disabled in case of empty caption
device-2019-06-02-214815
Duplicate Image Warning
device-2019-06-02-215142
Tooltips for title and description
device-2019-06-12-020526
Attaching screenshot for successful wikidata edit via nearby
image

@ashishkumar468
Copy link
Collaborator Author

@maskaravivek Can you ebaborate this one Ensure the same templates are added (not sure if this will be an issue if backend has not changed, but make sure you check)

@vanshikaarora
Copy link
Contributor

@ashishkumar468 I was checking for uploads for images. And currently I think we couldn't merge this branch into master. I have mostly focused on changing title to captions mostly the UI part. The image title for uploading the image is not the captions nor the filename. I'll take the task of First Caption as filename and sending through API. Till then we can focus on other Issues with this PR:)

@misaochan misaochan changed the title Refactor uploads [WIP] Refactor uploads Jun 3, 2019
@misaochan
Copy link
Member

Just spoke to @ashishkumar468 and this is ready for testing now. I will start tomorrow - as it is a HUGE change, help with testing is always appreciated. :)

Copy link
Member

@misaochan misaochan left a comment

Choose a reason for hiding this comment

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

Preliminary review: Looks good to me for the most part, thanks @ashishkumar468 ! :)

  • Javadocs are mostly present but missing from a few classes.
  • Code style needs to be fixed
  • Codecov bot does not seem to have made the usual comment re: code coverage. Not sure why that is. :/

I will proceed with the manual testing now

Copy link

@pullrequest pullrequest bot left a comment

Choose a reason for hiding this comment

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

1 Message
⚠️ Due to its size, this pull request will likely have a little longer turnaround time and will probably require multiple passes from our reviewers.

Copy link
Member

@misaochan misaochan left a comment

Choose a reason for hiding this comment

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

Pending fixes mentioned in bold in opening comment edit.

@ashishkumar468
Copy link
Collaborator Author

Thanks for testing this out @misaochan. I will make the necessary changes and let you know :-)

maskaravivek and others added 2 commits June 9, 2019 17:34
* merged with master

* BugFix IllegalStateException
* setRetainState(true), not required with FragmentStatePagerAdapter
* Increase the ViewPager's Offscreen Limit, we want all the fragments to be active

* BugFix, clear selected categoris for previous upload session
* Clear Selected Categories
* Addded JavaDocs for CategoriesModel

* Code Formatting in app/src/main/java/fr/free/nrw/commons/upload/UploadModel.java

* Added class level JavaDoc UploadRemoteDataSource

* Added class level JavaDoc for UploadRepository

* Added JavaDocs for ThumbnailsAdapter

* Added JavaDocs for MediaLicensePresenter, CategoriesPresenter

* Removed null check on category query
* Show default catgeories based on image title and gps location when category text empty
* Allow search for empty category search

* Attached image scale listener to upload media image

* Bug fix, reduced the add description edit text clickable bound
@maskaravivek
Copy link
Member

Just tested wikidata edits. They are working fine for me.

@codecov-io
Copy link

codecov-io commented Jun 9, 2019

Codecov Report

Merging #2981 into master will increase coverage by 0.69%.
The diff coverage is 16.15%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master   #2981      +/-   ##
=========================================
+ Coverage    3.74%   4.43%   +0.69%     
=========================================
  Files         249     259      +10     
  Lines       12102   12261     +159     
  Branches     1070    1051      -19     
=========================================
+ Hits          453     544      +91     
- Misses      11615   11678      +63     
- Partials       34      39       +5
Impacted Files Coverage Δ
...fr/free/nrw/commons/media/MediaDetailFragment.java 0% <ø> (ø) ⬆️
...va/fr/free/nrw/commons/explore/SearchActivity.java 0% <ø> (ø) ⬆️
.../fr/free/nrw/commons/di/FragmentBuilderModule.java 0% <ø> (ø) ⬆️
...a/fr/free/nrw/commons/upload/UploadController.java 39.08% <ø> (ø) ⬆️
app/src/main/java/fr/free/nrw/commons/Utils.java 18.03% <ø> (ø) ⬆️
.../java/fr/free/nrw/commons/upload/GPSExtractor.java 1.75% <ø> (ø) ⬆️
...ree/nrw/commons/contributions/ContributionDao.java 0% <ø> (ø) ⬆️
.../fr/free/nrw/commons/upload/ThumbnailsAdapter.java 0% <0%> (ø)
...fr/free/nrw/commons/upload/UploadBaseFragment.java 0% <0%> (ø)
.../fr/free/nrw/commons/category/CategoriesModel.java 0% <0%> (ø) ⬆️
... and 37 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 6619ccf...bf5bb76. Read the comment docs.

maskaravivek and others added 2 commits June 10, 2019 00:36
* merged with master

* BugFix IllegalStateException
* setRetainState(true), not required with FragmentStatePagerAdapter
* Increase the ViewPager's Offscreen Limit, we want all the fragments to be active

* BugFix, clear selected categoris for previous upload session
* Clear Selected Categories
* Addded JavaDocs for CategoriesModel

* Code Formatting in app/src/main/java/fr/free/nrw/commons/upload/UploadModel.java

* Added class level JavaDoc UploadRemoteDataSource

* Added class level JavaDoc for UploadRepository

* Added JavaDocs for ThumbnailsAdapter

* Added JavaDocs for MediaLicensePresenter, CategoriesPresenter

* Removed null check on category query
* Show default catgeories based on image title and gps location when category text empty
* Allow search for empty category search

* Attached image scale listener to upload media image

* Bug fix, reduced the add description edit text clickable bound

* Added tooltip in Title in UploadMediaFragment

* BugFix recent categories

* Updated test methods
@maskaravivek
Copy link
Member

Just checked the following:

  • title based suggestions
  • tooltip for title

These things are now working for me.

There's still a memory leak happening which needs to be fixed (This is different from what I fixed in #3001 ).

device-2019-06-10-111428

* merged with master

* BugFix IllegalStateException
* setRetainState(true), not required with FragmentStatePagerAdapter
* Increase the ViewPager's Offscreen Limit, we want all the fragments to be active

* BugFix, clear selected categoris for previous upload session
* Clear Selected Categories
* Addded JavaDocs for CategoriesModel

* Code Formatting in app/src/main/java/fr/free/nrw/commons/upload/UploadModel.java

* Added class level JavaDoc UploadRemoteDataSource

* Added class level JavaDoc for UploadRepository

* Added JavaDocs for ThumbnailsAdapter

* Added JavaDocs for MediaLicensePresenter, CategoriesPresenter

* Removed null check on category query
* Show default catgeories based on image title and gps location when category text empty
* Allow search for empty category search

* Attached image scale listener to upload media image

* Bug fix, reduced the add description edit text clickable bound

* Added tooltip in Title in UploadMediaFragment

* BugFix recent categories

* Updated test methods

* Avoid memory leak, free the adpater in MediaLicenseFragment.onDestroyView
@ashishkumar468
Copy link
Collaborator Author

ashishkumar468 commented Jun 11, 2019

@maskaravivek Thanks for pointing out the memory leak. I have added a fix for it as well. @misaochan @neslihanturan, The PR is up for testing :-)

Copy link
Member

@maskaravivek maskaravivek left a comment

Choose a reason for hiding this comment

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

Looks good to me. Am happy to merge once @misaochan's review is also completed. :)

@neslihanturan
Copy link
Collaborator

Hi @ashishkumar0207 , I get this error on your branch just after choosing and image from gallery. I am not sure if this is relevant with your changes though. On beta cluster, API 26 emulator.

 Caused by: java.lang.IllegalStateException: The application's PagerAdapter changed the adapter's contents without calling PagerAdapter#notifyDataSetChanged! Expected adapter item count: 0, found: 3 Pager id: fr.free.nrw.commons.beta:id/vp_upload Pager class: class fr.free.nrw.commons.contributions.UnswipableViewPager Problematic adapter: class fr.free.nrw.commons.upload.UploadActivity$UploadImageAdapter
        at androidx.viewpager.widget.ViewPager.populate(ViewPager.java:1143)
        at androidx.viewpager.widget.ViewPager.populate(ViewPager.java:1092)
        at androidx.viewpager.widget.ViewPager.setOffscreenPageLimit(ViewPager.java:856)
        at fr.free.nrw.commons.upload.UploadActivity$UploadImageAdapter.getCount(UploadActivity.java:434)
        at androidx.viewpager.widget.ViewPager.dataSetChanged(ViewPager.java:1023)
        at androidx.viewpager.widget.ViewPager$PagerObserver.onChanged(ViewPager.java:3097)
        at androidx.viewpager.widget.PagerAdapter.notifyDataSetChanged(PagerAdapter.java:291)
        at fr.free.nrw.commons.upload.UploadActivity$UploadImageAdapter.setFragments(UploadActivity.java:425)
        at fr.free.nrw.commons.upload.UploadActivity.receiveSharedItems(UploadActivity.java:343)
        at fr.free.nrw.commons.upload.UploadActivity.lambda$uFmJNhak7opat5jgMvaezcNPkNM(Unknown Source:0)
        at fr.free.nrw.commons.upload.-$$Lambda$UploadActivity$uFmJNhak7opat5jgMvaezcNPkNM.run(Unknown Source:2)
        at fr.free.nrw.commons.utils.PermissionUtils$1.onPermissionGranted(PermissionUtils.java:114)
        at com.karumi.dexter.MultiplePermissionsListenerToPermissionListenerAdapter.onPermissionsChecked(Unknown Source:35)

@ashishkumar468
Copy link
Collaborator Author

@neslihanturan Thanks for helping with the logs, I have raise a PR fixing the Issue. please have a look #3012

* merged with master

* BugFix IllegalStateException
* setRetainState(true), not required with FragmentStatePagerAdapter
* Increase the ViewPager's Offscreen Limit, we want all the fragments to be active

* BugFix, clear selected categoris for previous upload session
* Clear Selected Categories
* Addded JavaDocs for CategoriesModel

* Code Formatting in app/src/main/java/fr/free/nrw/commons/upload/UploadModel.java

* Added class level JavaDoc UploadRemoteDataSource

* Added class level JavaDoc for UploadRepository

* Added JavaDocs for ThumbnailsAdapter

* Added JavaDocs for MediaLicensePresenter, CategoriesPresenter

* Removed null check on category query
* Show default catgeories based on image title and gps location when category text empty
* Allow search for empty category search

* Attached image scale listener to upload media image

* Bug fix, reduced the add description edit text clickable bound

* Added tooltip in Title in UploadMediaFragment

* BugFix recent categories

* Updated test methods

* Avoid memory leak, free the adpater in MediaLicenseFragment.onDestroyView

* BugFix Illegal State Exception in ViewpPagerAdapter

* Remove irrelevant comment
@neslihanturan
Copy link
Collaborator

neslihanturan commented Jun 12, 2019

Closing this one since same changes are merged on another pull request.

Sorry my mistake, it is not solved.

@neslihanturan neslihanturan reopened this Jun 12, 2019
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.

Sorry I forgot approving it earlier:)

@maskaravivek maskaravivek merged commit 7a5dc77 into master Jun 13, 2019
@ashishkumar468 ashishkumar468 deleted the refactor_uploads branch June 19, 2019 09:54
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.

Refactor UploadActivity
6 participants