package de.chribi.predictable.statistics;

import android.content.Context;
import android.content.Intent;
import android.databinding.DataBindingUtil;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

import javax.inject.Inject;

import dagger.android.AndroidInjection;
import de.chribi.predictable.R;
import de.chribi.predictable.databinding.ActivityStatisticsBinding;

public class StatisticsActivity extends AppCompatActivity {

    public static void start(Context context) {
        Intent intent = new Intent(context, StatisticsActivity.class);
        context.startActivity(intent);
    }

    private StatisticsViewModel viewModel;

    @Inject
    void setDependencies(StatisticsViewModel viewModel) {
        this.viewModel = viewModel;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        AndroidInjection.inject(this);
        super.onCreate(savedInstanceState);
        ActivityStatisticsBinding binding
                = DataBindingUtil.setContentView(this, R.layout.activity_statistics);

        setSupportActionBar(binding.includedToolbar.toolbar);
        configureToolbar();
        binding.setStatistics(viewModel);
    }

    private void configureToolbar() {
        ActionBar toolbar = getSupportActionBar();
        if(toolbar != null) {
            toolbar.setTitle(R.string.title_activity_statistics);
            toolbar.setDisplayHomeAsUpEnabled(true);
        }
    }
}

@@ -99,16 +99,58 @@
 Intent;%0A
+import android.content.SharedPreferences;%0A
 import a
@@ -185,16 +185,16 @@
 ngUtil;%0A
-
 import a
@@ -531,16 +531,107 @@
 tivity %7B
+%0A    private static final String KEY_INVERT_IMPROBABLE_PREDICTIONS = %22INVERT_IMPROB_PREDS%22;
 %0A%0A    pu
@@ -1323,47 +1323,787 @@
 ();%0A
-        binding.setStatistics(viewModel
+%0A        // restore state of 'invert low confidence predictions' setting from activity preferences%0A        SharedPreferences activityPrefs = getPreferences(MODE_PRIVATE);%0A        viewModel.setInvertLowConfidencePredictions(%0A                activityPrefs.getBoolean(KEY_INVERT_IMPROBABLE_PREDICTIONS, false));%0A%0A        binding.setStatistics(viewModel);%0A    %7D%0A%0A    @Override protected void onPause() %7B%0A        super.onPause();%0A        // save the state of the 'invert low confidence predictions' setting across app restarts%0A        SharedPreferences activityPrefs = getPreferences(MODE_PRIVATE);%0A        activityPrefs.edit()%0A                .putBoolean(KEY_INVERT_IMPROBABLE_PREDICTIONS,%0A                        viewModel.isInvertLowConfidencePredictions())%0A                .apply(
 );%0A 

Save user preference for statistics display