aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott Jackson <daneren2005@gmail.com>2013-04-04 19:51:56 -0700
committerScott Jackson <daneren2005@gmail.com>2013-04-04 19:51:56 -0700
commit118f50723871c30290fea0b4ea52f1d6f535da27 (patch)
treee81267c688ef822fbd626900c80f8496ade6f399
parentb3841c04a7961cac98a8ec0e63e07d0613d7a08d (diff)
downloaddsub-118f50723871c30290fea0b4ea52f1d6f535da27.tar.gz
dsub-118f50723871c30290fea0b4ea52f1d6f535da27.tar.bz2
dsub-118f50723871c30290fea0b4ea52f1d6f535da27.zip
Pressing back goes to home tab, confirm to exit
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java29
1 files changed, 29 insertions, 0 deletions
diff --git a/subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java b/subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java
index 50fea96e..454a729d 100644
--- a/subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java
+++ b/subsonic-android/src/github/daneren2005/dsub/activity/MainActivity.java
@@ -1,5 +1,7 @@
package github.daneren2005.dsub.activity;
+import android.app.AlertDialog;
+import android.content.DialogInterface;
import com.actionbarsherlock.app.ActionBar;
import com.actionbarsherlock.app.ActionBar.Tab;
import com.actionbarsherlock.app.ActionBar.TabListener;
@@ -56,6 +58,32 @@ public class MainActivity extends SubsonicActivity {
public void onResume() {
super.onResume();
}
+
+ @Override
+ public void onBackPressed() {
+ int backStack = getSupportFragmentManager().getBackStackEntryCount();
+ int currentTab = viewPager.getCurrentItem();
+
+ if(backStack == 0) {
+ if(currentTab == 0) {
+ AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
+ builder.setTitle("Confirm Exit")
+ .setPositiveButton("OK", new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int id) {
+ MainActivity.super.onBackPressed();
+ }
+ })
+ .setNegativeButton("Cancel", null);
+ AlertDialog dialog = builder.create();
+ dialog.show();
+ } else {
+ viewPager.setCurrentItem(0);
+ }
+ } else {
+ super.onBackPressed();
+ }
+ }
protected void addTab(int titleRes, Class fragmentClass, Bundle args) {
pagerAdapter.addTab(getString(titleRes), fragmentClass, args);
@@ -109,6 +137,7 @@ public class MainActivity extends SubsonicActivity {
for (int i = 0; i < tabs.size(); i++) {
if ( tabs.get(i) == tabInfo ) {
pager.setCurrentItem(i);
+ break;
}
}
}