diff --git a/app/src/main/java/org/thoughtcrime/securesms/recipients/ui/bottomsheet/RecipientBottomSheetDialogFragment.java b/app/src/main/java/org/thoughtcrime/securesms/recipients/ui/bottomsheet/RecipientBottomSheetDialogFragment.java index 4fd5c73e5..3b2c11eed 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/recipients/ui/bottomsheet/RecipientBottomSheetDialogFragment.java +++ b/app/src/main/java/org/thoughtcrime/securesms/recipients/ui/bottomsheet/RecipientBottomSheetDialogFragment.java @@ -137,12 +137,12 @@ public final class RecipientBottomSheetDialogFragment extends BottomSheetDialogF }); boolean blocked = recipient.isBlocked(); - blockButton.setVisibility(blocked ? View.GONE : View.VISIBLE); - unblockButton.setVisibility(blocked ? View.VISIBLE : View.GONE); + blockButton .setVisibility(recipient.isLocalNumber() || blocked ? View.GONE : View.VISIBLE); + unblockButton.setVisibility(recipient.isLocalNumber() || !blocked ? View.GONE : View.VISIBLE); - secureCallButton.setVisibility(recipient.isRegistered() ? View.VISIBLE : View.GONE); + secureCallButton.setVisibility(recipient.isRegistered() && !recipient.isLocalNumber() ? View.VISIBLE : View.GONE); - if (recipient.isSystemContact() || recipient.isGroup()) { + if (recipient.isSystemContact() || recipient.isGroup() || recipient.isLocalNumber()) { addContactButton.setVisibility(View.GONE); } else { addContactButton.setVisibility(View.VISIBLE); @@ -152,7 +152,7 @@ public final class RecipientBottomSheetDialogFragment extends BottomSheetDialogF } addToGroupButton.setText(groupId == null ? R.string.RecipientBottomSheet_add_to_a_group : R.string.RecipientBottomSheet_add_to_another_group); - addToGroupButton.setVisibility(recipient.isRegistered() && !recipient.isGroup() ? View.VISIBLE : View.GONE); + addToGroupButton.setVisibility(recipient.isRegistered() && !recipient.isGroup() && !recipient.isLocalNumber() ? View.VISIBLE : View.GONE); }); viewModel.getAdminActionStatus().observe(getViewLifecycleOwner(), adminStatus -> { diff --git a/app/src/main/java/org/thoughtcrime/securesms/recipients/ui/bottomsheet/RecipientDialogRepository.java b/app/src/main/java/org/thoughtcrime/securesms/recipients/ui/bottomsheet/RecipientDialogRepository.java index 7f7157f1a..96377e0aa 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/recipients/ui/bottomsheet/RecipientDialogRepository.java +++ b/app/src/main/java/org/thoughtcrime/securesms/recipients/ui/bottomsheet/RecipientDialogRepository.java @@ -54,12 +54,11 @@ final class RecipientDialogRepository { return groupId; } - void getIdentity(@NonNull IdentityCallback callback) { - SimpleTask.run(SignalExecutors.BOUNDED, - () -> DatabaseFactory.getIdentityDatabase(context) - .getIdentity(recipientId) - .orNull(), - callback::remoteIdentity); + void getIdentity(@NonNull Consumer callback) { + SignalExecutors.BOUNDED.execute( + () -> callback.accept(DatabaseFactory.getIdentityDatabase(context) + .getIdentity(recipientId) + .orNull())); } void getRecipient(@NonNull RecipientCallback recipientCallback) { @@ -136,10 +135,6 @@ final class RecipientDialogRepository { onComplete::accept); } - interface IdentityCallback { - void remoteIdentity(@Nullable IdentityDatabase.IdentityRecord identityRecord); - } - interface RecipientCallback { void onRecipient(@NonNull Recipient recipient); } diff --git a/app/src/main/java/org/thoughtcrime/securesms/recipients/ui/bottomsheet/RecipientDialogViewModel.java b/app/src/main/java/org/thoughtcrime/securesms/recipients/ui/bottomsheet/RecipientDialogViewModel.java index fad496795..0b33647a9 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/recipients/ui/bottomsheet/RecipientDialogViewModel.java +++ b/app/src/main/java/org/thoughtcrime/securesms/recipients/ui/bottomsheet/RecipientDialogViewModel.java @@ -69,7 +69,10 @@ final class RecipientDialogViewModel extends ViewModel { recipient = Recipient.live(recipientDialogRepository.getRecipientId()).getLiveData(); - recipientDialogRepository.getIdentity(identity::setValue); + boolean isSelf = recipientDialogRepository.getRecipientId().equals(Recipient.self().getId()); + if (!isSelf) { + recipientDialogRepository.getIdentity(identity::postValue); + } } LiveData getRecipient() { diff --git a/app/src/main/java/org/thoughtcrime/securesms/recipients/ui/managerecipient/ManageRecipientFragment.java b/app/src/main/java/org/thoughtcrime/securesms/recipients/ui/managerecipient/ManageRecipientFragment.java index 371237389..67fcc615b 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/recipients/ui/managerecipient/ManageRecipientFragment.java +++ b/app/src/main/java/org/thoughtcrime/securesms/recipients/ui/managerecipient/ManageRecipientFragment.java @@ -74,12 +74,15 @@ public class ManageRecipientFragment extends Fragment { private TextView disappearingMessages; private View colorRow; private ImageView colorChip; + private View blockUnblockCard; private TextView block; private TextView unblock; + private View groupMembershipCard; private TextView addToAGroup; private SwitchCompat muteNotificationsSwitch; private View muteNotificationsRow; private TextView muteNotificationsUntilLabel; + private View notificationsCard; private TextView customNotificationsButton; private View customNotificationsRow; private View toggleAllGroups; @@ -120,13 +123,16 @@ public class ManageRecipientFragment extends Fragment { disappearingMessages = view.findViewById(R.id.disappearing_messages); colorRow = view.findViewById(R.id.color_row); colorChip = view.findViewById(R.id.color_chip); + blockUnblockCard = view.findViewById(R.id.recipient_block_and_leave_card); block = view.findViewById(R.id.block); unblock = view.findViewById(R.id.unblock); viewSafetyNumber = view.findViewById(R.id.view_safety_number); + groupMembershipCard = view.findViewById(R.id.recipient_membership_card); addToAGroup = view.findViewById(R.id.add_to_a_group); muteNotificationsUntilLabel = view.findViewById(R.id.recipient_mute_notifications_until); muteNotificationsSwitch = view.findViewById(R.id.recipient_mute_notifications_switch); muteNotificationsRow = view.findViewById(R.id.recipient_mute_notifications_row); + notificationsCard = view.findViewById(R.id.recipient_notifications_card); customNotificationsButton = view.findViewById(R.id.recipient_custom_notifications_button); customNotificationsRow = view.findViewById(R.id.recipient_custom_notifications_row); toggleAllGroups = view.findViewById(R.id.toggle_all_groups); @@ -146,9 +152,6 @@ public class ManageRecipientFragment extends Fragment { viewModel = ViewModelProviders.of(requireActivity(), factory).get(ManageRecipientViewModel.class); - viewModel.getVisibleSharedGroups().observe(getViewLifecycleOwner(), members -> sharedGroupList.setMembers(members)); - viewModel.getSharedGroupsCountSummary().observe(getViewLifecycleOwner(), members -> groupsInCommonCount.setText(members)); - viewModel.getCanCollapseMemberList().observe(getViewLifecycleOwner(), canCollapseMemberList -> { if (canCollapseMemberList) { toggleAllGroups.setVisibility(View.VISIBLE); @@ -172,6 +175,15 @@ public class ManageRecipientFragment extends Fragment { if (recipientId.equals(Recipient.self().getId())) { toolbar.getMenu().findItem(R.id.action_edit).setVisible(true); + notificationsCard.setVisibility(View.GONE); + groupMembershipCard.setVisibility(View.GONE); + blockUnblockCard.setVisibility(View.GONE); + } else { + viewModel.getVisibleSharedGroups().observe(getViewLifecycleOwner(), members -> sharedGroupList.setMembers(members)); + viewModel.getSharedGroupsCountSummary().observe(getViewLifecycleOwner(), members -> groupsInCommonCount.setText(members)); + addToAGroup.setOnClickListener(v -> viewModel.onAddToGroupButton(requireActivity())); + sharedGroupList.setRecipientClickListener(recipient -> viewModel.onGroupClicked(requireActivity(), recipient)); + sharedGroupList.setOverScrollMode(View.OVER_SCROLL_NEVER); } viewModel.getName().observe(getViewLifecycleOwner(), name::setText); @@ -184,11 +196,6 @@ public class ManageRecipientFragment extends Fragment { block.setOnClickListener(v -> viewModel.onBlockClicked(requireActivity())); unblock.setOnClickListener(v -> viewModel.onUnblockClicked(requireActivity())); - addToAGroup.setOnClickListener(v -> viewModel.onAddToGroupButton(requireActivity())); - - sharedGroupList.setRecipientClickListener(recipient -> viewModel.onGroupClicked(requireActivity(), recipient)); - sharedGroupList.setOverScrollMode(View.OVER_SCROLL_NEVER); - muteNotificationsRow.setOnClickListener(v -> { if (muteNotificationsSwitch.isEnabled()) { muteNotificationsSwitch.toggle(); @@ -259,8 +266,8 @@ public class ManageRecipientFragment extends Fragment { return true; }); - secureCallButton.setVisibility(recipient.isRegistered() ? View.VISIBLE : View.GONE); - secureVideoCallButton.setVisibility(recipient.isRegistered() ? View.VISIBLE : View.GONE); + secureCallButton.setVisibility(recipient.isRegistered() && !recipient.isLocalNumber() ? View.VISIBLE : View.GONE); + secureVideoCallButton.setVisibility(recipient.isRegistered() && !recipient.isLocalNumber() ? View.VISIBLE : View.GONE); } private void presentMediaCursor(ManageRecipientViewModel.MediaCursor mediaCursor) { diff --git a/app/src/main/res/layout/recipient_bottom_sheet.xml b/app/src/main/res/layout/recipient_bottom_sheet.xml index 4aff55258..f9f1e6773 100644 --- a/app/src/main/res/layout/recipient_bottom_sheet.xml +++ b/app/src/main/res/layout/recipient_bottom_sheet.xml @@ -139,7 +139,9 @@ android:paddingStart="20dp" android:paddingEnd="20dp" android:text="@string/RecipientBottomSheet_view_safety_number" - app:drawableStartCompat="?attr/recipient_view_safety_icon" /> + android:visibility="gone" + app:drawableStartCompat="?attr/recipient_view_safety_icon" + tools:visibility="visible" />