Browse Source

Handle new intents

main
M66B 6 years ago
parent
commit
c748c96d98
2 changed files with 42 additions and 27 deletions
  1. +1
    -0
      app/src/main/AndroidManifest.xml
  2. +41
    -27
      app/src/main/java/eu/faircode/email/ActivityView.java

+ 1
- 0
app/src/main/AndroidManifest.xml View File

@ -27,6 +27,7 @@
<activity <activity
android:name=".ActivitySetup" android:name=".ActivitySetup"
android:launchMode="singleTop"
android:parentActivityName=".ActivityView" /> android:parentActivityName=".ActivityView" />
<activity <activity


+ 41
- 27
app/src/main/java/eu/faircode/email/ActivityView.java View File

@ -58,6 +58,7 @@ import javax.mail.Address;
import javax.mail.internet.InternetAddress; import javax.mail.internet.InternetAddress;
public class ActivityView extends ActivityBase implements FragmentManager.OnBackStackChangedListener, SharedPreferences.OnSharedPreferenceChangeListener { public class ActivityView extends ActivityBase implements FragmentManager.OnBackStackChangedListener, SharedPreferences.OnSharedPreferenceChangeListener {
private boolean newIntent = false;
private DrawerLayout drawerLayout; private DrawerLayout drawerLayout;
private ListView drawerList; private ListView drawerList;
private ActionBarDrawerToggle drawerToggle; private ActionBarDrawerToggle drawerToggle;
@ -78,6 +79,7 @@ public class ActivityView extends ActivityBase implements FragmentManager.OnBack
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
Log.i(Helper.TAG, "View create");
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_view); setContentView(R.layout.activity_view);
@ -134,6 +136,7 @@ public class ActivityView extends ActivityBase implements FragmentManager.OnBack
@Override @Override
protected void onPostCreate(Bundle savedInstanceState) { protected void onPostCreate(Bundle savedInstanceState) {
Log.i(Helper.TAG, "View post create");
super.onPostCreate(savedInstanceState); super.onPostCreate(savedInstanceState);
drawerToggle.syncState(); drawerToggle.syncState();
syncState(); syncState();
@ -141,50 +144,53 @@ public class ActivityView extends ActivityBase implements FragmentManager.OnBack
@Override @Override
protected void onResume() { protected void onResume() {
Log.i(Helper.TAG, "View resume");
super.onResume(); super.onResume();
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(this); LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(this);
IntentFilter iff = new IntentFilter(); IntentFilter iff = new IntentFilter();
iff.addAction(ACTION_VIEW_MESSAGES); iff.addAction(ACTION_VIEW_MESSAGES);
iff.addAction(ACTION_VIEW_MESSAGE); iff.addAction(ACTION_VIEW_MESSAGE);
iff.addAction(ACTION_EDIT_FOLDER); iff.addAction(ACTION_EDIT_FOLDER);
lbm.registerReceiver(receiver, iff); lbm.registerReceiver(receiver, iff);
if (newIntent) {
newIntent = false;
getSupportFragmentManager().popBackStack("unified", 0);
}
} }
@Override @Override
protected void onPause() { protected void onPause() {
Log.i(Helper.TAG, "View pause");
super.onPause(); super.onPause();
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(this); LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(this);
lbm.unregisterReceiver(receiver); lbm.unregisterReceiver(receiver);
} }
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu_view, menu);
return true;
}
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
menu.findItem(R.id.menu_folders).setVisible(prefs.getBoolean("eula", false));
return super.onPrepareOptionsMenu(menu);
}
@Override @Override
protected void onNewIntent(Intent intent) { protected void onNewIntent(Intent intent) {
Log.i(Helper.TAG, "New intent=" + intent);
getSupportFragmentManager().popBackStack("unified", 0);
Log.i(Helper.TAG, "View new intent=" + intent);
newIntent = true;
super.onNewIntent(intent); super.onNewIntent(intent);
} }
@Override @Override
public void onConfigurationChanged(Configuration newConfig) { public void onConfigurationChanged(Configuration newConfig) {
Log.i(Helper.TAG, "View configuration changed");
super.onConfigurationChanged(newConfig); super.onConfigurationChanged(newConfig);
drawerToggle.onConfigurationChanged(newConfig); drawerToggle.onConfigurationChanged(newConfig);
} }
@Override
protected void onDestroy() {
Log.i(Helper.TAG, "View destroyed");
PreferenceManager.getDefaultSharedPreferences(this).unregisterOnSharedPreferenceChangeListener(this);
super.onDestroy();
}
@Override @Override
public void onBackPressed() { public void onBackPressed() {
if (drawerLayout.isDrawerOpen(drawerList)) if (drawerLayout.isDrawerOpen(drawerList))
@ -194,9 +200,9 @@ public class ActivityView extends ActivityBase implements FragmentManager.OnBack
} }
@Override @Override
protected void onDestroy() {
PreferenceManager.getDefaultSharedPreferences(this).unregisterOnSharedPreferenceChangeListener(this);
super.onDestroy();
public void onBackStackChanged() {
if (getSupportFragmentManager().getBackStackEntryCount() == 0)
finish();
} }
@Override @Override
@ -207,17 +213,17 @@ public class ActivityView extends ActivityBase implements FragmentManager.OnBack
} }
@Override @Override
public void onBackStackChanged() {
if (getSupportFragmentManager().getBackStackEntryCount() == 0)
finish();
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu_view, menu);
return true;
} }
private void syncState() {
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
boolean eula = prefs.getBoolean("eula", false);
drawerToggle.setDrawerIndicatorEnabled(eula);
getSupportActionBar().setDisplayHomeAsUpEnabled(eula);
getSupportActionBar().setHomeButtonEnabled(eula);
menu.findItem(R.id.menu_folders).setVisible(prefs.getBoolean("eula", false));
return super.onPrepareOptionsMenu(menu);
} }
@Override @Override
@ -234,6 +240,14 @@ public class ActivityView extends ActivityBase implements FragmentManager.OnBack
} }
} }
private void syncState() {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
boolean eula = prefs.getBoolean("eula", false);
drawerToggle.setDrawerIndicatorEnabled(eula);
getSupportActionBar().setDisplayHomeAsUpEnabled(eula);
getSupportActionBar().setHomeButtonEnabled(eula);
}
private void init() { private void init() {
syncState(); syncState();
invalidateOptionsMenu(); invalidateOptionsMenu();


Loading…
Cancel
Save