use of com.antest1.kcanotify.KcaConstants.PREF_CHECK_UPDATE_START in project kcanotify by antest1.
the class UpdateCheckActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_rescheck);
Intent intent = this.getIntent();
if (intent != null && intent.getExtras() != null) {
main_flag = intent.getExtras().getBoolean("main_flag", false);
}
toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setTitle(getResources().getString(R.string.setting_menu_kand_title_game_data_down));
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
dbHelper = new KcaDBHelper(getApplicationContext(), null, KCANOTIFY_DB_VERSION);
KcaApiData.setDBHelper(dbHelper);
downloader = KcaUtils.getInfoDownloader(getApplicationContext());
FetchConfiguration fetchConfiguration = new FetchConfiguration.Builder(getApplicationContext()).setDownloadConcurrentLimit(80).build();
fetch = Fetch.Impl.getInstance(fetchConfiguration);
handler = new UpdateHandler(this);
gamedata_adapter.setHandler(handler);
resource_adapter.setHandler(handler);
checkstart_chkbox = findViewById(R.id.reschk_checkatstart);
checkstart_chkbox.setText(getStringWithLocale(R.string.download_setting_checkatstart));
checkstart_chkbox.setChecked(getBooleanPreferences(getApplicationContext(), PREF_CHECK_UPDATE_START));
checkstart_chkbox.setOnCheckedChangeListener((buttonView, isChecked) -> setPreferences(getApplicationContext(), PREF_CHECK_UPDATE_START, isChecked));
localonly_chkbox = findViewById(R.id.reschk_local);
localonly_chkbox.setText(getStringWithLocale(R.string.download_use_internal_data));
localonly_chkbox.setChecked(getBooleanPreferences(getApplicationContext(), PREF_RES_USELOCAL));
localonly_chkbox.setOnCheckedChangeListener((buttonView, isChecked) -> setPreferences(getApplicationContext(), PREF_RES_USELOCAL, isChecked));
resource_reset = findViewById(R.id.reschk_reset);
resource_reset.setText(getStringWithLocale(R.string.download_reset));
resource_reset.setOnCheckedChangeListener((buttonView, isChecked) -> {
if (isChecked) {
AlertDialog.Builder alertDialog = new AlertDialog.Builder(UpdateCheckActivity.this);
alertDialog.setMessage(getString(R.string.download_reset_message));
alertDialog.setPositiveButton(getStringWithLocale(R.string.dialog_ok), (dialog, which) -> {
dbHelper.clearResVer();
setPreferences(getApplicationContext(), PREF_KCARESOURCE_VERSION, 0);
Intent mainIntent = new Intent(this, InitStartActivity.class);
mainIntent.putExtra(ACTION_RESET, true);
startActivity(mainIntent);
finish();
});
alertDialog.setNegativeButton(getStringWithLocale(R.string.dialog_cancel), (dialog, which) -> {
resource_reset.setChecked(false);
dialog.dismiss();
});
AlertDialog alert = alertDialog.create();
alert.setIcon(R.mipmap.ic_launcher);
alert.show();
}
});
data_list = findViewById(R.id.gamedata_list);
resource_list = findViewById(R.id.resources_list);
data_list.setAdapter(gamedata_adapter);
resource_list.setAdapter(resource_adapter);
gamedata_load = findViewById(R.id.gamedata_loading);
resource_load = findViewById(R.id.resources_loading);
gamedata_chk = findViewById(R.id.gamedata_updatecheck);
resource_chk = findViewById(R.id.resources_updatecheck);
resource_downall = findViewById(R.id.resources_downloadall);
gamedata_chk.setOnClickListener(v -> checkVersionUpdate());
resource_chk.setOnClickListener(v -> checkResourceUpdate());
resource_downall.setOnClickListener(v -> downloadAllResources());
resource_downall.setVisibility(View.GONE);
gamedata_server = findViewById(R.id.gamedata_server);
gamedata_server.setText(getStringWithLocale(R.string.action_server));
gamedata_server.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
final int initValue = checked;
String[] listItems = getResources().getStringArray(R.array.ServerLocation);
String[] listEntry = getResources().getStringArray(R.array.ServerLocationValue);
AlertDialog.Builder mBuilder = new AlertDialog.Builder(UpdateCheckActivity.this);
mBuilder.setTitle(getStringWithLocale(R.string.setting_menu_app_title_updatecheckserver));
String currentServer = getStringPreferences(getApplicationContext(), PREF_UPDATE_SERVER);
for (int i = 0; i < listEntry.length; i++) if (currentServer.equals(listEntry[i])) {
checked = i;
break;
}
mBuilder.setSingleChoiceItems(listItems, checked, (dialog, which) -> {
checked = which;
});
mBuilder.setPositiveButton(getStringWithLocale(R.string.dialog_ok), (dialog, which) -> {
Log.e("KCA", "selected: " + checked);
if (checked != -1) {
String selectedServer = listEntry[checked];
setPreferences(getApplicationContext(), PREF_UPDATE_SERVER, selectedServer);
}
});
mBuilder.setNegativeButton(getStringWithLocale(R.string.dialog_cancel), ((dialog, which) -> {
checked = initValue;
}));
AlertDialog mDialog = mBuilder.create();
mDialog.show();
}
});
checkVersionUpdate();
checkResourceUpdate();
}
use of com.antest1.kcanotify.KcaConstants.PREF_CHECK_UPDATE_START 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