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

Commit 4715c04e authored by Walter Jang's avatar Walter Jang
Browse files

First pass on group members list activity

Still missing first letter index so we're
stilling using the legacy GroupDetailActivity.

Bug 18641067

Change-Id: Ia726460edbaaa28e4017f51b4e6e016c8c9010c7
parent 6ec81f7c
Loading
Loading
Loading
Loading
+22 −0
Original line number Original line Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
     Copyright (C) 2016 The Android Open Source Project

     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
     You may obtain a copy of the License at

          http://www.apache.org/licenses/LICENSE-2.0

     Unless required by applicable law or agreed to in writing, software
     distributed under the License is distributed on an "AS IS" BASIS,
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     See the License for the specific language governing permissions and
     limitations under the License.
-->

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/fragment_container"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>
 No newline at end of file
+7 −0
Original line number Original line Diff line number Diff line
@@ -299,6 +299,13 @@
        <xliff:g id="group_name">%s</xliff:g> (<xliff:g id="count">%d</xliff:g>)
        <xliff:g id="group_name">%s</xliff:g> (<xliff:g id="count">%d</xliff:g>)
    </string>
    </string>


    <!-- Group list header title with the number of members in the group. [CHAR LIMIT=30] -->
    <plurals name="group_members_count">
        <item quantity="zero">No contacts</item>
        <item quantity="one">1 contact</item>
        <item quantity="other"><xliff:g id="count">%d</xliff:g> contacts</item>
    </plurals>

    <!-- The text displayed when the groups list is empty while displaying all groups [CHAR LIMIT=NONE] -->
    <!-- The text displayed when the groups list is empty while displaying all groups [CHAR LIMIT=NONE] -->
    <string name="noGroups">No groups.</string>
    <string name="noGroups">No groups.</string>


+89 −0
Original line number Original line Diff line number Diff line
/*
 * Copyright (C) 2016 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License
 */
package com.android.contacts.activities;

import android.app.ActionBar;
import android.app.FragmentManager;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;

import com.android.contacts.ContactsActivity;
import com.android.contacts.R;
import com.android.contacts.common.util.ImplicitIntentsUtil;
import com.android.contacts.group.GroupMembersListFragment;
import com.android.contacts.group.GroupMembersListFragment.GroupMembersCallbacks;
import com.android.contacts.quickcontact.QuickContactActivity;

/** Displays the members of a group. */
public class GroupMembersActivity extends ContactsActivity implements GroupMembersCallbacks {

    private static final String TAG_GROUP_MEMBERS = "group_members";

    public static final String EXTRA_MEMBERS_COUNT = "membersCount";

    private GroupMembersListFragment mFragment;

    @Override
    public void onCreate(Bundle savedState) {
        super.onCreate(savedState);

        setContentView(R.layout.group_members_activity);

        final ActionBar actionBar = getActionBar();
        if (actionBar != null) {
            actionBar.setDisplayShowHomeEnabled(true);
            actionBar.setDisplayHomeAsUpEnabled(true);
            actionBar.setDisplayShowTitleEnabled(true);
        }

        final FragmentManager fragmentManager = getFragmentManager();
        mFragment = (GroupMembersListFragment) fragmentManager.findFragmentByTag(TAG_GROUP_MEMBERS);
        if (mFragment == null) {
            mFragment = new GroupMembersListFragment();
            fragmentManager.beginTransaction()
                    .add(R.id.fragment_container, mFragment, TAG_GROUP_MEMBERS)
                    .commit();
        }
        mFragment.setGroupUri(getIntent().getData());
        mFragment.setMembersCount(getIntent().getIntExtra(EXTRA_MEMBERS_COUNT, -1));
        mFragment.setCallbacks(this);
    }

    @Override
    public void onHomePressed() {
        onBackPressed();
    }

    @Override
    public void onGroupNameLoaded(String groupName) {
        setTitle(groupName);
    }

