Skip to content

Fixed 4616 : Option for editing depictions#4725

Merged
nicolas-raoul merged 63 commits intocommons-app:masterfrom
Ayan-10:4616_edit_depicts
Mar 22, 2022
Merged

Fixed 4616 : Option for editing depictions#4725
nicolas-raoul merged 63 commits intocommons-app:masterfrom
Ayan-10:4616_edit_depicts

Conversation

@Ayan-10
Copy link
Contributor

@Ayan-10 Ayan-10 commented Dec 10, 2021

Description (required)

Made option for editing depictions.

Fixes #4616

What changes did you make and why?

In the current app depicts can be added only while uploading, it's very necessary for a user to edit depictions.

  1. I reused the depiction selection UI which is being used while uploading for letting user select the depicts
  2. Then I compare it with old depicts and send only new depicts for posting to the server
  3. A POST API call will post the new depicts in the commons server

Tests performed (required)

Tested lastest master betaDebug and ProdDebug on Pixel 3 with API level 30.

TODO

All tested with latest version after resetting data

  • Adding two depictions, actually only adds one.
  • Pressing "Back" goes back one level too far
  • Pressing "Back" is often very slow. If you wait for a few minutes on the UI, pressing the "Back" button in the depictions editor sometimes does nothing at first, the UI freezes.
  • The Nearby top banner sometimes appears, for instance if you open the dialog fast enough after starting the app.
  • Open the UI for a picture, close it, open for another picture: The depictions of the previous picture are still visible for a few seconds. They should not appear.
  • The UI does not take the whole screen: A bit of the media details is still visible at the bottom.
  • After adding a new depiction and saving, then opening the edition dialog again, the checkbox is not checked anymore.
  • When editing several pictures in a row, the edits are erroneous, for instance a picture for which I checked and saved "street" got actually edited (when looking at the Commons website) as "beach", a depiction I had used for a different picture before.
  • Depictions added via edit take longer to load in Media Details than the depictions that had been added in the Upload Wizard. For instance if I added depiction1/2/3 with Upload Wizard and depiction4/5/6 with the edition UI, then depiction1/2/3 appear immediately but depiction4/5/6 take a second or two to load. There should be zero difference.
  • Can not remove a depiction.
  • When I reach license then go back to depictions, sometimes the depictions I had selected are not selected anymore.

@codecov
Copy link

codecov bot commented Dec 10, 2021

Codecov Report

Merging #4725 (e647f8b) into master (1078c70) will increase coverage by 0.45%.
The diff coverage is 54.41%.

@@             Coverage Diff              @@
##             master    #4725      +/-   ##
============================================
+ Coverage     50.59%   51.04%   +0.45%     
- Complexity     2228     2293      +65     
============================================
  Files           338      341       +3     
  Lines         15599    15960     +361     
  Branches       1370     1410      +40     
============================================
+ Hits           7892     8147     +255     
- Misses         7114     7193      +79     
- Partials        593      620      +27     
Impacted Files Coverage Δ
...e/nrw/commons/notification/NotificationHelper.java 100.00% <ø> (ø)
...free/nrw/commons/wikidata/WikidataEditService.java 29.59% <33.33%> (+2.76%) ⬆️
...ee/nrw/commons/upload/depicts/DepictsFragment.java 55.33% <41.66%> (-27.02%) ⬇️
...ree/nrw/commons/upload/depicts/DepictsPresenter.kt 62.31% <45.71%> (-10.05%) ⬇️
...fr/free/nrw/commons/media/MediaDetailFragment.java 37.10% <55.55%> (+2.99%) ⬆️
...a/fr/free/nrw/commons/wikidata/WikiBaseClient.java 35.00% <66.66%> (+11.47%) ⬆️
...n/java/fr/free/nrw/commons/upload/UploadModel.java 37.14% <72.72%> (+11.56%) ⬆️
...ree/nrw/commons/upload/depicts/DepictEditHelper.kt 86.84% <86.84%> (ø)
.../free/nrw/commons/repository/UploadRepository.java 95.77% <92.85%> (-0.78%) ⬇️
...r/free/nrw/commons/contributions/MainActivity.java 74.86% <100.00%> (+0.13%) ⬆️
... and 15 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 1078c70...e647f8b. Read the comment docs.

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.

