Fixes #2815 - Nominating for deletion is cancelled on leaving the media details (#4295)

* fix issue with nominating for deletion

* Fix UI issue

* minor improvements

* fix App crash

* Added Javadoc and other minor improvements

* Updated string name

Co-authored-by: Pratham2305 <Pratham2305@users.noreply.github.com>
This commit is contained in:
Pratham Pahariya 2021-06-04 07:45:39 +05:30 committed by GitHub
parent 76b30678da
commit ca18763e4f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 224 additions and 38 deletions

View file

@ -565,6 +565,16 @@ public class ContributionsFragment
contributionsPresenter.saveContribution(contribution);
}
/**
* Notify the viewpager that number of items have changed.
*/
@Override
public void viewPagerNotifyDataSetChanged() {
if (mediaDetailPagerFragment != null) {
mediaDetailPagerFragment.notifyDataSetChanged();
}
}
/**
* Replace whatever is in the current contributionsFragmentContainer view with
* mediaDetailPagerFragment, and preserve previous state in back stack. Called when user selects a
@ -620,6 +630,21 @@ public class ContributionsFragment
return mediaDetailPagerFragment;
}
/**
* Reload media detail fragment once media is nominated
*
* @param index item position that has been nominated
*/
@Override
public void refreshNominatedMedia(int index) {
if(mediaDetailPagerFragment != null && !contributionsListFragment.isVisible()) {
removeFragment(mediaDetailPagerFragment);
mediaDetailPagerFragment = new MediaDetailPagerFragment(false, true);
mediaDetailPagerFragment.showImage(index);
showMediaDetailPagerFragment();
}
}
// click listener to toggle description that means uses can press the limited connection
// banner and description will hide. Tap again to show description.
private View.OnClickListener toggleDescriptionListener = new View.OnClickListener() {

View file

@ -157,6 +157,16 @@ public class ContributionsListFragment extends CommonsDaggerSupportFragment impl
}
}
}
/**
* Called whenever items in the list have changed
* Calls viewPagerNotifyDataSetChanged() that will notify the viewpager
*/
@Override
public void onItemRangeChanged(final int positionStart, final int itemCount) {
super.onItemRangeChanged(positionStart, itemCount);
callback.viewPagerNotifyDataSetChanged();
}
});
//Fab close on touch outside (Scrolling or taping on item triggers this action).
@ -370,11 +380,17 @@ public class ContributionsListFragment extends CommonsDaggerSupportFragment impl
public Media getMediaAtPosition(final int i) {
return adapter.getContributionForPosition(i).getMedia();
if(adapter.getContributionForPosition(i) != null) {
return adapter.getContributionForPosition(i).getMedia();
}
return null;
}
public int getTotalMediaCount() {
return adapter.getItemCount();
if(adapter != null) {
return adapter.getItemCount();
}
return 0;
}
/**
@ -406,5 +422,8 @@ public class ContributionsListFragment extends CommonsDaggerSupportFragment impl
void showDetail(int position, boolean isWikipediaButtonDisplayed);
void pauseUpload(Contribution contribution);
// Notify the viewpager that number of items have changed.
void viewPagerNotifyDataSetChanged();
}
}