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

In depictions selection screen, suggest recently selected items #4361

Merged
merged 8 commits into from
May 31, 2021
Merged

In depictions selection screen, suggest recently selected items #4361

merged 8 commits into from
May 31, 2021

Conversation

Prince-kushwaha
Copy link
Contributor

Description (required)

Fixes #3634

What changes did you make and why?

Implement RoomDataBase to save recent selected item of DepictedItem
when query is empty show the recent selected item of DepictedItem in recyclerview

Tests performed (required)
Android Device of API(25,29)

Screenshots (for UI changes only)
Screenshot_2021-04-17-16-23-38-086_fr free nrw commons 1

@codecov-commenter
Copy link

codecov-commenter commented Apr 17, 2021

Codecov Report

Merging #4361 (0bd93b5) into master (4bca142) will decrease coverage by 0.05%.
The diff coverage is 1.88%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master    #4361      +/-   ##
============================================
- Coverage     10.22%   10.17%   -0.06%     
  Complexity      469      469              
============================================
  Files           342      343       +1     
  Lines         13084    13156      +72     
  Branches       1062     1078      +16     
============================================
  Hits           1338     1338              
- Misses        11678    11749      +71     
- Partials         68       69       +1     
Impacted Files Coverage Δ Complexity Δ
...rc/main/java/fr/free/nrw/commons/db/AppDatabase.kt 0.00% <ø> (ø) 0.00 <0.00> (ø)
...c/main/java/fr/free/nrw/commons/db/Converters.java 0.00% <0.00%> (ø) 0.00 <0.00> (ø)
.../free/nrw/commons/di/CommonsApplicationModule.java 0.00% <0.00%> (ø) 0.00 <0.00> (ø)
...n/java/fr/free/nrw/commons/upload/UploadModel.java 0.00% <0.00%> (ø) 0.00 <0.00> (ø)
...a/fr/free/nrw/commons/upload/depicts/DepictsDao.kt 0.00% <0.00%> (ø) 0.00 <0.00> (?)
...ee/nrw/commons/upload/depicts/DepictsFragment.java 0.00% <0.00%> (ø) 0.00 <0.00> (ø)
...ree/nrw/commons/upload/depicts/DepictsPresenter.kt 85.71% <0.00%> (-6.60%) 12.00 <0.00> (ø)
...ommons/upload/structure/depictions/DepictedItem.kt 88.67% <100.00%> (ø) 16.00 <1.00> (ø)
...rw/commons/bookmarks/BookmarkListRootFragment.java 8.65% <0.00%> (-0.17%) 1.00% <0.00%> (ø%)
...va/fr/free/nrw/commons/explore/SearchActivity.java 0.00% <0.00%> (ø) 0.00% <0.00%> (ø%)
... and 12 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 4bca142...0bd93b5. 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.

It mostly runs great, good work!
I started testing it and I noticed a problem: when you search for a depiction (depiction1) select it, then empty the text from the search bar (for instance to search for another depiction depiction2), the selected depiction1 is not visible anymore.

@Prince-kushwaha
Copy link
Contributor Author

ok I fix it

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.

The problem I mentioned in my previous comment seems to be fixed, thanks! :-)

import androidx.room.*

