|
@ -1,8 +1,6 @@ |
|
|
package gr.thmmy.mthmmy.activities; |
|
|
package gr.thmmy.mthmmy.activities; |
|
|
|
|
|
|
|
|
import android.app.ProgressDialog; |
|
|
|
|
|
import android.content.Intent; |
|
|
import android.content.Intent; |
|
|
import android.os.AsyncTask; |
|
|
|
|
|
import android.os.Bundle; |
|
|
import android.os.Bundle; |
|
|
import android.support.design.widget.TabLayout; |
|
|
import android.support.design.widget.TabLayout; |
|
|
import android.support.v4.app.Fragment; |
|
|
import android.support.v4.app.Fragment; |
|
@ -10,23 +8,18 @@ import android.support.v4.app.FragmentManager; |
|
|
import android.support.v4.app.FragmentPagerAdapter; |
|
|
import android.support.v4.app.FragmentPagerAdapter; |
|
|
import android.support.v4.view.ViewPager; |
|
|
import android.support.v4.view.ViewPager; |
|
|
import android.support.v7.widget.Toolbar; |
|
|
import android.support.v7.widget.Toolbar; |
|
|
import android.view.Menu; |
|
|
|
|
|
import android.view.MenuItem; |
|
|
|
|
|
import android.widget.Toast; |
|
|
|
|
|
|
|
|
|
|
|
import gr.thmmy.mthmmy.R; |
|
|
import gr.thmmy.mthmmy.R; |
|
|
import gr.thmmy.mthmmy.data.TopicSummary; |
|
|
import gr.thmmy.mthmmy.data.TopicSummary; |
|
|
import gr.thmmy.mthmmy.sections.forum.ForumFragment; |
|
|
import gr.thmmy.mthmmy.sections.forum.ForumFragment; |
|
|
import gr.thmmy.mthmmy.sections.recent.RecentFragment; |
|
|
import gr.thmmy.mthmmy.sections.recent.RecentFragment; |
|
|
|
|
|
|
|
|
import static gr.thmmy.mthmmy.session.SessionManager.LOGGED_IN; |
|
|
|
|
|
import static gr.thmmy.mthmmy.session.SessionManager.LOGGED_OUT; |
|
|
import static gr.thmmy.mthmmy.session.SessionManager.LOGGED_OUT; |
|
|
|
|
|
|
|
|
public class MainActivity extends BaseActivity implements RecentFragment.OnListFragmentInteractionListener, ForumFragment.OnListFragmentInteractionListener { |
|
|
public class MainActivity extends BaseActivity implements RecentFragment.OnListFragmentInteractionListener, ForumFragment.OnListFragmentInteractionListener { |
|
|
|
|
|
|
|
|
//----------------------------------------CLASS VARIABLES-----------------------------------------
|
|
|
//----------------------------------------CLASS VARIABLES-----------------------------------------
|
|
|
private static final String TAG = "MainActivity"; |
|
|
private static final String TAG = "MainActivity"; |
|
|
private Menu menu; |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
protected void onCreate(Bundle savedInstanceState) { |
|
|
protected void onCreate(Bundle savedInstanceState) { |
|
@ -42,9 +35,12 @@ public class MainActivity extends BaseActivity implements RecentFragment.OnListF |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//Initialize toolbar
|
|
|
//Initialize toolbar
|
|
|
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); |
|
|
toolbar = (Toolbar) findViewById(R.id.toolbar); |
|
|
setSupportActionBar(toolbar); |
|
|
setSupportActionBar(toolbar); |
|
|
|
|
|
|
|
|
|
|
|
//Initialize drawer
|
|
|
|
|
|
createDrawer(); |
|
|
|
|
|
|
|
|
//Create the adapter that will return a fragment for each section of the activity
|
|
|
//Create the adapter that will return a fragment for each section of the activity
|
|
|
SectionsPagerAdapter mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager()); |
|
|
SectionsPagerAdapter mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager()); |
|
|
|
|
|
|
|
@ -54,66 +50,17 @@ public class MainActivity extends BaseActivity implements RecentFragment.OnListF |
|
|
|
|
|
|
|
|
TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs); |
|
|
TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs); |
|
|
tabLayout.setupWithViewPager(mViewPager); |
|
|
tabLayout.setupWithViewPager(mViewPager); |
|
|
|
|
|
|
|
|
//TODO: Drawer
|
|
|
|
|
|
// new DrawerBuilder().withActivity(this)
|
|
|
|
|
|
// .withToolbar(toolbar)
|
|
|
|
|
|
// .build();
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public boolean onCreateOptionsMenu(Menu menu) { |
|
|
protected void onResume() { |
|
|
//Inflate the menu; this adds items to the action bar if it is present.
|
|
|
super.onResume(); |
|
|
this.menu = menu; |
|
|
updateDrawer(); |
|
|
getMenuInflater().inflate(R.menu.menu_main, menu); |
|
|
|
|
|
|
|
|
|
|
|
if (sessionManager.getLogStatus()!= LOGGED_IN) //When logged out or if user is guest
|
|
|
|
|
|
hideLogout(); |
|
|
|
|
|
else |
|
|
|
|
|
hideLogin(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
public boolean onOptionsItemSelected(MenuItem item) { |
|
|
|
|
|
int id = item.getItemId(); |
|
|
|
|
|
|
|
|
|
|
|
if (id == R.id.action_about) { |
|
|
|
|
|
//Go to about
|
|
|
|
|
|
Intent i = new Intent(MainActivity.this, AboutActivity.class); |
|
|
|
|
|
startActivity(i); |
|
|
|
|
|
return true; |
|
|
|
|
|
} else if (id == R.id.action_logout) |
|
|
|
|
|
//Attempt logout
|
|
|
|
|
|
new LogoutTask().execute(); |
|
|
|
|
|
else { |
|
|
|
|
|
//Go to login
|
|
|
|
|
|
Intent intent = new Intent(MainActivity.this, LoginActivity.class); |
|
|
|
|
|
startActivity(intent); |
|
|
|
|
|
finish(); |
|
|
|
|
|
overridePendingTransition(R.anim.push_right_in, R.anim.push_right_out); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return super.onOptionsItemSelected(item); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void hideLogin() { //Hide login AND show logout
|
|
|
|
|
|
MenuItem login = menu.findItem(R.id.action_login); |
|
|
|
|
|
MenuItem logout = menu.findItem(R.id.action_logout); |
|
|
|
|
|
login.setVisible(false); |
|
|
|
|
|
logout.setVisible(true); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void hideLogout() { //Hide logout AND show login
|
|
|
|
|
|
MenuItem login = menu.findItem(R.id.action_login); |
|
|
|
|
|
MenuItem logout = menu.findItem(R.id.action_logout); |
|
|
|
|
|
login.setVisible(true); |
|
|
|
|
|
logout.setVisible(false); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public void onFragmentInteraction(TopicSummary topicSummary) { |
|
|
public void onFragmentInteraction(TopicSummary topicSummary) { |
|
@ -166,34 +113,4 @@ public class MainActivity extends BaseActivity implements RecentFragment.OnListF |
|
|
} |
|
|
} |
|
|
//-------------------------------FragmentPagerAdapter END-------------------------------------------
|
|
|
//-------------------------------FragmentPagerAdapter END-------------------------------------------
|
|
|
|
|
|
|
|
|
//-------------------------------------------LOGOUT-------------------------------------------------
|
|
|
|
|
|
/** |
|
|
|
|
|
* Result toast will always display a success, because when user chooses logout all data are |
|
|
|
|
|
* cleared regardless of the actual outcome |
|
|
|
|
|
*/ |
|
|
|
|
|
private class LogoutTask extends AsyncTask<Void, Void, Integer> { //Attempt logout
|
|
|
|
|
|
ProgressDialog progressDialog; |
|
|
|
|
|
|
|
|
|
|
|
protected Integer doInBackground(Void... voids) { |
|
|
|
|
|
return sessionManager.logout(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected void onPreExecute() |
|
|
|
|
|
{ //Show a progress dialog until done
|
|
|
|
|
|
progressDialog = new ProgressDialog(MainActivity.this, |
|
|
|
|
|
R.style.AppTheme_Dark_Dialog); |
|
|
|
|
|
progressDialog.setCancelable(false); |
|
|
|
|
|
progressDialog.setIndeterminate(true); |
|
|
|
|
|
progressDialog.setMessage("Logging out..."); |
|
|
|
|
|
progressDialog.show(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected void onPostExecute(Integer result) |
|
|
|
|
|
{ |
|
|
|
|
|
Toast.makeText(getBaseContext(), "Logged out successfully!", Toast.LENGTH_LONG).show(); |
|
|
|
|
|
hideLogout(); |
|
|
|
|
|
progressDialog.dismiss(); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
//-----------------------------------------LOGOUT END-----------------------------------------------
|
|
|
|
|
|
} |
|
|
} |