Commit 1514a0e1 authored by Shakti Sahu's avatar Shakti Sahu Committed by Commit Bot

Downloads : Tapping on prefetched content notification

Tapping on the notification for prefetched content should open
downloads home and expand the prefetch content section.

Bug: 810098
Change-Id: If2078ab2dfff2d187d8a4331c850a4266c037607
Reviewed-on: https://chromium-review.googlesource.com/907743
Commit-Queue: Shakti Sahu <shaktisahu@chromium.org>
Reviewed-by: default avatarDavid Trainor <dtrainor@chromium.org>
Cr-Commit-Position: refs/heads/master@{#536926}
parent 543aba0b
...@@ -10,7 +10,6 @@ import android.os.Bundle; ...@@ -10,7 +10,6 @@ import android.os.Bundle;
import org.chromium.base.VisibleForTesting; import org.chromium.base.VisibleForTesting;
import org.chromium.chrome.browser.IntentHandler; import org.chromium.chrome.browser.IntentHandler;
import org.chromium.chrome.browser.SnackbarActivity; import org.chromium.chrome.browser.SnackbarActivity;
import org.chromium.chrome.browser.UrlConstants;
import org.chromium.chrome.browser.download.items.OfflineContentAggregatorNotificationBridgeUiFactory; import org.chromium.chrome.browser.download.items.OfflineContentAggregatorNotificationBridgeUiFactory;
import org.chromium.chrome.browser.download.ui.DownloadFilter; import org.chromium.chrome.browser.download.ui.DownloadFilter;
import org.chromium.chrome.browser.download.ui.DownloadManagerUi; import org.chromium.chrome.browser.download.ui.DownloadManagerUi;
...@@ -49,6 +48,8 @@ public class DownloadActivity extends SnackbarActivity { ...@@ -49,6 +48,8 @@ public class DownloadActivity extends SnackbarActivity {
// Loads offline pages and prefetch downloads. // Loads offline pages and prefetch downloads.
OfflineContentAggregatorNotificationBridgeUiFactory.instance(); OfflineContentAggregatorNotificationBridgeUiFactory.instance();
boolean isOffTheRecord = DownloadUtils.shouldShowOffTheRecordDownloads(getIntent()); boolean isOffTheRecord = DownloadUtils.shouldShowOffTheRecordDownloads(getIntent());
String downloadHomeUrl =
IntentUtils.safeGetStringExtra(getIntent(), DownloadUtils.EXTRA_DOWNLOAD_HOME_URL);
ComponentName parentComponent = IntentUtils.safeGetParcelableExtra( ComponentName parentComponent = IntentUtils.safeGetParcelableExtra(
getIntent(), IntentHandler.EXTRA_PARENT_COMPONENT); getIntent(), IntentHandler.EXTRA_PARENT_COMPONENT);
mDownloadManagerUi = new DownloadManagerUi( mDownloadManagerUi = new DownloadManagerUi(
...@@ -56,8 +57,7 @@ public class DownloadActivity extends SnackbarActivity { ...@@ -56,8 +57,7 @@ public class DownloadActivity extends SnackbarActivity {
setContentView(mDownloadManagerUi.getView()); setContentView(mDownloadManagerUi.getView());
mIsOffTheRecord = isOffTheRecord; mIsOffTheRecord = isOffTheRecord;
mDownloadManagerUi.addObserver(mUiObserver); mDownloadManagerUi.addObserver(mUiObserver);
// Call updateForUrl() to align with how DownloadPage interacts with DownloadManagerUi. mDownloadManagerUi.updateForUrl(downloadHomeUrl);
mDownloadManagerUi.updateForUrl(UrlConstants.DOWNLOADS_URL);
} }
@Override @Override
......
...@@ -91,6 +91,9 @@ public class DownloadUtils { ...@@ -91,6 +91,9 @@ public class DownloadUtils {
private static final String EXTRA_IS_OFF_THE_RECORD = private static final String EXTRA_IS_OFF_THE_RECORD =
"org.chromium.chrome.browser.download.IS_OFF_THE_RECORD"; "org.chromium.chrome.browser.download.IS_OFF_THE_RECORD";
public static final String EXTRA_DOWNLOAD_HOME_URL =
"org.chromium.chrome.browser.download.DOWNLOAD_HOME_URL";
public static final String SHOW_PREFETCHED_CONTENT = "ShowPrefetchedContent";
@VisibleForTesting @VisibleForTesting
static final long SECONDS_PER_MINUTE = TimeUnit.MINUTES.toSeconds(1); static final long SECONDS_PER_MINUTE = TimeUnit.MINUTES.toSeconds(1);
...@@ -119,6 +122,19 @@ public class DownloadUtils { ...@@ -119,6 +122,19 @@ public class DownloadUtils {
* @return Whether the UI was shown. * @return Whether the UI was shown.
*/ */
public static boolean showDownloadManager(@Nullable Activity activity, @Nullable Tab tab) { public static boolean showDownloadManager(@Nullable Activity activity, @Nullable Tab tab) {
return showDownloadManager(activity, tab, false);
}
/**
* Displays the download manager UI. Note the UI is different on tablets and on phones.
* @param activity The current activity is available.
* @param tab The current tab if it exists.
* @param showPrefetchedContent Whether the manager should start with prefetched content section
* expanded.
* @return Whether the UI was shown.
*/
public static boolean showDownloadManager(
@Nullable Activity activity, @Nullable Tab tab, boolean showPrefetchedContent) {
// Figure out what tab was last being viewed by the user. // Figure out what tab was last being viewed by the user.
if (activity == null) activity = ApplicationStatus.getLastTrackedFocusedActivity(); if (activity == null) activity = ApplicationStatus.getLastTrackedFocusedActivity();
...@@ -127,10 +143,11 @@ public class DownloadUtils { ...@@ -127,10 +143,11 @@ public class DownloadUtils {
} }
Context appContext = ContextUtils.getApplicationContext(); Context appContext = ContextUtils.getApplicationContext();
String downloadHomeUrl = buildDownloadHomeUrl(showPrefetchedContent);
if (DeviceFormFactor.isTablet()) { if (DeviceFormFactor.isTablet()) {
// Download Home shows up as a tab on tablets. // Download Home shows up as a tab on tablets.
LoadUrlParams params = new LoadUrlParams(UrlConstants.DOWNLOADS_URL); LoadUrlParams params = new LoadUrlParams(downloadHomeUrl);
if (tab == null || !tab.isInitialized()) { if (tab == null || !tab.isInitialized()) {
// Open a new tab, which pops Chrome into the foreground. // Open a new tab, which pops Chrome into the foreground.
TabDelegate delegate = new TabDelegate(false); TabDelegate delegate = new TabDelegate(false);
...@@ -152,6 +169,7 @@ public class DownloadUtils { ...@@ -152,6 +169,7 @@ public class DownloadUtils {
Intent intent = new Intent(); Intent intent = new Intent();
intent.setClass(appContext, DownloadActivity.class); intent.setClass(appContext, DownloadActivity.class);
if (tab != null) intent.putExtra(EXTRA_IS_OFF_THE_RECORD, tab.isIncognito()); if (tab != null) intent.putExtra(EXTRA_IS_OFF_THE_RECORD, tab.isIncognito());
intent.putExtra(EXTRA_DOWNLOAD_HOME_URL, downloadHomeUrl);
if (activity == null) { if (activity == null) {
// Stands alone in its own task. // Stands alone in its own task.
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
...@@ -183,6 +201,18 @@ public class DownloadUtils { ...@@ -183,6 +201,18 @@ public class DownloadUtils {
return IntentUtils.safeGetBooleanExtra(intent, EXTRA_IS_OFF_THE_RECORD, false); return IntentUtils.safeGetBooleanExtra(intent, EXTRA_IS_OFF_THE_RECORD, false);
} }
/**
* Helper method to build the URL for downloads home. The URL can be leveraged for passing extra
* parameters to download home.
* @return The URL for download home.
*/
private static String buildDownloadHomeUrl(boolean showPrefetchedContent) {
Uri.Builder builder = Uri.parse(UrlConstants.DOWNLOADS_URL).buildUpon();
builder.appendQueryParameter(
SHOW_PREFETCHED_CONTENT, Boolean.toString(showPrefetchedContent));
return builder.build().toString();
}
/** /**
* Records metrics related to downloading a page. Should be called after a tap on the download * Records metrics related to downloading a page. Should be called after a tap on the download
* page button. * page button.
......
...@@ -173,6 +173,7 @@ public class DownloadHistoryAdapter extends DateDividedAdapter ...@@ -173,6 +173,7 @@ public class DownloadHistoryAdapter extends DateDividedAdapter
new FilePathsToDownloadItemsMap(); new FilePathsToDownloadItemsMap();
private SubsectionHeader mPrefetchHeader; private SubsectionHeader mPrefetchHeader;
private boolean mShouldPrefetchSectionExpand;
private final ComponentName mParentComponent; private final ComponentName mParentComponent;
private final boolean mShowOffTheRecord; private final boolean mShowOffTheRecord;
private final LoadingStateDelegate mLoadingDelegate; private final LoadingStateDelegate mLoadingDelegate;
...@@ -606,6 +607,7 @@ public class DownloadHistoryAdapter extends DateDividedAdapter ...@@ -606,6 +607,7 @@ public class DownloadHistoryAdapter extends DateDividedAdapter
if (mPrefetchHeader == null) mPrefetchHeader = new SubsectionHeader(); if (mPrefetchHeader == null) mPrefetchHeader = new SubsectionHeader();
mPrefetchHeader.update(prefetchedItems); mPrefetchHeader.update(prefetchedItems);
mPrefetchHeader.setIsExpanded(mShouldPrefetchSectionExpand);
ItemGroup prefetchItemGroup = new PrefetchItemGroup(); ItemGroup prefetchItemGroup = new PrefetchItemGroup();
prefetchItemGroup.addItem(mPrefetchHeader); prefetchItemGroup.addItem(mPrefetchHeader);
...@@ -650,7 +652,7 @@ public class DownloadHistoryAdapter extends DateDividedAdapter ...@@ -650,7 +652,7 @@ public class DownloadHistoryAdapter extends DateDividedAdapter
* @param expanded Whether the prefetched section should be expanded. * @param expanded Whether the prefetched section should be expanded.
*/ */
public void setPrefetchSectionExpanded(boolean expanded) { public void setPrefetchSectionExpanded(boolean expanded) {
mPrefetchHeader.setIsExpanded(expanded); mShouldPrefetchSectionExpand = expanded;
clear(false); clear(false);
filter(mFilter); filter(mFilter);
} }
......
...@@ -7,12 +7,15 @@ package org.chromium.chrome.browser.download.ui; ...@@ -7,12 +7,15 @@ package org.chromium.chrome.browser.download.ui;
import android.app.Activity; import android.app.Activity;
import android.content.ComponentName; import android.content.ComponentName;
import android.content.Intent; import android.content.Intent;
import android.net.Uri;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Handler;
import android.support.annotation.IntDef; import android.support.annotation.IntDef;
import android.support.graphics.drawable.VectorDrawableCompat; import android.support.graphics.drawable.VectorDrawableCompat;
import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar.OnMenuItemClickListener; import android.support.v7.widget.Toolbar.OnMenuItemClickListener;
import android.text.TextUtils;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.ViewGroup; import android.view.ViewGroup;
...@@ -180,6 +183,8 @@ public class DownloadManagerUi ...@@ -180,6 +183,8 @@ public class DownloadManagerUi
private static final int MENU_ACTION_SEARCH = 5; private static final int MENU_ACTION_SEARCH = 5;
private static final int MENU_ACTION_BOUNDARY = 6; private static final int MENU_ACTION_BOUNDARY = 6;
private static final int PREFETCH_BUNDLE_OPEN_DELAY_MS = 500;
private static BackendProvider sProviderForTests; private static BackendProvider sProviderForTests;
private final DownloadHistoryAdapter mHistoryAdapter; private final DownloadHistoryAdapter mHistoryAdapter;
...@@ -341,6 +346,16 @@ public class DownloadManagerUi ...@@ -341,6 +346,16 @@ public class DownloadManagerUi
* Sets the download manager to the state that the url represents. * Sets the download manager to the state that the url represents.
*/ */
public void updateForUrl(String url) { public void updateForUrl(String url) {
if (TextUtils.isEmpty(url)) return;
Uri uri = Uri.parse(url);
boolean showPrefetchedContent =
uri.getBooleanQueryParameter(DownloadUtils.SHOW_PREFETCHED_CONTENT, false);
if (showPrefetchedContent) {
new Handler().postDelayed(() -> {
mHistoryAdapter.setPrefetchSectionExpanded(true);
}, PREFETCH_BUNDLE_OPEN_DELAY_MS);
}
int filter = DownloadFilter.getFilterFromUrl(url); int filter = DownloadFilter.getFilterFromUrl(url);
onFilterChanged(filter); onFilterChanged(filter);
} }
......
...@@ -67,7 +67,7 @@ public class PrefetchedPagesNotifier { ...@@ -67,7 +67,7 @@ public class PrefetchedPagesNotifier {
// TODO(dewittj): Handle the case where we somehow get this broadcast but the Chrome // TODO(dewittj): Handle the case where we somehow get this broadcast but the Chrome
// download manager is unavailable. Today, if this happens then the Android download // download manager is unavailable. Today, if this happens then the Android download
// manager will be launched, and that will not contain any prefetched content. // manager will be launched, and that will not contain any prefetched content.
DownloadUtils.showDownloadManager(null, null); DownloadUtils.showDownloadManager(null, null, true /*showPrefetchedContent*/);
} }
} }
......
...@@ -31,6 +31,7 @@ import org.chromium.base.test.util.CallbackHelper; ...@@ -31,6 +31,7 @@ import org.chromium.base.test.util.CallbackHelper;
import org.chromium.base.test.util.Restriction; import org.chromium.base.test.util.Restriction;
import org.chromium.base.test.util.RetryOnFailure; import org.chromium.base.test.util.RetryOnFailure;
import org.chromium.chrome.R; import org.chromium.chrome.R;
import org.chromium.chrome.browser.UrlConstants;
import org.chromium.chrome.browser.download.ui.DownloadHistoryAdapter; import org.chromium.chrome.browser.download.ui.DownloadHistoryAdapter;
import org.chromium.chrome.browser.download.ui.DownloadHistoryItemViewHolder; import org.chromium.chrome.browser.download.ui.DownloadHistoryItemViewHolder;
import org.chromium.chrome.browser.download.ui.DownloadHistoryItemWrapper; import org.chromium.chrome.browser.download.ui.DownloadHistoryItemWrapper;
...@@ -686,6 +687,7 @@ public class DownloadActivityTest { ...@@ -686,6 +687,7 @@ public class DownloadActivityTest {
// Start the activity up. // Start the activity up.
Intent intent = new Intent(); Intent intent = new Intent();
intent.setClass(InstrumentationRegistry.getTargetContext(), DownloadActivity.class); intent.setClass(InstrumentationRegistry.getTargetContext(), DownloadActivity.class);
intent.putExtra(DownloadUtils.EXTRA_DOWNLOAD_HOME_URL, UrlConstants.DOWNLOADS_URL);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
return mActivityTestRule.launchActivity(intent); return mActivityTestRule.launchActivity(intent);
} }
......
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