Hide Block and Leave options when not available in group settings, add unblock.
This commit is contained in:
parent
db06cbbc86
commit
8dbcb255ad
5 changed files with 47 additions and 2 deletions
|
@ -61,6 +61,10 @@ public final class LiveGroup {
|
||||||
return Transformations.map(groupRecord, g -> g.isAdmin(Recipient.self()));
|
return Transformations.map(groupRecord, g -> g.isAdmin(Recipient.self()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public LiveData<Boolean> isActive() {
|
||||||
|
return Transformations.map(groupRecord, GroupDatabase.GroupRecord::isActive);
|
||||||
|
}
|
||||||
|
|
||||||
public LiveData<Boolean> getRecipientIsAdmin(@NonNull RecipientId recipientId) {
|
public LiveData<Boolean> getRecipientIsAdmin(@NonNull RecipientId recipientId) {
|
||||||
return LiveDataUtil.mapAsync(groupRecord, g -> g.isAdmin(Recipient.resolved(recipientId)));
|
return LiveDataUtil.mapAsync(groupRecord, g -> g.isAdmin(Recipient.resolved(recipientId)));
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,6 @@ import androidx.appcompat.widget.Toolbar;
|
||||||
import androidx.core.view.ViewCompat;
|
import androidx.core.view.ViewCompat;
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
import androidx.fragment.app.FragmentActivity;
|
import androidx.fragment.app.FragmentActivity;
|
||||||
import androidx.lifecycle.LifecycleObserver;
|
|
||||||
import androidx.lifecycle.ViewModelProviders;
|
import androidx.lifecycle.ViewModelProviders;
|
||||||
|
|
||||||
import com.google.android.material.snackbar.Snackbar;
|
import com.google.android.material.snackbar.Snackbar;
|
||||||
|
@ -84,6 +83,7 @@ public class ManageGroupFragment extends Fragment {
|
||||||
private View disappearingMessagesRow;
|
private View disappearingMessagesRow;
|
||||||
private TextView disappearingMessages;
|
private TextView disappearingMessages;
|
||||||
private TextView blockGroup;
|
private TextView blockGroup;
|
||||||
|
private TextView unblockGroup;
|
||||||
private TextView leaveGroup;
|
private TextView leaveGroup;
|
||||||
private TextView addMembers;
|
private TextView addMembers;
|
||||||
private SwitchCompat muteNotificationsSwitch;
|
private SwitchCompat muteNotificationsSwitch;
|
||||||
|
@ -157,6 +157,7 @@ public class ManageGroupFragment extends Fragment {
|
||||||
disappearingMessagesRow = view.findViewById(R.id.disappearing_messages_row);
|
disappearingMessagesRow = view.findViewById(R.id.disappearing_messages_row);
|
||||||
disappearingMessages = view.findViewById(R.id.disappearing_messages);
|
disappearingMessages = view.findViewById(R.id.disappearing_messages);
|
||||||
blockGroup = view.findViewById(R.id.blockGroup);
|
blockGroup = view.findViewById(R.id.blockGroup);
|
||||||
|
unblockGroup = view.findViewById(R.id.unblockGroup);
|
||||||
leaveGroup = view.findViewById(R.id.leaveGroup);
|
leaveGroup = view.findViewById(R.id.leaveGroup);
|
||||||
addMembers = view.findViewById(R.id.add_members);
|
addMembers = view.findViewById(R.id.add_members);
|
||||||
muteNotificationsUntilLabel = view.findViewById(R.id.group_mute_notifications_until);
|
muteNotificationsUntilLabel = view.findViewById(R.id.group_mute_notifications_until);
|
||||||
|
@ -247,6 +248,7 @@ public class ManageGroupFragment extends Fragment {
|
||||||
|
|
||||||
disappearingMessagesRow.setOnClickListener(v -> viewModel.handleExpirationSelection());
|
disappearingMessagesRow.setOnClickListener(v -> viewModel.handleExpirationSelection());
|
||||||
blockGroup.setOnClickListener(v -> viewModel.blockAndLeave(requireActivity()));
|
blockGroup.setOnClickListener(v -> viewModel.blockAndLeave(requireActivity()));
|
||||||
|
unblockGroup.setOnClickListener(v -> viewModel.unblock(requireActivity()));
|
||||||
|
|
||||||
addMembers.setOnClickListener(v -> viewModel.onAddMembersClick(this, PICK_CONTACT));
|
addMembers.setOnClickListener(v -> viewModel.onAddMembersClick(this, PICK_CONTACT));
|
||||||
|
|
||||||
|
@ -328,6 +330,12 @@ public class ManageGroupFragment extends Fragment {
|
||||||
}
|
}
|
||||||
|
|
||||||
viewModel.getSnackbarEvents().observe(getViewLifecycleOwner(), this::handleSnackbarEvent);
|
viewModel.getSnackbarEvents().observe(getViewLifecycleOwner(), this::handleSnackbarEvent);
|
||||||
|
|
||||||
|
viewModel.getCanLeaveGroup().observe(getViewLifecycleOwner(), canLeave -> leaveGroup.setVisibility(canLeave ? View.VISIBLE : View.GONE));
|
||||||
|
viewModel.getCanBlockGroup().observe(getViewLifecycleOwner(), canBlock -> {
|
||||||
|
blockGroup.setVisibility(canBlock ? View.VISIBLE : View.GONE);
|
||||||
|
unblockGroup.setVisibility(canBlock ? View.GONE : View.VISIBLE);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean onMenuItemSelected(@NonNull MenuItem item) {
|
public boolean onMenuItemSelected(@NonNull MenuItem item) {
|
||||||
|
|
|
@ -67,6 +67,8 @@ public class ManageGroupViewModel extends ViewModel {
|
||||||
private final LiveData<Boolean> hasCustomNotifications;
|
private final LiveData<Boolean> hasCustomNotifications;
|
||||||
private final LiveData<Boolean> canCollapseMemberList;
|
private final LiveData<Boolean> canCollapseMemberList;
|
||||||
private final DefaultValueLiveData<CollapseState> memberListCollapseState = new DefaultValueLiveData<>(CollapseState.COLLAPSED);
|
private final DefaultValueLiveData<CollapseState> memberListCollapseState = new DefaultValueLiveData<>(CollapseState.COLLAPSED);
|
||||||
|
private final LiveData<Boolean> canLeaveGroup;
|
||||||
|
private final LiveData<Boolean> canBlockGroup;
|
||||||
|
|
||||||
private ManageGroupViewModel(@NonNull Context context, @NonNull ManageGroupRepository manageGroupRepository) {
|
private ManageGroupViewModel(@NonNull Context context, @NonNull ManageGroupRepository manageGroupRepository) {
|
||||||
this.context = context;
|
this.context = context;
|
||||||
|
@ -99,6 +101,8 @@ public class ManageGroupViewModel extends ViewModel {
|
||||||
recipient -> new MuteState(recipient.getMuteUntil(), recipient.isMuted()));
|
recipient -> new MuteState(recipient.getMuteUntil(), recipient.isMuted()));
|
||||||
this.hasCustomNotifications = Transformations.map(this.groupRecipient,
|
this.hasCustomNotifications = Transformations.map(this.groupRecipient,
|
||||||
recipient -> recipient.getNotificationChannel() != null);
|
recipient -> recipient.getNotificationChannel() != null);
|
||||||
|
this.canLeaveGroup = liveGroup.isActive();
|
||||||
|
this.canBlockGroup = Transformations.map(this.groupRecipient, recipient -> !recipient.isBlocked());
|
||||||
}
|
}
|
||||||
|
|
||||||
@WorkerThread
|
@WorkerThread
|
||||||
|
@ -172,10 +176,18 @@ public class ManageGroupViewModel extends ViewModel {
|
||||||
return snackbarEvents;
|
return snackbarEvents;
|
||||||
}
|
}
|
||||||
|
|
||||||
public LiveData<Boolean> getCanCollapseMemberList() {
|
LiveData<Boolean> getCanCollapseMemberList() {
|
||||||
return canCollapseMemberList;
|
return canCollapseMemberList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LiveData<Boolean> getCanBlockGroup() {
|
||||||
|
return canBlockGroup;
|
||||||
|
}
|
||||||
|
|
||||||
|
LiveData<Boolean> getCanLeaveGroup() {
|
||||||
|
return canLeaveGroup;
|
||||||
|
}
|
||||||
|
|
||||||
void handleExpirationSelection() {
|
void handleExpirationSelection() {
|
||||||
manageGroupRepository.getRecipient(groupRecipient ->
|
manageGroupRepository.getRecipient(groupRecipient ->
|
||||||
ExpirationDialog.show(context,
|
ExpirationDialog.show(context,
|
||||||
|
@ -196,6 +208,11 @@ public class ManageGroupViewModel extends ViewModel {
|
||||||
() -> RecipientUtil.block(context, recipient)));
|
() -> RecipientUtil.block(context, recipient)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void unblock(@NonNull FragmentActivity activity) {
|
||||||
|
manageGroupRepository.getRecipient(recipient -> BlockUnblockDialog.showUnblockFor(activity, activity.getLifecycle(), recipient,
|
||||||
|
() -> RecipientUtil.unblock(context, recipient)));
|
||||||
|
}
|
||||||
|
|
||||||
void onAddMembers(List<RecipientId> selected) {
|
void onAddMembers(List<RecipientId> selected) {
|
||||||
manageGroupRepository.addMembers(selected, this::showSuccessSnackbar, this::showErrorToast);
|
manageGroupRepository.addMembers(selected, this::showSuccessSnackbar, this::showErrorToast);
|
||||||
}
|
}
|
||||||
|
|
|
@ -557,6 +557,21 @@
|
||||||
android:textAppearance="@style/Signal.Text.Body"
|
android:textAppearance="@style/Signal.Text.Body"
|
||||||
android:textColor="@color/core_red" />
|
android:textColor="@color/core_red" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/unblockGroup"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="@dimen/group_manage_fragment_row_height"
|
||||||
|
android:background="?selectableItemBackground"
|
||||||
|
android:gravity="center_vertical|start"
|
||||||
|
android:paddingStart="@dimen/group_manage_fragment_row_horizontal_padding"
|
||||||
|
android:paddingEnd="@dimen/group_manage_fragment_row_horizontal_padding"
|
||||||
|
android:text="@string/ManageGroupActivity_unblock_group"
|
||||||
|
android:textAlignment="viewStart"
|
||||||
|
android:textAppearance="@style/Signal.Text.Body"
|
||||||
|
android:textColor="@color/core_red"
|
||||||
|
android:visibility="gone"
|
||||||
|
tools:visibility="visible" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/leaveGroup"
|
android:id="@+id/leaveGroup"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
|
|
@ -518,6 +518,7 @@
|
||||||
<string name="ManageGroupActivity_who_can_edit_group_membership">Who can edit group membership</string>
|
<string name="ManageGroupActivity_who_can_edit_group_membership">Who can edit group membership</string>
|
||||||
<string name="ManageGroupActivity_who_can_edit_group_info">Who can edit group info</string>
|
<string name="ManageGroupActivity_who_can_edit_group_info">Who can edit group info</string>
|
||||||
<string name="ManageGroupActivity_block_group">Block group</string>
|
<string name="ManageGroupActivity_block_group">Block group</string>
|
||||||
|
<string name="ManageGroupActivity_unblock_group">Unblock group</string>
|
||||||
<string name="ManageGroupActivity_leave_group">Leave group</string>
|
<string name="ManageGroupActivity_leave_group">Leave group</string>
|
||||||
<string name="ManageGroupActivity_mute_notifications">Mute notifications</string>
|
<string name="ManageGroupActivity_mute_notifications">Mute notifications</string>
|
||||||
<string name="ManageGroupActivity_custom_notifications">Custom notifications</string>
|
<string name="ManageGroupActivity_custom_notifications">Custom notifications</string>
|
||||||
|
|
Loading…
Add table
Reference in a new issue