|
|
@ -10,6 +10,9 @@ import android.support.v4.app.FragmentPagerAdapter; |
|
|
|
import android.support.v4.view.ViewPager; |
|
|
|
import android.widget.Toast; |
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
import gr.thmmy.mthmmy.R; |
|
|
|
import gr.thmmy.mthmmy.activities.LoginActivity; |
|
|
|
import gr.thmmy.mthmmy.activities.board.BoardActivity; |
|
|
@ -39,6 +42,8 @@ public class MainActivity extends BaseActivity implements RecentFragment.RecentF |
|
|
|
//-----------------------------------------CLASS VARIABLES------------------------------------------
|
|
|
|
private static final int TIME_INTERVAL = 2000; |
|
|
|
private long mBackPressed; |
|
|
|
private SectionsPagerAdapter sectionsPagerAdapter; |
|
|
|
private ViewPager viewPager; |
|
|
|
|
|
|
|
@Override |
|
|
|
protected void onCreate(Bundle savedInstanceState) { |
|
|
@ -48,7 +53,6 @@ public class MainActivity extends BaseActivity implements RecentFragment.RecentF |
|
|
|
setContentView(R.layout.activity_main); |
|
|
|
|
|
|
|
if (sessionManager.isLoginScreenDefault()) |
|
|
|
|
|
|
|
{ |
|
|
|
//Go to login
|
|
|
|
Intent intent = new Intent(MainActivity.this, LoginActivity.class); |
|
|
@ -61,14 +65,21 @@ public class MainActivity extends BaseActivity implements RecentFragment.RecentF |
|
|
|
createDrawer(); |
|
|
|
|
|
|
|
//Create the adapter that will return a fragment for each section of the activity
|
|
|
|
SectionsPagerAdapter mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager()); |
|
|
|
sectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager()); |
|
|
|
sectionsPagerAdapter.addFragment(RecentFragment.newInstance(1), "RECENT"); |
|
|
|
sectionsPagerAdapter.addFragment(ForumFragment.newInstance(2), "FORUM"); |
|
|
|
if(sessionManager.isLoggedIn()) |
|
|
|
sectionsPagerAdapter.addFragment(UnreadFragment.newInstance(3), "UNREAD"); |
|
|
|
|
|
|
|
|
|
|
|
//Set up the ViewPager with the sections adapter.
|
|
|
|
ViewPager mViewPager = (ViewPager) findViewById(R.id.container); |
|
|
|
mViewPager.setAdapter(mSectionsPagerAdapter); |
|
|
|
viewPager = (ViewPager) findViewById(R.id.container); |
|
|
|
viewPager.setAdapter(sectionsPagerAdapter); |
|
|
|
|
|
|
|
TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs); |
|
|
|
tabLayout.setupWithViewPager(mViewPager); |
|
|
|
tabLayout.setupWithViewPager(viewPager); |
|
|
|
|
|
|
|
setMainActivity(this); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
@ -81,6 +92,7 @@ public class MainActivity extends BaseActivity implements RecentFragment.RecentF |
|
|
|
@Override |
|
|
|
protected void onResume() { |
|
|
|
drawer.setSelection(HOME_ID); |
|
|
|
updateTabs(); |
|
|
|
super.onResume(); |
|
|
|
} |
|
|
|
|
|
|
@ -135,45 +147,56 @@ public class MainActivity extends BaseActivity implements RecentFragment.RecentF |
|
|
|
* {@link android.support.v4.app.FragmentStatePagerAdapter}. |
|
|
|
*/ |
|
|
|
private class SectionsPagerAdapter extends FragmentPagerAdapter { |
|
|
|
private final List<Fragment> fragmentList = new ArrayList<>(); |
|
|
|
private final List<String> fragmentTitleList = new ArrayList<>(); |
|
|
|
|
|
|
|
SectionsPagerAdapter(FragmentManager fm) { |
|
|
|
super(fm); |
|
|
|
} |
|
|
|
|
|
|
|
void addFragment(Fragment fragment, String title) { |
|
|
|
fragmentList.add(fragment); |
|
|
|
fragmentTitleList.add(title); |
|
|
|
notifyDataSetChanged(); |
|
|
|
} |
|
|
|
|
|
|
|
void removeFragment(int position) { |
|
|
|
fragmentList.remove(position); |
|
|
|
fragmentTitleList.remove(position); |
|
|
|
notifyDataSetChanged(); |
|
|
|
if(viewPager.getCurrentItem()==position) |
|
|
|
viewPager.setCurrentItem(position-1); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public Fragment getItem(int position) { |
|
|
|
switch (position) { |
|
|
|
case 0: |
|
|
|
return RecentFragment.newInstance(position + 1); |
|
|
|
case 1: |
|
|
|
return ForumFragment.newInstance(position + 1); |
|
|
|
case 2: |
|
|
|
return UnreadFragment.newInstance(position + 1); |
|
|
|
default: |
|
|
|
return RecentFragment.newInstance(position + 1); //temp (?)
|
|
|
|
} |
|
|
|
return fragmentList.get(position); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public int getCount() { |
|
|
|
// Show 3 total pages.
|
|
|
|
return 3; |
|
|
|
return fragmentList.size(); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public CharSequence getPageTitle(int position) { |
|
|
|
switch (position) { |
|
|
|
case 0: |
|
|
|
return "RECENT"; |
|
|
|
case 1: |
|
|
|
return "FORUM"; |
|
|
|
case 2: |
|
|
|
return "UNREAD"; |
|
|
|
} |
|
|
|
return fragmentTitleList.get(position); |
|
|
|
} |
|
|
|
|
|
|
|
return null; |
|
|
|
@Override |
|
|
|
public int getItemPosition(Object object) { |
|
|
|
int position = fragmentList.indexOf(object); |
|
|
|
return position == -1 ? POSITION_NONE : position; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public void updateTabs() |
|
|
|
{ |
|
|
|
if(!sessionManager.isLoggedIn()&§ionsPagerAdapter.getCount()==3) |
|
|
|
sectionsPagerAdapter.removeFragment(2); |
|
|
|
else if(sessionManager.isLoggedIn()&§ionsPagerAdapter.getCount()==2) |
|
|
|
sectionsPagerAdapter.addFragment(UnreadFragment.newInstance(3), "UNREAD"); |
|
|
|
} |
|
|
|
//-------------------------------FragmentPagerAdapter END-------------------------------------------
|
|
|
|
|
|
|
|
private void redirectToActivityFromIntent(Intent intent) { |
|
|
|