21
21
package com .owncloud .android .ui .preview ;
22
22
23
23
import android .accounts .Account ;
24
+ import android .content .Context ;
24
25
import android .os .AsyncTask ;
25
26
import android .os .Bundle ;
26
27
import android .view .LayoutInflater ;
48
49
import com .owncloud .android .ui .dialog .LoadingDialog ;
49
50
import com .owncloud .android .ui .fragment .FileFragment ;
50
51
import com .owncloud .android .utils .PreferenceUtils ;
52
+ import io .noties .markwon .Markwon ;
53
+ import io .noties .markwon .ext .strikethrough .StrikethroughPlugin ;
54
+ import io .noties .markwon .ext .tables .TablePlugin ;
55
+ import io .noties .markwon .ext .tasklist .TaskListPlugin ;
56
+ import io .noties .markwon .html .HtmlPlugin ;
51
57
import timber .log .Timber ;
52
58
53
59
import java .io .BufferedWriter ;
@@ -180,7 +186,7 @@ public void onStart() {
180
186
181
187
private void loadAndShowTextPreview () {
182
188
mTextLoadTask = new TextLoadAsyncTask (new WeakReference <>(mTextPreview ));
183
- mTextLoadTask .execute (getFile (). getStoragePath () );
189
+ mTextLoadTask .execute (getFile ());
184
190
}
185
191
186
192
/**
@@ -189,6 +195,7 @@ private void loadAndShowTextPreview() {
189
195
private class TextLoadAsyncTask extends AsyncTask <Object , Void , StringWriter > {
190
196
private final String DIALOG_WAIT_TAG = "DIALOG_WAIT" ;
191
197
private final WeakReference <TextView > mTextViewReference ;
198
+ private String mimeType ;
192
199
193
200
private TextLoadAsyncTask (WeakReference <TextView > textView ) {
194
201
mTextViewReference = textView ;
@@ -205,7 +212,9 @@ protected StringWriter doInBackground(java.lang.Object... params) {
205
212
throw new IllegalArgumentException ("The parameter to " + TextLoadAsyncTask .class .getName () + " must " +
206
213
"be (1) the file location" );
207
214
}
208
- final String location = (String ) params [0 ];
215
+ final OCFile file = (OCFile ) params [0 ];
216
+ final String location = file .getStoragePath ();
217
+ mimeType = file .getMimeType ();
209
218
210
219
FileInputStream inputStream = null ;
211
220
Scanner sc = null ;
@@ -247,7 +256,20 @@ protected void onPostExecute(final StringWriter stringWriter) {
247
256
final TextView textView = mTextViewReference .get ();
248
257
249
258
if (textView != null ) {
250
- textView .setText (new String (stringWriter .getBuffer ()));
259
+ String text = new String (stringWriter .getBuffer ());
260
+ if (mimeType .equals ("text/markdown" )) {
261
+ Context context = textView .getContext ();
262
+ Markwon markwon = Markwon
263
+ .builder (context )
264
+ .usePlugin (TablePlugin .create (context ))
265
+ .usePlugin (StrikethroughPlugin .create ())
266
+ .usePlugin (TaskListPlugin .create (context ))
267
+ .usePlugin (HtmlPlugin .create ())
268
+ .build ();
269
+ markwon .setMarkdown (textView , text );
270
+ } else {
271
+ textView .setText (text );
272
+ }
251
273
textView .setVisibility (View .VISIBLE );
252
274
}
253
275
0 commit comments