    @Override
    public void onGroupMemberClicked(Uri contactLookupUri) {
        startActivity(ImplicitIntentsUtil.composeQuickContactIntent(
                contactLookupUri, QuickContactActivity.MODE_FULLY_EXPANDED));
    }

    @Override
    public void onEditGroup(Uri groupUri) {
        final Intent intent = new Intent(this, GroupEditorActivity.class);
        intent.setData(groupUri);
        intent.setAction(Intent.ACTION_EDIT);
        startActivity(intent);
    }
}
+2 −1
Original line number Original line Diff line number Diff line
@@ -928,7 +928,8 @@ public class PeopleActivity extends AppCompatContactsActivity implements
                    : getString(R.string.group_name_menu_item, groupListItem.getTitle(),
                    : getString(R.string.group_name_menu_item, groupListItem.getTitle(),
                            groupListItem.getMemberCount());
                            groupListItem.getMemberCount());
            final MenuItem menuItem = menu.add(R.id.nav_groups, Menu.NONE, Menu.NONE, title);
            final MenuItem menuItem = menu.add(R.id.nav_groups, Menu.NONE, Menu.NONE, title);
            menuItem.setIntent(GroupUtil.createViewGroupIntent(this, groupListItem.getGroupId()));
            menuItem.setIntent(GroupUtil.createViewGroupIntent(
                    this, groupListItem.getGroupId(), groupListItem.getMemberCount()));
        }
        }


        // Create a menu item to add new groups
        // Create a menu item to add new groups
+163 −0
Original line number Original line Diff line number Diff line
/*
 * Copyright (C) 2016 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.android.contacts.group;

import android.content.Context;
import android.content.CursorLoader;
import android.database.Cursor;
import android.net.Uri;
import android.provider.ContactsContract;
import android.provider.ContactsContract.CommonDataKinds.GroupMembership;
import android.provider.ContactsContract.Contacts;
import android.provider.ContactsContract.Data;
import android.provider.ContactsContract.Directory;
import android.view.View;
import android.view.ViewGroup;

import com.android.contacts.common.ContactPhotoManager.DefaultImageRequest;
import com.android.contacts.common.list.ContactEntryListAdapter;
import com.android.contacts.common.list.ContactListItemView;
import com.android.contacts.common.preference.ContactsPreferences;

/** Group members cursor adapter. */
public class GroupMembersListAdapter extends ContactEntryListAdapter {

    private static class GroupMembersQuery {

        private static final String[] PROJECTION_PRIMARY = new String[] {
                Data.CONTACT_ID,
                Data.PHOTO_ID,
                Data.LOOKUP_KEY,
                Data.CONTACT_PRESENCE,
                Data.CONTACT_STATUS,
                Data.DISPLAY_NAME_PRIMARY,
        };

        private static final String[] PROJECTION_ALTERNATIVE = new String[] {
                Data.CONTACT_ID,
                Data.PHOTO_ID,
                Data.LOOKUP_KEY,
                Data.CONTACT_PRESENCE,
                Data.CONTACT_STATUS,
                Data.DISPLAY_NAME_ALTERNATIVE,
        };

        public static final int CONTACT_ID                   = 0;
        public static final int CONTACT_PHOTO_ID             = 1;
        public static final int CONTACT_LOOKUP_KEY           = 2;
        public static final int CONTACT_PRESENCE             = 3;
        public static final int CONTACT_STATUS               = 4;
        public static final int CONTACT_DISPLAY_NAME         = 5;
    }

    private final CharSequence mUnknownNameText;
    private long mGroupId;

    public GroupMembersListAdapter(Context context) {
        super(context);
        mUnknownNameText = context.getText(android.R.string.unknownName);
    }

    /** Sets the ID of the group whose members will be displayed. */
    public void setGroupId(long groupId) {
        mGroupId = groupId;
    }

