Skip to content

Commit

Permalink
Infer contact multi-select allowing assertion removal.
Browse files Browse the repository at this point in the history
Hide count on invite friends.

Fixes #10125
  • Loading branch information
alan-signal authored and cody-signal committed Oct 23, 2020
1 parent 3f983a5 commit 4099154
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,11 @@ public final class ContactSelectionListFragment extends LoggingFragment
public static final int NO_LIMIT = Integer.MAX_VALUE;

public static final String DISPLAY_MODE = "display_mode";
public static final String MULTI_SELECT = "multi_select";
public static final String REFRESHABLE = "refreshable";
public static final String RECENTS = "recents";
public static final String SELECTION_LIMITS = "selection_limits";
public static final String CURRENT_SELECTION = "current_selection";
public static final String HIDE_COUNT = "hide_count";

private ConstraintLayout constraintLayout;
private TextView emptyText;
Expand All @@ -135,6 +135,7 @@ public final class ContactSelectionListFragment extends LoggingFragment
private SelectionLimits selectionLimit = SelectionLimits.NO_LIMITS;
private Set<RecipientId> currentSelection;
private boolean isMulti;
private boolean hideCount;

@Override
public void onAttach(@NonNull Context context) {
Expand Down Expand Up @@ -213,19 +214,12 @@ public boolean canReuseUpdatedViewHolder(@NonNull RecyclerView.ViewHolder viewHo

swipeRefresh.setEnabled(intent.getBooleanExtra(REFRESHABLE, true));

hideCount = intent.getBooleanExtra(HIDE_COUNT, false);
selectionLimit = intent.getParcelableExtra(SELECTION_LIMITS);
isMulti = intent.getBooleanExtra(MULTI_SELECT, false);
isMulti = selectionLimit != null;

if (isMulti) {
if (selectionLimit == null) {
throw new AssertionError("Selection limits not supplied in args for multi-select");
}
} else {
if (selectionLimit != null) {
throw new AssertionError("Selection limits supplied in args for a non-multi selection use");
} else {
selectionLimit = SelectionLimits.NO_LIMITS;
}
if (!isMulti) {
selectionLimit = SelectionLimits.NO_LIMITS;
}

currentSelection = getCurrentSelection();
Expand All @@ -238,7 +232,7 @@ public boolean canReuseUpdatedViewHolder(@NonNull RecyclerView.ViewHolder viewHo
private void updateGroupLimit(int chipCount) {
int members = currentSelection.size() + chipCount;
groupLimit.setText(getResources().getQuantityString(R.plurals.ContactSelectionListFragment_d_members, members, members));
groupLimit.setVisibility(isMulti ? View.VISIBLE : View.GONE);
groupLimit.setVisibility(isMulti && !hideCount ? View.VISIBLE : View.GONE);
groupLimit.setWarning(selectionWarningLimitExceeded());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.thoughtcrime.securesms.contacts.ContactsCursorLoader.DisplayMode;
import org.thoughtcrime.securesms.contacts.SelectedContact;
import org.thoughtcrime.securesms.database.DatabaseFactory;
import org.thoughtcrime.securesms.groups.SelectionLimits;
import org.thoughtcrime.securesms.recipients.Recipient;
import org.thoughtcrime.securesms.recipients.RecipientId;
import org.thoughtcrime.securesms.sms.MessageSender;
Expand Down Expand Up @@ -62,7 +63,8 @@ protected void onPreCreate() {
@Override
protected void onCreate(Bundle savedInstanceState, boolean ready) {
getIntent().putExtra(ContactSelectionListFragment.DISPLAY_MODE, DisplayMode.FLAG_SMS);
getIntent().putExtra(ContactSelectionListFragment.MULTI_SELECT, true);
getIntent().putExtra(ContactSelectionListFragment.SELECTION_LIMITS, SelectionLimits.NO_LIMITS);
getIntent().putExtra(ContactSelectionListFragment.HIDE_COUNT, true);
getIntent().putExtra(ContactSelectionListFragment.REFRESHABLE, false);

setContentView(R.layout.invite_activity);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ public class PushContactSelectionActivity extends ContactSelectionActivity {

@Override
protected void onCreate(Bundle icicle, boolean ready) {
getIntent().putExtra(ContactSelectionListFragment.MULTI_SELECT, true);
super.onCreate(icicle, ready);

initializeToolbar();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import android.os.Parcelable;

public final class SelectionLimits implements Parcelable {
public static final int NO_LIMIT = Integer.MAX_VALUE;
private static final int NO_LIMIT = Integer.MAX_VALUE;

public static final SelectionLimits NO_LIMITS = new SelectionLimits(NO_LIMIT, NO_LIMIT);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ public static Intent newIntent(@NonNull Context context,
{
Intent intent = new Intent(context, AddToGroupsActivity.class);

intent.putExtra(ContactSelectionListFragment.MULTI_SELECT, false);
intent.putExtra(ContactSelectionListFragment.REFRESHABLE, false);
intent.putExtra(ContactSelectionListFragment.RECENTS, true);
intent.putExtra(ContactSelectionActivity.EXTRA_LAYOUT_RES_ID, R.layout.add_to_group_activity);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ public class CreateGroupActivity extends ContactSelectionActivity {
public static Intent newIntent(@NonNull Context context) {
Intent intent = new Intent(context, CreateGroupActivity.class);

intent.putExtra(ContactSelectionListFragment.MULTI_SELECT, true);
intent.putExtra(ContactSelectionListFragment.REFRESHABLE, false);
intent.putExtra(ContactSelectionActivity.EXTRA_LAYOUT_RES_ID, R.layout.create_group_activity);

Expand Down

0 comments on commit 4099154

Please sign in to comment.