|
@@ -24,12 +24,10 @@
|
|
|
|
|
|
package com.owncloud.android.ui.dialog;
|
|
|
|
|
|
-import android.annotation.SuppressLint;
|
|
|
import android.app.Activity;
|
|
|
import android.app.Dialog;
|
|
|
import android.content.Context;
|
|
|
import android.content.Intent;
|
|
|
-import android.graphics.PorterDuff;
|
|
|
import android.os.AsyncTask;
|
|
|
import android.os.Bundle;
|
|
|
import android.util.ArrayMap;
|
|
@@ -38,7 +36,6 @@ import android.view.View;
|
|
|
import android.view.Window;
|
|
|
import android.view.WindowManager.LayoutParams;
|
|
|
import android.widget.Button;
|
|
|
-import android.widget.EditText;
|
|
|
|
|
|
import com.nextcloud.android.lib.resources.directediting.DirectEditingCreateFileRemoteOperation;
|
|
|
import com.nextcloud.android.lib.resources.directediting.DirectEditingObtainListOfTemplatesRemoteOperation;
|
|
@@ -48,6 +45,7 @@ import com.nextcloud.client.di.Injectable;
|
|
|
import com.nextcloud.client.network.ClientFactory;
|
|
|
import com.owncloud.android.MainApp;
|
|
|
import com.owncloud.android.R;
|
|
|
+import com.owncloud.android.databinding.ChooseTemplateBinding;
|
|
|
import com.owncloud.android.datamodel.FileDataStorageManager;
|
|
|
import com.owncloud.android.datamodel.OCFile;
|
|
|
import com.owncloud.android.lib.common.Creator;
|
|
@@ -66,6 +64,7 @@ import com.owncloud.android.utils.FileStorageUtils;
|
|
|
import com.owncloud.android.utils.ThemeUtils;
|
|
|
|
|
|
import java.lang.ref.WeakReference;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
import javax.inject.Inject;
|
|
|
|
|
@@ -73,9 +72,6 @@ import androidx.annotation.NonNull;
|
|
|
import androidx.appcompat.app.AlertDialog;
|
|
|
import androidx.fragment.app.DialogFragment;
|
|
|
import androidx.recyclerview.widget.GridLayoutManager;
|
|
|
-import androidx.recyclerview.widget.RecyclerView;
|
|
|
-import butterknife.BindView;
|
|
|
-import butterknife.ButterKnife;
|
|
|
|
|
|
/**
|
|
|
* Dialog to show templates for new documents/spreadsheets/presentations.
|
|
@@ -100,11 +96,7 @@ public class ChooseTemplateDialogFragment extends DialogFragment implements View
|
|
|
PRESENTATION
|
|
|
}
|
|
|
|
|
|
- @BindView(R.id.list)
|
|
|
- RecyclerView listView;
|
|
|
-
|
|
|
- @BindView(R.id.filename)
|
|
|
- EditText fileName;
|
|
|
+ ChooseTemplateBinding binding;
|
|
|
|
|
|
public static ChooseTemplateDialogFragment newInstance(OCFile parentFolder, Creator creator) {
|
|
|
ChooseTemplateDialogFragment frag = new ChooseTemplateDialogFragment();
|
|
@@ -144,18 +136,16 @@ public class ChooseTemplateDialogFragment extends DialogFragment implements View
|
|
|
throw new IllegalArgumentException("Activity may not be null");
|
|
|
}
|
|
|
|
|
|
- int accentColor = ThemeUtils.primaryAccentColor(getContext());
|
|
|
-
|
|
|
parentFolder = arguments.getParcelable(ARG_PARENT_FOLDER);
|
|
|
creator = arguments.getParcelable(ARG_CREATOR);
|
|
|
|
|
|
// Inflate the layout for the dialog
|
|
|
- LayoutInflater inflater = activity.getLayoutInflater();
|
|
|
- @SuppressLint("InflateParams") View view = inflater.inflate(R.layout.choose_template, null);
|
|
|
- ButterKnife.bind(this, view);
|
|
|
+ LayoutInflater inflater = requireActivity().getLayoutInflater();
|
|
|
+ binding = ChooseTemplateBinding.inflate(inflater, null, false);
|
|
|
+ View view = binding.getRoot();
|
|
|
|
|
|
- fileName.requestFocus();
|
|
|
- fileName.getBackground().setColorFilter(accentColor, PorterDuff.Mode.SRC_ATOP);
|
|
|
+ binding.filename.requestFocus();
|
|
|
+ ThemeUtils.colorTextInputLayout(binding.filenameContainer, ThemeUtils.primaryColor(getContext()));
|
|
|
|
|
|
try {
|
|
|
User user = currentAccount.getUser();
|
|
@@ -164,10 +154,10 @@ public class ChooseTemplateDialogFragment extends DialogFragment implements View
|
|
|
Log_OC.e(TAG, "Loading stream url not possible: " + e);
|
|
|
}
|
|
|
|
|
|
- listView.setHasFixedSize(true);
|
|
|
- listView.setLayoutManager(new GridLayoutManager(activity, 2));
|
|
|
+ binding.list.setHasFixedSize(true);
|
|
|
+ binding.list.setLayoutManager(new GridLayoutManager(activity, 2));
|
|
|
adapter = new TemplateAdapter(creator.getMimetype(), this, getContext(), currentAccount, clientFactory);
|
|
|
- listView.setAdapter(adapter);
|
|
|
+ binding.list.setAdapter(adapter);
|
|
|
|
|
|
// Build the dialog
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
|
|
@@ -186,12 +176,18 @@ public class ChooseTemplateDialogFragment extends DialogFragment implements View
|
|
|
return dialog;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public void onDestroyView() {
|
|
|
+ super.onDestroyView();
|
|
|
+ binding = null;
|
|
|
+ }
|
|
|
+
|
|
|
private void createFromTemplate(Template template, String path) {
|
|
|
new CreateFileFromTemplateTask(this, clientFactory, currentAccount.getUser(), template, path, creator).execute();
|
|
|
}
|
|
|
|
|
|
public void setTemplateList(TemplateList templateList) {
|
|
|
- ArrayMap<String, Template> map = new ArrayMap();
|
|
|
+ Map<String, Template> map = new ArrayMap<>();
|
|
|
|
|
|
map.put("1", new Template("1", "txt", "Test", "null"));
|
|
|
map.put("2", new Template("2", "txt", "Test", "null"));
|
|
@@ -208,15 +204,15 @@ public class ChooseTemplateDialogFragment extends DialogFragment implements View
|
|
|
|
|
|
@Override
|
|
|
public void onClick(View v) {
|
|
|
- String name = fileName.getText().toString();
|
|
|
+ String name = binding.filename.getText().toString();
|
|
|
String path = parentFolder.getRemotePath() + name;
|
|
|
|
|
|
Template selectedTemplate = adapter.getSelectedTemplate();
|
|
|
|
|
|
if (selectedTemplate == null) {
|
|
|
- DisplayUtils.showSnackMessage(listView, R.string.select_one_template);
|
|
|
+ DisplayUtils.showSnackMessage(binding.list, R.string.select_one_template);
|
|
|
} else if (name.isEmpty() || name.equalsIgnoreCase(DOT + selectedTemplate.getExtension())) {
|
|
|
- DisplayUtils.showSnackMessage(listView, R.string.enter_filename);
|
|
|
+ DisplayUtils.showSnackMessage(binding.list, R.string.enter_filename);
|
|
|
} else if (!name.endsWith(selectedTemplate.getExtension())) {
|
|
|
createFromTemplate(selectedTemplate, path + DOT + selectedTemplate.getExtension());
|
|
|
} else {
|
|
@@ -299,7 +295,7 @@ public class ChooseTemplateDialogFragment extends DialogFragment implements View
|
|
|
|
|
|
if (fragment != null && fragment.isAdded()) {
|
|
|
if (url.isEmpty()) {
|
|
|
- DisplayUtils.showSnackMessage(fragment.listView, "Error creating file from template");
|
|
|
+ DisplayUtils.showSnackMessage(fragment.binding.list, "Error creating file from template");
|
|
|
} else {
|
|
|
Intent editorWebView = new Intent(MainApp.getAppContext(), TextEditorWebView.class);
|
|
|
editorWebView.putExtra(ExternalSiteWebView.EXTRA_TITLE, "Text");
|
|
@@ -360,12 +356,12 @@ public class ChooseTemplateDialogFragment extends DialogFragment implements View
|
|
|
|
|
|
if (fragment != null && fragment.isAdded()) {
|
|
|
if (templateList.templates.isEmpty()) {
|
|
|
- DisplayUtils.showSnackMessage(fragment.listView, R.string.error_retrieving_templates);
|
|
|
+ DisplayUtils.showSnackMessage(fragment.binding.list, R.string.error_retrieving_templates);
|
|
|
} else {
|
|
|
fragment.setTemplateList(templateList);
|
|
|
|
|
|
String name = DOT + templateList.templates.values().iterator().next().getExtension();
|
|
|
- fragment.fileName.setText(name);
|
|
|
+ fragment.binding.filename.setText(name);
|
|
|
}
|
|
|
} else {
|
|
|
Log_OC.e(TAG, "Error streaming file: no previewMediaFragment!");
|