use of it.niedermann.owncloud.notes.persistence.entity.Account in project nextcloud-notes by stefan-niedermann.
the class ManageAccountsActivity method onChangeFileSuffix.
private void onChangeFileSuffix(@NonNull Account localAccount) {
final var repository = NotesRepository.getInstance(getApplicationContext());
final var spinner = new Spinner(this);
final var wrapper = createDialogViewWrapper();
final var adapter = ArrayAdapter.createFromResource(this, R.array.settings_file_suffixes, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
final var dialog = new BrandedAlertDialogBuilder(this).setTitle(R.string.settings_file_suffix).setMessage(R.string.settings_file_suffix_description).setView(wrapper).setNeutralButton(android.R.string.cancel, null).setPositiveButton(R.string.action_edit_save, (v, d) -> new Thread(() -> {
try {
final Call<NotesSettings> putSettingsCall = repository.putServerSettings(AccountImporter.getSingleSignOnAccount(this, localAccount.getAccountName()), new NotesSettings(null, spinner.getSelectedItem().toString()), getPreferredApiVersion(localAccount.getApiVersion()));
putSettingsCall.enqueue(new Callback<>() {
@Override
public void onResponse(@NonNull Call<NotesSettings> call, @NonNull Response<NotesSettings> response) {
final var body = response.body();
if (response.isSuccessful() && body != null) {
runOnUiThread(() -> Toast.makeText(ManageAccountsActivity.this, getString(R.string.settings_file_suffix_success, body.getNotesPath()), Toast.LENGTH_LONG).show());
} else {
runOnUiThread(() -> Toast.makeText(ManageAccountsActivity.this, getString(R.string.http_status_code, response.code()), Toast.LENGTH_LONG).show());
}
}
@Override
public void onFailure(@NonNull Call<NotesSettings> call, @NonNull Throwable t) {
runOnUiThread(() -> ExceptionDialogFragment.newInstance(t).show(getSupportFragmentManager(), ExceptionDialogFragment.class.getSimpleName()));
}
});
} catch (NextcloudFilesAppAccountNotFoundException e) {
runOnUiThread(() -> ExceptionDialogFragment.newInstance(e).show(getSupportFragmentManager(), ExceptionDialogFragment.class.getSimpleName()));
}
}).start()).show();
try {
repository.getServerSettings(AccountImporter.getSingleSignOnAccount(this, localAccount.getAccountName()), getPreferredApiVersion(localAccount.getApiVersion())).enqueue(new Callback<>() {
@Override
public void onResponse(@NonNull Call<NotesSettings> call, @NonNull Response<NotesSettings> response) {
final NotesSettings body = response.body();
runOnUiThread(() -> {
if (response.isSuccessful() && body != null) {
for (int i = 0; i < adapter.getCount(); i++) {
if (adapter.getItem(i).equals(body.getFileSuffix())) {
spinner.setSelection(i);
break;
}
}
wrapper.removeAllViews();
wrapper.addView(spinner);
} else {
dialog.dismiss();
ExceptionDialogFragment.newInstance(new Exception(getString(R.string.http_status_code, response.code()))).show(getSupportFragmentManager(), ExceptionDialogFragment.class.getSimpleName());
}
});
}
@Override
public void onFailure(@NonNull Call<NotesSettings> call, @NonNull Throwable t) {
runOnUiThread(() -> {
dialog.dismiss();
ExceptionDialogFragment.newInstance(t).show(getSupportFragmentManager(), ExceptionDialogFragment.class.getSimpleName());
});
}
});
} catch (NextcloudFilesAppAccountNotFoundException e) {
dialog.dismiss();
ExceptionDialogFragment.newInstance(e).show(getSupportFragmentManager(), ExceptionDialogFragment.class.getSimpleName());
}
}
Aggregations