Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1f2facbe authored by Adnan's avatar Adnan
Browse files

Contacts: Prevent NPE on multi select in local group select.

JIRA: CYAN-5788
https://jira.cyanogenmod.org/browse/CYAN-5788

Change-Id: I8d5daaf1b05372adcb19f10abc5533079f036e3f
parent dbd31fc0
Loading
Loading
Loading
Loading
+3 −9
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@
<!--
 *
 * Copyright (c) 2013, The Linux Foundation. All Rights Reserved.
 * Copyright (c) 2014, The CyanogenMod Project
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are
@@ -28,13 +29,7 @@
 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 -->
<TabHost
        android:id="@android:id/tabhost"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        xmlns:android="http://schemas.android.com/apk/res/android">

    <LinearLayout
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
@@ -59,4 +54,3 @@
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />
</LinearLayout>
</TabHost>
+1 −0
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@
     android:layout_height="wrap_content"
     android:gravity="center_vertical"
     android:minHeight="?android:attr/listPreferredItemHeight"
     android:background="?android:activatedBackgroundIndicator"
     android:paddingTop="3dip"
     android:paddingBottom="3dip"
     >
+48 −20
Original line number Diff line number Diff line
@@ -278,9 +278,16 @@ public class MemberListActivity extends Activity implements AdapterView.OnItemCl
        emptyText = (TextView) findViewById(R.id.emptyText);
        mListView = (ListView) findViewById(R.id.member_list);
        mListView.setAdapter(mAdapter);
        mListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);
        mListView.setOnItemClickListener(this);
        mListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);
        mListView.setMultiChoiceModeListener(mMultiChoiceModeListener);
        mListView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
            @Override
            public boolean onItemLongClick(AdapterView<?> list, View v, int position, long arg3) {
                mListView.setItemChecked(position, true);
                return true;
            }
        });
        uri = getIntent().getParcelableExtra("data");
        getContentResolver().registerContentObserver(
                Uri.withAppendedPath(LocalGroup.CONTENT_FILTER_URI,
@@ -290,6 +297,15 @@ public class MemberListActivity extends Activity implements AdapterView.OnItemCl
        actionBar.setSubtitle(mGroup.getTitle());
    }

    @Override
    public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
        if (!mListView.isItemChecked(position)) {
            mListView.setItemChecked(position, true);
        } else {
            mListView.setItemChecked(position, false);
        }
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater inflater = getMenuInflater();
@@ -389,7 +405,6 @@ public class MemberListActivity extends Activity implements AdapterView.OnItemCl
    @Override
    protected void onPause() {
        super.onPause();

        mPaused = true;
        mAdapter.changeCursor(null);
    }
@@ -415,15 +430,15 @@ public class MemberListActivity extends Activity implements AdapterView.OnItemCl
        @Override
        public void onItemCheckedStateChanged(ActionMode mode, int position,
                                              long id, boolean checked) {
            View v = mListView.getChildAt(position);
            String contactId = (String) v.getTag();
            CheckBox checkBox = (CheckBox) v.findViewById(R.id.pick_contact_check);
            if (mRemoveSet.containsKey(contactId)) {
                mRemoveSet.remove(contactId);
            ContactItem item = mAdapter.getItem(position);
            if (item != null) {
                if (mRemoveSet.containsKey(item.toString())) {
                    mRemoveSet.remove(item.toString());
                } else {
                mRemoveSet.putString(contactId, contactId);
                    mRemoveSet.putString(item.toString(), item.toString());
                }
            setCheckStatus(contactId, checkBox);
            }
            mAdapter.notifyDataSetChanged();
        }

        @Override
@@ -492,6 +507,15 @@ public class MemberListActivity extends Activity implements AdapterView.OnItemCl
                null, null);
    }

    class ContactItem {
        private long rawContactId;

        @Override
        public String toString() {
            return String.valueOf(rawContactId);
        }
    }

    private class QueryHandler extends AsyncQueryHandler {
        protected final WeakReference<MemberListActivity> mActivity;

@@ -517,6 +541,20 @@ public class MemberListActivity extends Activity implements AdapterView.OnItemCl
            super(context, null);
        }

        @Override
        public ContactItem getItem(int position) {
            Cursor cursor = getCursor();
            ContactItem contactItem;
            if (cursor != null && cursor.moveToPosition(position)) {
                contactItem = new ContactItem();
                contactItem.rawContactId = cursor.getLong(SUMMARY_RAW_CONTACTS_ID_INDEX);
            } else {
                return null;
            }

            return contactItem;
        }

        @Override
        public void bindView(View view, Context context, Cursor cursor) {
            long contactId = cursor.getLong(SUMMARY_ID_COLUMN_INDEX);
@@ -537,7 +575,6 @@ public class MemberListActivity extends Activity implements AdapterView.OnItemCl

            String key = String.valueOf(rawContactsId);
            setCheckStatus(key, checkBox);
            view.setTag(key);
        }

        @Override
@@ -647,15 +684,6 @@ public class MemberListActivity extends Activity implements AdapterView.OnItemCl
        return icon;
    }

    @Override
    public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
        if (!mListView.isItemChecked(position)) {
            mListView.setItemChecked(position, true);
        } else {
            mListView.setItemChecked(position, false);
        }
    }

    private void pickMembers() {
        Intent intent = new Intent(MultiPickContactActivity.ACTION_MULTI_PICK);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);