Skip to content

Commit

Permalink
Fix NPE when using grids as default activity
Browse files Browse the repository at this point in the history
  • Loading branch information
quentin-st committed Mar 19, 2016
1 parent c8e55d2 commit c3308b3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,6 @@ public void onCreate(Bundle savedInstanceState) {
*/
public void onLoadFinished() {
preloading = false;

// Inflate menu if not already done
if (!optionsMenuLoaded)
createOptionsMenu();

// Ask the user to rate the app
AlertDialog.Builder builder = new AlertDialog.Builder(this)
Expand Down Expand Up @@ -155,17 +151,19 @@ public void onClick(View view) {
} else
findViewById(R.id.setDefaultActivity).setVisibility(View.GONE);
} else {
switch (muninFoo.getSettings().getString(Settings.PrefKeys.DefaultActivity)) {
switch (settings.getString(Settings.PrefKeys.DefaultActivity)) {
case "grid": {
mainFragment = MainFragment.GRID;
findViewById(R.id.empty_layout).setVisibility(View.GONE);
findViewById(R.id.fragment_container).setVisibility(View.VISIBLE);

// Prepare fragment
boolean autoLoad = settings.getBool(Settings.PrefKeys.DefaultActivity_Grid_AutoloadGraphs);
fragment = new Fragment_Grid();
Bundle bundle = new Bundle();
int gridId = muninFoo.getSettings().getInt(Settings.PrefKeys.DefaultActivity_GridId);
bundle.putLong(Fragment_Grid.ARG_GRIDID, gridId);
bundle.putBoolean(Fragment_Grid.ARG_AUTOLOAD, settings.getBool(Settings.PrefKeys.DefaultActivity_Grid_AutoloadGraphs));
bundle.putBoolean(Fragment_Grid.ARG_AUTOLOAD, autoLoad);
fragment.setArguments(bundle);
getSupportFragmentManager().beginTransaction().add(R.id.fragment_container, fragment).commit();
break;
Expand Down Expand Up @@ -201,6 +199,10 @@ public void onClick(View view) {
dh.reset();
if (mainFragment == MainFragment.NONE)
dh.toggle();

// Inflate menu if not already done
if (!optionsMenuLoaded)
createOptionsMenu();
}

@Override
Expand Down Expand Up @@ -310,6 +312,11 @@ private void createOptionsMenu() {
// _refresh and _changePeriod are set visible when the user hits the "Load" button
menu_grid_refresh = menu.findItem(R.id.menu_grid_refresh);
menu_grid_changePeriod = menu.findItem(R.id.menu_grid_period);
// If autoLoad, toggle their visibility
if (settings.getString(Settings.PrefKeys.DefaultActivity, "none").equals("grid")
&& settings.getBool(Settings.PrefKeys.DefaultActivity_Grid_AutoloadGraphs)) {
onManualLoad();
}

// Alerts
menu.findItem(R.id.menu_alerts_refresh).setVisible(mainFragment == MainFragment.ALERTS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,7 @@ public void onClick(View v) {
if (autoLoad && grid.getItems().isEmpty())
edit();

if (autoLoad)
activity.onManualLoad();
else {
if (!autoLoad) {
view.findViewById(R.id.manual_load).setVisibility(View.VISIBLE);
view.findViewById(R.id.manual_load_action).setOnClickListener(new View.OnClickListener() {
@Override
Expand Down

0 comments on commit c3308b3

Please sign in to comment.