Skip to content

Commit

Permalink
Fixes signalapp#13870 - Showing SwipeProgressBar on Remove/Block contact
Browse files Browse the repository at this point in the history
  • Loading branch information
Sagar0-0 committed Jan 9, 2025
1 parent a39c6f4 commit fa0f32f
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,10 @@ public void setRefreshing(boolean refreshing) {
swipeRefresh.setRefreshing(refreshing);
}

public boolean isRefreshing() {
return swipeRefresh.isRefreshing();
}

public void reset() {
contactSearchMediator.clearSelection();
fastScroller.setVisibility(View.GONE);
Expand Down Expand Up @@ -674,6 +678,13 @@ public void addRecipientToSelectionIfAble(@NonNull RecipientId recipientId) {
listClickListener.onItemClick(new ContactSearchKey.RecipientSearchKey(recipientId, false));
}

public boolean isRecipientPresent(RecipientId recipientId) {
if(contactSearchMediator == null) {
return false;
}
return contactSearchMediator.isRecipientPresent(recipientId);
}

private class ListClickListener {
public void onItemClick(ContactSearchKey contact) {
boolean isUnknown = contact instanceof ContactSearchKey.UnknownRecipientKey;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -355,10 +355,13 @@ public boolean onLongClick(View anchorView, ContactSearchKey contactSearchKey, R
this.getLifecycle(),
recipient,
() -> {
disposables.add(viewModel.blockContact(recipient).subscribe(() -> {
displaySnackbar(R.string.NewConversationActivity__s_has_been_blocked, recipient.getDisplayName(this));
contactsFragment.reset();
}));
if (isRecipientCanBeRemoved(recipient.getId())) {
disposables.add(viewModel.blockContact(recipient).subscribe(() -> {
handleManualRefresh();
displaySnackbar(R.string.NewConversationActivity__s_has_been_blocked, recipient.getDisplayName(this));
contactsFragment.reset();
}));
}
})
);
}
Expand All @@ -380,16 +383,23 @@ private void displayRemovalDialog(@NonNull Recipient recipient) {
.setMessage(R.string.NewConversationActivity__you_wont_see_this_person)
.setPositiveButton(R.string.NewConversationActivity__remove,
(dialog, which) -> {
disposables.add(viewModel.hideContact(recipient).subscribe(() -> {
onRefresh();
displaySnackbar(R.string.NewConversationActivity__s_has_been_removed, recipient.getDisplayName(this));
}));
if (isRecipientCanBeRemoved(recipient.getId())) {
disposables.add(viewModel.hideContact(recipient).subscribe(() -> {
handleManualRefresh();
displaySnackbar(R.string.NewConversationActivity__s_has_been_removed, recipient.getDisplayName(this));
contactsFragment.reset();
}));
}
}
)
.setNegativeButton(android.R.string.cancel, null)
.show();
}

private Boolean isRecipientCanBeRemoved(@NonNull RecipientId recipientId) {
return contactsFragment.isRecipientPresent(recipientId) && !contactsFragment.isRefreshing();
}

private void displaySnackbar(@StringRes int message, Object... formatArgs) {
Snackbar.make(findViewById(android.R.id.content), getString(message, formatArgs), Snackbar.LENGTH_SHORT).show();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import org.thoughtcrime.securesms.R
import org.thoughtcrime.securesms.conversationlist.chatfilter.ConversationFilterRequest
import org.thoughtcrime.securesms.groups.SelectionLimits
import org.thoughtcrime.securesms.keyvalue.SignalStore
import org.thoughtcrime.securesms.recipients.RecipientId
import org.thoughtcrime.securesms.search.SearchRepository
import org.thoughtcrime.securesms.stories.settings.custom.PrivateStorySettingsFragment
import org.thoughtcrime.securesms.stories.settings.my.MyStorySettingsFragment
Expand Down Expand Up @@ -203,6 +204,10 @@ class ContactSearchMediator(
}
}

fun isRecipientPresent(recipientId: RecipientId): Boolean {
return viewModel.data.value?.any { it.contactSearchKey == ContactSearchKey.RecipientSearchKey(recipientId,false) } ?: false
}

private inner class StoryContextMenuCallbacks : ContactSearchAdapter.StoryContextMenuCallbacks {
override fun onOpenStorySettings(story: ContactSearchData.Story) {
if (story.recipient.isMyStory) {
Expand Down

0 comments on commit fa0f32f

Please sign in to comment.