Skip to content

Commit 2a5a5d5

Browse files
Sharing fixes
Signed-off-by: tobiasKaminsky <[email protected]>
1 parent b900223 commit 2a5a5d5

File tree

5 files changed

+47
-27
lines changed

5 files changed

+47
-27
lines changed

app/src/main/java/it/niedermann/owncloud/notes/persistence/sync/ShareAPI.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,6 @@ interface ShareAPI {
6767
@GET("shares/?format=json")
6868
fun getShareFromNote(
6969
@Query("path") path: String,
70-
@Query("shared_with_me") sharedWithMe: Boolean = true
70+
@Query("shared_with_me") sharedWithMe: Boolean = false
7171
): Call<OcsResponse<List<CreateShareResponse>>>
7272
}

app/src/main/java/it/niedermann/owncloud/notes/share/NoteShareActivity.java

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -355,11 +355,21 @@ private void setShareWithYou() {
355355
return;
356356
}
357357

358-
final var share = shares.get(0);
358+
OCShare share = null;
359+
for (OCShare s : shares) {
360+
if (account.getAccountName().split("@")[0].equalsIgnoreCase(s.getShareWith())) {
361+
share = s;
362+
break;
363+
}
364+
}
359365

366+
if (share == null) {
367+
return;
368+
}
369+
360370
binding.sharedWithYouUsername.setText(
361371
String.format(getString(R.string.note_share_activity_shared_with_you), share.getOwnerDisplayName()));
362-
AvatarLoader.INSTANCE.load(this, binding.sharedWithYouAvatar, account);
372+
AvatarLoader.INSTANCE.load(this, binding.sharedWithYouAvatar, account, share.getUserId());
363373
binding.sharedWithYouAvatar.setVisibility(View.VISIBLE);
364374

365375
String description = share.getNote();
@@ -370,6 +380,8 @@ private void setShareWithYou() {
370380
} else {
371381
binding.sharedWithYouNoteContainer.setVisibility(View.GONE);
372382
}
383+
384+
binding.sharedWithYouContainer.setVisibility(View.VISIBLE);
373385
}
374386
}
375387

