package uk.co.pilllogger.dialogs;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.DialogFragment;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;

import uk.co.pilllogger.R;
import uk.co.pilllogger.activities.MainActivity;

/**
 * Created by Alex on 26/04/2014
 * in uk.co.pilllogger.dialogs.
 */
public class ThemeChoiceDialog extends DialogFragment {

    private final Activity _activity;

    public ThemeChoiceDialog(Activity activity){
        _activity = activity;
    }

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        // Use the Builder class for convenient dialog construction
        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
        builder.setTitle(R.string.dialog_change_theme_title);
        builder.setMessage(R.string.dialog_change_theme)
                .setPositiveButton(R.string.dialog_change_theme_yes, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        // use new theme
                        Context context = _activity;
                        SharedPreferences defaultSharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
                        defaultSharedPreferences.edit().putString(context.getString(R.string.pref_key_theme_list), context.getString(R.string.professionalTheme)).commit();

                        dialog.dismiss();
                    }
                })
                .setNegativeButton(R.string.dialog_change_theme_no, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        // use current theme
                        Context context = _activity;
                        SharedPreferences defaultSharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
                        defaultSharedPreferences.edit().putString(context.getString(R.string.pref_key_theme_list), context.getString(R.string.rainbowTheme)).commit();
                        dialog.dismiss();

                        _activity.finish();
                        Intent intent = new Intent(_activity, _activity.getClass());
                        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                        startActivity(intent);
                    }
                });
        // Create the AlertDialog object and return it
        return builder.create();
    }

}

@@ -579,133 +579,8 @@
  %7B%0A%0A
-    private final Activity _activity;%0A%0A    public ThemeChoiceDialog(Activity activity)%7B%0A        _activity = activity;%0A    %7D%0A%0A
     
@@ -589,16 +589,16 @@
 verride%0A
+
     publ
@@ -719,16 +719,65 @@
 ruction%0A
+        final Activity activity = getActivity();%0A
         
@@ -830,29 +830,24 @@
 Builder(
-getA
+a
 ctivity
-()
 );%0A     
@@ -1218,33 +1218,32 @@
 ntext context = 
-_
 activity;%0A      
@@ -1886,17 +1886,16 @@
 ntext = 
-_
 activity
@@ -2255,17 +2255,16 @@
         
-_
 activity
@@ -2325,17 +2325,16 @@
  Intent(
-_
 activity
@@ -2335,17 +2335,16 @@
 tivity, 
-_
 activity

Fix for theme choice dialog