use of com.antest1.kcanotify.KcaUtils.compareVersion 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());
}
});
}
}
use of com.antest1.kcanotify.KcaUtils.compareVersion 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());
}
}
});
}
Aggregations