Skip to content

Commit

Permalink
Activity_Main: don't try to interact with the fragment if it hasn't b…
Browse files Browse the repository at this point in the history
…een prepared
  • Loading branch information
quentin-st committed Oct 13, 2016
1 parent f16778f commit 0696df2
Showing 1 changed file with 21 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public class Activity_Main extends AppCompatActivity implements IGridActivity, I
private ProgressBar progressBar;

private DrawerHelper dh;

// Preloading
private boolean preloading;
private boolean optionsMenuLoaded;
Expand All @@ -66,7 +66,7 @@ public class Activity_Main extends AppCompatActivity implements IGridActivity, I
private enum MainFragment { NONE, GRID, LABEL, ALERTS }
private MainFragment mainFragment;
private Fragment fragment;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand All @@ -86,7 +86,7 @@ public void onCreate(Bundle savedInstanceState) {
optionsMenuLoaded = false;
if (loaded)
preloading = false;

context = this;
setContentView(R.layout.activity_main);

Expand All @@ -101,13 +101,13 @@ public void onCreate(Bundle savedInstanceState) {
dh = new DrawerHelper(this, muninFoo, this.toolbar);

progressBar = Util.UI.prepareGmailStyleProgressBar(this, getSupportActionBar());

if (loaded)
onLoadFinished();
else
preload();
}

/**
* Executed when the app has loaded :
* - launching app, after the initialization
Expand All @@ -131,7 +131,7 @@ public void onLoadFinished() {
return;
}
}

// Ask the user to rate the app
AlertDialog.Builder builder = new AlertDialog.Builder(this)
.setTitle(getText(R.string.rate))
Expand Down Expand Up @@ -218,7 +218,7 @@ public void onClick(View view) {
if (!optionsMenuLoaded)
createOptionsMenu();
}

@Override
public void onBackPressed() {
if (dh.closeDrawerIfOpen())
Expand All @@ -232,9 +232,9 @@ public void onBackPressed() {
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}

doubleBackPressed = true;

new Handler().postDelayed(new Runnable() {
@Override
public void run() {
Expand Down Expand Up @@ -301,14 +301,14 @@ public boolean onOptionsItemSelected(MenuItem item) {

return true;
}

@Override
public boolean onCreateOptionsMenu(final Menu menu) {
this.menu = menu;

if (!preloading && !optionsMenuLoaded)
createOptionsMenu();

return true;
}
private void createOptionsMenu() {
Expand Down Expand Up @@ -368,11 +368,11 @@ public void onClick(DialogInterface dialogInterface, int i) {
}
}
}

private void preload() {
boolean updateOperations = !muninFoo.getSettings().getString(Settings.PrefKeys.LastDbVersion).equals(MuninFoo.DB_VERSION + "");


if (updateOperations) {
if (progressDialog == null || !progressDialog.isShowing())
progressDialog = ProgressDialog.show(context, "", getString(R.string.text39), true);
Expand All @@ -381,7 +381,7 @@ private void preload() {
} else
onLoadFinished();
}

public void updateActions() {
String strFromVersion = settings.getString(Settings.PrefKeys.LastDbVersion);
double fromVersion = 0;
Expand Down Expand Up @@ -424,6 +424,12 @@ public void onGridLoaded(Grid grid) {
public void onManualLoad() {
menu_grid_refresh.setVisible(true);
menu_grid_changePeriod.setVisible(true);

// If the fragment wasn't prepared (when redirecting to another activity),
// don't try to interact with it
if (this.fragment == null)
return;

// Set period MenuItem text
Fragment_Grid fragment = (Fragment_Grid) this.fragment;
menu_grid_changePeriod.setTitle(fragment.getCurrentPeriod().getLabel(this));
Expand Down

0 comments on commit 0696df2

Please sign in to comment.