// Path: app/src/main/java/com/ryansteckler/nlpunbounce/adapters/RegexAdapter.java
// public class RegexAdapter extends ArrayAdapter<String> {
// 
// 
//     private final ArrayList<String> list;
//     private final Activity context;
//     private final String mEntityName;
// 
//     public RegexAdapter(Activity context, ArrayList<String> list, String entityName) {
//         super(context, R.layout.fragment_regex_listitem, list);
//         this.context = context;
//         this.list = list;
//         this.mEntityName = entityName;
//     }
// 
//     @Override
//     public View getView(final int position, View convertView, ViewGroup parent) {
//         View view = null;
//         if (convertView == null) {
//             LayoutInflater inflator = context.getLayoutInflater();
//             view = inflator.inflate(R.layout.fragment_regex_listitem, null);
//         } else {
//             view = convertView;
//         }
// 
//         TextView text = (TextView) view.findViewById(R.id.textviewRegexName);
//         text.setText(this.list.get(position).substring(0, this.list.get(position).indexOf("$$||$$")));
//         Button button = (Button) view.findViewById(R.id.btn_delete_regex);
//         if (button != null) {
//             button.setTag(position);
//             button.setOnClickListener(new View.OnClickListener() {
//                 @Override
//                 public void onClick(View v) {
// 
//                     Integer tag = (Integer) v.getTag();
//                     int pos = tag.intValue();
// 
//                     list.remove(pos);
// 
//                     // saves the list
//                     SharedPreferences prefs = context.getSharedPreferences("com.ryansteckler.nlpunbounce_preferences", Context.MODE_WORLD_READABLE);
//                     Set<String> set = new HashSet<String>();
//                     set.addAll(list);
//                     SharedPreferences.Editor editor = prefs.edit();
//                     editor.putStringSet(mEntityName + "_regex_set", set);
//                     editor.commit();
// 
//                     notifyDataSetChanged();
// 
//                 }
//             });
//         }
//         return view;
//     }
// 
// }
// 
// Path: app/src/main/java/com/ryansteckler/nlpunbounce/helpers/ThemeHelper.java
// public class ThemeHelper {
// 
//     private static int sTheme = -1;
//     public final static int THEME_DEFAULT = 0;
//     public final static int THEME_DARK = 1;
//     /**
//      * Set the theme of the Activity, and restart it by creating a new Activity of the same type.
//      */
//     public static void changeToTheme(Activity activity, int theme)
//     {
//         sTheme = theme;
//         activity.finish();
//         activity.startActivity(new Intent(activity, activity.getClass()));
//     }
//     /** Set the theme of the activity, according to the configuration. */
//     public static int onActivityCreateSetTheme(Activity activity)
//     {
//         if (sTheme == -1) {
//             // Load from prefs
//             SharedPreferences prefs = activity.getSharedPreferences("com.ryansteckler.nlpunbounce" + "_preferences", Context.MODE_WORLD_READABLE);
//             sTheme = prefs.getString("theme", "default").equals("default") ? THEME_DEFAULT : THEME_DARK;
//         }
// 
//         switch (sTheme)
//         {
//             default:
//             case THEME_DEFAULT:
//                 activity.setTheme(R.style.UnbounceThemeLight);
//                 break;
//             case THEME_DARK:
//                 activity.setTheme(R.style.UnbounceThemeDark);
//                 break;
//         }
//         return sTheme;
//     }
//     public static int onActivityResumeVerifyTheme(Activity activity, int curTheme)
//     {
//         if (curTheme != sTheme) {
//             changeToTheme(activity, sTheme);
//         }
// 
//         return sTheme;
//     }
// 
//     public static int getTheme() {
//         return sTheme;
//     }
// 
// }


