|
@ -26,6 +26,7 @@ import gr.thmmy.mthmmy.base.BaseActivity; |
|
|
import gr.thmmy.mthmmy.model.Board; |
|
|
import gr.thmmy.mthmmy.model.Board; |
|
|
import gr.thmmy.mthmmy.model.ThmmyPage; |
|
|
import gr.thmmy.mthmmy.model.ThmmyPage; |
|
|
import gr.thmmy.mthmmy.model.TopicSummary; |
|
|
import gr.thmmy.mthmmy.model.TopicSummary; |
|
|
|
|
|
import timber.log.Timber; |
|
|
|
|
|
|
|
|
import static gr.thmmy.mthmmy.activities.board.BoardActivity.BUNDLE_BOARD_TITLE; |
|
|
import static gr.thmmy.mthmmy.activities.board.BoardActivity.BUNDLE_BOARD_TITLE; |
|
|
import static gr.thmmy.mthmmy.activities.board.BoardActivity.BUNDLE_BOARD_URL; |
|
|
import static gr.thmmy.mthmmy.activities.board.BoardActivity.BUNDLE_BOARD_URL; |
|
@ -39,7 +40,7 @@ import static gr.thmmy.mthmmy.activities.topic.TopicActivity.BUNDLE_TOPIC_URL; |
|
|
|
|
|
|
|
|
public class MainActivity extends BaseActivity implements RecentFragment.RecentFragmentInteractionListener, ForumFragment.ForumFragmentInteractionListener, UnreadFragment.UnreadFragmentInteractionListener { |
|
|
public class MainActivity extends BaseActivity implements RecentFragment.RecentFragmentInteractionListener, ForumFragment.ForumFragmentInteractionListener, UnreadFragment.UnreadFragmentInteractionListener { |
|
|
|
|
|
|
|
|
//-----------------------------------------CLASS VARIABLES------------------------------------------
|
|
|
//-----------------------------------------CLASS VARIABLES------------------------------------------
|
|
|
private static final int TIME_INTERVAL = 2000; |
|
|
private static final int TIME_INTERVAL = 2000; |
|
|
private long mBackPressed; |
|
|
private long mBackPressed; |
|
|
private SectionsPagerAdapter sectionsPagerAdapter; |
|
|
private SectionsPagerAdapter sectionsPagerAdapter; |
|
@ -52,8 +53,7 @@ public class MainActivity extends BaseActivity implements RecentFragment.RecentF |
|
|
redirectToActivityFromIntent(intentFilter); |
|
|
redirectToActivityFromIntent(intentFilter); |
|
|
setContentView(R.layout.activity_main); |
|
|
setContentView(R.layout.activity_main); |
|
|
|
|
|
|
|
|
if (sessionManager.isLoginScreenDefault()) |
|
|
if (sessionManager.isLoginScreenDefault()) { |
|
|
{ |
|
|
|
|
|
//Go to login
|
|
|
//Go to login
|
|
|
Intent intent = new Intent(MainActivity.this, LoginActivity.class); |
|
|
Intent intent = new Intent(MainActivity.this, LoginActivity.class); |
|
|
startActivity(intent); |
|
|
startActivity(intent); |
|
@ -68,7 +68,7 @@ public class MainActivity extends BaseActivity implements RecentFragment.RecentF |
|
|
sectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager()); |
|
|
sectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager()); |
|
|
sectionsPagerAdapter.addFragment(RecentFragment.newInstance(1), "RECENT"); |
|
|
sectionsPagerAdapter.addFragment(RecentFragment.newInstance(1), "RECENT"); |
|
|
sectionsPagerAdapter.addFragment(ForumFragment.newInstance(2), "FORUM"); |
|
|
sectionsPagerAdapter.addFragment(ForumFragment.newInstance(2), "FORUM"); |
|
|
if(sessionManager.isLoggedIn()) |
|
|
if (sessionManager.isLoggedIn()) |
|
|
sectionsPagerAdapter.addFragment(UnreadFragment.newInstance(3), "UNREAD"); |
|
|
sectionsPagerAdapter.addFragment(UnreadFragment.newInstance(3), "UNREAD"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -129,13 +129,13 @@ public class MainActivity extends BaseActivity implements RecentFragment.RecentF |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public void onUnreadFragmentInteraction(TopicSummary topicSummary) { |
|
|
public void onUnreadFragmentInteraction(TopicSummary topicSummary) { |
|
|
if (topicSummary.getLastUser() == null && topicSummary.getDateTimeModified() == null) { |
|
|
if (topicSummary.getTopicUrl() != null) { |
|
|
return; //TODO!
|
|
|
Intent i = new Intent(MainActivity.this, TopicActivity.class); |
|
|
} |
|
|
i.putExtra(BUNDLE_TOPIC_URL, topicSummary.getTopicUrl()); |
|
|
Intent i = new Intent(MainActivity.this, TopicActivity.class); |
|
|
i.putExtra(BUNDLE_TOPIC_TITLE, topicSummary.getSubject()); |
|
|
i.putExtra(BUNDLE_TOPIC_URL, topicSummary.getTopicUrl()); |
|
|
startActivity(i); |
|
|
i.putExtra(BUNDLE_TOPIC_TITLE, topicSummary.getSubject()); |
|
|
} else |
|
|
startActivity(i); |
|
|
Timber.e("onUnreadFragmentInteraction TopicSummary came without a link"); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//---------------------------------FragmentPagerAdapter---------------------------------------------
|
|
|
//---------------------------------FragmentPagerAdapter---------------------------------------------
|
|
@ -164,8 +164,8 @@ public class MainActivity extends BaseActivity implements RecentFragment.RecentF |
|
|
fragmentList.remove(position); |
|
|
fragmentList.remove(position); |
|
|
fragmentTitleList.remove(position); |
|
|
fragmentTitleList.remove(position); |
|
|
notifyDataSetChanged(); |
|
|
notifyDataSetChanged(); |
|
|
if(viewPager.getCurrentItem()==position) |
|
|
if (viewPager.getCurrentItem() == position) |
|
|
viewPager.setCurrentItem(position-1); |
|
|
viewPager.setCurrentItem(position - 1); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
@ -185,16 +185,16 @@ public class MainActivity extends BaseActivity implements RecentFragment.RecentF |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public int getItemPosition(Object object) { |
|
|
public int getItemPosition(Object object) { |
|
|
int position = fragmentList.indexOf(object); |
|
|
@SuppressWarnings("RedundantCast") |
|
|
|
|
|
int position = fragmentList.indexOf((Fragment) object); |
|
|
return position == -1 ? POSITION_NONE : position; |
|
|
return position == -1 ? POSITION_NONE : position; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public void updateTabs() |
|
|
public void updateTabs() { |
|
|
{ |
|
|
if (!sessionManager.isLoggedIn() && sectionsPagerAdapter.getCount() == 3) |
|
|
if(!sessionManager.isLoggedIn()&§ionsPagerAdapter.getCount()==3) |
|
|
|
|
|
sectionsPagerAdapter.removeFragment(2); |
|
|
sectionsPagerAdapter.removeFragment(2); |
|
|
else if(sessionManager.isLoggedIn()&§ionsPagerAdapter.getCount()==2) |
|
|
else if (sessionManager.isLoggedIn() && sectionsPagerAdapter.getCount() == 2) |
|
|
sectionsPagerAdapter.addFragment(UnreadFragment.newInstance(3), "UNREAD"); |
|
|
sectionsPagerAdapter.addFragment(UnreadFragment.newInstance(3), "UNREAD"); |
|
|
} |
|
|
} |
|
|
//-------------------------------FragmentPagerAdapter END-------------------------------------------
|
|
|
//-------------------------------FragmentPagerAdapter END-------------------------------------------
|
|
|