Эх сурвалжийг харах

adjusted to master

Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
tobiasKaminsky 5 жил өмнө
parent
commit
154b9af533

+ 4 - 0
src/main/java/com/nextcloud/client/di/ComponentsModule.java

@@ -76,6 +76,7 @@ import com.owncloud.android.ui.fragment.contactsbackup.ContactListFragment;
 import com.owncloud.android.ui.preview.PreviewImageActivity;
 import com.owncloud.android.ui.preview.PreviewImageFragment;
 import com.owncloud.android.ui.preview.PreviewMediaFragment;
+import com.owncloud.android.ui.preview.PreviewTextFileFragment;
 import com.owncloud.android.ui.preview.PreviewTextFragment;
 import com.owncloud.android.ui.preview.PreviewTextStringFragment;
 import com.owncloud.android.ui.preview.PreviewVideoActivity;
@@ -139,6 +140,9 @@ abstract class ComponentsModule {
     @ContributesAndroidInjector abstract ContactListFragment chooseContactListFragment();
     @ContributesAndroidInjector abstract PreviewMediaFragment previewMediaFragment();
     @ContributesAndroidInjector abstract PreviewTextFragment previewTextFragment();
+
+    @ContributesAndroidInjector
+    abstract PreviewTextFileFragment previewTextFileFragment();
     @ContributesAndroidInjector abstract PreviewTextStringFragment previewTextStringFragment();
     @ContributesAndroidInjector abstract PhotoFragment photoFragment();
 

+ 1 - 1
src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java

@@ -2371,7 +2371,7 @@ public class FileDisplayActivity extends FileActivity
             args.putBoolean(EXTRA_SEARCH, searchOpen);
             args.putString(EXTRA_SEARCH_QUERY, searchQuery);
             Fragment textPreviewFragment = Fragment.instantiate(getApplicationContext(),
-                    PreviewTextFragment.class.getName(), args);
+                                                                PreviewTextFileFragment.class.getName(), args);
             setSecondFragment(textPreviewFragment);
             updateFragmentsVisibility(true);
             updateActionBarTitleAndHomeButton(file);

+ 47 - 47
src/main/java/com/owncloud/android/ui/adapter/OCFileListAdapter.java

@@ -25,8 +25,8 @@
 package com.owncloud.android.ui.adapter;
 
 import android.accounts.AccountManager;
+import android.app.Activity;
 import android.content.ContentValues;
-import android.content.Context;
 import android.content.res.Resources;
 import android.graphics.Bitmap;
 import android.graphics.PorterDuff;
@@ -106,12 +106,12 @@ public class OCFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
     private static final int showFilenameColumnThreshold = 4;
     private final ComponentsGetter transferServiceGetter;
     private final String userId;
-    private Context mContext;
+    private Activity activity;
     private AppPreferences preferences;
     private UserAccountManager accountManager;
     private List<OCFile> mFiles = new ArrayList<>();
     private List<OCFile> mFilesAll = new ArrayList<>();
-    private boolean mHideItemOptions;
+    private boolean hideItemOptions;
     private long lastTimestamp;
     private boolean gridView;
     private boolean multiSelect;
