use of it.niedermann.owncloud.notes.branding.BrandedAlertDialogBuilder in project nextcloud-notes by stefan-niedermann.
the class CategoryDialogFragment method onCreateDialog.
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
final var dialogView = View.inflate(getContext(), R.layout.dialog_change_category, null);
binding = DialogChangeCategoryBinding.bind(dialogView);
this.editCategory = binding.search;
if (savedInstanceState == null) {
if (requireArguments().containsKey(PARAM_CATEGORY)) {
editCategory.setText(requireArguments().getString(PARAM_CATEGORY));
}
} else if (savedInstanceState.containsKey(STATE_CATEGORY)) {
editCategory.setText(savedInstanceState.getString(STATE_CATEGORY));
}
adapter = new CategoryAdapter(requireContext(), new CategoryAdapter.CategoryListener() {
@Override
public void onCategoryChosen(String category) {
listener.onCategoryChosen(category);
dismiss();
}
@Override
public void onCategoryAdded() {
listener.onCategoryChosen(editCategory.getText().toString());
dismiss();
}
@Override
public void onCategoryCleared() {
listener.onCategoryChosen("");
dismiss();
}
});
binding.recyclerView.setAdapter(adapter);
categoryLiveData = viewModel.getCategories(accountId);
categoryLiveData.observe(requireActivity(), categories -> adapter.setCategoryList(categories, binding.search.getText().toString()));
editCategory.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
// Nothing to do here...
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
// Nothing to do here...
}
@Override
public void afterTextChanged(Editable s) {
viewModel.postSearchTerm(editCategory.getText().toString());
}
});
return new BrandedAlertDialogBuilder(getActivity()).setTitle(R.string.change_category_title).setView(dialogView).setCancelable(true).setPositiveButton(R.string.action_edit_save, (dialog, which) -> listener.onCategoryChosen(editCategory.getText().toString())).setNegativeButton(R.string.simple_cancel, null).create();
}
use of it.niedermann.owncloud.notes.branding.BrandedAlertDialogBuilder in project nextcloud-notes by stefan-niedermann.
the class ManageAccountsActivity method onChangeNotesPath.
private void onChangeNotesPath(@NonNull Account localAccount) {
final var repository = NotesRepository.getInstance(getApplicationContext());
final var editText = new EditText(this);
final var wrapper = createDialogViewWrapper();
final var dialog = new BrandedAlertDialogBuilder(this).setTitle(R.string.settings_notes_path).setMessage(R.string.settings_notes_path_description).setView(wrapper).setNeutralButton(android.R.string.cancel, null).setPositiveButton(R.string.action_edit_save, (v, d) -> new Thread(() -> {
try {
final var putSettingsCall = repository.putServerSettings(AccountImporter.getSingleSignOnAccount(this, localAccount.getAccountName()), new NotesSettings(editText.getText().toString(), null), 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_notes_path_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) {
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) {
runOnUiThread(() -> {
final var body = response.body();
if (response.isSuccessful() && body != null) {
wrapper.removeAllViews();
final var editText = new EditText(ManageAccountsActivity.this);
editText.setText(body.getNotesPath());
wrapper.addView(editText);
} else {
dialog.dismiss();
ExceptionDialogFragment.newInstance(new NetworkErrorException(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());
}
}
use of it.niedermann.owncloud.notes.branding.BrandedAlertDialogBuilder 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