@@ -538,10 +550,8 @@ private void populateSharesList(List<OCShare> targetList) {
538550

539551
// Get shares from remote
540552
final var remoteShares = repository.getShareFromNote(note);
541-
if (remoteShares != null) {
542-
for (var entity : remoteShares) {
543-
addSharesToList(entity.getId(), targetList);
544-
}
553+
for (var entity : remoteShares) {
554+
addSharesToList(entity.getId(), targetList);
545555
}
546556
}
547557

app/src/main/java/it/niedermann/owncloud/notes/share/adapter/ShareeListAdapter.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,11 @@ protected final void sortShares() {
215215
List<OCShare> users = new ArrayList<>();
216216

217217
for (OCShare share : shares) {
218+
if (share.getShareWith().equalsIgnoreCase(account.getAccountName().split("@")[0])) {
219+
// this is then an incoming share, shown via "shared with you"
220+
continue;
221+
}
222+
218223
if (share.getShareType() != null) {
219224
if (ShareType.PUBLIC_LINK == share.getShareType() || ShareType.EMAIL == share.getShareType()) {
220225
links.add(share);

app/src/main/java/it/niedermann/owncloud/notes/share/adapter/holder/ShareViewHolder.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
import androidx.annotation.DrawableRes;
1515
import androidx.annotation.NonNull;
16-
import androidx.recyclerview.widget.RecyclerView;
1716

1817
import com.owncloud.android.lib.resources.shares.OCShare;
1918

@@ -78,7 +77,7 @@ public void bind(OCShare share, ShareeListAdapterListener listener) {
7877
binding.icon.setTag(share.getShareWith());
7978

8079
if (share.getSharedWithDisplayName() != null) {
81-
AvatarLoader.INSTANCE.load(context, binding.icon, account, share.getSharedWithDisplayName());
80+
AvatarLoader.INSTANCE.load(context, binding.icon, account, share.getShareWith());
8281
}
8382

8483
// binding.icon.setOnClickListener(v -> listener.showProfileBottomSheet(user, share.getShareWith()));
@@ -89,8 +88,9 @@ public void bind(OCShare share, ShareeListAdapterListener listener) {
8988

9089
binding.name.setText(name);
9190

92-
if (accountUserName.equalsIgnoreCase(share.getShareWith()) ||
93-
accountUserName.equalsIgnoreCase(share.getUserId())) {
91+
if (accountUserName.equalsIgnoreCase(share.getShareWith()) && accountUserName.equalsIgnoreCase(share.getUserId())) {
92+
binding.overflowMenu.setVisibility(View.GONE);
93+
} else {
9494
binding.overflowMenu.setVisibility(View.VISIBLE);
9595

9696
String permissionName = SharingMenuHelper.getPermissionName(context, share);
@@ -99,8 +99,6 @@ public void bind(OCShare share, ShareeListAdapterListener listener) {
9999
// bind listener to edit privileges
100100
binding.overflowMenu.setOnClickListener(v -> listener.showSharingMenuActionSheet(share));
101101
binding.shareNameLayout.setOnClickListener(v -> listener.showPermissionsDialog(share));
102-
} else {
103-
binding.overflowMenu.setVisibility(View.GONE);
104102
}
105103
}
106104

app/src/main/java/it/niedermann/owncloud/notes/share/repository/ShareRepository.kt

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import it.niedermann.owncloud.notes.shared.util.StringConstants
3535
import it.niedermann.owncloud.notes.shared.util.extensions.getErrorMessage
3636
import it.niedermann.owncloud.notes.shared.util.extensions.toExpirationDateString
3737
import org.json.JSONObject
38+
import retrofit2.Response
3839
import java.util.Date
3940

4041
class ShareRepository(private val applicationContext: Context, private val account: SingleSignOnAccount) {
@@ -58,13 +59,7 @@ class ShareRepository(private val applicationContext: Context, private val accou
5859
val notesPathResponseResult = getNotesPathResponseResult() ?: return null
5960
val notesPath = notesPathResponseResult.notesPath
6061
val notesSuffix = notesPathResponseResult.fileSuffix
61-
return if (note.category.isEmpty()) {
62-
StringConstants.PATH + notesPath + StringConstants.PATH + note.title + notesSuffix
63-
} else {
64-
StringConstants.PATH + notesPath + StringConstants.PATH + note.category + StringConstants.PATH +
65-
note.title +
66-
notesSuffix
67-
}
62+
return StringConstants.PATH + notesPath + StringConstants.PATH + note.category + StringConstants.PATH + note.title + notesSuffix
6863
}
6964

7065
fun getShareEntitiesForSpecificNote(note: Note): List<ShareEntity> {
@@ -286,25 +281,37 @@ class ShareRepository(private val applicationContext: Context, private val accou
286281
}
287282
}
288283

289-
fun getShareFromNote(note: Note): List<OCShare>? {
284+
fun getShareFromNote(note: Note): List<OCShare> {
290285
val shareAPI = apiProvider.getShareAPI(applicationContext, account)
291-
val path = getNotePath(note) ?: return null
292-
val call = shareAPI.getShareFromNote(path)
293-
val response = call.execute()
286+
val path = getNotePath(note) ?: return emptyList<OCShare>()
287+
288+
val callSharedWithMe = shareAPI.getShareFromNote(path, true)
289+
var response = callSharedWithMe.execute()
290+
val sharedWithMe = parseResponse(response)
291+
292+
val callSharedWithOthers = shareAPI.getShareFromNote(path, false)
293+
response = callSharedWithOthers.execute()
294+
val sharedWithOthers = parseResponse(response)
294295

296+
sharedWithOthers.addAll(sharedWithMe)
297+
298+
return sharedWithOthers
299+
}
300+
301+
private fun parseResponse(response: Response<OcsResponse<List<CreateShareResponse>>>): MutableList<OCShare> {
295302
return try {
296303
if (response.isSuccessful) {
297304
val body = response.body()
298305
Log_OC.d(tag, "Response successful: $body")
299-
body?.ocs?.data?.toOCShareList()
306+
body?.ocs?.data?.toOCShareList()?.toMutableList() ?: mutableListOf()
300307
} else {
301308
val errorBody = response.errorBody()?.string()
302309
Log_OC.d(tag, "Response failed: $errorBody")
303-
null
310+
mutableListOf()
304311
}
305312
} catch (e: Exception) {
306313
Log_OC.d(tag, "Exception while getting share from note: ", e)
307-
null
314+
mutableListOf()
308315
}
309316
}
310317

0 commit comments

Comments
 (0)