More descriptive copy for group link permission errors.
parent
adf1674877
commit
26404ff5d7
|
@ -10,6 +10,7 @@ import android.widget.Toast;
|
|||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.StringRes;
|
||||
import androidx.appcompat.widget.SwitchCompat;
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
import androidx.fragment.app.DialogFragment;
|
||||
|
@ -101,16 +102,19 @@ public final class ShareableGroupLinkDialogFragment extends DialogFragment {
|
|||
|
||||
shareRow.setOnClickListener(v -> GroupLinkBottomSheetDialogFragment.show(requireFragmentManager(), groupId));
|
||||
|
||||
shareableGroupLinkRow.setOnClickListener(v -> viewModel.onToggleGroupLink(requireContext()));
|
||||
approveNewMembersRow.setOnClickListener(v -> viewModel.onToggleApproveMembers(requireContext()));
|
||||
resetLinkRow.setOnClickListener(v ->
|
||||
new AlertDialog.Builder(requireContext())
|
||||
.setMessage(R.string.ShareableGroupLinkDialogFragment__are_you_sure_you_want_to_reset_the_group_link)
|
||||
.setPositiveButton(R.string.ShareableGroupLinkDialogFragment__reset_link, (dialog, which) -> viewModel.onResetLink(requireContext()))
|
||||
.setNegativeButton(android.R.string.cancel, null)
|
||||
.show());
|
||||
viewModel.getCanEdit().observe(getViewLifecycleOwner(), canEdit -> {
|
||||
if (canEdit) {
|
||||
shareableGroupLinkRow.setOnClickListener(v -> viewModel.onToggleGroupLink());
|
||||
approveNewMembersRow.setOnClickListener(v -> viewModel.onToggleApproveMembers());
|
||||
resetLinkRow.setOnClickListener(v -> onResetGroupLink());
|
||||
} else {
|
||||
shareableGroupLinkRow.setOnClickListener(v -> toast(R.string.ManageGroupActivity_only_admins_can_enable_or_disable_the_sharable_group_link));
|
||||
approveNewMembersRow.setOnClickListener(v -> toast(R.string.ManageGroupActivity_only_admins_can_enable_or_disable_the_option_to_approve_new_members));
|
||||
resetLinkRow.setOnClickListener(v -> toast(R.string.ManageGroupActivity_only_admins_can_reset_the_sharable_group_link));
|
||||
}
|
||||
});
|
||||
|
||||
viewModel.getToasts().observe(getViewLifecycleOwner(), t -> Toast.makeText(requireContext(), t, Toast.LENGTH_SHORT).show());
|
||||
viewModel.getToasts().observe(getViewLifecycleOwner(), this::toast);
|
||||
|
||||
viewModel.getBusy().observe(getViewLifecycleOwner(), busy -> {
|
||||
if (busy) {
|
||||
|
@ -126,6 +130,18 @@ public final class ShareableGroupLinkDialogFragment extends DialogFragment {
|
|||
});
|
||||
}
|
||||
|
||||
private void onResetGroupLink() {
|
||||
new AlertDialog.Builder(requireContext())
|
||||
.setMessage(R.string.ShareableGroupLinkDialogFragment__are_you_sure_you_want_to_reset_the_group_link)
|
||||
.setPositiveButton(R.string.ShareableGroupLinkDialogFragment__reset_link, (dialog, which) -> viewModel.onResetLink())
|
||||
.setNegativeButton(android.R.string.cancel, null)
|
||||
.show();
|
||||
}
|
||||
|
||||
protected void toast(@StringRes int message) {
|
||||
Toast.makeText(requireContext(), getString(message), Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
/**
|
||||
* Inserts zero width space characters between each character in the original ensuring it takes
|
||||
* the full width of the TextView.
|
||||
|
|
|
@ -1,14 +1,11 @@
|
|||
package org.thoughtcrime.securesms.recipients.ui.sharablegrouplink;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.ViewModel;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
|
||||
import org.thoughtcrime.securesms.R;
|
||||
import org.thoughtcrime.securesms.groups.GroupId;
|
||||
import org.thoughtcrime.securesms.groups.LiveGroup;
|
||||
import org.thoughtcrime.securesms.groups.ui.GroupChangeFailureReason;
|
||||
|
@ -21,12 +18,16 @@ final class ShareableGroupLinkViewModel extends ViewModel {
|
|||
|
||||
private final ShareableGroupLinkRepository repository;
|
||||
private final LiveData<GroupLinkUrlAndStatus> groupLink;
|
||||
private final SingleLiveEvent<String> toasts;
|
||||
private final SingleLiveEvent<Integer> toasts;
|
||||
private final SingleLiveEvent<Boolean> busy;
|
||||
private final LiveData<Boolean> canEdit;
|
||||
|
||||
private ShareableGroupLinkViewModel(@NonNull GroupId.V2 groupId, @NonNull ShareableGroupLinkRepository repository) {
|
||||
LiveGroup liveGroup = new LiveGroup(groupId);
|
||||
|
||||
this.repository = repository;
|
||||
this.groupLink = new LiveGroup(groupId).getGroupLink();
|
||||
this.groupLink = liveGroup.getGroupLink();
|
||||
this.canEdit = liveGroup.isSelfAdmin();
|
||||
this.toasts = new SingleLiveEvent<>();
|
||||
this.busy = new SingleLiveEvent<>();
|
||||
}
|
||||
|
@ -35,7 +36,7 @@ final class ShareableGroupLinkViewModel extends ViewModel {
|
|||
return groupLink;
|
||||
}
|
||||
|
||||
LiveData<String> getToasts() {
|
||||
LiveData<Integer> getToasts() {
|
||||
return toasts;
|
||||
}
|
||||
|
||||
|
@ -43,7 +44,11 @@ final class ShareableGroupLinkViewModel extends ViewModel {
|
|||
return busy;
|
||||
}
|
||||
|
||||
void onToggleGroupLink(@NonNull Context context) {
|
||||
LiveData<Boolean> getCanEdit() {
|
||||
return canEdit;
|
||||
}
|
||||
|
||||
void onToggleGroupLink() {
|
||||
busy.setValue(true);
|
||||
repository.toggleGroupLinkEnabled(new AsynchronousCallback.WorkerThread<Void, GroupChangeFailureReason>() {
|
||||
@Override
|
||||
|
@ -54,12 +59,12 @@ final class ShareableGroupLinkViewModel extends ViewModel {
|
|||
@Override
|
||||
public void onError(@Nullable GroupChangeFailureReason error) {
|
||||
busy.postValue(false);
|
||||
toasts.postValue(context.getString(GroupErrors.getUserDisplayMessage(error)));
|
||||
toasts.postValue(GroupErrors.getUserDisplayMessage(error));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void onToggleApproveMembers(@NonNull Context context) {
|
||||
void onToggleApproveMembers() {
|
||||
busy.setValue(true);
|
||||
repository.toggleGroupLinkApprovalRequired(new AsynchronousCallback.WorkerThread<Void, GroupChangeFailureReason>() {
|
||||
@Override
|
||||
|
@ -70,24 +75,23 @@ final class ShareableGroupLinkViewModel extends ViewModel {
|
|||
@Override
|
||||
public void onError(@Nullable GroupChangeFailureReason error) {
|
||||
busy.postValue(false);
|
||||
toasts.postValue(context.getString(GroupErrors.getUserDisplayMessage(error)));
|
||||
toasts.postValue(GroupErrors.getUserDisplayMessage(error));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void onResetLink(@NonNull Context context) {
|
||||
void onResetLink() {
|
||||
busy.setValue(true);
|
||||
repository.cycleGroupLinkPassword(new AsynchronousCallback.WorkerThread<Void, GroupChangeFailureReason>() {
|
||||
@Override
|
||||
public void onComplete(@Nullable Void result) {
|
||||
busy.postValue(false);
|
||||
toasts.postValue(context.getString(R.string.ShareableGroupLinkDialogFragment__group_link_reset));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(@Nullable GroupChangeFailureReason error) {
|
||||
busy.postValue(false);
|
||||
toasts.postValue(context.getString(GroupErrors.getUserDisplayMessage(error)));
|
||||
toasts.postValue(GroupErrors.getUserDisplayMessage(error));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -618,6 +618,10 @@
|
|||
<item quantity="other">%d members added.</item>
|
||||
</plurals>
|
||||
|
||||
<string name="ManageGroupActivity_only_admins_can_enable_or_disable_the_sharable_group_link">Only admins can enable or disable the sharable group link.</string>
|
||||
<string name="ManageGroupActivity_only_admins_can_enable_or_disable_the_option_to_approve_new_members">Only admins can enable or disable the option to approve new members.</string>
|
||||
<string name="ManageGroupActivity_only_admins_can_reset_the_sharable_group_link">Only admins can reset the sharable group link.</string>
|
||||
|
||||
<string name="ManageGroupActivity_you_dont_have_the_rights_to_do_this">You don\'t have the rights to do this</string>
|
||||
<string name="ManageGroupActivity_not_capable">Someone you added does not support new groups and needs to update Signal</string>
|
||||
<string name="ManageGroupActivity_failed_to_update_the_group">Failed to update the group</string>
|
||||
|
|
Loading…
Reference in New Issue