Search in sources :

Example 1 with PREF_KCA_DATA_VERSION

use of com.antest1.kcanotify.KcaConstants.PREF_KCA_DATA_VERSION in project kcanotify by antest1.

the class KcaService method handleServiceMessage.

public void handleServiceMessage(Message msg) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
    String url = msg.getData().getString("url");
    byte[] raw = msg.getData().getByteArray("data");
    Reader data = new InputStreamReader(new ByteArrayInputStream(raw));
    String request = msg.getData().getString("request");
    if (!prefs.getBoolean(PREF_SVC_ENABLED, false) || url.length() == 0) {
        return;
    }
    final JsonObject jsonDataObj;
    try {
        String init = new String(Arrays.copyOfRange(raw, 0, 7));
        if (init.contains("svdata=")) {
            data.skip("svdata=".length());
        }
        if (raw.length > 0) {
            JsonElement jsonData = gson.fromJson(data, JsonElement.class);
            if (jsonData.isJsonObject()) {
                jsonDataObj = jsonData.getAsJsonObject();
            } else {
                jsonDataObj = new JsonObject();
            }
        } else
            jsonDataObj = new JsonObject();
        if (url.equals(KCA_API_RESOURCE_URL)) {
            dbHelper.recordErrorLog(ERROR_TYPE_VPN, KCA_API_RESOURCE_URL, "", "", request);
            return;
        }
        if (getBooleanPreferences(getApplicationContext(), PREF_PACKET_LOG)) {
            packetLogger.log(url, request, jsonDataObj.toString());
        }
        if (url.equals(KCA_API_VPN_DATA_ERROR)) {
            // VPN Data Dump Send
            String api_url = jsonDataObj.get("uri").getAsString();
            String api_request = jsonDataObj.get("request").getAsString();
            String api_response = jsonDataObj.get("response").getAsString();
            String api_error = jsonDataObj.get("error").getAsString();
            List<String> filtered_resquest_list = new ArrayList<String>();
            try {
                String[] requestData = api_request.split("&");
                for (int i = 0; i < requestData.length; i++) {
                    String decodedData = URLDecoder.decode(requestData[i], "utf-8");
                    if (!decodedData.startsWith("api_token")) {
                        filtered_resquest_list.add(requestData[i]);
                    }
                }
                api_request = joinStr(filtered_resquest_list, "&");
            } catch (UnsupportedEncodingException e1) {
                e1.printStackTrace();
            }
            makeToast(getStringWithLocale(R.string.service_failed_msg), Toast.LENGTH_SHORT, ContextCompat.getColor(getApplicationContext(), R.color.colorPrimaryDark));
            dbHelper.recordErrorLog(ERROR_TYPE_VPN, api_url, api_request, api_response, api_error);
            return;
        }
        if (url.startsWith(KCA_VERSION)) {
            isPortAccessed = false;
            isInBattle = false;
            api_start2_init = false;
            KcaFleetViewService.setReadyFlag(false);
            // Toast.makeText(contextWithLocale, "KCA_VERSION", Toast.LENGTH_LONG).show();
            String version_data = new String(raw);
            JsonObject api_data = gson.fromJson(version_data, JsonObject.class);
            if (api_data != null && api_data.has("api")) {
                JsonObject api_version = api_data.getAsJsonObject("api");
                kca_version = api_version.get("api_start2").getAsString();
                Log.e("KCA", kca_version);
                setPreferences(getApplicationContext(), PREF_KCA_VERSION, kca_version);
                if (!getStringPreferences(getApplicationContext(), PREF_KCA_DATA_VERSION).equals(kca_version)) {
                    makeToast("new game data detected: " + String.valueOf(kca_version), Toast.LENGTH_LONG, ContextCompat.getColor(getApplicationContext(), R.color.colorPrimaryDark));
                }
            }
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !Settings.canDrawOverlays(getApplicationContext())) {
            // Can not draw overlays: pass
            } else {
                startService(new Intent(this, KcaViewButtonService.class));
                startService(new Intent(this, KcaQuestViewService.class));
                sendQuestCompletionInfo();
            }
            KcaMoraleInfo.initMoraleValue(Integer.parseInt(getStringPreferences(getApplicationContext(), PREF_KCA_MORALE_MIN)));
            return;
        // Toast.makeText(contextWithLocale, getPreferences("kca_version") + " " + String.valueOf(api_start2_down_mode), Toast.LENGTH_LONG).show();
        }
        if (url.startsWith(API_WORLD_GET_WORLDINFO)) {
            makeToast(getStringWithLocale(R.string.kca_toast_server_select), Toast.LENGTH_LONG, ContextCompat.getColor(getApplicationContext(), R.color.colorPrimaryDark));
            return;
        }
        if (url.startsWith(API_WORLD_GET_ID)) {
            return;
        }
        if (url.startsWith(API_REQ_MEMBER_GET_INCENTIVE)) {
            return;
        }
        if (url.equals(API_START2) || url.equals(API_START2_NEW)) {
            if (jsonDataObj.has("api_data")) {
                api_start2_data = jsonDataObj.toString();
                dbHelper.putValue(DB_KEY_STARTDATA, api_start2_data);
                // Toast.makeText(contextWithLocale, "Load Kancolle Data", Toast.LENGTH_LONG).show();
                KcaApiData.getKcGameData(jsonDataObj.getAsJsonObject("api_data"));
                if (kca_version != null) {
                    setPreferences(getApplicationContext(), "kca_version", kca_version);
                }
            }
            return;
        }
        if (url.startsWith(API_GET_MEMBER_REQUIRED_INFO)) {
            // Log.e("KCA", "Load Item Data");
            isInitState = true;
            if (jsonDataObj.has("api_data")) {
                // dbHelper.putValue(DB_KEY_USEREQUIP, jsonDataObj.getAsJsonObject("api_data").getAsJsonArray("api_slot_item").toString());
                JsonObject requiredInfoApiData = jsonDataObj.getAsJsonObject("api_data");
                if (requiredInfoApiData.has("api_useitem")) {
                    dbHelper.putValue(DB_KEY_USEITEMS, requiredInfoApiData.getAsJsonArray("api_useitem").toString());
                } else {
                    dbHelper.putValue(DB_KEY_USEITEMS, new JsonArray().toString());
                }
                dbHelper.putValue(DB_KEY_KDOCKDATA, requiredInfoApiData.getAsJsonArray("api_kdock").toString());
                JsonArray slotitem_data = requiredInfoApiData.getAsJsonArray("api_slot_item");
                int size2 = KcaApiData.putSlotItemDataToDB(slotitem_data);
                Log.e("KCA", "Total Items: " + String.valueOf(size2));
                if (size2 > 0)
                    restartFlag = false;
            }
            return;
        }
        if (url.startsWith(API_GET_MEMBER_USEITEM)) {
            if (jsonDataObj.has("api_data")) {
                dbHelper.putValue(DB_KEY_USEITEMS, jsonDataObj.getAsJsonArray("api_data").toString());
            } else {
                dbHelper.putValue(DB_KEY_USEITEMS, new JsonArray().toString());
            }
        }
        if (url.startsWith(API_GET_MEMBER_DECK)) {
            // Log.e("KCA", "Expedition Handler Called");
            if (jsonDataObj.has("api_data")) {
                dbHelper.putValue(DB_KEY_DECKPORT, jsonDataObj.getAsJsonArray("api_data").toString());
                processExpeditionInfo();
            }
        }
        if (url.startsWith(API_GET_MEMBER_NDOCK)) {
            if (jsonDataObj.has("api_data")) {
                JsonArray api_data = jsonDataObj.getAsJsonArray("api_data");
                KcaDocking.setDockData(api_data);
                dbHelper.putValue(DB_KEY_NDOCKDATA, api_data.toString());
            }
        }
        if (url.startsWith(API_REQ_MISSION_RESULT)) {
            int deck_id = -1;
            String[] requestData = request.split("&");
            for (int i = 0; i < requestData.length; i++) {
                String decodedData = URLDecoder.decode(requestData[i], "utf-8");
                if (decodedData.startsWith("api_deck_id")) {
                    deck_id = Integer.valueOf(decodedData.replace("api_deck_id=", "")) - 1;
                    break;
                }
            }
            int nid = getNotificationId(NOTI_EXP, deck_id);
            Intent deleteIntent = new Intent(this, KcaAlarmService.class).setAction(DELETE_ACTION.concat(String.valueOf(nid)));
            startService(deleteIntent);
            notifiManager.cancel(nid);
            if (jsonDataObj.has("api_data")) {
                JsonObject api_data = jsonDataObj.getAsJsonObject("api_data");
                if (api_data.has("api_clear_result") && api_data.get("api_clear_result").getAsInt() > 0) {
                    questTracker.updateIdCountTracker("402");
                    questTracker.updateIdCountTracker("403");
                    questTracker.updateIdCountTracker("404");
                    String api_name = api_data.get("api_quest_name").getAsString();
                    int api_no = KcaApiData.getExpeditionNoByName(api_name);
                    switch(api_no) {
                        case // 경계임무 (3)
                        3:
                            questTracker.updateIdCountTracker("426", 0);
                            break;
                        case // 대잠경계임무 (4)
                        4:
                            questTracker.updateIdCountTracker("426", 1);
                            questTracker.updateIdCountTracker("428", 0);
                            break;
                        case // 해상호위 (5)
                        5:
                            questTracker.updateIdCountTracker("424");
                            questTracker.updateIdCountTracker("426", 2);
                            break;
                        case // 강행정찰임무 (10)
                        10:
                            questTracker.updateIdCountTracker("426", 3);
                            break;
                        // 도쿄급행 (37, 38)
                        case 37:
                        case 38:
                            questTracker.updateIdCountTracker("410");
                            questTracker.updateIdCountTracker("411");
                            break;
                        case // 해협경계 (A2)
                        101:
                            questTracker.updateIdCountTracker("428", 1);
                            break;
                        case // 장시간대잠 (A3)
                        102:
                            questTracker.updateIdCountTracker("428", 2);
                            break;
                        default:
                            break;
                    }
                    updateQuestView();
                }
                if (api_data.has("api_get_exp")) {
                    dbHelper.updateExpScore(api_data.get("api_get_exp").getAsInt());
                }
            }
        }
        if (url.startsWith(API_REQ_HOKYU_CHARGE)) {
            questTracker.updateIdCountTracker("504");
            updateQuestView();
        }
        if (url.startsWith(API_GET_MEMBER_RECORD)) {
            if (jsonDataObj.has("api_data")) {
                JsonObject api_data = jsonDataObj.getAsJsonObject("api_data");
                JsonArray slotitem = api_data.getAsJsonArray("api_slotitem");
                restartFlag = (slotitem.get(0).getAsInt() != dbHelper.getItemCount());
            }
            return;
        }
        if (url.startsWith(API_PORT)) {
            isPortAccessed = true;
            isFirstState = false;
            stopService(new Intent(this, KcaBattleViewService.class));
            startService(new Intent(this, KcaViewButtonService.class).setAction(KcaViewButtonService.DEACTIVATE_BATTLEVIEW_ACTION));
            startService(new Intent(this, KcaViewButtonService.class).setAction(KcaViewButtonService.RESET_FAIRY_STATUS_ACTION));
            if (jsonDataObj.has("api_data")) {
                JsonObject reqPortApiData = jsonDataObj.getAsJsonObject("api_data");
                if (reqPortApiData.has("api_basic")) {
                    JsonObject prev_basic = dbHelper.getJsonObjectValue(DB_KEY_BASICIFNO);
                    JsonObject current_basic = reqPortApiData.getAsJsonObject("api_basic");
                    if (prev_basic != null && isInitState) {
                        long prev_ts = prev_basic.get("api_starttime").getAsLong();
                        long current_ts = current_basic.get("api_starttime").getAsLong();
                        if (current_ts - prev_ts < 43200000L) {
                            // in 12h
                            int prev_exp = prev_basic.get("api_experience").getAsInt();
                            int current_exp = current_basic.get("api_experience").getAsInt();
                            int diff = current_exp - prev_exp;
                            if (diff >= 0)
                                dbHelper.updateExpScore(current_exp - prev_exp, true);
                        }
                    }
                    isInitState = false;
                }
                KcaApiData.getPortData(reqPortApiData);
                if (reqPortApiData.has("api_deck_port")) {
                    dbHelper.putValue(DB_KEY_DECKPORT, reqPortApiData.getAsJsonArray("api_deck_port").toString());
                    dbHelper.test();
                }
                if (reqPortApiData.has("api_ship")) {
                    final String ship_data = reqPortApiData.get("api_ship").toString();
                    Thread ship_data_thread = new Thread(new Runnable() {

                        @Override
                        public void run() {
                            dbHelper.putValue(DB_KEY_SHIPIFNO, ship_data);
                        }
                    });
                    ship_data_thread.start();
                }
                if (reqPortApiData.has("api_ndock")) {
                    dbHelper.putValue(DB_KEY_NDOCKDATA, reqPortApiData.getAsJsonArray("api_ndock").toString());
                    JsonArray nDockData = reqPortApiData.getAsJsonArray("api_ndock");
                    KcaDocking.setDockData(nDockData);
                    processDockingInfo();
                }
                if (reqPortApiData.has("api_material")) {
                    JsonArray material_data = reqPortApiData.getAsJsonArray("api_material");
                    dbHelper.putValue(DB_KEY_MATERIALS, material_data.toString());
                    recordResourceLog(material_data, true);
                }
            }
        }
        if (url.startsWith(API_REQ_MAP_START) || url.startsWith(API_REQ_MAP_NEXT)) {
            if (jsonDataObj.has("api_data") && isBattleNodeEnabled()) {
                JsonObject api_data = jsonDataObj.getAsJsonObject("api_data");
                int currentMapArea = api_data.get("api_maparea_id").getAsInt();
                int currentMapNo = api_data.get("api_mapinfo_no").getAsInt();
                int currentNode = api_data.get("api_no").getAsInt();
                String currentNodeAlphabet = KcaApiData.getCurrentNodeAlphabet(currentMapArea, currentMapNo, currentNode);
                int api_event_kind = api_data.get("api_event_kind").getAsInt();
                int api_event_id = api_data.get("api_event_id").getAsInt();
                int api_color_no = api_data.get("api_color_no").getAsInt();
                currentNodeInfo = KcaApiData.getNodeFullInfo(contextWithLocale, currentNodeAlphabet, api_event_id, api_event_kind, false);
                makeToast(currentNodeInfo, Toast.LENGTH_LONG, getNodeColor(getApplicationContext(), api_event_id, api_event_kind, api_color_no));
            }
        }
        if (url.startsWith(API_GET_MEMBER_SLOT_ITEM)) {
            if (jsonDataObj.has("api_data")) {
                JsonArray api_data = jsonDataObj.get("api_data").getAsJsonArray();
                KcaApiData.putSlotItemDataToDB(api_data);
                restartFlag = false;
            }
        }
        if (url.equals(API_GET_MEMBER_MATERIAL)) {
            if (jsonDataObj.has("api_data")) {
                JsonArray api_data = jsonDataObj.get("api_data").getAsJsonArray();
                dbHelper.putValue(DB_KEY_MATERIALS, api_data.toString());
                recordResourceLog(api_data, true);
            }
            return;
        }
        if (!API_QUEST_REQS.contains(url) && !url.equals(API_GET_MEMBER_MATERIAL) && KcaQuestViewService.getQuestMode()) {
            startService(new Intent(this, KcaViewButtonService.class).setAction(KcaViewButtonService.DEACTIVATE_QUESTVIEW_ACTION));
            KcaQuestViewService.setQuestMode(false);
            startService(new Intent(this, KcaQuestViewService.class).setAction(KcaQuestViewService.CLOSE_QUESTVIEW_ACTION));
            updateQuestView();
        }
        if (url.startsWith(API_GET_MEMBER_QUESTLIST)) {
            startService(new Intent(this, KcaViewButtonService.class).setAction(KcaViewButtonService.ACTIVATE_QUESTVIEW_ACTION));
            KcaQuestViewService.setQuestMode(true);
            int api_tab_id = -1;
            String[] requestData = request.split("&");
            for (int i = 0; i < requestData.length; i++) {
                String decodedData = URLDecoder.decode(requestData[i], "utf-8");
                if (decodedData.startsWith("api_tab_id")) {
                    api_tab_id = Integer.valueOf(decodedData.replace("api_tab_id=", ""));
                    break;
                }
            }
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !Settings.canDrawOverlays(getApplicationContext())) {
            // Can not draw overlays: pass
            } else if (jsonDataObj.has("api_data")) {
                JsonObject api_data = jsonDataObj.getAsJsonObject("api_data");
                KcaQuestViewService.setApiData(api_data);
                startService(new Intent(getBaseContext(), KcaQuestViewService.class).setAction(REFRESH_QUESTVIEW_ACTION).putExtra("tab_id", api_tab_id));
            }
            sendQuestCompletionInfo();
            return;
        }
        if (url.startsWith(API_REQ_QUEST_CLEARITEMGET)) {
            int quest_id = 0;
            String[] requestData = request.split("&");
            for (int i = 0; i < requestData.length; i++) {
                String decodedData = URLDecoder.decode(requestData[i], "utf-8");
                if (decodedData.startsWith("api_quest_id")) {
                    quest_id = Integer.valueOf(decodedData.replace("api_quest_id=", ""));
                    break;
                }
            }
            Log.e("KCA", "clear " + String.valueOf(quest_id));
            dbHelper.removeQuest(quest_id);
            questTracker.removeQuestTrack(quest_id, true);
            if (quest_id == 212 || quest_id == 218)
                questTracker.clearApDupFlag();
            sendQuestCompletionInfo();
            return;
        }
        // Game Data Dependent Tasks
        if (restartFlag) {
            makeToast(getStringWithLocale(R.string.kca_toast_restart_at_kcanotify), Toast.LENGTH_LONG, ContextCompat.getColor(getApplicationContext(), R.color.colorPrimaryDark));
        } else if (!checkDataLoadTriggered()) {
            makeToast(getStringWithLocale(R.string.kca_toast_get_data_at_settings), Toast.LENGTH_LONG, ContextCompat.getColor(getApplicationContext(), R.color.colorPrimaryDark));
        // new retrieveApiStartData().execute("", "down", "");
        } else {
            if (url.startsWith(API_PORT)) {
                KcaFleetViewService.setReadyFlag(true);
                heavyDamagedMode = HD_NONE;
                currentNodeInfo = "";
                KcaBattle.currentFleet = -1;
                KcaApiData.resetShipCountInBattle();
                KcaApiData.resetItemCountInBattle();
                Log.e("KCA", "Port Handler Called");
                if (jsonDataObj.has("api_data")) {
                    JsonObject reqPortApiData = jsonDataObj.getAsJsonObject("api_data");
                    int size = KcaApiData.getPortData(reqPortApiData);
                    if (reqPortApiData.has("api_combined_flag")) {
                        int combined_flag = reqPortApiData.get("api_combined_flag").getAsInt();
                        isCombined = (combined_flag > 0);
                        KcaBattle.isCombined = isCombined;
                        KcaBattle.cleanEscapeList();
                    }
                    // Log.e("KCA", "Total Ships: " + String.valueOf(size));
                    if (reqPortApiData.has("api_deck_port")) {
                        processExpeditionInfo();
                        JsonArray portdeckdata = reqPortApiData.getAsJsonArray("api_deck_port");
                        KcaMoraleInfo.setDeckCount(portdeckdata.size());
                        for (int i = 0; i < portdeckdata.size(); i++) {
                            boolean result = KcaMoraleInfo.setMoraleValue(i, deckInfoCalc.checkMinimumMorale(portdeckdata, i), isInBattle, false);
                            processMoraleInfo(i, portdeckdata, result);
                        }
                        JsonArray akashi_flagship_deck = deckInfoCalc.checkAkashiFlagship(portdeckdata);
                        boolean is_init_state = KcaAkashiRepairInfo.getAkashiTimerValue() < 0;
                        boolean over_20min = KcaAkashiRepairInfo.getAkashiElapsedTimeInSecond() >= AKASHI_TIMER_20MIN;
                        if (akashi_flagship_deck.size() > 0) {
                            if (is_init_state || over_20min) {
                                KcaAkashiRepairInfo.setAkashiTimer();
                                processAkashiTimerInfo();
                                isAkashiTimerNotiWait = true;
                            }
                        } else {
                            if (!is_init_state && over_20min) {
                                KcaAkashiRepairInfo.initAkashiTimer();
                                processAkashiTimerInfo();
                                isAkashiTimerNotiWait = false;
                            }
                        }
                        KcaAkashiRepairInfo.setAkashiExist(akashi_flagship_deck.size() > 0);
                        updateFleetView();
                    }
                }
                runTimer();
                updateFleetView();
                isInBattle = false;
            }
            if (url.startsWith(API_REQ_MAP_SELECT_EVENTMAP_RANK)) {
                String[] requestData = request.split("&");
                int mapno = 0;
                int rank = 0;
                for (int i = 0; i < requestData.length; i++) {
                    String decodedData = URLDecoder.decode(requestData[i], "utf-8");
                    if (decodedData.startsWith("api_map_no")) {
                        mapno = Integer.valueOf(decodedData.replace("api_map_no=", ""));
                        break;
                    } else if (decodedData.startsWith("api_rank")) {
                        rank = Integer.valueOf(decodedData.replace("api_rank=", ""));
                        break;
                    }
                }
                KcaApiData.setEventMapDifficulty(mapno, rank);
                if (KcaMapHpPopupService.isActive()) {
                    Intent qintent = new Intent(this, KcaMapHpPopupService.class);
                    qintent.setAction(KcaMapHpPopupService.MAPHP_RESET_ACTION);
                    startService(qintent);
                }
            }
            if (url.startsWith(API_GET_MEMBER_MAPINFO) || url.startsWith(API_GET_MEMBER_MISSION)) {
                if (url.startsWith(API_GET_MEMBER_MAPINFO) && jsonDataObj.has("api_data")) {
                    JsonObject api_data = jsonDataObj.getAsJsonObject("api_data");
                    JsonArray api_map_info = api_data.getAsJsonArray("api_map_info");
                    dbHelper.putValue(DB_KEY_APIMAPINFO, api_map_info.toString());
                    if (KcaMapHpPopupService.isActive()) {
                        Intent qintent = new Intent(getBaseContext(), KcaMapHpPopupService.class);
                        qintent.setAction(KcaMapHpPopupService.MAPHP_SHOW_ACTION);
                        startService(qintent);
                    }
                    int eventMapCount = 0;
                    for (JsonElement map : api_map_info) {
                        JsonObject mapData = map.getAsJsonObject();
                        if (mapData.has("api_eventmap")) {
                            eventMapCount += 1;
                            JsonObject eventData = mapData.getAsJsonObject("api_eventmap");
                            if (eventData.has("api_selected_rank"))
                                KcaApiData.setEventMapDifficulty(eventMapCount, eventData.get("api_selected_rank").getAsInt());
                        }
                    }
                    if (api_data.has("api_air_base") && api_data.get("api_air_base").isJsonArray()) {
                        JsonArray api_airbase_info = api_data.getAsJsonArray("api_air_base");
                        dbHelper.putValue(DB_KEY_LABSIFNO, api_airbase_info.toString());
                        updateAirbasePopupInfo();
                    } else {
                        JsonArray api_airbase_info = new JsonArray();
                        dbHelper.putValue(DB_KEY_LABSIFNO, api_airbase_info.toString());
                        updateAirbasePopupInfo();
                    }
                }
                // Notification Part
                String message = "";
                boolean isHeavyDamagedFlag = false;
                boolean isNotSuppliedFlag = false;
                JsonArray portdeckdata = dbHelper.getJsonArrayValue(DB_KEY_DECKPORT);
                if (isCurrentPortDeckDataReady()) {
                    for (int i = 0; i < portdeckdata.size(); i++) {
                        if (url.startsWith(API_GET_MEMBER_MISSION) && i == 0)
                            continue;
                        if (deckInfoCalc.checkNotSuppliedExist(portdeckdata, i)) {
                            isNotSuppliedFlag = true;
                            message = message.concat(KcaUtils.format(getStringWithLocale(R.string.not_supplied), i + 1)).concat("\n");
                        }
                    }
                    if (url.startsWith(API_GET_MEMBER_MAPINFO)) {
                        for (int i = 0; i < portdeckdata.size(); i++) {
                            int checkvalue = deckInfoCalc.checkHeavyDamageExist(portdeckdata, i);
                            switch(checkvalue) {
                                case HD_DAMECON:
                                case HD_DANGER:
                                    isHeavyDamagedFlag = true;
                                    if (checkvalue == HD_DANGER) {
                                        message = message.concat(KcaUtils.format("[#%d] %s", i + 1, getStringWithLocale(R.string.heavy_damaged))).concat("\n");
                                    } else if (checkvalue == HD_DAMECON) {
                                        message = message.concat(KcaUtils.format("[#%d] %s", i + 1, getStringWithLocale(R.string.heavy_damaged_damecon))).concat("\n");
                                    }
                                    break;
                                default:
                                    break;
                            }
                        }
                    }
                    if (message.length() > 0) {
                        boolean hcondition = (isHeavyDamagedFlag && isHDVibrateEnabled());
                        boolean ncondition = (isNotSuppliedFlag && isNSVibrateEnabled());
                        if (hcondition || ncondition) {
                            String soundKind = getStringPreferences(getApplicationContext(), PREF_KCA_NOTI_SOUND_KIND);
                            if (soundKind.equals(getString(R.string.sound_kind_value_normal)) || soundKind.equals(getString(R.string.sound_kind_value_mixed))) {
                                if (mAudioManager.getRingerMode() == AudioManager.RINGER_MODE_NORMAL) {
                                    Uri notificationUri = KcaUtils.getContentUri(getApplicationContext(), Uri.parse(getStringPreferences(getApplicationContext(), PREF_KCA_NOTI_RINGTONE)));
                                    Log.e("KCA", getStringPreferences(getApplicationContext(), PREF_KCA_NOTI_RINGTONE));
                                    KcaUtils.playNotificationSound(mediaPlayer, getApplicationContext(), notificationUri);
                                }
                            }
                            doVibrate(vibrator, 1000);
                        }
                        int toastColor;
                        if (hcondition)
                            toastColor = R.color.colorHeavyDmgStatePanel;
                        else
                            toastColor = R.color.colorWarningPanel;
                        makeToast(message.trim(), Toast.LENGTH_LONG, ContextCompat.getColor(getApplicationContext(), toastColor));
                    }
                }
            }
            if (url.startsWith(API_GET_MEMBER_MAPINFO) || url.startsWith(API_GET_MEMBER_PRACTICE)) {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !Settings.canDrawOverlays(getApplicationContext())) {
                // Can not draw overlays: pass
                } else {
                    Intent qintent = new Intent(this, KcaBattleViewService.class);
                    startService(qintent);
                }
            }
            if (API_BATTLE_REQS.contains(url) && isCurrentPortDeckDataReady()) {
                if (jsonDataObj.has("api_data")) {
                    JsonObject battleApiData = jsonDataObj.getAsJsonObject("api_data");
                    if (url.equals(API_REQ_MAP_START) || url.equals(API_REQ_PRACTICE_BATTLE)) {
                        JsonArray portdeckdata = dbHelper.getJsonArrayValue(DB_KEY_DECKPORT);
                        isInBattle = true;
                        int deck_id = -1;
                        String[] requestData = request.split("&");
                        for (int i = 0; i < requestData.length; i++) {
                            String decodedData = URLDecoder.decode(requestData[i], "utf-8");
                            if (decodedData.startsWith("api_deck_id")) {
                                deck_id = Integer.valueOf(decodedData.replace("api_deck_id=", "")) - 1;
                                break;
                            }
                        }
                        if (deck_id != -1) {
                            KcaBattle.currentFleet = deck_id;
                        }
                        JsonObject api_data = new JsonObject();
                        JsonArray api_deck_data = new JsonArray();
                        JsonArray api_ship_data = new JsonArray();
                        int checkvalue = 0;
                        if (deck_id == 0 && isCombined) {
                            JsonObject first = portdeckdata.get(0).getAsJsonObject();
                            JsonObject second = portdeckdata.get(1).getAsJsonObject();
                            api_deck_data.add(first);
                            JsonArray firstShipInfo = first.getAsJsonArray("api_ship");
                            for (JsonElement e : firstShipInfo) {
                                int ship_id = e.getAsInt();
                                if (ship_id != -1)
                                    api_ship_data.add(KcaApiData.getUserShipDataById(ship_id, "all"));
                            }
                            api_deck_data.add(second);
                            JsonArray secondShipInfo = second.getAsJsonArray("api_ship");
                            for (JsonElement e : secondShipInfo) {
                                int ship_id = e.getAsInt();
                                if (ship_id != -1)
                                    api_ship_data.add(KcaApiData.getUserShipDataById(ship_id, "all"));
                            }
                            KcaBattle.checkhdmgflag = deckInfoCalc.getHeavyDmgCheckStatus(api_deck_data, 0);
                            KcaBattle.checkhdmgcbflag = deckInfoCalc.getHeavyDmgCheckStatus(api_deck_data, 1);
                            KcaBattle.dameconflag = deckInfoCalc.getDameconStatus(api_deck_data, 0);
                            KcaBattle.dameconcbflag = deckInfoCalc.getDameconStatus(api_deck_data, 1);
                            int firstHeavyDamaged = deckInfoCalc.checkHeavyDamageExist(portdeckdata, 0);
                            int secondHeavyDamaged = 0;
                            if (portdeckdata.size() >= 2) {
                                secondHeavyDamaged = deckInfoCalc.checkHeavyDamageExist(portdeckdata, 1);
                            }
                            checkvalue = Math.max(firstHeavyDamaged, secondHeavyDamaged);
                        } else {
                            JsonObject fleet = portdeckdata.get(deck_id).getAsJsonObject();
                            int fleetHeavyDamaged = deckInfoCalc.checkHeavyDamageExist(portdeckdata, deck_id);
                            checkvalue = fleetHeavyDamaged;
                            api_deck_data.add(fleet);
                            JsonArray firstShipInfo = fleet.getAsJsonArray("api_ship");
                            for (JsonElement e : firstShipInfo) {
                                int ship_id = e.getAsInt();
                                if (ship_id != -1)
                                    api_ship_data.add(KcaApiData.getUserShipDataById(ship_id, "all"));
                            }
                            KcaBattle.checkhdmgflag = deckInfoCalc.getHeavyDmgCheckStatus(api_deck_data, 0);
                            KcaBattle.dameconflag = deckInfoCalc.getDameconStatus(api_deck_data, 0);
                        }
                        api_data.add("api_deck_data", api_deck_data);
                        api_data.add("api_ship_data", api_ship_data);
                        KcaBattle.setDeckPortData(api_data);
                        KcaBattle.setStartHeavyDamageExist(checkvalue);
                        if (isBattleViewEnabled()) {
                            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !Settings.canDrawOverlays(getApplicationContext())) {
                            // Can not draw overlays: pass
                            } else {
                                startService(new Intent(this, KcaViewButtonService.class).setAction(KcaViewButtonService.ACTIVATE_BATTLEVIEW_ACTION));
                                startService(new Intent(this, KcaBattleViewService.class));
                            }
                        }
                    }
                    KcaBattle.processData(dbHelper, url, battleApiData);
                } else if (url.equals(API_REQ_COMBINED_GOBACKPORT) || url.equals(API_REQ_SORTIE_GOBACKPORT)) {
                    KcaBattle.processData(dbHelper, url, null);
                }
                updateFleetView();
            }
            if (url.startsWith(API_GET_MEMBER_SHIP_DECK) && isCurrentPortDeckDataReady()) {
                if (jsonDataObj.has("api_data")) {
                    JsonObject api_data = jsonDataObj.getAsJsonObject("api_data");
                    JsonArray api_deck_data = (JsonArray) api_data.get("api_deck_data");
                    KcaApiData.updatePortDataOnBattle(api_data);
                    for (int i = 0; i < api_deck_data.size(); i++) {
                        if (i == 0) {
                            KcaBattle.dameconflag = deckInfoCalc.getDameconStatus(api_deck_data, 0);
                        } else if (i == 1) {
                            KcaBattle.dameconcbflag = deckInfoCalc.getDameconStatus(api_deck_data, 1);
                        }
                    }
                    KcaBattle.setDeckPortData(api_data);
                    updateFleetView();
                }
            }
            if (url.startsWith(API_REQ_MISSION_RETURN)) {
                // Log.e("KCA", "Expedition Handler Called");
                if (jsonDataObj.has("api_data")) {
                    JsonObject reqGetMemberDeckApiData = jsonDataObj.getAsJsonObject("api_data");
                    cancelExpeditionInfo(reqGetMemberDeckApiData);
                }
            }
            if (url.startsWith(API_REQ_MEMBER_GET_PRACTICE_ENEMYINFO)) {
                if (jsonDataObj.has("api_data")) {
                    JsonObject api_data = jsonDataObj.getAsJsonObject("api_data");
                    KcaBattle.currentEnemyDeckName = api_data.get("api_deckname").getAsString();
                }
            }
            if (url.startsWith(API_REQ_HOKYU_CHARGE)) {
                if (jsonDataObj.has("api_data")) {
                    JsonObject api_data = jsonDataObj.getAsJsonObject("api_data");
                    KcaApiData.updateSuppliedUserShip(api_data.getAsJsonArray("api_ship"));
                }
            }
            if (url.startsWith(API_GET_MEMBER_NDOCK)) {
                processDockingInfo();
                updateFleetView();
            }
            if (url.startsWith(API_REQ_NYUKYO_SPEEDCHAGNE)) {
                int ndock_id = -1;
                String[] requestData = request.split("&");
                for (int i = 0; i < requestData.length; i++) {
                    String decodedData = URLDecoder.decode(requestData[i], "utf-8");
                    if (decodedData.startsWith("api_ndock_id")) {
                        ndock_id = Integer.valueOf(decodedData.replace("api_ndock_id=", "")) - 1;
                        break;
                    }
                }
                if (ndock_id != -1)
                    processDockingSpeedup(ndock_id);
                updateFleetView();
            }
            if (url.startsWith(API_REQ_NYUKYO_START)) {
                questTracker.updateIdCountTracker("503");
                updateQuestView();
                int ship_id = -1;
                int highspeed = -1;
                String[] requestData = request.split("&");
                for (int i = 0; i < requestData.length; i++) {
                    String decodedData = URLDecoder.decode(requestData[i], "utf-8");
                    if (decodedData.startsWith("api_ship_id")) {
                        ship_id = Integer.valueOf(decodedData.replace("api_ship_id=", ""));
                    } else if (decodedData.startsWith("api_highspeed")) {
                        highspeed = Integer.valueOf(decodedData.replace("api_highspeed=", ""));
                    }
                }
                KcaApiData.updateShipMorale(ship_id);
                JsonArray portdeckdata = dbHelper.getJsonArrayValue(DB_KEY_DECKPORT);
                int check_in_deck = deckInfoCalc.checkShipInDeck(portdeckdata, ship_id);
                if (check_in_deck != -1) {
                    boolean result = setMoraleValue(check_in_deck, deckInfoCalc.checkMinimumMorale(portdeckdata, check_in_deck), false, false);
                    processMoraleInfo(check_in_deck, portdeckdata, result);
                }
                if (highspeed > 0)
                    KcaApiData.updateShipHpFull(ship_id);
                updateFleetView();
            }
            if (url.startsWith(API_REQ_AIR_CORPS_SETPLANE)) {
                int target_area_id = 0;
                int target_base_id = 0;
                String[] requestData = request.split("&");
                for (int i = 0; i < requestData.length; i++) {
                    String decodedData = URLDecoder.decode(requestData[i], "utf-8");
                    if (decodedData.startsWith("api_area_id")) {
                        target_area_id = Integer.valueOf(decodedData.replace("api_area_id=", ""));
                    } else if (decodedData.startsWith("api_base_id")) {
                        target_base_id = Integer.valueOf(decodedData.replace("api_base_id=", ""));
                    }
                }
                int new_distance = -1;
                JsonObject distance_data = new JsonObject();
                JsonArray api_plane_info = new JsonArray();
                if (jsonDataObj.has("api_data")) {
                    JsonObject api_data = jsonDataObj.getAsJsonObject("api_data");
                    api_plane_info = api_data.getAsJsonArray("api_plane_info");
                    distance_data = api_data.getAsJsonObject("api_distance");
                }
                JsonArray airbase_data = dbHelper.getJsonArrayValue(DB_KEY_LABSIFNO);
                if (airbase_data != null) {
                    for (int i = 0; i < airbase_data.size(); i++) {
                        JsonObject airbase_item = airbase_data.get(i).getAsJsonObject();
                        int area_id = airbase_item.get("api_area_id").getAsInt();
                        int rid = airbase_item.get("api_rid").getAsInt();
                        if (area_id == target_area_id && rid == target_base_id) {
                            airbase_item.add("api_distance", distance_data);
                            JsonArray airbase_plane_info = airbase_item.getAsJsonArray("api_plane_info");
                            for (int j = 0; j < api_plane_info.size(); j++) {
                                JsonObject plane_item = api_plane_info.get(j).getAsJsonObject();
                                int plane_item_id = plane_item.get("api_squadron_id").getAsInt();
                                for (int k = 0; k < airbase_plane_info.size(); k++) {
                                    JsonObject target_plane_item = airbase_plane_info.get(k).getAsJsonObject();
                                    if (target_plane_item.get("api_squadron_id").getAsInt() == plane_item_id) {
                                        airbase_plane_info.set(k, plane_item);
                                        break;
                                    }
                                }
                            }
                            break;
                        }
                    }
                    dbHelper.putValue(DB_KEY_LABSIFNO, airbase_data.toString());
                    updateAirbasePopupInfo();
                }
            }
            if (url.startsWith(API_REQ_AIR_CORPS_CHANGENAME)) {
                int target_area_id = 0;
                int target_base_id = 0;
                String new_name = "";
                String[] requestData = request.split("&");
                for (int i = 0; i < requestData.length; i++) {
                    String decodedData = URLDecoder.decode(requestData[i], "utf-8");
                    if (decodedData.startsWith("api_area_id")) {
                        target_area_id = Integer.valueOf(decodedData.replace("api_area_id=", ""));
                    } else if (decodedData.startsWith("api_base_id")) {
                        target_base_id = Integer.valueOf(decodedData.replace("api_base_id=", ""));
                    } else if (decodedData.startsWith("api_name")) {
                        new_name = decodedData.replace("api_name=", "");
                    }
                }
                JsonArray airbase_data = dbHelper.getJsonArrayValue(DB_KEY_LABSIFNO);
                if (airbase_data != null) {
                    for (int i = 0; i < airbase_data.size(); i++) {
                        JsonObject airbase_item = airbase_data.get(i).getAsJsonObject();
                        int area_id = airbase_item.get("api_area_id").getAsInt();
                        int rid = airbase_item.get("api_rid").getAsInt();
                        if (area_id == target_area_id && rid == target_base_id) {
                            airbase_item.addProperty("api_name", new_name);
                            break;
                        }
                    }
                    dbHelper.putValue(DB_KEY_LABSIFNO, airbase_data.toString());
                    updateAirbasePopupInfo();
                }
            }
            if (url.startsWith(API_REQ_AIR_CORPS_SETACTION)) {
                int target_area_id = 0;
                String target_base_id = "";
                String new_action_kind = "";
                String[] requestData = request.split("&");
                for (int i = 0; i < requestData.length; i++) {
                    String decodedData = URLDecoder.decode(requestData[i], "utf-8");
                    if (decodedData.startsWith("api_area_id")) {
                        target_area_id = Integer.valueOf(decodedData.replace("api_area_id=", ""));
                    } else if (decodedData.startsWith("api_base_id")) {
                        target_base_id = decodedData.replace("api_base_id=", "");
                    } else if (decodedData.startsWith("api_action_kind")) {
                        new_action_kind = decodedData.replace("api_action_kind=", "");
                    }
                }
                String[] target_base_list = target_base_id.split(",");
                String[] new_action_list = new_action_kind.split(",");
                JsonArray airbase_data = dbHelper.getJsonArrayValue(DB_KEY_LABSIFNO);
                if (airbase_data != null) {
                    for (int i = 0; i < airbase_data.size(); i++) {
                        JsonObject airbase_item = airbase_data.get(i).getAsJsonObject();
                        int area_id = airbase_item.get("api_area_id").getAsInt();
                        int rid = airbase_item.get("api_rid").getAsInt();
                        for (int j = 0; j < target_base_list.length; j++) {
                            int target_base = Integer.parseInt(target_base_list[j]);
                            if (area_id == target_area_id && rid == target_base) {
                                airbase_item.addProperty("api_action_kind", Integer.parseInt(new_action_list[j]));
                                break;
                            }
                        }
                    }
                    dbHelper.putValue(DB_KEY_LABSIFNO, airbase_data.toString());
                    updateAirbasePopupInfo();
                }
            }
            if (url.startsWith(API_REQ_AIR_CORPS_SUPPLY)) {
                int target_area_id = 0;
                int target_base_id = 0;
                String[] requestData = request.split("&");
                for (int i = 0; i < requestData.length; i++) {
                    String decodedData = URLDecoder.decode(requestData[i], "utf-8");
                    if (decodedData.startsWith("api_area_id")) {
                        target_area_id = Integer.valueOf(decodedData.replace("api_area_id=", ""));
                    } else if (decodedData.startsWith("api_base_id")) {
                        target_base_id = Integer.valueOf(decodedData.replace("api_base_id=", ""));
                    }
                }
                JsonArray api_plane_info = new JsonArray();
                if (jsonDataObj.has("api_data")) {
                    JsonObject api_data = jsonDataObj.getAsJsonObject("api_data");
                    api_plane_info = api_data.getAsJsonArray("api_plane_info");
                }
                JsonArray airbase_data = dbHelper.getJsonArrayValue(DB_KEY_LABSIFNO);
                if (airbase_data != null) {
                    for (int i = 0; i < airbase_data.size(); i++) {
                        JsonObject airbase_item = airbase_data.get(i).getAsJsonObject();
                        int area_id = airbase_item.get("api_area_id").getAsInt();
                        int rid = airbase_item.get("api_rid").getAsInt();
                        if (area_id == target_area_id && rid == target_base_id) {
                            JsonArray airbase_plane_info = airbase_item.getAsJsonArray("api_plane_info");
                            for (int j = 0; j < api_plane_info.size(); j++) {
                                JsonObject plane_item = api_plane_info.get(j).getAsJsonObject();
                                int plane_item_id = plane_item.get("api_squadron_id").getAsInt();
                                for (int k = 0; k < airbase_plane_info.size(); k++) {
                                    JsonObject target_plane_item = airbase_plane_info.get(k).getAsJsonObject();
                                    if (target_plane_item.get("api_squadron_id").getAsInt() == plane_item_id) {
                                        airbase_plane_info.set(k, plane_item);
                                        break;
                                    }
                                }
                            }
                            break;
                        }
                    }
                    dbHelper.putValue(DB_KEY_LABSIFNO, airbase_data.toString());
                    updateAirbasePopupInfo();
                }
            }
            if (url.startsWith(API_REQ_AIR_CORPS_EXPANDBASE)) {
                JsonObject api_base_info = new JsonObject();
                if (jsonDataObj.has("api_data")) {
                    api_base_info = jsonDataObj.getAsJsonObject("api_data");
                }
                JsonArray airbase_data = dbHelper.getJsonArrayValue(DB_KEY_LABSIFNO);
                if (airbase_data != null) {
                    airbase_data.add(api_base_info);
                    dbHelper.putValue(DB_KEY_LABSIFNO, airbase_data.toString());
                    updateAirbasePopupInfo();
                }
            }
            if (isCurrentPortDeckDataReady()) {
                if (url.startsWith(API_REQ_KOUSYOU_CREATEITEM)) {
                    String[] requestData = request.split("&");
                    int[] materials = { 0, 0, 0, 0 };
                    JsonArray portdeckdata = dbHelper.getJsonArrayValue(DB_KEY_DECKPORT);
                    int flagship = deckInfoCalc.getKcShipList(portdeckdata, 0)[0];
                    for (int i = 0; i < requestData.length; i++) {
                        String decodedData = URLDecoder.decode(requestData[i], "utf-8");
                        if (decodedData.startsWith("api_item1")) {
                            materials[0] = Integer.valueOf(decodedData.replace("api_item1=", ""));
                        }
                        if (decodedData.startsWith("api_item2")) {
                            materials[1] = Integer.valueOf(decodedData.replace("api_item2=", ""));
                        }
                        if (decodedData.startsWith("api_item3")) {
                            materials[2] = Integer.valueOf(decodedData.replace("api_item3=", ""));
                        }
                        if (decodedData.startsWith("api_item4")) {
                            materials[3] = Integer.valueOf(decodedData.replace("api_item4=", ""));
                        }
                    }
                    if (jsonDataObj.has("api_data")) {
                        JsonObject api_data = jsonDataObj.getAsJsonObject("api_data");
                        // int itemKcId = KcaApiData.updateSlotItemData(api_data);
                        JsonArray devInfo = KcaApiData.updateDevelopItemData(api_data);
                        for (int i = 0; i < devInfo.size(); i++) {
                            questTracker.updateIdCountTracker("605");
                            questTracker.updateIdCountTracker("607");
                            JsonObject dev_instance = devInfo.get(i).getAsJsonObject();
                            boolean createFlag = dev_instance.get("api_id").getAsInt() > 0;
                            int itemKcId = dev_instance.get("api_slotitem_id").getAsInt();
                            int itemFailKcId = 0;
                            if (isPoiDBEnabled())
                                KcaPoiDBAPI.sendEquipDevData(Arrays.toString(materials), flagship, createFlag ? itemKcId : itemFailKcId, getAdmiralLevel(), createFlag);
                        }
                        updateQuestView();
                        JsonArray material_data = api_data.getAsJsonArray("api_material");
                        recordResourceLog(material_data, false);
                        JsonObject shipData = KcaApiData.getKcShipDataById(flagship, "name");
                        String shipname = shipData.get("name").getAsString();
                        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                        String timetext = dateFormat.format(new Date());
                        JsonObject equipdevdata = new JsonObject();
                        equipdevdata.addProperty("flagship", shipname);
                        equipdevdata.addProperty("time", timetext);
                        equipdevdata.add("items", new JsonArray());
                        for (int i = 0; i < devInfo.size(); i++) {
                            String itemname = "";
                            int itemtype = 0;
                            String itemcount = "";
                            JsonObject dev_instance = devInfo.get(i).getAsJsonObject();
                            int itemKcId = dev_instance.get("api_slotitem_id").getAsInt();
                            boolean createFlag = dev_instance.get("api_id").getAsInt() > 0;
                            if (createFlag) {
                                JsonObject itemData = KcaApiData.getKcItemStatusById(itemKcId, "name,type");
                                itemname = itemData.get("name").getAsString();
                                itemtype = itemData.get("type").getAsJsonArray().get(3).getAsInt();
                                itemcount = KcaUtils.format("(%d)", KcaApiData.getItemCountByKcId(itemKcId));
                            } else {
                                itemname = "item_fail";
                                itemtype = 999;
                            }
                            dev_instance.addProperty("name", itemname);
                            dev_instance.addProperty("type", itemtype);
                            dev_instance.addProperty("count", itemcount);
                            equipdevdata.getAsJsonArray("items").add(dev_instance);
                        }
                        dbHelper.putValue(DB_KEY_LATESTDEV, equipdevdata.toString());
                        if (KcaDevelopPopupService.isActive()) {
                            Intent qintent = new Intent(getBaseContext(), KcaDevelopPopupService.class);
                            qintent.setAction(KcaDevelopPopupService.DEV_DATA_ACTION);
                            qintent.putExtra("data", equipdevdata.toString());
                            startService(qintent);
                        }
                    }
                }
                if (url.startsWith(API_REQ_KOUSYOU_DESTROYITEM)) {
                    String[] requestData = request.split("&");
                    for (int i = 0; i < requestData.length; i++) {
                        String decodedData = URLDecoder.decode(requestData[i], "utf-8");
                        if (decodedData.startsWith("api_slotitem_ids")) {
                            String itemlist = decodedData.replace("api_slotitem_ids=", "");
                            String[] itemlist_array = itemlist.split(",");
                            for (String item : itemlist_array) {
                                JsonObject status = getUserItemStatusById(Integer.parseInt(item), "lv,alv", "id,type");
                                if (status != null && status.has("id")) {
                                    int item_id = status.get("id").getAsInt();
                                    switch(item_id) {
                                        case // Type 96 Fighter
                                        19:
                                            questTracker.updateIdCountTracker("678", 0);
                                        case // Type 0 Model 21
                                        20:
                                            questTracker.updateIdCountTracker("678", 1);
                                        default:
                                            break;
                                    }
                                }
                                if (status != null && status.has("type")) {
                                    switch(status.getAsJsonArray("type").get(2).getAsInt()) {
                                        case T2_GUN_SMALL:
                                            questTracker.updateIdCountTracker("673");
                                            break;
                                        case T2_GUN_MEDIUM:
                                            questTracker.updateIdCountTracker("676", 0);
                                            break;
                                        case T2_SUB_GUN:
                                            questTracker.updateIdCountTracker("676", 1);
                                            break;
                                        case T2_TORPEDO:
                                            questTracker.updateIdCountTracker("677", 2);
                                            break;
                                        case T2_FIGHTER:
                                            questTracker.updateIdCountTracker("675", 0);
                                            break;
                                        case T2_SEA_SCOUT:
                                            questTracker.updateIdCountTracker("677", 1);
                                            break;
                                        case T2_MACHINE_GUN:
                                            questTracker.updateIdCountTracker("638");
                                            questTracker.updateIdCountTracker("674");
                                            questTracker.updateIdCountTracker("675", 1);
                                            questTracker.updateIdCountTracker("680", 0);
                                            break;
                                        case T2_RADAR_SMALL:
                                        case T2_RADAR_LARGE:
                                        case T2_RADER_LARGE_II:
                                            questTracker.updateIdCountTracker("680", 1);
                                            break;
                                        case T2_GUN_LARGE:
                                        case T2_GUN_LARGE_II:
                                            questTracker.updateIdCountTracker("663");
                                            questTracker.updateIdCountTracker("677", 0);
                                            break;
                                        case T2_DRUM_CAN:
                                            questTracker.updateIdCountTracker("676", 2);
                                            break;
                                        default:
                                            break;
                                    }
                                }
                            }
                            KcaApiData.removeSlotItemData(itemlist);
                            break;
                        }
                    }
                    questTracker.updateIdCountTracker("613");
                    updateQuestView();
                    updateFleetView();
                }
                if (url.equals(API_REQ_KOUSYOU_CREATESHIP)) {
                    String[] requestData = request.split("&");
                    for (int i = 0; i < requestData.length; i++) {
                        String decodedData = URLDecoder.decode(requestData[i], "utf-8");
                        if (decodedData.startsWith("api_kdock_id=")) {
                            checkKdockId = Integer.valueOf(decodedData.replace("api_kdock_id=", "")) - 1;
                        } else if (decodedData.startsWith("api_highspeed=")) {
                            checkHighSpeed = Integer.valueOf(decodedData.replace("api_highspeed=", ""));
                        } else if (decodedData.startsWith("api_large_flag=")) {
                            checkLargeFlag = Integer.valueOf(decodedData.replace("api_large_flag=", ""));
                        }
                    }
                    questTracker.updateIdCountTracker("606");
                    questTracker.updateIdCountTracker("608");
                    updateQuestView();
                }
                if (url.equals(API_REQ_KOUSYOU_CREATESHIP_SPEEDCHANGE)) {
                    int kdockid = -1;
                    String[] requestData = request.split("&");
                    for (int i = 0; i < requestData.length; i++) {
                        String decodedData = URLDecoder.decode(requestData[i], "utf-8");
                        if (decodedData.startsWith("api_kdock_id=")) {
                            kdockid = Integer.valueOf(decodedData.replace("api_kdock_id=", "")) - 1;
                            break;
                        }
                    }
                    Log.e("KCA-S", "" + kdockid);
                    if (kdockid > -1) {
                        JsonArray kdata = dbHelper.getJsonArrayValue(DB_KEY_KDOCKDATA);
                        if (kdata != null) {
                            JsonObject item = kdata.get(kdockid).getAsJsonObject();
                            item.addProperty("api_complete_time", 0);
                            kdata.set(kdockid, item);
                        }
                        dbHelper.putValue(DB_KEY_KDOCKDATA, kdata.toString());
                    }
                }
                if (url.startsWith(API_REQ_KOUSYOU_GETSHIP)) {
                    if (jsonDataObj.has("api_data")) {
                        JsonObject api_data = jsonDataObj.getAsJsonObject("api_data");
                        KcaApiData.addUserShip(api_data);
                        JsonArray api_kdock = api_data.getAsJsonArray("api_kdock");
                        dbHelper.putValue(DB_KEY_KDOCKDATA, api_kdock.toString());
                    }
                }
                if (url.startsWith(API_REQ_KAISOU_SLOTSET)) {
                    kaisouProcessFlag = true;
                }
                if (url.startsWith(API_REQ_KAISOU_SLOTSET_EX)) {
                    kaisouProcessFlag = true;
                }
                if (url.startsWith(API_REQ_KAISOU_UNSLOTSET_ALL)) {
                    kaisouProcessFlag = true;
                }
                if (url.startsWith(API_GET_MEMBER_KDOCK)) {
                    Log.e("KCA", String.valueOf(checkKdockId));
                    if (jsonDataObj.has("api_data")) {
                        JsonArray api_data = jsonDataObj.getAsJsonArray("api_data");
                        dbHelper.putValue(DB_KEY_KDOCKDATA, api_data.toString());
                        if (checkKdockId != -1) {
                            JsonObject api_kdock_item = api_data.get(checkKdockId).getAsJsonObject();
                            JsonArray portdeckdata = dbHelper.getJsonArrayValue(DB_KEY_DECKPORT);
                            int flagship = deckInfoCalc.getKcShipList(portdeckdata, 0)[0];
                            int[] materials = { 0, 0, 0, 0, 0 };
                            for (int i = 0; i < materials.length; i++) {
                                materials[i] = api_kdock_item.get(KcaUtils.format("api_item%d", i + 1)).getAsInt();
                            }
                            int created_ship_id = api_kdock_item.get("api_created_ship_id").getAsInt();
                            if (isPoiDBEnabled())
                                KcaPoiDBAPI.sendShipDevData(Arrays.toString(materials), checkKdockId, flagship, created_ship_id, checkHighSpeed, getAdmiralLevel(), checkLargeFlag);
                            checkKdockId = -1;
                            checkLargeFlag = -1;
                            checkHighSpeed = -1;
                        }
                    }
                }
                if (url.startsWith(API_REQ_KOUSYOU_DESTROYSHIP)) {
                    String targetShip = "";
                    int slotDestFlag = 0;
                    String[] requestData = request.split("&");
                    for (int i = 0; i < requestData.length; i++) {
                        String decodedData = URLDecoder.decode(requestData[i], "utf-8");
                        if (decodedData.startsWith("api_ship_id")) {
                            targetShip = decodedData.replace("api_ship_id=", "");
                        } else if (decodedData.startsWith("api_slot_dest_flag")) {
                            slotDestFlag = Integer.parseInt(decodedData.replace("api_slot_dest_flag=", ""));
                        }
                    }
                    KcaApiData.deleteUserShip(targetShip, slotDestFlag);
                    String[] targetShipList = targetShip.split(",");
                    JsonArray portdeckdata = dbHelper.getJsonArrayValue(DB_KEY_DECKPORT);
                    for (int i = 0; i < portdeckdata.size(); i++) {
                        JsonObject deckData = portdeckdata.get(i).getAsJsonObject();
                        JsonArray deckShipData = deckData.get("api_ship").getAsJsonArray();
                        for (int j = 0; j < deckShipData.size(); j++) {
                            for (int k = 0; k < targetShipList.length; k++) {
                                if (targetShipList[k].equals(String.valueOf(deckShipData.get(j).getAsInt()))) {
                                    deckShipData.set(j, new JsonPrimitive(-1));
                                    deckData.add("api_ship", deckShipData);
                                    portdeckdata.set(i, deckData);
                                }
                            }
                        }
                    }
                    dbHelper.putValue(DB_KEY_DECKPORT, portdeckdata.toString());
                    for (int i = 0; i < targetShipList.length; i++) {
                        questTracker.updateIdCountTracker("609");
                    }
                    updateQuestView();
                    updateFleetView();
                }
                if (url.startsWith(API_REQ_HENSEI_CHANGE)) {
                    String[] requestData = request.split("&");
                    int deckIdx = -1;
                    int shipIdx = -1;
                    int shipId = -3;
                    int originalDeckIdx = -1;
                    int originalShipIdx = -1;
                    boolean in_change = false;
                    for (int i = 0; i < requestData.length; i++) {
                        String decodedData = URLDecoder.decode(requestData[i], "utf-8");
                        if (decodedData.startsWith("api_ship_idx=")) {
                            shipIdx = Integer.valueOf(decodedData.replace("api_ship_idx=", ""));
                        } else if (decodedData.startsWith("api_ship_id=")) {
                            shipId = Integer.valueOf(decodedData.replace("api_ship_id=", ""));
                        } else if (decodedData.startsWith("api_id=")) {
                            deckIdx = Integer.valueOf(decodedData.replace("api_id=", "")) - 1;
                        }
                    }
                    if (deckIdx != -1) {
                        JsonArray portdeckdata = dbHelper.getJsonArrayValue(DB_KEY_DECKPORT);
                        JsonObject targetDeckIdxData = portdeckdata.get(deckIdx).getAsJsonObject();
                        JsonArray targetDeckIdxShipIdata = targetDeckIdxData.get("api_ship").getAsJsonArray();
                        if (shipId == -2) {
                            in_change = true;
                            for (int i = 1; i < targetDeckIdxShipIdata.size(); i++) {
                                targetDeckIdxShipIdata.set(i, new JsonPrimitive(-1));
                            }
                        } else if (shipId == -1) {
                            // remove ship
                            in_change = true;
                            targetDeckIdxShipIdata.remove(shipIdx);
                            targetDeckIdxShipIdata.add(new JsonPrimitive(-1));
                        } else {
                            // check whether target ship is in deck
                            for (int i = 0; i < portdeckdata.size(); i++) {
                                JsonArray deckData = portdeckdata.get(i).getAsJsonObject().get("api_ship").getAsJsonArray();
                                for (int j = 0; j < deckData.size(); j++) {
                                    if (shipId == deckData.get(j).getAsInt()) {
                                        originalDeckIdx = i;
                                        originalShipIdx = j;
                                        break;
                                    }
                                }
                            }
                            if (originalDeckIdx != -1) {
                                // if in deck
                                JsonObject sourceDeckIdxData = portdeckdata.get(originalDeckIdx).getAsJsonObject();
                                JsonArray sourceDeckIdxShipIdata = sourceDeckIdxData.get("api_ship").getAsJsonArray();
                                JsonElement replacement = targetDeckIdxShipIdata.get(shipIdx);
                                if (replacement.getAsInt() != -1) {
                                    sourceDeckIdxShipIdata.set(originalShipIdx, replacement);
                                } else {
                                    sourceDeckIdxShipIdata.remove(originalShipIdx);
                                    sourceDeckIdxShipIdata.add(new JsonPrimitive(-1));
                                    sourceDeckIdxData.add("api_ship", sourceDeckIdxShipIdata);
                                    portdeckdata.set(originalDeckIdx, sourceDeckIdxData);
                                }
                            }
                            // replace
                            targetDeckIdxShipIdata.set(shipIdx, new JsonPrimitive(shipId));
                        }
                        targetDeckIdxData.add("api_ship", targetDeckIdxShipIdata);
                        portdeckdata.set(deckIdx, targetDeckIdxData);
                        dbHelper.putValue(DB_KEY_DECKPORT, portdeckdata.toString());
                        for (int i = 0; i < portdeckdata.size(); i++) {
                            boolean result = setMoraleValue(i, deckInfoCalc.checkMinimumMorale(portdeckdata, i), false, in_change);
                            processMoraleInfo(i, portdeckdata, result);
                        }
                        JsonArray akashi_flagship_deck = deckInfoCalc.checkAkashiFlagship(portdeckdata);
                        boolean akashi_nochange_flag = true;
                        for (int i = 0; i < akashi_flagship_deck.size(); i++) {
                            int deckid = akashi_flagship_deck.get(i).getAsInt();
                            if (deckid == deckIdx || deckid == originalDeckIdx) {
                                akashi_nochange_flag = false;
                                break;
                            }
                        }
                        KcaAkashiRepairInfo.setAkashiExist(akashi_flagship_deck.size() > 0);
                        if (!akashi_nochange_flag) {
                            KcaAkashiRepairInfo.setAkashiTimer();
                            processAkashiTimerInfo();
                            isAkashiTimerNotiWait = true;
                        }
                    }
                    updateFleetView();
                }
                if (url.startsWith(API_REQ_HENSEI_PRESET) && isCurrentPortDeckDataReady()) {
                    String[] requestData = request.split("&");
                    int deckIdx = -1;
                    for (int i = 0; i < requestData.length; i++) {
                        String decodedData = URLDecoder.decode(requestData[i], "utf-8");
                        if (decodedData.startsWith("api_deck_id=")) {
                            deckIdx = Integer.valueOf(decodedData.replace("api_deck_id=", "")) - 1;
                            break;
                        }
                    }
                    if (deckIdx != -1) {
                        if (jsonDataObj.has("api_data")) {
                            boolean is_same = true;
                            JsonArray portdeckdata = dbHelper.getJsonArrayValue(DB_KEY_DECKPORT);
                            JsonArray before_ship_list = portdeckdata.get(deckIdx).getAsJsonObject().getAsJsonArray("api_ship");
                            JsonObject api_data = jsonDataObj.getAsJsonObject("api_data");
                            JsonArray after_ship_list = api_data.getAsJsonArray("api_ship");
                            for (int i = 0; i < after_ship_list.size(); i++) {
                                if (!before_ship_list.contains(after_ship_list.get(i))) {
                                    is_same = false;
                                    break;
                                }
                            }
                            portdeckdata.set(deckIdx, api_data);
                            dbHelper.putValue(DB_KEY_DECKPORT, portdeckdata.toString());
                            boolean result = setMoraleValue(deckIdx, deckInfoCalc.checkMinimumMorale(portdeckdata, deckIdx), false, is_same);
                            processMoraleInfo(deckIdx, portdeckdata, result);
                        }
                    }
                    updateFleetView();
                }
                if (url.startsWith(API_REQ_HENSEI_COMBINED)) {
                    if (jsonDataObj.has("api_data")) {
                        JsonObject api_data = jsonDataObj.getAsJsonObject("api_data");
                        int api_combined = api_data.get("api_combined").getAsInt();
                        isCombined = (api_combined > 0);
                        KcaBattle.isCombined = api_combined > 0;
                    }
                    Log.e("KCA", "Combined: " + String.valueOf(isCombined));
                    updateFleetView();
                }
                if (url.startsWith(API_REQ_MEMBER_ITEMUSE_COND)) {
                    String[] requestData = request.split("&");
                    int deckIdx = -1;
                    for (int i = 0; i < requestData.length; i++) {
                        String decodedData = URLDecoder.decode(requestData[i], "utf-8");
                        if (decodedData.startsWith("api_deck_id=")) {
                            deckIdx = Integer.valueOf(decodedData.replace("api_deck_id=", "")) - 1;
                            break;
                        }
                    }
                    KcaMoraleInfo.setItemUseDeck(deckIdx);
                    updateFleetView();
                }
                if (url.startsWith(API_GET_MEMBER_SHIP2)) {
                    if (jsonDataObj.has("api_data")) {
                        JsonArray api_data = jsonDataObj.getAsJsonArray("api_data");
                        JsonArray api_data_deck = jsonDataObj.getAsJsonArray("api_data_deck");
                        KcaApiData.updateUserShipData(api_data);
                        dbHelper.putValue(DB_KEY_DECKPORT, api_data_deck.toString());
                        int itemuse_deck = KcaMoraleInfo.getItemUseDeckAndReset();
                        if (itemuse_deck > 0) {
                            boolean result = setMoraleValue(itemuse_deck, deckInfoCalc.checkMinimumMorale(api_data_deck, itemuse_deck), false, false);
                            processMoraleInfo(itemuse_deck, api_data_deck, result);
                        }
                    }
                    updateFleetView();
                }
                if (url.startsWith(API_GET_MEMBER_SHIP3)) {
                    String[] requestData = request.split("&");
                    int userShipId = -1;
                    for (int i = 0; i < requestData.length; i++) {
                        String decodedData = URLDecoder.decode(requestData[i], "utf-8");
                        if (decodedData.startsWith("api_shipid=")) {
                            userShipId = Integer.valueOf(decodedData.replace("api_shipid=", ""));
                            break;
                        }
                    }
                    if (userShipId != -1) {
                        if (jsonDataObj.has("api_data")) {
                            JsonObject api_data = jsonDataObj.getAsJsonObject("api_data");
                            dbHelper.putValue(DB_KEY_DECKPORT, api_data.get("api_deck_data").getAsJsonArray().toString());
                            dbHelper.test();
                            KcaApiData.updateUserShip(api_data.get("api_ship_data").getAsJsonArray().get(0).getAsJsonObject());
                        }
                    }
                    if (kaisouProcessFlag) {
                        toastInfo();
                        kaisouProcessFlag = false;
                        updateFleetView();
                    }
                }
                if (url.startsWith(API_REQ_KAISOU_SLOT_EXCHANGE)) {
                    String[] requestData = request.split("&");
                    int userShipId = -1;
                    for (int i = 0; i < requestData.length; i++) {
                        String decodedData = URLDecoder.decode(requestData[i], "utf-8");
                        if (decodedData.startsWith("api_id=")) {
                            userShipId = Integer.valueOf(decodedData.replace("api_id=", ""));
                            break;
                        }
                    }
                    if (userShipId != -1 && jsonDataObj.has("api_data")) {
                        JsonObject api_data = jsonDataObj.getAsJsonObject("api_data");
                        if (api_data.has("api_ship_data")) {
                            JsonObject ship_data = api_data.getAsJsonObject("api_ship_data");
                            KcaApiData.updateUserShipSlot(userShipId, ship_data);
                        }
                    }
                    updateFleetView();
                // toastInfo();
                }
                if (url.startsWith(API_REQ_KAISOU_SLOT_DEPRIVE)) {
                    if (jsonDataObj.has("api_data")) {
                        JsonObject api_data = jsonDataObj.getAsJsonObject("api_data");
                        JsonObject api_ship_data = api_data.get("api_ship_data").getAsJsonObject();
                        KcaApiData.updateUserShip(api_ship_data.get("api_set_ship").getAsJsonObject());
                        KcaApiData.updateUserShip(api_ship_data.get("api_unset_ship").getAsJsonObject());
                    }
                    updateFleetView();
                // toastInfo();
                }
                if (url.startsWith(API_REQ_KAISOU_POWERUP)) {
                    String[] requestData = request.split("&");
                    int targetId = -1;
                    String itemIds = "";
                    int slotDestFlag = -1;
                    for (int i = 0; i < requestData.length; i++) {
                        String decodedData = URLDecoder.decode(requestData[i], "utf-8");
                        if (decodedData.startsWith("api_id=")) {
                            targetId = Integer.valueOf(decodedData.replace("api_id=", ""));
                        }
                        if (decodedData.startsWith("api_id_items=")) {
                            itemIds = decodedData.replace("api_id_items=", "");
                        }
                        if (decodedData.startsWith("api_slot_dest_flag=")) {
                            slotDestFlag = Integer.valueOf(decodedData.replace("api_slot_dest_flag=", ""));
                        }
                    }
                    if (jsonDataObj.has("api_data")) {
                        JsonObject api_data = jsonDataObj.getAsJsonObject("api_data");
                        dbHelper.putValue(DB_KEY_DECKPORT, api_data.getAsJsonArray("api_deck").toString());
                        dbHelper.test();
                        updateUserShip(api_data.getAsJsonObject("api_ship"));
                        KcaApiData.deleteUserShip(itemIds, slotDestFlag);
                        if (api_data.has("api_powerup_flag") && api_data.get("api_powerup_flag").getAsInt() == 1) {
                            questTracker.updateIdCountTracker("702");
                            questTracker.updateIdCountTracker("703");
                            updateQuestView();
                        }
                    }
                    updateFleetView();
                }
                if (url.equals(API_REQ_KOUSYOU_REMOEL_SLOT)) {
                    JsonArray portdeckdata = dbHelper.getJsonArrayValue(DB_KEY_DECKPORT);
                    int[] kcShipData = deckInfoCalc.getKcShipList(portdeckdata, 0);
                    int flagship = kcShipData[0];
                    int assistant = kcShipData[1];
                    String[] requestData = request.split("&");
                    int certainFlag = 0;
                    int itemId = 0;
                    for (int i = 0; i < requestData.length; i++) {
                        String decodedData = URLDecoder.decode(requestData[i], "utf-8");
                        if (decodedData.startsWith("api_certain_flag=")) {
                            certainFlag = Integer.valueOf(decodedData.replace("api_certain_flag=", ""));
                        }
                        if (decodedData.startsWith("api_slot_id=")) {
                            itemId = Integer.valueOf(decodedData.replace("api_slot_id=", ""));
                        }
                    }
                    JsonObject itemData = KcaApiData.getUserItemStatusById(itemId, "slotitem_id,level", "");
                    if (itemData != null) {
                        int itemKcId = itemData.get("slotitem_id").getAsInt();
                        int level = itemData.get("level").getAsInt();
                        int api_remodel_flag = 0;
                        if (jsonDataObj.has("api_data")) {
                            JsonObject api_data = jsonDataObj.getAsJsonObject("api_data");
                            api_remodel_flag = api_data.get("api_remodel_flag").getAsInt();
                            if (certainFlag == 1 || api_remodel_flag == 1) {
                                JsonObject api_after_slot = api_data.get("api_after_slot").getAsJsonObject();
                                JsonArray api_slot_item = new JsonArray();
                                api_slot_item.add(api_after_slot);
                                for (int i = 0; i < api_slot_item.size(); i++) {
                                    JsonObject item = api_slot_item.get(i).getAsJsonObject();
                                    dbHelper.putItemValue(item.get("api_id").getAsInt(), item.toString());
                                }
                            }
                            JsonElement use_slot_id = api_data.get("api_use_slot_id");
                            List<String> use_slot_id_list = new ArrayList<String>();
                            if (use_slot_id != null) {
                                for (JsonElement id : use_slot_id.getAsJsonArray()) {
                                    use_slot_id_list.add(id.getAsString());
                                }
                                KcaApiData.removeSlotItemData(joinStr(use_slot_id_list, ","));
                            }
                        }
                        questTracker.updateIdCountTracker("619");
                        updateQuestView();
                    }
                }
            }
        }
        if (API_WIDGET_TU_REQS.contains(url)) {
            Intent widgetUpdateIndent = new Intent(getApplicationContext(), KcaTimerWidget.class);
            widgetUpdateIndent.setAction(WIDGET_DATA_UPDATE);
            sendBroadcast(widgetUpdateIndent);
        }
        sendQuestCompletionInfo();
    } catch (Exception e) {
        e.printStackTrace();
        String api_request = "";
        List<String> filtered_resquest_list = new ArrayList<String>();
        try {
            String[] requestData = request.split("&");
            for (int i = 0; i < requestData.length; i++) {
                String decodedData = URLDecoder.decode(requestData[i], "utf-8");
                if (!decodedData.startsWith("api_token")) {
                    filtered_resquest_list.add(requestData[i]);
                }
            }
            api_request = joinStr(filtered_resquest_list, "&");
        } catch (UnsupportedEncodingException e1) {
            e1.printStackTrace();
        }
        String process_data = new String(raw);
        if (url.contains(API_PORT)) {
            process_data = "PORT DATA OMITTED";
        }
        dbHelper.recordErrorLog(ERROR_TYPE_SERVICE, url, api_request, process_data, getStringFromException(e));
    }
}
Also used : JsonPrimitive(com.google.gson.JsonPrimitive) ArrayList(java.util.ArrayList) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) JsonObject(com.google.gson.JsonObject) Uri(android.net.Uri) ArrayList(java.util.ArrayList) List(java.util.List) InputStreamReader(java.io.InputStreamReader) SharedPreferences(android.content.SharedPreferences) UnsupportedEncodingException(java.io.UnsupportedEncodingException) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) Date(java.util.Date) KcaUtils.getStringFromException(com.antest1.kcanotify.KcaUtils.getStringFromException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) JsonSyntaxException(com.google.gson.JsonSyntaxException) JsonArray(com.google.gson.JsonArray) ByteArrayInputStream(java.io.ByteArrayInputStream) JsonElement(com.google.gson.JsonElement) SimpleDateFormat(java.text.SimpleDateFormat)

