Search in sources :

Example 1 with KcaUtils.getStringPreferences

use of com.antest1.kcanotify.KcaUtils.getStringPreferences 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 2 with KcaUtils.getStringPreferences

use of com.antest1.kcanotify.KcaUtils.getStringPreferences 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)

Example 3 with KcaUtils.getStringPreferences

use of com.antest1.kcanotify.KcaUtils.getStringPreferences in project kcanotify by antest1.

the class KcaExpeditionCheckViewService method onCreate.

public void onCreate() {
    super.onCreate();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !Settings.canDrawOverlays(getApplicationContext())) {
        // Can not draw overlays: pass
        stopSelf();
    }
    try {
        active = true;
        locale = LocaleUtils.getResourceLocaleCode(KcaUtils.getStringPreferences(getApplicationContext(), PREF_KCA_LANGUAGE));
        ship_data = new ArrayList<>();
        checkdata = new HashMap<>();
        dbHelper = new KcaDBHelper(getApplicationContext(), null, KCANOTIFY_DB_VERSION);
        contextWithLocale = KcaUtils.getContextWithLocale(getApplicationContext(), getBaseContext());
        mInflater = LayoutInflater.from(contextWithLocale);
        mView = mInflater.inflate(R.layout.view_excheck_list, null);
        KcaUtils.resizeFullWidthView(getApplicationContext(), mView);
        mView.setVisibility(View.GONE);
        itemView = mView.findViewById(R.id.view_excheck_detail);
        mParams = new WindowManager.LayoutParams(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT, getWindowLayoutType(), WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, PixelFormat.TRANSLUCENT);
        mParams.gravity = Gravity.CENTER;
        mManager = (WindowManager) getSystemService(WINDOW_SERVICE);
        mManager.addView(mView, mParams);
        Display display = ((WindowManager) getApplicationContext().getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
        Point size = new Point();
        display.getSize(size);
        displayWidth = size.x;
    } catch (Exception e) {
        e.printStackTrace();
        active = false;
        error_flag = true;
        stopSelf();
    }
}
Also used : Point(android.graphics.Point) KcaUtils.getStringFromException(com.antest1.kcanotify.KcaUtils.getStringFromException) WindowManager(android.view.WindowManager) Display(android.view.Display)

Aggregations

KcaUtils.getStringFromException (com.antest1.kcanotify.KcaUtils.getStringFromException)3 JsonObject (com.google.gson.JsonObject)2 JsonParser (com.google.gson.JsonParser)2 SuppressLint (android.annotation.SuppressLint)1 Intent (android.content.Intent)1 Point (android.graphics.Point)1 Display (android.view.Display)1 WindowManager (android.view.WindowManager)1 AlertDialog (androidx.appcompat.app.AlertDialog)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Call (retrofit2.Call)1