// Path: app/src/main/java/com/antest1/kcanotify/KcaConstants.java
// public static final String PREF_FV_MENU_ORDER = "fleetview_menu_order";
// 
// Path: app/src/main/java/com/antest1/kcanotify/KcaFleetViewService.java
// public static final String[] fleetview_menu_keys = {"quest", "excheck", "develop", "construction", "docking", "maphp", "fchk", "labinfo", "akashi"};
// 
// 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.os.Bundle;
import android.os.Handler;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.appcompat.widget.Toolbar;
import android.view.MenuItem;
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.woxthebox.draglistview.DragListView;
import java.util.ArrayList;
import static com.antest1.kcanotify.KcaConstants.PREF_FV_MENU_ORDER;
import static com.antest1.kcanotify.KcaFleetViewService.fleetview_menu_keys;
import static com.antest1.kcanotify.KcaUtils.getStringPreferences;
import static com.antest1.kcanotify.KcaUtils.setPreferences;
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_setting_mbtn_order);
        toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        getSupportActionBar().setTitle(getStringWithLocale(R.string.setting_menu_kand_title_fleetview_button_order));
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);

        ArrayList<JsonObject> data = new ArrayList<>();
        String pref_value = getStringPreferences(getApplicationContext(), PREF_FV_MENU_ORDER);
        if (pref_value.length() > 0) {
            order_data = new JsonParser().parse(pref_value).getAsJsonArray();
            for (int i = 0; i < order_data.size(); i++) {
                JsonObject item = new JsonObject();
                int key = order_data.get(i).getAsInt();
                item.addProperty("key", key);
                item.addProperty("value", fleetview_menu_keys[key]);
                item.addProperty("label", getStringWithLocale(KcaUtils.getId(
                        KcaUtils.format("viewmenu_%s", fleetview_menu_keys[key]), R.string.class)));
                data.add(item);
            }
        } else {
            for (int i = 0; i < fleetview_menu_keys.length; i++) {
                JsonObject item = new JsonObject();
                item.addProperty("key", i);
                item.addProperty("value", fleetview_menu_keys[i]);
                item.addProperty("label", getStringWithLocale(KcaUtils.getId(
                        KcaUtils.format("viewmenu_%s", fleetview_menu_keys[i]), R.string.class)));
                data.add(item);
                order_data.add(i);
            }
// Path: app/src/main/java/com/antest1/kcanotify/KcaConstants.java
// public static final String PREF_FV_MENU_ORDER = "fleetview_menu_order";
// 
// Path: app/src/main/java/com/antest1/kcanotify/KcaFleetViewService.java
// public static final String[] fleetview_menu_keys = {"quest", "excheck", "develop", "construction", "docking", "maphp", "fchk", "labinfo", "akashi"};
// 
// 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/KcaFleetViewMenuOrderActivity.java
import android.os.Bundle;
import android.os.Handler;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.appcompat.widget.Toolbar;
import android.view.MenuItem;
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.woxthebox.draglistview.DragListView;
import java.util.ArrayList;
import static com.antest1.kcanotify.KcaConstants.PREF_FV_MENU_ORDER;
import static com.antest1.kcanotify.KcaFleetViewService.fleetview_menu_keys;
import static com.antest1.kcanotify.KcaUtils.getStringPreferences;
import static com.antest1.kcanotify.KcaUtils.setPreferences;

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_setting_mbtn_order);
        toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        getSupportActionBar().setTitle(getStringWithLocale(R.string.setting_menu_kand_title_fleetview_button_order));
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);

        ArrayList<JsonObject> data = new ArrayList<>();
        String pref_value = getStringPreferences(getApplicationContext(), PREF_FV_MENU_ORDER);
        if (pref_value.length() > 0) {
            order_data = new JsonParser().parse(pref_value).getAsJsonArray();
            for (int i = 0; i < order_data.size(); i++) {
                JsonObject item = new JsonObject();
                int key = order_data.get(i).getAsInt();
                item.addProperty("key", key);
                item.addProperty("value", fleetview_menu_keys[key]);
                item.addProperty("label", getStringWithLocale(KcaUtils.getId(
                        KcaUtils.format("viewmenu_%s", fleetview_menu_keys[key]), R.string.class)));
                data.add(item);
            }
        } else {
            for (int i = 0; i < fleetview_menu_keys.length; i++) {
                JsonObject item = new JsonObject();
                item.addProperty("key", i);
                item.addProperty("value", fleetview_menu_keys[i]);
                item.addProperty("label", getStringWithLocale(KcaUtils.getId(
                        KcaUtils.format("viewmenu_%s", fleetview_menu_keys[i]), R.string.class)));
                data.add(item);
                order_data.add(i);
            }
            setPreferences(getApplicationContext(), PREF_FV_MENU_ORDER, order_data.toString());