-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Feature/refactor contributions #3046
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
Feature/refactor contributions #3046
Conversation
* Added ContributionsPresenter * Extracted out the cursor to presenter * Probable fix for commons-app#3028
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.
✅ A review job has been created and sent to the PullRequest network.
Check the status or cancel PullRequest code review here.
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.
Codecov Report
@@ Coverage Diff @@
## master #3046 +/- ##
=========================================
+ Coverage 4.41% 4.67% +0.25%
=========================================
Files 259 264 +5
Lines 12309 12354 +45
Branches 1056 1051 -5
=========================================
+ Hits 544 577 +33
- Misses 11726 11734 +8
- Partials 39 43 +4
Continue to review full report at Codecov.
|
…completed && local uri exists, use that uri to show image
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.
Hi @ashishkumar468 , I see same images on fast scroll, instead of new ones. Then after a while correct images are displayed. Do you think this is related with this pull request?
|
@ashishkumar468 Does the PR fix #3028? If it does we can rebase the PR on |
|
Thanks for testing this out @neslihanturan . Should not be related to this PR, but this PR intends to fix those things. I will look into it and add a fix for the same |
|
Yes, it is part of #3024 which is needed for 2.11. @misaochan can reconfirm. |
|
Hmm. Yes, we do need a fix for #3028 , however this PR introduces many other changes as well (which is expected because it is also part of the refactor task). Would it be simple to isolate the part that fixes #3028 ? If yes, it would be easier to simply submit a different PR for that, because otherwise I would need to run the comprehensive tests all over again. Normally once I finish pre-release testing, I try to have minimal code changes so that we don't hit unexpected side effects. |
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.
Very nice work! I think that most of my comments are questions and minor suggestions.
Reviewed with ❤️ by PullRequest
| import javax.inject.Inject; | ||
| import javax.inject.Named; | ||
|
|
||
| class ContributionsLocalDatSource { |
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.
Should this be ContributionsLocalDataSource?
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.
Yes, my bad, I will do the correction
| imageView.setBackground(null); | ||
| if ((contribution.getState() != Contribution.STATE_COMPLETED) && fileExists( | ||
| contribution.getLocalUri())) { | ||
| imageView.setImageURI(contribution.getLocalUri()); |
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.
If getState() != Contribution.STATE_COMPLETED, does contribution.getLocalUri() have some temporary image?
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.
Yes, contribution.localUri has the temporary uri for the image which is saved in the db while the upload is in progress
| @Binds | ||
| public abstract ContributionsContract.UserActionListener bindsContibutionsPresenter( | ||
| ContributionsPresenter | ||
| presenter); |
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.
Looks like this should go on the previous line.
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.
Do you mean the formatting ?
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.
Yes—just formatting. :-)
| } | ||
|
|
||
| @Override | ||
| public void onLoaderReset(@NonNull Loader<Cursor> loader) { |
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 documentation of LoaderManager.LoaderCallbacks doesn't mention whether onLoadFinished is guaranteed to be called before onLoaderReset. I found a StackOverflow thread where one commenter says:
onLoaderReset(Loader)asks you to fulfill the same contract [asonLoadFinished], but without providing a replacement [cursor]
Thus, I would suggest that you turn off the progress bar and all of the tip, just to be sure.
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.
Thanks for letting me know, I will make the required changes
|
|
||
| void registerDataSetObserver(DataSetObserver observer); | ||
|
|
||
| void unregisterDataSetObserver(DataSetObserver observer); |
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.
Removing these unused methods from the interface is a good idea.
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.
Sure, will do :-)
|
|
||
| @Override | ||
| public void onLoadFinished(@NonNull Loader<Cursor> loader, Cursor cursor) { | ||
| view.showProgress(false); |
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.
Where is view.showProgress(true)?
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.
That is called from the parent fragment, that is the one which initialises the loader, the parent fragment of ContributionsListFragment and MediaDetailPagerFragment
| rvContributionsList.setLayoutManager(gridLayoutManager); | ||
| } else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) { | ||
| fab_layout.setOrientation(LinearLayout.VERTICAL); | ||
| rvContributionsList.setLayoutManager(linearLayoutManager); |
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.
One of the things that is unclear to me is whether switching view managers like this will maintain the current scroll position. You wouldn't want to to pop up to the top just because the orientation changed. Likewise, because I believe these two maintain different scroll positions, you could get some strange effects by scrolling to different places in each orientation and then rotating the device to change back and forth.
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.
Yes, as a fix to that, we can store the id of the corresponding list item and use to id to request focus (bring to user's visible position) to that particular child
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.
Sounds like a good plan.
| public interface ViewHolder<T> { | ||
| void bindModel(Context context, T model); | ||
| void init(int position, | ||
| DisplayableContribution contribution); |
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'm a bit confused by this. ViewHolder is meant to be a generic holder object for a model (the generic T) and the Android context. It doesn't see appropriate to convert this to such a specific method. Perhaps this happened with some automated refactoring? I would strongly urge you to change it back and to introduce a new interface if necessary.
If you really want to go down this route, then you need to at least change ViewHolder to not have a generic parameter and rename the class to something more specific, like DisplayableContributionHolder. You may also want to move it to commons/contributions since that's where it seems to be used.
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.
Thanks for figuring this out, yes I am planning to change it to void bindModel(int position, T model);, context is not required by the view holder, it can get it from its itemView, what do you think ?
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 way I think about it, ViewHolder<T> is a very generic interface—you should be able to call bindModel with any type. As soon as you add position to it, the interface is no longer generic—the model must have some idea of "position" that is an integer.
But maybe this doesn't really matter. In this change, you only call init(...) from onBindViewHolder, which takes a ContributionViewHolder. Thus you don't even need to implement ViewHolder.
Thus, I would suggest reverting the changes to ViewHolder<T> and making ContributionViewHolder not implement that interface.
What do you think?
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.
Yes, I have made ContributionViewHolder not implement the generic ViewHolder, later on when the model holds the position, it could be refactored to implement the ViewHolder
| if ((contribution.getState() != Contribution.STATE_COMPLETED) && fileExists( | ||
| contribution.getLocalUri())) { | ||
| imageView.setImageURI(contribution.getLocalUri()); | ||
| }else { |
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.
Space before else.
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.
Will add :-)
| } | ||
|
|
||
| public void onDataSetInvalidated() { | ||
| //Doing nothing as of now |
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.
Most other comments have a space after //. Also, you may want to describe briefly what should happen in the future.
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.
Sure, will do
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.
| */ | ||
| private String getKeyForLRUCache(Uri contentUri) { | ||
| String[] split = contentUri.toString().split("/"); | ||
| return split[split.length-1]; |
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.
Consider using Uri.getLastPathSegment()—it seems to do what you want and is probably more efficient.
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.
Thanks for letting me know, I will use the same :-)
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.
Looks good to me.
| import fr.free.nrw.commons.BasePresenter; | ||
| import fr.free.nrw.commons.Media; | ||
|
|
||
| public class ContributionsContract { |
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.
Please add java docs
| import android.database.Cursor; | ||
| import javax.inject.Inject; | ||
|
|
||
| public class ContributionsRepository { |
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.
java docs
| * @param localUri | ||
| * @return | ||
| */ | ||
| private boolean fileExists(Uri localUri) { |
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.
Move this to FileUtils
| import timber.log.Timber; | ||
|
|
||
| public class ContributionViewHolder implements ViewHolder<DisplayableContribution> { | ||
| public class ContributionViewHolder extends RecyclerView.ViewHolder{ |
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.
formatting
|
@neslihanturan, the image list bug (wrong image being showed), can it be taken as a separate bug fix ? I think that is anyways existing as of now (in master). That seems to be somewhat related to the underlying image library+ListView combination. |
|
Sure @ashishkumar468 , other parts seems good to me. And I didn't experienced any issues on my previous tests except displaying wrong image. So I can merge it after tests passed. |
|
Thanks @neslihanturan :-) |
Description (required)
Fixes #3045 Refactor Contributions
What changes did you make and why?
Tests performed (required)
Tested {build variant, betaDebug} on Pixel-27