Click downloading notification to go to the downloading item
This commit is contained in:
1 parent
cd33a557cd
commit
44c2d25218
3 files changed
+57
-18
No files matched your search
@@ -168,6 +168,11 @@ public class DownloadManager implements SpiderQueen.OnSpiderListener {
|
||||
return mMap.get(label);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public DownloadInfo getDownloadInfo(long gid) {
|
||||
return mAllInfoMap.get(gid);
|
||||
}
|
||||
|
||||
public int getDownloadState(long gid) {
|
||||
DownloadInfo info = mAllInfoMap.get(gid);
|
||||
if (null != info) {
|
||||
|
||||
@@ -209,15 +209,6 @@ public class DownloadService extends Service implements DownloadManager.Download
|
||||
stopAllIntent.setAction(ACTION_STOP_ALL);
|
||||
PendingIntent piStopAll = PendingIntent.getService(this, 0, stopAllIntent, 0);
|
||||
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString(DownloadsScene.KEY_ACTION, DownloadsScene.ACTION_CLEAR_DOWNLOAD_SERVICE);
|
||||
Intent activityIntent = new Intent(this, MainActivity.class);
|
||||
activityIntent.setAction(StageActivity.ACTION_START_SCENE);
|
||||
activityIntent.putExtra(StageActivity.KEY_SCENE_NAME, DownloadsScene.class.getName());
|
||||
activityIntent.putExtra(StageActivity.KEY_SCENE_ARGS, bundle);
|
||||
PendingIntent piActivity = PendingIntent.getActivity(DownloadService.this, 0,
|
||||
activityIntent, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
|
||||
mDownloadingBuilder = new NotificationCompat.Builder(getApplicationContext())
|
||||
.setSmallIcon(android.R.drawable.stat_sys_download)
|
||||
.setOngoing(true)
|
||||
@@ -225,8 +216,7 @@ public class DownloadService extends Service implements DownloadManager.Download
|
||||
.setCategory(NotificationCompat.CATEGORY_PROGRESS)
|
||||
.setColor(getResources().getColor(R.color.colorPrimary))
|
||||
.addAction(R.drawable.ic_pause_x24, getString(R.string.stat_download_action_stop_all), piStopAll)
|
||||
.setShowWhen(false)
|
||||
.setContentIntent(piActivity);
|
||||
.setShowWhen(false);
|
||||
|
||||
mDownloadingDelay = new NotificationDelay(this, mNotifyManager, mDownloadingBuilder, ID_DOWNLOADING);
|
||||
}
|
||||
@@ -297,10 +287,20 @@ public class DownloadService extends Service implements DownloadManager.Download
|
||||
|
||||
ensureDownloadingBuilder();
|
||||
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putLong(DownloadsScene.KEY_GID, info.gid);
|
||||
Intent activityIntent = new Intent(this, MainActivity.class);
|
||||
activityIntent.setAction(StageActivity.ACTION_START_SCENE);
|
||||
activityIntent.putExtra(StageActivity.KEY_SCENE_NAME, DownloadsScene.class.getName());
|
||||
activityIntent.putExtra(StageActivity.KEY_SCENE_ARGS, bundle);
|
||||
PendingIntent piActivity = PendingIntent.getActivity(DownloadService.this, 0,
|
||||
activityIntent, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
|
||||
mDownloadingBuilder.setContentTitle(EhUtils.getSuitableTitle(info))
|
||||
.setContentText(null)
|
||||
.setContentInfo(null)
|
||||
.setProgress(0, 0, true);
|
||||
.setProgress(0, 0, true)
|
||||
.setContentIntent(piActivity);
|
||||
|
||||
mDownloadingDelay.startForeground();
|
||||
}
|
||||
|
||||
@@ -102,6 +102,8 @@ public class DownloadsScene extends ToolbarScene
|
||||
|
||||
private static final String TAG = DownloadsScene.class.getSimpleName();
|
||||
|
||||
public static final String KEY_GID = "gid";
|
||||
|
||||
public static final String KEY_ACTION = "action";
|
||||
private static final String KEY_LABEL = "label";
|
||||
|
||||
@@ -133,15 +135,43 @@ public class DownloadsScene extends ToolbarScene
|
||||
|
||||
private ShowcaseView mShowcaseView;
|
||||
|
||||
private int mInitPosition = -1;
|
||||
|
||||
@Override
|
||||
public int getNavCheckedItem() {
|
||||
return R.id.nav_downloads;
|
||||
}
|
||||
|
||||
private void handleArguments(Bundle args) {
|
||||
if (args != null && ACTION_CLEAR_DOWNLOAD_SERVICE.equals(args.getString(KEY_ACTION))) {
|
||||
private boolean handleArguments(Bundle args) {
|
||||
if (null == args) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (ACTION_CLEAR_DOWNLOAD_SERVICE.equals(args.getString(KEY_ACTION))) {
|
||||
DownloadService.clear();
|
||||
}
|
||||
|
||||
long gid;
|
||||
if (null != mDownloadManager && -1L != (gid = args.getLong(KEY_GID, -1L))) {
|
||||
DownloadInfo info = mDownloadManager.getDownloadInfo(gid);
|
||||
if (null != info) {
|
||||
mLabel = info.getLabel();
|
||||
updateForLabel();
|
||||
updateView();
|
||||
|
||||
// Get position
|
||||
if (null != mList) {
|
||||
int position = mList.indexOf(info);
|
||||
if (position >= 0 && null != mRecyclerView) {
|
||||
mRecyclerView.scrollToPosition(position);
|
||||
} else {
|
||||
mInitPosition = position;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -153,8 +183,6 @@ public class DownloadsScene extends ToolbarScene
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
handleArguments(getArguments());
|
||||
|
||||
Context context = getContext2();
|
||||
AssertUtils.assertNotNull(context);
|
||||
mDownloadManager = EhApplication.getDownloadManager(context);
|
||||
@@ -218,8 +246,10 @@ public class DownloadsScene extends ToolbarScene
|
||||
}
|
||||
|
||||
private void onInit() {
|
||||
mLabel = Settings.getRecentDownloadLabel();
|
||||
updateForLabel();
|
||||
if (!handleArguments(getArguments())) {
|
||||
mLabel = Settings.getRecentDownloadLabel();
|
||||
updateForLabel();
|
||||
}
|
||||
}
|
||||
|
||||
private void onRestore(@NonNull Bundle savedInstanceState) {
|
||||
@@ -274,6 +304,10 @@ public class DownloadsScene extends ToolbarScene
|
||||
int paddingH = context.getResources().getDimensionPixelOffset(R.dimen.list_content_margin_h);
|
||||
int paddingV = context.getResources().getDimensionPixelOffset(R.dimen.list_content_margin_v);
|
||||
mRecyclerView.setPadding(paddingV, paddingH, paddingV, paddingH);
|
||||
if (mInitPosition >= 0) {
|
||||
mRecyclerView.scrollToPosition(mInitPosition);
|
||||
mInitPosition = -1;
|
||||
}
|
||||
|
||||
fastScroller.attachToRecyclerView(mRecyclerView);
|
||||
HandlerDrawable handlerDrawable = new HandlerDrawable();
|
||||
|
||||
Reference in new issue
Block a user