Search in sources :

Example 1 with BrandedAlertDialogBuilder

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();
}
Also used : TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) BrandedAlertDialogBuilder(it.niedermann.owncloud.notes.branding.BrandedAlertDialogBuilder) NonNull(androidx.annotation.NonNull)

Example 2 with BrandedAlertDialogBuilder

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());
    }
}
Also used : EditText(android.widget.EditText) AttrRes(androidx.annotation.AttrRes) Bundle(android.os.Bundle) AlertDialog(androidx.appcompat.app.AlertDialog) LockedActivity(it.niedermann.owncloud.notes.LockedActivity) ProgressBar(android.widget.ProgressBar) NonNull(androidx.annotation.NonNull) FrameLayout(android.widget.FrameLayout) Response(retrofit2.Response) NextcloudFilesAppAccountNotFoundException(com.nextcloud.android.sso.exceptions.NextcloudFilesAppAccountNotFoundException) SDK_INT(android.os.Build.VERSION.SDK_INT) Px(androidx.annotation.Px) LOLLIPOP_MR1(android.os.Build.VERSION_CODES.LOLLIPOP_MR1) ActivityManageAccountsBinding(it.niedermann.owncloud.notes.databinding.ActivityManageAccountsBinding) Toast(android.widget.Toast) NotesSettings(it.niedermann.owncloud.notes.shared.model.NotesSettings) IResponseCallback(it.niedermann.owncloud.notes.shared.model.IResponseCallback) ViewModelProvider(androidx.lifecycle.ViewModelProvider) R(it.niedermann.owncloud.notes.R) ViewGroup(android.view.ViewGroup) Spinner(android.widget.Spinner) ExceptionDialogFragment(it.niedermann.owncloud.notes.exception.ExceptionDialogFragment) NotesRepository(it.niedermann.owncloud.notes.persistence.NotesRepository) NetworkErrorException(android.accounts.NetworkErrorException) ArrayAdapter(android.widget.ArrayAdapter) AccountImporter(com.nextcloud.android.sso.AccountImporter) BrandedAlertDialogBuilder(it.niedermann.owncloud.notes.branding.BrandedAlertDialogBuilder) Nullable(androidx.annotation.Nullable) TypedValue(android.util.TypedValue) Callback(retrofit2.Callback) ApiVersionUtil.getPreferredApiVersion(it.niedermann.owncloud.notes.shared.util.ApiVersionUtil.getPreferredApiVersion) BrandedDeleteAlertDialogBuilder(it.niedermann.owncloud.notes.branding.BrandedDeleteAlertDialogBuilder) Call(retrofit2.Call) EditText(android.widget.EditText) Account(it.niedermann.owncloud.notes.persistence.entity.Account) Call(retrofit2.Call) NotesSettings(it.niedermann.owncloud.notes.shared.model.NotesSettings) BrandedAlertDialogBuilder(it.niedermann.owncloud.notes.branding.BrandedAlertDialogBuilder) Response(retrofit2.Response) NetworkErrorException(android.accounts.NetworkErrorException) ExceptionDialogFragment(it.niedermann.owncloud.notes.exception.ExceptionDialogFragment) IResponseCallback(it.niedermann.owncloud.notes.shared.model.IResponseCallback) Callback(retrofit2.Callback) NonNull(androidx.annotation.NonNull) NextcloudFilesAppAccountNotFoundException(com.nextcloud.android.sso.exceptions.NextcloudFilesAppAccountNotFoundException)

