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