1/*
2 * Copyright (C) 2014 Google Inc.
3 * Licensed to The Android Open Source Project.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 *      http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18package com.android.mail.ui;
19
20import android.content.Context;
21import android.support.v4.text.BidiFormatter;
22import android.util.AttributeSet;
23import android.widget.ImageView;
24import android.widget.LinearLayout;
25import android.widget.TextView;
26
27import com.android.mail.R;
28import com.android.mail.providers.Folder;
29import com.android.mail.utils.EmptyStateUtils;
30
31/**
32 * Empty view for {@link ConversationListFragment}.
33 */
34public class ConversationListEmptyView extends LinearLayout {
35
36    private ImageView mIcon;
37    private TextView mText;
38
39    public ConversationListEmptyView(Context context) {
40        this(context, null);
41    }
42
43    public ConversationListEmptyView(Context context, AttributeSet attrs) {
44        super(context, attrs);
45    }
46
47    @Override
48    protected void onFinishInflate() {
49        super.onFinishInflate();
50
51        mIcon = (ImageView) findViewById(R.id.empty_icon);
52        mText = (TextView) findViewById(R.id.empty_text);
53    }
54
55    /**
56     * Initializes the empty view to use the proper icon and text
57     * based on the type of folder that will be visible.
58     */
59    public void setupEmptyText(final Folder folder, final String searchQuery,
60            final BidiFormatter bidiFormatter, boolean shouldShowIcon) {
61        if (shouldShowIcon) {
62            EmptyStateUtils.bindEmptyFolderIcon(mIcon, folder);
63            mIcon.setVisibility(VISIBLE);
64        } else {
65            mIcon.setVisibility(GONE);
66        }
67
68        EmptyStateUtils.bindEmptyFolderText(mText, folder, getResources(), searchQuery,
69                bidiFormatter);
70    }
71}
72