import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.app.DialogFragment;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import com.ryansteckler.nlpunbounce.adapters.RegexAdapter;
import com.ryansteckler.nlpunbounce.helpers.ThemeHelper;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;

        // Create The Adapter with passing ArrayList as 3rd parameter
        mAdapter = new RegexAdapter(getActivity(), list, "wakelock");

        // Sets The Adapter
        setListAdapter(mAdapter);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        int id = item.getItemId();

        if (id == R.id.action_new_custom) {
            //Create a new custom wakelock regex
            DialogFragment dialog = RegexDialogFragment.newInstance("", "", "wakelock");
            dialog.setTargetFragment(this, 0);
            dialog.show(getActivity().getFragmentManager(), "RegexDialog");
        }
        return super.onOptionsItemSelected(item);
    }


    @Override
    public void onPrepareOptionsMenu(Menu menu) {
        super.onPrepareOptionsMenu(menu);
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
// Path: app/src/main/java/com/ryansteckler/nlpunbounce/adapters/RegexAdapter.java
// public class RegexAdapter extends ArrayAdapter<String> {
// 
// 
//     private final ArrayList<String> list;
//     private final Activity context;
//     private final String mEntityName;
// 
//     public RegexAdapter(Activity context, ArrayList<String> list, String entityName) {
//         super(context, R.layout.fragment_regex_listitem, list);
//         this.context = context;
//         this.list = list;
//         this.mEntityName = entityName;
//     }
// 
//     @Override
//     public View getView(final int position, View convertView, ViewGroup parent) {
//         View view = null;
//         if (convertView == null) {
//             LayoutInflater inflator = context.getLayoutInflater();
//             view = inflator.inflate(R.layout.fragment_regex_listitem, null);
//         } else {
//             view = convertView;
//         }
// 
//         TextView text = (TextView) view.findViewById(R.id.textviewRegexName);
//         text.setText(this.list.get(position).substring(0, this.list.get(position).indexOf("$$||$$")));
//         Button button = (Button) view.findViewById(R.id.btn_delete_regex);
//         if (button != null) {
//             button.setTag(position);
//             button.setOnClickListener(new View.OnClickListener() {
//                 @Override
//                 public void onClick(View v) {
// 
//                     Integer tag = (Integer) v.getTag();
//                     int pos = tag.intValue();
// 
//                     list.remove(pos);
// 
//                     // saves the list
//                     SharedPreferences prefs = context.getSharedPreferences("com.ryansteckler.nlpunbounce_preferences", Context.MODE_WORLD_READABLE);
//                     Set<String> set = new HashSet<String>();
//                     set.addAll(list);
//                     SharedPreferences.Editor editor = prefs.edit();
//                     editor.putStringSet(mEntityName + "_regex_set", set);
//                     editor.commit();
// 
//                     notifyDataSetChanged();
// 
//                 }
//             });
//         }
//         return view;
//     }
// 
// }
// 
// Path: app/src/main/java/com/ryansteckler/nlpunbounce/helpers/ThemeHelper.java
// public class ThemeHelper {
// 
//     private static int sTheme = -1;
//     public final static int THEME_DEFAULT = 0;
//     public final static int THEME_DARK = 1;
//     /**
//      * Set the theme of the Activity, and restart it by creating a new Activity of the same type.
//      */
//     public static void changeToTheme(Activity activity, int theme)
//     {
//         sTheme = theme;
//         activity.finish();
//         activity.startActivity(new Intent(activity, activity.getClass()));
//     }
//     /** Set the theme of the activity, according to the configuration. */
//     public static int onActivityCreateSetTheme(Activity activity)
//     {
//         if (sTheme == -1) {
//             // Load from prefs
//             SharedPreferences prefs = activity.getSharedPreferences("com.ryansteckler.nlpunbounce" + "_preferences", Context.MODE_WORLD_READABLE);
//             sTheme = prefs.getString("theme", "default").equals("default") ? THEME_DEFAULT : THEME_DARK;
//         }
// 
//         switch (sTheme)
//         {
//             default:
//             case THEME_DEFAULT:
//                 activity.setTheme(R.style.UnbounceThemeLight);
//                 break;
//             case THEME_DARK:
//                 activity.setTheme(R.style.UnbounceThemeDark);
//                 break;
//         }
//         return sTheme;
//     }
//     public static int onActivityResumeVerifyTheme(Activity activity, int curTheme)
//     {
//         if (curTheme != sTheme) {
//             changeToTheme(activity, sTheme);
//         }
// 
//         return sTheme;
//     }
// 
//     public static int getTheme() {
//         return sTheme;
//     }
// 
// }


// Path: app/src/main/java/com/ryansteckler/nlpunbounce/WakelockRegexFragment.java
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.app.DialogFragment;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import com.ryansteckler.nlpunbounce.adapters.RegexAdapter;
import com.ryansteckler.nlpunbounce.helpers.ThemeHelper;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;


        // Create The Adapter with passing ArrayList as 3rd parameter
        mAdapter = new RegexAdapter(getActivity(), list, "wakelock");

        // Sets The Adapter
        setListAdapter(mAdapter);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        int id = item.getItemId();

        if (id == R.id.action_new_custom) {
            //Create a new custom wakelock regex
            DialogFragment dialog = RegexDialogFragment.newInstance("", "", "wakelock");
            dialog.setTargetFragment(this, 0);
            dialog.show(getActivity().getFragmentManager(), "RegexDialog");
        }
        return super.onOptionsItemSelected(item);
    }


    @Override
    public void onPrepareOptionsMenu(Menu menu) {
        super.onPrepareOptionsMenu(menu);
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ThemeHelper.onActivityCreateSetTheme(this.getActivity());