Go back to top when same tab is pressed
This commit is contained in:
parent
82d9deff6c
commit
501f889bb2
|
@ -109,6 +109,7 @@ public class MainActivity extends AppCompatActivity
|
||||||
private ViewPager viewPager;
|
private ViewPager viewPager;
|
||||||
private RelativeLayout main_app_container;
|
private RelativeLayout main_app_container;
|
||||||
private Stack<Integer> stackBack = new Stack<>();
|
private Stack<Integer> stackBack = new Stack<>();
|
||||||
|
|
||||||
public MainActivity() {
|
public MainActivity() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -145,8 +146,9 @@ public class MainActivity extends AppCompatActivity
|
||||||
tabLayout = (TabLayout) findViewById(R.id.tabLayout);
|
tabLayout = (TabLayout) findViewById(R.id.tabLayout);
|
||||||
viewPager = (ViewPager) findViewById(R.id.viewpager);
|
viewPager = (ViewPager) findViewById(R.id.viewpager);
|
||||||
main_app_container = (RelativeLayout) findViewById(R.id.main_app_container);
|
main_app_container = (RelativeLayout) findViewById(R.id.main_app_container);
|
||||||
viewPager.setAdapter(new PagerAdapter
|
PagerAdapter adapter = new PagerAdapter
|
||||||
(getSupportFragmentManager(), tabLayout.getTabCount()));
|
(getSupportFragmentManager(), tabLayout.getTabCount());
|
||||||
|
viewPager.setAdapter(adapter);
|
||||||
viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
|
viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
|
||||||
tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
|
tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -216,7 +218,21 @@ public class MainActivity extends AppCompatActivity
|
||||||
toot.setVisibility(View.VISIBLE);
|
toot.setVisibility(View.VISIBLE);
|
||||||
else
|
else
|
||||||
toot.setVisibility(View.GONE);
|
toot.setVisibility(View.GONE);
|
||||||
|
Fragment fragment = (Fragment) viewPager.getAdapter().instantiateItem(viewPager, tab.getPosition());
|
||||||
|
switch (tab.getPosition()){
|
||||||
|
case 0:
|
||||||
|
case 2:
|
||||||
|
case 3:
|
||||||
|
DisplayStatusFragment displayStatusFragment = ((DisplayStatusFragment) fragment);
|
||||||
|
if( displayStatusFragment != null )
|
||||||
|
displayStatusFragment.scrollToTop();
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
DisplayNotificationsFragment displayNotificationsFragment = ((DisplayNotificationsFragment) fragment);
|
||||||
|
if( displayNotificationsFragment != null )
|
||||||
|
displayNotificationsFragment.scrollToTop();
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
for(int i = 0 ; i < 4 ; i++)
|
for(int i = 0 ; i < 4 ; i++)
|
||||||
|
@ -787,20 +803,18 @@ public class MainActivity extends AppCompatActivity
|
||||||
statusFragment.setArguments(bundle);
|
statusFragment.setArguments(bundle);
|
||||||
return statusFragment;
|
return statusFragment;
|
||||||
case 1:
|
case 1:
|
||||||
|
toot.setVisibility(View.GONE);
|
||||||
return new DisplayNotificationsFragment();
|
return new DisplayNotificationsFragment();
|
||||||
|
|
||||||
case 2:
|
case 2:
|
||||||
statusFragment = new DisplayStatusFragment();
|
statusFragment = new DisplayStatusFragment();
|
||||||
bundle.putSerializable("type", RetrieveFeedsAsyncTask.Type.LOCAL);
|
bundle.putSerializable("type", RetrieveFeedsAsyncTask.Type.LOCAL);
|
||||||
statusFragment.setArguments(bundle);
|
statusFragment.setArguments(bundle);
|
||||||
return statusFragment;
|
return statusFragment;
|
||||||
|
|
||||||
case 3:
|
case 3:
|
||||||
statusFragment = new DisplayStatusFragment();
|
statusFragment = new DisplayStatusFragment();
|
||||||
bundle.putSerializable("type", RetrieveFeedsAsyncTask.Type.PUBLIC);
|
bundle.putSerializable("type", RetrieveFeedsAsyncTask.Type.PUBLIC);
|
||||||
statusFragment.setArguments(bundle);
|
statusFragment.setArguments(bundle);
|
||||||
return statusFragment;
|
return statusFragment;
|
||||||
|
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -202,4 +202,9 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve
|
||||||
}
|
}
|
||||||
firstLoad = false;
|
firstLoad = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void scrollToTop(){
|
||||||
|
if( lv_notifications != null)
|
||||||
|
lv_notifications.setAdapter(notificationsListAdapter);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -308,4 +308,9 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
|
||||||
firstLoad = false;
|
firstLoad = false;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void scrollToTop(){
|
||||||
|
if( lv_status != null)
|
||||||
|
lv_status.setAdapter(statusListAdapter);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue