[Contributions-Tab] Scroll to top on NavBar Button Pressed (#4668)

* [Contributions-Tab] Scroll to top on NavBar Button Pressed

On NavBar Contributions Button pressed, if already on the Contributions tab,
scroll to the top of the recyclerView in ContributionsListFragment.

* [UnitTest][Contributions-Tab] Scroll to Top on NavBar Button Pressed
This commit is contained in:
codingtosh 2021-10-27 19:56:16 +05:30 committed by GitHub
parent 88b21a678e
commit 55c0b07ebf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 47 additions and 1 deletions

View file

@ -204,6 +204,12 @@ public class ContributionsFragment
throwable -> Timber.e(throwable, "Error occurred while loading notifications")));
}
public void scrollToTop( ){
if (contributionsListFragment != null) {
contributionsListFragment.scrollToTop();
}
}
private void initNotificationViews(List<Notification> notificationList) {
Timber.d("Number of notifications is %d", notificationList.size());
if (notificationList.isEmpty()) {

View file

@ -312,6 +312,10 @@ public class ContributionsListFragment extends CommonsDaggerSupportFragment impl
animateFAB(isFabOpen);
}
public void scrollToTop() {
rvContributionsList.smoothScrollToPosition(0);
}
private void animateFAB(final boolean isFabOpen) {
this.isFabOpen = !isFabOpen;
if (fabPlus.isShown()) {

View file

@ -163,7 +163,9 @@ public class MainActivity extends BaseActivity
//showBottom so that we do not show the bottom tray again when constructing
//from the saved instance state.
if (fragment instanceof ContributionsFragment) {
if (activeFragment == ActiveFragment.CONTRIBUTIONS) { // Do nothing if same tab
if (activeFragment == ActiveFragment.CONTRIBUTIONS) {
// scroll to top if already on the Contributions tab
contributionsFragment.scrollToTop();
return true;
}
contributionsFragment = (ContributionsFragment) fragment;