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.media;
17
18import java.util.List;
19
20/**
21 * Holds cached information of VCard contact info.
22 * The temporarily persisted avatar icon Uri is tied to the VCardResource. As a result, whenever
23 * the VCardResource is no longer used (i.e. close() is called), we need to asynchronously
24 * delete the avatar image from temp storage since no one will have reference to the avatar Uri
25 * again. The next time the same VCard is displayed, since the old resource has been evicted from
26 * the memory cache, we'll load and persist the avatar icon again.
27 */
28public class VCardResource extends RefCountedMediaResource {
29    private final List<VCardResourceEntry> mVCards;
30
31    public VCardResource(final String key, final List<VCardResourceEntry> vcards) {
32        super(key);
33        mVCards = vcards;
34    }
35
36    public List<VCardResourceEntry> getVCards() {
37        return mVCards;
38    }
39
40    @Override
41    public int getMediaSize() {
42        // Instead of track VCards by size in kilobytes, we track them by count.
43        return 0;
44    }
45
46    @Override
47    protected void close() {
48        for (final VCardResourceEntry vcard : mVCards) {
49            vcard.close();
50        }
51    }
52}
53