Search in sources :

Example 1 with ERROR_TYPE_SETTING

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

the class MainPreferenceFragment method checkRecentVersion.

private void checkRecentVersion() {
    String currentVersion = BuildConfig.VERSION_NAME;
    final Call<String> rv_data = downloader.getRecentVersion();
    rv_data.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();
                }
            } catch (Exception e) {
                dbHelper.recordErrorLog(ERROR_TYPE_MAIN, "version_check", "", "", getStringFromException(e));
            }
            Log.e("KCA", response_data.toString());
            if (response_data.has("version")) {
                String recentVersion = response_data.get("version").getAsString();
                if (compareVersion(currentVersion, recentVersion)) {
                    // True if latest
                    showToast(getActivity(), KcaUtils.format(getStringWithLocale(R.string.sa_checkupdate_latest), currentVersion), Toast.LENGTH_LONG);
                } else if (!getActivity().isFinishing()) {
                    AlertDialog.Builder alertDialog = new AlertDialog.Builder(getActivity());
                    alertDialog.setMessage(KcaUtils.format(getStringWithLocale(R.string.sa_checkupdate_hasupdate), recentVersion));
                    alertDialog.setPositiveButton(getStringWithLocale(R.string.dialog_ok), (dialog, which) -> {
                        String downloadUrl = getStringPreferences(getContext(), PREF_APK_DOWNLOAD_SITE);
                        Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(downloadUrl));
                        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                        if (intent.resolveActivity(getContext().getPackageManager()) != null) {
                            startActivity(intent);
                        } else if (downloadUrl.contains(getStringWithLocale(R.string.app_download_link_playstore))) {
                            showToast(getContext(), "Google Play Store not found", Toast.LENGTH_LONG);
                            AlertDialog.Builder apkDownloadPathDialog = new AlertDialog.Builder(getActivity());
                            apkDownloadPathDialog.setIcon(R.mipmap.ic_launcher);
                            apkDownloadPathDialog.setTitle(getStringWithLocale(R.string.setting_menu_app_title_down));
                            apkDownloadPathDialog.setCancelable(true);
                            apkDownloadPathDialog.setItems(R.array.downloadSiteOptionWithoutPlayStore, new DialogInterface.OnClickListener() {

                                @Override
                                public void onClick(DialogInterface dialogInterface, int i) {
                                    String[] path_value = getResources().getStringArray(R.array.downloadSiteOptionWithoutPlayStoreValue);
                                    setPreferences(getContext(), PREF_APK_DOWNLOAD_SITE, path_value[i]);
                                    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(path_value[i]));
                                    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                                    startActivity(intent);
                                }
                            });
                            apkDownloadPathDialog.show();
                        }
                    });
                    alertDialog.setNegativeButton(getStringWithLocale(R.string.dialog_cancel), (dialog, which) -> {
                    // None
                    });
                    AlertDialog alert = alertDialog.create();
                    alert.setIcon(R.mipmap.ic_launcher);
                    alert.setTitle(getStringWithLocale(R.string.sa_checkupdate_dialogtitle));
                    alert.show();
                }
            } else {
                showToast(getActivity(), getStringWithLocale(R.string.sa_checkupdate_servererror), Toast.LENGTH_LONG);
            }
        }

        @Override
        public void onFailure(Call<String> call, Throwable t) {
            Activity activity = getActivity();
            if (activity != null && KcaUtils.checkOnline(activity)) {
                showToast(activity, getStringWithLocale(R.string.sa_checkupdate_servererror), Toast.LENGTH_LONG);
                dbHelper.recordErrorLog(ERROR_TYPE_SETTING, "version_check", "", "", t.getMessage());
            }
        }
    });
}
Also used : AlertDialog(android.app.AlertDialog) DialogInterface(android.content.DialogInterface) JsonObject(com.google.gson.JsonObject) Activity(android.app.Activity) Intent(android.content.Intent) KcaUtils.getStringFromException(com.antest1.kcanotify.KcaUtils.getStringFromException) JsonParser(com.google.gson.JsonParser)

Example 2 with ERROR_TYPE_SETTING

use of com.antest1.kcanotify.KcaConstants.ERROR_TYPE_SETTING 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 3 with ERROR_TYPE_SETTING

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

