diff --git a/app/src/main/java/com/owncloud/android/ui/dialog/ChooseRichDocumentsTemplateDialogFragment.kt b/app/src/main/java/com/owncloud/android/ui/dialog/ChooseRichDocumentsTemplateDialogFragment.kt
index b62576fd822c..477aeb78d939 100644
--- a/app/src/main/java/com/owncloud/android/ui/dialog/ChooseRichDocumentsTemplateDialogFragment.kt
+++ b/app/src/main/java/com/owncloud/android/ui/dialog/ChooseRichDocumentsTemplateDialogFragment.kt
@@ -21,437 +21,438 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see .
*/
-
-package com.owncloud.android.ui.dialog;
-
-import android.app.Activity;
-import android.app.Dialog;
-import android.content.Intent;
-import android.os.AsyncTask;
-import android.os.Bundle;
-import android.text.Editable;
-import android.text.TextWatcher;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.widget.Button;
-
-import com.google.android.material.button.MaterialButton;
-import com.google.android.material.dialog.MaterialAlertDialogBuilder;
-import com.google.common.collect.Sets;
-import com.nextcloud.client.account.CurrentAccountProvider;
-import com.nextcloud.client.account.User;
-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.datamodel.Template;
-import com.owncloud.android.files.CreateFileFromTemplateOperation;
-import com.owncloud.android.files.FetchTemplateOperation;
-import com.owncloud.android.lib.common.OwnCloudClient;
-import com.owncloud.android.lib.common.operations.RemoteOperationResult;
-import com.owncloud.android.lib.common.utils.Log_OC;
-import com.owncloud.android.lib.resources.files.ReadFileRemoteOperation;
-import com.owncloud.android.lib.resources.files.model.RemoteFile;
-import com.owncloud.android.ui.activity.ExternalSiteWebView;
-import com.owncloud.android.ui.activity.RichDocumentsEditorWebView;
-import com.owncloud.android.ui.adapter.RichDocumentsTemplateAdapter;
-import com.owncloud.android.utils.DisplayUtils;
-import com.owncloud.android.utils.FileStorageUtils;
-import com.owncloud.android.utils.KeyboardUtils;
-import com.owncloud.android.utils.NextcloudServer;
-import com.owncloud.android.utils.theme.ViewThemeUtils;
-
-import java.lang.ref.WeakReference;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Objects;
-import java.util.Set;
-
-import javax.inject.Inject;
-
-import androidx.annotation.NonNull;
-import androidx.appcompat.app.AlertDialog;
-import androidx.fragment.app.DialogFragment;
-import androidx.recyclerview.widget.GridLayoutManager;
+package com.owncloud.android.ui.dialog
+
+import android.annotation.SuppressLint
+import android.app.Dialog
+import android.content.Intent
+import android.os.AsyncTask
+import android.os.Bundle
+import android.text.Editable
+import android.text.TextWatcher
+import android.view.View
+import androidx.appcompat.app.AlertDialog
+import androidx.fragment.app.DialogFragment
+import androidx.recyclerview.widget.GridLayoutManager
+import com.google.android.material.button.MaterialButton
+import com.google.android.material.dialog.MaterialAlertDialogBuilder
+import com.google.common.collect.Sets
+import com.nextcloud.client.account.CurrentAccountProvider
+import com.nextcloud.client.account.User
+import com.nextcloud.client.di.Injectable
+import com.nextcloud.client.network.ClientFactory
+import com.nextcloud.client.network.ClientFactory.CreationException
+import com.nextcloud.utils.extensions.getParcelableArgument
+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.datamodel.Template
+import com.owncloud.android.files.CreateFileFromTemplateOperation
+import com.owncloud.android.files.FetchTemplateOperation
+import com.owncloud.android.lib.common.OwnCloudClient
+import com.owncloud.android.lib.common.utils.Log_OC
+import com.owncloud.android.lib.resources.files.ReadFileRemoteOperation
+import com.owncloud.android.lib.resources.files.model.RemoteFile
+import com.owncloud.android.ui.activity.ExternalSiteWebView
+import com.owncloud.android.ui.activity.RichDocumentsEditorWebView
+import com.owncloud.android.ui.adapter.RichDocumentsTemplateAdapter
+import com.owncloud.android.ui.dialog.IndeterminateProgressDialog.Companion.newInstance
+import com.owncloud.android.utils.DisplayUtils
+import com.owncloud.android.utils.FileStorageUtils
+import com.owncloud.android.utils.KeyboardUtils
+import com.owncloud.android.utils.NextcloudServer
+import com.owncloud.android.utils.theme.ViewThemeUtils
+import java.lang.ref.WeakReference
+import java.util.Objects
+import javax.inject.Inject
/**
* Dialog to show templates for new documents/spreadsheets/presentations.
*/
-public class ChooseRichDocumentsTemplateDialogFragment extends DialogFragment implements View.OnClickListener,
- RichDocumentsTemplateAdapter.ClickListener, Injectable {
-
- private static final String ARG_PARENT_FOLDER = "PARENT_FOLDER";
- private static final String ARG_TYPE = "TYPE";
- private static final String TAG = ChooseRichDocumentsTemplateDialogFragment.class.getSimpleName();
- private static final String DOT = ".";
- public static final int SINGLE_TEMPLATE = 1;
- private static final String WAIT_DIALOG_TAG = "WAIT";
-
- private Set fileNames;
-
- @Inject CurrentAccountProvider currentAccount;
- @Inject ClientFactory clientFactory;
- @Inject ViewThemeUtils viewThemeUtils;
- @Inject FileDataStorageManager fileDataStorageManager;
- @Inject KeyboardUtils keyboardUtils;
- private RichDocumentsTemplateAdapter adapter;
- private OCFile parentFolder;
- private OwnCloudClient client;
- private MaterialButton positiveButton;
- private DialogFragment waitDialog;
-
- public enum Type {
- DOCUMENT,
- SPREADSHEET,
- PRESENTATION
+class ChooseRichDocumentsTemplateDialogFragment :
+ DialogFragment(),
+ View.OnClickListener,
+ RichDocumentsTemplateAdapter.ClickListener,
+ Injectable {
+
+ private var fileNames: MutableSet? = null
+
+ @JvmField
+ @Inject
+ var currentAccount: CurrentAccountProvider? = null
+
+ @JvmField
+ @Inject
+ var clientFactory: ClientFactory? = null
+
+ @JvmField
+ @Inject
+ var viewThemeUtils: ViewThemeUtils? = null
+
+ @JvmField
+ @Inject
+ var fileDataStorageManager: FileDataStorageManager? = null
+
+ @JvmField
+ @Inject
+ var keyboardUtils: KeyboardUtils? = null
+
+ private var adapter: RichDocumentsTemplateAdapter? = null
+ private var parentFolder: OCFile? = null
+ private var client: OwnCloudClient? = null
+ private var positiveButton: MaterialButton? = null
+ private var waitDialog: DialogFragment? = null
+
+ enum class Type {
+ DOCUMENT, SPREADSHEET, PRESENTATION
}
- ChooseTemplateBinding binding;
+ var binding: ChooseTemplateBinding? = null
- @NextcloudServer(max = 18) // will be removed in favor of generic direct editing
- public static ChooseRichDocumentsTemplateDialogFragment newInstance(OCFile parentFolder, Type type) {
- ChooseRichDocumentsTemplateDialogFragment frag = new ChooseRichDocumentsTemplateDialogFragment();
- Bundle args = new Bundle();
- args.putParcelable(ARG_PARENT_FOLDER, parentFolder);
- args.putString(ARG_TYPE, type.name());
- frag.setArguments(args);
- return frag;
+ override fun onStart() {
+ super.onStart()
+ setupAlertDialogButtons()
+ checkEnablingCreateButton()
}
- @Override
- public void onStart() {
- super.onStart();
-
- AlertDialog alertDialog = (AlertDialog) getDialog();
-
- if (alertDialog != null) {
- positiveButton = (MaterialButton) alertDialog.getButton(AlertDialog.BUTTON_POSITIVE);
- viewThemeUtils.material.colorMaterialButtonPrimaryTonal(positiveButton);
-
- MaterialButton negativeButton = (MaterialButton) alertDialog.getButton(AlertDialog.BUTTON_NEGATIVE);
- if (negativeButton != null) {
- viewThemeUtils.material.colorMaterialButtonPrimaryBorderless(negativeButton);
+ private fun setupAlertDialogButtons() {
+ (dialog as AlertDialog?)?.run {
+ positiveButton = getButton(AlertDialog.BUTTON_POSITIVE) as MaterialButton
+ positiveButton?.let {
+ viewThemeUtils?.material?.colorMaterialButtonPrimaryTonal(it)
}
+ positiveButton?.setOnClickListener(this@ChooseRichDocumentsTemplateDialogFragment)
+ positiveButton?.isEnabled = false
- positiveButton.setOnClickListener(this);
- positiveButton.setEnabled(false);
+ val negativeButton = getButton(AlertDialog.BUTTON_NEGATIVE) as? MaterialButton
+ negativeButton?.let {
+ viewThemeUtils?.material?.colorMaterialButtonPrimaryBorderless(it)
+ }
}
-
- checkEnablingCreateButton();
}
- @Override
- public void onResume() {
- super.onResume();
- keyboardUtils.showKeyboardForEditText(requireDialog().getWindow(), binding.filename);
+ override fun onResume() {
+ super.onResume()
+ binding?.let {
+ keyboardUtils?.showKeyboardForEditText(requireDialog().window, it.filename)
+ }
}
- @NonNull
- @Override
- public Dialog onCreateDialog(Bundle savedInstanceState) {
- Bundle arguments = getArguments();
- if (arguments == null) {
- throw new IllegalArgumentException("Arguments may not be null");
- }
+ override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
+ val bundle = arguments ?: throw IllegalArgumentException("Arguments may not be null")
+ val activity = activity ?: throw IllegalArgumentException("Activity may not be null")
- Activity activity = getActivity();
- if (activity == null) {
- throw new IllegalArgumentException("Activity may not be null");
- }
+ setupClient()
+ setupParentFolder(bundle)
- try {
- client = clientFactory.create(currentAccount.getUser());
- } catch (ClientFactory.CreationException e) {
- throw new RuntimeException(e); // we'll NPE without the client
- }
+ val inflater = requireActivity().layoutInflater
+ binding = ChooseTemplateBinding.inflate(inflater, null, false)
- parentFolder = arguments.getParcelable(ARG_PARENT_FOLDER);
- List folderContent = fileDataStorageManager.getFolderContent(parentFolder, false);
- fileNames = Sets.newHashSetWithExpectedSize(folderContent.size());
+ viewThemeUtils?.material?.colorTextInputLayout(binding!!.filenameContainer)
- for (OCFile file : folderContent) {
- fileNames.add(file.getFileName());
- }
+ val type = bundle.getString(ARG_TYPE)?.let { Type.valueOf(it) }
+ setupList(type)
- // Inflate the layout for the dialog
- LayoutInflater inflater = requireActivity().getLayoutInflater();
- binding = ChooseTemplateBinding.inflate(inflater, null, false);
- View view = binding.getRoot();
+ setupFileName()
- viewThemeUtils.material.colorTextInputLayout(binding.filenameContainer);
+ // Build the dialog
+ val builder = MaterialAlertDialogBuilder(activity)
+ builder.setView(view)
+ .setPositiveButton(R.string.create, null)
+ .setNegativeButton(R.string.common_cancel, null)
- Type type = Type.valueOf(arguments.getString(ARG_TYPE));
- new FetchTemplateTask(this, client).execute(type);
+ type?.let {
+ builder.setTitle(getTitle(it))
+ }
- binding.list.setHasFixedSize(true);
- binding.list.setLayoutManager(new GridLayoutManager(activity, 2));
- adapter = new RichDocumentsTemplateAdapter(type,
- this,
- getContext(),
- currentAccount,
- clientFactory,
- viewThemeUtils);
- binding.list.setAdapter(adapter);
+ viewThemeUtils?.dialog?.colorMaterialAlertDialogBackground(activity, builder)
+ return builder.create()
+ }
- binding.filename.addTextChangedListener(new TextWatcher() {
- @Override
- public void beforeTextChanged(CharSequence s, int start, int count, int after) {
+ @Suppress("TooGenericExceptionThrown")
+ private fun setupClient() {
+ client = try {
+ clientFactory?.create(currentAccount?.user)
+ } catch (e: CreationException) {
+ // we'll NPE without the client
+ throw RuntimeException(e)
+ }
+ }
+ private fun setupParentFolder(bundle: Bundle?) {
+ parentFolder = bundle?.getParcelableArgument(ARG_PARENT_FOLDER, OCFile::class.java)
+ val folderContent = fileDataStorageManager?.getFolderContent(parentFolder, false)
+ fileNames = folderContent?.size?.let { Sets.newHashSetWithExpectedSize(it) }
+ if (folderContent != null) {
+ for (file in folderContent) {
+ fileNames?.add(file.fileName)
}
+ }
+ }
- @Override
- public void onTextChanged(CharSequence s, int start, int before, int count) {
- // not needed
- }
+ private fun setupList(type: Type?) {
+ FetchTemplateTask(this, client).execute(type)
+ binding?.list?.setHasFixedSize(true)
+ binding?.list?.layoutManager = GridLayoutManager(activity, 2)
+ adapter = RichDocumentsTemplateAdapter(
+ type,
+ this,
+ context,
+ currentAccount,
+ clientFactory,
+ viewThemeUtils
+ )
+ binding?.list?.adapter = adapter
+ }
- @Override
- public void afterTextChanged(Editable s) {
- checkEnablingCreateButton();
+ @Suppress("EmptyFunctionBlock")
+ private fun setupFileName() {
+ binding?.filename?.addTextChangedListener(object : TextWatcher {
+ override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) {}
+ override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) {
}
- });
-
- int titleTextId = getTitle(type);
- // Build the dialog
- MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(activity);
- builder.setView(view)
- .setPositiveButton(R.string.create, null)
- .setNegativeButton(R.string.common_cancel, null)
- .setTitle(titleTextId);
-
- viewThemeUtils.dialog.colorMaterialAlertDialogBackground(activity, builder);
-
- return builder.create();
+ override fun afterTextChanged(s: Editable) {
+ checkEnablingCreateButton()
+ }
+ })
}
- private int getTitle(Type type) {
- if (type == Type.DOCUMENT) {
- return R.string.create_new_document;
- } else if (type == Type.SPREADSHEET) {
- return R.string.create_new_spreadsheet;
- } else if (type == Type.PRESENTATION) {
- return R.string.create_new_presentation;
+ @Suppress("ReturnCount")
+ private fun getTitle(type: Type): Int {
+ when (type) {
+ Type.DOCUMENT -> {
+ return R.string.create_new_document
+ }
+ Type.SPREADSHEET -> {
+ return R.string.create_new_spreadsheet
+ }
+ Type.PRESENTATION -> {
+ return R.string.create_new_presentation
+ }
+ else -> return R.string.select_template
}
-
- return R.string.select_template;
}
- @Override
- public void onDestroyView() {
- super.onDestroyView();
- binding = null;
+ override fun onDestroyView() {
+ super.onDestroyView()
+ binding = null
}
- private void createFromTemplate(Template template, String path) {
- waitDialog = IndeterminateProgressDialog.newInstance(R.string.wait_a_moment, false);
- waitDialog.show(getParentFragmentManager(), WAIT_DIALOG_TAG);
- new CreateFileFromTemplateTask(this, client, template, path, currentAccount.getUser()).execute();
+ private fun createFromTemplate(template: Template, path: String) {
+ waitDialog = newInstance(R.string.wait_a_moment, false)
+ waitDialog?.show(parentFragmentManager, WAIT_DIALOG_TAG)
+ CreateFileFromTemplateTask(this, client, template, path, currentAccount!!.user).execute()
}
- public void setTemplateList(List templateList) {
- adapter.setTemplateList(templateList);
- adapter.notifyDataSetChanged();
+ @SuppressLint("NotifyDataSetChanged")
+ fun setTemplateList(templateList: List?) {
+ adapter?.setTemplateList(templateList)
+ adapter?.notifyDataSetChanged()
}
- @Override
- public void onClick(View v) {
- String name = binding.filename.getText().toString();
- String path = parentFolder.getRemotePath() + name;
-
- Template selectedTemplate = adapter.getSelectedTemplate();
+ override fun onClick(v: View) {
+ val name = binding?.filename?.text.toString()
+ val path = parentFolder?.remotePath + name
+ val selectedTemplate = adapter?.selectedTemplate
if (selectedTemplate == null) {
- DisplayUtils.showSnackMessage(binding.list, R.string.select_one_template);
- } else if (name.isEmpty() || name.equalsIgnoreCase(DOT + selectedTemplate.getExtension())) {
- DisplayUtils.showSnackMessage(binding.list, R.string.enter_filename);
- } else if (!name.endsWith(selectedTemplate.getExtension())) {
- createFromTemplate(selectedTemplate, path + DOT + selectedTemplate.getExtension());
+ DisplayUtils.showSnackMessage(binding?.list, R.string.select_one_template)
+ } else if (name.isEmpty() || name.equals(DOT + selectedTemplate.extension, ignoreCase = true)) {
+ DisplayUtils.showSnackMessage(binding?.list, R.string.enter_filename)
+ } else if (!name.endsWith(selectedTemplate.extension)) {
+ createFromTemplate(selectedTemplate, path + DOT + selectedTemplate.extension)
} else {
- createFromTemplate(selectedTemplate, path);
+ createFromTemplate(selectedTemplate, path)
}
}
- @Override
- public void onClick(Template template) {
- onTemplateChosen(template);
+ override fun onClick(template: Template) {
+ onTemplateChosen(template)
}
- private void onTemplateChosen(Template template) {
- adapter.setTemplateAsActive(template);
- prefillFilenameIfEmpty(template);
- checkEnablingCreateButton();
+ private fun onTemplateChosen(template: Template) {
+ adapter?.setTemplateAsActive(template)
+ prefillFilenameIfEmpty(template)
+ checkEnablingCreateButton()
}
- private void prefillFilenameIfEmpty(Template template) {
- String name = binding.filename.getText().toString();
- if (name.isEmpty() || name.equalsIgnoreCase(DOT + template.getExtension())) {
- binding.filename.setText(String.format("%s.%s", template.getName(), template.getExtension()));
+ private fun prefillFilenameIfEmpty(template: Template) {
+ val name = binding?.filename?.text.toString()
+ if (name.isEmpty() || name.equals(DOT + template.extension, ignoreCase = true)) {
+ binding?.filename?.setText(String.format("%s.%s", template.name, template.extension))
}
-
- final int dotIndex = binding.filename.getText().toString().lastIndexOf('.');
+ val dotIndex = binding?.filename?.text.toString().lastIndexOf('.')
if (dotIndex >= 0) {
- binding.filename.setSelection(dotIndex);
+ binding?.filename?.setSelection(dotIndex)
}
}
- private void checkEnablingCreateButton() {
+ private fun checkEnablingCreateButton() {
if (positiveButton != null) {
- Template selectedTemplate = adapter.getSelectedTemplate();
- String name = Objects.requireNonNull(binding.filename.getText()).toString();
- boolean isNameJustExtension = selectedTemplate != null && name.equalsIgnoreCase(
- DOT + selectedTemplate.getExtension());
- boolean isNameEmpty = name.isEmpty() || isNameJustExtension;
- boolean state = selectedTemplate != null && !isNameEmpty && !fileNames.contains(name);
-
- positiveButton.setEnabled(selectedTemplate != null && !name.isEmpty() &&
- !name.equalsIgnoreCase(DOT + selectedTemplate.getExtension()));
- positiveButton.setEnabled(state);
- positiveButton.setClickable(state);
- binding.filenameContainer.setErrorEnabled(!state);
-
+ val selectedTemplate = adapter!!.selectedTemplate
+ val name = Objects.requireNonNull(binding?.filename?.text).toString()
+ val isNameJustExtension = selectedTemplate != null && name.equals(
+ DOT + selectedTemplate.extension, ignoreCase = true
+ )
+ val isNameEmpty = name.isEmpty() || isNameJustExtension
+ val state = selectedTemplate != null && !isNameEmpty && !fileNames!!.contains(name)
+ positiveButton?.isEnabled = selectedTemplate != null && name.isNotEmpty() && !name.equals(
+ DOT + selectedTemplate.extension,
+ ignoreCase = true
+ )
+ positiveButton?.isEnabled = state
+ positiveButton?.isClickable = state
+ binding?.filenameContainer?.isErrorEnabled = !state
if (!state) {
if (isNameEmpty) {
- binding.filenameContainer.setError(getText(R.string.filename_empty));
+ binding?.filenameContainer?.error = getText(R.string.filename_empty)
} else {
- binding.filenameContainer.setError(getText(R.string.file_already_exists));
+ binding?.filenameContainer?.error = getText(R.string.file_already_exists)
}
}
}
}
- private static class CreateFileFromTemplateTask extends AsyncTask {
- private OwnCloudClient client;
- private WeakReference chooseTemplateDialogFragmentWeakReference;
- private Template template;
- private String path;
- private User user;
- private OCFile file;
-
- CreateFileFromTemplateTask(ChooseRichDocumentsTemplateDialogFragment chooseTemplateDialogFragment,
- OwnCloudClient client,
- Template template,
- String path,
- User user
- ) {
- this.client = client;
- this.chooseTemplateDialogFragmentWeakReference = new WeakReference<>(chooseTemplateDialogFragment);
- this.template = template;
- this.path = path;
- this.user = user;
+ @Suppress("DEPRECATION")
+ private class CreateFileFromTemplateTask(
+ chooseTemplateDialogFragment: ChooseRichDocumentsTemplateDialogFragment?,
+ private val client: OwnCloudClient?,
+ private val template: Template,
+ private val path: String,
+ private val user: User
+ ) : AsyncTask() {
+ private val chooseTemplateDialogFragmentWeakReference: WeakReference
+ private var file: OCFile? = null
+
+ init {
+ chooseTemplateDialogFragmentWeakReference = WeakReference(chooseTemplateDialogFragment)
}
- @Override
- protected String doInBackground(Void... voids) {
- RemoteOperationResult result = new CreateFileFromTemplateOperation(path, template.getId()).execute(client);
-
- if (result.isSuccess()) {
+ @Deprecated("Deprecated in Java")
+ override fun doInBackground(vararg voids: Void?): String {
+ val result = CreateFileFromTemplateOperation(path, template.id).execute(client)
+ return if (result.isSuccess) {
// get file
- RemoteOperationResult newFileResult = new ReadFileRemoteOperation(path).execute(client);
-
- if (newFileResult.isSuccess()) {
- OCFile temp = FileStorageUtils.fillOCFile((RemoteFile) newFileResult.getData().get(0));
-
+ val newFileResult = ReadFileRemoteOperation(path).execute(client)
+ if (newFileResult.isSuccess) {
+ val temp = FileStorageUtils.fillOCFile(newFileResult.data[0] as RemoteFile)
if (chooseTemplateDialogFragmentWeakReference.get() != null) {
- FileDataStorageManager storageManager = new FileDataStorageManager(
+ val storageManager = FileDataStorageManager(
user,
- chooseTemplateDialogFragmentWeakReference.get().requireContext().getContentResolver());
- storageManager.saveFile(temp);
- file = storageManager.getFileByPath(path);
-
- return result.getData().get(0).toString();
+ chooseTemplateDialogFragmentWeakReference.get()!!.requireContext().contentResolver
+ )
+ storageManager.saveFile(temp)
+ file = storageManager.getFileByPath(path)
+ result.data[0].toString()
} else {
- return "";
+ ""
}
} else {
- return "";
+ ""
}
} else {
- return "";
+ ""
}
}
- @Override
- protected void onPostExecute(String url) {
- ChooseRichDocumentsTemplateDialogFragment fragment = chooseTemplateDialogFragmentWeakReference.get();
-
- if (fragment != null && fragment.isAdded()) {
+ @Deprecated("Deprecated in Java")
+ override fun onPostExecute(url: String) {
+ val fragment = chooseTemplateDialogFragmentWeakReference.get()
+ if (fragment != null && fragment.isAdded) {
if (fragment.waitDialog != null) {
- fragment.waitDialog.dismiss();
+ fragment.waitDialog!!.dismiss()
}
-
if (url.isEmpty()) {
- fragment.dismiss();
- DisplayUtils.showSnackMessage(fragment.requireActivity(), R.string.error_creating_file_from_template);
+ fragment.dismiss()
+ DisplayUtils.showSnackMessage(
+ fragment.requireActivity(),
+ R.string.error_creating_file_from_template
+ )
} else {
- Intent collaboraWebViewIntent = new Intent(MainApp.getAppContext(), RichDocumentsEditorWebView.class);
- collaboraWebViewIntent.putExtra(ExternalSiteWebView.EXTRA_TITLE, "Collabora");
- collaboraWebViewIntent.putExtra(ExternalSiteWebView.EXTRA_URL, url);
- collaboraWebViewIntent.putExtra(ExternalSiteWebView.EXTRA_FILE, file);
- collaboraWebViewIntent.putExtra(ExternalSiteWebView.EXTRA_SHOW_SIDEBAR, false);
- collaboraWebViewIntent.putExtra(ExternalSiteWebView.EXTRA_TEMPLATE, template);
- fragment.startActivity(collaboraWebViewIntent);
-
- fragment.dismiss();
+ val collaboraWebViewIntent = Intent(MainApp.getAppContext(), RichDocumentsEditorWebView::class.java)
+ collaboraWebViewIntent.putExtra(ExternalSiteWebView.EXTRA_TITLE, "Collabora")
+ collaboraWebViewIntent.putExtra(ExternalSiteWebView.EXTRA_URL, url)
+ collaboraWebViewIntent.putExtra(ExternalSiteWebView.EXTRA_FILE, file)
+ collaboraWebViewIntent.putExtra(ExternalSiteWebView.EXTRA_SHOW_SIDEBAR, false)
+ collaboraWebViewIntent.putExtra(ExternalSiteWebView.EXTRA_TEMPLATE, template)
+ fragment.startActivity(collaboraWebViewIntent)
+ fragment.dismiss()
}
} else {
- Log_OC.e(TAG, "Error creating file from template!");
+ Log_OC.e(TAG, "Error creating file from template!")
}
}
}
- private static class FetchTemplateTask extends AsyncTask> {
+ @Suppress("DEPRECATION")
+ private class FetchTemplateTask(
+ chooseTemplateDialogFragment: ChooseRichDocumentsTemplateDialogFragment,
+ private val client: OwnCloudClient?
+ ) : AsyncTask>() {
+ private val chooseTemplateDialogFragmentWeakReference: WeakReference
- private OwnCloudClient client;
- private WeakReference chooseTemplateDialogFragmentWeakReference;
-
- FetchTemplateTask(ChooseRichDocumentsTemplateDialogFragment chooseTemplateDialogFragment, OwnCloudClient client) {
- this.client = client;
- this.chooseTemplateDialogFragmentWeakReference = new WeakReference<>(chooseTemplateDialogFragment);
+ init {
+ chooseTemplateDialogFragmentWeakReference = WeakReference(chooseTemplateDialogFragment)
}
- @Override
- protected List doInBackground(Type... type) {
- FetchTemplateOperation fetchTemplateOperation = new FetchTemplateOperation(type[0]);
- RemoteOperationResult result = fetchTemplateOperation.execute(client);
-
- if (!result.isSuccess()) {
- return new ArrayList<>();
+ @Deprecated("Deprecated in Java")
+ override fun doInBackground(vararg type: Type?): List {
+ val fetchTemplateOperation = FetchTemplateOperation(type[0])
+ val result = fetchTemplateOperation.execute(client)
+ if (!result.isSuccess) {
+ return ArrayList()
}
-
- List templateList = new ArrayList<>();
- for (Object object : result.getData()) {
- templateList.add((Template) object);
+ val templateList: MutableList = ArrayList()
+ for (`object` in result.data) {
+ templateList.add(`object` as Template)
}
-
- return templateList;
+ return templateList
}
- @Override
- protected void onPostExecute(List templateList) {
- ChooseRichDocumentsTemplateDialogFragment fragment = chooseTemplateDialogFragmentWeakReference.get();
-
+ @Deprecated("Deprecated in Java")
+ override fun onPostExecute(templateList: List) {
+ val fragment = chooseTemplateDialogFragmentWeakReference.get()
if (fragment != null) {
if (templateList.isEmpty()) {
- fragment.dismiss();
- DisplayUtils.showSnackMessage(fragment.requireActivity(), R.string.error_retrieving_templates);
+ fragment.dismiss()
+ DisplayUtils.showSnackMessage(fragment.requireActivity(), R.string.error_retrieving_templates)
} else {
- if (templateList.size() == SINGLE_TEMPLATE) {
- fragment.onTemplateChosen(templateList.get(0));
- fragment.binding.list.setVisibility(View.GONE);
+ if (templateList.size == SINGLE_TEMPLATE) {
+ fragment.onTemplateChosen(templateList[0])
+ fragment.binding?.list?.visibility = View.GONE
} else {
- String name = DOT + templateList.get(0).getExtension();
- fragment.binding.filename.setText(name);
- fragment.binding.helperText.setVisibility(View.VISIBLE);
+ val name = DOT + templateList[0].extension
+ fragment.binding?.filename?.setText(name)
+ fragment.binding?.helperText?.visibility = View.VISIBLE
}
-
- fragment.setTemplateList(templateList);
+ fragment.setTemplateList(templateList)
}
} else {
- Log_OC.e(TAG, "Error streaming file: no previewMediaFragment!");
+ Log_OC.e(TAG, "Error streaming file: no previewMediaFragment!")
}
}
}
+
+ companion object {
+ private const val ARG_PARENT_FOLDER = "PARENT_FOLDER"
+ private const val ARG_TYPE = "TYPE"
+ private val TAG = ChooseRichDocumentsTemplateDialogFragment::class.java.simpleName
+ private const val DOT = "."
+ const val SINGLE_TEMPLATE = 1
+ private const val WAIT_DIALOG_TAG = "WAIT"
+
+ @JvmStatic
+ @NextcloudServer(max = 18) // will be removed in favor of generic direct editing
+ fun newInstance(parentFolder: OCFile?, type: Type): ChooseRichDocumentsTemplateDialogFragment {
+ val frag = ChooseRichDocumentsTemplateDialogFragment()
+ val args = Bundle()
+ args.putParcelable(ARG_PARENT_FOLDER, parentFolder)
+ args.putString(ARG_TYPE, type.name)
+ frag.arguments = args
+ return frag
+ }
+ }
}