Browse Source

Fixes on drawer and back button handling

Double back to exit app
First back closes drawer
Toolbar has a back icon instead of drawer icon and drawer only opens with left to right swipe
pull/24/head
Apostolos Fanakis 8 years ago
parent
commit
4a48f367ba
  1. 12
      app/src/main/java/gr/thmmy/mthmmy/activities/BaseActivity.java
  2. 21
      app/src/main/java/gr/thmmy/mthmmy/activities/main/MainActivity.java
  3. 9
      app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicActivity.java

12
app/src/main/java/gr/thmmy/mthmmy/activities/BaseActivity.java

@ -8,6 +8,8 @@ import android.os.AsyncTask;
import android.os.Bundle; 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.view.MenuItem;
import android.view.View; import android.view.View;
import android.widget.Toast; import android.widget.Toast;
@ -62,7 +64,6 @@ public class BaseActivity extends AppCompatActivity
sessionManager = new SessionManager(client, cookieJar, sharedPrefsCookiePersistor, sharedPrefs); sessionManager = new SessionManager(client, cookieJar, sharedPrefsCookiePersistor, sharedPrefs);
init = true; init = true;
} }
} }
public static OkHttpClient getClient() public static OkHttpClient getClient()
@ -127,6 +128,15 @@ public class BaseActivity extends AppCompatActivity
}) })
.build(); .build();
drawer.setSelection(-1); drawer.setSelection(-1);
drawer.getActionBarDrawerToggle().setDrawerIndicatorEnabled(false);
drawer.setOnDrawerNavigationListener(new Drawer.OnDrawerNavigationListener() {
@Override
public boolean onNavigationClickListener(View clickedView) {
onBackPressed();
return true;
}
});
} }
protected void updateDrawer() protected void updateDrawer()

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

@ -8,6 +8,7 @@ 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.widget.Toast;
import gr.thmmy.mthmmy.R; import gr.thmmy.mthmmy.R;
import gr.thmmy.mthmmy.activities.BaseActivity; import gr.thmmy.mthmmy.activities.BaseActivity;
@ -23,6 +24,8 @@ public class MainActivity extends BaseActivity implements RecentFragment.OnListF
//----------------------------------------CLASS VARIABLES----------------------------------------- //----------------------------------------CLASS VARIABLES-----------------------------------------
private static final String TAG = "MainActivity"; private static final String TAG = "MainActivity";
private static final int TIME_INTERVAL = 2000;
private long mBackPressed;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@ -61,9 +64,21 @@ public class MainActivity extends BaseActivity implements RecentFragment.OnListF
updateDrawer(); updateDrawer();
} }
@Override
public void onBackPressed() {
if(drawer.isDrawerOpen()){
drawer.closeDrawer();
return;
}
else if (mBackPressed + TIME_INTERVAL > System.currentTimeMillis()) {
super.onBackPressed();
return;
} else {
Toast.makeText(getBaseContext(), "Press back again to exit!"
, Toast.LENGTH_SHORT).show();
}
mBackPressed = System.currentTimeMillis();
}
@Override @Override
public void onFragmentInteraction(TopicSummary topicSummary) { public void onFragmentInteraction(TopicSummary topicSummary) {

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

@ -182,6 +182,15 @@ public class TopicActivity extends BaseActivity {
new TopicTask().execute(extras.getString("TOPIC_URL")); //Attempt data parsing new TopicTask().execute(extras.getString("TOPIC_URL")); //Attempt data parsing
} }
@Override
public void onBackPressed() {
if (drawer.isDrawerOpen()) {
drawer.closeDrawer();
return;
}
super.onBackPressed();
}
@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();

Loading…
Cancel
Save