Example 2 with PREF_KCA_DATA_VERSION

use of com.antest1.kcanotify.KcaConstants.PREF_KCA_DATA_VERSION in project kcanotify by antest1.

the class UpdateCheckActivity method checkVersionUpdate.

private void checkVersionUpdate() {
    gamedata_load.setVisibility(View.VISIBLE);
    data_list.setVisibility(View.GONE);
    gamedata_info.clear();
    final Call<String> load_version = downloader.getRecentVersion();
    if (!KcaUtils.checkOnline(getApplicationContext())) {
        gamedata_load.setText("No Internet Connection.");
    } else {
        load_version.enqueue(new Callback<String>() {

            @Override
            public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {
                try {
                    String ver_result = response.body();
                    JsonObject ver_data = gson.fromJson(ver_result, JsonObject.class);
                    latest_gamedata_version = ver_data.get("data_version").getAsString();
                    JsonObject gamedata = new JsonObject();
                    gamedata.addProperty("name", "api_start2");
                    gamedata.addProperty("desc", "kancolle game data for kcanotify");
                    String current_gd_v = getStringPreferences(getApplicationContext(), PREF_KCA_DATA_VERSION);
                    String latest_gd_v = latest_gamedata_version;
                    gamedata.addProperty("version", latest_gd_v);
                    gamedata.addProperty("version_str", getVersionString(current_gd_v, latest_gd_v));
                    gamedata.addProperty("highlight", !KcaUtils.compareVersion(current_gd_v, latest_gd_v));
                    gamedata.addProperty("url", "call_kcadata_download");
                    gamedata_info.add(gamedata);
                    gamedata_adapter.setContext(getApplicationContext());
                    gamedata_adapter.setListItem(gamedata_info);
                    gamedata_adapter.notifyDataSetChanged();
                    gamedata_load.setVisibility(View.GONE);
                    data_list.setVisibility(View.VISIBLE);
                } catch (Exception e) {
                    gamedata_load.setText("Error: " + e.getMessage());
                }
            }

            @Override
            public void onFailure(@NonNull Call<String> call, @NonNull Throwable t) {
                gamedata_load.setText("Error: " + t.toString());
            }
        });
    }
}
Also used : JsonObject(com.google.gson.JsonObject) KcaUtils.getStringFromException(com.antest1.kcanotify.KcaUtils.getStringFromException)

