OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 package org.chromium.chrome.browser.download.ui; |
| 6 |
| 7 import android.content.Context; |
| 8 import android.text.format.Formatter; |
| 9 import android.util.AttributeSet; |
| 10 import android.view.View; |
| 11 import android.widget.FrameLayout; |
| 12 import android.widget.ImageView; |
| 13 import android.widget.TextView; |
| 14 |
| 15 import org.chromium.chrome.R; |
| 16 |
| 17 import java.util.Date; |
| 18 |
| 19 /** |
| 20 * A header that presents users the option to view or hide the suggested offline
pages. |
| 21 * TODO(shaktisahu): Make this layout selectable. |
| 22 */ |
| 23 public class OfflineGroupHeaderView extends FrameLayout { |
| 24 private Date mDate; |
| 25 private DownloadHistoryAdapter mAdapter; |
| 26 |
| 27 private TextView mPageCountHeader; |
| 28 private TextView mFileSizeView; |
| 29 private ImageView mImageView; |
| 30 |
| 31 public OfflineGroupHeaderView(Context context, AttributeSet attrs) { |
| 32 super(context, attrs); |
| 33 setOnClickListener(new View.OnClickListener() { |
| 34 @Override |
| 35 public void onClick(View v) { |
| 36 boolean newState = !mAdapter.isSubsectionExpanded(mDate); |
| 37 mAdapter.setSubsectionExpanded(mDate, newState); |
| 38 updateImageView(newState); |
| 39 } |
| 40 }); |
| 41 } |
| 42 |
| 43 @Override |
| 44 protected void onFinishInflate() { |
| 45 super.onFinishInflate(); |
| 46 mPageCountHeader = (TextView) findViewById(R.id.page_count_text); |
| 47 mFileSizeView = (TextView) findViewById(R.id.filesize_view); |
| 48 mImageView = (ImageView) findViewById(R.id.expand_icon); |
| 49 } |
| 50 |
| 51 /** |
| 52 * @param adapter The adapter associated with this header. |
| 53 */ |
| 54 public void setAdapter(DownloadHistoryAdapter adapter) { |
| 55 mAdapter = adapter; |
| 56 } |
| 57 |
| 58 /** |
| 59 * Updates the properties of this header. |
| 60 * @param date The date associated with this header. |
| 61 * @param expanded Whether the items should be expanded or not. |
| 62 * @param pageCount The total number of associated pages. |
| 63 * @param fileSize The total file size of all the associated pages. |
| 64 */ |
| 65 public void update(Date date, boolean expanded, int pageCount, long fileSize
) { |
| 66 mDate = new Date(date.getTime()); |
| 67 mPageCountHeader.setText(getResources().getString( |
| 68 R.string.download_manager_offline_header_title, pageCount)); |
| 69 mFileSizeView.setText(Formatter.formatFileSize(getContext(), fileSize)); |
| 70 updateImageView(expanded); |
| 71 } |
| 72 |
| 73 private void updateImageView(boolean expanded) { |
| 74 mImageView.setImageResource(expanded ? R.drawable.ic_collapsed : R.drawa
ble.ic_expanded); |
| 75 mImageView.setContentDescription( |
| 76 getResources().getString(expanded ? R.string.accessibility_colla
pse_offline_pages |
| 77 : R.string.accessibility_expan
d_offline_pages)); |
| 78 } |
| 79 } |
OLD | NEW |