diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/AboutActivity.java b/app/src/main/java/gr/thmmy/mthmmy/activities/AboutActivity.java index 426c2dad..332bae19 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/AboutActivity.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/AboutActivity.java @@ -24,6 +24,7 @@ public class AboutActivity extends BaseActivity getSupportActionBar().setDisplayShowHomeEnabled(true); createDrawer(); + drawer.setSelection(ABOUT_ID); TextView tv = (TextView) findViewById(R.id.version); @@ -32,4 +33,10 @@ public class AboutActivity extends BaseActivity //TODO: add licenses } + + @Override + protected void onResume() { + super.onResume(); + drawer.setSelection(ABOUT_ID); + } } diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/BaseActivity.java b/app/src/main/java/gr/thmmy/mthmmy/activities/BaseActivity.java index b3cc4176..ae74707f 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/BaseActivity.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/BaseActivity.java @@ -9,7 +9,6 @@ import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; import android.util.Log; -import android.view.MenuItem; import android.view.View; import android.widget.Toast; @@ -24,6 +23,7 @@ import com.mikepenz.materialdrawer.model.PrimaryDrawerItem; import com.mikepenz.materialdrawer.model.interfaces.IDrawerItem; import gr.thmmy.mthmmy.R; +import gr.thmmy.mthmmy.activities.main.MainActivity; import gr.thmmy.mthmmy.session.SessionManager; import okhttp3.OkHttpClient; @@ -74,16 +74,21 @@ public class BaseActivity extends AppCompatActivity //TODO: move stuff below //------------------------------------------DRAWER STUFF---------------------------------------- - private static final int LOGINLOGOUT_ID=0; - private static final int ABOUT_ID=1; + protected static final int HOME_ID=0; + protected static final int LOG_ID =1; + protected static final int ABOUT_ID=2; - protected PrimaryDrawerItem loginLogout, about; - protected IconicsDrawable loginIcon,logoutIcon, aboutIcon; + protected PrimaryDrawerItem home,loginLogout, about; + protected IconicsDrawable homeIcon,loginIcon,logoutIcon, aboutIcon; /** * Call only after initializing Toolbar */ protected void createDrawer()//TODO { + homeIcon =new IconicsDrawable(this) + .icon(FontAwesome.Icon.faw_home) + .color(Color.BLACK) + .sizeDp(24); loginIcon =new IconicsDrawable(this) .icon(FontAwesome.Icon.faw_sign_in) .color(Color.BLACK) @@ -92,19 +97,28 @@ public class BaseActivity extends AppCompatActivity .icon(FontAwesome.Icon.faw_sign_out) .color(Color.BLACK) .sizeDp(24); - loginLogout = new PrimaryDrawerItem().withIdentifier(LOGINLOGOUT_ID).withName(R.string.logout).withIcon(logoutIcon); aboutIcon =new IconicsDrawable(this) .icon(FontAwesome.Icon.faw_info_circle) .color(Color.BLACK) .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); - drawer = new DrawerBuilder().withActivity(BaseActivity.this) + drawer = new DrawerBuilder().withActivity(this) .withToolbar(toolbar) - .addDrawerItems(loginLogout,about) + .addDrawerItems(home,loginLogout,about) .withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() { @Override 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 { @@ -112,22 +126,24 @@ public class BaseActivity extends AppCompatActivity startActivity(intent); finish(); overridePendingTransition(R.anim.push_right_in, R.anim.push_right_out); - } else new LogoutTask().execute(); } else if(drawerItem.equals(ABOUT_ID)) { - Intent i = new Intent(BaseActivity.this, AboutActivity.class); - startActivity(i); + if(!(BaseActivity.this instanceof AboutActivity)) + { + Intent i = new Intent(BaseActivity.this, AboutActivity.class); + startActivity(i); + } + } drawer.closeDrawer(); return true; } }) .build(); - drawer.setSelection(-1); drawer.getActionBarDrawerToggle().setDrawerIndicatorEnabled(false); drawer.setOnDrawerNavigationListener(new Drawer.OnDrawerNavigationListener() { diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/main/MainActivity.java b/app/src/main/java/gr/thmmy/mthmmy/activities/main/MainActivity.java index 909cb942..e7ea4ed2 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/main/MainActivity.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/main/MainActivity.java @@ -61,6 +61,7 @@ public class MainActivity extends BaseActivity implements RecentFragment.OnListF @Override protected void onResume() { super.onResume(); + drawer.setSelection(HOME_ID); updateDrawer(); } diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicActivity.java b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicActivity.java index d71dadca..3bbcecb4 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicActivity.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicActivity.java @@ -191,6 +191,12 @@ public class TopicActivity extends BaseActivity { super.onBackPressed(); } + @Override + protected void onResume() { + super.onResume(); + drawer.setSelection(-1); + } + @Override protected void onDestroy() { //When finished cancel whatever request can still be canceled super.onDestroy(); diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 1559972f..9d41cfac 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -21,4 +21,5 @@ Page next last + Home