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 */
16package com.android.messaging.datamodel.data;
17
18import android.content.Context;
19import android.content.Intent;
20import android.net.Uri;
21import android.text.TextUtils;
22
23import com.android.messaging.datamodel.action.BugleActionToasts;
24import com.android.messaging.datamodel.action.UpdateDestinationBlockedAction;
25import com.android.messaging.util.AvatarUriUtil;
26
27/**
28 * Helps visualize a ParticipantData in a PersonItemView
29 */
30public class ParticipantListItemData extends PersonItemData {
31    private final Uri mAvatarUri;
32    private final String mDisplayName;
33    private final String mDetails;
34    private final long mContactId;
35    private final String mLookupKey;
36    private final String mNormalizedDestination;
37
38    /**
39     * Constructor. Takes necessary info from the incoming ParticipantData.
40     */
41    public ParticipantListItemData(final ParticipantData participant) {
42        mAvatarUri = AvatarUriUtil.createAvatarUri(participant);
43        mContactId = participant.getContactId();
44        mLookupKey = participant.getLookupKey();
45        mNormalizedDestination = participant.getNormalizedDestination();
46        if (TextUtils.isEmpty(participant.getFullName())) {
47            mDisplayName = participant.getSendDestination();
48            mDetails = null;
49        } else {
50            mDisplayName = participant.getFullName();
51            mDetails = (participant.isUnknownSender()) ? null : participant.getSendDestination();
52        }
53    }
54
55    @Override
56    public Uri getAvatarUri() {
57        return mAvatarUri;
58    }
59
60    @Override
61    public String getDisplayName() {
62        return mDisplayName;
63    }
64
65    @Override
66    public String getDetails() {
67        return mDetails;
68    }
69
70    @Override
71    public Intent getClickIntent() {
72        return null;
73    }
74
75    @Override
76    public long getContactId() {
77        return mContactId;
78    }
79
80    @Override
81    public String getLookupKey() {
82        return mLookupKey;
83    }
84
85    @Override
86    public String getNormalizedDestination() {
87        return mNormalizedDestination;
88    }
89
90    public void unblock(final Context context) {
91        UpdateDestinationBlockedAction.updateDestinationBlocked(
92                mNormalizedDestination, false, null,
93                BugleActionToasts.makeUpdateDestinationBlockedActionListener(context));
94    }
95}
96