Skip to content

Commit c95e694

Browse files
committed
Extend OCFileListAdapter to handle open in notes button
Signed-off-by: ZetaTom <70907959+ZetaTom@users.noreply.github.com>
1 parent 710ffe3 commit c95e694

File tree

1 file changed

+40
-6
lines changed

1 file changed

+40
-6
lines changed

app/src/main/java/com/owncloud/android/ui/adapter/OCFileListAdapter.java

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import com.nextcloud.client.preferences.AppPreferences;
4141
import com.nextcloud.model.OCFileFilterType;
4242
import com.nextcloud.model.OfflineOperationType;
43+
import com.nextcloud.utils.LinkHelper;
4344
import com.nextcloud.utils.extensions.ViewExtensionsKt;
4445
import com.nextcloud.utils.mdm.MDMConfig;
4546
import com.owncloud.android.MainApp;
@@ -65,6 +66,7 @@
6566
import com.owncloud.android.lib.resources.shares.OCShare;
6667
import com.owncloud.android.lib.resources.shares.ShareType;
6768
import com.owncloud.android.lib.resources.shares.ShareeUser;
69+
import com.owncloud.android.lib.resources.status.OCCapability;
6870
import com.owncloud.android.lib.resources.tags.Tag;
6971
import com.owncloud.android.operations.RefreshFolderOperation;
7072
import com.owncloud.android.operations.RemoteOperationFailedException;
@@ -79,6 +81,7 @@
7981
import com.owncloud.android.utils.FileSortOrder;
8082
import com.owncloud.android.utils.FileStorageUtils;
8183
import com.owncloud.android.utils.MimeTypeUtil;
84+
import com.owncloud.android.utils.theme.CapabilityUtils;
8285
import com.owncloud.android.utils.theme.ViewThemeUtils;
8386

8487
import java.io.File;
@@ -116,6 +119,7 @@ public class OCFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
116119
private final String userId;
117120
private final Activity activity;
118121
private final AppPreferences preferences;
122+
private final OCCapability capability;
119123
private List<OCFile> mFiles = new ArrayList<>();
120124
private final List<OCFile> mFilesAll = new ArrayList<>();
121125
private final boolean hideItemOptions;
@@ -126,7 +130,6 @@ public class OCFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
126130
private User user;
127131
private final OCFileListFragmentInterface ocFileListFragmentInterface;
128132

129-
130133
private OCFile currentDirectory;
131134
private static final String TAG = OCFileListAdapter.class.getSimpleName();
132135

