|
@ -9,7 +9,6 @@ import android.os.Bundle; |
|
|
import android.support.v7.app.AppCompatActivity; |
|
|
import android.support.v7.app.AppCompatActivity; |
|
|
import android.support.v7.widget.Toolbar; |
|
|
import android.support.v7.widget.Toolbar; |
|
|
import android.util.Log; |
|
|
import android.util.Log; |
|
|
import android.view.MenuItem; |
|
|
|
|
|
import android.view.View; |
|
|
import android.view.View; |
|
|
import android.widget.Toast; |
|
|
import android.widget.Toast; |
|
|
|
|
|
|
|
@ -24,6 +23,7 @@ import com.mikepenz.materialdrawer.model.PrimaryDrawerItem; |
|
|
import com.mikepenz.materialdrawer.model.interfaces.IDrawerItem; |
|
|
import com.mikepenz.materialdrawer.model.interfaces.IDrawerItem; |
|
|
|
|
|
|
|
|
import gr.thmmy.mthmmy.R; |
|
|
import gr.thmmy.mthmmy.R; |
|
|
|
|
|
import gr.thmmy.mthmmy.activities.main.MainActivity; |
|
|
import gr.thmmy.mthmmy.session.SessionManager; |
|
|
import gr.thmmy.mthmmy.session.SessionManager; |
|
|
import okhttp3.OkHttpClient; |
|
|
import okhttp3.OkHttpClient; |
|
|
|
|
|
|
|
@ -74,16 +74,21 @@ public class BaseActivity extends AppCompatActivity |
|
|
//TODO: move stuff below
|
|
|
//TODO: move stuff below
|
|
|
//------------------------------------------DRAWER STUFF----------------------------------------
|
|
|
//------------------------------------------DRAWER STUFF----------------------------------------
|
|
|
|
|
|
|
|
|
private static final int LOGINLOGOUT_ID=0; |
|
|
protected static final int HOME_ID=0; |
|
|
private static final int ABOUT_ID=1; |
|
|
protected static final int LOG_ID =1; |
|
|
|
|
|
protected static final int ABOUT_ID=2; |
|
|
|
|
|
|
|
|
protected PrimaryDrawerItem loginLogout, about; |
|
|
protected PrimaryDrawerItem home,loginLogout, about; |
|
|
protected IconicsDrawable loginIcon,logoutIcon, aboutIcon; |
|
|
protected IconicsDrawable homeIcon,loginIcon,logoutIcon, aboutIcon; |
|
|
/** |
|
|
/** |
|
|
* Call only after initializing Toolbar |
|
|
* Call only after initializing Toolbar |
|
|
*/ |
|
|
*/ |
|
|
protected void createDrawer()//TODO
|
|
|
protected void createDrawer()//TODO
|
|
|
{ |
|
|
{ |
|
|
|
|
|
homeIcon =new IconicsDrawable(this) |
|
|
|
|
|
.icon(FontAwesome.Icon.faw_home) |
|
|
|
|
|
.color(Color.BLACK) |
|
|
|
|
|
.sizeDp(24); |
|
|
loginIcon =new IconicsDrawable(this) |
|
|
loginIcon =new IconicsDrawable(this) |
|
|
.icon(FontAwesome.Icon.faw_sign_in) |
|
|
.icon(FontAwesome.Icon.faw_sign_in) |
|
|
.color(Color.BLACK) |
|
|
.color(Color.BLACK) |
|
@ -92,19 +97,28 @@ public class BaseActivity extends AppCompatActivity |
|
|
.icon(FontAwesome.Icon.faw_sign_out) |
|
|
.icon(FontAwesome.Icon.faw_sign_out) |
|
|
.color(Color.BLACK) |
|
|
.color(Color.BLACK) |
|
|
.sizeDp(24); |
|
|
.sizeDp(24); |
|
|
loginLogout = new PrimaryDrawerItem().withIdentifier(LOGINLOGOUT_ID).withName(R.string.logout).withIcon(logoutIcon); |
|
|
|
|
|
aboutIcon =new IconicsDrawable(this) |
|
|
aboutIcon =new IconicsDrawable(this) |
|
|
.icon(FontAwesome.Icon.faw_info_circle) |
|
|
.icon(FontAwesome.Icon.faw_info_circle) |
|
|
.color(Color.BLACK) |
|
|
.color(Color.BLACK) |
|
|
.sizeDp(24); |
|
|
.sizeDp(24); |
|
|
|
|
|
home = new PrimaryDrawerItem().withIdentifier(HOME_ID).withName(R.string.home).withIcon(homeIcon); |
|
|
|
|
|
loginLogout = new PrimaryDrawerItem().withIdentifier(LOG_ID).withName(R.string.logout).withIcon(logoutIcon); |
|
|
about = new PrimaryDrawerItem().withIdentifier(ABOUT_ID).withName(R.string.about).withIcon(aboutIcon); |
|
|
about = new PrimaryDrawerItem().withIdentifier(ABOUT_ID).withName(R.string.about).withIcon(aboutIcon); |
|
|
drawer = new DrawerBuilder().withActivity(BaseActivity.this) |
|
|
drawer = new DrawerBuilder().withActivity(this) |
|
|
.withToolbar(toolbar) |
|
|
.withToolbar(toolbar) |
|
|
.addDrawerItems(loginLogout,about) |
|
|
.addDrawerItems(home,loginLogout,about) |
|
|
.withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() { |
|
|
.withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() { |
|
|
@Override |
|
|
@Override |
|
|
public boolean onItemClick(View view, int position, IDrawerItem drawerItem) { |
|
|
public boolean onItemClick(View view, int position, IDrawerItem drawerItem) { |
|
|
if(drawerItem.equals(LOGINLOGOUT_ID)) |
|
|
if(drawerItem.equals(HOME_ID)) |
|
|
|
|
|
{ |
|
|
|
|
|
if(!(BaseActivity.this instanceof MainActivity)) |
|
|
|
|
|
{ |
|
|
|
|
|
Intent i = new Intent(BaseActivity.this, MainActivity.class); |
|
|
|
|
|
startActivity(i); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
else if(drawerItem.equals(LOG_ID)) |
|
|
{ |
|
|
{ |
|
|
if (sessionManager.getLogStatus()!= LOGGED_IN) //When logged out or if user is guest
|
|
|
if (sessionManager.getLogStatus()!= LOGGED_IN) //When logged out or if user is guest
|
|
|
{ |
|
|
{ |
|
@ -112,22 +126,24 @@ public class BaseActivity extends AppCompatActivity |
|
|
startActivity(intent); |
|
|
startActivity(intent); |
|
|
finish(); |
|
|
finish(); |
|
|
overridePendingTransition(R.anim.push_right_in, R.anim.push_right_out); |
|
|
overridePendingTransition(R.anim.push_right_in, R.anim.push_right_out); |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
else |
|
|
else |
|
|
new LogoutTask().execute(); |
|
|
new LogoutTask().execute(); |
|
|
} |
|
|
} |
|
|
else if(drawerItem.equals(ABOUT_ID)) |
|
|
else if(drawerItem.equals(ABOUT_ID)) |
|
|
|
|
|
{ |
|
|
|
|
|
if(!(BaseActivity.this instanceof AboutActivity)) |
|
|
{ |
|
|
{ |
|
|
Intent i = new Intent(BaseActivity.this, AboutActivity.class); |
|
|
Intent i = new Intent(BaseActivity.this, AboutActivity.class); |
|
|
startActivity(i); |
|
|
startActivity(i); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
drawer.closeDrawer(); |
|
|
drawer.closeDrawer(); |
|
|
return true; |
|
|
return true; |
|
|
} |
|
|
} |
|
|
}) |
|
|
}) |
|
|
.build(); |
|
|
.build(); |
|
|
drawer.setSelection(-1); |
|
|
|
|
|
|
|
|
|
|
|
drawer.getActionBarDrawerToggle().setDrawerIndicatorEnabled(false); |
|
|
drawer.getActionBarDrawerToggle().setDrawerIndicatorEnabled(false); |
|
|
drawer.setOnDrawerNavigationListener(new Drawer.OnDrawerNavigationListener() { |
|
|
drawer.setOnDrawerNavigationListener(new Drawer.OnDrawerNavigationListener() { |
|
|