// 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;
        JsonArray list = new JsonParser().parse(getStringPreferences(context, PREF_PACKAGE_ALLOW)).getAsJsonArray();

        View v = convertView;
        if (v == null) {
            LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            v = inflater.inflate(R.layout.listview_package_item, parent, false);
            ViewHolder holder = new ViewHolder();
            holder.itemView = v.findViewById(R.id.app_item);
            holder.iconView = v.findViewById(R.id.app_icon);
            holder.nameView = v.findViewById(R.id.app_name);
            holder.packageView = v.findViewById(R.id.app_package);
            v.setTag(holder);
        }

        JsonObject item = listViewItemList.get(position);
        String name = item.get("name").getAsString();
        String pkgname = item.get("package").getAsString();
        ViewHolder holder = (ViewHolder) v.getTag();
        try {
            holder.iconView.setImageDrawable(pm.getApplicationIcon(pkgname));
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
        holder.nameView.setText(name); // pm.getApplicationLabel(item.applicationInfo));
        holder.nameView.setTextColor(ContextCompat.getColor(context,
                getCheckedTextColor(list.contains(new JsonPrimitive(pkgname)))));
        holder.packageView.setText(pkgname);

        final String package_name = pkgname;
        holder.itemView.setOnClickListener(v1 -> {
// 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;

        JsonArray list = new JsonParser().parse(getStringPreferences(context, PREF_PACKAGE_ALLOW)).getAsJsonArray();

        View v = convertView;
        if (v == null) {
            LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            v = inflater.inflate(R.layout.listview_package_item, parent, false);
            ViewHolder holder = new ViewHolder();
            holder.itemView = v.findViewById(R.id.app_item);
            holder.iconView = v.findViewById(R.id.app_icon);
            holder.nameView = v.findViewById(R.id.app_name);
            holder.packageView = v.findViewById(R.id.app_package);
            v.setTag(holder);
        }

        JsonObject item = listViewItemList.get(position);
        String name = item.get("name").getAsString();
        String pkgname = item.get("package").getAsString();
        ViewHolder holder = (ViewHolder) v.getTag();
        try {
            holder.iconView.setImageDrawable(pm.getApplicationIcon(pkgname));
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
        holder.nameView.setText(name); // pm.getApplicationLabel(item.applicationInfo));
        holder.nameView.setTextColor(ContextCompat.getColor(context,
                getCheckedTextColor(list.contains(new JsonPrimitive(pkgname)))));
        holder.packageView.setText(pkgname);

        final String package_name = pkgname;
        holder.itemView.setOnClickListener(v1 -> {
            JsonArray data = new JsonParser().parse(getStringPreferences(context, PREF_PACKAGE_ALLOW)).getAsJsonArray();