use of com.tonyodev.fetch2.FetchConfiguration 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.tonyodev.fetch2.FetchConfiguration in project kcanotify by antest1.
the class KcaFairySelectActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_setting_fairy);
toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setTitle(getResources().getString(R.string.setting_menu_kand_title_fairy_select));
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, KcaFairySelectActivity.class.getName());
FetchConfiguration fetchConfiguration = new FetchConfiguration.Builder(getApplicationContext()).setDownloadConcurrentLimit(24).build();
fetch = Fetch.Impl.getInstance(fetchConfiguration);
mProgressDialog = new ProgressDialog(KcaFairySelectActivity.this);
mProgressDialog.setMessage(getStringWithLocale(R.string.download_progress));
mProgressDialog.setIndeterminate(true);
mProgressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
mProgressDialog.setCancelable(false);
mProgressDialog.setProgressNumberFormat("%1d file(s)");
dbHelper = new KcaDBHelper(getApplicationContext(), null, KCANOTIFY_DB_VERSION);
JsonArray icon_info = KcaUtils.getJsonArrayFromStorage(getApplicationContext(), "icon_info.json", dbHelper);
Log.e("KCA-FS", icon_info.toString());
List<String> fairy_id = new ArrayList<>();
boolean fairy_downloaded = getBooleanPreferences(getApplicationContext(), PREF_FAIRY_DOWN_FLAG);
int fairy_size = fairy_downloaded ? icon_info.size() : 1;
if (FAIRY_SPECIAL_FLAG) {
for (int i = 0; i < FAIRY_SPECIAL_COUNT; i++) {
fairy_id.add("noti_icon_".concat(String.valueOf(i + FAIRY_SPECIAL_PREFIX)));
}
}
for (int i = 0; i < fairy_size; i++) {
fairy_id.add("noti_icon_".concat(String.valueOf(i)));
}
final KcaItemAdapter adapter = new KcaItemAdapter(getApplicationContext(), R.layout.listview_image_item, fairy_id);
String pref_value = getStringPreferences(getApplicationContext(), PREF_FAIRY_ICON);
if (pref_value.length() > 0) {
adapter.setPrevActive(Integer.parseInt(pref_value));
}
gv = (GridView) findViewById(R.id.fairy_gridview);
gv.setAdapter(adapter);
gv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
int value = Integer.parseInt(fairy_id.get(position).replace("noti_icon_", ""));
setPreferences(getApplicationContext(), PREF_FAIRY_REV, 0);
setPreferences(getApplicationContext(), PREF_FAIRY_ICON, String.valueOf(value));
if (KcaService.getServiceStatus()) {
JsonObject data = new JsonObject();
data.addProperty("id", value);
Bundle bundle = new Bundle();
bundle.putString("url", KCA_API_PREF_FAIRY_CHANGED);
bundle.putString("data", data.toString());
Message sMsg = sHandler.obtainMessage();
sMsg.setData(bundle);
sHandler.sendMessage(sMsg);
}
adapter.setPrevActive(position);
gv.invalidateViews();
}
});
}
Aggregations