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
android:name=".ActivitySetup"
android:launchMode="singleTop"
android:parentActivityName=".ActivityView" />
<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;
public class ActivityView extends ActivityBase implements FragmentManager.OnBackStackChangedListener, SharedPreferences.OnSharedPreferenceChangeListener {
private boolean newIntent = false;
private DrawerLayout drawerLayout;
private ListView drawerList;
private ActionBarDrawerToggle drawerToggle;
@ -78,6 +79,7 @@ public class ActivityView extends ActivityBase implements FragmentManager.OnBack
@Override
protected void onCreate(Bundle savedInstanceState) {
Log.i(Helper.TAG, "View create");
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_view);
@ -134,6 +136,7 @@ public class ActivityView extends ActivityBase implements FragmentManager.OnBack
@Override
protected void onPostCreate(Bundle savedInstanceState) {
Log.i(Helper.TAG, "View post create");
super.onPostCreate(savedInstanceState);
drawerToggle.syncState();
syncState();
@ -141,50 +144,53 @@ public class ActivityView extends ActivityBase implements FragmentManager.OnBack
@Override
protected void onResume() {
Log.i(Helper.TAG, "View resume");
super.onResume();
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(this);
IntentFilter iff = new IntentFilter();
iff.addAction(ACTION_VIEW_MESSAGES);
iff.addAction(ACTION_VIEW_MESSAGE);
iff.addAction(ACTION_EDIT_FOLDER);
lbm.registerReceiver(receiver, iff);
if (newIntent) {
newIntent = false;
getSupportFragmentManager().popBackStack("unified", 0);
}
}
@Override
protected void onPause() {
Log.i(Helper.TAG, "View pause");
super.onPause();
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(this);
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
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);
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
Log.i(Helper.TAG, "View configuration changed");
super.onConfigurationChanged(newConfig);
drawerToggle.onConfigurationChanged(newConfig);
}
@Override
protected void onDestroy() {
Log.i(Helper.TAG, "View destroyed");
PreferenceManager.getDefaultSharedPreferences(this).unregisterOnSharedPreferenceChangeListener(this);
super.onDestroy();
}
@Override
public void onBackPressed() {
if (drawerLayout.isDrawerOpen(drawerList))
@ -194,9 +200,9 @@ public class ActivityView extends ActivityBase implements FragmentManager.OnBack
}
@Override
protected void onDestroy() {
PreferenceManager.getDefaultSharedPreferences(this).unregisterOnSharedPreferenceChangeListener(this);
super.onDestroy();
public void onBackStackChanged() {
if (getSupportFragmentManager().getBackStackEntryCount() == 0)
finish();
}
@Override
@ -207,17 +213,17 @@ public class ActivityView extends ActivityBase implements FragmentManager.OnBack
}
@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);
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
@ -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() {
syncState();
invalidateOptionsMenu();


Loading…
Cancel
Save