|
@@ -20,10 +20,12 @@
|
|
|
package com.owncloud.android.ui.preview;
|
|
|
|
|
|
import android.accounts.Account;
|
|
|
+import android.content.Context;
|
|
|
import android.os.AsyncTask;
|
|
|
import android.os.Bundle;
|
|
|
import android.os.Handler;
|
|
|
import android.text.Html;
|
|
|
+import android.text.Spanned;
|
|
|
import android.view.LayoutInflater;
|
|
|
import android.view.Menu;
|
|
|
import android.view.MenuInflater;
|
|
@@ -66,6 +68,11 @@ import javax.inject.Inject;
|
|
|
import androidx.annotation.NonNull;
|
|
|
import androidx.appcompat.widget.SearchView;
|
|
|
import androidx.core.view.MenuItemCompat;
|
|
|
+import io.noties.markwon.Markwon;
|
|
|
+import io.noties.markwon.ext.strikethrough.StrikethroughPlugin;
|
|
|
+import io.noties.markwon.ext.tables.TablePlugin;
|
|
|
+import io.noties.markwon.ext.tasklist.TaskListPlugin;
|
|
|
+import io.noties.markwon.html.HtmlPlugin;
|
|
|
|
|
|
public class PreviewTextFragment extends FileFragment implements SearchView.OnQueryTextListener, Injectable {
|
|
|
private static final String EXTRA_FILE = "FILE";
|
|
@@ -120,8 +127,6 @@ public class PreviewTextFragment extends FileFragment implements SearchView.OnQu
|
|
|
View ret = inflater.inflate(R.layout.text_file_preview, container, false);
|
|
|
mTextPreview = ret.findViewById(R.id.text_preview);
|
|
|
|
|
|
- mTextPreview = ret.findViewById(R.id.text_preview);
|
|
|
-
|
|
|
mMultiView = ret.findViewById(R.id.multi_view);
|
|
|
|
|
|
setupMultiView(ret);
|
|
@@ -243,7 +248,7 @@ public class PreviewTextFragment extends FileFragment implements SearchView.OnQu
|
|
|
mTextPreview.setText(Html.fromHtml(coloredText.replace("\n", "<br \\>")));
|
|
|
}
|
|
|
} else {
|
|
|
- mTextPreview.setText(mOriginalText);
|
|
|
+ setText(mTextPreview, mOriginalText, getFile());
|
|
|
}
|
|
|
}, delay);
|
|
|
}
|
|
@@ -253,6 +258,17 @@ public class PreviewTextFragment extends FileFragment implements SearchView.OnQu
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private Spanned getRenderedMarkdownText(Context context, String markdown) {
|
|
|
+ final Markwon markwon = Markwon.builder(context)
|
|
|
+ .usePlugin(TablePlugin.create(context))
|
|
|
+ .usePlugin(TaskListPlugin.create(context))
|
|
|
+ .usePlugin(StrikethroughPlugin.create())
|
|
|
+ .usePlugin(HtmlPlugin.create())
|
|
|
+ .build();
|
|
|
+
|
|
|
+ return markwon.toMarkdown(markdown);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* Reads the file to preview and shows its contents. Too critical to be anonymous.
|
|
|
*/
|
|
@@ -324,7 +340,8 @@ public class PreviewTextFragment extends FileFragment implements SearchView.OnQu
|
|
|
if (textView != null) {
|
|
|
mOriginalText = stringWriter.toString();
|
|
|
mSearchView.setOnQueryTextListener(PreviewTextFragment.this);
|
|
|
- textView.setText(mOriginalText);
|
|
|
+
|
|
|
+ setText(textView, mOriginalText, getFile());
|
|
|
|
|
|
if (mSearchOpen) {
|
|
|
mSearchView.setQuery(mSearchQuery, true);
|
|
@@ -505,4 +522,13 @@ public class PreviewTextFragment extends FileFragment implements SearchView.OnQu
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
+
|
|
|
+ private void setText(TextView textView, String text, OCFile file) {
|
|
|
+ if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN
|
|
|
+ && MimeTypeUtil.MIMETYPE_TEXT_MARKDOWN.equals(file.getMimeType())) {
|
|
|
+ textView.setText(getRenderedMarkdownText(getContext(), text));
|
|
|
+ } else {
|
|
|
+ textView.setText(text);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|