| 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.net.Uri; | 11 import android.net.Uri; |
| 12 import android.os.AsyncTask; | 12 import android.os.AsyncTask; |
| 13 import android.os.StrictMode; | 13 import android.os.StrictMode; |
| 14 import android.support.graphics.drawable.VectorDrawableCompat; |
| 14 import android.support.v4.view.GravityCompat; | 15 import android.support.v4.view.GravityCompat; |
| 15 import android.support.v4.widget.DrawerLayout; | 16 import android.support.v4.widget.DrawerLayout; |
| 16 import android.support.v4.widget.DrawerLayout.DrawerListener; | 17 import android.support.v4.widget.DrawerLayout.DrawerListener; |
| 17 import android.support.v7.widget.LinearLayoutManager; | 18 import android.support.v7.widget.LinearLayoutManager; |
| 18 import android.support.v7.widget.RecyclerView; | 19 import android.support.v7.widget.RecyclerView; |
| 19 import android.support.v7.widget.RecyclerView.AdapterDataObserver; | 20 import android.support.v7.widget.RecyclerView.AdapterDataObserver; |
| 20 import android.support.v7.widget.Toolbar.OnMenuItemClickListener; | 21 import android.support.v7.widget.Toolbar.OnMenuItemClickListener; |
| 21 import android.text.TextUtils; | 22 import android.text.TextUtils; |
| 22 import android.view.Gravity; | 23 import android.view.Gravity; |
| 23 import android.view.LayoutInflater; | 24 import android.view.LayoutInflater; |
| 24 import android.view.MenuItem; | 25 import android.view.MenuItem; |
| 25 import android.view.View; | 26 import android.view.View; |
| 26 import android.view.ViewGroup; | 27 import android.view.ViewGroup; |
| 27 import android.widget.ListView; | 28 import android.widget.ListView; |
| 29 import android.widget.TextView; |
| 28 | 30 |
| 29 import org.chromium.base.ApiCompatibilityUtils; | 31 import org.chromium.base.ApiCompatibilityUtils; |
| 30 import org.chromium.base.ContentUriUtils; | 32 import org.chromium.base.ContentUriUtils; |
| 31 import org.chromium.base.ContextUtils; | 33 import org.chromium.base.ContextUtils; |
| 32 import org.chromium.base.FileUtils; | 34 import org.chromium.base.FileUtils; |
| 33 import org.chromium.base.Log; | 35 import org.chromium.base.Log; |
| 34 import org.chromium.base.ObserverList; | 36 import org.chromium.base.ObserverList; |
| 35 import org.chromium.base.VisibleForTesting; | 37 import org.chromium.base.VisibleForTesting; |
| 36 import org.chromium.base.metrics.RecordHistogram; | 38 import org.chromium.base.metrics.RecordHistogram; |
| 37 import org.chromium.base.metrics.RecordUserAction; | 39 import org.chromium.base.metrics.RecordUserAction; |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 private final ObserverList<DownloadUiObserver> mObservers = new ObserverList
<>(); | 132 private final ObserverList<DownloadUiObserver> mObservers = new ObserverList
<>(); |
| 131 private final BackendProvider mBackendProvider; | 133 private final BackendProvider mBackendProvider; |
| 132 | 134 |
| 133 private final Activity mActivity; | 135 private final Activity mActivity; |
| 134 private final boolean mIsOffTheRecord; | 136 private final boolean mIsOffTheRecord; |
| 135 private final ViewGroup mMainView; | 137 private final ViewGroup mMainView; |
| 136 private final DownloadManagerToolbar mToolbar; | 138 private final DownloadManagerToolbar mToolbar; |
| 137 private final SpaceDisplay mSpaceDisplay; | 139 private final SpaceDisplay mSpaceDisplay; |
| 138 private final ListView mFilterView; | 140 private final ListView mFilterView; |
| 139 private final RecyclerView mRecyclerView; | 141 private final RecyclerView mRecyclerView; |
| 140 private final View mEmptyView; | 142 private final TextView mEmptyView; |
| 141 private final LoadingView mLoadingView; | 143 private final LoadingView mLoadingView; |
| 142 | 144 |
| 143 private BasicNativePage mNativePage; | 145 private BasicNativePage mNativePage; |
| 144 | 146 |
| 145 private final AdapterDataObserver mAdapterObserver = new AdapterDataObserver
() { | 147 private final AdapterDataObserver mAdapterObserver = new AdapterDataObserver
() { |
| 146 @Override | 148 @Override |
| 147 public void onChanged() { | 149 public void onChanged() { |
| 148 if (mHistoryAdapter.getItemCount() == 0) { | 150 if (mHistoryAdapter.getItemCount() == 0) { |
| 149 mEmptyView.setVisibility(View.VISIBLE); | 151 mEmptyView.setVisibility(View.VISIBLE); |
| 150 mRecyclerView.setVisibility(View.GONE); | 152 mRecyclerView.setVisibility(View.GONE); |
| 151 } else { | 153 } else { |
| 152 mEmptyView.setVisibility(View.GONE); | 154 mEmptyView.setVisibility(View.GONE); |
| 153 mRecyclerView.setVisibility(View.VISIBLE); | 155 mRecyclerView.setVisibility(View.VISIBLE); |
| 154 } | 156 } |
| 155 // At inflation, the RecyclerView is set to gone, and the loading vi
ew is visible. As | 157 // At inflation, the RecyclerView is set to gone, and the loading vi
ew is visible. As |
| 156 // long as the adapter data changes, we show the recycler view, and
hide loading view. | 158 // long as the adapter data changes, we show the recycler view, and
hide loading view. |
| 157 mLoadingView.hideLoadingUI(); | 159 mLoadingView.hideLoadingUI(); |
| 158 } | 160 } |
| 159 }; | 161 }; |
| 160 | 162 |
| 161 public DownloadManagerUi( | 163 public DownloadManagerUi( |
| 162 Activity activity, boolean isOffTheRecord, ComponentName parentCompo
nent) { | 164 Activity activity, boolean isOffTheRecord, ComponentName parentCompo
nent) { |
| 163 mActivity = activity; | 165 mActivity = activity; |
| 164 mIsOffTheRecord = isOffTheRecord; | 166 mIsOffTheRecord = isOffTheRecord; |
| 165 mBackendProvider = | 167 mBackendProvider = |
| 166 sProviderForTests == null ? new DownloadBackendProvider() : sPro
viderForTests; | 168 sProviderForTests == null ? new DownloadBackendProvider() : sPro
viderForTests; |
| 167 | 169 |
| 168 mMainView = (ViewGroup) LayoutInflater.from(activity).inflate(R.layout.d
ownload_main, null); | 170 mMainView = (ViewGroup) LayoutInflater.from(activity).inflate(R.layout.d
ownload_main, null); |
| 169 | 171 |
| 170 mEmptyView = mMainView.findViewById(R.id.empty_view); | 172 mEmptyView = (TextView) mMainView.findViewById(R.id.empty_view); |
| 173 mEmptyView.setCompoundDrawablesWithIntrinsicBounds(null, VectorDrawableC
ompat |
| 174 .create(activity.getResources(), R.drawable.downloads_big, activ
ity.getTheme()), |
| 175 null, null); |
| 171 mLoadingView = (LoadingView) mMainView.findViewById(R.id.loading_view); | 176 mLoadingView = (LoadingView) mMainView.findViewById(R.id.loading_view); |
| 172 mLoadingView.showLoadingUI(); | 177 mLoadingView.showLoadingUI(); |
| 173 | 178 |
| 174 mHistoryAdapter = new DownloadHistoryAdapter(isOffTheRecord, parentCompo
nent); | 179 mHistoryAdapter = new DownloadHistoryAdapter(isOffTheRecord, parentCompo
nent); |
| 175 mHistoryAdapter.registerAdapterDataObserver(mAdapterObserver); | 180 mHistoryAdapter.registerAdapterDataObserver(mAdapterObserver); |
| 176 mHistoryAdapter.initialize(mBackendProvider); | 181 mHistoryAdapter.initialize(mBackendProvider); |
| 177 addObserver(mHistoryAdapter); | 182 addObserver(mHistoryAdapter); |
| 178 | 183 |
| 179 mSpaceDisplay = new SpaceDisplay(mMainView, mHistoryAdapter); | 184 mSpaceDisplay = new SpaceDisplay(mMainView, mHistoryAdapter); |
| 180 mHistoryAdapter.registerAdapterDataObserver(mSpaceDisplay); | 185 mHistoryAdapter.registerAdapterDataObserver(mSpaceDisplay); |
| (...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 562 public DownloadHistoryAdapter getDownloadHistoryAdapterForTests() { | 567 public DownloadHistoryAdapter getDownloadHistoryAdapterForTests() { |
| 563 return mHistoryAdapter; | 568 return mHistoryAdapter; |
| 564 } | 569 } |
| 565 | 570 |
| 566 /** Sets a BackendProvider that is used in place of a real one. */ | 571 /** Sets a BackendProvider that is used in place of a real one. */ |
| 567 @VisibleForTesting | 572 @VisibleForTesting |
| 568 public static void setProviderForTests(BackendProvider provider) { | 573 public static void setProviderForTests(BackendProvider provider) { |
| 569 sProviderForTests = provider; | 574 sProviderForTests = provider; |
| 570 } | 575 } |
| 571 } | 576 } |
| OLD | NEW |