@Dao
interface DepictsDao {
Copy link
Member

Choose a reason for hiding this comment

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

What is the equivalent class for categories? (the DAO that saves previously selected categories)

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 a small bug:
adb
Feel free to either fix it now, or create a new issue to solve later, as it is not a big issue compared to the merits that history brings.

/**
* Get the depictesItem form DepictsRoomdataBase
*/
List<DepictedItem> getRecentDepictesItem(final Application application) {
Copy link
Member

Choose a reason for hiding this comment

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

getRecentDepictesItem -> getRecentDepictedItems

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.

Some bad practices found.

// if it is, then create the database
return INSTANCE ?: synchronized(this) {
val instance = Room.databaseBuilder(
context.applicationContext,
Copy link
Collaborator

Choose a reason for hiding this comment

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

to get the context here, you have passed application at the beginning of method calls. No need to pass Application, just pass the context.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Why do we need to create a new Database? Why are we not using the existing database and adding a table in that?

Copy link
Collaborator

@ashishkumar468 ashishkumar468 left a comment

Choose a reason for hiding this comment

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

@Prince-kushwaha Thanks for the PR, even though this PR solves the issue, I would very much recommend to rediscuss the approach on the thread and probably revise the PR with the suggestions

@@ -149,7 +153,7 @@ public void setDepictsList(List<DepictedItem> depictedItemList) {

@OnClick(R.id.depicts_next)
public void onNextButtonClicked() {
presenter.verifyDepictions();
presenter.verifyDepictions(getActivity().getApplication());
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why are we passing the context to the presenter? Let it be the other way around, the presenter should ask the view for the things which need context

if (repository.selectedDepictions.isNotEmpty()) {
if (application.applicationContext != null) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

We have dagger in place for DB read write operations, we need not worry about the context, please refer other similar classes to see how we have used the corresponding DAO's to query the DB

// if it is, then create the database
return INSTANCE ?: synchronized(this) {
val instance = Room.databaseBuilder(
context.applicationContext,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why do we need to create a new Database? Why are we not using the existing database and adding a table in that?

@@ -0,0 +1,63 @@
package fr.free.nrw.commons.upload.depicts
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is not needed I guess, Room handles the threading part on its own, even if it does not why make a separate class and not let the callers switch threads as needed?

@@ -177,8 +178,10 @@ public void deletePicture(final String filePath) {
public void onDepictItemClicked(DepictedItem depictedItem) {
if (depictedItem.isSelected()) {
selectedDepictions.add(depictedItem);
DepictsFragment.selectedDepictedItem.add(depictedItem);
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should ideally avoid static variables, can this not be done via callbacks?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i thing no can you tell me other way

Copy link
Collaborator

Choose a reason for hiding this comment

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

It has to be done with "callbacks". You can basically search how to avoid static variables and how to use callbacks and you will find several online examples that shows you the required structure.

@Prince-kushwaha
Copy link
Contributor Author

@ashishkumar468 contributionDao is implement in nice way i change DepictsDao like this and use AppDataBase to store table
AppDatabase file is in db folder contribution data is also save in AppDataBase

@Prince-kushwaha
Copy link
Contributor Author

@ashishkumar468 Room need thread except livedata for threading what i use kotlin coroutines or rxandroid ?

@neslihanturan
Copy link
Collaborator

It seems like there are still several reviews to be fixed on this PR, am I wrong?

@Prince-kushwaha
Copy link
Contributor Author

@neslihanturan i fixed all the issue in the PR in commit improve implemention strategy

"

view.goToNextScreen()
} else {
view.noDepictionSelected()
}
}

/**
* Get the depictesItem form DepictsRoomdataBase
Copy link
Member

Choose a reason for hiding this comment

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

Typo: depictesItem

Copy link
Member

Choose a reason for hiding this comment

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

Typo: form

@nicolas-raoul
Copy link
Member

I just tested, it works perfectly :-)

@neslihanturan
Copy link
Collaborator

Seems like we can merge this one as soon as small fixes are done. @Prince-kushwaha can you let us know if you are not interested anymore or plan to continue?

@Prince-kushwaha
Copy link
Contributor Author

@neslihanturan i work

@Prince-kushwaha
Copy link
Contributor Author

@nicolas-raoul @neslihanturan i fixed small issue you can merge this

@nicolas-raoul nicolas-raoul merged commit 4fa18e5 into commons-app:master May 31, 2021
@nicolas-raoul
Copy link
Member

Thanks, very useful addition, it will save users a lot of time! :-)

ashishkumar468 pushed a commit to ashishkumar468/apps-android-commons that referenced this pull request Jul 5, 2021
…ons-app#4361)

* implement in depictions selection screen to suggest recently selected items

*use RoomDataBase
* Add Javadoc

* fix an bug

* minar change and remove extra line of code

* minar changes

* improve implemention strategy

* fix unittest

* Add javadoc

* added javadoc
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.

In depictions selection screen, suggest recently selected items
5 participants