OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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.ui; | 5 package org.chromium.chrome.browser.download.ui; |
6 | 6 |
7 import android.app.Activity; | 7 import android.app.Activity; |
8 import android.content.ComponentName; | 8 import android.content.ComponentName; |
9 import android.content.Intent; | 9 import android.content.Intent; |
10 import android.content.res.Resources; | 10 import android.content.res.Resources; |
11 import android.os.AsyncTask; | 11 import android.os.AsyncTask; |
12 import android.support.graphics.drawable.VectorDrawableCompat; | 12 import android.support.graphics.drawable.VectorDrawableCompat; |
13 import android.support.v4.view.GravityCompat; | 13 import android.support.v4.view.GravityCompat; |
14 import android.support.v4.widget.DrawerLayout; | 14 import android.support.v4.widget.DrawerLayout; |
15 import android.support.v4.widget.DrawerLayout.DrawerListener; | 15 import android.support.v4.widget.DrawerLayout.DrawerListener; |
16 import android.support.v7.widget.RecyclerView; | 16 import android.support.v7.widget.RecyclerView; |
| 17 import android.support.v7.widget.Toolbar; |
17 import android.support.v7.widget.Toolbar.OnMenuItemClickListener; | 18 import android.support.v7.widget.Toolbar.OnMenuItemClickListener; |
18 import android.view.Gravity; | 19 import android.view.Gravity; |
19 import android.view.LayoutInflater; | 20 import android.view.LayoutInflater; |
20 import android.view.MenuItem; | 21 import android.view.MenuItem; |
21 import android.view.View; | 22 import android.view.View; |
22 import android.view.ViewGroup; | 23 import android.view.ViewGroup; |
23 import android.widget.ListView; | 24 import android.widget.ListView; |
24 | 25 |
25 import org.chromium.base.ContextUtils; | 26 import org.chromium.base.ContextUtils; |
26 import org.chromium.base.FileUtils; | 27 import org.chromium.base.FileUtils; |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 private final SpaceDisplay mSpaceDisplay; | 173 private final SpaceDisplay mSpaceDisplay; |
173 private final ListView mFilterView; | 174 private final ListView mFilterView; |
174 private final UndoDeletionSnackbarController mUndoDeletionSnackbarController
; | 175 private final UndoDeletionSnackbarController mUndoDeletionSnackbarController
; |
175 private final RecyclerView mRecyclerView; | 176 private final RecyclerView mRecyclerView; |
176 | 177 |
177 private BasicNativePage mNativePage; | 178 private BasicNativePage mNativePage; |
178 private Activity mActivity; | 179 private Activity mActivity; |
179 private ViewGroup mMainView; | 180 private ViewGroup mMainView; |
180 private DownloadManagerToolbar mToolbar; | 181 private DownloadManagerToolbar mToolbar; |
181 private SelectableListLayout<DownloadHistoryItemWrapper> mSelectableListLayo
ut; | 182 private SelectableListLayout<DownloadHistoryItemWrapper> mSelectableListLayo
ut; |
| 183 private boolean mIsSeparateActivity; |
182 | 184 |
183 @SuppressWarnings("unchecked") // mSelectableListLayout | 185 /** |
184 public DownloadManagerUi( | 186 * Constructs a new DownloadManagerUi. |
185 Activity activity, boolean isOffTheRecord, ComponentName parentCompo
nent) { | 187 * @param activity The {@link Activity} associated with the download manager
. |
| 188 * @param isOffTheRecord Whether an off-the-record tab is currently being di
splayed. |
| 189 * @param parentComponent The {@link ComponentName} of the parent activity. |
| 190 * @param isSeparateActivity Whether the download manager UI will be shown i
n a separate |
| 191 * activity than the main Chrome activity. |
| 192 */ |
| 193 @SuppressWarnings("unchecked") // mSelectableListLayout |
| 194 public DownloadManagerUi(Activity activity, boolean isOffTheRecord, |
| 195 ComponentName parentComponent, boolean isSeparateActivity) { |
186 mActivity = activity; | 196 mActivity = activity; |
187 mBackendProvider = | 197 mBackendProvider = |
188 sProviderForTests == null ? new DownloadBackendProvider() : sPro
viderForTests; | 198 sProviderForTests == null ? new DownloadBackendProvider() : sPro
viderForTests; |
189 | 199 |
190 mMainView = (ViewGroup) LayoutInflater.from(activity).inflate(R.layout.d
ownload_main, null); | 200 mMainView = (ViewGroup) LayoutInflater.from(activity).inflate(R.layout.d
ownload_main, null); |
191 | 201 |
192 DrawerLayout drawerLayout = null; | 202 DrawerLayout drawerLayout = null; |
193 if (!DeviceFormFactor.isLargeTablet(activity)) { | 203 if (!DeviceFormFactor.isLargeTablet(activity)) { |
194 drawerLayout = (DrawerLayout) mMainView; | 204 drawerLayout = (DrawerLayout) mMainView; |
195 addDrawerListener(drawerLayout); | 205 addDrawerListener(drawerLayout); |
(...skipping 30 matching lines...) Expand all Loading... |
226 this); | 236 this); |
227 mToolbar.setTitle(R.string.menu_downloads); | 237 mToolbar.setTitle(R.string.menu_downloads); |
228 mToolbar.initializeSearchView(this, R.string.download_manager_search, R.
id.search_menu_id); | 238 mToolbar.initializeSearchView(this, R.string.download_manager_search, R.
id.search_menu_id); |
229 addObserver(mToolbar); | 239 addObserver(mToolbar); |
230 | 240 |
231 mFilterView = (ListView) mMainView.findViewById(R.id.section_list); | 241 mFilterView = (ListView) mMainView.findViewById(R.id.section_list); |
232 mFilterView.setAdapter(mFilterAdapter); | 242 mFilterView.setAdapter(mFilterAdapter); |
233 mFilterView.setOnItemClickListener(mFilterAdapter); | 243 mFilterView.setOnItemClickListener(mFilterAdapter); |
234 | 244 |
235 mUndoDeletionSnackbarController = new UndoDeletionSnackbarController(); | 245 mUndoDeletionSnackbarController = new UndoDeletionSnackbarController(); |
| 246 |
| 247 mIsSeparateActivity = isSeparateActivity; |
| 248 if (!mIsSeparateActivity) mToolbar.removeCloseButton(); |
236 } | 249 } |
237 | 250 |
238 /** | 251 /** |
239 * Sets the {@link BasicNativePage} that holds this manager. | 252 * Sets the {@link BasicNativePage} that holds this manager. |
240 */ | 253 */ |
241 public void setBasicNativePage(BasicNativePage delegate) { | 254 public void setBasicNativePage(BasicNativePage delegate) { |
242 mNativePage = delegate; | 255 mNativePage = delegate; |
243 } | 256 } |
244 | 257 |
245 /** | 258 /** |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
281 } | 294 } |
282 | 295 |
283 /** | 296 /** |
284 * @return The view that shows the main download UI. | 297 * @return The view that shows the main download UI. |
285 */ | 298 */ |
286 public ViewGroup getView() { | 299 public ViewGroup getView() { |
287 return mMainView; | 300 return mMainView; |
288 } | 301 } |
289 | 302 |
290 /** | 303 /** |
291 * See {@link SelectableListLayout#detachContentView()}. | 304 * See {@link SelectableListLayout#detachToolbarView()}. |
292 */ | 305 */ |
293 public View detachContentView() { | 306 public Toolbar detachToolbarView() { |
294 return mSelectableListLayout.detachContentView(); | 307 return mSelectableListLayout.detachToolbarView(); |
295 } | 308 } |
296 | 309 |
297 /** | 310 /** |
298 * @return The vertical scroll offset of the content view. | 311 * @return The vertical scroll offset of the content view. |
299 */ | 312 */ |
300 public int getVerticalScrollOffset() { | 313 public int getVerticalScrollOffset() { |
301 return mRecyclerView.computeVerticalScrollOffset(); | 314 return mRecyclerView.computeVerticalScrollOffset(); |
302 } | 315 } |
303 | 316 |
304 /** | 317 /** |
305 * Sets the download manager to the state that the url represents. | 318 * Sets the download manager to the state that the url represents. |
306 */ | 319 */ |
307 public void updateForUrl(String url) { | 320 public void updateForUrl(String url) { |
308 int filter = DownloadFilter.getFilterFromUrl(url); | 321 int filter = DownloadFilter.getFilterFromUrl(url); |
309 onFilterChanged(filter); | 322 onFilterChanged(filter); |
310 } | 323 } |
311 | 324 |
312 @Override | 325 @Override |
313 public boolean onMenuItemClick(MenuItem item) { | 326 public boolean onMenuItemClick(MenuItem item) { |
314 if (item.getItemId() == R.id.close_menu_id && !DeviceFormFactor.isTablet
(mActivity)) { | 327 if (item.getItemId() == R.id.close_menu_id && mIsSeparateActivity) { |
315 mActivity.finish(); | 328 mActivity.finish(); |
316 return true; | 329 return true; |
317 } else if (item.getItemId() == R.id.selection_mode_delete_menu_id) { | 330 } else if (item.getItemId() == R.id.selection_mode_delete_menu_id) { |
318 deleteSelectedItems(); | 331 deleteSelectedItems(); |
319 return true; | 332 return true; |
320 } else if (item.getItemId() == R.id.selection_mode_share_menu_id) { | 333 } else if (item.getItemId() == R.id.selection_mode_share_menu_id) { |
321 shareSelectedItems(); | 334 shareSelectedItems(); |
322 return true; | 335 return true; |
323 } else if (item.getItemId() == R.id.search_menu_id) { | 336 } else if (item.getItemId() == R.id.search_menu_id) { |
324 mSelectableListLayout.onStartSearch(); | 337 mSelectableListLayout.onStartSearch(); |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
521 public SpaceDisplay getSpaceDisplayForTests() { | 534 public SpaceDisplay getSpaceDisplayForTests() { |
522 return mSpaceDisplay; | 535 return mSpaceDisplay; |
523 } | 536 } |
524 | 537 |
525 /** Sets a BackendProvider that is used in place of a real one. */ | 538 /** Sets a BackendProvider that is used in place of a real one. */ |
526 @VisibleForTesting | 539 @VisibleForTesting |
527 public static void setProviderForTests(BackendProvider provider) { | 540 public static void setProviderForTests(BackendProvider provider) { |
528 sProviderForTests = provider; | 541 sProviderForTests = provider; |
529 } | 542 } |
530 } | 543 } |
OLD | NEW |