Browse Source

Drawer improvements

pull/24/head
Ezerous 8 years ago
parent
commit
0e7be4e87d
  1. 7
      app/src/main/java/gr/thmmy/mthmmy/activities/AboutActivity.java
  2. 38
      app/src/main/java/gr/thmmy/mthmmy/activities/BaseActivity.java
  3. 1
      app/src/main/java/gr/thmmy/mthmmy/activities/main/MainActivity.java
  4. 6
      app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicActivity.java
  5. 1
      app/src/main/res/values/strings.xml

7
app/src/main/java/gr/thmmy/mthmmy/activities/AboutActivity.java

@ -24,6 +24,7 @@ public class AboutActivity extends BaseActivity
getSupportActionBar().setDisplayShowHomeEnabled(true); getSupportActionBar().setDisplayShowHomeEnabled(true);
createDrawer(); createDrawer();
drawer.setSelection(ABOUT_ID);
TextView tv = (TextView) findViewById(R.id.version); TextView tv = (TextView) findViewById(R.id.version);
@ -32,4 +33,10 @@ public class AboutActivity extends BaseActivity
//TODO: add licenses //TODO: add licenses
} }
@Override
protected void onResume() {
super.onResume();
drawer.setSelection(ABOUT_ID);
}
} }

38
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.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() {

1
app/src/main/java/gr/thmmy/mthmmy/activities/main/MainActivity.java

@ -61,6 +61,7 @@ public class MainActivity extends BaseActivity implements RecentFragment.OnListF
@Override @Override
protected void onResume() { protected void onResume() {
super.onResume(); super.onResume();
drawer.setSelection(HOME_ID);
updateDrawer(); updateDrawer();
} }

6
app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicActivity.java

@ -191,6 +191,12 @@ public class TopicActivity extends BaseActivity {
super.onBackPressed(); super.onBackPressed();
} }
@Override
protected void onResume() {
super.onResume();
drawer.setSelection(-1);
}
@Override @Override
protected void onDestroy() { //When finished cancel whatever request can still be canceled protected void onDestroy() { //When finished cancel whatever request can still be canceled
super.onDestroy(); super.onDestroy();

1
app/src/main/res/values/strings.xml

@ -21,4 +21,5 @@
<string name="text_page">Page</string> <string name="text_page">Page</string>
<string name="text_next">next</string> <string name="text_next">next</string>
<string name="text_last">last</string> <string name="text_last">last</string>
<string name="home">Home</string>
</resources> </resources>

Loading…
Cancel
Save