@@ -136,7 +136,7 @@ public class OCFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
     @Setter private OCFile highlightedItem;
 
     public OCFileListAdapter(
-        Context context,
+        Activity activity,
         User user,
         AppPreferences preferences,
         UserAccountManager accountManager,
@@ -146,18 +146,18 @@ public class OCFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
         boolean gridView
     ) {
         this.ocFileListFragmentInterface = ocFileListFragmentInterface;
-        mContext = context;
+        this.activity = activity;
         this.preferences = preferences;
         this.accountManager = accountManager;
         this.user = user;
-        mHideItemOptions = argHideItemOptions;
+        hideItemOptions = argHideItemOptions;
         this.gridView = gridView;
         checkedFiles = new HashSet<>();
 
         this.transferServiceGetter = transferServiceGetter;
 
         if (this.user != null) {
-            AccountManager platformAccountManager = AccountManager.get(mContext);
+            AccountManager platformAccountManager = AccountManager.get(this.activity);
             userId = platformAccountManager.getUserData(this.user.toPlatformAccount(),
                                                 com.owncloud.android.lib.common.accounts.AccountUtils.Constants.KEY_USER_ID);
         } else {
@@ -285,28 +285,28 @@ public class OCFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
             default:
             case VIEWTYPE_ITEM:
                 if (gridView) {
-                    View itemView = LayoutInflater.from(mContext).inflate(R.layout.grid_item, parent, false);
+                    View itemView = LayoutInflater.from(activity).inflate(R.layout.grid_item, parent, false);
                     return new OCFileListGridItemViewHolder(itemView);
                 } else {
-                    View itemView = LayoutInflater.from(mContext).inflate(R.layout.list_item, parent, false);
+                    View itemView = LayoutInflater.from(activity).inflate(R.layout.list_item, parent, false);
                     return new OCFileListItemViewHolder(itemView);
                 }
 
             case VIEWTYPE_IMAGE:
                 if (gridView) {
-                    View itemView = LayoutInflater.from(mContext).inflate(R.layout.grid_image, parent, false);
+                    View itemView = LayoutInflater.from(activity).inflate(R.layout.grid_image, parent, false);
                     return new OCFileListGridImageViewHolder(itemView);
                 } else {
-                    View itemView = LayoutInflater.from(mContext).inflate(R.layout.list_item, parent, false);
+                    View itemView = LayoutInflater.from(activity).inflate(R.layout.list_item, parent, false);
                     return new OCFileListItemViewHolder(itemView);
                 }
 
             case VIEWTYPE_FOOTER:
-                View itemView = LayoutInflater.from(mContext).inflate(R.layout.list_footer, parent, false);
+                View itemView = LayoutInflater.from(activity).inflate(R.layout.list_footer, parent, false);
                 return new OCFileListFooterViewHolder(itemView);
 
             case VIEWTYPE_HEADER:
-                View headerView = LayoutInflater.from(mContext).inflate(R.layout.list_header, parent, false);
+                View headerView = LayoutInflater.from(activity).inflate(R.layout.list_header, parent, false);
 
                 ViewGroup.LayoutParams layoutParams = headerView.getLayoutParams();
                 layoutParams.height = (int) (parent.getHeight() * 0.3);
@@ -321,7 +321,7 @@ public class OCFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
         if (holder instanceof OCFileListFooterViewHolder) {
             OCFileListFooterViewHolder footerViewHolder = (OCFileListFooterViewHolder) holder;
             footerViewHolder.footerText.setText(getFooterText());
-            footerViewHolder.progressBar.getIndeterminateDrawable().setColorFilter(ThemeUtils.primaryColor(mContext),
+            footerViewHolder.progressBar.getIndeterminateDrawable().setColorFilter(ThemeUtils.primaryColor(activity),
                                                                                    PorterDuff.Mode.SRC_IN);
             footerViewHolder.progressBar.setVisibility(
                 ocFileListFragmentInterface.isLoading() ? View.VISIBLE : View.GONE);
@@ -329,7 +329,7 @@ public class OCFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
             OCFileListHeaderViewHolder headerViewHolder = (OCFileListHeaderViewHolder) holder;
             String text = currentDirectory.getRichWorkspace();
 
-            PreviewTextFragment.setText(headerViewHolder.headerText, text, mContext);
+            PreviewTextFragment.setText(headerViewHolder.headerText, text, getItem(position), activity);
             headerViewHolder.headerView.setOnClickListener(v -> ocFileListFragmentInterface.onHeaderClicked());
         } else {
             OCFileListGridImageViewHolder gridViewHolder = (OCFileListGridImageViewHolder) holder;
@@ -342,21 +342,21 @@ public class OCFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
             setThumbnail(file, gridViewHolder.thumbnail);
 
             if (highlightedItem != null && file.getFileId() == highlightedItem.getFileId()) {
-                gridViewHolder.itemLayout.setBackgroundColor(mContext.getResources()
+                gridViewHolder.itemLayout.setBackgroundColor(activity.getResources()
                                                                  .getColor(R.color.selected_item_background));
             } else if (isCheckedFile(file)) {
-                gridViewHolder.itemLayout.setBackgroundColor(mContext.getResources()
+                gridViewHolder.itemLayout.setBackgroundColor(activity.getResources()
                                                                  .getColor(R.color.selected_item_background));
                 gridViewHolder.checkbox.setImageDrawable(ThemeUtils.tintDrawable(R.drawable.ic_checkbox_marked,
-                                                                                 ThemeUtils.primaryColor(mContext)));
+                                                                                 ThemeUtils.primaryColor(activity)));
             } else {
-                gridViewHolder.itemLayout.setBackgroundColor(mContext.getResources().getColor(R.color.bg_default));
+                gridViewHolder.itemLayout.setBackgroundColor(activity.getResources().getColor(R.color.bg_default));
                 gridViewHolder.checkbox.setImageResource(R.drawable.ic_checkbox_blank_outline);
             }
 
             gridViewHolder.itemLayout.setOnClickListener(v -> ocFileListFragmentInterface.onItemClicked(file));
 
-            if (!mHideItemOptions) {
+            if (!hideItemOptions) {
                 gridViewHolder.itemLayout.setLongClickable(true);
                 gridViewHolder.itemLayout.setOnLongClickListener(v ->
                                                                      ocFileListFragmentInterface.onLongItemClicked(file));
@@ -374,11 +374,11 @@ public class OCFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
             if (holder instanceof OCFileListItemViewHolder) {
                 OCFileListItemViewHolder itemViewHolder = (OCFileListItemViewHolder) holder;
 
-                Resources resources = mContext.getResources();
+                Resources resources = activity.getResources();
                 float avatarRadius = resources.getDimension(R.dimen.list_item_avatar_icon_radius);
 
                 if ((file.isSharedWithMe() || file.isSharedWithSharee()) && !multiSelect && !gridView &&
-                    !mHideItemOptions) {
+                    !hideItemOptions) {
                     itemViewHolder.sharedAvatars.setVisibility(View.VISIBLE);
                     itemViewHolder.sharedAvatars.removeAllViews();
 
@@ -396,14 +396,14 @@ public class OCFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
                     Log_OC.d(this, "sharees of " + file.getFileName() + ": " + sharees);
 
                     int shareeSize = Math.min(sharees.size(), 3);
-                    int w = DisplayUtils.convertDpToPixel(40, mContext);
-                    int margin = DisplayUtils.convertDpToPixel(24, mContext);
+                    int w = DisplayUtils.convertDpToPixel(40, activity);
+                    int margin = DisplayUtils.convertDpToPixel(24, activity);
                     int size = 60 * (shareeSize - 1) + w;
 
                     for (int i = 0; i < shareeSize; i++) {
                         ShareeUser sharee = file.getSharees().get(i);
 
-                        ImageView avatar = new ImageView(mContext);
+                        ImageView avatar = new ImageView(activity);
 
                         if (i == 0 && sharees.size() > 3) {
                             avatar.setImageResource(R.drawable.ic_people);
@@ -427,7 +427,7 @@ public class OCFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
                                                        avatarRadius,
                                                        resources,
                                                        avatar,
-                                                       mContext);
+                                                       activity);
                             }
                         }
 
@@ -464,10 +464,10 @@ public class OCFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
                 } else {
                     itemViewHolder.fileSize.setText(DisplayUtils.bytesToHumanReadable(file.getFileLength()));
                 }
-                itemViewHolder.lastModification.setText(DisplayUtils.getRelativeTimestamp(mContext,
+                itemViewHolder.lastModification.setText(DisplayUtils.getRelativeTimestamp(activity,
                                                                                           file.getModificationTimestamp()));
 
-                if (multiSelect || gridView || mHideItemOptions) {
+                if (multiSelect || gridView || hideItemOptions) {
                     itemViewHolder.overflowMenu.setVisibility(View.GONE);
                 } else {
                     itemViewHolder.overflowMenu.setVisibility(View.VISIBLE);
@@ -530,7 +530,7 @@ public class OCFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
                 }
             }
 
-            if (mHideItemOptions || (file.isFolder() && !file.canReshare())) {
+            if (hideItemOptions || (file.isFolder() && !file.canReshare())) {
                 gridViewHolder.shared.setVisibility(View.GONE);
             } else {
                 showShareIcon(gridViewHolder, file);
@@ -545,7 +545,7 @@ public class OCFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
         String server = split[1];
 
         String url = "https://" + server + "/index.php/avatar/" + userId + "/" +
-            DisplayUtils.convertDpToPixel(avatarRadius, mContext);
+            DisplayUtils.convertDpToPixel(avatarRadius, activity);
 
         Drawable placeholder;
         try {
@@ -556,7 +556,7 @@ public class OCFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
         }
 
         avatar.setTag(null);
-        Glide.with(mContext).load(url)
+        Glide.with(activity).load(url)
             .asBitmap()
             .placeholder(placeholder)
             .error(placeholder)
@@ -564,7 +564,7 @@ public class OCFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
                 @Override
                 protected void setResource(Bitmap resource) {
                     RoundedBitmapDrawable circularBitmapDrawable =
-                        RoundedBitmapDrawableFactory.create(mContext.getResources(), resource);
+                        RoundedBitmapDrawableFactory.create(activity.getResources(), resource);
                     circularBitmapDrawable.setCircular(true);
                     avatar.setImageDrawable(circularBitmapDrawable);
                 }
@@ -576,7 +576,7 @@ public class OCFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
             thumbnailView.setImageDrawable(MimeTypeUtil
                                                .getFolderTypeIcon(file.isSharedWithMe() || file.isSharedWithSharee(),
                                                                   file.isSharedViaLink(), file.isEncrypted(),
-                                                                  file.getMountType(), mContext));
+                                                                  file.getMountType(), activity));
         } else {
             if (file.getRemoteId() != null && file.isPreviewAvailable()) {
                 // Thumbnail in cache?
@@ -606,10 +606,10 @@ public class OCFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
                                     MimeTypeUtil.getFileTypeIcon(file.getMimeType(),
                                                                  file.getFileName(),
                                                                  user.toPlatformAccount(),
-                                                                 mContext));
+                                                                 activity));
                             }
                             final ThumbnailsCacheManager.AsyncThumbnailDrawable asyncDrawable =
-                                new ThumbnailsCacheManager.AsyncThumbnailDrawable(mContext.getResources(),
+                                new ThumbnailsCacheManager.AsyncThumbnailDrawable(activity.getResources(),
                                                                                   thumbnail, task);
                             thumbnailView.setImageDrawable(asyncDrawable);
                             asyncTasks.add(task);
@@ -622,13 +622,13 @@ public class OCFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
                 }
 
                 if ("image/png".equalsIgnoreCase(file.getMimeType())) {
-                    thumbnailView.setBackgroundColor(mContext.getResources().getColor(R.color.bg_default));
+                    thumbnailView.setBackgroundColor(activity.getResources().getColor(R.color.bg_default));
                 }
             } else {
                 thumbnailView.setImageDrawable(MimeTypeUtil.getFileTypeIcon(file.getMimeType(),
                                                                             file.getFileName(),
                                                                             user.toPlatformAccount(),
-                                                                            mContext));
+                                                                            activity));
             }
         }
     }