    /** Returns the lookup Uri for the contact at the given position in the underlying cursor. */
    public Uri getContactLookupUri(int position) {
        final Cursor cursor = (Cursor) getItem(position);
        final long contactId = cursor.getLong(GroupMembersQuery.CONTACT_ID);
        final String lookupKey = cursor.getString(GroupMembersQuery.CONTACT_LOOKUP_KEY);
        return Contacts.getLookupUri(contactId, lookupKey);
    }

    @Override
    public void configureLoader(CursorLoader loader, long directoryId) {
        loader.setUri(Data.CONTENT_URI.buildUpon()
                .appendQueryParameter(ContactsContract.DIRECTORY_PARAM_KEY,
                        String.valueOf(Directory.DEFAULT))
                .build());

        loader.setSelection(Data.MIMETYPE + "=?" + " AND " + GroupMembership.GROUP_ROW_ID + "=?");

        final String[] selectionArgs = new String[2];
        selectionArgs[0] = GroupMembership.CONTENT_ITEM_TYPE;
        selectionArgs[1] = String.valueOf(mGroupId);
        loader.setSelectionArgs(selectionArgs);

        loader.setProjection(
                getContactNameDisplayOrder() == ContactsPreferences.DISPLAY_ORDER_PRIMARY
                        ? GroupMembersQuery.PROJECTION_PRIMARY
                        : GroupMembersQuery.PROJECTION_ALTERNATIVE);

        loader.setSortOrder(
                getSortOrder() == ContactsPreferences.SORT_ORDER_PRIMARY
                        ? Data.DISPLAY_NAME_PRIMARY
                        : Data.DISPLAY_NAME_ALTERNATIVE);
    }

    @Override
    public String getContactDisplayName(int position) {
        return ((Cursor) getItem(position)).getString(GroupMembersQuery.CONTACT_DISPLAY_NAME);
    }

    @Override
    protected ContactListItemView newView(Context context, int partition, Cursor cursor,
            int position, ViewGroup parent) {
        final ContactListItemView view =
                super.newView(context, partition, cursor, position, parent);
        view.setUnknownNameText(mUnknownNameText);
        view.setQuickContactEnabled(isQuickContactEnabled());
        view.setIsSectionHeaderEnabled(isSectionHeaderDisplayEnabled());
        return view;
    }

    @Override
    protected void bindView(View v, int partition, Cursor cursor, int position) {
        super.bindView(v, partition, cursor, position);
        final ContactListItemView view = (ContactListItemView) v;
        bindSectionHeaderAndDivider(view, position);
        bindName(view, cursor);
        bindViewId(view, cursor, GroupMembersQuery.CONTACT_ID);
        bindPhoto(view, cursor);
    }

    private void bindSectionHeaderAndDivider(final ContactListItemView view, int position) {
        final int section = getSectionForPosition(position);
        if (getPositionForSection(section) == position) {
            final String header = (String) getSections()[section];
            view.setSectionHeader(header);
        } else {
            view.setSectionHeader(null);
        }
    }

    private void bindName(ContactListItemView view, Cursor cursor) {
        view.showDisplayName(cursor, GroupMembersQuery.CONTACT_DISPLAY_NAME,
                getContactNameDisplayOrder());
    }

    private void bindPhoto(final ContactListItemView view, Cursor cursor) {
        final long photoId = cursor.isNull(GroupMembersQuery.CONTACT_PHOTO_ID)
                ? 0 : cursor.getLong(GroupMembersQuery.CONTACT_PHOTO_ID);
        final DefaultImageRequest imageRequest = photoId == 0
                ? getDefaultImageRequestFromCursor(cursor, GroupMembersQuery.CONTACT_DISPLAY_NAME,
                        GroupMembersQuery.CONTACT_LOOKUP_KEY)
                : null;
        getPhotoLoader().loadThumbnail(view.getPhotoView(), photoId, false, getCircularPhotos(),
                imageRequest);
    }
}
Loading