Thanks, that is extremely helpful!
I noticed a few issues:

  • After saving, depiction does not appear immediately in the media details (above the pen).
  • Pressing the "Back" button in the depictions editor sometimes does nothing at first, the UI freezes, then all of the backs are done very quickly. I observed something similar in the categories editor pull request.
  • The nearby banner appears at the top, if you open the dialog fast enough after starting the app.

@Ayan-10
Copy link
Contributor Author

Ayan-10 commented Dec 15, 2021

@nicolas-raoul I think "Depictions not updating instantly" issue is resolved now.

@nicolas-raoul
Copy link
Member

Would you mind solving the conflict? Sorry for the delay in reviewing, and thanks for your patience!

@Ayan-10
Copy link
Contributor Author

Ayan-10 commented Dec 22, 2021

@nicolas-raoul I resolved the conflicts and also could you please review #4515 once? the requested changes are made a long ago.

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 noticed another issue: On a picture that already has a depiction, the Edit Depicts dialog does not show that depiction. If I search for it, it is shown as checked.
Desired behavior: When opening Edit Depicts, it should show all current depictions (with the checkbox checked).
Thanks a lot!

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.

Also, pressing Back should bring back to the media details.
Currently, pressing back brings me to the list of media (one level too far).

@Ayan-10
Copy link
Contributor Author

Ayan-10 commented Dec 29, 2021

I noticed another issue: On a picture that already has a depiction, the Edit Depicts dialog does not show that depiction. If I search for it, it is shown as checked. Desired behavior: When opening Edit Depicts, it should show all current depictions (with the checkbox checked). Thanks a lot!

To show all existing depicts at the top we have to make a call to get DepictedItems because only Depicted IDs are available as existing depicts. In this PR I just compared the existing IDs with the search result and changed their checked states accordingly.

@nicolas-raoul
Copy link
Member

So you would have to call the API (with the depicted IDs) to get the information required for displaying them, right?

That sounds doable, and I think it is important to have a consistent behavior with the Upload Wizard :-)

@nicolas-raoul
Copy link
Member

nicolas-raoul commented Dec 30, 2021

Great, the UI now shows already existing depictions! :-)

Remaining bugs:

  • Pressing "Back" goes back one level too far
  • If you wait for a few minutes on the UI, pressing the "Back" button in the depictions editor sometimes does nothing at first, the UI freezes.
  • The Nearby top banner sometimes appears, for instance if you open the dialog fast enough after starting the app.
  • Open the UI for a picture, close it, open for another picture: The depictions of the previous picture are still visible for a few seconds. They should not appear.
  • The UI does not take the whole screen: A bit of the media details is still visible at the bottom.
  • After adding a new depiction and saving, then opening the edition dialog again, the checkbox is not checked anymore.
  • When editing several pictures in a row, the edits are erroneous, for instance a picture for which I checked and saved "street" got actually edited (when looking at the Commons website) as "beach", a depiction I had used for a different picture before.

@Ayan-10
Copy link
Contributor Author

Ayan-10 commented Dec 30, 2021

  • Open the UI for a picture, close it, open for another picture: The depictions of the previous picture are still visible for a few seconds. They should not appear.

@nicolas-raoul Currently the depictions of the previous picture are appearing as checked. I will remove the checked state of previous depictions. Is this ok with you or the previous ones should not appear at all?

@nicolas-raoul
Copy link
Member

I will remove the checked state of previous depictions

Sounds good! :-)

@nicolas-raoul
Copy link
Member

codeconv says that this pull request reduces unit test coverage significantly... would you mind trying to add more unit tests? @madhurgupta10 any recommendations maybe?

@madhurgupta10
Copy link
Collaborator

The diff coverage is 40.93%.

The diff coverage is 40.93% which means only about 40% of new lines are tested. Looking at the scope of this PR it is highly important to get around 70-80%

@Ayan-10 Try to break your code blocks into smaller blocks to test individual units (TDD)

