Hide "Add to a group" if you don't have any groups.
This commit is contained in:
parent
f3dbe4416f
commit
137cd45497
7 changed files with 50 additions and 2 deletions
|
@ -251,6 +251,20 @@ public final class GroupDatabase extends Database {
|
|||
return new Reader(cursor);
|
||||
}
|
||||
|
||||
public int getActiveGroupCount() {
|
||||
SQLiteDatabase db = databaseHelper.getReadableDatabase();
|
||||
String[] cols = { "COUNT(*)" };
|
||||
String query = ACTIVE + " = 1";
|
||||
|
||||
try (Cursor cursor = db.query(TABLE_NAME, cols, query, null, null, null, null)) {
|
||||
if (cursor != null && cursor.moveToFirst()) {
|
||||
return cursor.getInt(0);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
public @NonNull List<Recipient> getGroupMembers(@NonNull GroupId groupId, @NonNull MemberSet memberSet) {
|
||||
if (groupId.isV2()) {
|
||||
|
|
|
@ -29,7 +29,6 @@ import org.thoughtcrime.securesms.groups.GroupId;
|
|||
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||
import org.thoughtcrime.securesms.recipients.RecipientExporter;
|
||||
import org.thoughtcrime.securesms.recipients.RecipientId;
|
||||
import org.thoughtcrime.securesms.util.CommunicationActions;
|
||||
import org.thoughtcrime.securesms.util.ServiceUtil;
|
||||
import org.thoughtcrime.securesms.util.ThemeUtil;
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
|
@ -179,9 +178,11 @@ public final class RecipientBottomSheetDialogFragment extends BottomSheetDialogF
|
|||
startActivityForResult(RecipientExporter.export(recipient).asAddContactIntent(), REQUEST_CODE_ADD_CONTACT);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
viewModel.getCanAddToAGroup().observe(getViewLifecycleOwner(), canAdd -> {
|
||||
addToGroupButton.setText(groupId == null ? R.string.RecipientBottomSheet_add_to_a_group : R.string.RecipientBottomSheet_add_to_another_group);
|
||||
addToGroupButton.setVisibility(recipient.isRegistered() && !recipient.isGroup() && !recipient.isLocalNumber() ? View.VISIBLE : View.GONE);
|
||||
addToGroupButton.setVisibility(canAdd ? View.VISIBLE : View.GONE);
|
||||
});
|
||||
|
||||
viewModel.getAdminActionStatus().observe(getViewLifecycleOwner(), adminStatus -> {
|
||||
|
|
|
@ -135,6 +135,10 @@ final class RecipientDialogRepository {
|
|||
onComplete::accept);
|
||||
}
|
||||
|
||||
public void getActiveGroupCount(@NonNull Consumer<Integer> onComplete) {
|
||||
SignalExecutors.BOUNDED.execute(() -> onComplete.accept(DatabaseFactory.getGroupDatabase(context).getActiveGroupCount()));
|
||||
}
|
||||
|
||||
interface RecipientCallback {
|
||||
void onRecipient(@NonNull Recipient recipient);
|
||||
}
|
||||
|
|
|
@ -40,6 +40,7 @@ final class RecipientDialogViewModel extends ViewModel {
|
|||
private final LiveData<Recipient> recipient;
|
||||
private final MutableLiveData<IdentityDatabase.IdentityRecord> identity;
|
||||
private final LiveData<AdminActionStatus> adminActionStatus;
|
||||
private final LiveData<Boolean> canAddToAGroup;
|
||||
private final MutableLiveData<Boolean> adminActionBusy;
|
||||
|
||||
private RecipientDialogViewModel(@NonNull Context context,
|
||||
|
@ -73,12 +74,23 @@ final class RecipientDialogViewModel extends ViewModel {
|
|||
if (!isSelf) {
|
||||
recipientDialogRepository.getIdentity(identity::postValue);
|
||||
}
|
||||
|
||||
MutableLiveData<Integer> localGroupCount = new MutableLiveData<>(0);
|
||||
|
||||
canAddToAGroup = LiveDataUtil.combineLatest(recipient, localGroupCount,
|
||||
(r, count) -> count > 0 && r.isRegistered() && !r.isGroup() && !r.isLocalNumber());
|
||||
|
||||
recipientDialogRepository.getActiveGroupCount(localGroupCount::postValue);
|
||||
}
|
||||
|
||||
LiveData<Recipient> getRecipient() {
|
||||
return recipient;
|
||||
}
|
||||
|
||||
public LiveData<Boolean> getCanAddToAGroup() {
|
||||
return canAddToAGroup;
|
||||
}
|
||||
|
||||
LiveData<AdminActionStatus> getAdminActionStatus() {
|
||||
return adminActionStatus;
|
||||
}
|
||||
|
|
|
@ -202,6 +202,7 @@ public class ManageRecipientFragment extends LoggingFragment {
|
|||
viewModel.getRecipient().observe(getViewLifecycleOwner(), this::presentRecipient);
|
||||
viewModel.getMediaCursor().observe(getViewLifecycleOwner(), this::presentMediaCursor);
|
||||
viewModel.getMuteState().observe(getViewLifecycleOwner(), this::presentMuteState);
|
||||
viewModel.getCanAddToAGroup().observe(getViewLifecycleOwner(), canAdd -> addToAGroup.setVisibility(canAdd ? View.VISIBLE : View.GONE));
|
||||
|
||||
disappearingMessagesRow.setOnClickListener(v -> viewModel.handleExpirationSelection(requireContext()));
|
||||
block.setOnClickListener(v -> viewModel.onBlockClicked(requireActivity()));
|
||||
|
|
|
@ -105,4 +105,8 @@ final class ManageRecipientRepository {
|
|||
.sortBy(gr -> gr.getDisplayName(context))
|
||||
.toList();
|
||||
}
|
||||
|
||||
void getActiveGroupCount(@NonNull Consumer<Integer> onComplete) {
|
||||
SignalExecutors.BOUNDED.execute(() -> onComplete.accept(DatabaseFactory.getGroupDatabase(context).getActiveGroupCount()));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -58,6 +58,7 @@ public final class ManageRecipientViewModel extends ViewModel {
|
|||
private final LiveData<Boolean> canBlock;
|
||||
private final LiveData<List<GroupMemberEntry.FullMember>> visibleSharedGroups;
|
||||
private final LiveData<String> sharedGroupsCountSummary;
|
||||
private final LiveData<Boolean> canAddToAGroup;
|
||||
|
||||
private ManageRecipientViewModel(@NonNull Context context, @NonNull ManageRecipientRepository manageRecipientRepository) {
|
||||
this.context = context;
|
||||
|
@ -95,6 +96,13 @@ public final class ManageRecipientViewModel extends ViewModel {
|
|||
if (!isSelf) {
|
||||
manageRecipientRepository.getIdentity(identity::postValue);
|
||||
}
|
||||
|
||||
MutableLiveData<Integer> localGroupCount = new MutableLiveData<>(0);
|
||||
|
||||
canAddToAGroup = LiveDataUtil.combineLatest(recipient, localGroupCount,
|
||||
(r, count) -> count > 0 && r.isRegistered() && !r.isGroup() && !r.isLocalNumber());
|
||||
|
||||
manageRecipientRepository.getActiveGroupCount(localGroupCount::postValue);
|
||||
}
|
||||
|
||||
private static @NonNull String getDisplayTitle(@NonNull Recipient recipient, @NonNull Context context) {
|
||||
|
@ -132,6 +140,10 @@ public final class ManageRecipientViewModel extends ViewModel {
|
|||
return recipient;
|
||||
}
|
||||
|
||||
LiveData<Boolean> getCanAddToAGroup() {
|
||||
return canAddToAGroup;
|
||||
}
|
||||
|
||||
LiveData<MediaCursor> getMediaCursor() {
|
||||
return mediaCursor;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue