-
Notifications
You must be signed in to change notification settings - Fork 1.3k
In depictions selection screen, suggest recently selected items #4361
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
Conversation
… items *use RoomDataBase * Add Javadoc
Codecov Report
@@ 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
Continue to review full report at Codecov.
|
There was a problem hiding this 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.
ok I fix it |
There was a problem hiding this 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 { |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/** | ||
* Get the depictesItem form DepictsRoomdataBase | ||
*/ | ||
List<DepictedItem> getRecentDepictesItem(final Application application) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getRecentDepictesItem -> getRecentDepictedItems
There was a problem hiding this 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, |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this 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()); |
There was a problem hiding this comment.
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
app/src/main/java/fr/free/nrw/commons/upload/depicts/DepictsFragment.java
Outdated
Show resolved
Hide resolved
if (repository.selectedDepictions.isNotEmpty()) { | ||
if (application.applicationContext != null) { |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
@ashishkumar468 contributionDao is implement in nice way i change DepictsDao like this and use AppDataBase to store table |
@ashishkumar468 Room need thread except livedata for threading what i use kotlin coroutines or rxandroid ? |
It seems like there are still several reviews to be fixed on this PR, am I wrong? |
@neslihanturan i fixed all the issue in the PR in commit " |
view.goToNextScreen() | ||
} else { | ||
view.noDepictionSelected() | ||
} | ||
} | ||
|
||
/** | ||
* Get the depictesItem form DepictsRoomdataBase |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo: depictesItem
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo: form
I just tested, it works perfectly :-) |
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? |
@neslihanturan i work |
@nicolas-raoul @neslihanturan i fixed small issue you can merge this |
Thanks, very useful addition, it will save users a lot of time! :-) |
…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
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)
