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;
}
Aggregations