Commit ba44cdfb authored by ianwen's avatar ianwen Committed by Commit bot

[Android] Introduce DateDividedAdapter to Chrome

This CL brings DateDividedAdapter to Chrome, and lets Download Manager
UI to utilize it. This adapter will take a list of timed items, groups
these items by date, and displays the groups in sections.

BUG=616324

Review-Url: https://codereview.chromium.org/2154063003
Cr-Commit-Position: refs/heads/master@{#406641}
parent 474d850f
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2016 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file. -->
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
style="@style/RobotoMediumStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:layout_marginEnd="16dp"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:textSize="16sp" />
......@@ -553,6 +553,11 @@
<item name="android:paddingEnd">16dp</item>
<item name="android:background">?attr/listChoiceBackgroundIndicator</item>
</style>
<style name="RobotoMediumStyle">
<item name="android:fontFamily">sans-serif</item>
<item name="android:textStyle">bold</item>
</style>
<!-- New tab page RecyclerView overscroll color -->
<style name="NewTabPageRecyclerView">
<item name="android:colorEdgeEffect">@color/google_grey_300</item>
......
......@@ -4,6 +4,9 @@
found in the LICENSE file. -->
<resources>
<style name="RobotoMediumStyle">
<item name="android:fontFamily">sans-serif-medium</item>
</style>
<!-- Preferences -->
<style name="PreferencesTheme" parent="ThemeWithActionBar">
<item name="android:textColorLink">@color/pref_accent_color</item>
......
......@@ -4,11 +4,13 @@
package org.chromium.chrome.browser.download;
import org.chromium.chrome.browser.widget.DateDividedAdapter.TimedItem;
/**
* A generic class representing a download item. The item can be either downloaded through the
* Android DownloadManager, or through Chrome's network stack
*/
public class DownloadItem {
public class DownloadItem implements TimedItem {
static final long INVALID_DOWNLOAD_ID = -1L;
private boolean mUseAndroidDownloadManager;
private DownloadInfo mDownloadInfo;
......@@ -83,6 +85,7 @@ public class DownloadItem {
*
* @return Download start time from System.currentTimeMillis().
*/
@Override
public long getStartTime() {
return mStartTime;
}
......
......@@ -6,6 +6,7 @@ package org.chromium.chrome.browser.download.ui;
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.RecyclerView.ViewHolder;
import android.text.TextUtils;
import android.text.format.Formatter;
import android.view.LayoutInflater;
......@@ -17,22 +18,21 @@ import android.widget.TextView;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.download.DownloadItem;
import org.chromium.chrome.browser.util.UrlUtilities;
import org.chromium.chrome.browser.widget.DateDividedAdapter;
import java.util.ArrayList;
import java.util.List;
/** Bridges the user's download history and the UI used to display it. */
public class DownloadHistoryAdapter
extends RecyclerView.Adapter<DownloadHistoryAdapter.ViewHolder> {
public class DownloadHistoryAdapter extends DateDividedAdapter {
/** Holds onto a View that displays information about a downloaded file. */
static class ViewHolder extends RecyclerView.ViewHolder {
static class ItemViewHolder extends RecyclerView.ViewHolder {
public ImageView mIconView;
public TextView mFilenameView;
public TextView mHostnameView;
public TextView mFilesizeView;
public ViewHolder(View itemView) {
public ItemViewHolder(View itemView) {
super(itemView);
mIconView = (ImageView) itemView.findViewById(R.id.icon_view);
mFilenameView = (TextView) itemView.findViewById(R.id.filename_view);
......@@ -53,27 +53,28 @@ public class DownloadHistoryAdapter
private static final String MIMETYPE_IMAGE = "image";
private static final String MIMETYPE_DOCUMENT = "text";
private final List<DownloadItem> mDownloadItems = new ArrayList<>();
/** Called when the user's download history has been gathered into a List of DownloadItems. */
public void onAllDownloadsRetrieved(List<DownloadItem> list) {
mDownloadItems.clear();
for (DownloadItem item : list) mDownloadItems.add(item);
notifyDataSetChanged();
loadItems(list);
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
protected int getTimedItemViewResId() {
return R.layout.download_date_view;
}
@Override
public ViewHolder createViewHolder(ViewGroup parent) {
View v = LayoutInflater.from(parent.getContext()).inflate(
R.layout.download_item_view, parent, false);
return new ViewHolder(v);
return new ItemViewHolder(v);
}
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
public void bindViewHolderForTimedItem(ViewHolder current, TimedItem timedItem) {
ItemViewHolder holder = (ItemViewHolder) current;
Context context = holder.mFilesizeView.getContext();
DownloadItem item = mDownloadItems.get(position);
DownloadItem item = (DownloadItem) timedItem;
holder.mFilenameView.setText(item.getDownloadInfo().getFileName());
holder.mHostnameView.setText(
UrlUtilities.formatUrlForSecurityDisplay(item.getDownloadInfo().getUrl(), false));
......@@ -105,16 +106,6 @@ public class DownloadHistoryAdapter
holder.mIconView.setImageResource(iconResource);
}
@Override
public int getItemCount() {
return mDownloadItems.size();
}
/** Clears out all of the downloads tracked by the Adapter. */
public void clear() {
mDownloadItems.clear();
}
/** Identifies the type of file represented by the given MIME type string. */
private static int convertMimeTypeToFileType(String mimeType) {
if (TextUtils.isEmpty(mimeType)) return FILETYPE_OTHER;
......
......@@ -189,6 +189,12 @@ CHAR-LIMIT guidelines:
<message name="IDS_HELP" desc="Generic label for a button that displays help for the current screen.">
Help
</message>
<message name="IDS_TODAY" desc="Generic Label saying the date is today.">
Today
</message>
<message name="IDS_YESTERDAY" desc="Generic Label saying the date is yesterday.">
Yesterday
</message>
<!-- Main Preferences -->
<message name="IDS_PREFERENCES" desc="Title for Chrome's Settings.">
......
......@@ -956,6 +956,7 @@ chrome_java_sources = [
"java/src/org/chromium/chrome/browser/widget/ClipDrawableProgressBar.java",
"java/src/org/chromium/chrome/browser/widget/CompatibilityTextInputLayout.java",
"java/src/org/chromium/chrome/browser/widget/ControlContainer.java",
"java/src/org/chromium/chrome/browser/widget/DateDividedAdapter.java",
"java/src/org/chromium/chrome/browser/widget/DualControlLayout.java",
"java/src/org/chromium/chrome/browser/widget/EmptyAlertEditText.java",
"java/src/org/chromium/chrome/browser/widget/FadingShadow.java",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment