Improve download
This commit is contained in:
1 parent
4a80ea7dcd
commit
2c7d5a3369
13 files changed
+147
-30
No files matched your search
@@ -78,6 +78,9 @@ public class GallerySpider implements GalleryProvider, SpiderQueen.SpiderListene
|
||||
mMap.put(key, gs);
|
||||
// The spider add to db in the construct of GallerySpider
|
||||
} else {
|
||||
if (mode == ImageHandler.Mode.DOWNLOAD) {
|
||||
gs.setMode(ImageHandler.Mode.DOWNLOAD);
|
||||
}
|
||||
// Touch the date
|
||||
DBUtils.touchDirname(galleryBase.gid);
|
||||
}
|
||||
@@ -101,6 +104,7 @@ public class GallerySpider implements GalleryProvider, SpiderQueen.SpiderListene
|
||||
mGalleryBase = galleryBase;
|
||||
mMode = mode;
|
||||
|
||||
// TODO let imagehandler handle download dir
|
||||
mDownloadDirname = DBUtils.getDirname(galleryBase.gid);
|
||||
if (mDownloadDirname == null) {
|
||||
mDownloadDirname = downloadDirname(galleryBase);
|
||||
|
||||
@@ -153,6 +153,15 @@ public class DownloadManager {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isInDownloadList(int gid) {
|
||||
for (DownloadInfo info : mDownloadInfos) {
|
||||
if (info.galleryBase.gid == gid) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Make sure is downloading
|
||||
private void ensureDownload() {
|
||||
if (mCurrentTask != null) {
|
||||
|
||||
@@ -27,6 +27,8 @@ import android.support.v4.app.NotificationCompat;
|
||||
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.client.data.GalleryBase;
|
||||
import com.hippo.ehviewer.ui.ContentActivity;
|
||||
import com.hippo.ehviewer.ui.scene.DownloadScene;
|
||||
import com.hippo.yorozuya.FileUtils;
|
||||
|
||||
public class DownloadService extends Service implements DownloadManager.DownloadUpdateListener {
|
||||
@@ -37,6 +39,8 @@ public class DownloadService extends Service implements DownloadManager.Download
|
||||
public static final String KEY_TAG = "tag";
|
||||
public static final String KEY_GID = "gid";
|
||||
|
||||
public static final String KEY_CLEAR = "clear";
|
||||
|
||||
public static final String ACTION_START = "com.hippo.ehviewer.service.DownloadService.START";
|
||||
public static final String ACTION_START_ALL = "com.hippo.ehviewer.service.DownloadService.START_ALL";
|
||||
public static final String ACTION_STOP = "com.hippo.ehviewer.service.DownloadService.STOP";
|
||||
@@ -57,6 +61,11 @@ public class DownloadService extends Service implements DownloadManager.Download
|
||||
|
||||
private DownloadManager mDownloadManager;
|
||||
|
||||
public static void clear() {
|
||||
sSucceeCount = 0;
|
||||
sFailedCount = 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
@@ -119,6 +128,14 @@ public class DownloadService extends Service implements DownloadManager.Download
|
||||
checkStop = true;
|
||||
} else if (ACTION_DELETE.equals(action)) {
|
||||
// TODO
|
||||
int gid = intent.getIntExtra(KEY_GID, 0);
|
||||
if (gid != 0) {
|
||||
mDownloadManager.stopDownload(gid);
|
||||
}
|
||||
checkStop = true;
|
||||
|
||||
|
||||
|
||||
} else if (ACTION_CLEAR.equals(action)) {
|
||||
sSucceeCount = 0;
|
||||
sFailedCount = 0;
|
||||
@@ -153,6 +170,13 @@ public class DownloadService extends Service implements DownloadManager.Download
|
||||
stopAllIntent.setAction(ACTION_STOP_ALL);
|
||||
PendingIntent piStopAll = PendingIntent.getService(this, 0, stopAllIntent, 0);
|
||||
mDownloadingBuilder.addAction(R.drawable.ic_close_x24, getString(R.string.stop_all), piStopAll);
|
||||
|
||||
Intent intent = new Intent(DownloadService.this, ContentActivity.class);
|
||||
intent.setAction(ContentActivity.ACTION_START_SCENE);
|
||||
intent.putExtra(ContentActivity.KEY_SCENE, DownloadScene.class);
|
||||
PendingIntent pendingIntent = PendingIntent.getActivity(DownloadService.this, 0,
|
||||
intent, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
mDownloadingBuilder.setContentIntent(pendingIntent);
|
||||
}
|
||||
|
||||
private void ensureDownloadedNotification() {
|
||||
@@ -166,6 +190,14 @@ public class DownloadService extends Service implements DownloadManager.Download
|
||||
mDownloadedBuilder = new NotificationCompat.Builder(getApplicationContext());
|
||||
mDownloadedBuilder.setSmallIcon(android.R.drawable.stat_sys_download_done)
|
||||
.setDeleteIntent(piClear).setOngoing(false).setAutoCancel(true);
|
||||
|
||||
Intent intent = new Intent(DownloadService.this, ContentActivity.class);
|
||||
intent.setAction(ContentActivity.ACTION_START_SCENE);
|
||||
intent.putExtra(ContentActivity.KEY_SCENE, DownloadScene.class);
|
||||
intent.putExtra(DownloadService.KEY_CLEAR, true);
|
||||
PendingIntent pendingIntent = PendingIntent.getActivity(DownloadService.this, 0,
|
||||
intent, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
mDownloadedBuilder.setContentIntent(pendingIntent);
|
||||
}
|
||||
|
||||
private void setPendingIntent() {
|
||||
|
||||
@@ -18,16 +18,19 @@ package com.hippo.ehviewer.ui;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.view.Gravity;
|
||||
import android.view.View;
|
||||
import android.widget.AdapterView;
|
||||
|
||||
import com.hippo.ehviewer.Constants;
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.service.DownloadService;
|
||||
import com.hippo.ehviewer.ui.scene.DownloadScene;
|
||||
import com.hippo.ehviewer.ui.scene.DrawerProvider;
|
||||
import com.hippo.ehviewer.ui.scene.GalleryListScene;
|
||||
@@ -38,7 +41,6 @@ import com.hippo.ehviewer.widget.DrawerLeftPanel;
|
||||
import com.hippo.ehviewer.widget.DrawerRightPanel;
|
||||
import com.hippo.ehviewer.widget.FitStageLayout;
|
||||
import com.hippo.scene.Announcer;
|
||||
import com.hippo.scene.OffsetCurtain;
|
||||
import com.hippo.scene.Scene;
|
||||
import com.hippo.scene.SceneManager;
|
||||
import com.hippo.scene.StageActivity;
|
||||
@@ -49,10 +51,18 @@ import com.hippo.widget.DrawerLayout;
|
||||
import com.hippo.widget.DrawerListView;
|
||||
import com.hippo.yorozuya.Messenger;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public final class ContentActivity extends StageActivity
|
||||
implements FitStageLayout.OnFitPaddingBottomListener,
|
||||
DrawerLeftPanel.Helper {
|
||||
|
||||
public static final String TAG = ContentActivity.class.getSimpleName();
|
||||
|
||||
public static final String ACTION_START_SCENE = "com.hippo.ehviewer.ui.ContentActivity.START_SCENE";
|
||||
|
||||
public static final String KEY_SCENE = "scene";
|
||||
|
||||
public static final int DRAWER_LIST_NONE = -1;
|
||||
public static final int DRAWER_LIST_HOMEPAGE = 0;
|
||||
public static final int DRAWER_LIST_WHATS_HOT = 1;
|
||||
@@ -78,22 +88,22 @@ public final class ContentActivity extends StageActivity
|
||||
case DRAWER_LIST_HOMEPAGE:
|
||||
announcer = new Announcer();
|
||||
announcer.putExtra(GalleryListScene.KEY_MODE, GalleryListScene.MODE_HOMEPAGE);
|
||||
startScene(GalleryListScene.class, announcer, new OffsetCurtain(OffsetCurtain.DIRECTION_BOTTOM));
|
||||
startScene(GalleryListScene.class);
|
||||
break;
|
||||
case DRAWER_LIST_WHATS_HOT:
|
||||
announcer = new Announcer();
|
||||
announcer.putExtra(GalleryListScene.KEY_MODE, GalleryListScene.MODE_POPULAR);
|
||||
startScene(GalleryListScene.class, announcer, new OffsetCurtain(OffsetCurtain.DIRECTION_BOTTOM));
|
||||
startScene(GalleryListScene.class);
|
||||
break;
|
||||
case DRAWER_LIST_HISTORY:
|
||||
break;
|
||||
case DRAWER_LIST_FAVORITE:
|
||||
break;
|
||||
case DRAWER_LIST_DOWNLOAD:
|
||||
startScene(DownloadScene.class, null, new OffsetCurtain(OffsetCurtain.DIRECTION_BOTTOM));
|
||||
startScene(DownloadScene.class);
|
||||
break;
|
||||
case DRAWER_LIST_SETTINGS:
|
||||
startScene(MainSettingsScene.class, null, new OffsetCurtain(OffsetCurtain.DIRECTION_BOTTOM));
|
||||
startScene(MainSettingsScene.class);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -166,6 +176,45 @@ public final class ContentActivity extends StageActivity
|
||||
}
|
||||
};
|
||||
|
||||
private void handleIntent(@Nullable Intent intent, boolean fromOnCreate) {
|
||||
String action;
|
||||
if (intent == null) {
|
||||
action = null;
|
||||
} else {
|
||||
action = intent.getAction();
|
||||
}
|
||||
|
||||
if (ACTION_START_SCENE.equals(action)) {
|
||||
Serializable serializable = intent.getSerializableExtra(KEY_SCENE);
|
||||
if (serializable instanceof Class) {
|
||||
Class sceneClazz = (Class) serializable;
|
||||
try {
|
||||
startScene(sceneClazz);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
boolean clear = intent.getBooleanExtra(DownloadService.KEY_CLEAR, false);
|
||||
if (clear) {
|
||||
DownloadService.clear();
|
||||
}
|
||||
}
|
||||
|
||||
if (getSceneCount() == 0) {
|
||||
if (fromOnCreate) {
|
||||
startScene(GalleryListScene.class);
|
||||
} else {
|
||||
finish();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onNewIntent(Intent intent) {
|
||||
super.onNewIntent(intent);
|
||||
handleIntent(intent, false);
|
||||
}
|
||||
|
||||
@SuppressLint("RtlHardcoded")
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
@@ -218,10 +267,7 @@ public final class ContentActivity extends StageActivity
|
||||
mDrawerListView.setData(drawerListDrawables, drawerListStrings);
|
||||
mDrawerListView.setOnItemClickListener(mDrawerListListener);
|
||||
|
||||
// First time
|
||||
if (savedInstanceState == null) {
|
||||
startScene(GalleryListScene.class, null);
|
||||
}
|
||||
handleIntent(getIntent(), true);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -286,7 +332,7 @@ public final class ContentActivity extends StageActivity
|
||||
@Override
|
||||
public void onClickSignIn() {
|
||||
mDrawerLayout.closeDrawers();
|
||||
startScene(SignInScene.class, null, new OffsetCurtain(OffsetCurtain.DIRECTION_BOTTOM));
|
||||
startScene(SignInScene.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -51,6 +51,7 @@ import com.hippo.ehviewer.gallery.ui.GalleryLayout;
|
||||
import com.hippo.ehviewer.gallery.ui.GalleryPageView;
|
||||
import com.hippo.ehviewer.gallery.ui.GalleryPanel;
|
||||
import com.hippo.ehviewer.gallery.ui.GalleryView;
|
||||
import com.hippo.ehviewer.service.DownloadManager;
|
||||
import com.hippo.ehviewer.util.Settings;
|
||||
import com.hippo.util.SystemUiHelper;
|
||||
import com.hippo.vectorold.content.VectorContext;
|
||||
@@ -110,8 +111,9 @@ public class GalleryActivity extends StatsActivity implements TiledTexture.OnFre
|
||||
GalleryBase galleryBase = intent.getParcelableExtra(KEY_GALLERY_BASE);
|
||||
if (galleryBase != null) {
|
||||
try {
|
||||
// TODO get mode
|
||||
mGalleryProvider = GallerySpider.obtain(galleryBase, ImageHandler.Mode.DOWNLOAD);
|
||||
mGalleryProvider = GallerySpider.obtain(galleryBase,
|
||||
DownloadManager.getInstance().isInDownloadList(galleryBase.gid) ?
|
||||
ImageHandler.Mode.DOWNLOAD : ImageHandler.Mode.READ);
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
|
||||
@@ -38,6 +38,7 @@ import com.hippo.ehviewer.util.EhUtils;
|
||||
import com.hippo.ehviewer.widget.LoadImageView;
|
||||
import com.hippo.ehviewer.widget.SimpleRatingView;
|
||||
import com.hippo.rippleold.RippleSalon;
|
||||
import com.hippo.scene.Announcer;
|
||||
import com.hippo.scene.Scene;
|
||||
import com.hippo.widget.recyclerview.EasyRecyclerView;
|
||||
import com.hippo.yorozuya.FileUtils;
|
||||
@@ -56,8 +57,15 @@ public class DownloadScene extends Scene implements DrawerProvider,
|
||||
|
||||
private GidPositionMap mGidPositionMap;
|
||||
|
||||
private int mOriginalPaddingBottom;
|
||||
|
||||
private int mLastUpdateSize = -1;
|
||||
|
||||
@Override
|
||||
public int getLaunchMode() {
|
||||
return LAUNCH_MODE_SINGLE_TOP;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onInit() {
|
||||
super.onInit();
|
||||
@@ -89,6 +97,8 @@ public class DownloadScene extends Scene implements DrawerProvider,
|
||||
mRecyclerView.setLayoutManager(new LinearLayoutManager(getStageActivity()));
|
||||
mRecyclerView.setOnItemClickListener(this);
|
||||
mRecyclerView.setHasFixedSize(true);
|
||||
|
||||
mOriginalPaddingBottom = mRecyclerView.getPaddingBottom();
|
||||
}
|
||||
|
||||
|
||||
@@ -99,6 +109,14 @@ public class DownloadScene extends Scene implements DrawerProvider,
|
||||
((ContentActivity) getStageActivity()).setDrawerListActivatedPosition(ContentActivity.DRAWER_LIST_DOWNLOAD);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onGetFitPaddingBottom(int b) {
|
||||
super.onGetFitPaddingBottom(b);
|
||||
|
||||
mRecyclerView.setPadding(mRecyclerView.getPaddingLeft(), mRecyclerView.getPaddingTop(),
|
||||
mRecyclerView.getPaddingRight(), b + mOriginalPaddingBottom);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean showLeftDrawer() {
|
||||
return true;
|
||||
@@ -112,7 +130,12 @@ public class DownloadScene extends Scene implements DrawerProvider,
|
||||
|
||||
@Override
|
||||
public boolean onItemClick(EasyRecyclerView parent, View view, int position, long id) {
|
||||
return false;
|
||||
DownloadInfo info = mDownloadInfos.get(position);
|
||||
Announcer announcer = new Announcer();
|
||||
announcer.setAction(GalleryDetailScene.ACTION_GALLERY_BASE);
|
||||
announcer.putExtra(GalleryDetailScene.KEY_GALLERY_BASE, info.galleryBase);
|
||||
startScene(GalleryDetailScene.class, announcer);
|
||||
return true;
|
||||
}
|
||||
|
||||
private View.OnClickListener mStartListener = new View.OnClickListener() {
|
||||
|
||||
@@ -79,11 +79,11 @@ public class GalleryDetailScene extends Scene implements View.OnClickListener,
|
||||
|
||||
private static final String TAG = GalleryDetailScene.class.getSimpleName();
|
||||
|
||||
public static final String ACTION_GALLERY_INFO = "action_gallery_info";
|
||||
public static final String ACTION_GALLERY_BASE = "key_gallery_base";
|
||||
public static final String ACTION_GID_TOKEN = "action_gid_token";
|
||||
public static final String ACTION_URL = "action_url";
|
||||
|
||||
public static final String KEY_GALLERY_INFO = "key_gallery_info";
|
||||
public static final String KEY_GALLERY_BASE = "key_gallery_base";
|
||||
public static final String KEY_GID = "key_gid";
|
||||
public static final String KEY_TOKEN = "key_token";
|
||||
public static final String KEY_URL = "key_url";
|
||||
@@ -484,8 +484,8 @@ public class GalleryDetailScene extends Scene implements View.OnClickListener,
|
||||
if (announcer != null) {
|
||||
String action = announcer.getAction();
|
||||
mActionStr = action;
|
||||
if (ACTION_GALLERY_INFO.equals(action)) {
|
||||
mGalleryBase = announcer.getExtra(KEY_GALLERY_INFO, GalleryBase.class);
|
||||
if (ACTION_GALLERY_BASE.equals(action)) {
|
||||
mGalleryBase = announcer.getExtra(KEY_GALLERY_BASE, GalleryBase.class);
|
||||
if (mGalleryBase != null) {
|
||||
bindGalleryInfo(mGalleryBase);
|
||||
return;
|
||||
@@ -553,7 +553,7 @@ public class GalleryDetailScene extends Scene implements View.OnClickListener,
|
||||
mViewTransition.showView(1); // Show progress view
|
||||
mState = STATE_TOTALLY_LOADING;
|
||||
mAdapter.notifyDataSetChanged();
|
||||
if (ACTION_GALLERY_INFO.equals(mActionStr)) {
|
||||
if (ACTION_GALLERY_BASE.equals(mActionStr)) {
|
||||
requestGalleryDetail(mGalleryBase.gid, mGalleryBase.token);
|
||||
} else {
|
||||
requestGalleryDetail(mGid, mToken);
|
||||
|
||||
@@ -901,8 +901,8 @@ public final class GalleryListScene extends Scene implements ListSearchBar.Helpe
|
||||
public boolean onItemClick(EasyRecyclerView parent, View view, int position, long id) {
|
||||
GalleryInfo gi = mGalleryListHelper.getDataAt(position);
|
||||
Announcer announcer = new Announcer();
|
||||
announcer.setAction(GalleryDetailScene.ACTION_GALLERY_INFO);
|
||||
announcer.putExtra(GalleryDetailScene.KEY_GALLERY_INFO, gi);
|
||||
announcer.setAction(GalleryDetailScene.ACTION_GALLERY_BASE);
|
||||
announcer.putExtra(GalleryDetailScene.KEY_GALLERY_BASE, gi);
|
||||
|
||||
Curtain curtain = new ElementsSharedCurtain(new TransitonHelper(position));
|
||||
|
||||
|
||||
@@ -22,7 +22,6 @@ import android.os.Bundle;
|
||||
import android.os.Parcelable;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.util.SparseArray;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
@@ -30,7 +29,6 @@ import android.view.ViewParent;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.FrameLayout;
|
||||
|
||||
import com.hippo.ehviewer.client.data.DownloadInfo;
|
||||
import com.hippo.yorozuya.AssertUtils;
|
||||
|
||||
/**
|
||||
@@ -137,7 +135,7 @@ public abstract class Scene {
|
||||
startScene(sceneClass, announcer, getDefaultCurtain());
|
||||
}
|
||||
|
||||
public Curtain getDefaultCurtain() {
|
||||
static Curtain getDefaultCurtain() {
|
||||
return new OffsetCurtain(OffsetCurtain.DIRECTION_BOTTOM);
|
||||
}
|
||||
|
||||
|
||||
@@ -170,12 +170,12 @@ public class SceneManager {
|
||||
scene.setSceneManager(this);
|
||||
return scene;
|
||||
} catch (InstantiationException e) {
|
||||
throw new IllegalStateException("Can't instance " + sceneClass.getName());
|
||||
throw new IllegalStateException("Can't instance " + sceneClass.getName(), e);
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new IllegalStateException("The constructor of " +
|
||||
sceneClass.getName() + " is not visible");
|
||||
sceneClass.getName() + " is not visible", e);
|
||||
} catch (ClassCastException e) {
|
||||
throw new IllegalStateException(sceneClass.getName() + " can not cast to scene");
|
||||
throw new IllegalStateException(sceneClass.getName() + " can not cast to scene", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -76,6 +76,10 @@ public abstract class StageActivity extends StatsActivity {
|
||||
mSceneManager = null;
|
||||
}
|
||||
|
||||
public int getSceneCount() {
|
||||
return mSceneManager.getSceneCount();
|
||||
}
|
||||
|
||||
public int getFitPaddingBottom() {
|
||||
return mFitPaddingBottom;
|
||||
}
|
||||
@@ -100,11 +104,11 @@ public abstract class StageActivity extends StatsActivity {
|
||||
}
|
||||
|
||||
public void startScene(@NonNull Class sceneClass) {
|
||||
mSceneManager.startScene(sceneClass, null, null);
|
||||
startScene(sceneClass, null);
|
||||
}
|
||||
|
||||
public void startScene(@NonNull Class sceneClass, @Nullable Announcer announcer) {
|
||||
mSceneManager.startScene(sceneClass, announcer, null);
|
||||
startScene(sceneClass, announcer, Scene.getDefaultCurtain());
|
||||
}
|
||||
|
||||
public void startScene(@NonNull Class sceneClass, @Nullable Announcer announcer,
|
||||
|
||||
Reference in new issue
Block a user