Skip to content

Commit 40d4251

Browse files
committed
add updateShare
Signed-off-by: alperozturk <[email protected]>
1 parent 8677a77 commit 40d4251

File tree

2 files changed

+52
-4
lines changed

2 files changed

+52
-4
lines changed

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

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ private void initializeArguments() {
131131
setupSearchView((SearchManager) getSystemService(Context.SEARCH_SERVICE), getComponentName());
132132
}
133133

134-
refreshSharesFromDB();
134+
updateShareeListAdapter();
135135
binding.loadingLayout.setVisibility(View.GONE);
136136
});
137137
} catch (Exception e) {
@@ -422,7 +422,7 @@ public void requestPasswordForShare(OCShare share, boolean askForPassword) {
422422
public void showProfileBottomSheet(Account account, String shareWith) {
423423
}
424424

425-
public void refreshSharesFromDB() {
425+
public void updateShareeListAdapter() {
426426
executorService.submit(() -> {
427427
try {
428428
ShareeListAdapter adapter = (ShareeListAdapter) binding.sharesList.getAdapter();
@@ -459,7 +459,7 @@ public void refreshSharesFromDB() {
459459
setShareWithYou();
460460
});
461461
} catch (Exception e) {
462-
Log_OC.d(TAG, "Exception while refreshSharesFromDB: " + e);
462+
Log_OC.d(TAG, "Exception while updateShareeListAdapter: " + e);
463463
}
464464
});
465465
}
@@ -652,14 +652,42 @@ public void onQuickPermissionChanged(OCShare share, int permission) {
652652
final var result = repository.updateSharePermission(share.getId(), permission);
653653
runOnUiThread(() -> {
654654
if (ApiResultKt.isSuccess(result)) {
655-
NoteShareActivity.this.recreate();
655+
updateShare(share);
656656
} else if (result instanceof ApiResult.Error error) {
657657
DisplayUtils.showSnackMessage(NoteShareActivity.this, error.getMessage());
658658
}
659659
});
660660
});
661661
}
662662

663+
private void updateShare(OCShare share) {
664+
executorService.submit(() -> {
665+
try {
666+
final var updatedShares = repository.getShares(share.getId());
667+
668+
runOnUiThread(() -> {
669+
if (updatedShares != null && binding.sharesList.getAdapter() instanceof ShareeListAdapter adapter) {
670+
OCShare updatedShare = null;
671+
for (int i=0;i<updatedShares.size();i++) {
672+
if (updatedShares.get(i).getId() == share.getId()) {
673+
updatedShare = updatedShares.get(i);
674+
break;
675+
}
676+
}
677+
678+
if (updatedShare == null) {
679+
return;
680+
}
681+
682+
adapter.updateShare(updatedShare);
683+
}
684+
});
685+
} catch (Exception e) {
686+
Log_OC.d(TAG, "Exception while refreshing share info: " + e);
687+
}
688+
});
689+
}
690+
663691
private final ActivityResultLauncher<String> requestContactPermissionLauncher =
664692
registerForActivityResult(new ActivityResultContracts.RequestPermission(), isGranted -> {
665693
if (isGranted) {

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,26 @@ public void removeAll() {
167167
notifyDataSetChanged();
168168
}
169169

170+
public void updateShare(OCShare updatedShare) {
171+
if (updatedShare == null) {
172+
return;
173+
}
174+
175+
int indexToUpdate = -1;
176+
for (int i = 0; i < getItemCount(); i++) {
177+
final var share = shares.get(i);
178+
if (share != null && share.getId() == updatedShare.getId()) {
179+
indexToUpdate = i;
180+
break;
181+
}
182+
}
183+
184+
if (indexToUpdate != -1) {
185+
shares.set(indexToUpdate, updatedShare);
186+
notifyItemChanged(indexToUpdate);
187+
}
188+
}
189+
170190
/**
171191
* sort all by creation time, then email/link shares on top
172192
*/

0 commit comments

Comments
 (0)