@@ -656,7 +656,7 @@ public class OCFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
 
     private String generateFooterText(int filesCount, int foldersCount) {
         String output;
-        Resources resources = mContext.getResources();
+        Resources resources = activity.getResources();
 
         if (filesCount + foldersCount <= 0) {
             output = "";
@@ -723,14 +723,14 @@ public class OCFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
                 } else {
                     sharedIconView.setVisibility(View.VISIBLE);
                     sharedIconView.setImageResource(R.drawable.shared_via_users);
-                    sharedIconView.setContentDescription(mContext.getString(R.string.shared_icon_shared));
+                    sharedIconView.setContentDescription(activity.getString(R.string.shared_icon_shared));
                 }
             } else if (file.isSharedViaLink()) {
                 sharedIconView.setImageResource(R.drawable.shared_via_link);
-                sharedIconView.setContentDescription(mContext.getString(R.string.shared_icon_shared_via_link));
+                sharedIconView.setContentDescription(activity.getString(R.string.shared_icon_shared_via_link));
             } else {
                 sharedIconView.setImageResource(R.drawable.ic_unshared);
-                sharedIconView.setContentDescription(mContext.getString(R.string.shared_icon_share));
+                sharedIconView.setContentDescription(activity.getString(R.string.shared_icon_share));
             }
             if (accountManager.accountOwnsFile(file, user.toPlatformAccount())) {
                 sharedIconView.setOnClickListener(view -> ocFileListFragmentInterface.onShareIconClick(file));
@@ -795,7 +795,7 @@ public class OCFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
         }
 
         if (mStorageManager == null) {
-            mStorageManager = new FileDataStorageManager(user.toPlatformAccount(), mContext.getContentResolver());
+            mStorageManager = new FileDataStorageManager(user.toPlatformAccount(), activity.getContentResolver());
         }
 
         if (clear) {
@@ -856,12 +856,12 @@ public class OCFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
 
                 // get ocFile from Server to have an up-to-date copy
                 RemoteOperationResult result = new ReadFileRemoteOperation(ocShare.getPath()).execute(user.toPlatformAccount(),
-                                                                                                      mContext);
+                                                                                                      activity);
 
                 if (result.isSuccess()) {
                     OCFile file = FileStorageUtils.fillOCFile((RemoteFile) result.getData().get(0));
                     FileStorageUtils.searchForLocalFileInDefaultPath(file, user.toPlatformAccount());
-                    file = mStorageManager.saveFileWithParent(file, mContext);
+                    file = mStorageManager.saveFileWithParent(file, activity);
 
                     ShareType newShareType = ocShare.getShareType();
                     if (newShareType == ShareType.PUBLIC_LINK) {
@@ -922,7 +922,7 @@ public class OCFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
                     mStorageManager.saveFile(ocFile);
                 } else {
 
-                    ocFile = mStorageManager.saveFileWithParent(ocFile, mContext);
+                    ocFile = mStorageManager.saveFileWithParent(ocFile, activity);
 
                     // also sync folder content
                     if (ocFile.isFolder()) {
@@ -933,8 +933,8 @@ public class OCFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
                                                                                             false,
                                                                                             mStorageManager,
                                                                                             user.toPlatformAccount(),
-                                                                                            mContext);
-                        refreshFolderOperation.execute(user.toPlatformAccount(), mContext);
+                                                                                            activity);
+                        refreshFolderOperation.execute(user.toPlatformAccount(), activity);
                     }
                 }
 

