fixed crash when selecting participants

This commit is contained in:
Daniel Gultsch 2018-02-17 12:27:04 +01:00
parent df82e7689d
commit 6f5076e8c4

View file

@ -2,6 +2,7 @@ package eu.siacs.conversations.ui;
import android.Manifest; import android.Manifest;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.support.annotation.NonNull;
import android.support.v7.app.AlertDialog; import android.support.v7.app.AlertDialog;
import android.app.Dialog; import android.app.Dialog;
import android.app.PendingIntent; import android.app.PendingIntent;
@ -77,8 +78,6 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
public int conference_context_id; public int conference_context_id;
public int contact_context_id; public int contact_context_id;
private ActionBar.Tab mContactsTab;
private ActionBar.Tab mConferencesTab;
private ViewPager mViewPager; private ViewPager mViewPager;
private ListPagerAdapter mListPagerAdapter; private ListPagerAdapter mListPagerAdapter;
private List<ListItem> contacts = new ArrayList<>(); private List<ListItem> contacts = new ArrayList<>();
@ -91,8 +90,8 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
private Invite mPendingInvite = null; private Invite mPendingInvite = null;
private EditText mSearchEditText; private EditText mSearchEditText;
private AtomicBoolean mRequestedContactsPermission = new AtomicBoolean(false); private AtomicBoolean mRequestedContactsPermission = new AtomicBoolean(false);
private final int REQUEST_SYNC_CONTACTS = 0x3b28cf; private final int REQUEST_SYNC_CONTACTS = 0x28cf;
private final int REQUEST_CREATE_CONFERENCE = 0x3b39da; private final int REQUEST_CREATE_CONFERENCE = 0x39da;
private Dialog mCurrentDialog = null; private Dialog mCurrentDialog = null;
private MenuItem.OnActionExpandListener mOnActionExpandListener = new MenuItem.OnActionExpandListener() { private MenuItem.OnActionExpandListener mOnActionExpandListener = new MenuItem.OnActionExpandListener() {
@ -243,8 +242,8 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
ActionBar actionBar = getSupportActionBar(); ActionBar actionBar = getSupportActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
mContactsTab = actionBar.newTab().setText(R.string.contacts).setTabListener(mTabListener); ActionBar.Tab mContactsTab = actionBar.newTab().setText(R.string.contacts).setTabListener(mTabListener);
mConferencesTab = actionBar.newTab().setText(R.string.conferences).setTabListener(mTabListener); ActionBar.Tab mConferencesTab = actionBar.newTab().setText(R.string.conferences).setTabListener(mTabListener);
actionBar.addTab(mContactsTab); actionBar.addTab(mContactsTab);
actionBar.addTab(mConferencesTab); actionBar.addTab(mConferencesTab);
@ -447,9 +446,9 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
final AlertDialog.Builder builder = new AlertDialog.Builder(this); final AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(R.string.dialog_title_join_conference); builder.setTitle(R.string.dialog_title_join_conference);
final View dialogView = getLayoutInflater().inflate(R.layout.join_conference_dialog, null); final View dialogView = getLayoutInflater().inflate(R.layout.join_conference_dialog, null);
final Spinner spinner = (Spinner) dialogView.findViewById(R.id.account); final Spinner spinner = dialogView.findViewById(R.id.account);
final AutoCompleteTextView jid = (AutoCompleteTextView) dialogView.findViewById(R.id.jid); final AutoCompleteTextView jid = dialogView.findViewById(R.id.jid);
final TextView jabberIdDesc = (TextView) dialogView.findViewById(R.id.jabber_id); final TextView jabberIdDesc = dialogView.findViewById(R.id.jabber_id);
jabberIdDesc.setText(R.string.conference_address); jabberIdDesc.setText(R.string.conference_address);
jid.setHint(R.string.conference_address_example); jid.setHint(R.string.conference_address_example);
jid.setAdapter(new KnownHostsAdapter(this, R.layout.simple_list_item, mKnownConferenceHosts)); jid.setAdapter(new KnownHostsAdapter(this, R.layout.simple_list_item, mKnownConferenceHosts));
@ -519,8 +518,8 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
final AlertDialog.Builder builder = new AlertDialog.Builder(this); final AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(R.string.dialog_title_create_conference); builder.setTitle(R.string.dialog_title_create_conference);
final View dialogView = getLayoutInflater().inflate(R.layout.create_conference_dialog, null); final View dialogView = getLayoutInflater().inflate(R.layout.create_conference_dialog, null);
final Spinner spinner = (Spinner) dialogView.findViewById(R.id.account); final Spinner spinner = dialogView.findViewById(R.id.account);
final EditText subject = (EditText) dialogView.findViewById(R.id.subject); final EditText subject = dialogView.findViewById(R.id.subject);
populateAccountSpinner(this, mActivatedAccounts, spinner); populateAccountSpinner(this, mActivatedAccounts, spinner);
builder.setView(dialogView); builder.setView(dialogView);
builder.setPositiveButton(R.string.choose_participants, new OnClickListener() { builder.setPositiveButton(R.string.choose_participants, new OnClickListener() {
@ -597,7 +596,7 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
mMenuSearchView = menu.findItem(R.id.action_search); mMenuSearchView = menu.findItem(R.id.action_search);
mMenuSearchView.setOnActionExpandListener(mOnActionExpandListener); mMenuSearchView.setOnActionExpandListener(mOnActionExpandListener);
View mSearchView = mMenuSearchView.getActionView(); View mSearchView = mMenuSearchView.getActionView();
mSearchEditText = (EditText) mSearchView.findViewById(R.id.search_field); mSearchEditText = mSearchView.findViewById(R.id.search_field);
mSearchEditText.addTextChangedListener(mSearchTextWatcher); mSearchEditText.addTextChangedListener(mSearchTextWatcher);
mSearchEditText.setOnEditorActionListener(mSearchDone); mSearchEditText.setOnEditorActionListener(mSearchDone);
if (getSupportActionBar().getSelectedNavigationIndex() == 0) { if (getSupportActionBar().getSelectedNavigationIndex() == 0) {
@ -740,7 +739,7 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
} }
@Override @Override
public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) { public void onRequestPermissionsResult(int requestCode,@NonNull String permissions[],@NonNull int[] grantResults) {
if (grantResults.length > 0) if (grantResults.length > 0)
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) { if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
if (requestCode == REQUEST_SYNC_CONTACTS && xmppConnectionServiceBound) { if (requestCode == REQUEST_SYNC_CONTACTS && xmppConnectionServiceBound) {
@ -964,7 +963,7 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
} }
@Override @Override
public void destroyItem(ViewGroup container, int position, Object object) { public void destroyItem(@NonNull ViewGroup container, int position,@NonNull Object object) {
assert (0 <= position && position < fragments.length); assert (0 <= position && position < fragments.length);
FragmentTransaction trans = fragmentManager.beginTransaction(); FragmentTransaction trans = fragmentManager.beginTransaction();
trans.remove(fragments[position]); trans.remove(fragments[position]);
@ -973,7 +972,7 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
} }
@Override @Override
public Fragment instantiateItem(ViewGroup container, int position) { public Fragment instantiateItem(@NonNull ViewGroup container, int position) {
Fragment fragment = getItem(position); Fragment fragment = getItem(position);
FragmentTransaction trans = fragmentManager.beginTransaction(); FragmentTransaction trans = fragmentManager.beginTransaction();
trans.add(container.getId(), fragment, "fragment:" + position); trans.add(container.getId(), fragment, "fragment:" + position);
@ -987,7 +986,7 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
} }
@Override @Override
public boolean isViewFromObject(View view, Object fragment) { public boolean isViewFromObject(@NonNull View view,@NonNull Object fragment) {
return ((Fragment) fragment).getView() == view; return ((Fragment) fragment).getView() == view;
} }
@ -998,26 +997,12 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
if (position == 1) { if (position == 1) {
listFragment.setListAdapter(mConferenceAdapter); listFragment.setListAdapter(mConferenceAdapter);
listFragment.setContextMenu(R.menu.conference_context); listFragment.setContextMenu(R.menu.conference_context);
listFragment.setOnListItemClickListener(new OnItemClickListener() { listFragment.setOnListItemClickListener((arg0, arg1, p, arg3) -> openConversationForBookmark(p));
@Override
public void onItemClick(AdapterView<?> arg0, View arg1,
int position, long arg3) {
openConversationForBookmark(position);
}
});
} else { } else {
listFragment.setListAdapter(mContactsAdapter); listFragment.setListAdapter(mContactsAdapter);
listFragment.setContextMenu(R.menu.contact_context); listFragment.setContextMenu(R.menu.contact_context);
listFragment.setOnListItemClickListener(new OnItemClickListener() { listFragment.setOnListItemClickListener((arg0, arg1, p, arg3) -> openConversationForContact(p));
@Override
public void onItemClick(AdapterView<?> arg0, View arg1,
int position, long arg3) {
openConversationForContact(position);
}
});
} }
fragments[position] = listFragment; fragments[position] = listFragment;
} }
@ -1045,7 +1030,7 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
} }
@Override @Override
public void onViewCreated(final View view, final Bundle savedInstanceState) { public void onViewCreated(@NonNull final View view, final Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState); super.onViewCreated(view, savedInstanceState);
registerForContextMenu(getListView()); registerForContextMenu(getListView());
getListView().setFastScrollEnabled(true); getListView().setFastScrollEnabled(true);
@ -1056,6 +1041,9 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
final ContextMenuInfo menuInfo) { final ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo); super.onCreateContextMenu(menu, v, menuInfo);
final StartConversationActivity activity = (StartConversationActivity) getActivity(); final StartConversationActivity activity = (StartConversationActivity) getActivity();
if (activity == null) {
return;
}
activity.getMenuInflater().inflate(mResContextMenu, menu); activity.getMenuInflater().inflate(mResContextMenu, menu);
final AdapterView.AdapterContextMenuInfo acmi = (AdapterContextMenuInfo) menuInfo; final AdapterView.AdapterContextMenuInfo acmi = (AdapterContextMenuInfo) menuInfo;
if (mResContextMenu == R.menu.conference_context) { if (mResContextMenu == R.menu.conference_context) {
@ -1084,6 +1072,9 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
@Override @Override
public boolean onContextItemSelected(final MenuItem item) { public boolean onContextItemSelected(final MenuItem item) {
StartConversationActivity activity = (StartConversationActivity) getActivity(); StartConversationActivity activity = (StartConversationActivity) getActivity();
if (activity == null) {
return true;
}
switch (item.getItemId()) { switch (item.getItemId()) {
case R.id.context_start_conversation: case R.id.context_start_conversation:
activity.openConversationForContact(); activity.openConversationForContact();