Walter Jang | cab3dce | 2015-02-09 17:48:03 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.contacts.editor; |
| 18 | |
Marcus Hagerott | fac695a | 2016-08-24 17:02:40 -0700 | [diff] [blame] | 19 | import com.android.contacts.common.model.account.AccountDisplayInfo; |
| 20 | import com.android.contacts.common.model.account.AccountDisplayInfoFactory; |
Walter Jang | cab3dce | 2015-02-09 17:48:03 -0800 | [diff] [blame] | 21 | import com.android.contacts.R; |
| 22 | import com.android.contacts.common.model.AccountTypeManager; |
| 23 | import com.android.contacts.common.model.RawContactDelta; |
| 24 | import com.android.contacts.common.model.RawContactDeltaList; |
Walter Jang | e720fde | 2015-02-17 10:54:14 -0800 | [diff] [blame] | 25 | import com.android.contacts.common.model.RawContactModifier; |
Walter Jang | cab3dce | 2015-02-09 17:48:03 -0800 | [diff] [blame] | 26 | import com.android.contacts.common.model.ValuesDelta; |
| 27 | import com.android.contacts.common.model.account.AccountType; |
Walter Jang | 2d3f31c | 2015-06-18 23:15:31 -0700 | [diff] [blame] | 28 | import com.android.contacts.common.model.account.AccountWithDataSet; |
Walter Jang | cab3dce | 2015-02-09 17:48:03 -0800 | [diff] [blame] | 29 | import com.android.contacts.common.model.dataitem.DataKind; |
Walter Jang | 708ea9e | 2015-09-10 15:42:05 -0700 | [diff] [blame] | 30 | import com.android.contacts.common.util.AccountsListAdapter; |
Walter Jang | f46abd8 | 2015-02-20 16:52:04 -0800 | [diff] [blame] | 31 | import com.android.contacts.common.util.MaterialColorMapUtils; |
Walter Jang | 708ea9e | 2015-09-10 15:42:05 -0700 | [diff] [blame] | 32 | import com.android.contacts.util.UiClosables; |
Walter Jang | cab3dce | 2015-02-09 17:48:03 -0800 | [diff] [blame] | 33 | |
Marcus Hagerott | cf7f295 | 2016-09-06 13:49:17 -0700 | [diff] [blame] | 34 | import android.animation.LayoutTransition; |
Tingting Wang | 655ad1a | 2015-10-05 17:51:14 -0700 | [diff] [blame] | 35 | import android.content.ContentUris; |
Walter Jang | cab3dce | 2015-02-09 17:48:03 -0800 | [diff] [blame] | 36 | import android.content.Context; |
Walter Jang | f10ca15 | 2015-09-22 15:23:55 -0700 | [diff] [blame] | 37 | import android.database.Cursor; |
Walter Jang | 3efae4a | 2015-02-18 11:12:00 -0800 | [diff] [blame] | 38 | import android.graphics.Bitmap; |
Walter Jang | 41b3ea1 | 2015-03-09 17:30:06 -0700 | [diff] [blame] | 39 | import android.net.Uri; |
Walter Jang | 3f18d61 | 2015-10-07 16:01:05 -0700 | [diff] [blame] | 40 | import android.os.Bundle; |
Walter Jang | 79658e1 | 2015-09-24 10:36:26 -0700 | [diff] [blame] | 41 | import android.os.Parcel; |
| 42 | import android.os.Parcelable; |
Tingting Wang | 655ad1a | 2015-10-05 17:51:14 -0700 | [diff] [blame] | 43 | import android.provider.ContactsContract; |
Walter Jang | cab3dce | 2015-02-09 17:48:03 -0800 | [diff] [blame] | 44 | import android.provider.ContactsContract.CommonDataKinds.Email; |
Walter Jang | f5dfea4 | 2015-09-16 12:30:36 -0700 | [diff] [blame] | 45 | import android.provider.ContactsContract.CommonDataKinds.Event; |
Walter Jang | cab3dce | 2015-02-09 17:48:03 -0800 | [diff] [blame] | 46 | import android.provider.ContactsContract.CommonDataKinds.GroupMembership; |
Walter Jang | f5dfea4 | 2015-09-16 12:30:36 -0700 | [diff] [blame] | 47 | import android.provider.ContactsContract.CommonDataKinds.Im; |
Walter Jang | 3efae4a | 2015-02-18 11:12:00 -0800 | [diff] [blame] | 48 | import android.provider.ContactsContract.CommonDataKinds.Nickname; |
Walter Jang | f5dfea4 | 2015-09-16 12:30:36 -0700 | [diff] [blame] | 49 | import android.provider.ContactsContract.CommonDataKinds.Note; |
| 50 | import android.provider.ContactsContract.CommonDataKinds.Organization; |
Walter Jang | cab3dce | 2015-02-09 17:48:03 -0800 | [diff] [blame] | 51 | import android.provider.ContactsContract.CommonDataKinds.Phone; |
| 52 | import android.provider.ContactsContract.CommonDataKinds.Photo; |
Walter Jang | f5dfea4 | 2015-09-16 12:30:36 -0700 | [diff] [blame] | 53 | import android.provider.ContactsContract.CommonDataKinds.Relation; |
| 54 | import android.provider.ContactsContract.CommonDataKinds.SipAddress; |
Walter Jang | cab3dce | 2015-02-09 17:48:03 -0800 | [diff] [blame] | 55 | import android.provider.ContactsContract.CommonDataKinds.StructuredName; |
Walter Jang | f5dfea4 | 2015-09-16 12:30:36 -0700 | [diff] [blame] | 56 | import android.provider.ContactsContract.CommonDataKinds.StructuredPostal; |
| 57 | import android.provider.ContactsContract.CommonDataKinds.Website; |
Walter Jang | cab3dce | 2015-02-09 17:48:03 -0800 | [diff] [blame] | 58 | import android.text.TextUtils; |
| 59 | import android.util.AttributeSet; |
| 60 | import android.util.Log; |
Walter Jang | 2d3f31c | 2015-06-18 23:15:31 -0700 | [diff] [blame] | 61 | import android.util.Pair; |
Walter Jang | cab3dce | 2015-02-09 17:48:03 -0800 | [diff] [blame] | 62 | import android.view.LayoutInflater; |
Walter Jang | b1c8762 | 2015-02-13 17:51:38 -0800 | [diff] [blame] | 63 | import android.view.View; |
Walter Jang | cab3dce | 2015-02-09 17:48:03 -0800 | [diff] [blame] | 64 | import android.view.ViewGroup; |
Walter Jang | 708ea9e | 2015-09-10 15:42:05 -0700 | [diff] [blame] | 65 | import android.widget.AdapterView; |
Tingting Wang | 655ad1a | 2015-10-05 17:51:14 -0700 | [diff] [blame] | 66 | import android.widget.BaseAdapter; |
| 67 | import android.widget.ImageView; |
Walter Jang | cab3dce | 2015-02-09 17:48:03 -0800 | [diff] [blame] | 68 | import android.widget.LinearLayout; |
Walter Jang | 708ea9e | 2015-09-10 15:42:05 -0700 | [diff] [blame] | 69 | import android.widget.ListPopupWindow; |
Walter Jang | 2d3f31c | 2015-06-18 23:15:31 -0700 | [diff] [blame] | 70 | import android.widget.TextView; |
Walter Jang | cab3dce | 2015-02-09 17:48:03 -0800 | [diff] [blame] | 71 | |
Walter Jang | 708774a | 2015-10-16 09:32:06 -0700 | [diff] [blame] | 72 | import java.io.FileNotFoundException; |
Walter Jang | cab3dce | 2015-02-09 17:48:03 -0800 | [diff] [blame] | 73 | import java.util.ArrayList; |
Walter Jang | f5dfea4 | 2015-09-16 12:30:36 -0700 | [diff] [blame] | 74 | import java.util.Arrays; |
Walter Jang | 192a01c | 2015-09-22 15:23:55 -0700 | [diff] [blame] | 75 | import java.util.Collections; |
Walter Jang | f5dfea4 | 2015-09-16 12:30:36 -0700 | [diff] [blame] | 76 | import java.util.Comparator; |
Walter Jang | 19d985f | 2015-07-01 13:36:27 -0700 | [diff] [blame] | 77 | import java.util.HashMap; |
Walter Jang | cab3dce | 2015-02-09 17:48:03 -0800 | [diff] [blame] | 78 | import java.util.List; |
Walter Jang | 19d985f | 2015-07-01 13:36:27 -0700 | [diff] [blame] | 79 | import java.util.Map; |
Walter Jang | f5dfea4 | 2015-09-16 12:30:36 -0700 | [diff] [blame] | 80 | import java.util.TreeSet; |
Walter Jang | cab3dce | 2015-02-09 17:48:03 -0800 | [diff] [blame] | 81 | |
| 82 | /** |
Walter Jang | f5dfea4 | 2015-09-16 12:30:36 -0700 | [diff] [blame] | 83 | * View to display information from multiple {@link RawContactDelta}s grouped together. |
Walter Jang | cab3dce | 2015-02-09 17:48:03 -0800 | [diff] [blame] | 84 | */ |
Walter Jang | b6ca272 | 2015-02-20 11:10:25 -0800 | [diff] [blame] | 85 | public class CompactRawContactsEditorView extends LinearLayout implements View.OnClickListener { |
Walter Jang | cab3dce | 2015-02-09 17:48:03 -0800 | [diff] [blame] | 86 | |
Walter Jang | 4f5594a | 2015-10-06 18:40:31 -0700 | [diff] [blame] | 87 | static final String TAG = "CompactEditorView"; |
Walter Jang | cab3dce | 2015-02-09 17:48:03 -0800 | [diff] [blame] | 88 | |
Walter Jang | 192a01c | 2015-09-22 15:23:55 -0700 | [diff] [blame] | 89 | private static final KindSectionDataMapEntryComparator |
| 90 | KIND_SECTION_DATA_MAP_ENTRY_COMPARATOR = new KindSectionDataMapEntryComparator(); |
Walter Jang | f5dfea4 | 2015-09-16 12:30:36 -0700 | [diff] [blame] | 91 | |
Walter Jang | b6ca272 | 2015-02-20 11:10:25 -0800 | [diff] [blame] | 92 | /** |
| 93 | * Callbacks for hosts of {@link CompactRawContactsEditorView}s. |
| 94 | */ |
| 95 | public interface Listener { |
| 96 | |
| 97 | /** |
Walter Jang | 151f3e6 | 2015-02-26 15:29:40 -0800 | [diff] [blame] | 98 | * Invoked when the structured name editor field has changed. |
| 99 | * |
| 100 | * @param rawContactId The raw contact ID from the underlying {@link RawContactDelta}. |
| 101 | * @param valuesDelta The values from the underlying {@link RawContactDelta}. |
| 102 | */ |
| 103 | public void onNameFieldChanged(long rawContactId, ValuesDelta valuesDelta); |
Walter Jang | 708ea9e | 2015-09-10 15:42:05 -0700 | [diff] [blame] | 104 | |
| 105 | /** |
| 106 | * Invoked when the compact editor should rebind editors for a new account. |
| 107 | * |
| 108 | * @param oldState Old data being edited. |
| 109 | * @param oldAccount Old account associated with oldState. |
| 110 | * @param newAccount New account to be used. |
| 111 | */ |
| 112 | public void onRebindEditorsForNewContact(RawContactDelta oldState, |
| 113 | AccountWithDataSet oldAccount, AccountWithDataSet newAccount); |
Walter Jang | 79658e1 | 2015-09-24 10:36:26 -0700 | [diff] [blame] | 114 | |
| 115 | /** |
| 116 | * Invoked when no editors could be bound for the contact. |
| 117 | */ |
| 118 | public void onBindEditorsFailed(); |
Walter Jang | d675315 | 2015-10-02 09:23:13 -0700 | [diff] [blame] | 119 | |
| 120 | /** |
| 121 | * Invoked after editors have been bound for the contact. |
| 122 | */ |
| 123 | public void onEditorsBound(); |
Tingting Wang | 655ad1a | 2015-10-05 17:51:14 -0700 | [diff] [blame] | 124 | |
| 125 | /** |
Tingting Wang | 5585c6e | 2015-10-14 11:19:58 -0700 | [diff] [blame] | 126 | * Invoked when a rawcontact from linked contacts is selected in editor. |
Tingting Wang | 655ad1a | 2015-10-05 17:51:14 -0700 | [diff] [blame] | 127 | */ |
Tingting Wang | 91cee28 | 2015-10-07 13:48:17 -0700 | [diff] [blame] | 128 | public void onRawContactSelected(Uri uri, long rawContactId, boolean isReadOnly); |
Walter Jang | 3f18d61 | 2015-10-07 16:01:05 -0700 | [diff] [blame] | 129 | |
| 130 | /** |
| 131 | * Returns the map of raw contact IDs to newly taken or selected photos that have not |
| 132 | * yet been saved to CP2. |
| 133 | */ |
| 134 | public Bundle getUpdatedPhotos(); |
Tingting Wang | 655ad1a | 2015-10-05 17:51:14 -0700 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | /** |
| 138 | * Used to list the account info for the given raw contacts list. |
| 139 | */ |
| 140 | private static final class RawContactAccountListAdapter extends BaseAdapter { |
| 141 | private final LayoutInflater mInflater; |
| 142 | private final Context mContext; |
| 143 | private final RawContactDeltaList mRawContactDeltas; |
| 144 | |
| 145 | public RawContactAccountListAdapter(Context context, RawContactDeltaList rawContactDeltas) { |
| 146 | mContext = context; |
| 147 | mRawContactDeltas = new RawContactDeltaList(); |
| 148 | for (RawContactDelta rawContactDelta : rawContactDeltas) { |
Walter Jang | 2370954 | 2015-10-22 12:50:58 -0700 | [diff] [blame] | 149 | if (rawContactDelta.isVisible() && rawContactDelta.getRawContactId() > 0) { |
Tingting Wang | 655ad1a | 2015-10-05 17:51:14 -0700 | [diff] [blame] | 150 | mRawContactDeltas.add(rawContactDelta); |
| 151 | } |
| 152 | } |
| 153 | mInflater = LayoutInflater.from(context); |
| 154 | } |
| 155 | |
| 156 | @Override |
| 157 | public View getView(int position, View convertView, ViewGroup parent) { |
| 158 | final View resultView = convertView != null ? convertView |
| 159 | : mInflater.inflate(R.layout.account_selector_list_item, parent, false); |
| 160 | |
| 161 | final RawContactDelta rawContactDelta = mRawContactDeltas.get(position); |
Tingting Wang | 655ad1a | 2015-10-05 17:51:14 -0700 | [diff] [blame] | 162 | |
| 163 | final TextView text1 = (TextView) resultView.findViewById(android.R.id.text1); |
Walter Jang | 9488a76 | 2015-10-16 13:42:48 -0700 | [diff] [blame] | 164 | final AccountType accountType = rawContactDelta.getRawContactAccountType(mContext); |
Tingting Wang | 655ad1a | 2015-10-05 17:51:14 -0700 | [diff] [blame] | 165 | text1.setText(accountType.getDisplayLabel(mContext)); |
| 166 | |
Tingting Wang | 655ad1a | 2015-10-05 17:51:14 -0700 | [diff] [blame] | 167 | final TextView text2 = (TextView) resultView.findViewById(android.R.id.text2); |
Walter Jang | 9488a76 | 2015-10-16 13:42:48 -0700 | [diff] [blame] | 168 | final String accountName = rawContactDelta.getAccountName(); |
Tingting Wang | a0b6940 | 2015-10-13 14:27:58 -0700 | [diff] [blame] | 169 | if (TextUtils.isEmpty(accountName)) { |
| 170 | text2.setVisibility(View.GONE); |
| 171 | } else { |
Walter Jang | 9488a76 | 2015-10-16 13:42:48 -0700 | [diff] [blame] | 172 | // Truncate email addresses in the middle so we don't lose the domain |
Tingting Wang | a0b6940 | 2015-10-13 14:27:58 -0700 | [diff] [blame] | 173 | text2.setText(accountName); |
| 174 | text2.setEllipsize(TextUtils.TruncateAt.MIDDLE); |
| 175 | } |
Tingting Wang | 655ad1a | 2015-10-05 17:51:14 -0700 | [diff] [blame] | 176 | |
| 177 | final ImageView icon = (ImageView) resultView.findViewById(android.R.id.icon); |
| 178 | icon.setImageDrawable(accountType.getDisplayIcon(mContext)); |
| 179 | |
| 180 | return resultView; |
| 181 | } |
| 182 | |
| 183 | @Override |
| 184 | public int getCount() { |
| 185 | return mRawContactDeltas.size(); |
| 186 | } |
| 187 | |
| 188 | @Override |
| 189 | public RawContactDelta getItem(int position) { |
| 190 | return mRawContactDeltas.get(position); |
| 191 | } |
| 192 | |
| 193 | @Override |
| 194 | public long getItemId(int position) { |
| 195 | return getItem(position).getRawContactId(); |
| 196 | } |
Walter Jang | 151f3e6 | 2015-02-26 15:29:40 -0800 | [diff] [blame] | 197 | } |
| 198 | |
Walter Jang | 192a01c | 2015-09-22 15:23:55 -0700 | [diff] [blame] | 199 | /** Used to sort entire kind sections. */ |
| 200 | private static final class KindSectionDataMapEntryComparator implements |
Walter Jang | cbd431d | 2015-10-06 13:07:30 -0700 | [diff] [blame] | 201 | Comparator<Map.Entry<String,KindSectionDataList>> { |
Walter Jang | f5dfea4 | 2015-09-16 12:30:36 -0700 | [diff] [blame] | 202 | |
Walter Jang | 192a01c | 2015-09-22 15:23:55 -0700 | [diff] [blame] | 203 | final MimeTypeComparator mMimeTypeComparator = new MimeTypeComparator(); |
| 204 | |
| 205 | @Override |
Walter Jang | cbd431d | 2015-10-06 13:07:30 -0700 | [diff] [blame] | 206 | public int compare(Map.Entry<String, KindSectionDataList> entry1, |
| 207 | Map.Entry<String, KindSectionDataList> entry2) { |
Walter Jang | 192a01c | 2015-09-22 15:23:55 -0700 | [diff] [blame] | 208 | if (entry1 == entry2) return 0; |
| 209 | if (entry1 == null) return -1; |
| 210 | if (entry2 == null) return 1; |
| 211 | |
| 212 | final String mimeType1 = entry1.getKey(); |
| 213 | final String mimeType2 = entry2.getKey(); |
| 214 | |
| 215 | return mMimeTypeComparator.compare(mimeType1, mimeType2); |
| 216 | } |
| 217 | } |
| 218 | |
| 219 | /** |
| 220 | * Sorts kinds roughly the same as quick contacts; we diverge in the following ways: |
| 221 | * <ol> |
| 222 | * <li>All names are together at the top.</li> |
| 223 | * <li>IM is moved up after addresses</li> |
| 224 | * <li>SIP addresses are moved to below phone numbers</li> |
Walter Jang | 79658e1 | 2015-09-24 10:36:26 -0700 | [diff] [blame] | 225 | * <li>Group membership is placed at the end</li> |
Walter Jang | 192a01c | 2015-09-22 15:23:55 -0700 | [diff] [blame] | 226 | * </ol> |
| 227 | */ |
| 228 | private static final class MimeTypeComparator implements Comparator<String> { |
| 229 | |
Walter Jang | f5dfea4 | 2015-09-16 12:30:36 -0700 | [diff] [blame] | 230 | private static final List<String> MIME_TYPE_ORDER = Arrays.asList(new String[] { |
| 231 | StructuredName.CONTENT_ITEM_TYPE, |
Walter Jang | f5dfea4 | 2015-09-16 12:30:36 -0700 | [diff] [blame] | 232 | Nickname.CONTENT_ITEM_TYPE, |
Walter Jang | 2ae2175 | 2015-09-25 11:25:38 -0700 | [diff] [blame] | 233 | Organization.CONTENT_ITEM_TYPE, |
Walter Jang | f5dfea4 | 2015-09-16 12:30:36 -0700 | [diff] [blame] | 234 | Phone.CONTENT_ITEM_TYPE, |
| 235 | SipAddress.CONTENT_ITEM_TYPE, |
| 236 | Email.CONTENT_ITEM_TYPE, |
| 237 | StructuredPostal.CONTENT_ITEM_TYPE, |
| 238 | Im.CONTENT_ITEM_TYPE, |
| 239 | Website.CONTENT_ITEM_TYPE, |
Walter Jang | f5dfea4 | 2015-09-16 12:30:36 -0700 | [diff] [blame] | 240 | Event.CONTENT_ITEM_TYPE, |
| 241 | Relation.CONTENT_ITEM_TYPE, |
Walter Jang | f10ca15 | 2015-09-22 15:23:55 -0700 | [diff] [blame] | 242 | Note.CONTENT_ITEM_TYPE, |
| 243 | GroupMembership.CONTENT_ITEM_TYPE |
Walter Jang | f5dfea4 | 2015-09-16 12:30:36 -0700 | [diff] [blame] | 244 | }); |
| 245 | |
| 246 | @Override |
Walter Jang | 192a01c | 2015-09-22 15:23:55 -0700 | [diff] [blame] | 247 | public int compare(String mimeType1, String mimeType2) { |
| 248 | if (mimeType1 == mimeType2) return 0; |
| 249 | if (mimeType1 == null) return -1; |
| 250 | if (mimeType2 == null) return 1; |
Walter Jang | f5dfea4 | 2015-09-16 12:30:36 -0700 | [diff] [blame] | 251 | |
| 252 | int index1 = MIME_TYPE_ORDER.indexOf(mimeType1); |
| 253 | int index2 = MIME_TYPE_ORDER.indexOf(mimeType2); |
| 254 | |
| 255 | // Fallback to alphabetical ordering of the mime type if both are not found |
| 256 | if (index1 < 0 && index2 < 0) return mimeType1.compareTo(mimeType2); |
| 257 | if (index1 < 0) return 1; |
| 258 | if (index2 < 0) return -1; |
| 259 | |
| 260 | return index1 < index2 ? -1 : 1; |
| 261 | } |
| 262 | } |
| 263 | |
Walter Jang | 192a01c | 2015-09-22 15:23:55 -0700 | [diff] [blame] | 264 | /** |
| 265 | * Sorts primary accounts and google account types before others. |
| 266 | */ |
| 267 | private static final class EditorComparator implements Comparator<KindSectionData> { |
| 268 | |
| 269 | private RawContactDeltaComparator mRawContactDeltaComparator; |
| 270 | |
| 271 | private EditorComparator(Context context) { |
| 272 | mRawContactDeltaComparator = new RawContactDeltaComparator(context); |
| 273 | } |
| 274 | |
| 275 | @Override |
| 276 | public int compare(KindSectionData kindSectionData1, KindSectionData kindSectionData2) { |
| 277 | if (kindSectionData1 == kindSectionData2) return 0; |
| 278 | if (kindSectionData1 == null) return -1; |
| 279 | if (kindSectionData2 == null) return 1; |
| 280 | |
| 281 | final RawContactDelta rawContactDelta1 = kindSectionData1.getRawContactDelta(); |
| 282 | final RawContactDelta rawContactDelta2 = kindSectionData2.getRawContactDelta(); |
| 283 | |
| 284 | if (rawContactDelta1 == rawContactDelta2) return 0; |
| 285 | if (rawContactDelta1 == null) return -1; |
| 286 | if (rawContactDelta2 == null) return 1; |
| 287 | |
| 288 | return mRawContactDeltaComparator.compare(rawContactDelta1, rawContactDelta2); |
| 289 | } |
| 290 | } |
| 291 | |
Walter Jang | 79658e1 | 2015-09-24 10:36:26 -0700 | [diff] [blame] | 292 | public static class SavedState extends BaseSavedState { |
| 293 | |
| 294 | public static final Parcelable.Creator<SavedState> CREATOR = |
| 295 | new Parcelable.Creator<SavedState>() { |
| 296 | public SavedState createFromParcel(Parcel in) { |
| 297 | return new SavedState(in); |
| 298 | } |
| 299 | public SavedState[] newArray(int size) { |
| 300 | return new SavedState[size]; |
| 301 | } |
| 302 | }; |
| 303 | |
| 304 | private boolean mIsExpanded; |
| 305 | |
| 306 | public SavedState(Parcelable superState) { |
| 307 | super(superState); |
| 308 | } |
| 309 | |
| 310 | private SavedState(Parcel in) { |
| 311 | super(in); |
| 312 | mIsExpanded = in.readInt() != 0; |
| 313 | } |
| 314 | |
| 315 | @Override |
| 316 | public void writeToParcel(Parcel out, int flags) { |
| 317 | super.writeToParcel(out, flags); |
| 318 | out.writeInt(mIsExpanded ? 1 : 0); |
| 319 | } |
| 320 | } |
| 321 | |
Walter Jang | 3e5ae0d | 2015-09-20 12:43:37 -0700 | [diff] [blame] | 322 | private CompactRawContactsEditorView.Listener mListener; |
Walter Jang | b6ca272 | 2015-02-20 11:10:25 -0800 | [diff] [blame] | 323 | |
Walter Jang | cab3dce | 2015-02-09 17:48:03 -0800 | [diff] [blame] | 324 | private AccountTypeManager mAccountTypeManager; |
Marcus Hagerott | fac695a | 2016-08-24 17:02:40 -0700 | [diff] [blame] | 325 | private AccountDisplayInfoFactory mAccountDisplayInfoFactory; |
Walter Jang | cab3dce | 2015-02-09 17:48:03 -0800 | [diff] [blame] | 326 | private LayoutInflater mLayoutInflater; |
Walter Jang | d35e5ef | 2015-02-24 09:18:16 -0800 | [diff] [blame] | 327 | |
Walter Jang | cab3dce | 2015-02-09 17:48:03 -0800 | [diff] [blame] | 328 | private ViewIdGenerator mViewIdGenerator; |
Walter Jang | f46abd8 | 2015-02-20 16:52:04 -0800 | [diff] [blame] | 329 | private MaterialColorMapUtils.MaterialPalette mMaterialPalette; |
Walter Jang | 82acd42 | 2015-10-17 14:01:27 -0700 | [diff] [blame] | 330 | private long mPhotoId = -1; |
Walter Jang | 708ea9e | 2015-09-10 15:42:05 -0700 | [diff] [blame] | 331 | private boolean mHasNewContact; |
| 332 | private boolean mIsUserProfile; |
| 333 | private AccountWithDataSet mPrimaryAccount; |
Walter Jang | 9a55237 | 2016-08-24 11:51:05 -0700 | [diff] [blame] | 334 | private RawContactDeltaList mRawContactDeltas; |
| 335 | private long mRawContactIdToDisplayAlone = -1; |
| 336 | private boolean mRawContactDisplayAloneIsReadOnly; |
| 337 | private boolean mIsEditingReadOnlyRawContactWithNewContact; |
Walter Jang | cbd431d | 2015-10-06 13:07:30 -0700 | [diff] [blame] | 338 | private Map<String,KindSectionDataList> mKindSectionDataMap = new HashMap<>(); |
Walter Jang | cab3dce | 2015-02-09 17:48:03 -0800 | [diff] [blame] | 339 | |
Walter Jang | 708ea9e | 2015-09-10 15:42:05 -0700 | [diff] [blame] | 340 | // Account header |
| 341 | private View mAccountHeaderContainer; |
| 342 | private TextView mAccountHeaderType; |
| 343 | private TextView mAccountHeaderName; |
Tingting Wang | 91cee28 | 2015-10-07 13:48:17 -0700 | [diff] [blame] | 344 | private ImageView mAccountHeaderIcon; |
Gary Mai | 46cb310 | 2016-08-10 18:14:09 -0700 | [diff] [blame] | 345 | private ImageView mAccountHeaderExpanderIcon; |
Walter Jang | 708ea9e | 2015-09-10 15:42:05 -0700 | [diff] [blame] | 346 | |
Tingting Wang | 655ad1a | 2015-10-05 17:51:14 -0700 | [diff] [blame] | 347 | // Raw contacts selector |
| 348 | private View mRawContactContainer; |
| 349 | private TextView mRawContactSummary; |
Tingting Wang | 655ad1a | 2015-10-05 17:51:14 -0700 | [diff] [blame] | 350 | |
Walter Jang | 3e5ae0d | 2015-09-20 12:43:37 -0700 | [diff] [blame] | 351 | private CompactPhotoEditorView mPhotoView; |
Walter Jang | f5dfea4 | 2015-09-16 12:30:36 -0700 | [diff] [blame] | 352 | private ViewGroup mKindSectionViews; |
Walter Jang | f10ca15 | 2015-09-22 15:23:55 -0700 | [diff] [blame] | 353 | private Map<String,List<CompactKindSectionView>> mKindSectionViewsMap = new HashMap<>(); |
Walter Jang | b6ca272 | 2015-02-20 11:10:25 -0800 | [diff] [blame] | 354 | private View mMoreFields; |
Walter Jang | cab3dce | 2015-02-09 17:48:03 -0800 | [diff] [blame] | 355 | |
Walter Jang | 79658e1 | 2015-09-24 10:36:26 -0700 | [diff] [blame] | 356 | private boolean mIsExpanded; |
Walter Jang | cbd431d | 2015-10-06 13:07:30 -0700 | [diff] [blame] | 357 | |
Walter Jang | 3efae4a | 2015-02-18 11:12:00 -0800 | [diff] [blame] | 358 | private long mPhotoRawContactId; |
Walter Jang | 31a74ad | 2015-10-02 19:17:39 -0700 | [diff] [blame] | 359 | private ValuesDelta mPhotoValuesDelta; |
Walter Jang | 82acd42 | 2015-10-17 14:01:27 -0700 | [diff] [blame] | 360 | |
| 361 | private Pair<KindSectionData, ValuesDelta> mPrimaryNameKindSectionData; |
Walter Jang | 3efae4a | 2015-02-18 11:12:00 -0800 | [diff] [blame] | 362 | |
Walter Jang | cab3dce | 2015-02-09 17:48:03 -0800 | [diff] [blame] | 363 | public CompactRawContactsEditorView(Context context) { |
| 364 | super(context); |
| 365 | } |
| 366 | |
| 367 | public CompactRawContactsEditorView(Context context, AttributeSet attrs) { |
| 368 | super(context, attrs); |
| 369 | } |
| 370 | |
Walter Jang | b6ca272 | 2015-02-20 11:10:25 -0800 | [diff] [blame] | 371 | /** |
| 372 | * Sets the receiver for {@link CompactRawContactsEditorView} callbacks. |
| 373 | */ |
| 374 | public void setListener(Listener listener) { |
| 375 | mListener = listener; |
| 376 | } |
| 377 | |
Walter Jang | cab3dce | 2015-02-09 17:48:03 -0800 | [diff] [blame] | 378 | @Override |
| 379 | protected void onFinishInflate() { |
| 380 | super.onFinishInflate(); |
| 381 | |
| 382 | mAccountTypeManager = AccountTypeManager.getInstance(getContext()); |
Marcus Hagerott | fac695a | 2016-08-24 17:02:40 -0700 | [diff] [blame] | 383 | mAccountDisplayInfoFactory = AccountDisplayInfoFactory.forWritableAccounts(getContext()); |
Walter Jang | cab3dce | 2015-02-09 17:48:03 -0800 | [diff] [blame] | 384 | mLayoutInflater = (LayoutInflater) |
| 385 | getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); |
| 386 | |
Walter Jang | 708ea9e | 2015-09-10 15:42:05 -0700 | [diff] [blame] | 387 | // Account header |
Gary Mai | 46cb310 | 2016-08-10 18:14:09 -0700 | [diff] [blame] | 388 | mAccountHeaderContainer = findViewById(R.id.account_header_container); |
Walter Jang | 708ea9e | 2015-09-10 15:42:05 -0700 | [diff] [blame] | 389 | mAccountHeaderType = (TextView) findViewById(R.id.account_type); |
| 390 | mAccountHeaderName = (TextView) findViewById(R.id.account_name); |
Tingting Wang | 91cee28 | 2015-10-07 13:48:17 -0700 | [diff] [blame] | 391 | mAccountHeaderIcon = (ImageView) findViewById(R.id.account_type_icon); |
Gary Mai | 46cb310 | 2016-08-10 18:14:09 -0700 | [diff] [blame] | 392 | mAccountHeaderExpanderIcon = (ImageView) findViewById(R.id.account_expander_icon); |
Walter Jang | 708ea9e | 2015-09-10 15:42:05 -0700 | [diff] [blame] | 393 | |
Tingting Wang | 655ad1a | 2015-10-05 17:51:14 -0700 | [diff] [blame] | 394 | // Raw contacts selector |
| 395 | mRawContactContainer = findViewById(R.id.all_rawcontacts_accounts_container); |
| 396 | mRawContactSummary = (TextView) findViewById(R.id.rawcontacts_accounts_summary); |
Tingting Wang | 655ad1a | 2015-10-05 17:51:14 -0700 | [diff] [blame] | 397 | |
Walter Jang | 3e5ae0d | 2015-09-20 12:43:37 -0700 | [diff] [blame] | 398 | mPhotoView = (CompactPhotoEditorView) findViewById(R.id.photo_editor); |
Walter Jang | f5dfea4 | 2015-09-16 12:30:36 -0700 | [diff] [blame] | 399 | mKindSectionViews = (LinearLayout) findViewById(R.id.kind_section_views); |
Walter Jang | b6ca272 | 2015-02-20 11:10:25 -0800 | [diff] [blame] | 400 | mMoreFields = findViewById(R.id.more_fields); |
| 401 | mMoreFields.setOnClickListener(this); |
| 402 | } |
| 403 | |
Walter Jang | b6ca272 | 2015-02-20 11:10:25 -0800 | [diff] [blame] | 404 | @Override |
| 405 | public void onClick(View view) { |
Walter Jang | f5dfea4 | 2015-09-16 12:30:36 -0700 | [diff] [blame] | 406 | if (view.getId() == R.id.more_fields) { |
Walter Jang | d675315 | 2015-10-02 09:23:13 -0700 | [diff] [blame] | 407 | showAllFields(); |
Walter Jang | b6ca272 | 2015-02-20 11:10:25 -0800 | [diff] [blame] | 408 | } |
Walter Jang | cab3dce | 2015-02-09 17:48:03 -0800 | [diff] [blame] | 409 | } |
| 410 | |
| 411 | @Override |
| 412 | public void setEnabled(boolean enabled) { |
| 413 | super.setEnabled(enabled); |
Walter Jang | 3e5ae0d | 2015-09-20 12:43:37 -0700 | [diff] [blame] | 414 | final int childCount = mKindSectionViews.getChildCount(); |
| 415 | for (int i = 0; i < childCount; i++) { |
| 416 | mKindSectionViews.getChildAt(i).setEnabled(enabled); |
Walter Jang | cab3dce | 2015-02-09 17:48:03 -0800 | [diff] [blame] | 417 | } |
| 418 | } |
| 419 | |
Walter Jang | 79658e1 | 2015-09-24 10:36:26 -0700 | [diff] [blame] | 420 | @Override |
| 421 | public Parcelable onSaveInstanceState() { |
| 422 | final Parcelable superState = super.onSaveInstanceState(); |
| 423 | final SavedState savedState = new SavedState(superState); |
| 424 | savedState.mIsExpanded = mIsExpanded; |
| 425 | return savedState; |
| 426 | } |
| 427 | |
| 428 | @Override |
| 429 | public void onRestoreInstanceState(Parcelable state) { |
| 430 | if(!(state instanceof SavedState)) { |
| 431 | super.onRestoreInstanceState(state); |
| 432 | return; |
| 433 | } |
| 434 | final SavedState savedState = (SavedState) state; |
| 435 | super.onRestoreInstanceState(savedState.getSuperState()); |
| 436 | mIsExpanded = savedState.mIsExpanded; |
Walter Jang | d675315 | 2015-10-02 09:23:13 -0700 | [diff] [blame] | 437 | if (mIsExpanded) { |
| 438 | showAllFields(); |
Walter Jang | 79658e1 | 2015-09-24 10:36:26 -0700 | [diff] [blame] | 439 | } |
| 440 | } |
| 441 | |
Walter Jang | 3efae4a | 2015-02-18 11:12:00 -0800 | [diff] [blame] | 442 | /** |
Walter Jang | 31a74ad | 2015-10-02 19:17:39 -0700 | [diff] [blame] | 443 | * Pass through to {@link CompactPhotoEditorView#setListener}. |
Walter Jang | 3efae4a | 2015-02-18 11:12:00 -0800 | [diff] [blame] | 444 | */ |
Walter Jang | 31a74ad | 2015-10-02 19:17:39 -0700 | [diff] [blame] | 445 | public void setPhotoListener(CompactPhotoEditorView.Listener listener) { |
| 446 | mPhotoView.setListener(listener); |
Walter Jang | 3efae4a | 2015-02-18 11:12:00 -0800 | [diff] [blame] | 447 | } |
| 448 | |
Walter Jang | 31a74ad | 2015-10-02 19:17:39 -0700 | [diff] [blame] | 449 | public void removePhoto() { |
Walter Jang | 45b86d5 | 2015-10-15 15:23:16 -0700 | [diff] [blame] | 450 | mPhotoValuesDelta.setFromTemplate(true); |
Walter Jang | 31a74ad | 2015-10-02 19:17:39 -0700 | [diff] [blame] | 451 | mPhotoValuesDelta.put(Photo.PHOTO, (byte[]) null); |
| 452 | |
| 453 | mPhotoView.removePhoto(); |
Walter Jang | 3efae4a | 2015-02-18 11:12:00 -0800 | [diff] [blame] | 454 | } |
| 455 | |
| 456 | /** |
Walter Jang | 41b3ea1 | 2015-03-09 17:30:06 -0700 | [diff] [blame] | 457 | * Pass through to {@link CompactPhotoEditorView#setFullSizedPhoto(Uri)}. |
| 458 | */ |
| 459 | public void setFullSizePhoto(Uri photoUri) { |
Walter Jang | 3e5ae0d | 2015-09-20 12:43:37 -0700 | [diff] [blame] | 460 | mPhotoView.setFullSizedPhoto(photoUri); |
Walter Jang | 41b3ea1 | 2015-03-09 17:30:06 -0700 | [diff] [blame] | 461 | } |
| 462 | |
Walter Jang | 31a74ad | 2015-10-02 19:17:39 -0700 | [diff] [blame] | 463 | public void updatePhoto(Uri photoUri) { |
Walter Jang | 45b86d5 | 2015-10-15 15:23:16 -0700 | [diff] [blame] | 464 | mPhotoValuesDelta.setFromTemplate(false); |
Wenyi Wang | b8ab861 | 2015-10-27 11:18:49 -0700 | [diff] [blame] | 465 | // Unset primary for all photos |
Wenyi Wang | 9086fb9 | 2015-11-16 09:58:20 -0800 | [diff] [blame] | 466 | unsetSuperPrimaryFromAllPhotos(); |
Wenyi Wang | b8ab861 | 2015-10-27 11:18:49 -0700 | [diff] [blame] | 467 | // Mark the currently displayed photo as primary |
| 468 | mPhotoValuesDelta.setSuperPrimary(true); |
Walter Jang | 31a74ad | 2015-10-02 19:17:39 -0700 | [diff] [blame] | 469 | |
Wenyi Wang | 4c9cf3a | 2015-10-15 17:58:23 -0700 | [diff] [blame] | 470 | // Even though high-res photos cannot be saved by passing them via |
| 471 | // an EntityDeltaList (since they cause the Bundle size limit to be |
| 472 | // exceeded), we still pass a low-res thumbnail. This simplifies |
| 473 | // code all over the place, because we don't have to test whether |
| 474 | // there is a change in EITHER the delta-list OR a changed photo... |
| 475 | // this way, there is always a change in the delta-list. |
| 476 | try { |
| 477 | final byte[] bytes = EditorUiUtils.getCompressedThumbnailBitmapBytes( |
| 478 | getContext(), photoUri); |
| 479 | if (bytes != null) { |
| 480 | mPhotoValuesDelta.setPhoto(bytes); |
| 481 | } |
| 482 | } catch (FileNotFoundException e) { |
| 483 | elog("Failed to get bitmap from photo Uri"); |
| 484 | } |
| 485 | |
Walter Jang | 31a74ad | 2015-10-02 19:17:39 -0700 | [diff] [blame] | 486 | mPhotoView.setFullSizedPhoto(photoUri); |
| 487 | } |
| 488 | |
Wenyi Wang | 9086fb9 | 2015-11-16 09:58:20 -0800 | [diff] [blame] | 489 | private void unsetSuperPrimaryFromAllPhotos() { |
Walter Jang | 3f18d61 | 2015-10-07 16:01:05 -0700 | [diff] [blame] | 490 | final List<KindSectionData> kindSectionDataList = |
| 491 | mKindSectionDataMap.get(Photo.CONTENT_ITEM_TYPE); |
| 492 | for (KindSectionData kindSectionData : kindSectionDataList) { |
Wenyi Wang | 9086fb9 | 2015-11-16 09:58:20 -0800 | [diff] [blame] | 493 | for (ValuesDelta valuesDelta : kindSectionData.getNonEmptyValuesDeltas()) { |
| 494 | valuesDelta.setSuperPrimary(false); |
Walter Jang | 3f18d61 | 2015-10-07 16:01:05 -0700 | [diff] [blame] | 495 | } |
| 496 | } |
| 497 | } |
| 498 | |
Walter Jang | 41b3ea1 | 2015-03-09 17:30:06 -0700 | [diff] [blame] | 499 | /** |
Walter Jang | a5e4bb2 | 2015-02-24 13:08:16 -0800 | [diff] [blame] | 500 | * Pass through to {@link CompactPhotoEditorView#isWritablePhotoSet}. |
Walter Jang | 3efae4a | 2015-02-18 11:12:00 -0800 | [diff] [blame] | 501 | */ |
| 502 | public boolean isWritablePhotoSet() { |
Walter Jang | 3e5ae0d | 2015-09-20 12:43:37 -0700 | [diff] [blame] | 503 | return mPhotoView.isWritablePhotoSet(); |
Walter Jang | 3efae4a | 2015-02-18 11:12:00 -0800 | [diff] [blame] | 504 | } |
| 505 | |
| 506 | /** |
Walter Jang | 3efae4a | 2015-02-18 11:12:00 -0800 | [diff] [blame] | 507 | * Get the raw contact ID for the CompactHeaderView photo. |
| 508 | */ |
Walter Jang | 3efae4a | 2015-02-18 11:12:00 -0800 | [diff] [blame] | 509 | public long getPhotoRawContactId() { |
| 510 | return mPhotoRawContactId; |
| 511 | } |
| 512 | |
Walter Jang | 4f5594a | 2015-10-06 18:40:31 -0700 | [diff] [blame] | 513 | public StructuredNameEditorView getPrimaryNameEditorView() { |
Walter Jang | e394595 | 2015-10-27 12:44:54 -0700 | [diff] [blame] | 514 | final CompactKindSectionView primaryNameKindSectionView = getPrimaryNameKindSectionView(); |
| 515 | return primaryNameKindSectionView == null |
| 516 | ? null : primaryNameKindSectionView.getPrimaryNameEditorView(); |
Walter Jang | 4f5594a | 2015-10-06 18:40:31 -0700 | [diff] [blame] | 517 | } |
| 518 | |
Walter Jang | 31a74ad | 2015-10-02 19:17:39 -0700 | [diff] [blame] | 519 | /** |
| 520 | * Returns a data holder for every non-default/non-empty photo from each raw contact, whether |
| 521 | * the raw contact is writable or not. |
| 522 | */ |
| 523 | public ArrayList<CompactPhotoSelectionFragment.Photo> getPhotos() { |
| 524 | final ArrayList<CompactPhotoSelectionFragment.Photo> photos = new ArrayList<>(); |
| 525 | |
Walter Jang | 3f18d61 | 2015-10-07 16:01:05 -0700 | [diff] [blame] | 526 | final Bundle updatedPhotos = mListener == null ? null : mListener.getUpdatedPhotos(); |
| 527 | |
Walter Jang | 31a74ad | 2015-10-02 19:17:39 -0700 | [diff] [blame] | 528 | final List<KindSectionData> kindSectionDataList = |
| 529 | mKindSectionDataMap.get(Photo.CONTENT_ITEM_TYPE); |
| 530 | for (int i = 0; i < kindSectionDataList.size(); i++) { |
| 531 | final KindSectionData kindSectionData = kindSectionDataList.get(i); |
| 532 | final AccountType accountType = kindSectionData.getAccountType(); |
Walter Jang | 228e02f | 2015-11-13 09:11:01 -0800 | [diff] [blame] | 533 | final List<ValuesDelta> valuesDeltas = kindSectionData.getNonEmptyValuesDeltas(); |
| 534 | if (valuesDeltas.isEmpty()) continue; |
| 535 | for (int j = 0; j < valuesDeltas.size(); j++) { |
| 536 | final ValuesDelta valuesDelta = valuesDeltas.get(j); |
Walter Jang | 31a74ad | 2015-10-02 19:17:39 -0700 | [diff] [blame] | 537 | final Bitmap bitmap = EditorUiUtils.getPhotoBitmap(valuesDelta); |
| 538 | if (bitmap == null) continue; |
| 539 | |
| 540 | final CompactPhotoSelectionFragment.Photo photo = |
| 541 | new CompactPhotoSelectionFragment.Photo(); |
| 542 | photo.titleRes = accountType.titleRes; |
| 543 | photo.iconRes = accountType.iconRes; |
| 544 | photo.syncAdapterPackageName = accountType.syncAdapterPackageName; |
| 545 | photo.valuesDelta = valuesDelta; |
| 546 | photo.primary = valuesDelta.isSuperPrimary(); |
| 547 | photo.kindSectionDataListIndex = i; |
| 548 | photo.valuesDeltaListIndex = j; |
Walter Jang | da258ff | 2015-11-17 11:06:02 -0800 | [diff] [blame] | 549 | photo.photoId = valuesDelta.getId(); |
Walter Jang | 3f18d61 | 2015-10-07 16:01:05 -0700 | [diff] [blame] | 550 | |
| 551 | if (updatedPhotos != null) { |
| 552 | photo.updatedPhotoUri = (Uri) updatedPhotos.get(String.valueOf( |
| 553 | kindSectionData.getRawContactDelta().getRawContactId())); |
| 554 | } |
| 555 | |
Wenyi Wang | d375c35 | 2016-03-28 15:12:45 -0700 | [diff] [blame] | 556 | final CharSequence accountTypeLabel = accountType.getDisplayLabel(getContext()); |
| 557 | photo.accountType = accountTypeLabel == null ? "" : accountTypeLabel.toString(); |
| 558 | final String accountName = kindSectionData.getRawContactDelta().getAccountName(); |
| 559 | photo.accountName = accountName == null ? "" : accountName; |
Wenyi Wang | ab36017 | 2015-12-15 10:35:58 -0800 | [diff] [blame] | 560 | |
Walter Jang | 31a74ad | 2015-10-02 19:17:39 -0700 | [diff] [blame] | 561 | photos.add(photo); |
| 562 | } |
| 563 | } |
| 564 | |
| 565 | return photos; |
| 566 | } |
| 567 | |
| 568 | /** |
| 569 | * Marks the raw contact photo given as primary for the aggregate contact and updates the |
| 570 | * UI. |
| 571 | */ |
| 572 | public void setPrimaryPhoto(CompactPhotoSelectionFragment.Photo photo) { |
Walter Jang | 31a74ad | 2015-10-02 19:17:39 -0700 | [diff] [blame] | 573 | // Find the values delta to mark as primary |
Walter Jang | 3f18d61 | 2015-10-07 16:01:05 -0700 | [diff] [blame] | 574 | final KindSectionDataList kindSectionDataList = |
| 575 | mKindSectionDataMap.get(Photo.CONTENT_ITEM_TYPE); |
Walter Jang | 31a74ad | 2015-10-02 19:17:39 -0700 | [diff] [blame] | 576 | if (photo.kindSectionDataListIndex < 0 |
| 577 | || photo.kindSectionDataListIndex >= kindSectionDataList.size()) { |
| 578 | wlog("Invalid kind section data list index"); |
| 579 | return; |
| 580 | } |
| 581 | final KindSectionData kindSectionData = |
| 582 | kindSectionDataList.get(photo.kindSectionDataListIndex); |
Walter Jang | 228e02f | 2015-11-13 09:11:01 -0800 | [diff] [blame] | 583 | final List<ValuesDelta> valuesDeltaList = kindSectionData.getNonEmptyValuesDeltas(); |
Walter Jang | 31a74ad | 2015-10-02 19:17:39 -0700 | [diff] [blame] | 584 | if (photo.valuesDeltaListIndex >= valuesDeltaList.size()) { |
| 585 | wlog("Invalid values delta list index"); |
| 586 | return; |
| 587 | } |
Walter Jang | da258ff | 2015-11-17 11:06:02 -0800 | [diff] [blame] | 588 | |
| 589 | // Update values delta |
Walter Jang | 31a74ad | 2015-10-02 19:17:39 -0700 | [diff] [blame] | 590 | final ValuesDelta valuesDelta = valuesDeltaList.get(photo.valuesDeltaListIndex); |
| 591 | valuesDelta.setFromTemplate(false); |
Wenyi Wang | 9086fb9 | 2015-11-16 09:58:20 -0800 | [diff] [blame] | 592 | unsetSuperPrimaryFromAllPhotos(); |
Wenyi Wang | b8ab861 | 2015-10-27 11:18:49 -0700 | [diff] [blame] | 593 | valuesDelta.setSuperPrimary(true); |
Walter Jang | da258ff | 2015-11-17 11:06:02 -0800 | [diff] [blame] | 594 | |
Walter Jang | 31a74ad | 2015-10-02 19:17:39 -0700 | [diff] [blame] | 595 | // Update the UI |
| 596 | mPhotoView.setPhoto(valuesDelta, mMaterialPalette); |
| 597 | } |
| 598 | |
Walter Jang | d35e5ef | 2015-02-24 09:18:16 -0800 | [diff] [blame] | 599 | public View getAggregationAnchorView() { |
Walter Jang | f10ca15 | 2015-09-22 15:23:55 -0700 | [diff] [blame] | 600 | final List<CompactKindSectionView> kindSectionViews = getKindSectionViews( |
Walter Jang | 192a01c | 2015-09-22 15:23:55 -0700 | [diff] [blame] | 601 | StructuredName.CONTENT_ITEM_TYPE); |
Walter Jang | f10ca15 | 2015-09-22 15:23:55 -0700 | [diff] [blame] | 602 | if (!kindSectionViews.isEmpty()) { |
Walter Jang | 192a01c | 2015-09-22 15:23:55 -0700 | [diff] [blame] | 603 | return mKindSectionViews.getChildAt(0).findViewById(R.id.anchor_view); |
Walter Jang | d35e5ef | 2015-02-24 09:18:16 -0800 | [diff] [blame] | 604 | } |
Walter Jang | 3e5ae0d | 2015-09-20 12:43:37 -0700 | [diff] [blame] | 605 | return null; |
Walter Jang | d35e5ef | 2015-02-24 09:18:16 -0800 | [diff] [blame] | 606 | } |
| 607 | |
Walter Jang | f10ca15 | 2015-09-22 15:23:55 -0700 | [diff] [blame] | 608 | public void setGroupMetaData(Cursor groupMetaData) { |
| 609 | final List<CompactKindSectionView> kindSectionViews = getKindSectionViews( |
| 610 | GroupMembership.CONTENT_ITEM_TYPE); |
| 611 | for (CompactKindSectionView kindSectionView : kindSectionViews) { |
| 612 | kindSectionView.setGroupMetaData(groupMetaData); |
Walter Jang | d675315 | 2015-10-02 09:23:13 -0700 | [diff] [blame] | 613 | if (mIsExpanded) { |
| 614 | kindSectionView.setHideWhenEmpty(false); |
| 615 | kindSectionView.updateEmptyEditors(/* shouldAnimate =*/ true); |
| 616 | } |
Walter Jang | f10ca15 | 2015-09-22 15:23:55 -0700 | [diff] [blame] | 617 | } |
| 618 | } |
| 619 | |
Walter Jang | f46abd8 | 2015-02-20 16:52:04 -0800 | [diff] [blame] | 620 | public void setState(RawContactDeltaList rawContactDeltas, |
Walter Jang | 06f73a1 | 2015-06-17 11:15:48 -0700 | [diff] [blame] | 621 | MaterialColorMapUtils.MaterialPalette materialPalette, ViewIdGenerator viewIdGenerator, |
Walter Jang | e394595 | 2015-10-27 12:44:54 -0700 | [diff] [blame] | 622 | long photoId, boolean hasNewContact, boolean isUserProfile, |
Walter Jang | 9a55237 | 2016-08-24 11:51:05 -0700 | [diff] [blame] | 623 | AccountWithDataSet primaryAccount, long rawContactIdToDisplayAlone, |
| 624 | boolean rawContactDisplayAloneIsReadOnly, |
| 625 | boolean isEditingReadOnlyRawContactWithNewContact) { |
Marcus Hagerott | cf7f295 | 2016-09-06 13:49:17 -0700 | [diff] [blame] | 626 | // Enable layout animations for new contacts. This looks nicer when switching to and from |
| 627 | // an account that doesn't support profile photos (e.g. SIM accounts). |
| 628 | if (hasNewContact && getLayoutTransition() == null) { |
| 629 | setLayoutTransition(new LayoutTransition()); |
| 630 | } |
Marcus Hagerott | f04c975 | 2016-09-08 15:22:57 -0700 | [diff] [blame^] | 631 | |
Walter Jang | 9a55237 | 2016-08-24 11:51:05 -0700 | [diff] [blame] | 632 | mRawContactDeltas = rawContactDeltas; |
| 633 | mRawContactIdToDisplayAlone = rawContactIdToDisplayAlone; |
| 634 | mRawContactDisplayAloneIsReadOnly = rawContactDisplayAloneIsReadOnly; |
| 635 | mIsEditingReadOnlyRawContactWithNewContact = isEditingReadOnlyRawContactWithNewContact; |
| 636 | |
Walter Jang | 363d3fd | 2015-09-16 10:29:07 -0700 | [diff] [blame] | 637 | mKindSectionDataMap.clear(); |
Marcus Hagerott | cf7f295 | 2016-09-06 13:49:17 -0700 | [diff] [blame] | 638 | mKindSectionViewsMap.clear(); |
Walter Jang | f5dfea4 | 2015-09-16 12:30:36 -0700 | [diff] [blame] | 639 | mKindSectionViews.removeAllViews(); |
Walter Jang | 363d3fd | 2015-09-16 10:29:07 -0700 | [diff] [blame] | 640 | mMoreFields.setVisibility(View.VISIBLE); |
Walter Jang | cab3dce | 2015-02-09 17:48:03 -0800 | [diff] [blame] | 641 | |
Walter Jang | f46abd8 | 2015-02-20 16:52:04 -0800 | [diff] [blame] | 642 | mMaterialPalette = materialPalette; |
Walter Jang | 3e5ae0d | 2015-09-20 12:43:37 -0700 | [diff] [blame] | 643 | mViewIdGenerator = viewIdGenerator; |
Walter Jang | 708ea9e | 2015-09-10 15:42:05 -0700 | [diff] [blame] | 644 | mPhotoId = photoId; |
Tingting Wang | f695eb3 | 2015-10-15 18:45:15 -0700 | [diff] [blame] | 645 | |
Walter Jang | 708ea9e | 2015-09-10 15:42:05 -0700 | [diff] [blame] | 646 | mHasNewContact = hasNewContact; |
| 647 | mIsUserProfile = isUserProfile; |
| 648 | mPrimaryAccount = primaryAccount; |
| 649 | if (mPrimaryAccount == null) { |
| 650 | mPrimaryAccount = ContactEditorUtils.getInstance(getContext()).getDefaultAccount(); |
| 651 | } |
| 652 | vlog("state: primary " + mPrimaryAccount); |
Walter Jang | cab3dce | 2015-02-09 17:48:03 -0800 | [diff] [blame] | 653 | |
Walter Jang | 3e5ae0d | 2015-09-20 12:43:37 -0700 | [diff] [blame] | 654 | // Parse the given raw contact deltas |
| 655 | if (rawContactDeltas == null || rawContactDeltas.isEmpty()) { |
| 656 | elog("No raw contact deltas"); |
Walter Jang | 79658e1 | 2015-09-24 10:36:26 -0700 | [diff] [blame] | 657 | if (mListener != null) mListener.onBindEditorsFailed(); |
Walter Jang | f5dfea4 | 2015-09-16 12:30:36 -0700 | [diff] [blame] | 658 | return; |
| 659 | } |
Walter Jang | cbd431d | 2015-10-06 13:07:30 -0700 | [diff] [blame] | 660 | parseRawContactDeltas(rawContactDeltas); |
Walter Jang | 79658e1 | 2015-09-24 10:36:26 -0700 | [diff] [blame] | 661 | if (mKindSectionDataMap.isEmpty()) { |
Walter Jang | 3e5ae0d | 2015-09-20 12:43:37 -0700 | [diff] [blame] | 662 | elog("No kind section data parsed from RawContactDelta(s)"); |
Walter Jang | 79658e1 | 2015-09-24 10:36:26 -0700 | [diff] [blame] | 663 | if (mListener != null) mListener.onBindEditorsFailed(); |
Walter Jang | 3e5ae0d | 2015-09-20 12:43:37 -0700 | [diff] [blame] | 664 | return; |
| 665 | } |
Walter Jang | 82acd42 | 2015-10-17 14:01:27 -0700 | [diff] [blame] | 666 | |
Marcus Hagerott | cf7f295 | 2016-09-06 13:49:17 -0700 | [diff] [blame] | 667 | |
Walter Jang | 82acd42 | 2015-10-17 14:01:27 -0700 | [diff] [blame] | 668 | // Get the primary name kind section data |
Marcus Hagerott | cf7f295 | 2016-09-06 13:49:17 -0700 | [diff] [blame] | 669 | mPrimaryNameKindSectionData = |
| 670 | getOrCreateKindSectionDataList(StructuredName.CONTENT_ITEM_TYPE) |
| 671 | .getEntryToWrite(/* id =*/ -1, mPrimaryAccount, mIsUserProfile); |
Walter Jang | 82acd42 | 2015-10-17 14:01:27 -0700 | [diff] [blame] | 672 | if (mPrimaryNameKindSectionData != null) { |
| 673 | // Ensure that a structured name and photo exists |
| 674 | final RawContactDelta rawContactDelta = |
| 675 | mPrimaryNameKindSectionData.first.getRawContactDelta(); |
| 676 | RawContactModifier.ensureKindExists( |
| 677 | rawContactDelta, |
| 678 | rawContactDelta.getAccountType(mAccountTypeManager), |
Walter Jang | cbd431d | 2015-10-06 13:07:30 -0700 | [diff] [blame] | 679 | StructuredName.CONTENT_ITEM_TYPE); |
Walter Jang | 82acd42 | 2015-10-17 14:01:27 -0700 | [diff] [blame] | 680 | RawContactModifier.ensureKindExists( |
| 681 | rawContactDelta, |
| 682 | rawContactDelta.getAccountType(mAccountTypeManager), |
Walter Jang | cbd431d | 2015-10-06 13:07:30 -0700 | [diff] [blame] | 683 | Photo.CONTENT_ITEM_TYPE); |
| 684 | } |
Walter Jang | 3e5ae0d | 2015-09-20 12:43:37 -0700 | [diff] [blame] | 685 | |
| 686 | // Setup the view |
Walter Jang | 363d3fd | 2015-09-16 10:29:07 -0700 | [diff] [blame] | 687 | addPhotoView(); |
Walter Jang | 9a55237 | 2016-08-24 11:51:05 -0700 | [diff] [blame] | 688 | if (isSingleReadOnlyRawContact()) { |
| 689 | // We're want to display the inputs fields for a single read only raw contact |
| 690 | addReadOnlyRawContactEditorViews(); |
| 691 | // Hide the "More fields" link |
| 692 | mMoreFields.setVisibility(View.GONE); |
| 693 | } else if (mIsEditingReadOnlyRawContactWithNewContact) { |
| 694 | // A new writable raw contact was created and joined with the read only contact |
| 695 | // that the user is trying to edit. |
| 696 | setupCompactEditorNormally(); |
Walter Jang | e394595 | 2015-10-27 12:44:54 -0700 | [diff] [blame] | 697 | |
Walter Jang | 9a55237 | 2016-08-24 11:51:05 -0700 | [diff] [blame] | 698 | // TODO: Hide the raw contact selector since it will just contain the read-only raw |
| 699 | // contact and clicking that will just open the exact same editor. When we clean up |
| 700 | // the whole account header, selector, and raw contact selector mess, we can prevent |
| 701 | // the selector from being displayed in a less hacky way. |
| 702 | mRawContactContainer.setVisibility(View.GONE); |
| 703 | } else if (mRawContactDeltas.size() > 1) { |
| 704 | // We're editing an aggregate composed of more than one writable raw contacts |
Walter Jang | d675315 | 2015-10-02 09:23:13 -0700 | [diff] [blame] | 705 | |
Walter Jang | 9a55237 | 2016-08-24 11:51:05 -0700 | [diff] [blame] | 706 | // TODO: Don't render any input fields. Eventually we will show a list of account |
| 707 | // types and names but for now just show the account selector and hide the "More fields" |
| 708 | // link. |
| 709 | addAccountInfo(rawContactDeltas); |
| 710 | mMoreFields.setVisibility(View.GONE); |
| 711 | } else { |
| 712 | setupCompactEditorNormally(); |
| 713 | } |
Walter Jang | d675315 | 2015-10-02 09:23:13 -0700 | [diff] [blame] | 714 | if (mListener != null) mListener.onEditorsBound(); |
Walter Jang | cab3dce | 2015-02-09 17:48:03 -0800 | [diff] [blame] | 715 | } |
| 716 | |
Walter Jang | 9a55237 | 2016-08-24 11:51:05 -0700 | [diff] [blame] | 717 | private void setupCompactEditorNormally() { |
| 718 | addAccountInfo(mRawContactDeltas); |
| 719 | addKindSectionViews(); |
Walter Jang | cab3dce | 2015-02-09 17:48:03 -0800 | [diff] [blame] | 720 | |
Marcus Hagerott | cf7f295 | 2016-09-06 13:49:17 -0700 | [diff] [blame] | 721 | mMoreFields.setVisibility(hasMoreFields() ? View.VISIBLE : View.GONE); |
| 722 | |
Walter Jang | 9a55237 | 2016-08-24 11:51:05 -0700 | [diff] [blame] | 723 | if (mIsExpanded) showAllFields(); |
| 724 | } |
| 725 | |
| 726 | private boolean isSingleReadOnlyRawContact() { |
| 727 | return mRawContactDeltas.size() == 1 |
| 728 | && mRawContactDeltas.get(0).getRawContactId() == mRawContactIdToDisplayAlone |
| 729 | && mRawContactDisplayAloneIsReadOnly; |
| 730 | } |
| 731 | |
Walter Jang | cbd431d | 2015-10-06 13:07:30 -0700 | [diff] [blame] | 732 | private void parseRawContactDeltas(RawContactDeltaList rawContactDeltas) { |
Walter Jang | 363d3fd | 2015-09-16 10:29:07 -0700 | [diff] [blame] | 733 | // Build the kind section data list map |
Walter Jang | 192a01c | 2015-09-22 15:23:55 -0700 | [diff] [blame] | 734 | vlog("parse: " + rawContactDeltas.size() + " rawContactDelta(s)"); |
| 735 | for (int j = 0; j < rawContactDeltas.size(); j++) { |
| 736 | final RawContactDelta rawContactDelta = rawContactDeltas.get(j); |
| 737 | vlog("parse: " + j + " rawContactDelta" + rawContactDelta); |
Walter Jang | 363d3fd | 2015-09-16 10:29:07 -0700 | [diff] [blame] | 738 | if (rawContactDelta == null || !rawContactDelta.isVisible()) continue; |
Walter Jang | cab3dce | 2015-02-09 17:48:03 -0800 | [diff] [blame] | 739 | final AccountType accountType = rawContactDelta.getAccountType(mAccountTypeManager); |
Walter Jang | 363d3fd | 2015-09-16 10:29:07 -0700 | [diff] [blame] | 740 | if (accountType == null) continue; |
| 741 | final List<DataKind> dataKinds = accountType.getSortedDataKinds(); |
| 742 | final int dataKindSize = dataKinds == null ? 0 : dataKinds.size(); |
| 743 | vlog("parse: " + dataKindSize + " dataKinds(s)"); |
| 744 | for (int i = 0; i < dataKindSize; i++) { |
| 745 | final DataKind dataKind = dataKinds.get(i); |
Walter Jang | 9a55237 | 2016-08-24 11:51:05 -0700 | [diff] [blame] | 746 | if (dataKind == null) { |
| 747 | vlog("parse: " + i + " " + dataKind.mimeType + " dropped null data kind"); |
Walter Jang | 192a01c | 2015-09-22 15:23:55 -0700 | [diff] [blame] | 748 | continue; |
| 749 | } |
| 750 | final String mimeType = dataKind.mimeType; |
| 751 | |
| 752 | // Skip psuedo mime types |
| 753 | if (DataKind.PSEUDO_MIME_TYPE_DISPLAY_NAME.equals(mimeType) |
| 754 | || DataKind.PSEUDO_MIME_TYPE_PHONETIC_NAME.equals(mimeType)) { |
| 755 | vlog("parse: " + i + " " + dataKind.mimeType + " dropped pseudo type"); |
| 756 | continue; |
| 757 | } |
| 758 | |
Walter Jang | 3f18d61 | 2015-10-07 16:01:05 -0700 | [diff] [blame] | 759 | final KindSectionDataList kindSectionDataList = |
Walter Jang | cbd431d | 2015-10-06 13:07:30 -0700 | [diff] [blame] | 760 | getOrCreateKindSectionDataList(mimeType); |
Walter Jang | 363d3fd | 2015-09-16 10:29:07 -0700 | [diff] [blame] | 761 | final KindSectionData kindSectionData = |
| 762 | new KindSectionData(accountType, dataKind, rawContactDelta); |
| 763 | kindSectionDataList.add(kindSectionData); |
Walter Jang | 192a01c | 2015-09-22 15:23:55 -0700 | [diff] [blame] | 764 | |
Walter Jang | 363d3fd | 2015-09-16 10:29:07 -0700 | [diff] [blame] | 765 | vlog("parse: " + i + " " + dataKind.mimeType + " " + |
Walter Jang | 228e02f | 2015-11-13 09:11:01 -0800 | [diff] [blame] | 766 | kindSectionData.getValuesDeltas().size() + " value(s) " + |
Tingting Wang | d482e0c | 2015-11-16 10:13:29 -0800 | [diff] [blame] | 767 | kindSectionData.getNonEmptyValuesDeltas().size() + " non-empty value(s) " + |
Wenyi Wang | 42d740c | 2015-11-13 14:23:54 -0800 | [diff] [blame] | 768 | kindSectionData.getVisibleValuesDeltas().size() + |
Walter Jang | 228e02f | 2015-11-13 09:11:01 -0800 | [diff] [blame] | 769 | " visible value(s)"); |
Walter Jang | ac679af | 2015-06-01 12:17:06 -0700 | [diff] [blame] | 770 | } |
| 771 | } |
Walter Jang | 3efae4a | 2015-02-18 11:12:00 -0800 | [diff] [blame] | 772 | } |
| 773 | |
Walter Jang | 3f18d61 | 2015-10-07 16:01:05 -0700 | [diff] [blame] | 774 | private KindSectionDataList getOrCreateKindSectionDataList(String mimeType) { |
Walter Jang | cbd431d | 2015-10-06 13:07:30 -0700 | [diff] [blame] | 775 | KindSectionDataList kindSectionDataList = mKindSectionDataMap.get(mimeType); |
Walter Jang | 3e5ae0d | 2015-09-20 12:43:37 -0700 | [diff] [blame] | 776 | if (kindSectionDataList == null) { |
Walter Jang | cbd431d | 2015-10-06 13:07:30 -0700 | [diff] [blame] | 777 | kindSectionDataList = new KindSectionDataList(); |
Walter Jang | 3e5ae0d | 2015-09-20 12:43:37 -0700 | [diff] [blame] | 778 | mKindSectionDataMap.put(mimeType, kindSectionDataList); |
| 779 | } |
| 780 | return kindSectionDataList; |
| 781 | } |
| 782 | |
Walter Jang | 9a55237 | 2016-08-24 11:51:05 -0700 | [diff] [blame] | 783 | private void addReadOnlyRawContactEditorViews() { |
| 784 | final LayoutInflater inflater = (LayoutInflater) getContext().getSystemService( |
| 785 | Context.LAYOUT_INFLATER_SERVICE); |
| 786 | final AccountTypeManager accountTypes = AccountTypeManager.getInstance( |
| 787 | getContext()); |
| 788 | |
| 789 | for (int i = 0; i < mRawContactDeltas.size(); i++) { |
| 790 | final RawContactDelta rawContactDelta = mRawContactDeltas.get(i); |
| 791 | if (!rawContactDelta.isVisible()) continue; |
| 792 | final AccountType type = rawContactDelta.getAccountType(accountTypes); |
| 793 | if (type.areContactsWritable()) continue; |
| 794 | |
| 795 | final BaseRawContactEditorView editor = (BaseRawContactEditorView) inflater.inflate( |
| 796 | R.layout.raw_contact_readonly_editor_view, mKindSectionViews, false); |
| 797 | editor.setCollapsed(false); |
| 798 | mKindSectionViews.addView(editor); |
| 799 | editor.setState(rawContactDelta, type, mViewIdGenerator, mIsUserProfile); |
| 800 | } |
| 801 | } |
| 802 | |
| 803 | // TODO: we have mRawContactDeltas, we don't need to pass the RawContactDeltaList to this method |
Tingting Wang | 655ad1a | 2015-10-05 17:51:14 -0700 | [diff] [blame] | 804 | private void addAccountInfo(RawContactDeltaList rawContactDeltas) { |
Walter Jang | 82acd42 | 2015-10-17 14:01:27 -0700 | [diff] [blame] | 805 | mAccountHeaderContainer.setVisibility(View.GONE); |
Walter Jang | 82acd42 | 2015-10-17 14:01:27 -0700 | [diff] [blame] | 806 | mRawContactContainer.setVisibility(View.GONE); |
| 807 | |
| 808 | if (mPrimaryNameKindSectionData == null) return; |
| 809 | final RawContactDelta rawContactDelta = |
| 810 | mPrimaryNameKindSectionData.first.getRawContactDelta(); |
Walter Jang | 708ea9e | 2015-09-10 15:42:05 -0700 | [diff] [blame] | 811 | |
Marcus Hagerott | fac695a | 2016-08-24 17:02:40 -0700 | [diff] [blame] | 812 | final AccountDisplayInfo account = |
| 813 | mAccountDisplayInfoFactory.getAccountDisplayInfoFor(rawContactDelta); |
| 814 | |
Walter Jang | 708ea9e | 2015-09-10 15:42:05 -0700 | [diff] [blame] | 815 | // Get the account information for the primary raw contact delta |
Marcus Hagerott | fac695a | 2016-08-24 17:02:40 -0700 | [diff] [blame] | 816 | final String accountLabel = mIsUserProfile |
| 817 | ? EditorUiUtils.getAccountHeaderLabelForMyProfile(getContext(), account) |
| 818 | : account.getNameLabel().toString(); |
Walter Jang | 708ea9e | 2015-09-10 15:42:05 -0700 | [diff] [blame] | 819 | |
Walter Jang | 2370954 | 2015-10-22 12:50:58 -0700 | [diff] [blame] | 820 | // Either the account header or selector should be shown, not both. |
Walter Jang | 708ea9e | 2015-09-10 15:42:05 -0700 | [diff] [blame] | 821 | final List<AccountWithDataSet> accounts = |
| 822 | AccountTypeManager.getInstance(getContext()).getAccounts(true); |
Walter Jang | 82acd42 | 2015-10-17 14:01:27 -0700 | [diff] [blame] | 823 | if (mHasNewContact && !mIsUserProfile) { |
| 824 | if (accounts.size() > 1) { |
Marcus Hagerott | fac695a | 2016-08-24 17:02:40 -0700 | [diff] [blame] | 825 | addAccountSelector(rawContactDelta, accountLabel); |
Walter Jang | be5e1b1 | 2015-10-17 11:38:29 -0700 | [diff] [blame] | 826 | } else { |
Marcus Hagerott | fac695a | 2016-08-24 17:02:40 -0700 | [diff] [blame] | 827 | addAccountHeader(accountLabel); |
Walter Jang | be5e1b1 | 2015-10-17 11:38:29 -0700 | [diff] [blame] | 828 | } |
Tingting Wang | 1594c6f | 2015-10-26 17:39:16 -0700 | [diff] [blame] | 829 | } else if (mIsUserProfile || !shouldHideAccountContainer(rawContactDeltas)) { |
Marcus Hagerott | fac695a | 2016-08-24 17:02:40 -0700 | [diff] [blame] | 830 | addAccountHeader(accountLabel); |
Walter Jang | 708ea9e | 2015-09-10 15:42:05 -0700 | [diff] [blame] | 831 | } |
Walter Jang | 2370954 | 2015-10-22 12:50:58 -0700 | [diff] [blame] | 832 | |
| 833 | // The raw contact selector should only display linked raw contacts that can be edited in |
| 834 | // the full editor (i.e. they are not newly created raw contacts) |
Tingting Wang | 2bb85d2 | 2015-10-23 13:01:09 -0700 | [diff] [blame] | 835 | final RawContactAccountListAdapter adapter = new RawContactAccountListAdapter(getContext(), |
| 836 | getRawContactDeltaListForSelector(rawContactDeltas)); |
| 837 | if (adapter.getCount() > 0) { |
| 838 | final String accountsSummary = getResources().getQuantityString( |
| 839 | R.plurals.compact_editor_linked_contacts_selector_title, |
| 840 | adapter.getCount(), adapter.getCount()); |
Walter Jang | 2370954 | 2015-10-22 12:50:58 -0700 | [diff] [blame] | 841 | addRawContactAccountSelector(accountsSummary, adapter); |
| 842 | } |
Walter Jang | 708ea9e | 2015-09-10 15:42:05 -0700 | [diff] [blame] | 843 | } |
| 844 | |
Tingting Wang | 2bb85d2 | 2015-10-23 13:01:09 -0700 | [diff] [blame] | 845 | private RawContactDeltaList getRawContactDeltaListForSelector( |
| 846 | RawContactDeltaList rawContactDeltas) { |
| 847 | // Sort raw contacts so google accounts come first |
| 848 | Collections.sort(rawContactDeltas, new RawContactDeltaComparator(getContext())); |
| 849 | |
| 850 | final RawContactDeltaList result = new RawContactDeltaList(); |
| 851 | for (RawContactDelta rawContactDelta : rawContactDeltas) { |
| 852 | if (rawContactDelta.isVisible() && rawContactDelta.getRawContactId() > 0) { |
| 853 | // Only add raw contacts that can be opened in the editor |
| 854 | result.add(rawContactDelta); |
| 855 | } |
| 856 | } |
| 857 | // Don't return a list of size 1 that would just open the raw contact being edited |
| 858 | // in the compact editor in the full editor |
| 859 | if (result.size() == 1 && result.get(0).getRawContactAccountType( |
| 860 | getContext()).areContactsWritable()) { |
| 861 | result.clear(); |
| 862 | return result; |
| 863 | } |
| 864 | return result; |
| 865 | } |
| 866 | |
Tingting Wang | 1594c6f | 2015-10-26 17:39:16 -0700 | [diff] [blame] | 867 | // Returns true if there are multiple writable rawcontacts and no read-only ones, |
| 868 | // or there are both writable and read-only rawcontacts. |
| 869 | private boolean shouldHideAccountContainer(RawContactDeltaList rawContactDeltas) { |
Tingting Wang | 2bb85d2 | 2015-10-23 13:01:09 -0700 | [diff] [blame] | 870 | int writable = 0; |
| 871 | int readonly = 0; |
| 872 | for (RawContactDelta rawContactDelta : rawContactDeltas) { |
| 873 | if (rawContactDelta.isVisible() && rawContactDelta.getRawContactId() > 0) { |
| 874 | if (rawContactDelta.getRawContactAccountType(getContext()).areContactsWritable()) { |
| 875 | writable++; |
| 876 | } else { |
| 877 | readonly++; |
| 878 | } |
| 879 | } |
| 880 | } |
| 881 | return (writable > 1 || (writable > 0 && readonly > 0)); |
| 882 | } |
| 883 | |
Marcus Hagerott | fac695a | 2016-08-24 17:02:40 -0700 | [diff] [blame] | 884 | private void addAccountHeader(String accountLabel) { |
Walter Jang | 82acd42 | 2015-10-17 14:01:27 -0700 | [diff] [blame] | 885 | mAccountHeaderContainer.setVisibility(View.VISIBLE); |
| 886 | |
Walter Jang | be5e1b1 | 2015-10-17 11:38:29 -0700 | [diff] [blame] | 887 | // Set the account name |
Walter Jang | be5e1b1 | 2015-10-17 11:38:29 -0700 | [diff] [blame] | 888 | mAccountHeaderName.setVisibility(View.VISIBLE); |
Marcus Hagerott | fac695a | 2016-08-24 17:02:40 -0700 | [diff] [blame] | 889 | mAccountHeaderName.setText(accountLabel); |
Walter Jang | be5e1b1 | 2015-10-17 11:38:29 -0700 | [diff] [blame] | 890 | |
| 891 | // Set the account type |
| 892 | final String selectorTitle = getResources().getString( |
| 893 | R.string.compact_editor_account_selector_title); |
| 894 | mAccountHeaderType.setText(selectorTitle); |
| 895 | |
| 896 | // Set the icon |
Walter Jang | 82acd42 | 2015-10-17 14:01:27 -0700 | [diff] [blame] | 897 | if (mPrimaryNameKindSectionData != null) { |
| 898 | final RawContactDelta rawContactDelta = |
| 899 | mPrimaryNameKindSectionData.first.getRawContactDelta(); |
| 900 | if (rawContactDelta != null) { |
| 901 | final AccountType accountType = |
| 902 | rawContactDelta.getRawContactAccountType(getContext()); |
| 903 | mAccountHeaderIcon.setImageDrawable(accountType.getDisplayIcon(getContext())); |
| 904 | } |
| 905 | } |
Walter Jang | be5e1b1 | 2015-10-17 11:38:29 -0700 | [diff] [blame] | 906 | |
| 907 | // Set the content description |
| 908 | mAccountHeaderContainer.setContentDescription( |
Marcus Hagerott | fac695a | 2016-08-24 17:02:40 -0700 | [diff] [blame] | 909 | EditorUiUtils.getAccountInfoContentDescription(accountLabel, |
| 910 | selectorTitle)); |
Walter Jang | be5e1b1 | 2015-10-17 11:38:29 -0700 | [diff] [blame] | 911 | } |
| 912 | |
Marcus Hagerott | fac695a | 2016-08-24 17:02:40 -0700 | [diff] [blame] | 913 | private void addAccountSelector(final RawContactDelta rawContactDelta, CharSequence nameLabel) { |
Gary Mai | 46cb310 | 2016-08-10 18:14:09 -0700 | [diff] [blame] | 914 | // Show save to default account. |
Marcus Hagerott | fac695a | 2016-08-24 17:02:40 -0700 | [diff] [blame] | 915 | addAccountHeader(nameLabel.toString()); |
Gary Mai | 46cb310 | 2016-08-10 18:14:09 -0700 | [diff] [blame] | 916 | // Add handlers for choosing another account to save to. |
| 917 | mAccountHeaderExpanderIcon.setVisibility(View.VISIBLE); |
| 918 | mAccountHeaderContainer.setOnClickListener(new View.OnClickListener() { |
Walter Jang | 708ea9e | 2015-09-10 15:42:05 -0700 | [diff] [blame] | 919 | @Override |
| 920 | public void onClick(View v) { |
| 921 | final ListPopupWindow popup = new ListPopupWindow(getContext(), null); |
| 922 | final AccountsListAdapter adapter = |
| 923 | new AccountsListAdapter(getContext(), |
| 924 | AccountsListAdapter.AccountListFilter.ACCOUNTS_CONTACT_WRITABLE, |
| 925 | mPrimaryAccount); |
Gary Mai | 46cb310 | 2016-08-10 18:14:09 -0700 | [diff] [blame] | 926 | popup.setWidth(mAccountHeaderContainer.getWidth()); |
| 927 | popup.setAnchorView(mAccountHeaderContainer); |
Walter Jang | 708ea9e | 2015-09-10 15:42:05 -0700 | [diff] [blame] | 928 | popup.setAdapter(adapter); |
| 929 | popup.setModal(true); |
| 930 | popup.setInputMethodMode(ListPopupWindow.INPUT_METHOD_NOT_NEEDED); |
| 931 | popup.setOnItemClickListener(new AdapterView.OnItemClickListener() { |
| 932 | @Override |
| 933 | public void onItemClick(AdapterView<?> parent, View view, int position, |
| 934 | long id) { |
| 935 | UiClosables.closeQuietly(popup); |
| 936 | final AccountWithDataSet newAccount = adapter.getItem(position); |
| 937 | if (mListener != null && !mPrimaryAccount.equals(newAccount)) { |
| 938 | mListener.onRebindEditorsForNewContact( |
Walter Jang | 82acd42 | 2015-10-17 14:01:27 -0700 | [diff] [blame] | 939 | rawContactDelta, |
Walter Jang | 708ea9e | 2015-09-10 15:42:05 -0700 | [diff] [blame] | 940 | mPrimaryAccount, |
| 941 | newAccount); |
| 942 | } |
| 943 | } |
| 944 | }); |
| 945 | popup.show(); |
| 946 | } |
| 947 | }); |
| 948 | } |
| 949 | |
Walter Jang | 2370954 | 2015-10-22 12:50:58 -0700 | [diff] [blame] | 950 | private void addRawContactAccountSelector(String accountsSummary, |
| 951 | final RawContactAccountListAdapter adapter) { |
Tingting Wang | 655ad1a | 2015-10-05 17:51:14 -0700 | [diff] [blame] | 952 | mRawContactContainer.setVisibility(View.VISIBLE); |
| 953 | |
Tingting Wang | 655ad1a | 2015-10-05 17:51:14 -0700 | [diff] [blame] | 954 | mRawContactSummary.setText(accountsSummary); |
Tingting Wang | 655ad1a | 2015-10-05 17:51:14 -0700 | [diff] [blame] | 955 | |
| 956 | mRawContactContainer.setOnClickListener(new View.OnClickListener() { |
| 957 | @Override |
| 958 | public void onClick(View v) { |
| 959 | final ListPopupWindow popup = new ListPopupWindow(getContext(), null); |
Tingting Wang | 655ad1a | 2015-10-05 17:51:14 -0700 | [diff] [blame] | 960 | popup.setWidth(mRawContactContainer.getWidth()); |
| 961 | popup.setAnchorView(mRawContactContainer); |
| 962 | popup.setAdapter(adapter); |
| 963 | popup.setModal(true); |
| 964 | popup.setInputMethodMode(ListPopupWindow.INPUT_METHOD_NOT_NEEDED); |
| 965 | popup.setOnItemClickListener(new AdapterView.OnItemClickListener() { |
| 966 | @Override |
| 967 | public void onItemClick(AdapterView<?> parent, View view, int position, |
| 968 | long id) { |
| 969 | UiClosables.closeQuietly(popup); |
Tingting Wang | 655ad1a | 2015-10-05 17:51:14 -0700 | [diff] [blame] | 970 | |
| 971 | if (mListener != null) { |
Tingting Wang | 91cee28 | 2015-10-07 13:48:17 -0700 | [diff] [blame] | 972 | final long rawContactId = adapter.getItemId(position); |
| 973 | final Uri rawContactUri = ContentUris.withAppendedId( |
| 974 | ContactsContract.RawContacts.CONTENT_URI, rawContactId); |
| 975 | final RawContactDelta rawContactDelta = adapter.getItem(position); |
| 976 | final AccountTypeManager accountTypes = AccountTypeManager.getInstance( |
| 977 | getContext()); |
| 978 | final AccountType accountType = rawContactDelta.getAccountType( |
| 979 | accountTypes); |
| 980 | final boolean isReadOnly = !accountType.areContactsWritable(); |
| 981 | |
| 982 | mListener.onRawContactSelected(rawContactUri, rawContactId, isReadOnly); |
Tingting Wang | 655ad1a | 2015-10-05 17:51:14 -0700 | [diff] [blame] | 983 | } |
| 984 | } |
| 985 | }); |
| 986 | popup.show(); |
| 987 | } |
| 988 | }); |
| 989 | } |
| 990 | |
Walter Jang | 363d3fd | 2015-09-16 10:29:07 -0700 | [diff] [blame] | 991 | private void addPhotoView() { |
Walter Jang | 31a74ad | 2015-10-02 19:17:39 -0700 | [diff] [blame] | 992 | // Get the kind section data and values delta that we will display in the photo view |
Walter Jang | cbd431d | 2015-10-06 13:07:30 -0700 | [diff] [blame] | 993 | final KindSectionDataList kindSectionDataList = |
Marcus Hagerott | cf7f295 | 2016-09-06 13:49:17 -0700 | [diff] [blame] | 994 | getOrCreateKindSectionDataList(Photo.CONTENT_ITEM_TYPE); |
Walter Jang | cbd431d | 2015-10-06 13:07:30 -0700 | [diff] [blame] | 995 | final Pair<KindSectionData,ValuesDelta> photoToDisplay = |
| 996 | kindSectionDataList.getEntryToDisplay(mPhotoId); |
| 997 | if (photoToDisplay == null) { |
Walter Jang | 3e5ae0d | 2015-09-20 12:43:37 -0700 | [diff] [blame] | 998 | wlog("photo: no kind section data parsed"); |
Walter Jang | cbd431d | 2015-10-06 13:07:30 -0700 | [diff] [blame] | 999 | mPhotoView.setVisibility(View.GONE); |
Walter Jang | 363d3fd | 2015-09-16 10:29:07 -0700 | [diff] [blame] | 1000 | return; |
Marcus Hagerott | cf7f295 | 2016-09-06 13:49:17 -0700 | [diff] [blame] | 1001 | } else { |
| 1002 | mPhotoView.setVisibility(View.VISIBLE); |
Walter Jang | 363d3fd | 2015-09-16 10:29:07 -0700 | [diff] [blame] | 1003 | } |
Walter Jang | 06f73a1 | 2015-06-17 11:15:48 -0700 | [diff] [blame] | 1004 | |
Walter Jang | 31a74ad | 2015-10-02 19:17:39 -0700 | [diff] [blame] | 1005 | // Set the photo view |
Walter Jang | cbd431d | 2015-10-06 13:07:30 -0700 | [diff] [blame] | 1006 | mPhotoView.setPhoto(photoToDisplay.second, mMaterialPalette); |
Walter Jang | 31a74ad | 2015-10-02 19:17:39 -0700 | [diff] [blame] | 1007 | |
| 1008 | // Find the raw contact ID and values delta that will be written when the photo is edited |
Walter Jang | da258ff | 2015-11-17 11:06:02 -0800 | [diff] [blame] | 1009 | final Pair<KindSectionData, ValuesDelta> photoToWrite = kindSectionDataList.getEntryToWrite( |
Walter Jang | 82acd42 | 2015-10-17 14:01:27 -0700 | [diff] [blame] | 1010 | mPhotoId, mPrimaryAccount, mIsUserProfile); |
Walter Jang | da258ff | 2015-11-17 11:06:02 -0800 | [diff] [blame] | 1011 | if (photoToWrite == null) { |
Walter Jang | 31a74ad | 2015-10-02 19:17:39 -0700 | [diff] [blame] | 1012 | mPhotoView.setReadOnly(true); |
| 1013 | return; |
| 1014 | } |
Walter Jang | 31a74ad | 2015-10-02 19:17:39 -0700 | [diff] [blame] | 1015 | mPhotoView.setReadOnly(false); |
Walter Jang | da258ff | 2015-11-17 11:06:02 -0800 | [diff] [blame] | 1016 | mPhotoRawContactId = photoToWrite.first.getRawContactDelta().getRawContactId(); |
| 1017 | mPhotoValuesDelta = photoToWrite.second; |
Walter Jang | 31a74ad | 2015-10-02 19:17:39 -0700 | [diff] [blame] | 1018 | } |
| 1019 | |
Walter Jang | f5dfea4 | 2015-09-16 12:30:36 -0700 | [diff] [blame] | 1020 | private void addKindSectionViews() { |
| 1021 | // Sort the kinds |
Walter Jang | cbd431d | 2015-10-06 13:07:30 -0700 | [diff] [blame] | 1022 | final TreeSet<Map.Entry<String,KindSectionDataList>> entries = |
Walter Jang | 192a01c | 2015-09-22 15:23:55 -0700 | [diff] [blame] | 1023 | new TreeSet<>(KIND_SECTION_DATA_MAP_ENTRY_COMPARATOR); |
Walter Jang | f5dfea4 | 2015-09-16 12:30:36 -0700 | [diff] [blame] | 1024 | entries.addAll(mKindSectionDataMap.entrySet()); |
Walter Jang | 3efae4a | 2015-02-18 11:12:00 -0800 | [diff] [blame] | 1025 | |
Walter Jang | f5dfea4 | 2015-09-16 12:30:36 -0700 | [diff] [blame] | 1026 | vlog("kind: " + entries.size() + " kindSection(s)"); |
Walter Jang | 3e5ae0d | 2015-09-20 12:43:37 -0700 | [diff] [blame] | 1027 | int i = -1; |
Walter Jang | cbd431d | 2015-10-06 13:07:30 -0700 | [diff] [blame] | 1028 | for (Map.Entry<String, KindSectionDataList> entry : entries) { |
Walter Jang | 3e5ae0d | 2015-09-20 12:43:37 -0700 | [diff] [blame] | 1029 | i++; |
| 1030 | |
Walter Jang | f5dfea4 | 2015-09-16 12:30:36 -0700 | [diff] [blame] | 1031 | final String mimeType = entry.getKey(); |
Walter Jang | 82acd42 | 2015-10-17 14:01:27 -0700 | [diff] [blame] | 1032 | |
Tingting Wang | f695eb3 | 2015-10-15 18:45:15 -0700 | [diff] [blame] | 1033 | if (StructuredName.CONTENT_ITEM_TYPE.equals(mimeType)) { |
Walter Jang | 82acd42 | 2015-10-17 14:01:27 -0700 | [diff] [blame] | 1034 | if (mPrimaryNameKindSectionData == null) { |
| 1035 | vlog("kind: " + i + " " + mimeType + " dropped"); |
| 1036 | continue; |
Tingting Wang | f695eb3 | 2015-10-15 18:45:15 -0700 | [diff] [blame] | 1037 | } |
Walter Jang | 82acd42 | 2015-10-17 14:01:27 -0700 | [diff] [blame] | 1038 | vlog("kind: " + i + " " + mimeType + " using first entry only"); |
| 1039 | final KindSectionDataList kindSectionDataList = new KindSectionDataList(); |
| 1040 | kindSectionDataList.add(mPrimaryNameKindSectionData.first); |
Walter Jang | f5dfea4 | 2015-09-16 12:30:36 -0700 | [diff] [blame] | 1041 | final CompactKindSectionView kindSectionView = inflateKindSectionView( |
Walter Jang | 82acd42 | 2015-10-17 14:01:27 -0700 | [diff] [blame] | 1042 | mKindSectionViews, kindSectionDataList, mimeType, |
| 1043 | mPrimaryNameKindSectionData.second); |
Walter Jang | f5dfea4 | 2015-09-16 12:30:36 -0700 | [diff] [blame] | 1044 | mKindSectionViews.addView(kindSectionView); |
Walter Jang | f10ca15 | 2015-09-22 15:23:55 -0700 | [diff] [blame] | 1045 | |
| 1046 | // Keep a pointer to all the KindSectionsViews for each mimeType |
| 1047 | getKindSectionViews(mimeType).add(kindSectionView); |
Walter Jang | 82acd42 | 2015-10-17 14:01:27 -0700 | [diff] [blame] | 1048 | } else { |
| 1049 | final KindSectionDataList kindSectionDataList = entry.getValue(); |
| 1050 | |
| 1051 | // Ignore mime types that we've already handled |
| 1052 | if (Photo.CONTENT_ITEM_TYPE.equals(mimeType)) { |
| 1053 | vlog("kind: " + i + " " + mimeType + " dropped"); |
| 1054 | continue; |
| 1055 | } |
| 1056 | |
| 1057 | // Don't show more than one group editor on the compact editor. |
| 1058 | // Groups will still be editable for each raw contact individually on the full editor. |
| 1059 | if (GroupMembership.CONTENT_ITEM_TYPE.equals(mimeType) |
| 1060 | && kindSectionDataList.size() > 1) { |
| 1061 | vlog("kind: " + i + " " + mimeType + " dropped"); |
| 1062 | continue; |
| 1063 | } |
| 1064 | |
| 1065 | if (kindSectionDataList != null && !kindSectionDataList.isEmpty()) { |
| 1066 | vlog("kind: " + i + " " + mimeType + " " + kindSectionDataList.size() + |
| 1067 | " kindSectionData(s)"); |
| 1068 | |
| 1069 | final CompactKindSectionView kindSectionView = inflateKindSectionView( |
| 1070 | mKindSectionViews, kindSectionDataList, mimeType, |
| 1071 | /* primaryValueDelta =*/ null); |
| 1072 | mKindSectionViews.addView(kindSectionView); |
| 1073 | |
| 1074 | // Keep a pointer to all the KindSectionsViews for each mimeType |
| 1075 | getKindSectionViews(mimeType).add(kindSectionView); |
| 1076 | } |
Walter Jang | cab3dce | 2015-02-09 17:48:03 -0800 | [diff] [blame] | 1077 | } |
| 1078 | } |
| 1079 | } |
| 1080 | |
Walter Jang | f10ca15 | 2015-09-22 15:23:55 -0700 | [diff] [blame] | 1081 | private List<CompactKindSectionView> getKindSectionViews(String mimeType) { |
| 1082 | List<CompactKindSectionView> kindSectionViews = mKindSectionViewsMap.get(mimeType); |
| 1083 | if (kindSectionViews == null) { |
| 1084 | kindSectionViews = new ArrayList<>(); |
| 1085 | mKindSectionViewsMap.put(mimeType, kindSectionViews); |
| 1086 | } |
| 1087 | return kindSectionViews; |
| 1088 | } |
| 1089 | |
Walter Jang | f5dfea4 | 2015-09-16 12:30:36 -0700 | [diff] [blame] | 1090 | private CompactKindSectionView inflateKindSectionView(ViewGroup viewGroup, |
Walter Jang | 82acd42 | 2015-10-17 14:01:27 -0700 | [diff] [blame] | 1091 | KindSectionDataList kindSectionDataList, String mimeType, |
| 1092 | ValuesDelta primaryValuesDelta) { |
Walter Jang | f5dfea4 | 2015-09-16 12:30:36 -0700 | [diff] [blame] | 1093 | final CompactKindSectionView kindSectionView = (CompactKindSectionView) |
| 1094 | mLayoutInflater.inflate(R.layout.compact_item_kind_section, viewGroup, |
| 1095 | /* attachToRoot =*/ false); |
Walter Jang | 45b86d5 | 2015-10-15 15:23:16 -0700 | [diff] [blame] | 1096 | kindSectionView.setIsUserProfile(mIsUserProfile); |
Walter Jang | f5dfea4 | 2015-09-16 12:30:36 -0700 | [diff] [blame] | 1097 | |
Walter Jang | 192a01c | 2015-09-22 15:23:55 -0700 | [diff] [blame] | 1098 | if (Phone.CONTENT_ITEM_TYPE.equals(mimeType) |
Walter Jang | f5dfea4 | 2015-09-16 12:30:36 -0700 | [diff] [blame] | 1099 | || Email.CONTENT_ITEM_TYPE.equals(mimeType)) { |
Walter Jang | 192a01c | 2015-09-22 15:23:55 -0700 | [diff] [blame] | 1100 | // Phone numbers and email addresses are always displayed, |
| 1101 | // even if they are empty |
Walter Jang | f5dfea4 | 2015-09-16 12:30:36 -0700 | [diff] [blame] | 1102 | kindSectionView.setHideWhenEmpty(false); |
| 1103 | } |
Walter Jang | f5dfea4 | 2015-09-16 12:30:36 -0700 | [diff] [blame] | 1104 | |
Walter Jang | 192a01c | 2015-09-22 15:23:55 -0700 | [diff] [blame] | 1105 | // Since phone numbers and email addresses displayed even if they are empty, |
| 1106 | // they will be the only types you add new values to initially for new contacts |
| 1107 | kindSectionView.setShowOneEmptyEditor(true); |
| 1108 | |
Walter Jang | 82acd42 | 2015-10-17 14:01:27 -0700 | [diff] [blame] | 1109 | // Sort non-name editors so they wind up in the order we want |
| 1110 | if (!StructuredName.CONTENT_ITEM_TYPE.equals(mimeType)) { |
Walter Jang | 192a01c | 2015-09-22 15:23:55 -0700 | [diff] [blame] | 1111 | Collections.sort(kindSectionDataList, new EditorComparator(getContext())); |
Walter Jang | 3e5ae0d | 2015-09-20 12:43:37 -0700 | [diff] [blame] | 1112 | } |
| 1113 | |
Walter Jang | 82acd42 | 2015-10-17 14:01:27 -0700 | [diff] [blame] | 1114 | kindSectionView.setState(kindSectionDataList, mViewIdGenerator, mListener, |
| 1115 | primaryValuesDelta); |
Walter Jang | f5dfea4 | 2015-09-16 12:30:36 -0700 | [diff] [blame] | 1116 | |
| 1117 | return kindSectionView; |
Walter Jang | cab3dce | 2015-02-09 17:48:03 -0800 | [diff] [blame] | 1118 | } |
| 1119 | |
Walter Jang | e394595 | 2015-10-27 12:44:54 -0700 | [diff] [blame] | 1120 | void maybeSetReadOnlyDisplayNameAsPrimary(String readOnlyDisplayName) { |
| 1121 | if (TextUtils.isEmpty(readOnlyDisplayName)) return; |
| 1122 | final CompactKindSectionView primaryNameKindSectionView = getPrimaryNameKindSectionView(); |
| 1123 | if (primaryNameKindSectionView != null && primaryNameKindSectionView.isEmptyName()) { |
| 1124 | vlog("name: using read only display name as primary name"); |
| 1125 | primaryNameKindSectionView.setName(readOnlyDisplayName); |
| 1126 | } |
| 1127 | } |
| 1128 | |
| 1129 | private CompactKindSectionView getPrimaryNameKindSectionView() { |
Walter Jang | 4f5594a | 2015-10-06 18:40:31 -0700 | [diff] [blame] | 1130 | final List<CompactKindSectionView> kindSectionViews |
| 1131 | = mKindSectionViewsMap.get(StructuredName.CONTENT_ITEM_TYPE); |
Walter Jang | e394595 | 2015-10-27 12:44:54 -0700 | [diff] [blame] | 1132 | return kindSectionViews == null || kindSectionViews.isEmpty() |
| 1133 | ? null : kindSectionViews.get(0); |
Walter Jang | 4f5594a | 2015-10-06 18:40:31 -0700 | [diff] [blame] | 1134 | } |
| 1135 | |
Walter Jang | d675315 | 2015-10-02 09:23:13 -0700 | [diff] [blame] | 1136 | private void showAllFields() { |
Walter Jang | 79658e1 | 2015-09-24 10:36:26 -0700 | [diff] [blame] | 1137 | // Stop hiding empty editors and allow the user to enter values for all kinds now |
| 1138 | for (int i = 0; i < mKindSectionViews.getChildCount(); i++) { |
| 1139 | final CompactKindSectionView kindSectionView = |
| 1140 | (CompactKindSectionView) mKindSectionViews.getChildAt(i); |
| 1141 | kindSectionView.setHideWhenEmpty(false); |
| 1142 | kindSectionView.updateEmptyEditors(/* shouldAnimate =*/ true); |
| 1143 | } |
| 1144 | mIsExpanded = true; |
Walter Jang | 79658e1 | 2015-09-24 10:36:26 -0700 | [diff] [blame] | 1145 | |
Walter Jang | f5dfea4 | 2015-09-16 12:30:36 -0700 | [diff] [blame] | 1146 | // Hide the more fields button |
| 1147 | mMoreFields.setVisibility(View.GONE); |
Walter Jang | cab3dce | 2015-02-09 17:48:03 -0800 | [diff] [blame] | 1148 | } |
| 1149 | |
Marcus Hagerott | cf7f295 | 2016-09-06 13:49:17 -0700 | [diff] [blame] | 1150 | private boolean hasMoreFields() { |
| 1151 | for (List<CompactKindSectionView> sections : mKindSectionViewsMap.values()) { |
| 1152 | for (CompactKindSectionView section : sections) { |
| 1153 | if (section.getVisibility() != View.VISIBLE) { |
| 1154 | return true; |
| 1155 | } |
| 1156 | } |
| 1157 | } |
| 1158 | return false; |
| 1159 | } |
| 1160 | |
Walter Jang | bf63a6d | 2015-05-05 09:14:35 -0700 | [diff] [blame] | 1161 | private static void vlog(String message) { |
| 1162 | if (Log.isLoggable(TAG, Log.VERBOSE)) { |
| 1163 | Log.v(TAG, message); |
Walter Jang | cab3dce | 2015-02-09 17:48:03 -0800 | [diff] [blame] | 1164 | } |
| 1165 | } |
Walter Jang | 363d3fd | 2015-09-16 10:29:07 -0700 | [diff] [blame] | 1166 | |
| 1167 | private static void wlog(String message) { |
| 1168 | if (Log.isLoggable(TAG, Log.WARN)) { |
| 1169 | Log.w(TAG, message); |
| 1170 | } |
| 1171 | } |
| 1172 | |
| 1173 | private static void elog(String message) { |
| 1174 | Log.e(TAG, message); |
| 1175 | } |
Walter Jang | cab3dce | 2015-02-09 17:48:03 -0800 | [diff] [blame] | 1176 | } |