Example 3 with BrandedAlertDialogBuilder

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());
    }
}
Also used : AttrRes(androidx.annotation.AttrRes) Bundle(android.os.Bundle) AlertDialog(androidx.appcompat.app.AlertDialog) LockedActivity(it.niedermann.owncloud.notes.LockedActivity) ProgressBar(android.widget.ProgressBar) NonNull(androidx.annotation.NonNull) FrameLayout(android.widget.FrameLayout) Response(retrofit2.Response) NextcloudFilesAppAccountNotFoundException(com.nextcloud.android.sso.exceptions.NextcloudFilesAppAccountNotFoundException) SDK_INT(android.os.Build.VERSION.SDK_INT) Px(androidx.annotation.Px) LOLLIPOP_MR1(android.os.Build.VERSION_CODES.LOLLIPOP_MR1) ActivityManageAccountsBinding(it.niedermann.owncloud.notes.databinding.ActivityManageAccountsBinding) Toast(android.widget.Toast) NotesSettings(it.niedermann.owncloud.notes.shared.model.NotesSettings) IResponseCallback(it.niedermann.owncloud.notes.shared.model.IResponseCallback) ViewModelProvider(androidx.lifecycle.ViewModelProvider) R(it.niedermann.owncloud.notes.R) ViewGroup(android.view.ViewGroup) Spinner(android.widget.Spinner) ExceptionDialogFragment(it.niedermann.owncloud.notes.exception.ExceptionDialogFragment) NotesRepository(it.niedermann.owncloud.notes.persistence.NotesRepository) NetworkErrorException(android.accounts.NetworkErrorException) ArrayAdapter(android.widget.ArrayAdapter) AccountImporter(com.nextcloud.android.sso.AccountImporter) BrandedAlertDialogBuilder(it.niedermann.owncloud.notes.branding.BrandedAlertDialogBuilder) Nullable(androidx.annotation.Nullable) TypedValue(android.util.TypedValue) Callback(retrofit2.Callback) ApiVersionUtil.getPreferredApiVersion(it.niedermann.owncloud.notes.shared.util.ApiVersionUtil.getPreferredApiVersion) BrandedDeleteAlertDialogBuilder(it.niedermann.owncloud.notes.branding.BrandedDeleteAlertDialogBuilder) Call(retrofit2.Call) EditText(android.widget.EditText) Account(it.niedermann.owncloud.notes.persistence.entity.Account) Call(retrofit2.Call) Spinner(android.widget.Spinner) NotesSettings(it.niedermann.owncloud.notes.shared.model.NotesSettings) BrandedAlertDialogBuilder(it.niedermann.owncloud.notes.branding.BrandedAlertDialogBuilder) NextcloudFilesAppAccountNotFoundException(com.nextcloud.android.sso.exceptions.NextcloudFilesAppAccountNotFoundException) NetworkErrorException(android.accounts.NetworkErrorException) Response(retrofit2.Response) IResponseCallback(it.niedermann.owncloud.notes.shared.model.IResponseCallback) Callback(retrofit2.Callback) NonNull(androidx.annotation.NonNull) NextcloudFilesAppAccountNotFoundException(com.nextcloud.android.sso.exceptions.NextcloudFilesAppAccountNotFoundException)

Aggregations

NonNull (androidx.annotation.NonNull)3 BrandedAlertDialogBuilder (it.niedermann.owncloud.notes.branding.BrandedAlertDialogBuilder)3 NetworkErrorException (android.accounts.NetworkErrorException)2 SDK_INT (android.os.Build.VERSION.SDK_INT)2 LOLLIPOP_MR1 (android.os.Build.VERSION_CODES.LOLLIPOP_MR1)2 Bundle (android.os.Bundle)2 TypedValue (android.util.TypedValue)2 ViewGroup (android.view.ViewGroup)2 ArrayAdapter (android.widget.ArrayAdapter)2 EditText (android.widget.EditText)2 FrameLayout (android.widget.FrameLayout)2 ProgressBar (android.widget.ProgressBar)2 Spinner (android.widget.Spinner)2 Toast (android.widget.Toast)2 AttrRes (androidx.annotation.AttrRes)2 Nullable (androidx.annotation.Nullable)2 Px (androidx.annotation.Px)2 AlertDialog (androidx.appcompat.app.AlertDialog)2 ViewModelProvider (androidx.lifecycle.ViewModelProvider)2 AccountImporter (com.nextcloud.android.sso.AccountImporter)2