OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.chrome.browser.download; | 5 package org.chromium.chrome.browser.download; |
6 | 6 |
7 import android.app.Activity; | 7 import android.app.Activity; |
| 8 import android.support.v7.widget.Toolbar; |
8 import android.view.View; | 9 import android.view.View; |
9 | 10 |
10 import org.chromium.base.ActivityState; | 11 import org.chromium.base.ActivityState; |
11 import org.chromium.base.ApplicationStatus; | 12 import org.chromium.base.ApplicationStatus; |
12 import org.chromium.base.ApplicationStatus.ActivityStateListener; | 13 import org.chromium.base.ApplicationStatus.ActivityStateListener; |
13 import org.chromium.base.ThreadUtils; | 14 import org.chromium.base.ThreadUtils; |
| 15 import org.chromium.chrome.browser.ChromeActivity; |
14 import org.chromium.chrome.browser.download.ui.DownloadManagerUi; | 16 import org.chromium.chrome.browser.download.ui.DownloadManagerUi; |
| 17 import org.chromium.chrome.browser.toolbar.BottomToolbarPhone; |
15 import org.chromium.chrome.browser.widget.BottomSheet.BottomSheetContent; | 18 import org.chromium.chrome.browser.widget.BottomSheet.BottomSheetContent; |
16 | 19 |
17 /** | 20 /** |
18 * A {@link BottomSheetContent} holding a {@link DownloadManagerUi} for display
in the BottomSheet. | 21 * A {@link BottomSheetContent} holding a {@link DownloadManagerUi} for display
in the BottomSheet. |
19 */ | 22 */ |
20 public class DownloadSheetContent implements BottomSheetContent { | 23 public class DownloadSheetContent implements BottomSheetContent { |
21 private final View mContentView; | 24 private final View mContentView; |
| 25 private final Toolbar mToolbarView; |
22 private final ActivityStateListener mActivityStateListener; | 26 private final ActivityStateListener mActivityStateListener; |
23 private DownloadManagerUi mDownloadManager; | 27 private DownloadManagerUi mDownloadManager; |
24 | 28 |
25 /** | 29 /** |
26 * @param activity The activity displaying the download manager UI. | 30 * @param activity The activity displaying the download manager UI. |
27 * @param isIncognito Whether the activity is currently displaying an incogn
ito tab. | 31 * @param isIncognito Whether the activity is currently displaying an incogn
ito tab. |
28 */ | 32 */ |
29 public DownloadSheetContent(Activity activity, final boolean isIncognito) { | 33 public DownloadSheetContent(ChromeActivity activity, final boolean isIncogni
to) { |
30 ThreadUtils.assertOnUiThread(); | 34 ThreadUtils.assertOnUiThread(); |
31 | 35 |
32 mDownloadManager = | 36 mDownloadManager = |
33 new DownloadManagerUi(activity, isIncognito, activity.getCompone
ntName()); | 37 new DownloadManagerUi(activity, isIncognito, activity.getCompone
ntName(), false); |
34 mContentView = mDownloadManager.detachContentView(); | 38 mContentView = mDownloadManager.getView(); |
| 39 mToolbarView = mDownloadManager.detachToolbarView(); |
| 40 ((BottomToolbarPhone) activity.getToolbarManager().getToolbar()) |
| 41 .setOtherToolbarStyle(mToolbarView); |
35 | 42 |
36 // #destroy() unregisters the ActivityStateListener to avoid checking fo
r externally removed | 43 // #destroy() unregisters the ActivityStateListener to avoid checking fo
r externally removed |
37 // downloads after the downloads UI is closed. This requires each downlo
ad UI to have its | 44 // downloads after the downloads UI is closed. This requires each downlo
ad UI to have its |
38 // own ActivityStateListener. If multiple tabs are showing the downloads
page, multiple | 45 // own ActivityStateListener. If multiple tabs are showing the downloads
page, multiple |
39 // requests to check for externally removed downloads will be issued whe
n the activity is | 46 // requests to check for externally removed downloads will be issued whe
n the activity is |
40 // resumed. | 47 // resumed. |
41 mActivityStateListener = new ActivityStateListener() { | 48 mActivityStateListener = new ActivityStateListener() { |
42 @Override | 49 @Override |
43 public void onActivityStateChange(Activity activity, int newState) { | 50 public void onActivityStateChange(Activity activity, int newState) { |
44 if (newState == ActivityState.RESUMED) { | 51 if (newState == ActivityState.RESUMED) { |
45 DownloadUtils.checkForExternallyRemovedDownloads( | 52 DownloadUtils.checkForExternallyRemovedDownloads( |
46 mDownloadManager.getBackendProvider(), isIncognito); | 53 mDownloadManager.getBackendProvider(), isIncognito); |
47 } | 54 } |
48 } | 55 } |
49 }; | 56 }; |
50 ApplicationStatus.registerStateListenerForActivity(mActivityStateListene
r, activity); | 57 ApplicationStatus.registerStateListenerForActivity(mActivityStateListene
r, activity); |
51 } | 58 } |
52 | 59 |
53 @Override | 60 @Override |
54 public View getContentView() { | 61 public View getContentView() { |
55 return mContentView; | 62 return mContentView; |
56 } | 63 } |
57 | 64 |
58 @Override | 65 @Override |
59 public View getToolbarView() { | 66 public View getToolbarView() { |
60 return null; | 67 return mToolbarView; |
61 } | 68 } |
62 | 69 |
63 @Override | 70 @Override |
64 public int getVerticalScrollOffset() { | 71 public int getVerticalScrollOffset() { |
65 return mDownloadManager.getVerticalScrollOffset(); | 72 return mDownloadManager.getVerticalScrollOffset(); |
66 } | 73 } |
67 | 74 |
68 @Override | 75 @Override |
69 public void destroy() { | 76 public void destroy() { |
70 mDownloadManager.onDestroyed(); | 77 mDownloadManager.onDestroyed(); |
71 mDownloadManager = null; | 78 mDownloadManager = null; |
72 ApplicationStatus.unregisterActivityStateListener(mActivityStateListener
); | 79 ApplicationStatus.unregisterActivityStateListener(mActivityStateListener
); |
73 } | 80 } |
74 } | 81 } |
OLD | NEW |