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. 42
      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);
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);
}
}

42
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() {

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
protected void onResume() {
super.onResume();
drawer.setSelection(HOME_ID);
updateDrawer();
}

6
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();

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

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

Loading…
Cancel
Save