blob: 7e8edeedfb572620bb567eb345bff8c34ea27972 [file] [log] [blame]
Rohan Shahb9587012013-03-20 14:34:38 -07001/**
2 * Copyright (c) 2013, Google Inc.
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.mail.ui;
17
18import com.android.mail.R;
19
Rohan Shahb905f0e2013-04-26 09:17:37 -070020import android.widget.ImageView;
Rohan Shahb9587012013-03-20 14:34:38 -070021import android.widget.TextView;
22
23import com.android.mail.providers.Account;
Rohan Shahb9587012013-03-20 14:34:38 -070024import com.android.mail.utils.Utils;
25
26import android.content.Context;
Rohan Shah074a5a12013-04-04 17:43:15 -070027
Rohan Shahb9587012013-03-20 14:34:38 -070028import android.util.AttributeSet;
Rohan Shahb9587012013-03-20 14:34:38 -070029import android.view.View;
30import android.widget.RelativeLayout;
31
32/**
Rohan Shah671133b2013-03-26 14:48:10 -070033 * The view for each account in the folder list/drawer.
Rohan Shahb9587012013-03-20 14:34:38 -070034 */
35public class AccountItemView extends RelativeLayout {
Rohan Shah671133b2013-03-26 14:48:10 -070036 private TextView mAccountTextView;
Rohan Shahb9587012013-03-20 14:34:38 -070037 private TextView mUnreadCountTextView;
Rohan Shahb905f0e2013-04-26 09:17:37 -070038 private ImageView mSelectedButton;
Rohan Shahb9587012013-03-20 14:34:38 -070039
40 public AccountItemView(Context context) {
41 super(context);
42 }
43
44 public AccountItemView(Context context, AttributeSet attrs) {
45 super(context, attrs);
46 }
47
48 public AccountItemView(Context context, AttributeSet attrs, int defStyle) {
49 super(context, attrs, defStyle);
50 }
51
52 @Override
53 protected void onFinishInflate() {
54 super.onFinishInflate();
Rohan Shah671133b2013-03-26 14:48:10 -070055 mAccountTextView = (TextView)findViewById(R.id.name);
Rohan Shahb9587012013-03-20 14:34:38 -070056 mUnreadCountTextView = (TextView)findViewById(R.id.unread);
Rohan Shahb905f0e2013-04-26 09:17:37 -070057 mSelectedButton = (ImageView)findViewById(R.id.account_radio_button);
Rohan Shahb9587012013-03-20 14:34:38 -070058 }
59
Rohan Shah671133b2013-03-26 14:48:10 -070060 /**
Rohan Shahc1e45062013-04-28 10:50:49 -070061 * Sets the account name and draws the unread count. Depending on the account state (current or
62 * unused), the colors and drawables will change through the call to setSelected for each
63 * necessary element.
Rohan Shah671133b2013-03-26 14:48:10 -070064 *
65 * @param account account whose name will be displayed
Rohan Shah074a5a12013-04-04 17:43:15 -070066 * @param isCurrentAccount true if the account is the one in use, false otherwise
Rohan Shah671133b2013-03-26 14:48:10 -070067 * @param count unread count
68 */
Rohan Shah074a5a12013-04-04 17:43:15 -070069 public void bind(final Account account, final boolean isCurrentAccount, final int count) {
Rohan Shah671133b2013-03-26 14:48:10 -070070 mAccountTextView.setText(account.name);
Rohan Shahb9587012013-03-20 14:34:38 -070071 setUnreadCount(count);
Rohan Shahc1e45062013-04-28 10:50:49 -070072 mUnreadCountTextView.setSelected(isCurrentAccount);
73 mAccountTextView.setSelected(isCurrentAccount);
74 mSelectedButton.setSelected(isCurrentAccount);
Rohan Shahb9587012013-03-20 14:34:38 -070075 }
76
77 /**
Rohan Shah671133b2013-03-26 14:48:10 -070078 * Sets the unread count, taking care to hide/show the textview if the count
79 * is zero/non-zero.
Rohan Shahb9587012013-03-20 14:34:38 -070080 */
Rohan Shah074a5a12013-04-04 17:43:15 -070081 private void setUnreadCount(final int count) {
Rohan Shahb9587012013-03-20 14:34:38 -070082 mUnreadCountTextView.setVisibility(count > 0 ? View.VISIBLE : View.GONE);
83 if (count > 0) {
84 mUnreadCountTextView.setText(Utils.getUnreadCountString(getContext(), count));
85 }
86 }
Rohan Shahb9587012013-03-20 14:34:38 -070087}