Search in sources :

Example 1 with DynamicDialogMenu

use of forpdateam.ru.forpda.ui.views.DynamicDialogMenu in project ForPDA by RadiationX.

the class UpdateCheckerActivity method checkUpdate.

private void checkUpdate(JSONObject updateObject) throws JSONException {
    final int currentVersionCode = BuildConfig.VERSION_CODE;
    final int versionCode = Integer.parseInt(updateObject.getString("version_code"));
    if (versionCode > currentVersionCode) {
        final String versionName = updateObject.getString("version_name");
        final String versionBuild = updateObject.getString("version_build");
        final String buildDate = updateObject.getString("build_date");
        final String linkGit = updateObject.getString("link_github");
        final String link4pda = updateObject.getString("link_4pda");
        final JSONObject changesObject = updateObject.getJSONObject("changes");
        final JSONArray important = changesObject.getJSONArray("important");
        final JSONArray added = changesObject.getJSONArray("added");
        final JSONArray fixed = changesObject.getJSONArray("fixed");
        final JSONArray changed = changesObject.getJSONArray("changed");
        updateInfo.setText(generateCurrentInfo(versionName, buildDate));
        addSection("Важно", important);
        addSection("Добавлено", added);
        addSection("Исправлено", fixed);
        addSection("Изменено", changed);
        updateInfo.setVisibility(View.VISIBLE);
        updateContent.setVisibility(View.VISIBLE);
        updateButton.setVisibility(View.VISIBLE);
        divider.setVisibility(View.VISIBLE);
        updateButton.setOnClickListener(v -> {
            DynamicDialogMenu<UpdateCheckerActivity, Object> dialogMenu = new DynamicDialogMenu<>();
            dialogMenu.addItem("github.com", (context, data) -> IntentHandler.handleDownload(linkGit));
            if (ClientHelper.getAuthState()) {
                dialogMenu.addItem("4pda.ru", (context, data) -> IntentHandler.handleDownload(link4pda));
            }
            dialogMenu.addItem("Google Play", (context, data) -> IntentHandler.handle(GOOGLE_PLAY_LINK));
            dialogMenu.allowAll();
            String title = getString(R.string.load_from);
            dialogMenu.show(UpdateCheckerActivity.this, title, UpdateCheckerActivity.this, null);
        });
    } else {
        updateInfo.setText(R.string.no_updates);
        updateInfo.setVisibility(View.VISIBLE);
        updateContent.setVisibility(View.GONE);
        updateButton.setVisibility(View.GONE);
        divider.setVisibility(View.GONE);
        updateButton.setOnClickListener(null);
    }
}
Also used : JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) JSONObject(org.json.JSONObject) DynamicDialogMenu(forpdateam.ru.forpda.ui.views.DynamicDialogMenu)

Aggregations

DynamicDialogMenu (forpdateam.ru.forpda.ui.views.DynamicDialogMenu)1 JSONArray (org.json.JSONArray)1 JSONObject (org.json.JSONObject)1