the class KcaInspectorActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_inspector);
    toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setTitle(getResources().getString(R.string.action_inspector));
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    listViewItemList = new ArrayList<>();
    adapter = new KcaInspectViewAdpater();
    dbHelper = new KcaDBHelper(getApplicationContext(), null, KCANOTIFY_DB_VERSION);
    questTracker = new KcaQuestTracker(getApplicationContext(), null, KCANOTIFY_QTDB_VERSION);
    packetLogger = new KcaPacketLogger(getApplicationContext(), null, KCANOTIFY_PACKETLOG_VERSION);
    for (String db_key : DB_KEY_ARRAY) {
        String db_value = dbHelper.getValue(db_key);
        if (db_value == null)
            db_value = "<null>";
        else if (db_value.length() > 100) {
            db_value = db_value.substring(0, 100).concat(KcaUtils.format("... (%d)", db_value.length()));
        }
        listViewItemList.add(new AbstractMap.SimpleEntry<>(DB_PREFIX.concat(db_key), db_value));
    }
    String questlist_data = dbHelper.getQuestListData();
    String questlist_view = questlist_data.replace("\n", ", ");
    if (questlist_view.length() > 100) {
        questlist_view = questlist_view.substring(0, 100).concat(KcaUtils.format("... (%d)", questlist_data.length()));
    }
    listViewItemList.add(new AbstractMap.SimpleEntry<>(DQ_PREFIX.concat("quest_data"), questlist_view));
    String questtrack_data = questTracker.getQuestTrackerDump();
    listViewItemList.add(new AbstractMap.SimpleEntry<>(QT_PREFIX.concat("tracked_data"), questtrack_data));
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
    listViewItemList.add(new AbstractMap.SimpleEntry<>(SPREF_PREFIX.concat(PREF_VPN_ENABLED), String.valueOf(prefs.getBoolean(PREF_VPN_ENABLED, false))));
    listViewItemList.add(new AbstractMap.SimpleEntry<>(SPREF_PREFIX.concat(PREF_SVC_ENABLED), String.valueOf(prefs.getBoolean(PREF_SVC_ENABLED, false))));
    for (String pref_key : PREFS_LIST) {
        String pref_value = "";
        try {
            if (PREFS_BOOLEAN_LIST.contains(pref_key)) {
                pref_value = String.valueOf(getBooleanPreferences(getApplicationContext(), pref_key));
            } else {
                pref_value = getStringPreferences(getApplicationContext(), pref_key);
            }
        } catch (Exception e) {
            dbHelper.recordErrorLog(ERROR_TYPE_SETTING, "pref", "", "", getStringFromException(e));
        }
        listViewItemList.add(new AbstractMap.SimpleEntry<>(PREF_PREFIX.concat(pref_key), pref_value));
    }
    adapter.setListViewItemList(listViewItemList);
    listview = findViewById(R.id.inspector_listview);
    listview.setAdapter(adapter);
    packetlogEnable = findViewById(R.id.packetlog_enable);
    packetlogEnable.setChecked(getBooleanPreferences(getApplicationContext(), PREF_PACKET_LOG));
    packetlogEnable.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            KcaUtils.setPreferences(getApplicationContext(), PREF_PACKET_LOG, isChecked);
        }
    });
    packletlogClear = findViewById(R.id.packetlog_clear);
    packletlogClear.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            packetLogger.clear();
        }
    });
    packetlogDump = findViewById(R.id.packetlog_dump);
    packetlogDump.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            boolean result = packetLogger.dump(getApplicationContext());
            Toast.makeText(getApplicationContext(), String.valueOf(result), Toast.LENGTH_LONG).show();
        }
    });
}
Also used : SharedPreferences(android.content.SharedPreferences) View(android.view.View) ListView(android.widget.ListView) KcaUtils.getStringFromException(com.antest1.kcanotify.KcaUtils.getStringFromException) AbstractMap(java.util.AbstractMap) CompoundButton(android.widget.CompoundButton)

Aggregations

KcaUtils.getStringFromException (com.antest1.kcanotify.KcaUtils.getStringFromException)3 JsonObject (com.google.gson.JsonObject)2 JsonParser (com.google.gson.JsonParser)2 Activity (android.app.Activity)1 AlertDialog (android.app.AlertDialog)1 DialogInterface (android.content.DialogInterface)1 Intent (android.content.Intent)1 SharedPreferences (android.content.SharedPreferences)1 View (android.view.View)1 CompoundButton (android.widget.CompoundButton)1 ListView (android.widget.ListView)1 AbstractMap (java.util.AbstractMap)1