@Ayan-10
Copy link
Contributor Author

Ayan-10 commented Mar 19, 2022

@madhurgupta10 Thanks a lot for the suggestion. But I think I added tests for most of the new lines. I think the problem here is a lot of lines gets auto intended that's why even if I didn't change anything on those lines, those lines are showing as changed lines. I will try to reverse the indentation. Other than that I added tests for all the lines that I really added or edited. @nicolas-raoul I think that will increase the diff coverage.

Thanks.

@nicolas-raoul
Copy link
Member

Thanks for reversing the indentation changes, that makes the pull request much clearer! :-)

The code coverage now looks much better, but still some effort needed before a good coverage rate is reached. Would you mind following Madhur's advice breaking your code blocks into smaller blocks to test individual units? Thanks a lot!

@Ayan-10
Copy link
Contributor Author

Ayan-10 commented Mar 20, 2022

@nicolas-raoul Yes, I can surely break the codes into small test individual units. But according to codecov/patch all the large blocks are already covered, among the left ones most of them are individual units. The problem that I found here is most of the uncovered lines need a real device for testing otherwise they will show errors in unit testing for example getParentFragment or getView. I tried to cover the lines as much as possible even the single line codes. If I try I can increase the coverage a little more but 70-80% apparently seems not possible.

@madhurgupta10 please have a look and if I am wrong somewhere please give your input.

Thanks a lot.

@madhurgupta10
Copy link
Collaborator

I think the coverage is sufficient for this PR to be merged, you can add instrumentation tests in future if needed.

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.

Minor variable name refactoring

</LinearLayout>

<Button
android:id="@+id/depictEditButton"
Copy link
Member

Choose a reason for hiding this comment

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

depictEditButton -> depictionsEditButton

* By clicking on the edit depicts button, it will send user to depict fragment
*/
@OnClick(R.id.depictEditButton)
public void onDepictEditButtonClicked() {
Copy link
Member

Choose a reason for hiding this comment

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

onDepictEditButtonClicked -> onDepictionsEditButtonClicked

public static final int NOTIFICATION_EDIT_CATEGORY = 2;
public static final int NOTIFICATION_EDIT_COORDINATES = 3;
public static final int NOTIFICATION_EDIT_DESCRIPTION = 4;
public static final int NOTIFICATION_EDIT_DEPICT = 5;
Copy link
Member

Choose a reason for hiding this comment

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

NOTIFICATION_EDIT_DEPICT -> NOTIFICATION_EDIT_DEPICTIONS

<item quantity="one">Depiction %1$s is added.</item>
<item quantity="other">Depictions %1$s are added.</item>
</plurals>
<string name="depict_edit_helper_edit_message_else">Could not add depictions.</string>
Copy link
Member

Choose a reason for hiding this comment

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

depict_edit_helper_edit_message_else -> depictions_edit_helper_edit_message_else

<string name="contributions_of_user">Contributions of User: %s</string>
<string name="achievements_of_user">Achievements of User: %s</string>
<string name="menu_view_user_page">View user page</string>
<string name="edit_depicts">Edit depictions</string>
Copy link
Member

Choose a reason for hiding this comment

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

edit_depicts -> edit_depictions

* and saves them in local storage
*/
@SuppressLint("CheckResult")
override fun updateDepicts(media: Media) {
Copy link
Member

Choose a reason for hiding this comment

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

updateDepicts -> updateDepictions

})
{
Timber.e(
"Failed to update depicts"
Copy link
Member

Choose a reason for hiding this comment

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

depicts -> depictions


void goBackToPreviousScreen();

List<String> getExistingDepicts();
Copy link
Member

Choose a reason for hiding this comment

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

getExistingDepicts -> getExistingDepictions

@nicolas-raoul nicolas-raoul merged commit bd9531b into commons-app:master Mar 22, 2022
@nicolas-raoul
Copy link
Member

Thanks Ayan! That's a great feature to have, it was not easy but thanks for your perseverance!

@Ayan-10
Copy link
Contributor Author

Ayan-10 commented Mar 22, 2022

Thanks for your appreciation.

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.

Media details: Make depictions editable

3 participants