Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7)

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/download/DownloadActivity.java

Issue 2271583006: [Android] Implement back key functionality in download manager (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@loading
Patch Set: fix test Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | chrome/android/java/src/org/chromium/chrome/browser/download/ui/DownloadFilter.java » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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; 5 package org.chromium.chrome.browser.download;
6 6
7 import android.content.ComponentName; 7 import android.content.ComponentName;
8 import android.os.Bundle; 8 import android.os.Bundle;
9 9
10 import org.chromium.base.VisibleForTesting; 10 import org.chromium.base.VisibleForTesting;
11 import org.chromium.chrome.browser.IntentHandler; 11 import org.chromium.chrome.browser.IntentHandler;
12 import org.chromium.chrome.browser.SnackbarActivity; 12 import org.chromium.chrome.browser.SnackbarActivity;
13 import org.chromium.chrome.browser.UrlConstants;
14 import org.chromium.chrome.browser.download.ui.DownloadFilter;
13 import org.chromium.chrome.browser.download.ui.DownloadManagerUi; 15 import org.chromium.chrome.browser.download.ui.DownloadManagerUi;
16 import org.chromium.chrome.browser.download.ui.DownloadManagerUi.DownloadUiObser ver;
14 import org.chromium.chrome.browser.util.IntentUtils; 17 import org.chromium.chrome.browser.util.IntentUtils;
15 18
19 import java.util.Deque;
20 import java.util.LinkedList;
21
16 /** 22 /**
17 * Activity for managing downloads handled through Chrome. 23 * Activity for managing downloads handled through Chrome.
18 */ 24 */
19 public class DownloadActivity extends SnackbarActivity { 25 public class DownloadActivity extends SnackbarActivity {
20 private DownloadManagerUi mDownloadManagerUi; 26 private DownloadManagerUi mDownloadManagerUi;
21 private boolean mIsOffTheRecord; 27 private boolean mIsOffTheRecord;
22 28
29 /** Caches the stack of filters applied to let the user backtrack through th eir history. */
30 private final Deque<String> mBackStack = new LinkedList<>();
31
32 private final DownloadUiObserver mUiObserver = new DownloadUiObserver() {
33 @Override
34 public void onManagerDestroyed() { }
35
36 @Override
37 public void onFilterChanged(int filter) {
38 String url = DownloadFilter.getUrlForFilter(filter);
39 if (mBackStack.isEmpty() || !mBackStack.peek().equals(url)) {
40 mBackStack.push(url);
41 }
42 }
43 };
44
23 @Override 45 @Override
24 public void onCreate(Bundle savedInstanceState) { 46 public void onCreate(Bundle savedInstanceState) {
25 super.onCreate(savedInstanceState); 47 super.onCreate(savedInstanceState);
26 48
27 boolean isOffTheRecord = DownloadUtils.shouldShowOffTheRecordDownloads(g etIntent()); 49 boolean isOffTheRecord = DownloadUtils.shouldShowOffTheRecordDownloads(g etIntent());
28 ComponentName parentComponent = IntentUtils.safeGetParcelableExtra( 50 ComponentName parentComponent = IntentUtils.safeGetParcelableExtra(
29 getIntent(), IntentHandler.EXTRA_PARENT_COMPONENT); 51 getIntent(), IntentHandler.EXTRA_PARENT_COMPONENT);
30 mDownloadManagerUi = new DownloadManagerUi(this, isOffTheRecord, parentC omponent); 52 mDownloadManagerUi = new DownloadManagerUi(this, isOffTheRecord, parentC omponent);
31 setContentView(mDownloadManagerUi.getView()); 53 setContentView(mDownloadManagerUi.getView());
32 mIsOffTheRecord = isOffTheRecord; 54 mIsOffTheRecord = isOffTheRecord;
55 mDownloadManagerUi.addObserver(mUiObserver);
56 // Call updateForUrl() to align with how DownloadPage interacts with Dow nloadManagerUi.
57 mDownloadManagerUi.updateForUrl(UrlConstants.DOWNLOADS_URL);
33 } 58 }
34 59
35 @Override 60 @Override
36 public void onResume() { 61 public void onResume() {
37 super.onResume(); 62 super.onResume();
38 DownloadUtils.checkForExternallyRemovedDownloads(mDownloadManagerUi.getB ackendProvider(), 63 DownloadUtils.checkForExternallyRemovedDownloads(mDownloadManagerUi.getB ackendProvider(),
39 mIsOffTheRecord); 64 mIsOffTheRecord);
40 } 65 }
41 66
42 @Override 67 @Override
43 public void onBackPressed() { 68 public void onBackPressed() {
44 if (!mDownloadManagerUi.onBackPressed()) super.onBackPressed(); 69 if (mDownloadManagerUi.onBackPressed()) return;
70 // The top of the stack always represents the current filter. When back is pressed,
71 // the top is popped off and the new top indicates what filter to use. I f there are
72 // no filters remaining, the Activity itself is closed.
73 if (mBackStack.size() > 1) {
74 mBackStack.pop();
75 mDownloadManagerUi.updateForUrl(mBackStack.peek());
76 } else {
77 if (!mBackStack.isEmpty()) mBackStack.pop();
78 super.onBackPressed();
79 }
45 } 80 }
46 81
47 @Override 82 @Override
48 protected void onDestroy() { 83 protected void onDestroy() {
49 mDownloadManagerUi.onDestroyed(); 84 mDownloadManagerUi.onDestroyed();
50 super.onDestroy(); 85 super.onDestroy();
51 } 86 }
52 87
53 @VisibleForTesting 88 @VisibleForTesting
54 DownloadManagerUi getDownloadManagerUiForTests() { 89 DownloadManagerUi getDownloadManagerUiForTests() {
55 return mDownloadManagerUi; 90 return mDownloadManagerUi;
56 } 91 }
57 } 92 }
OLDNEW
« no previous file with comments | « no previous file | chrome/android/java/src/org/chromium/chrome/browser/download/ui/DownloadFilter.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698