Thanks to visit codestin.com
Credit goes to github.com

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
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,6 @@ interface ShareAPI {
@GET("shares/?format=json")
fun getShareFromNote(
@Query("path") path: String,
@Query("shared_with_me") sharedWithMe: Boolean = true
@Query("shared_with_me") sharedWithMe: Boolean = false
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The web calls

format=json
path=%2FNotes%2FSamples%2FFormatting.md
shared_with_me=true

So I am not sure if this is correct to be changed

): Call<OcsResponse<List<CreateShareResponse>>>
}
Original file line number Diff line number Diff line change
Expand Up @@ -355,11 +355,21 @@ private void setShareWithYou() {
return;
}

final var share = shares.get(0);
OCShare share = null;
for (OCShare s : shares) {
if (account.getAccountName().split("@")[0].equalsIgnoreCase(s.getShareWith())) {
share = s;
break;
}
}

if (share == null) {
return;
}

binding.sharedWithYouUsername.setText(
String.format(getString(R.string.note_share_activity_shared_with_you), share.getOwnerDisplayName()));
AvatarLoader.INSTANCE.load(this, binding.sharedWithYouAvatar, account);
AvatarLoader.INSTANCE.load(this, binding.sharedWithYouAvatar, account, share.getUserId());
binding.sharedWithYouAvatar.setVisibility(View.VISIBLE);

String description = share.getNote();
Expand All @@ -370,6 +380,8 @@ private void setShareWithYou() {
} else {
binding.sharedWithYouNoteContainer.setVisibility(View.GONE);
}

binding.sharedWithYouContainer.setVisibility(View.VISIBLE);
}
}

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

// Get shares from remote
final var remoteShares = repository.getShareFromNote(note);
if (remoteShares != null) {
for (var entity : remoteShares) {
addSharesToList(entity.getId(), targetList);
}
for (var entity : remoteShares) {
addSharesToList(entity.getId(), targetList);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,11 @@ protected final void sortShares() {
List<OCShare> users = new ArrayList<>();

for (OCShare share : shares) {
if (share.getShareWith().equalsIgnoreCase(account.getAccountName().split("@")[0])) {
// this is then an incoming share, shown via "shared with you"
continue;
}

if (share.getShareType() != null) {
if (ShareType.PUBLIC_LINK == share.getShareType() || ShareType.EMAIL == share.getShareType()) {
links.add(share);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

import androidx.annotation.DrawableRes;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

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

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

if (share.getSharedWithDisplayName() != null) {
AvatarLoader.INSTANCE.load(context, binding.icon, account, share.getSharedWithDisplayName());
AvatarLoader.INSTANCE.load(context, binding.icon, account, share.getShareWith());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Than the if-clause needs to be updated as well

}

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

binding.name.setText(name);

if (accountUserName.equalsIgnoreCase(share.getShareWith()) ||
accountUserName.equalsIgnoreCase(share.getUserId())) {
if (accountUserName.equalsIgnoreCase(share.getShareWith()) && accountUserName.equalsIgnoreCase(share.getUserId())) {
binding.overflowMenu.setVisibility(View.GONE);
} else {
binding.overflowMenu.setVisibility(View.VISIBLE);

String permissionName = SharingMenuHelper.getPermissionName(context, share);
Expand All @@ -99,8 +99,6 @@ public void bind(OCShare share, ShareeListAdapterListener listener) {
// bind listener to edit privileges
binding.overflowMenu.setOnClickListener(v -> listener.showSharingMenuActionSheet(share));
binding.shareNameLayout.setOnClickListener(v -> listener.showPermissionsDialog(share));
} else {
binding.overflowMenu.setVisibility(View.GONE);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import it.niedermann.owncloud.notes.shared.util.StringConstants
import it.niedermann.owncloud.notes.shared.util.extensions.getErrorMessage
import it.niedermann.owncloud.notes.shared.util.extensions.toExpirationDateString
import org.json.JSONObject
import retrofit2.Response
import java.util.Date

class ShareRepository(private val applicationContext: Context, private val account: SingleSignOnAccount) {
Expand All @@ -58,13 +59,7 @@ class ShareRepository(private val applicationContext: Context, private val accou
val notesPathResponseResult = getNotesPathResponseResult() ?: return null
val notesPath = notesPathResponseResult.notesPath
val notesSuffix = notesPathResponseResult.fileSuffix
return if (note.category.isEmpty()) {
StringConstants.PATH + notesPath + StringConstants.PATH + note.title + notesSuffix
} else {
StringConstants.PATH + notesPath + StringConstants.PATH + note.category + StringConstants.PATH +
note.title +
notesSuffix
}
return StringConstants.PATH + notesPath + StringConstants.PATH + note.category + StringConstants.PATH + note.title + notesSuffix
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will fail for notes not in a category I guess because it woudl add a StringConstants.PATH + StringConstants.PATH no?

}

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

fun getShareFromNote(note: Note): List<OCShare>? {
fun getShareFromNote(note: Note): List<OCShare> {
val shareAPI = apiProvider.getShareAPI(applicationContext, account)
val path = getNotePath(note) ?: return null
val call = shareAPI.getShareFromNote(path)
val response = call.execute()
val path = getNotePath(note) ?: return emptyList<OCShare>()

val callSharedWithMe = shareAPI.getShareFromNote(path, true)
var response = callSharedWithMe.execute()
val sharedWithMe = parseResponse(response)

val callSharedWithOthers = shareAPI.getShareFromNote(path, false)
response = callSharedWithOthers.execute()
val sharedWithOthers = parseResponse(response)

sharedWithOthers.addAll(sharedWithMe)

return sharedWithOthers
}

private fun parseResponse(response: Response<OcsResponse<List<CreateShareResponse>>>): MutableList<OCShare> {
return try {
if (response.isSuccessful) {
val body = response.body()
Log_OC.d(tag, "Response successful: $body")
body?.ocs?.data?.toOCShareList()
body?.ocs?.data?.toOCShareList()?.toMutableList() ?: mutableListOf()
} else {
val errorBody = response.errorBody()?.string()
Log_OC.d(tag, "Response failed: $errorBody")
null
mutableListOf()
}
} catch (e: Exception) {
Log_OC.d(tag, "Exception while getting share from note: ", e)
null
mutableListOf()
}
}

Expand Down
Loading