// Path: app/src/main/java/com/antest1/kcanotify/KcaConstants.java
// public static final String PREF_PACKAGE_ALLOW = "package_allow";
// 
// Path: app/src/main/java/com/antest1/kcanotify/KcaUtils.java
// public static String getStringPreferences(Context ctx, String key) {
//     SharedPreferences pref = ctx.getSharedPreferences("pref", Context.MODE_PRIVATE);
//     try {
//         return String.valueOf(pref.getInt(key, 0));
//     } catch (Exception e) {
//         // Nothing to do
//     }
//     return pref.getString(key, "");
// }
// 
// Path: app/src/main/java/com/antest1/kcanotify/KcaUtils.java
// public static void setPreferences(Context ctx, String key, Object value) {
//     SharedPreferences pref = ctx.getSharedPreferences("pref", Context.MODE_PRIVATE);
//     SharedPreferences.Editor editor = pref.edit();
//     if (value instanceof String) {
//         editor.putString(key, (String) value);
//     } else if (value instanceof Boolean) {
//         editor.putBoolean(key, (Boolean) value);
//     } else if (value instanceof Integer) {
//         editor.putString(key, String.valueOf(value));
//     } else {
//         editor.putString(key, value.toString());
//     }
//     editor.commit();
// }


import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Handler;
import androidx.core.content.ContextCompat;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.google.gson.JsonPrimitive;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import static com.antest1.kcanotify.KcaConstants.PREF_PACKAGE_ALLOW;
import static com.antest1.kcanotify.KcaUtils.getStringPreferences;
import static com.antest1.kcanotify.KcaUtils.setPreferences;
        return v;
    }

    static class ViewHolder {
        View itemView;
        ImageView iconView;
        TextView nameView, packageView;
    }

    public void setList(PackageManager pm) {
        List<PackageInfo> data = pm.getInstalledPackages(0);
        listViewItemList = new ArrayList<>();
        for (PackageInfo p: data) {
            JsonObject item = new JsonObject();
            item.addProperty("name", pm.getApplicationLabel(p.applicationInfo).toString());
            item.addProperty("package", p.packageName);
            listViewItemList.add(item);
        }
        PackageNameCompare cmp = new PackageNameCompare(pm);
        Collections.sort(listViewItemList, cmp);
    }

    private int getCheckedTextColor(boolean checked) {
        if (checked) return R.color.colorAccent;
        else return R.color.black;
    }

    private class PackageNameCompare implements Comparator<JsonObject> {
        PackageManager pm;
        private PackageNameCompare(PackageManager pm) {
// Path: app/src/main/java/com/antest1/kcanotify/KcaConstants.java
// public static final String PREF_PACKAGE_ALLOW = "package_allow";
// 
// Path: app/src/main/java/com/antest1/kcanotify/KcaUtils.java
// public static String getStringPreferences(Context ctx, String key) {
//     SharedPreferences pref = ctx.getSharedPreferences("pref", Context.MODE_PRIVATE);
//     try {
//         return String.valueOf(pref.getInt(key, 0));
//     } catch (Exception e) {
//         // Nothing to do
//     }
//     return pref.getString(key, "");
// }
// 
// Path: app/src/main/java/com/antest1/kcanotify/KcaUtils.java
// public static void setPreferences(Context ctx, String key, Object value) {
//     SharedPreferences pref = ctx.getSharedPreferences("pref", Context.MODE_PRIVATE);
//     SharedPreferences.Editor editor = pref.edit();
//     if (value instanceof String) {
//         editor.putString(key, (String) value);
//     } else if (value instanceof Boolean) {
//         editor.putBoolean(key, (Boolean) value);
//     } else if (value instanceof Integer) {
//         editor.putString(key, String.valueOf(value));
//     } else {
//         editor.putString(key, value.toString());
//     }
//     editor.commit();
// }


// Path: app/src/main/java/com/antest1/kcanotify/KcaPackageListViewAdpater.java
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Handler;
import androidx.core.content.ContextCompat;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.google.gson.JsonPrimitive;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import static com.antest1.kcanotify.KcaConstants.PREF_PACKAGE_ALLOW;
import static com.antest1.kcanotify.KcaUtils.getStringPreferences;
import static com.antest1.kcanotify.KcaUtils.setPreferences;

        return v;
    }

    static class ViewHolder {
        View itemView;
        ImageView iconView;
        TextView nameView, packageView;
    }

    public void setList(PackageManager pm) {
        List<PackageInfo> data = pm.getInstalledPackages(0);
        listViewItemList = new ArrayList<>();
        for (PackageInfo p: data) {
            JsonObject item = new JsonObject();
            item.addProperty("name", pm.getApplicationLabel(p.applicationInfo).toString());
            item.addProperty("package", p.packageName);
            listViewItemList.add(item);
        }
        PackageNameCompare cmp = new PackageNameCompare(pm);
        Collections.sort(listViewItemList, cmp);
    }

    private int getCheckedTextColor(boolean checked) {
        if (checked) return R.color.colorAccent;
        else return R.color.black;
    }

    private class PackageNameCompare implements Comparator<JsonObject> {
        PackageManager pm;
        private PackageNameCompare(PackageManager pm) {
            this.pm = pm;