Example 3 with PREF_KCA_DATA_VERSION

use of com.antest1.kcanotify.KcaConstants.PREF_KCA_DATA_VERSION in project kcanotify by antest1.

the class UpdateCheckActivity method downloadGameData.

private void downloadGameData() {
    final Call<String> down_gamedata = downloader.getGameData("recent");
    down_gamedata.enqueue(new retrofit2.Callback<String>() {

        @Override
        public void onResponse(Call<String> call, retrofit2.Response<String> response) {
            JsonObject response_data = new JsonObject();
            try {
                if (response.body() != null) {
                    response_data = new JsonParser().parse(response.body()).getAsJsonObject();
                    String kca_version = KcaUtils.getStringPreferences(getApplicationContext(), PREF_KCA_VERSION);
                    String server_kca_version = response.headers().get("X-Api-Version");
                    Log.e("KCA", "api_version: " + server_kca_version);
                    if (kca_version == null || compareVersion(server_kca_version, kca_version)) {
                        dbHelper.putValue(DB_KEY_STARTDATA, response_data.toString());
                        KcaApiData.getKcGameData(response_data.getAsJsonObject("api_data"));
                        KcaUtils.setPreferences(getApplicationContext(), PREF_KCA_DATA_VERSION, server_kca_version);
                        KcaApiData.setDataLoadTriggered();
                        Toast.makeText(getApplicationContext(), getStringWithLocale(R.string.sa_getupdate_finished), Toast.LENGTH_LONG).show();
                        JsonObject gamedata = gamedata_info.get(0);
                        String latest_gd_v = latest_gamedata_version;
                        gamedata.addProperty("version", latest_gd_v);
                        gamedata.addProperty("version_str", getVersionString(server_kca_version, latest_gd_v));
                        gamedata.addProperty("highlight", !KcaUtils.compareVersion(server_kca_version, latest_gd_v));
                        gamedata_adapter.setContext(getApplicationContext());
                        gamedata_adapter.setListItem(gamedata_info);
                        gamedata_adapter.notifyDataSetChanged();
                    } else {
                        Toast.makeText(getApplicationContext(), getStringWithLocale(R.string.kca_toast_inconsistent_data), Toast.LENGTH_LONG).show();
                        ;
                    }
                }
            } catch (Exception e) {
                Toast.makeText(getApplicationContext(), "Error: not valid data.", Toast.LENGTH_LONG).show();
                ;
                dbHelper.recordErrorLog(ERROR_TYPE_SETTING, "fairy_queue", "", "", getStringFromException(e));
            }
        }

        @Override
        public void onFailure(Call<String> call, Throwable t) {
            if (KcaUtils.checkOnline(getApplicationContext())) {
                Toast.makeText(getApplicationContext(), KcaUtils.format(getStringWithLocale(R.string.sa_getupdate_servererror), t.getMessage()), Toast.LENGTH_LONG).show();
                ;
                dbHelper.recordErrorLog(ERROR_TYPE_SETTING, "fairy_queue", "", "", t.getMessage());
            }
        }
    });
}
Also used : JsonObject(com.google.gson.JsonObject) KcaUtils.getStringFromException(com.antest1.kcanotify.KcaUtils.getStringFromException) JsonParser(com.google.gson.JsonParser)

