mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 12:53:55 +01:00
[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:
parent
88b21a678e
commit
55c0b07ebf
6 changed files with 47 additions and 1 deletions
|
|
@ -204,6 +204,12 @@ public class ContributionsFragment
|
||||||
throwable -> Timber.e(throwable, "Error occurred while loading notifications")));
|
throwable -> Timber.e(throwable, "Error occurred while loading notifications")));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void scrollToTop( ){
|
||||||
|
if (contributionsListFragment != null) {
|
||||||
|
contributionsListFragment.scrollToTop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void initNotificationViews(List<Notification> notificationList) {
|
private void initNotificationViews(List<Notification> notificationList) {
|
||||||
Timber.d("Number of notifications is %d", notificationList.size());
|
Timber.d("Number of notifications is %d", notificationList.size());
|
||||||
if (notificationList.isEmpty()) {
|
if (notificationList.isEmpty()) {
|
||||||
|
|
|
||||||
|
|
@ -312,6 +312,10 @@ public class ContributionsListFragment extends CommonsDaggerSupportFragment impl
|
||||||
animateFAB(isFabOpen);
|
animateFAB(isFabOpen);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void scrollToTop() {
|
||||||
|
rvContributionsList.smoothScrollToPosition(0);
|
||||||
|
}
|
||||||
|
|
||||||
private void animateFAB(final boolean isFabOpen) {
|
private void animateFAB(final boolean isFabOpen) {
|
||||||
this.isFabOpen = !isFabOpen;
|
this.isFabOpen = !isFabOpen;
|
||||||
if (fabPlus.isShown()) {
|
if (fabPlus.isShown()) {
|
||||||
|
|
|
||||||
|
|
@ -163,7 +163,9 @@ public class MainActivity extends BaseActivity
|
||||||
//showBottom so that we do not show the bottom tray again when constructing
|
//showBottom so that we do not show the bottom tray again when constructing
|
||||||
//from the saved instance state.
|
//from the saved instance state.
|
||||||
if (fragment instanceof ContributionsFragment) {
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
contributionsFragment = (ContributionsFragment) fragment;
|
contributionsFragment = (ContributionsFragment) fragment;
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,7 @@ import org.junit.runner.RunWith
|
||||||
import org.mockito.ArgumentMatchers.*
|
import org.mockito.ArgumentMatchers.*
|
||||||
import org.mockito.Mock
|
import org.mockito.Mock
|
||||||
import org.mockito.Mockito.`when`
|
import org.mockito.Mockito.`when`
|
||||||
|
import org.mockito.Mockito.verify
|
||||||
import org.mockito.MockitoAnnotations
|
import org.mockito.MockitoAnnotations
|
||||||
import org.powermock.reflect.Whitebox
|
import org.powermock.reflect.Whitebox
|
||||||
import org.robolectric.Robolectric
|
import org.robolectric.Robolectric
|
||||||
|
|
@ -217,6 +218,14 @@ class ContributionsFragmentUnitTests {
|
||||||
fragment.updateLimitedConnectionToggle(menu)
|
fragment.updateLimitedConnectionToggle(menu)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Throws(Exception::class)
|
||||||
|
fun testScrollToTop(){
|
||||||
|
Shadows.shadowOf(Looper.getMainLooper()).idle()
|
||||||
|
fragment.scrollToTop()
|
||||||
|
verify(contributionsListFragment).scrollToTop()
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Throws(Exception::class)
|
@Throws(Exception::class)
|
||||||
fun testOnAttach() {
|
fun testOnAttach() {
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@ import org.junit.runner.RunWith
|
||||||
import org.mockito.ArgumentMatchers.anyInt
|
import org.mockito.ArgumentMatchers.anyInt
|
||||||
import org.mockito.Mock
|
import org.mockito.Mock
|
||||||
import org.mockito.Mockito.`when`
|
import org.mockito.Mockito.`when`
|
||||||
|
import org.mockito.Mockito.verify
|
||||||
import org.mockito.MockitoAnnotations
|
import org.mockito.MockitoAnnotations
|
||||||
import org.powermock.reflect.Whitebox
|
import org.powermock.reflect.Whitebox
|
||||||
import org.robolectric.Robolectric
|
import org.robolectric.Robolectric
|
||||||
|
|
@ -160,6 +161,14 @@ class ContributionsListFragmentUnitTests {
|
||||||
fragment.getContributionStateAt(0)
|
fragment.getContributionStateAt(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Throws(Exception::class)
|
||||||
|
fun testOnScrollToTop() {
|
||||||
|
Shadows.shadowOf(Looper.getMainLooper()).idle()
|
||||||
|
fragment.scrollToTop()
|
||||||
|
verify(rvContributionsList).smoothScrollToPosition(0)
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Throws(Exception::class)
|
@Throws(Exception::class)
|
||||||
fun testOnConfirmClicked() {
|
fun testOnConfirmClicked() {
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@ import org.junit.Test
|
||||||
import org.junit.runner.RunWith
|
import org.junit.runner.RunWith
|
||||||
import org.mockito.Mock
|
import org.mockito.Mock
|
||||||
import org.mockito.Mockito.`when`
|
import org.mockito.Mockito.`when`
|
||||||
|
import org.mockito.Mockito.verify
|
||||||
import org.mockito.MockitoAnnotations
|
import org.mockito.MockitoAnnotations
|
||||||
import org.powermock.api.mockito.PowerMockito
|
import org.powermock.api.mockito.PowerMockito
|
||||||
import org.robolectric.Robolectric
|
import org.robolectric.Robolectric
|
||||||
|
|
@ -243,6 +244,21 @@ class MainActivityUnitTests {
|
||||||
method.invoke(activity, contributionsFragment, false)
|
method.invoke(activity, contributionsFragment, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Throws(Exception::class)
|
||||||
|
fun testLoadFragmentCaseContributionsFragmentCaseTrue() {
|
||||||
|
activeFragment = ActiveFragment.CONTRIBUTIONS
|
||||||
|
activity.activeFragment = activeFragment
|
||||||
|
val method: Method = MainActivity::class.java.getDeclaredMethod(
|
||||||
|
"loadFragment",
|
||||||
|
Fragment::class.java,
|
||||||
|
Boolean::class.java
|
||||||
|
)
|
||||||
|
method.isAccessible = true
|
||||||
|
method.invoke(activity, contributionsFragment, false)
|
||||||
|
verify(contributionsFragment).scrollToTop();
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Throws(Exception::class)
|
@Throws(Exception::class)
|
||||||
fun testLoadFragmentCaseNearbyParentFragmentCaseTrue() {
|
fun testLoadFragmentCaseNearbyParentFragmentCaseTrue() {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue