Search in sources :

Example 1 with TemplateAdapter

use of com.owncloud.android.ui.adapter.TemplateAdapter in project android by nextcloud.

the class ChooseTemplateDialogFragment method onCreateDialog.

@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    Bundle arguments = getArguments();
    if (arguments == null) {
        throw new IllegalArgumentException("Arguments may not be null");
    }
    Activity activity = getActivity();
    if (activity == null) {
        throw new IllegalArgumentException("Activity may not be null");
    }
    parentFolder = arguments.getParcelable(ARG_PARENT_FOLDER);
    creator = arguments.getParcelable(ARG_CREATOR);
    title = arguments.getString(ARG_HEADLINE, getString(R.string.select_template));
    if (savedInstanceState == null) {
        title = arguments.getString(ARG_HEADLINE);
    } else {
        title = savedInstanceState.getString(ARG_HEADLINE);
    }
    // Inflate the layout for the dialog
    LayoutInflater inflater = requireActivity().getLayoutInflater();
    binding = ChooseTemplateBinding.inflate(inflater, null, false);
    View view = binding.getRoot();
    binding.filename.requestFocus();
    ThemeTextInputUtils.colorTextInput(binding.filenameContainer, binding.filename, ThemeColorUtils.primaryColor(getContext()));
    binding.filename.setOnKeyListener((v, keyCode, event) -> {
        checkEnablingCreateButton();
        return false;
    });
    binding.filename.addTextChangedListener(new TextWatcher() {

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        // generated method stub
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        // generated method stub
        }

        @Override
        public void afterTextChanged(Editable s) {
            checkEnablingCreateButton();
        }
    });
    try {
        User user = currentAccount.getUser();
        new FetchTemplateTask(this, clientFactory, user, creator).execute();
    } catch (Exception e) {
        Log_OC.e(TAG, "Loading stream url not possible: " + e);
    }
    binding.list.setHasFixedSize(true);
    binding.list.setLayoutManager(new GridLayoutManager(activity, 2));
    adapter = new TemplateAdapter(creator.getMimetype(), this, getContext(), currentAccount, clientFactory);
    binding.list.setAdapter(adapter);
    // Build the dialog
    AlertDialog.Builder builder = new AlertDialog.Builder(activity);
    builder.setView(view).setPositiveButton(R.string.create, null).setNeutralButton(R.string.common_cancel, null).setTitle(title);
    Dialog dialog = builder.create();
    Window window = dialog.getWindow();
    if (window != null) {
        window.setSoftInputMode(LayoutParams.SOFT_INPUT_STATE_VISIBLE);
    }
    return dialog;
}
Also used : AlertDialog(androidx.appcompat.app.AlertDialog) Window(android.view.Window) User(com.nextcloud.client.account.User) Bundle(android.os.Bundle) Activity(android.app.Activity) View(android.view.View) ExternalSiteWebView(com.owncloud.android.ui.activity.ExternalSiteWebView) TextEditorWebView(com.owncloud.android.ui.activity.TextEditorWebView) GridLayoutManager(androidx.recyclerview.widget.GridLayoutManager) AlertDialog(androidx.appcompat.app.AlertDialog) Dialog(android.app.Dialog) LayoutInflater(android.view.LayoutInflater) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) TemplateAdapter(com.owncloud.android.ui.adapter.TemplateAdapter) NonNull(androidx.annotation.NonNull)

Aggregations

Activity (android.app.Activity)1 Dialog (android.app.Dialog)1 Bundle (android.os.Bundle)1 Editable (android.text.Editable)1 TextWatcher (android.text.TextWatcher)1 LayoutInflater (android.view.LayoutInflater)1 View (android.view.View)1 Window (android.view.Window)1 NonNull (androidx.annotation.NonNull)1 AlertDialog (androidx.appcompat.app.AlertDialog)1 GridLayoutManager (androidx.recyclerview.widget.GridLayoutManager)1 User (com.nextcloud.client.account.User)1 ExternalSiteWebView (com.owncloud.android.ui.activity.ExternalSiteWebView)1 TextEditorWebView (com.owncloud.android.ui.activity.TextEditorWebView)1 TemplateAdapter (com.owncloud.android.ui.adapter.TemplateAdapter)1