Example 4 with PREF_KCA_DATA_VERSION

use of com.antest1.kcanotify.KcaConstants.PREF_KCA_DATA_VERSION in project kcanotify by antest1.

the class MainActivity method checkRecentVersion.

private void checkRecentVersion() {
    String currentVersion = BuildConfig.VERSION_NAME;
    String currentDataVersion = getStringPreferences(getApplicationContext(), PREF_KCA_DATA_VERSION);
    final Call<String> rv_data = downloader.getRecentVersion();
    rv_data.enqueue(new Callback<String>() {

        @Override
        public void onResponse(Call<String> call, retrofit2.Response<String> response) {
            JsonObject response_data = new JsonObject();
            try {
                if (response.body() != null) {
                    response_data = new JsonParser().parse(response.body()).getAsJsonObject();
                }
            } catch (Exception e) {
                dbHelper.recordErrorLog(ERROR_TYPE_MAIN, "version_check", "", "", getStringFromException(e));
            }
            Log.e("KCA", response_data.toString());
            int nid = getNotificationId(NOTI_UPDATE, 0);
            Intent deleteIntent = new Intent(MainActivity.this, KcaAlarmService.class).setAction(DELETE_ACTION.concat(String.valueOf(nid)));
            startService(deleteIntent);
        }

        @Override
        public void onFailure(Call<String> call, Throwable t) {
            if (KcaUtils.checkOnline(getApplicationContext())) {
                Toast.makeText(getApplicationContext(), getStringWithLocale(R.string.sa_checkupdate_servererror), Toast.LENGTH_LONG).show();
                dbHelper.recordErrorLog(ERROR_TYPE_MAIN, "version_check", "", "", t.getMessage());
            }
            int nid = getNotificationId(NOTI_UPDATE, 0);
            Intent deleteIntent = new Intent(MainActivity.this, KcaAlarmService.class).setAction(DELETE_ACTION.concat(String.valueOf(nid)));
            startService(deleteIntent);
        }
    });
}
Also used : JsonObject(com.google.gson.JsonObject) CustomTabsIntent(androidx.browser.customtabs.CustomTabsIntent) Intent(android.content.Intent) KcaUtils.getKcIntent(com.antest1.kcanotify.KcaUtils.getKcIntent) ParseException(java.text.ParseException) KcaUtils.getStringFromException(com.antest1.kcanotify.KcaUtils.getStringFromException) IOException(java.io.IOException) JsonParser(com.google.gson.JsonParser)