+ 1 - 3
src/main/java/com/owncloud/android/ui/preview/PreviewTextFileFragment.java

@@ -215,7 +215,7 @@ public class PreviewTextFileFragment extends PreviewTextFragment {
                 mOriginalText = stringWriter.toString();
                 mSearchView.setOnQueryTextListener(PreviewTextFileFragment.this);
 
-                setText(textView, mOriginalText, getContext());
+                setText(textView, mOriginalText, getFile(), requireActivity());
 
                 if (mSearchOpen) {
                     mSearchView.setQuery(mSearchQuery, true);
@@ -226,9 +226,7 @@ public class PreviewTextFileFragment extends PreviewTextFragment {
             if (mMultiView != null) {
                 mMultiView.setVisibility(View.GONE);
             }
-
         }
-
     }
 
     /**

+ 24 - 18
src/main/java/com/owncloud/android/ui/preview/PreviewTextFragment.java

@@ -19,11 +19,12 @@
 
 package com.owncloud.android.ui.preview;
 
-import android.content.Context;
+import android.app.Activity;
 import android.content.Intent;
 import android.graphics.Color;
 import android.graphics.PorterDuff;
 import android.graphics.PorterDuffColorFilter;
+import android.net.Uri;
 import android.os.Bundle;
 import android.os.Handler;
 import android.text.Html;
@@ -42,9 +43,12 @@ import android.widget.Toast;
 import com.nextcloud.client.account.UserAccountManager;
 import com.nextcloud.client.di.Injectable;
 import com.owncloud.android.R;
+import com.owncloud.android.datamodel.OCFile;
 import com.owncloud.android.lib.common.utils.Log_OC;
 import com.owncloud.android.ui.activity.FileDisplayActivity;
 import com.owncloud.android.ui.fragment.FileFragment;
+import com.owncloud.android.utils.DisplayUtils;
+import com.owncloud.android.utils.MimeTypeUtil;
 import com.owncloud.android.utils.StringUtils;
 import com.owncloud.android.utils.ThemeUtils;
 
@@ -53,12 +57,9 @@ import javax.inject.Inject;
 import androidx.annotation.NonNull;
 import androidx.appcompat.widget.SearchView;
 import io.noties.markwon.AbstractMarkwonPlugin;
-import io.noties.markwon.LinkResolver;
-import io.noties.markwon.LinkResolverDef;
 import io.noties.markwon.Markwon;
 import io.noties.markwon.MarkwonConfiguration;
 import io.noties.markwon.core.MarkwonTheme;
-import io.noties.markwon.core.spans.LinkSpan;
 import io.noties.markwon.ext.strikethrough.StrikethroughPlugin;
 import io.noties.markwon.ext.tables.TablePlugin;
 import io.noties.markwon.ext.tasklist.TaskListDrawable;
@@ -172,7 +173,7 @@ public abstract class PreviewTextFragment extends FileFragment implements Search
                         mTextPreview.setText(Html.fromHtml(coloredText.replace("\n", "<br \\>")));
                     }
                 } else {
-                    setText(mTextPreview, mOriginalText, getContext());
+                    setText(mTextPreview, mOriginalText, getFile(), requireActivity());
                 }
             }, delay);
         }
@@ -182,19 +183,20 @@ public abstract class PreviewTextFragment extends FileFragment implements Search
         }
     }
 
-    protected static Spanned getRenderedMarkdownText(Context context, String markdown) {
+    protected static Spanned getRenderedMarkdownText(Activity activity, String markdown) {
         Prism4j prism4j = new Prism4j(new MarkwonGrammarLocator());
         Prism4jTheme prism4jTheme = Prism4jThemeDefault.create();
         TaskListDrawable drawable = new TaskListDrawable(Color.GRAY, Color.GRAY, Color.WHITE);
-        drawable.setColorFilter(ThemeUtils.primaryColor(context, true), PorterDuff.Mode.SRC_ATOP);
+        drawable.setColorFilter(ThemeUtils.primaryColor(activity, true), PorterDuff.Mode.SRC_ATOP);
 
-        final Markwon markwon = Markwon.builder(context)
+        final Markwon markwon = Markwon.builder(activity)
             .usePlugin(new AbstractMarkwonPlugin() {
                 @Override
                 public void configureTheme(@NonNull MarkwonTheme.Builder builder) {
                     TextPaint textPaint = new TextPaint();
-                    textPaint.setColorFilter(new PorterDuffColorFilter(ThemeUtils.primaryColor(context), PorterDuff.Mode.SRC_ATOP));
-                    builder.linkColor(ThemeUtils.primaryColor(context, true));
+                    textPaint.setColorFilter(new PorterDuffColorFilter(ThemeUtils.primaryColor(activity),
+                                                                       PorterDuff.Mode.SRC_ATOP));
+                    builder.linkColor(ThemeUtils.primaryColor(activity, true));
                 }
 
                 @Override
@@ -202,15 +204,15 @@ public abstract class PreviewTextFragment extends FileFragment implements Search
                     builder.linkResolver((view, link) -> {
                         try {
                             Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(link));
-                            DisplayUtils.startIntentIfAppAvailable(intent, getActivity(), R.string.no_browser_available);
+                            DisplayUtils.startIntentIfAppAvailable(intent, activity, R.string.no_browser_available);
                         } catch (Throwable throwable) {
-                            Toast.makeText(context, R.string.error_opening_link, Toast.LENGTH_SHORT).show();
+                            Toast.makeText(activity, R.string.error_opening_link, Toast.LENGTH_SHORT).show();
                         }
 
                     });
                 }
             })
-            .usePlugin(TablePlugin.create(context))
+            .usePlugin(TablePlugin.create(activity))
             .usePlugin(TaskListPlugin.create(drawable))
             .usePlugin(StrikethroughPlugin.create())
             .usePlugin(HtmlPlugin.create())
@@ -227,12 +229,16 @@ public abstract class PreviewTextFragment extends FileFragment implements Search
         getActivity().runOnUiThread(() -> getActivity().onBackPressed());
     }
 
-    private void setText(TextView textView, String text, OCFile file) {
-        if (MimeTypeUtil.MIMETYPE_TEXT_MARKDOWN.equals(file.getMimeType())
-        android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN
-            && context != null) {
+    public static void setText(TextView textView, String text, OCFile file, Activity activity) {
+        setText(textView, text, file, activity, false);
+    }
+
+    public static void setText(TextView textView, String text, OCFile file, Activity activity, boolean ignoreMimetype) {
+        if ((MimeTypeUtil.MIMETYPE_TEXT_MARKDOWN.equals(file.getMimeType()) || ignoreMimetype) &&
+            android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN
+            && activity != null) {
             textView.setMovementMethod(LinkMovementMethod.getInstance());
-            textView.setText(getRenderedMarkdownText(getContext(), text));
+            textView.setText(getRenderedMarkdownText(activity, text));
         } else {
             textView.setText(text);
         }

+ 1 - 1
src/main/java/com/owncloud/android/ui/preview/PreviewTextStringFragment.java

@@ -145,7 +145,7 @@ public class PreviewTextStringFragment extends PreviewTextFragment {
     void loadAndShowTextPreview() {
         if (mTextPreview != null) {
             mOriginalText = getFile().getRichWorkspace();
-            setText(mTextPreview, mOriginalText, getContext());
+            setText(mTextPreview, mOriginalText, getFile(), requireActivity(), true);
             mTextPreview.setVisibility(View.VISIBLE);
         }