@@ -168,6 +171,7 @@ public OCFileListAdapter(
168171
hideItemOptions = argHideItemOptions;
169172
this.gridView = gridView;
170173
mStorageManager = transferServiceGetter.getStorageManager();
174+
this.capability = CapabilityUtils.getCapability(user, activity);
171175

172176
if (activity instanceof FileDisplayActivity) {
173177
((FileDisplayActivity) activity).showSortListGroup(true);
@@ -434,23 +438,43 @@ public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int positi
434438
footerViewHolder.getLoadingProgressBar().setVisibility(
435439
ocFileListFragmentInterface.isLoading() ? View.VISIBLE : View.GONE);
436440
} else if (holder instanceof OCFileListHeaderViewHolder headerViewHolder) {
441+
ListHeaderBinding headerBinding = headerViewHolder.getBinding();
442+
headerViewHolder.getHeaderView().setOnClickListener(v -> ocFileListFragmentInterface.onHeaderClicked());
443+
437444
String text = currentDirectory.getRichWorkspace();
438445
PreviewTextFragment.setText(headerViewHolder.getHeaderText(), text, null, activity, true, true, viewThemeUtils);
439-
headerViewHolder.getHeaderView().setOnClickListener(v -> ocFileListFragmentInterface.onHeaderClicked());
440446

441-
ViewExtensionsKt.setVisibleIf(headerViewHolder.getBinding().recommendedFilesRecyclerView, shouldShowRecommendedFiles());
442-
ViewExtensionsKt.setVisibleIf(headerViewHolder.getBinding().recommendedFilesTitle, shouldShowRecommendedFiles());
443-
ViewExtensionsKt.setVisibleIf(headerViewHolder.getBinding().allFilesTitle, shouldShowRecommendedFiles());
447+
// hide header text if empty (server returns NBSP)
448+
ViewExtensionsKt.setVisibleIf(headerViewHolder.getHeaderText(), text != null && !text.isBlank() && !text.equals(" "));
449+
450+
ViewExtensionsKt.setVisibleIf(headerBinding.recommendedFilesRecyclerView, shouldShowRecommendedFiles());
451+
ViewExtensionsKt.setVisibleIf(headerBinding.recommendedFilesTitle, shouldShowRecommendedFiles());
452+
ViewExtensionsKt.setVisibleIf(headerBinding.allFilesTitle, shouldShowRecommendedFiles());
444453

445454
if (shouldShowRecommendedFiles()) {
446-
final var recommendedFilesRecyclerView = headerViewHolder.getBinding().recommendedFilesRecyclerView;
455+
final var recommendedFilesRecyclerView = headerBinding.recommendedFilesRecyclerView;
447456

448457
final LinearLayoutManager layoutManager = new LinearLayoutManager(activity, LinearLayoutManager.HORIZONTAL, false);
449458
recommendedFilesRecyclerView.setLayoutManager(layoutManager);
450459

451460
final var adapter = new RecommendedFilesAdapter(recommendedFiles, ocFileListDelegate, this, mStorageManager);
452461
recommendedFilesRecyclerView.setAdapter(adapter);
453462
}
463+
464+
ViewExtensionsKt.setVisibleIf(headerBinding.openIn.getRoot(), shouldShowOpenInNotes());
465+
466+
if (shouldShowOpenInNotes()) {
467+
final var listHeaderOpenInBinding = headerBinding.openIn;
468+
469+
listHeaderOpenInBinding.infoText.setText(String.format(activity.getString(R.string.folder_best_viewed_in),
470+
activity.getString(R.string.ecosystem_apps_notes)));
471+
472+
listHeaderOpenInBinding.openInButton.setText(String.format(activity.getString(R.string.open_in_app),
473+
activity.getString(R.string.ecosystem_apps_display_notes)));
474+
475+
listHeaderOpenInBinding.openInButton.setOnClickListener(v -> LinkHelper.INSTANCE.openAppOrStore(LinkHelper.APP_NEXTCLOUD_NOTES, user, activity));
476+
}
477+
454478
} else {
455479
ListViewHolder gridViewHolder = (ListViewHolder) holder;
456480
OCFile file = getItem(position);
@@ -486,6 +510,12 @@ private boolean shouldShowRecommendedFiles() {
486510
return !recommendedFiles.isEmpty() && currentDirectory.isRootDirectory();
487511
}
488512

513+
private boolean shouldShowOpenInNotes() {
514+
String notesFolderPath = capability.getNotesFolderPath();
515+
String currentPath = currentDirectory.getDecryptedRemotePath();
516+
return notesFolderPath != null && currentPath != null && currentPath.startsWith(notesFolderPath);
517+
}
518+
489519
private void checkVisibilityOfFileFeaturesLayout(ListViewHolder holder) {
490520
int fileFeaturesVisibility = View.GONE;
491521
LinearLayout fileFeaturesLayout = holder.getFileFeaturesLayout();
@@ -806,6 +836,10 @@ public boolean shouldShowHeader() {
806836
return true;
807837
}
808838

839+
if (shouldShowOpenInNotes()) {
840+
return true;
841+
}
842+
809843
if (currentDirectory.getRichWorkspace() == null) {
810844
return false;
811845
}

0 commit comments

Comments
 (0)