Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/src/main/java/com/owncloud/android/datamodel/OCFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public class OCFile implements Parcelable, Comparable<OCFile>, ServerFileInterfa
private String ownerId;
private String ownerDisplayName;
String note;
private List<ShareeUser> sharees;
private List<ShareeUser> sharees = new ArrayList<>();
private String richWorkspace;
private boolean locked;
@Nullable
Expand Down Expand Up @@ -988,7 +988,7 @@ public void setNote(String note) {
}

public void setSharees(List<ShareeUser> sharees) {
this.sharees = sharees;
this.sharees = (sharees == null) ? new ArrayList<>() : new ArrayList<>(sharees);
}

public void setRichWorkspace(String richWorkspace) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
* Nextcloud - Android Client
*
* SPDX-FileCopyrightText: 2026 Alper Ozturk <alper.ozturk@nextcloud.com>
* SPDX-FileCopyrightText: 2023 TSI-mc
* SPDX-FileCopyrightText: 2020 Chris Narkiewicz <hello@ezaquarii.com>
* SPDX-FileCopyrightText: 2018 Tobias Kaminsky <tobias@kaminsky.me>
Expand Down Expand Up @@ -75,7 +76,6 @@
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Locale;
Expand Down Expand Up @@ -594,29 +594,44 @@ private void handleListMode(ListGridItemViewHolder holder,
}

private void bindSharedAvatars(ListItemViewHolder holder, OCFile file) {
final var sharedAvatars = holder.getSharedAvatars();

if (!(file.isSharedWithMe() || file.isSharedWithSharee()) || isMultiSelect() || gridView || hideItemOptions) {
holder.getSharedAvatars().setVisibility(View.GONE);
holder.getSharedAvatars().removeAllViews();
sharedAvatars.setVisibility(View.GONE);
if (sharedAvatars.getChildCount() > 0) {
sharedAvatars.removeAllViews();
}
return;
}

final var sharees = new ArrayList<>(file.getSharees());
sharedAvatars.setVisibility(View.VISIBLE);
sharedAvatars.setAvatars(user, avatarSharees(file), viewThemeUtils);
sharedAvatars.setOnClickListener(view -> ocFileListFragmentInterface.onShareIconClick(file));
}

private List<ShareeUser> avatarSharees(OCFile file) {
final List<ShareeUser> sharees = file.getSharees();

ShareeUser owner = null;
final String ownerId = file.getOwnerId();
if (!TextUtils.isEmpty(ownerId) && !ownerId.equals(userId)) {
final var ownerSharee = new ShareeUser(ownerId, file.getOwnerDisplayName(), ShareType.USER);
if (!sharees.contains(ownerSharee)) {
sharees.add(ownerSharee);
owner = ownerSharee;
}
}

Collections.reverse(sharees);
final var ordered = new ArrayList<ShareeUser>(sharees.size() + (owner == null ? 0 : 1));
if (owner != null) {
ordered.add(owner);
}

final var sharedAvatars = holder.getSharedAvatars();
sharedAvatars.setVisibility(View.VISIBLE);
sharedAvatars.removeAllViews();
sharedAvatars.setAvatars(user, sharees, viewThemeUtils);
sharedAvatars.setOnClickListener(view -> ocFileListFragmentInterface.onShareIconClick(file));
// count from last to first to get desired order
for (int i = sharees.size() - 1; i >= 0; i--) {
ordered.add(sharees.get(i));
}

return ordered;
}

private void bindListItemViewHolder(ListItemViewHolder holder, OCFile file) {
Expand Down
24 changes: 24 additions & 0 deletions app/src/test/java/com/owncloud/android/datamodel/OCFileTest.kt
Original file line number Diff line number Diff line change
@@ -1,17 +1,41 @@
/*
* Nextcloud - Android Client
*
* SPDX-FileCopyrightText: 2026 Alper Ozturk <alper.ozturk@nextcloud.com>
* SPDX-FileCopyrightText: 2022 Tobias Kaminsky <tobias@kaminsky.me>
* SPDX-FileCopyrightText: 2022 Nextcloud GmbH
* SPDX-License-Identifier: AGPL-3.0-or-later OR GPL-2.0-only
*/
package com.owncloud.android.datamodel

import com.owncloud.android.lib.resources.shares.ShareType
import com.owncloud.android.lib.resources.shares.ShareeUser
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNotEquals
import org.junit.Assert.assertTrue
import org.junit.Test

class OCFileTest {
@Test
fun testShareesDefaultsToEmptyMutableList() {
val sut = OCFile("/")

assertTrue(sut.sharees.isEmpty())

sut.sharees.add(ShareeUser("alice", "Alice", ShareType.USER))
assertEquals(1, sut.sharees.size)
}

@Test
fun testShareesStayMutableWhenSetFromImmutableList() {
val sut = OCFile("/")

sut.sharees = listOf(ShareeUser("alice", "Alice", ShareType.USER))

sut.sharees.add(ShareeUser("bob", "Bob", ShareType.USER))
assertEquals(2, sut.sharees.size)
}

@Test
fun testLongIds() {
val sut = OCFile("/")
Expand Down
Loading