Compare commits

..

4 Commits

Author SHA1 Message Date
copilot-swe-agent[bot] 0adf3eeb4f Final cleanup - remove unnecessary defensive code
Co-authored-by: adbenitez <24558636+adbenitez@users.noreply.github.com>
2026-01-28 23:37:59 +00:00
copilot-swe-agent[bot] fee867c620 Add defensive checks and default values for fragment arguments
Co-authored-by: adbenitez <24558636+adbenitez@users.noreply.github.com>
2026-01-28 23:34:03 +00:00
copilot-swe-agent[bot] 2d216ca890 Fix fragment constructor crashes - add no-arg constructors and use Bundle for arguments
Co-authored-by: adbenitez <24558636+adbenitez@users.noreply.github.com>
2026-01-28 23:31:50 +00:00
copilot-swe-agent[bot] 8577ffa50f Initial plan 2026-01-28 23:27:01 +00:00
8 changed files with 62 additions and 56 deletions
@@ -23,9 +23,7 @@ import android.view.MenuInflater;
import android.view.MenuItem;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
/**
* Activity container for selecting a list of contacts.
@@ -36,9 +34,6 @@ import java.util.Set;
public class ContactMultiSelectionActivity extends ContactSelectionActivity {
public static final String CONTACTS_EXTRA = "contacts_extra";
public static final String REMOVED_CONTACTS_EXTRA = "removed_contacts_extra";
private ArrayList<Integer> preselectedContacts;
@Override
protected void onCreate(Bundle icicle, boolean ready) {
@@ -49,9 +44,6 @@ public class ContactMultiSelectionActivity extends ContactSelectionActivity {
// it's a bit confusing having one "X" button on the left and one on the right -
// and the "clear search" button is not that important.
getToolbar().setUseClearButton(false);
// Store preselected contacts to track which ones were removed
preselectedContacts = getIntent().getIntegerArrayListExtra(ContactSelectionListFragment.PRESELECTED_CONTACTS);
}
@Override
@@ -80,19 +72,6 @@ public class ContactMultiSelectionActivity extends ContactSelectionActivity {
Intent resultIntent = getIntent();
List<Integer> selectedContacts = contactsFragment.getSelectedContacts();
resultIntent.putIntegerArrayListExtra(CONTACTS_EXTRA, new ArrayList<>(selectedContacts));
// Calculate which contacts were removed (preselected but not in final selection)
if (preselectedContacts != null) {
Set<Integer> selectedSet = new HashSet<>(selectedContacts);
ArrayList<Integer> removedContacts = new ArrayList<>();
for (Integer preselectedId : preselectedContacts) {
if (!selectedSet.contains(preselectedId)) {
removedContacts.add(preselectedId);
}
}
resultIntent.putIntegerArrayListExtra(REMOVED_CONTACTS_EXTRA, removedContacts);
}
setResult(RESULT_OK, resultIntent);
}
}
@@ -891,7 +891,7 @@ public class ConversationFragment extends MessageSelectorFragment
@Override
public void onReactionClicked(DcMsg messageRecord) {
ReactionsDetailsFragment dialog = new ReactionsDetailsFragment(messageRecord.getId());
ReactionsDetailsFragment dialog = ReactionsDetailsFragment.newInstance(messageRecord.getId());
dialog.show(getActivity().getSupportFragmentManager(), null);
}
}
@@ -310,24 +310,13 @@ public class ProfileFragment extends Fragment
super.onActivityResult(requestCode, resultCode, data);
if (requestCode==REQUEST_CODE_PICK_CONTACT && resultCode==Activity.RESULT_OK && data!=null) {
List<Integer> selected = data.getIntegerArrayListExtra(ContactMultiSelectionActivity.CONTACTS_EXTRA);
List<Integer> removed = data.getIntegerArrayListExtra(ContactMultiSelectionActivity.REMOVED_CONTACTS_EXTRA);
if(selected == null) return;
Util.runOnAnyBackgroundThread(() -> {
// Add new members
for (Integer contactId : selected) {
if (contactId != null) {
if (contactId!=null) {
dcContext.addContactToChat(chatId, contactId);
}
}
// Remove members that were explicitly unchecked
if (removed != null) {
for (Integer contactId : removed) {
if (contactId != null) {
dcContext.removeContactFromChat(chatId, contactId);
}
}
}
});
}
}
@@ -47,20 +47,40 @@ import chat.delta.rpc.RpcException;
public class AccountSelectionListFragment extends DialogFragment implements DcEventCenter.DcEventDelegate
{
private static final String TAG = AccountSelectionListFragment.class.getSimpleName();
private final ConversationListActivity activity;
private static final String ARG_SELECT_ONLY = "select_only";
private ConversationListActivity activity;
private RecyclerView recyclerView;
private AccountSelectionListAdapter adapter;
private final boolean selectOnly;
private boolean selectOnly;
public AccountSelectionListFragment(ConversationListActivity activity, boolean selectOnly) {
public AccountSelectionListFragment() {
super();
this.activity = activity;
this.selectOnly = selectOnly;
}
public static AccountSelectionListFragment newInstance(boolean selectOnly) {
AccountSelectionListFragment fragment = new AccountSelectionListFragment();
Bundle args = new Bundle();
args.putBoolean(ARG_SELECT_ONLY, selectOnly);
fragment.setArguments(args);
return fragment;
}
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
// Retrieve selectOnly from arguments (defaults to false if not present)
if (getArguments() != null) {
selectOnly = getArguments().getBoolean(ARG_SELECT_ONLY, false);
}
// Get the activity from the context - must be ConversationListActivity
if (getActivity() instanceof ConversationListActivity) {
activity = (ConversationListActivity) getActivity();
} else {
throw new IllegalStateException("AccountSelectionListFragment must be attached to ConversationListActivity");
}
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity())
.setTitle(R.string.switch_account)
.setNegativeButton(R.string.cancel, null);
@@ -138,7 +138,7 @@ public class AccountManager {
// ui
public void showSwitchAccountMenu(ConversationListActivity activity, boolean selectOnly) {
AccountSelectionListFragment dialog = new AccountSelectionListFragment(activity, selectOnly);
AccountSelectionListFragment dialog = AccountSelectionListFragment.newInstance(selectOnly);
dialog.show(((FragmentActivity) activity).getSupportFragmentManager(), null);
}
@@ -69,7 +69,7 @@ public class QrActivity extends BaseActionBarActivity implements View.OnClickLis
scanRelay = getIntent().getBooleanExtra(EXTRA_SCAN_RELAY, false);
qrShowFragment = new QrShowFragment(this);
qrShowFragment = new QrShowFragment();
tabLayout = ViewUtil.findById(this, R.id.tab_layout);
viewPager = ViewUtil.findById(this, R.id.pager);
ProfilePagerAdapter adapter = new ProfilePagerAdapter(this, getSupportFragmentManager());
@@ -54,15 +54,8 @@ public class QrShowFragment extends Fragment implements DcEventCenter.DcEventDel
private DcContext dcContext;
private View.OnClickListener scanClicklistener;
public QrShowFragment() {
this(null);
}
public QrShowFragment(View.OnClickListener scanClicklistener) {
super();
this.scanClicklistener = scanClicklistener;
}
@Override
@@ -79,9 +72,14 @@ public class QrShowFragment extends Fragment implements DcEventCenter.DcEventDel
dcContext = DcHelper.getContext(getActivity());
dcEventCenter = DcHelper.getEventCenter(getActivity());
Bundle extras = getActivity().getIntent().getExtras();
if (extras != null) {
chatId = extras.getInt(CHAT_ID);
// First try to get chatId from fragment arguments, then fall back to activity intent
if (getArguments() != null && getArguments().containsKey(CHAT_ID)) {
chatId = getArguments().getInt(CHAT_ID);
} else {
Bundle extras = getActivity().getIntent().getExtras();
if (extras != null) {
chatId = extras.getInt(CHAT_ID);
}
}
dcEventCenter.addObserver(DcContext.DC_EVENT_SECUREJOIN_INVITER_PROGRESS, this);
@@ -108,9 +106,16 @@ public class QrShowFragment extends Fragment implements DcEventCenter.DcEventDel
view.findViewById(R.id.share_link_button).setOnClickListener((v) -> showInviteLinkDialog());
Button scanBtn = view.findViewById(R.id.scan_qr_button);
if (scanClicklistener != null) {
// Check if the activity implements View.OnClickListener to provide scan functionality
View.OnClickListener scanClickListener = null;
if (getActivity() instanceof View.OnClickListener) {
scanClickListener = (View.OnClickListener) getActivity();
}
if (scanClickListener != null) {
scanBtn.setVisibility(View.VISIBLE);
scanBtn.setOnClickListener(scanClicklistener);
scanBtn.setOnClickListener(scanClickListener);
} else {
scanBtn.setVisibility(View.GONE);
}
@@ -36,19 +36,32 @@ import chat.delta.rpc.types.Reactions;
public class ReactionsDetailsFragment extends DialogFragment implements DcEventCenter.DcEventDelegate {
private static final String TAG = ReactionsDetailsFragment.class.getSimpleName();
private static final String ARG_MSG_ID = "msg_id";
private RecyclerView recyclerView;
private ReactionRecipientsAdapter adapter;
private final int msgId;
private int msgId;
public ReactionsDetailsFragment(int msgId) {
public ReactionsDetailsFragment() {
super();
this.msgId = msgId;
}
public static ReactionsDetailsFragment newInstance(int msgId) {
ReactionsDetailsFragment fragment = new ReactionsDetailsFragment();
Bundle args = new Bundle();
args.putInt(ARG_MSG_ID, msgId);
fragment.setArguments(args);
return fragment;
}
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
// Retrieve msgId from arguments
if (getArguments() != null) {
msgId = getArguments().getInt(ARG_MSG_ID, 0);
}
adapter = new ReactionRecipientsAdapter(requireActivity(), GlideApp.with(requireActivity()), new ListClickListener());
LayoutInflater inflater = requireActivity().getLayoutInflater();