Example 5 with PREF_KCA_DATA_VERSION

use of com.antest1.kcanotify.KcaConstants.PREF_KCA_DATA_VERSION in project kcanotify by antest1.

the class InitStartActivity method onCreate.

@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_init_download);
    Log.e("KCA-DA", "created");
    sendUserAnalytics(getApplicationContext(), START_APP, null);
    Intent mainIntent = getIntent();
    reset_flag = mainIntent.getBooleanExtra(ACTION_RESET, false);
    is_destroyed = false;
    PreferenceManager.setDefaultValues(this, R.xml.pref_settings, false);
    setDefaultPreferences();
    dbHelper = new KcaDBHelper(getApplicationContext(), null, KCANOTIFY_DB_VERSION);
    downloader = KcaUtils.getInfoDownloader(getApplicationContext());
    KcaApiData.setDBHelper(dbHelper);
    appname = findViewById(R.id.app_title);
    appname.setText(getStringWithLocale(R.string.app_name));
    appversion = findViewById(R.id.app_version);
    appversion.setText(getString(R.string.app_version));
    appmessage = findViewById(R.id.app_message);
    appmessage.setText("");
    appfront = findViewById(R.id.app_icon);
    int img_id = (int) (Math.random() * 4);
    appfront.setImageResource(R.mipmap.main_image);
    int fairy_id = Integer.parseInt(getStringPreferences(getApplicationContext(), PREF_FAIRY_ICON));
    if (!FAIRY_SPECIAL_FLAG && fairy_id >= FAIRY_SPECIAL_PREFIX) {
        setPreferences(getApplicationContext(), PREF_FAIRY_ICON, 0);
    }
    // Initialize resources
    setPreferences(getApplicationContext(), PREF_DATALOAD_ERROR_FLAG, false);
    loadDefaultAsset();
    validated_flag = KcaUtils.validateResourceFiles(getApplicationContext(), dbHelper);
    setPreferences(getApplicationContext(), PREF_DATALOAD_ERROR_FLAG, false);
    findViewById(R.id.init_layout).setOnClickListener(v -> {
        if (validated_flag && !reset_flag) {
            startMainActivity(false);
            is_skipped = true;
        }
    });
    new Thread(() -> {
        runOnUiThread(() -> appmessage.setText("Loading Translation Data..."));
        loadTranslationData(getApplicationContext());
        runOnUiThread(() -> appmessage.setText("Loading KanColle Game Data..."));
        int setDefaultGameDataResult = KcaUtils.setDefaultGameData(getApplicationContext(), dbHelper);
        if (setDefaultGameDataResult != 1) {
            runOnUiThread(() -> Toast.makeText(getApplicationContext(), "error loading game data", Toast.LENGTH_LONG).show());
        }
        runOnUiThread(() -> appmessage.setText("Checking External Filter..."));
        boolean allow_ext = KcaUtils.getBooleanPreferences(getApplicationContext(), PREF_ALLOW_EXTFILTER);
        List<String> result = KcaVpnData.setExternalFilter(allow_ext);
        boolean is_default_written = KcaUtils.getStringPreferences(getApplicationContext(), PREF_DEFAULT_APIVER).equals(BuildConfig.VERSION_NAME);
        if (!is_default_written) {
            runOnUiThread(() -> appmessage.setText("Writing Default Data..."));
            String internal_kca_version = getString(R.string.default_gamedata_version);
            try {
                InputStream api_ais = getAssets().open("api_start2");
                byte[] bytes = gzipdecompress(ByteStreams.toByteArray(api_ais));
                String asset_start2_data = new String(bytes);
                dbHelper.putValue(DB_KEY_STARTDATA, asset_start2_data);
                KcaUtils.setPreferences(getApplicationContext(), PREF_DEFAULT_APIVER, BuildConfig.VERSION_NAME);
                KcaUtils.setPreferences(getApplicationContext(), PREF_KCA_VERSION, internal_kca_version);
                KcaUtils.setPreferences(getApplicationContext(), PREF_KCA_DATA_VERSION, internal_kca_version);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        // main update check
        if (!KcaUtils.checkOnline(getApplicationContext()) || !getBooleanPreferences(getApplicationContext(), PREF_CHECK_UPDATE_START)) {
            startMainActivity(true);
        } else {
            if (is_skipped)
                return;
            runOnUiThread(() -> appmessage.setText("Checking Updates..."));
            String currentVersion = BuildConfig.VERSION_NAME;
            final Call<String> rv_data = downloader.getRecentVersion();
            String response = getResultFromCall(rv_data);
            new_resversion = -1;
            fairy_flag = 0;
            JsonObject response_data = new JsonObject();
            try {
                if (response != null) {
                    response_data = new JsonParser().parse(response).getAsJsonObject();
                }
            } catch (Exception e) {
                dbHelper.recordErrorLog(ERROR_TYPE_MAIN, "version_check", "", "", getStringFromException(e));
            }
            Log.e("KCA", response_data.toString());
            if (response_data.has("kc_maintenance")) {
                dbHelper.putValue(DB_KEY_KCMAINTNC, response_data.get("kc_maintenance").toString());
            }
            if (response_data.has("version")) {
                String recentVersion = response_data.get("version").getAsString();
                if (!compareVersion(currentVersion, recentVersion)) {
                    // True if latest
                    JsonObject data = response_data;
                    if (!is_skipped) {
                        runOnUiThread(() -> {
                            AlertDialog.Builder alertDialog = getUpdateAlertDialog(recentVersion, data);
                            AlertDialog alert = alertDialog.create();
                            alert.setIcon(R.mipmap.ic_launcher);
                            alert.setTitle(getStringWithLocale(R.string.sa_checkupdate_dialogtitle));
                            if (!InitStartActivity.this.isFinishing()) {
                                alert.show();
                            }
                        });
                    }
                } else {
                    dataCheck(response_data);
                }
            }
        }
    }).start();
}
Also used : AlertDialog(androidx.appcompat.app.AlertDialog) Call(retrofit2.Call) InputStream(java.io.InputStream) JsonObject(com.google.gson.JsonObject) Intent(android.content.Intent) IOException(java.io.IOException) SuppressLint(android.annotation.SuppressLint) KcaUtils.getStringFromException(com.antest1.kcanotify.KcaUtils.getStringFromException) IOException(java.io.IOException) List(java.util.List) ArrayList(java.util.ArrayList) JsonParser(com.google.gson.JsonParser)

Aggregations

KcaUtils.getStringFromException (com.antest1.kcanotify.KcaUtils.getStringFromException)5 JsonObject (com.google.gson.JsonObject)5 Intent (android.content.Intent)3 JsonParser (com.google.gson.JsonParser)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 SuppressLint (android.annotation.SuppressLint)1 PendingIntent (android.app.PendingIntent)1 SharedPreferences (android.content.SharedPreferences)1 Uri (android.net.Uri)1 AlertDialog (androidx.appcompat.app.AlertDialog)1 CustomTabsIntent (androidx.browser.customtabs.CustomTabsIntent)1 KcaUtils.getKcIntent (com.antest1.kcanotify.KcaUtils.getKcIntent)1 JsonArray (com.google.gson.JsonArray)1 JsonElement (com.google.gson.JsonElement)1 JsonPrimitive (com.google.gson.JsonPrimitive)1 JsonSyntaxException (com.google.gson.JsonSyntaxException)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1