package me.vickychijwani.spectre.view;

import android.support.v4.app.Fragment;
import android.support.v4.app.NavUtils;
import android.support.v7.app.ActionBarActivity;
import android.view.MenuItem;

import java.util.List;

import me.vickychijwani.spectre.model.AuthToken;
import me.vickychijwani.spectre.view.fragments.BaseFragment;

public abstract class BaseActivity extends ActionBarActivity {

    // TODO get rid of this shit
    protected static AuthToken sAuthToken = null;

    public static AuthToken getAuthToken() {
        return sAuthToken;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case android.R.id.home:
                NavUtils.navigateUpFromSameTask(this);
                return true;
            default:
                return super.onOptionsItemSelected(item);
        }
    }

    @Override
    public void onBackPressed() {
        List<Fragment> fragments = getSupportFragmentManager().getFragments();
        for (Fragment f : fragments) {
            BaseFragment bf = (BaseFragment) f;
            if (bf.onBackPressed()) {
                return;
            }
        }
        super.onBackPressed();
    }

}

@@ -1002,24 +1002,61 @@
 ragments();%0A
+        if (fragments != null) %7B%0A    
         for 
@@ -1078,24 +1078,176 @@
 ragments) %7B%0A
+                if (!(f instanceof BaseFragment)) %7B%0A                    continue;  // vanilla fragments don't have onBackPressed%0A                %7D%0A%0A    
             
@@ -1290,24 +1290,28 @@
             
+    
 if (bf.onBac
@@ -1344,16 +1344,20 @@
     
+    
 return;%0A
     
@@ -1352,16 +1352,34 @@
 return;%0A
+                %7D%0A
         

Fix crashes in BaseActivity#onBackPressed().