Skip to content

Commit 0537470

Browse files
committed
fix display of contributions
1 parent 27a8352 commit 0537470

13 files changed

+186
-301
lines changed

app/src/main/java/fr/free/nrw/commons/contributions/Contribution.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,4 +310,15 @@ public Contribution[] newArray(int size) {
310310
return new Contribution[size];
311311
}
312312
};
313+
314+
@NonNull
315+
@Override
316+
public String toString() {
317+
return String.valueOf(_id);
318+
}
319+
320+
@Override
321+
public int hashCode() {
322+
return toString().hashCode();
323+
}
313324
}

app/src/main/java/fr/free/nrw/commons/contributions/ContributionsContract.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ public class ContributionsContract {
1212

1313
public interface View {
1414

15-
void showProgress(boolean shouldShow);
16-
1715
void showMessage(String localizedMessage);
1816
}
1917

@@ -23,8 +21,6 @@ public interface UserActionListener extends BasePresenter<ContributionsContract.
2321

2422
void deleteUpload(Contribution contribution);
2523

26-
Media getItemAtPosition(int i);
27-
2824
void updateContribution(Contribution contribution);
2925

3026
void fetchMediaDetails(Contribution contribution);

app/src/main/java/fr/free/nrw/commons/contributions/ContributionsFragment.java

Lines changed: 68 additions & 134 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import androidx.annotation.NonNull;
2020
import androidx.annotation.Nullable;
2121
import androidx.fragment.app.Fragment;
22-
import androidx.fragment.app.FragmentManager;
2322
import androidx.fragment.app.FragmentManager.OnBackStackChangedListener;
2423
import androidx.fragment.app.FragmentTransaction;
2524
import butterknife.BindView;
@@ -31,7 +30,7 @@
3130
import fr.free.nrw.commons.campaigns.CampaignView;
3231
import fr.free.nrw.commons.campaigns.CampaignsPresenter;
3332
import fr.free.nrw.commons.campaigns.ICampaignsView;
34-
import fr.free.nrw.commons.contributions.ContributionsListAdapter.Callback;
33+
import fr.free.nrw.commons.contributions.ContributionsListFragment.Callback;
3534
import fr.free.nrw.commons.contributions.ContributionsListFragment.SourceRefresher;
3635
import fr.free.nrw.commons.di.CommonsDaggerSupportFragment;
3736
import fr.free.nrw.commons.kvstore.JsonKvStore;
@@ -62,11 +61,11 @@
6261
public class ContributionsFragment
6362
extends CommonsDaggerSupportFragment
6463
implements
65-
MediaDetailProvider,
6664
OnBackStackChangedListener,
6765
SourceRefresher,
6866
LocationUpdateListener,
69-
ICampaignsView, ContributionsContract.View {
67+
MediaDetailProvider,
68+
ICampaignsView, ContributionsContract.View, Callback {
7069
@Inject @Named("default_preferences") JsonKvStore store;
7170
@Inject NearbyController nearbyController;
7271
@Inject OkHttpJsonApiClient okHttpJsonApiClient;
@@ -78,8 +77,8 @@ public class ContributionsFragment
7877
private CompositeDisposable compositeDisposable = new CompositeDisposable();
7978

8079
private ContributionsListFragment contributionsListFragment;
81-
private MediaDetailPagerFragment mediaDetailPagerFragment;
8280
private static final String CONTRIBUTION_LIST_FRAGMENT_TAG = "ContributionListFragmentTag";
81+
private MediaDetailPagerFragment mediaDetailPagerFragment;
8382
static final String MEDIA_DETAIL_PAGER_FRAGMENT_TAG = "MediaDetailFragmentTag";
8483

8584
@BindView(R.id.card_view_nearby) public NearbyNotificationCardView nearbyNotificationCardView;
@@ -113,7 +112,6 @@ public void onServiceDisconnected(ComponentName componentName) {
113112
}
114113
};
115114
private boolean shouldShowMediaDetailsFragment;
116-
private int numberOfContributions;
117115
private boolean isAuthCookieAcquired;
118116

119117
@Override
@@ -140,103 +138,21 @@ public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
140138

141139
if (savedInstanceState != null) {
142140
mediaDetailPagerFragment = (MediaDetailPagerFragment) getChildFragmentManager()
143-
.findFragmentByTag(MEDIA_DETAIL_PAGER_FRAGMENT_TAG);
141+
.findFragmentByTag(MEDIA_DETAIL_PAGER_FRAGMENT_TAG);
144142
contributionsListFragment = (ContributionsListFragment) getChildFragmentManager()
145-
.findFragmentByTag(CONTRIBUTION_LIST_FRAGMENT_TAG);
143+
.findFragmentByTag(CONTRIBUTION_LIST_FRAGMENT_TAG);
146144
shouldShowMediaDetailsFragment = savedInstanceState.getBoolean("mediaDetailsVisible");
147145
}
148146

149147
initFragments();
150148

151-
if(shouldShowMediaDetailsFragment){
152-
showMediaDetailPagerFragment();
153-
}else{
154-
showContributionsListFragment();
155-
}
156-
157149
if (!ConfigUtils.isBetaFlavour()) {
158150
setUploadCount();
159151
}
160152

161-
getChildFragmentManager().registerFragmentLifecycleCallbacks(
162-
new FragmentManager.FragmentLifecycleCallbacks() {
163-
@Override public void onFragmentResumed(FragmentManager fm, Fragment f) {
164-
super.onFragmentResumed(fm, f);
165-
//If media detail pager fragment is visible, hide the campaigns view [might not be the best way to do, this but yeah, this proves to work for now]
166-
Timber.e("onFragmentResumed %s", f.getClass().getName());
167-
if (f instanceof MediaDetailPagerFragment) {
168-
campaignView.setVisibility(View.GONE);
169-
}
170-
}
171-
172-
@Override public void onFragmentDetached(FragmentManager fm, Fragment f) {
173-
super.onFragmentDetached(fm, f);
174-
Timber.e("onFragmentDetached %s", f.getClass().getName());
175-
//If media detail pager fragment is detached, ContributionsList fragment is gonna be visible, [becomes tightly coupled though]
176-
if (f instanceof MediaDetailPagerFragment) {
177-
fetchCampaigns();
178-
}
179-
}
180-
}, true);
181-
182153
return view;
183154
}
184155

185-
/**
186-
* Initialose the ContributionsListFragment and MediaDetailPagerFragment fragment
187-
*/
188-
private void initFragments() {
189-
if (null == contributionsListFragment) {
190-
contributionsListFragment = new ContributionsListFragment();
191-
}
192-
193-
contributionsListFragment.setCallback(new Callback() {
194-
@Override
195-
public void retryUpload(Contribution contribution) {
196-
ContributionsFragment.this.retryUpload(contribution);
197-
}
198-
199-
@Override
200-
public void deleteUpload(Contribution contribution) {
201-
contributionsPresenter.deleteUpload(contribution);
202-
}
203-
204-
@Override
205-
public void openMediaDetail(int position) {
206-
showDetail(position);
207-
}
208-
209-
@Override
210-
public Contribution getContributionForPosition(int position) {
211-
return (Contribution) contributionsPresenter.getItemAtPosition(position);
212-
}
213-
214-
@Override
215-
public void fetchMediaUriFor(Contribution contribution) {
216-
Timber.d("Fetching thumbnail for %s", contribution.filename);
217-
contributionsPresenter.fetchMediaDetails(contribution);
218-
}
219-
});
220-
221-
if(null==mediaDetailPagerFragment){
222-
mediaDetailPagerFragment=new MediaDetailPagerFragment();
223-
}
224-
}
225-
226-
227-
/**
228-
* Replaces the root frame layout with the given fragment
229-
* @param fragment
230-
* @param tag
231-
*/
232-
private void showFragment(Fragment fragment, String tag) {
233-
FragmentTransaction transaction = getChildFragmentManager().beginTransaction();
234-
transaction.replace(R.id.root_frame, fragment, tag);
235-
transaction.addToBackStack(CONTRIBUTION_LIST_FRAGMENT_TAG);
236-
transaction.commit();
237-
getChildFragmentManager().executePendingTransactions();
238-
}
239-
240156
@Override
241157
public void onAttach(Context context) {
242158
super.onAttach(context);
@@ -264,7 +180,7 @@ private void showContributionsListFragment() {
264180
if (nearbyNotificationCardView != null) {
265181
if (store.getBoolean("displayNearbyCardView", true)) {
266182
if (nearbyNotificationCardView.cardViewVisibilityState
267-
== NearbyNotificationCardView.CardViewVisibilityState.READY) {
183+
== NearbyNotificationCardView.CardViewVisibilityState.READY) {
268184
nearbyNotificationCardView.setVisibility(View.VISIBLE);
269185
}
270186
} else {
@@ -274,18 +190,20 @@ private void showContributionsListFragment() {
274190
showFragment(contributionsListFragment, CONTRIBUTION_LIST_FRAGMENT_TAG);
275191
}
276192

277-
/**
278-
* Replace FrameLayout with MediaDetailPagerFragment, user will see details of selected media.
279-
* Creates new one if null.
280-
*/
281193
private void showMediaDetailPagerFragment() {
282194
// hide tabs on media detail view is visible
283-
((MainActivity)getActivity()).hideTabs();
195+
((MainActivity) getActivity()).hideTabs();
284196
// hide nearby card view on media detail is visible
285197
nearbyNotificationCardView.setVisibility(View.GONE);
286198

287-
showFragment(mediaDetailPagerFragment,MEDIA_DETAIL_PAGER_FRAGMENT_TAG);
199+
showFragment(mediaDetailPagerFragment, MEDIA_DETAIL_PAGER_FRAGMENT_TAG);
200+
201+
}
288202

203+
private void setupViewForMediaDetails() {
204+
campaignView.setVisibility(View.GONE);
205+
nearbyNotificationCardView.setVisibility(View.GONE);
206+
((MainActivity)getActivity()).hideTabs();
289207
}
290208

291209
@Override
@@ -306,43 +224,47 @@ void onAuthCookieAcquired() {
306224

307225
}
308226

309-
public Intent getUploadServiceIntent(){
310-
Intent intent = new Intent(getActivity(), UploadService.class);
311-
intent.setAction(UploadService.ACTION_START_SERVICE);
312-
return intent;
313-
}
227+
private void initFragments() {
228+
if (null == contributionsListFragment) {
229+
contributionsListFragment = new ContributionsListFragment(this);
230+
}
314231

315-
/**
316-
* Replace whatever is in the current contributionsFragmentContainer view with
317-
* mediaDetailPagerFragment, and preserve previous state in back stack.
318-
* Called when user selects a contribution.
319-
*/
320-
private void showDetail(int i) {
321-
if (mediaDetailPagerFragment == null || !mediaDetailPagerFragment.isVisible()) {
322-
mediaDetailPagerFragment = new MediaDetailPagerFragment();
232+
if (shouldShowMediaDetailsFragment) {
323233
showMediaDetailPagerFragment();
234+
} else {
235+
showContributionsListFragment();
324236
}
325-
mediaDetailPagerFragment.showImage(i);
326-
}
327237

328-
@Override
329-
public void refreshSource() {
238+
showFragment(contributionsListFragment, CONTRIBUTION_LIST_FRAGMENT_TAG);
239+
}
330240

241+
/**
242+
* Replaces the root frame layout with the given fragment
243+
*
244+
* @param fragment
245+
* @param tag
246+
*/
247+
private void showFragment(Fragment fragment, String tag) {
248+
FragmentTransaction transaction = getChildFragmentManager().beginTransaction();
249+
transaction.replace(R.id.root_frame, fragment, tag);
250+
transaction.addToBackStack(CONTRIBUTION_LIST_FRAGMENT_TAG);
251+
transaction.commit();
252+
getChildFragmentManager().executePendingTransactions();
331253
}
332254

333-
@Override
334-
public Media getMediaAtPosition(int i) {
335-
return contributionsPresenter.getItemAtPosition(i);
255+
public Intent getUploadServiceIntent(){
256+
Intent intent = new Intent(getActivity(), UploadService.class);
257+
intent.setAction(UploadService.ACTION_START_SERVICE);
258+
return intent;
336259
}
337260

338261
@Override
339-
public int getTotalMediaCount() {
340-
return numberOfContributions;
262+
public void refreshSource() {
263+
341264
}
342265

343266
@SuppressWarnings("ConstantConditions")
344267
private void setUploadCount() {
345-
346268
compositeDisposable.add(okHttpJsonApiClient
347269
.getUploadCount(((MainActivity)getActivity()).sessionManager.getCurrentAccount().name)
348270
.subscribeOn(Schedulers.io())
@@ -372,8 +294,6 @@ public void onPause() {
372294
@Override
373295
public void onSaveInstanceState(Bundle outState) {
374296
super.onSaveInstanceState(outState);
375-
boolean mediaDetailsVisible = mediaDetailPagerFragment != null && mediaDetailPagerFragment.isVisible();
376-
outState.putBoolean("mediaDetailsVisible", mediaDetailsVisible);
377297
}
378298

379299
@Override
@@ -458,17 +378,11 @@ private void updateClosestNearbyCardViewInfo() {
458378
}
459379

460380
private void updateNearbyNotification(@Nullable NearbyController.NearbyPlacesInfo nearbyPlacesInfo) {
461-
462381
if (nearbyPlacesInfo != null && nearbyPlacesInfo.placeList != null && nearbyPlacesInfo.placeList.size() > 0) {
463382
Place closestNearbyPlace = nearbyPlacesInfo.placeList.get(0);
464383
String distance = formatDistanceBetween(curLatLng, closestNearbyPlace.location);
465384
closestNearbyPlace.setDistance(distance);
466385
nearbyNotificationCardView.updateContent(closestNearbyPlace);
467-
if (mediaDetailPagerFragment != null && mediaDetailPagerFragment.isVisible()) {
468-
nearbyNotificationCardView.setVisibility(View.GONE);
469-
}else {
470-
nearbyNotificationCardView.setVisibility(View.VISIBLE);
471-
}
472386
} else {
473387
// Means that no close nearby place is found
474388
nearbyNotificationCardView.setVisibility(View.GONE);
@@ -548,17 +462,13 @@ private void fetchCampaigns() {
548462
presenter.onDetachView();
549463
}
550464

551-
@Override
552-
public void showProgress(boolean shouldShow) {
553-
contributionsListFragment.showProgress(shouldShow);
554-
}
555-
556465
/**
557466
* Retry upload when it is failed
558467
*
559468
* @param contribution contribution to be retried
560469
*/
561-
private void retryUpload(Contribution contribution) {
470+
@Override
471+
public void retryUpload(Contribution contribution) {
562472
if (NetworkUtils.isInternetConnectionEstablished(getContext())) {
563473
if (contribution.getState() == STATE_FAILED && null != uploadService) {
564474
uploadService.queue(UploadService.ACTION_UPLOAD_FILE, contribution);
@@ -571,5 +481,29 @@ private void retryUpload(Contribution contribution) {
571481
}
572482

573483
}
484+
485+
/**
486+
* Replace whatever is in the current contributionsFragmentContainer view with
487+
* mediaDetailPagerFragment, and preserve previous state in back stack. Called when user selects a
488+
* contribution.
489+
*/
490+
@Override
491+
public void showDetail(int position) {
492+
if (mediaDetailPagerFragment == null || !mediaDetailPagerFragment.isVisible()) {
493+
mediaDetailPagerFragment = new MediaDetailPagerFragment();
494+
showMediaDetailPagerFragment();
495+
}
496+
mediaDetailPagerFragment.showImage(position);
497+
}
498+
499+
@Override
500+
public Media getMediaAtPosition(int i) {
501+
return contributionsListFragment.getMediaAtPosition(i);
502+
}
503+
504+
@Override
505+
public int getTotalMediaCount() {
506+
return contributionsListFragment.getTotalMediaCount();
507+
}
574508
}
575509

0 commit comments

Comments
 (0)