Improve DownloadInfo in EhDB

This commit is contained in:
seven332 committed 2016-03-05 23:48:39 +08:00
1 parent b1ae94824c
commit 4444899e4b
33 files changed
+416 -366

No files matched your search

@@ -22,7 +22,6 @@ import android.os.Debug;
import android.support.annotation.NonNull;
import android.util.Log;
import android.util.SparseArray;
import android.util.SparseBooleanArray;
import com.hippo.beerbelly.LruCacheEx;
import com.hippo.conaco.Conaco;
@@ -41,6 +40,8 @@ import com.hippo.text.Html;
import com.hippo.util.ReadableTime;
import com.hippo.yorozuya.FileUtils;
import com.hippo.yorozuya.SimpleHandler;
import com.hippo.yorozuya.sparse.SparseJBArray;
import com.hippo.yorozuya.sparse.SparseJLArray;
import java.io.File;
import java.util.Comparator;
@@ -63,13 +64,13 @@ public class EhApplication extends SceneApplication {
private OkHttpClient mOkHttpClient;
private ImageWrapperHelper mImageWrapperHelper;
private Conaco<ImageWrapper> mConaco;
private LruCacheEx<Integer, GalleryDetail> mGalleryDetailCache;
private LruCacheEx<Long, GalleryDetail> mGalleryDetailCache;
private LruCacheEx<String, LargePreviewSet> mLargePreviewSetCache;
private LruCacheEx<Integer, Integer> mPreviewPagesCache;
private LruCacheEx<Long, Integer> mPreviewPagesCache;
private DownloadManager mDownloadManager;
private SparseBooleanArray mItemStateArray;
private SparseArray<String> mItemTitleArray;
private SparseJBArray mItemStateArray;
private SparseJLArray<String> mItemTitleArray;
private int mFailedCount;
private int mFinishedCount;
private int mDownloadedCount;
@@ -209,14 +210,14 @@ public class EhApplication extends SceneApplication {
}
@NonNull
public static LruCacheEx<Integer, GalleryDetail> getGalleryDetailCache(@NonNull Context context) {
public static LruCacheEx<Long, GalleryDetail> getGalleryDetailCache(@NonNull Context context) {
EhApplication application = ((EhApplication) context.getApplicationContext());
if (application.mGalleryDetailCache == null) {
// Max size 25, 3 min timeout
application.mGalleryDetailCache = new LruCacheEx<>(25, 3 * 60 * 1000, new Comparator<Integer>() {
application.mGalleryDetailCache = new LruCacheEx<>(25, 3 * 60 * 1000, new Comparator<Long>() {
@Override
public int compare(Integer lhs, Integer rhs) {
return lhs - rhs;
public int compare(Long lhs, Long rhs) {
return lhs > rhs ? 1 : lhs > rhs ? -1 : 0;
}
});
}
@@ -239,14 +240,14 @@ public class EhApplication extends SceneApplication {
}
@NonNull
public static LruCacheEx<Integer, Integer> getPreviewPagesCache(@NonNull Context context) {
public static LruCacheEx<Long, Integer> getPreviewPagesCache(@NonNull Context context) {
EhApplication application = ((EhApplication) context.getApplicationContext());
if (application.mPreviewPagesCache == null) {
// Max size 50, 3 min timeout
application.mPreviewPagesCache = new LruCacheEx<>(50, 3 * 60 * 1000, new Comparator<Integer>() {
application.mPreviewPagesCache = new LruCacheEx<>(50, 3 * 60 * 1000, new Comparator<Long>() {
@Override
public int compare(Integer lhs, Integer rhs) {
return lhs - rhs;
public int compare(Long lhs, Long rhs) {
return lhs > rhs ? 1 : lhs > rhs ? -1 : 0;
}
});
}
@@ -266,10 +267,10 @@ public class EhApplication extends SceneApplication {
public static void initDownloadService(Context context, DownloadService service) {
EhApplication application = ((EhApplication) context.getApplicationContext());
if (application.mItemStateArray == null) {
application.mItemStateArray = new SparseBooleanArray();
application.mItemStateArray = new SparseJBArray();
}
if (application.mItemTitleArray == null) {
application.mItemTitleArray = new SparseArray<>();
application.mItemTitleArray = new SparseJLArray<>();
}
service.init(application.mItemStateArray, application.mItemTitleArray,
+92 -72
View File
@@ -30,10 +30,10 @@ import com.hippo.ehviewer.dao.DaoMaster;
import com.hippo.ehviewer.dao.DaoSession;
import com.hippo.ehviewer.dao.DownloadDirnameDao;
import com.hippo.ehviewer.dao.DownloadDirnameRaw;
import com.hippo.ehviewer.dao.DownloadInfoDao;
import com.hippo.ehviewer.dao.DownloadInfoRaw;
import com.hippo.ehviewer.dao.DownloadInfo;
import com.hippo.ehviewer.dao.DownloadLabelDao;
import com.hippo.ehviewer.dao.DownloadLabelRaw;
import com.hippo.ehviewer.dao.DownloadsDao;
import com.hippo.ehviewer.dao.GalleryInfoDao;
import com.hippo.ehviewer.dao.GalleryInfoRaw;
import com.hippo.ehviewer.dao.HistoryInfoDao;
@@ -42,15 +42,15 @@ import com.hippo.ehviewer.dao.LocalFavoritesDao;
import com.hippo.ehviewer.dao.LocalFavoritesRaw;
import com.hippo.ehviewer.dao.QuickSearchDao;
import com.hippo.ehviewer.dao.QuickSearchRaw;
import com.hippo.ehviewer.download.DownloadInfo;
import com.hippo.yorozuya.sparse.SparseJLArray;
import java.util.ArrayList;
import java.util.List;
import de.greenrobot.dao.query.LazyList;
public class EhDB {
private static final String TAG = EhDB.class.getSimpleName();
private static DaoSession sDaoSession;
private static boolean sHasOldDB;
@@ -124,6 +124,34 @@ public class EhDB {
return;
}
// Get GalleryInfo list
SparseJLArray<GalleryInfo> map = new SparseJLArray<>();
try {
Cursor cursor = oldDB.rawQuery("select * from " + OldDBHelper.TABLE_GALLERY, null);
if (cursor != null) {
if (cursor.moveToFirst()) {
while (!cursor.isAfterLast()) {
GalleryInfo gi = new GalleryInfo();
gi.gid = cursor.getInt(0);
gi.token = cursor.getString(1);
gi.title = cursor.getString(2);
gi.posted = cursor.getString(3);
gi.category = cursor.getInt(4);
gi.thumb = cursor.getString(5);
gi.uploader = cursor.getString(5);
gi.rating = cursor.getFloat(6);
map.put(gi.gid, gi);
cursor.moveToNext();
}
}
cursor.close();
}
} catch (Exception e) {
// Ignore
}
// Merge gallery info
try {
Cursor cursor = oldDB.rawQuery("select * from " + OldDBHelper.TABLE_GALLERY, null);
@@ -213,27 +241,33 @@ public class EhDB {
try {
Cursor cursor = oldDB.rawQuery("select * from " + OldDBHelper.TABLE_DOWNLOAD, null);
if (cursor != null) {
DownloadInfoDao dao = sDaoSession.getDownloadInfoDao();
DownloadsDao dao = sDaoSession.getDownloadsDao();
if (cursor.moveToFirst()) {
long i = 0L;
while (!cursor.isAfterLast()) {
DownloadInfoRaw raw = new DownloadInfoRaw();
// Get GalleryInfo first
long gid = cursor.getInt(0);
GalleryInfo gi = map.get(gid);
if (gi == null) {
Log.e(TAG, "Can't get GalleryInfo with gid: " + gid);
cursor.moveToNext();
continue;
}
DownloadInfo info = new DownloadInfo(gi);
int state = cursor.getInt(2);
int legacy = cursor.getInt(3);
if (state == DownloadInfo.STATE_FINISH && legacy > 0) {
state = DownloadInfo.STATE_FAILED;
}
raw.setGid((long) cursor.getInt(0));
raw.setState(state);
raw.setLegacy(legacy);
info.setState(state);
info.setLegacy(legacy);
if (cursor.getColumnCount() == 5) {
raw.setDate(cursor.getLong(4));
info.setTime(cursor.getLong(4));
} else {
raw.setDate(i);
info.setTime(i);
}
dao.insert(raw);
dao.insert(info);
cursor.moveToNext();
i++;
}
@@ -274,11 +308,11 @@ public class EhDB {
private static synchronized void addGalleryInfo(GalleryInfo galleryInfo) {
GalleryInfoDao dao = sDaoSession.getGalleryInfoDao();
GalleryInfoRaw raw = dao.load((long) galleryInfo.gid);
GalleryInfoRaw raw = dao.load(galleryInfo.gid);
if (raw == null) {
// add new item, set reference 1
raw = new GalleryInfoRaw();
raw.setGid((long) galleryInfo.gid);
raw.setGid(galleryInfo.gid);
raw.setToken(galleryInfo.token);
raw.setTitle(galleryInfo.title);
raw.setThumb(galleryInfo.thumb);
@@ -309,12 +343,12 @@ public class EhDB {
}
}
public static synchronized GalleryInfo getGalleryInfo(int gid) {
public static synchronized GalleryInfo getGalleryInfo(long gid) {
GalleryInfoDao dao = sDaoSession.getGalleryInfoDao();
GalleryInfoRaw raw = dao.load((long) gid);
GalleryInfoRaw raw = dao.load(gid);
if (raw != null) {
GalleryInfo gi = new GalleryInfo();
gi.gid = (int) (long) raw.getGid();
gi.gid = raw.getGid();
gi.token = raw.getToken();
gi.title = raw.getTitle();
gi.thumb = raw.getThumb();
@@ -329,52 +363,38 @@ public class EhDB {
}
}
public static synchronized LazyList<DownloadInfoRaw> getDownloadInfoLazyList() {
return sDaoSession.getDownloadInfoDao().queryBuilder()
.orderAsc(DownloadInfoDao.Properties.Date).listLazy();
public static synchronized List<DownloadInfo> getAllDownloadInfos() {
DownloadsDao dao = sDaoSession.getDownloadsDao();
List<DownloadInfo> list = dao.queryBuilder().orderAsc(DownloadsDao.Properties.Time).list();
// Fix state
for (DownloadInfo info: list) {
if (info.state == DownloadInfo.STATE_WAIT || info.state == DownloadInfo.STATE_DOWNLOAD) {
info.state = DownloadInfo.STATE_NONE;
}
}
return list;
}
public static synchronized void addDownloadInfo(DownloadInfo info) {
// Add gallery info first
addGalleryInfo(info.galleryInfo);
// Add download info
DownloadInfoDao dao = sDaoSession.getDownloadInfoDao();
DownloadInfoRaw raw = new DownloadInfoRaw();
raw.setGid((long) info.galleryInfo.gid);
raw.setState(info.state);
raw.setLegacy(info.legacy);
raw.setDate(info.date);
raw.setLabel(info.label);
dao.insert(raw);
}
public static synchronized void updateDownloadInfo(DownloadInfo info) {
DownloadInfoDao dao = sDaoSession.getDownloadInfoDao();
DownloadInfoRaw raw = dao.load((long) info.galleryInfo.gid);
if (raw == null) {
Log.e("TAG", "Can't find download info: " + info.galleryInfo.gid);
addDownloadInfo(info);
// Insert or update
public static synchronized void putDownloadInfo(DownloadInfo downloadInfo) {
DownloadsDao dao = sDaoSession.getDownloadsDao();
if (null != dao.load(downloadInfo.gid)) {
// Update
dao.update(downloadInfo);
} else {
raw.setState(info.state);
raw.setLegacy(info.legacy);
raw.setDate(info.date);
raw.setLabel(info.label);
dao.update(raw);
// Insert
dao.insert(downloadInfo);
}
}
public static synchronized void removeDownloadInfo(int gid) {
DownloadInfoDao dao = sDaoSession.getDownloadInfoDao();
if (null != dao.load((long) gid)) {
removeGalleryInfo(gid);
dao.deleteByKey((long) gid);
}
public static synchronized void removeDownloadInfo(long gid) {
sDaoSession.getDownloadsDao().deleteByKey(gid);
}
@Nullable
public static synchronized String getDownloadDirname(int gid) {
public static synchronized String getDownloadDirname(long gid) {
DownloadDirnameDao dao = sDaoSession.getDownloadDirnameDao();
DownloadDirnameRaw raw = dao.load((long) gid);
DownloadDirnameRaw raw = dao.load(gid);
if (raw != null) {
return raw.getDirname();
} else {
@@ -385,23 +405,23 @@ public class EhDB {
/**
* Insert or update
*/
public static synchronized void putDownloadDirname(int gid, String dirname) {
public static synchronized void putDownloadDirname(long gid, String dirname) {
DownloadDirnameDao dao = sDaoSession.getDownloadDirnameDao();
DownloadDirnameRaw raw = dao.load((long) gid);
DownloadDirnameRaw raw = dao.load(gid);
if (raw != null) { // Update
raw.setDirname(dirname);
dao.update(raw);
} else { // Insert
raw = new DownloadDirnameRaw();
raw.setGid((long) gid);
raw.setGid(gid);
raw.setDirname(dirname);
dao.insert(raw);
}
}
public static synchronized void removeDownloadDirname(int gid) {
public static synchronized void removeDownloadDirname(long gid) {
DownloadDirnameDao dao = sDaoSession.getDownloadDirnameDao();
dao.deleteByKey((long) gid);
dao.deleteByKey(gid);
}
@NonNull
@@ -459,7 +479,7 @@ public class EhDB {
List<LocalFavoritesRaw> list = dao.queryBuilder().orderAsc(LocalFavoritesDao.Properties.Date).list();
List<GalleryInfo> result = new ArrayList<>(list.size());
for (LocalFavoritesRaw raw: list) {
GalleryInfo gi = getGalleryInfo((int) (long) raw.getGid());
GalleryInfo gi = getGalleryInfo(raw.getGid());
if (null == gi) {
continue;
}
@@ -482,32 +502,32 @@ public class EhDB {
return result;
}
public static synchronized void removeLocalFavorites(int gid) {
sDaoSession.getLocalFavoritesDao().deleteByKey((long) gid);
public static synchronized void removeLocalFavorites(long gid) {
sDaoSession.getLocalFavoritesDao().deleteByKey(gid);
}
public static synchronized void removeLocalFavorites(int[] gidArray) {
public static synchronized void removeLocalFavorites(long[] gidArray) {
LocalFavoritesDao dao = sDaoSession.getLocalFavoritesDao();
for (int gid: gidArray) {
dao.deleteByKey((long) gid);
for (long gid: gidArray) {
dao.deleteByKey(gid);
}
}
public static synchronized boolean containLocalFavorites(int gid) {
public static synchronized boolean containLocalFavorites(long gid) {
LocalFavoritesDao dao = sDaoSession.getLocalFavoritesDao();
return null != dao.load((long) gid);
return null != dao.load(gid);
}
public static synchronized void addLocalFavorites(GalleryInfo galleryInfo) {
LocalFavoritesDao dao = sDaoSession.getLocalFavoritesDao();
if (null != dao.load((long) galleryInfo.gid)) {
if (null != dao.load(galleryInfo.gid)) {
// Contained
return;
}
addGalleryInfo(galleryInfo);
LocalFavoritesRaw raw = new LocalFavoritesRaw();
raw.setGid((long) galleryInfo.gid);
raw.setGid(galleryInfo.gid);
raw.setDate(System.currentTimeMillis());
dao.insert(raw);
}
@@ -515,14 +535,14 @@ public class EhDB {
public static synchronized void addLocalFavorites(List<GalleryInfo> galleryInfoList) {
LocalFavoritesDao dao = sDaoSession.getLocalFavoritesDao();
for (GalleryInfo gi: galleryInfoList) {
if (null != dao.load((long) gi.gid)) {
if (null != dao.load(gi.gid)) {
// Contained
continue;
}
addGalleryInfo(gi);
LocalFavoritesRaw raw = new LocalFavoritesRaw();
raw.setGid((long) gi.gid);
raw.setGid(gi.gid);
raw.setDate(System.currentTimeMillis());
dao.insert(raw);
}
@@ -18,23 +18,23 @@ package com.hippo.ehviewer.client;
public class EhCacheKeyFactory {
public static String getThumbKey(int gid) {
public static String getThumbKey(long gid) {
return "thumb:" + gid;
}
public static String getNormalPreviewKey(int gid, int index) {
public static String getNormalPreviewKey(long gid, int index) {
return "preview:normal:" + gid + ":" + index;
}
public static String getLargePreviewKey(int gid, int index) {
public static String getLargePreviewKey(long gid, int index) {
return "preview:large:" + gid + ":" + index;
}
public static String getLargePreviewSetKey(int gid, int index) {
public static String getLargePreviewSetKey(long gid, int index) {
return "large_preview_set:" + gid + ":" + index;
}
public static String getImageKey(int gid, int index) {
public static String getImageKey(long gid, int index) {
return "image:" + gid + ":" + index;
}
}
@@ -156,19 +156,19 @@ public class EhClient {
case METHOD_GET_LARGE_PREVIEW_SET:
return EhEngine.getLargePreviewSet(this, mOkHttpClient, (String) params[0]);
case METHOD_GET_RATE_GALLERY:
return EhEngine.rateGallery(this, mOkHttpClient, (Integer) params[0], (String) params[1], (Float) params[2]);
return EhEngine.rateGallery(this, mOkHttpClient, (Long) params[0], (String) params[1], (Float) params[2]);
case METHOD_GET_COMMENT_GALLERY:
return EhEngine.commentGallery(this, mOkHttpClient, (String) params[0], (String) params[1]);
case METHOD_GET_GALLERY_TOKEN:
return EhEngine.getGalleryToken(this, mOkHttpClient, (Integer) params[0], (String) params[1], (Integer) params[2]);
return EhEngine.getGalleryToken(this, mOkHttpClient, (Long) params[0], (String) params[1], (Integer) params[2]);
case METHOD_GET_FAVORITES:
return EhEngine.getFavorites(this, mOkHttpClient, (String) params[0], (Boolean) params[1]);
case METHOD_ADD_FAVORITES:
return EhEngine.addFavorites(this, mOkHttpClient, (Integer) params[0], (String) params[1], (Integer) params[2], (String) params[3]);
return EhEngine.addFavorites(this, mOkHttpClient, (Long) params[0], (String) params[1], (Integer) params[2], (String) params[3]);
case METHOD_ADD_FAVORITES_RANGE:
return EhEngine.addFavoritesRange(this, mOkHttpClient, (int[]) params[0], (String[]) params[1], (Integer) params[2]);
return EhEngine.addFavoritesRange(this, mOkHttpClient, (long[]) params[0], (String[]) params[1], (Integer) params[2]);
case METHOD_MODIFY_FAVORITES:
return EhEngine.modifyFavorites(this, mOkHttpClient, (String) params[0], (int[]) params[1], (Integer) params[2], (Boolean) params[3]);
return EhEngine.modifyFavorites(this, mOkHttpClient, (String) params[0], (long[]) params[1], (Integer) params[2], (Boolean) params[3]);
case METHOD_GET_TORRENT_LIST:
return EhEngine.getTorrentList(this, mOkHttpClient, (String) params[0]);
default:
@@ -264,7 +264,7 @@ public class EhEngine {
}
public static RateGalleryParser.Result rateGallery(EhClient.Task task,
OkHttpClient okHttpClient, int gid, String token, float rating) throws Exception {
OkHttpClient okHttpClient, long gid, String token, float rating) throws Exception {
final JSONObject json = new JSONObject();
json.put("method", "rategallery");
json.put("apiuid", APIUID);
@@ -328,7 +328,7 @@ public class EhEngine {
}
public static String getGalleryToken(EhClient.Task task, OkHttpClient okHttpClient,
int gid, String gtoken, int page) throws Exception {
long gid, String gtoken, int page) throws Exception {
JSONObject json = new JSONObject()
.put("method", "gtoken")
.put("pagelist", new JSONArray().put(
@@ -395,7 +395,7 @@ public class EhEngine {
* @param note max 250 characters
*/
public static Void addFavorites(EhClient.Task task, OkHttpClient okHttpClient,
int gid, String token, int dstCat, String note) throws Exception {
long gid, String token, int dstCat, String note) throws Exception {
String catStr;
if (dstCat == -1) {
catStr = "favdel";
@@ -437,7 +437,7 @@ public class EhEngine {
}
public static Void addFavoritesRange(EhClient.Task task, OkHttpClient okHttpClient,
int[] gidArray, String[] tokenArray, int dstCat) throws Exception {
long[] gidArray, String[] tokenArray, int dstCat) throws Exception {
AssertUtils.assertEqualsEx(gidArray.length, tokenArray.length);
for (int i = 0, n = gidArray.length; i < n; i++) {
addFavorites(task, okHttpClient, gidArray[i], tokenArray[i], dstCat, null);
@@ -446,7 +446,7 @@ public class EhEngine {
}
public static FavoritesParser.Result modifyFavorites(EhClient.Task task, OkHttpClient okHttpClient,
String url, int[] gidArray, int dstCat, boolean callApi) throws Exception {
String url, long[] gidArray, int dstCat, boolean callApi) throws Exception {
String catStr;
if (dstCat == -1) {
catStr = "delete";
@@ -457,8 +457,8 @@ public class EhEngine {
}
FormBody.Builder builder = new FormBody.Builder();
builder.add("ddact", catStr);
for (int gid : gidArray) {
builder.add("modifygids[]", Integer.toString(gid));
for (long gid : gidArray) {
builder.add("modifygids[]", Long.toString(gid));
}
builder.add("apply", "Apply");
Log.d(TAG, url);
@@ -34,11 +34,11 @@ public class EhUrl {
public static final String URL_FAVORITES = HOST_EX + "favorites.php";
public static String getGalleryDetailUrl(int gid, String token) {
public static String getGalleryDetailUrl(long gid, String token) {
return getGalleryDetailUrl(gid, token, 0, false);
}
public static String getGalleryDetailUrl(int gid, String token, int index, boolean allComment) {
public static String getGalleryDetailUrl(long gid, String token, int index, boolean allComment) {
UrlBuilder builder = new UrlBuilder(HOST_EX + "g/" + gid + '/' + token + '/');
if (index != 0) {
builder.addQuery("p", index);
@@ -49,11 +49,11 @@ public class EhUrl {
return builder.build();
}
public static String getPageUrl(int gid, int index, String pToken) {
public static String getPageUrl(long gid, int index, String pToken) {
return HOST_EX + "s/" + pToken + '/' + gid + '-' + (index + 1);
}
public static String getAddFavorites(int gid, String token) {
public static String getAddFavorites(long gid, String token) {
return HOST_EX + "gallerypopups.php?gid=" + gid + "&t=" + token + "&act=addfav";
}
}
@@ -59,7 +59,7 @@ public class EhUrlOpener {
if (result1 != null) {
Bundle args = new Bundle();
args.putString(GalleryDetailScene.KEY_ACTION, GalleryDetailScene.ACTION_GID_TOKEN);
args.putInt(GalleryDetailScene.KEY_GID, result1.gid);
args.putLong(GalleryDetailScene.KEY_GID, result1.gid);
args.putString(GalleryDetailScene.KEY_TOKEN, result1.token);
intent = new Intent(activity, MainActivity.class);
intent.putExtra(StageActivity.KEY_SCENE_NAME, GalleryDetailScene.class.getName());
@@ -72,9 +72,9 @@ public class EhUrlOpener {
if (result2 != null) {
Bundle args = new Bundle();
args.putString(ProgressScene.KEY_ACTION, ProgressScene.ACTION_GALLERY_TOKEN);
args.putInt(ProgressScene.KEY_GID, result2.gid);
args.putLong(ProgressScene.KEY_GID, result2.gid);
args.putString(ProgressScene.KEY_PTOKEN, result2.pToken);
args.putInt(ProgressScene.KEY_PAGE, result2.page);
args.putLong(ProgressScene.KEY_PAGE, result2.page);
intent = new Intent(activity, MainActivity.class);
intent.putExtra(StageActivity.KEY_SCENE_NAME, ProgressScene.class.getName());
intent.putExtra(StageActivity.KEY_SCENE_ARGS, args);
@@ -22,7 +22,7 @@ import android.support.annotation.Nullable;
public class GalleryApiInfo implements Parcelable {
public int gid;
public long gid;
public String token;
public String archiverKey;
public String title;
@@ -46,7 +46,7 @@ public class GalleryApiInfo implements Parcelable {
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeInt(this.gid);
dest.writeLong(this.gid);
dest.writeString(this.token);
dest.writeString(this.archiverKey);
dest.writeString(this.title);
@@ -67,7 +67,7 @@ public class GalleryApiInfo implements Parcelable {
}
protected GalleryApiInfo(Parcel in) {
this.gid = in.readInt();
this.gid = in.readLong();
this.token = in.readString();
this.archiverKey = in.readString();
this.title = in.readString();
@@ -18,6 +18,7 @@ package com.hippo.ehviewer.client.data;
import android.os.Parcel;
import android.os.Parcelable;
import android.support.annotation.Nullable;
import java.util.regex.Pattern;
@@ -77,7 +78,7 @@ public class GalleryInfo implements Parcelable {
Pattern.compile("[(\\[]dutch[)\\]]", Pattern.CASE_INSENSITIVE),
};
public int gid;
public long gid ;
public String token;
public String title;
public String titleJpn;
@@ -86,6 +87,7 @@ public class GalleryInfo implements Parcelable {
public String posted;
public String uploader;
public float rating;
@Nullable
public String[] simpleTags;
/**
@@ -110,7 +112,7 @@ public class GalleryInfo implements Parcelable {
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeInt(this.gid);
dest.writeLong(this.gid);
dest.writeString(this.token);
dest.writeString(this.title);
dest.writeString(this.titleJpn);
@@ -120,12 +122,13 @@ public class GalleryInfo implements Parcelable {
dest.writeString(this.uploader);
dest.writeFloat(this.rating);
dest.writeString(this.simpleLanguage);
dest.writeStringArray(this.simpleTags);
}
public GalleryInfo() {}
protected GalleryInfo(Parcel in) {
this.gid = in.readInt();
this.gid = in.readLong();
this.token = in.readString();
this.title = in.readString();
this.titleJpn = in.readString();
@@ -135,6 +138,7 @@ public class GalleryInfo implements Parcelable {
this.uploader = in.readString();
this.rating = in.readFloat();
this.simpleLanguage = in.readString();
this.simpleTags = in.createStringArray();
}
public static final Parcelable.Creator<GalleryInfo> CREATOR = new Parcelable.Creator<GalleryInfo>() {
@@ -33,7 +33,7 @@ public class GalleryApiParser {
for (int i = 0, length = ja.length(); i < length; i++) {
JSONObject g = ja.getJSONObject(i);
int gid = g.getInt("gid");
long gid = g.getLong("gid");
GalleryInfo gi = getGalleryInfoByGid(galleryInfoList, gid);
if (gi == null) {
continue;
@@ -56,7 +56,7 @@ public class GalleryApiParser {
}
}
private static GalleryInfo getGalleryInfoByGid(List<GalleryInfo> galleryInfoList, int gid) {
private static GalleryInfo getGalleryInfoByGid(List<GalleryInfo> galleryInfoList, long gid) {
for (int i = 0, size = galleryInfoList.size(); i < size; i++) {
GalleryInfo gi = galleryInfoList.get(i);
if (gi.gid == gid) {
@@ -125,7 +125,7 @@ public class GalleryDetailParser {
throw new ParseException("Parse gallery detail error", body);
}
gd.gid = ParserUtils.parseInt(m.group(1));
gd.gid = ParserUtils.parseLong(m.group(1));
gd.token = ParserUtils.trim(m.group(2));
gd.thumb = ParserUtils.trim(m.group(3));
gd.title = ParserUtils.trim(m.group(4));
@@ -38,7 +38,7 @@ public final class GalleryDetailUrlParser {
Matcher m = URL_PATTERN.matcher(url);
if (m.find()) {
Result result = new Result();
result.gid = Integer.parseInt(m.group(1));
result.gid = Long.parseLong(m.group(1));
result.token = m.group(2);
return result;
} else {
@@ -47,7 +47,7 @@ public final class GalleryDetailUrlParser {
}
public static class Result {
public int gid;
public long gid;
public String token;
}
}
@@ -90,7 +90,7 @@ public class GalleryListParser {
Matcher matcher = GalleryDetailUrlParser.URL_PATTERN.matcher(m.group(9));
if (matcher.find()) {
gi.gid = ParserUtils.parseInt(matcher.group(1));
gi.gid = ParserUtils.parseLong(matcher.group(1));
gi.token = ParserUtils.trim(matcher.group(2));
} else {
continue;
@@ -37,7 +37,7 @@ public final class GalleryPageUrlParser {
Matcher m = URL_PATTERN.matcher(url);
if (m.find()) {
Result result = new Result();
result.gid = Integer.parseInt(m.group(2));
result.gid = Long.parseLong(m.group(2));
result.pToken = m.group(1);
result.page = Integer.parseInt(m.group(3)) - 1;
return result;
@@ -47,7 +47,7 @@ public final class GalleryPageUrlParser {
}
public static class Result {
public int gid;
public long gid;
public String pToken;
public int page;
}
@@ -31,4 +31,8 @@ public class ParserUtils {
public static int parseInt(String str) {
return Integer.parseInt(trim(str).replace(",", ""));
}
public static long parseLong(String str) {
return Long.parseLong(trim(str).replace(",", ""));
}
}
@@ -1,46 +0,0 @@
/*
* Copyright 2016 Hippo Seven
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.hippo.ehviewer.download;
import com.hippo.ehviewer.client.data.GalleryInfo;
public class DownloadInfo {
public static final int STATE_NONE = 0;
public static final int STATE_WAIT = 1;
public static final int STATE_DOWNLOAD = 2;
public static final int STATE_FINISH = 3;
public static final int STATE_FAILED = 4;
public String label;
public GalleryInfo galleryInfo;
public int state = STATE_NONE;
// byte/second, -1 for can't get speed now
public long speed;
// Remain time millis
public long remaining;
// -1 for unknown
public int finished = 0;
// -1 for unknown
public int downloaded = 0;
// -1 for unknown
public int total = -1;
// -1 for unknown
public int legacy = -1;
// For order
public long date;
}
@@ -20,20 +20,20 @@ import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.Log;
import android.util.SparseArray;
import com.hippo.ehviewer.EhDB;
import com.hippo.ehviewer.client.data.GalleryInfo;
import com.hippo.ehviewer.dao.DownloadInfoRaw;
import com.hippo.ehviewer.dao.DownloadInfo;
import com.hippo.ehviewer.dao.DownloadLabelRaw;
import com.hippo.ehviewer.spider.SpiderQueen;
import com.hippo.image.Image;
import com.hippo.yorozuya.ConcurrentPool;
import com.hippo.yorozuya.IntList;
import com.hippo.yorozuya.LongList;
import com.hippo.yorozuya.MathUtils;
import com.hippo.yorozuya.ObjectUtils;
import com.hippo.yorozuya.SimpleHandler;
import com.hippo.yorozuya.sparse.SparseIJArray;
import com.hippo.yorozuya.sparse.SparseJLArray;
import java.util.Collections;
import java.util.Comparator;
@@ -43,8 +43,6 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import de.greenrobot.dao.query.LazyList;
public class DownloadManager implements SpiderQueen.OnSpiderListener {
private static final String TAG = DownloadManager.class.getSimpleName();
@@ -61,7 +59,7 @@ public class DownloadManager implements SpiderQueen.OnSpiderListener {
private final LinkedList<DownloadInfo> mDefaultInfoList;
// For quick search
@NonNull
private final SparseArray<DownloadInfo> mAllInfoMap;
private final SparseJLArray<DownloadInfo> mAllInfoMap;
// Store download info wait to start
@NonNull
private final LinkedList<DownloadInfo> mWaitList;
@@ -96,21 +94,16 @@ public class DownloadManager implements SpiderQueen.OnSpiderListener {
// Create default for non tag
mDefaultInfoList = new LinkedList<>();
// Create all download info map
SparseArray<DownloadInfo> allInfoMap = new SparseArray<>();
SparseJLArray<DownloadInfo> allInfoMap = new SparseJLArray<>();
mAllInfoMap = allInfoMap;
// Fill download info list
LazyList<DownloadInfoRaw> lazyList = EhDB.getDownloadInfoLazyList();
for (DownloadInfoRaw raw : lazyList) {
DownloadInfo info = createDownloadInfo(raw);
if (info == null) {
continue;
}
List<DownloadInfo> allInfoList = EhDB.getAllDownloadInfos();
for (DownloadInfo info: allInfoList) {
// Add to all info map
allInfoMap.put(info.galleryInfo.gid, info);
allInfoMap.put(info.gid, info);
// Add to list
// Add to each label list
LinkedList<DownloadInfo> list = getInfoListForLabel(info.label);
if (list == null) {
list = new LinkedList<>();
@@ -122,7 +115,6 @@ public class DownloadManager implements SpiderQueen.OnSpiderListener {
}
list.add(info);
}
lazyList.close();
// Create wait list
mWaitList = new LinkedList<>();
@@ -130,27 +122,6 @@ public class DownloadManager implements SpiderQueen.OnSpiderListener {
mSpeedReminder = new SpeedReminder();
}
@Nullable
private static DownloadInfo createDownloadInfo(DownloadInfoRaw raw) {
GalleryInfo gi = EhDB.getGalleryInfo((int) (long) raw.getGid());
if (gi == null) {
Log.d(TAG, "Can't get GalleryInfo: " + raw.getGid());
return null;
}
DownloadInfo info = new DownloadInfo();
int state = raw.getState();
if (state == DownloadInfo.STATE_WAIT || state == DownloadInfo.STATE_DOWNLOAD) {
state = DownloadInfo.STATE_NONE;
}
info.galleryInfo = gi;
info.state = state;
info.legacy = raw.getLegacy();
info.date = raw.getDate();
info.label = raw.getLabel();
return info;
}
@Nullable
private LinkedList<DownloadInfo> getInfoListForLabel(String label) {
if (label == null) {
@@ -174,7 +145,7 @@ public class DownloadManager implements SpiderQueen.OnSpiderListener {
return false;
}
public boolean containDownloadInfo(int gid) {
public boolean containDownloadInfo(long gid) {
return mAllInfoMap.indexOfKey(gid) >= 0;
}
@@ -210,7 +181,7 @@ public class DownloadManager implements SpiderQueen.OnSpiderListener {
// Get download from wait list
if (!mWaitList.isEmpty()) {
DownloadInfo info = mWaitList.removeFirst();
SpiderQueen spider = SpiderQueen.obtainSpiderQueen(mContext, info.galleryInfo, SpiderQueen.MODE_DOWNLOAD);
SpiderQueen spider = SpiderQueen.obtainSpiderQueen(mContext, info, SpiderQueen.MODE_DOWNLOAD);
mCurrentTask = info;
mCurrentSpider = spider;
spider.addOnSpiderListener(this);
@@ -222,7 +193,7 @@ public class DownloadManager implements SpiderQueen.OnSpiderListener {
info.downloaded = 0;
info.legacy = -1;
// Update in DB
EhDB.updateDownloadInfo(info);
EhDB.putDownloadInfo(info);
// Start speed count
mSpeedReminder.start();
// Notify start downloading
@@ -238,7 +209,7 @@ public class DownloadManager implements SpiderQueen.OnSpiderListener {
}
void startDownload(GalleryInfo galleryInfo, @Nullable String label) {
if (mCurrentTask != null && mCurrentTask.galleryInfo.gid == galleryInfo.gid) {
if (mCurrentTask != null && mCurrentTask.gid == galleryInfo.gid) {
// It is current task
return;
}
@@ -252,7 +223,7 @@ public class DownloadManager implements SpiderQueen.OnSpiderListener {
// Add to wait list
mWaitList.add(info);
// Update in DB
EhDB.updateDownloadInfo(info);
EhDB.putDownloadInfo(info);
// Notify state update
List<DownloadInfo> list = getInfoListForLabel(info.label);
if (list != null && mDownloadInfoListener != null) {
@@ -263,11 +234,10 @@ public class DownloadManager implements SpiderQueen.OnSpiderListener {
}
} else {
// It is new download info
info = new DownloadInfo();
info.galleryInfo = galleryInfo;
info = new DownloadInfo(galleryInfo);
info.label = label;
info.state = DownloadInfo.STATE_WAIT;
info.date = System.currentTimeMillis();
info.time = System.currentTimeMillis();
// Add to label download list
LinkedList<DownloadInfo> list = getInfoListForLabel(info.label);
@@ -284,7 +254,7 @@ public class DownloadManager implements SpiderQueen.OnSpiderListener {
mWaitList.add(info);
// Save to
EhDB.addDownloadInfo(info);
EhDB.putDownloadInfo(info);
// Notify
if (mDownloadInfoListener != null) {
@@ -295,11 +265,11 @@ public class DownloadManager implements SpiderQueen.OnSpiderListener {
}
}
void startRangeDownload(IntList gidList) {
void startRangeDownload(LongList gidList) {
boolean update = false;
for (int i = 0, n = gidList.size(); i < n; i++) {
int gid = gidList.get(i);
long gid = gidList.get(i);
DownloadInfo info = mAllInfoMap.get(gid);
if (null == info) {
Log.d(TAG, "Can't get download info with gid: " + gid);
@@ -315,7 +285,7 @@ public class DownloadManager implements SpiderQueen.OnSpiderListener {
// Add to wait list
mWaitList.add(info);
// Update in DB
EhDB.updateDownloadInfo(info);
EhDB.putDownloadInfo(info);
}
}
@@ -333,7 +303,7 @@ public class DownloadManager implements SpiderQueen.OnSpiderListener {
boolean update = false;
// Start all STATE_NONE and STATE_FAILED item
// TODO keep order in wait list
SparseArray<DownloadInfo> allInfoMap = mAllInfoMap;
SparseJLArray<DownloadInfo> allInfoMap = mAllInfoMap;
List<DownloadInfo> waitList = mWaitList;
for (int i = 0, n = allInfoMap.size(); i < n; i++) {
DownloadInfo info = allInfoMap.valueAt(i);
@@ -344,7 +314,7 @@ public class DownloadManager implements SpiderQueen.OnSpiderListener {
// Add to wait list
waitList.add(info);
// Update in DB
EhDB.updateDownloadInfo(info);
EhDB.putDownloadInfo(info);
}
}
@@ -358,7 +328,7 @@ public class DownloadManager implements SpiderQueen.OnSpiderListener {
}
}
void stopDownload(int gid) {
void stopDownload(long gid) {
DownloadInfo info = stopDownloadInternal(gid);
if (info != null) {
// Update listener
@@ -384,7 +354,7 @@ public class DownloadManager implements SpiderQueen.OnSpiderListener {
}
}
void stopRangeDownload(IntList gidList) {
void stopRangeDownload(LongList gidList) {
stopRangeDownloadInternal(gidList);
// Update listener
@@ -401,7 +371,7 @@ public class DownloadManager implements SpiderQueen.OnSpiderListener {
for (DownloadInfo info : mWaitList) {
info.state = DownloadInfo.STATE_NONE;
// Update in DB
EhDB.updateDownloadInfo(info);
EhDB.putDownloadInfo(info);
}
mWaitList.clear();
@@ -414,15 +384,15 @@ public class DownloadManager implements SpiderQueen.OnSpiderListener {
}
}
void deleteDownload(int gid) {
void deleteDownload(long gid) {
stopDownloadInternal(gid);
DownloadInfo info = mAllInfoMap.get(gid);
if (info != null) {
// Remove from DB
EhDB.removeDownloadInfo(info.galleryInfo.gid);
EhDB.removeDownloadInfo(info.gid);
// Remove all list and map
mAllInfoMap.remove(info.galleryInfo.gid);
mAllInfoMap.remove(info.gid);
// Remove label list
LinkedList<DownloadInfo> list = getInfoListForLabel(info.label);
@@ -442,11 +412,11 @@ public class DownloadManager implements SpiderQueen.OnSpiderListener {
}
}
void deleteRangeDownload(IntList gidList) {
void deleteRangeDownload(LongList gidList) {
stopRangeDownloadInternal(gidList);
for (int i = 0, n = gidList.size(); i < n; i++) {
int gid = gidList.get(i);
long gid = gidList.get(i);
DownloadInfo info = mAllInfoMap.get(gid);
if (null == info) {
Log.d(TAG, "Can't get download info with gid: " + gid);
@@ -454,10 +424,10 @@ public class DownloadManager implements SpiderQueen.OnSpiderListener {
}
// Remove from DB
EhDB.removeDownloadInfo(info.galleryInfo.gid);
EhDB.removeDownloadInfo(info.gid);
// Remove from all info map
mAllInfoMap.remove(info.galleryInfo.gid);
mAllInfoMap.remove(info.gid);
// Remove from label list
LinkedList<DownloadInfo> list = getInfoListForLabel(info.label);
@@ -475,22 +445,22 @@ public class DownloadManager implements SpiderQueen.OnSpiderListener {
// Update in DB
// Update listener
// No ensureDownload
private DownloadInfo stopDownloadInternal(int gid) {
private DownloadInfo stopDownloadInternal(long gid) {
// Check current task
if (mCurrentTask != null && mCurrentTask.galleryInfo.gid == gid) {
if (mCurrentTask != null && mCurrentTask.gid == gid) {
// Stop current
return stopCurrentDownloadInternal();
}
for (Iterator<DownloadInfo> iterator = mWaitList.iterator(); iterator.hasNext();) {
DownloadInfo info = iterator.next();
if (info.galleryInfo.gid == gid) {
if (info.gid == gid) {
// Remove from wait list
iterator.remove();
// Update state
info.state = DownloadInfo.STATE_NONE;
// Update in DB
EhDB.updateDownloadInfo(info);
EhDB.putDownloadInfo(info);
return info;
}
}
@@ -518,7 +488,7 @@ public class DownloadManager implements SpiderQueen.OnSpiderListener {
// Update state
info.state = DownloadInfo.STATE_NONE;
// Update in DB
EhDB.updateDownloadInfo(info);
EhDB.putDownloadInfo(info);
// Listener
if (mDownloadListener != null) {
mDownloadListener.onCancel(info);
@@ -528,7 +498,7 @@ public class DownloadManager implements SpiderQueen.OnSpiderListener {
// Update in DB
// Update mDownloadListener
private void stopRangeDownloadInternal(IntList gidList) {
private void stopRangeDownloadInternal(LongList gidList) {
// Two way
if (gidList.size() < mWaitList.size()) {
for (int i = 0, n = gidList.size(); i < n; i++) {
@@ -536,7 +506,7 @@ public class DownloadManager implements SpiderQueen.OnSpiderListener {
}
} else {
// Check current task
if (mCurrentTask != null && gidList.contains(mCurrentTask.galleryInfo.gid)) {
if (mCurrentTask != null && gidList.contains(mCurrentTask.gid)) {
// Stop current
stopCurrentDownloadInternal();
}
@@ -544,13 +514,13 @@ public class DownloadManager implements SpiderQueen.OnSpiderListener {
// Check all in wait list
for (Iterator<DownloadInfo> iterator = mWaitList.iterator(); iterator.hasNext();) {
DownloadInfo info = iterator.next();
if (gidList.contains(info.galleryInfo.gid)) {
if (gidList.contains(info.gid)) {
// Remove from wait list
iterator.remove();
// Update state
info.state = DownloadInfo.STATE_NONE;
// Update in DB
EhDB.updateDownloadInfo(info);
EhDB.putDownloadInfo(info);
}
}
}
@@ -591,7 +561,7 @@ public class DownloadManager implements SpiderQueen.OnSpiderListener {
Collections.sort(dstList, sDateAscComparator);
// Save to DB
EhDB.updateDownloadInfo(info);
EhDB.putDownloadInfo(info);
changed = true;
}
@@ -649,7 +619,7 @@ public class DownloadManager implements SpiderQueen.OnSpiderListener {
for (DownloadInfo info: list) {
info.label = to;
// Update in DB
EhDB.updateDownloadInfo(info);
EhDB.putDownloadInfo(info);
}
// Put list back with new label
mMap.put(to, list);
@@ -685,7 +655,7 @@ public class DownloadManager implements SpiderQueen.OnSpiderListener {
for (DownloadInfo info: list) {
info.label = null;
// Update in DB
EhDB.updateDownloadInfo(info);
EhDB.putDownloadInfo(info);
mDefaultInfoList.add(info);
}
@@ -925,7 +895,7 @@ public class DownloadManager implements SpiderQueen.OnSpiderListener {
info.state = DownloadInfo.STATE_FAILED;
}
// Update in DB
EhDB.updateDownloadInfo(info);
EhDB.putDownloadInfo(info);
// Notify
if (mDownloadListener != null) {
mDownloadListener.onFinish(info);
@@ -1041,7 +1011,7 @@ public class DownloadManager implements SpiderQueen.OnSpiderListener {
private static final Comparator<DownloadInfo> sDateAscComparator = new Comparator<DownloadInfo>() {
@Override
public int compare(DownloadInfo lhs, DownloadInfo rhs) {
return lhs.date - rhs.date > 0 ? 1 : -1;
return lhs.time - rhs.time > 0 ? 1 : -1;
}
};
@@ -28,16 +28,17 @@ import android.support.annotation.IntDef;
import android.support.annotation.Nullable;
import android.support.v4.app.NotificationCompat;
import android.util.Log;
import android.util.SparseArray;
import android.util.SparseBooleanArray;
import com.hippo.ehviewer.EhApplication;
import com.hippo.ehviewer.R;
import com.hippo.ehviewer.client.data.GalleryInfo;
import com.hippo.ehviewer.dao.DownloadInfo;
import com.hippo.util.ReadableTime;
import com.hippo.yorozuya.FileUtils;
import com.hippo.yorozuya.IntList;
import com.hippo.yorozuya.LongList;
import com.hippo.yorozuya.SimpleHandler;
import com.hippo.yorozuya.sparse.SparseJBArray;
import com.hippo.yorozuya.sparse.SparseJLArray;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@@ -78,15 +79,15 @@ public class DownloadService extends Service implements DownloadManager.Download
private NotificationDelay m509Delay;
@Nullable
private SparseBooleanArray mItemStateArray;
private SparseJBArray mItemStateArray;
@Nullable
private SparseArray<String> mItemTitleArray;
private SparseJLArray<String> mItemTitleArray;
private int mFailedCount;
private int mFinishedCount;
private int mDownloadedCount;
public void init(SparseBooleanArray stateArray, SparseArray<String> titleArray,
public void init(SparseJBArray stateArray, SparseJLArray<String> titleArray,
int failedCount, int finishedCount, int downloadedCount) {
mItemStateArray = stateArray;
mItemTitleArray = titleArray;
@@ -163,7 +164,7 @@ public class DownloadService extends Service implements DownloadManager.Download
mDownloadManager.startDownload(gi, label);
}
} else if (ACTION_START_RANGE.equals(action)) {
IntList gidList = intent.getParcelableExtra(KEY_GID_LIST);
LongList gidList = intent.getParcelableExtra(KEY_GID_LIST);
if (gidList != null && mDownloadManager != null) {
mDownloadManager.startRangeDownload(gidList);
}
@@ -172,7 +173,7 @@ public class DownloadService extends Service implements DownloadManager.Download
mDownloadManager.startAllDownload();
}
} else if (ACTION_STOP.equals(action)) {
int gid = intent.getIntExtra(KEY_GID, -1);
long gid = intent.getLongExtra(KEY_GID, -1);
if (gid != -1 && mDownloadManager != null) {
mDownloadManager.stopDownload(gid);
}
@@ -181,7 +182,7 @@ public class DownloadService extends Service implements DownloadManager.Download
mDownloadManager.stopCurrentDownload();
}
} else if (ACTION_STOP_RANGE.equals(action)) {
IntList gidList = intent.getParcelableExtra(KEY_GID_LIST);
LongList gidList = intent.getParcelableExtra(KEY_GID_LIST);
if (gidList != null && mDownloadManager != null) {
mDownloadManager.stopRangeDownload(gidList);
}
@@ -190,12 +191,12 @@ public class DownloadService extends Service implements DownloadManager.Download
mDownloadManager.stopAllDownload();
}
} else if (ACTION_DELETE.equals(action)) {
int gid = intent.getIntExtra(KEY_GID, -1);
long gid = intent.getLongExtra(KEY_GID, -1);
if (gid != -1 && mDownloadManager != null) {
mDownloadManager.deleteDownload(gid);
}
} else if (ACTION_DELETE_RANGE.equals(action)) {
IntList gidList = intent.getParcelableExtra(KEY_GID_LIST);
LongList gidList = intent.getParcelableExtra(KEY_GID_LIST);
if (gidList != null && mDownloadManager != null) {
mDownloadManager.deleteRangeDownload(gidList);
}
@@ -287,7 +288,7 @@ public class DownloadService extends Service implements DownloadManager.Download
ensureDownloadingBuilder();
mDownloadingBuilder.setContentTitle(info.galleryInfo.title)
mDownloadingBuilder.setContentTitle(info.title)
.setContentText(null)
.setContentInfo(null)
.setProgress(0, 0, true)
@@ -313,7 +314,7 @@ public class DownloadService extends Service implements DownloadManager.Download
} else {
text = getString(R.string.download_speed_text, text);
}
mDownloadingBuilder.setContentTitle(info.galleryInfo.title)
mDownloadingBuilder.setContentTitle(info.title)
.setContentText(text)
.setContentInfo(info.total == -1 || info.finished == -1 ? null : info.finished + "/" + info.total)
.setProgress(info.total, info.finished, false);
@@ -342,11 +343,11 @@ public class DownloadService extends Service implements DownloadManager.Download
ensureDownloadedBuilder();
boolean finish = info.state == DownloadInfo.STATE_FINISH;
int gid = info.galleryInfo.gid;
long gid = info.gid;
int index = mItemStateArray.indexOfKey(gid);
if (index < 0) { // Not contain
mItemStateArray.put(gid, finish);
mItemTitleArray.put(gid, info.galleryInfo.title);
mItemTitleArray.put(gid, info.title);
mDownloadedCount++;
if (finish) {
mFinishedCount++;
@@ -356,7 +357,7 @@ public class DownloadService extends Service implements DownloadManager.Download
} else { // Contain
boolean oldFinish = mItemStateArray.valueAt(index);
mItemStateArray.put(gid, finish);
mItemTitleArray.put(gid, info.galleryInfo.title);
mItemTitleArray.put(gid, info.title);
if (oldFinish && !finish) {
mFinishedCount--;
mFailedCount++;
@@ -403,10 +404,10 @@ public class DownloadService extends Service implements DownloadManager.Download
if (needStyle) {
style = new NotificationCompat.InboxStyle();
style.setBigContentTitle(getString(R.string.stat_download_done_title));
SparseBooleanArray stateArray = mItemStateArray;
SparseArray<String> titleArray = mItemTitleArray;
SparseJBArray stateArray = mItemStateArray;
SparseJLArray<String> titleArray = mItemTitleArray;
for (int i = 0, n = stateArray.size(); i < n; i++) {
int id = stateArray.keyAt(i);
long id = stateArray.keyAt(i);
boolean fin = stateArray.valueAt(i);
String title = titleArray.get(id);
if (title == null) {
@@ -46,7 +46,7 @@ public final class SpiderDen {
@Nullable
private final UniFile mDownloadDir;
private volatile int mMode = SpiderQueen.MODE_READ;
private final int mGid;
private final long mGid;
@Nullable
private static SimpleDiskCache sCache;
@@ -37,7 +37,7 @@ public class SpiderInfo {
static final String TOKEN_WAIT = "wait";
int currentIndex = 0;
int gid = -1;
long gid = -1;
String token = null;
int pages = -1;
int previewPages = -1;
@@ -58,7 +58,7 @@ public class SpiderInfo {
// Current index
spiderInfo.currentIndex = Integer.parseInt(IOUtils.readAsciiLine(is), 16);
// Gid
spiderInfo.gid = Integer.parseInt(IOUtils.readAsciiLine(is));
spiderInfo.gid = Long.parseLong(IOUtils.readAsciiLine(is));
// Token
spiderInfo.token = IOUtils.readAsciiLine(is);
// Deprecated, mode, only ex is support now, MUST be 1
@@ -106,7 +106,7 @@ public class SpiderInfo {
writer = new OutputStreamWriter(os);
writer.write(String.format("%08x", currentIndex));
writer.write("\n");
writer.write(Integer.toString(gid));
writer.write(Long.toString(gid));
writer.write("\n");
writer.write(token);
writer.write("\n");
@@ -52,6 +52,7 @@ import com.hippo.yorozuya.PriorityThreadFactory;
import com.hippo.yorozuya.StringUtils;
import com.hippo.yorozuya.io.InputStreamPipe;
import com.hippo.yorozuya.io.OutputStreamPipe;
import com.hippo.yorozuya.sparse.SparseJLArray;
import java.io.File;
import java.io.FileOutputStream;
@@ -109,7 +110,7 @@ public class SpiderQueen implements Runnable {
"/509s.gif"
};
private static final SparseArray<SpiderQueen> sQueenMap = new SparseArray<>();
private static final SparseJLArray<SpiderQueen> sQueenMap = new SparseJLArray<>();
private final OkHttpClient mHttpClient;
private final GalleryInfo mGalleryInfo;
@@ -547,7 +548,7 @@ public class SpiderQueen implements Runnable {
// Read from cache
File dir = AppConfig.getSpiderInfoCacheDir();
if (dir != null) {
UniFile file = UniFile.fromFile(new File(dir, Integer.toString(mGalleryInfo.gid)));
UniFile file = UniFile.fromFile(new File(dir, Long.toString(mGalleryInfo.gid)));
SpiderInfo spiderInfo = SpiderInfo.readFromUniFile(file);
if (spiderInfo != null && spiderInfo.gid == mGalleryInfo.gid &&
spiderInfo.token.equals(mGalleryInfo.token)) {
@@ -642,7 +643,7 @@ public class SpiderQueen implements Runnable {
File dir = AppConfig.getSpiderInfoCacheDir();
if (dir != null) {
try {
spiderInfo.write(new FileOutputStream(new File(dir, Integer.toString(mGalleryInfo.gid))));
spiderInfo.write(new FileOutputStream(new File(dir, Long.toString(mGalleryInfo.gid))));
} catch (Exception e) {
// Ignore
}
@@ -799,7 +800,7 @@ public class SpiderQueen implements Runnable {
private class SpiderWorker implements Runnable {
private final int mWorkerIndex;
private final int mGid;
private final long mGid;
public SpiderWorker(int workerIndex) {
mWorkerIndex = workerIndex;
@@ -851,7 +852,7 @@ public class SpiderQueen implements Runnable {
}
}
private GalleryPageParser.Result getImageUrl(int gid, int index, String pToken,
private GalleryPageParser.Result getImageUrl(long gid, int index, String pToken,
String skipHathKey) throws IOException, ParseException, Image509Exception {
String url = EhUrl.getPageUrl(gid, index, pToken);
if (skipHathKey != null) {
@@ -874,7 +875,7 @@ public class SpiderQueen implements Runnable {
}
// false for stop
private boolean downloadImage(int gid, int index, String pToken, boolean force) {
private boolean downloadImage(long gid, int index, String pToken, boolean force) {
String skipHathKey = null;
String imageUrl;
String error = null;
@@ -58,8 +58,8 @@ import com.hippo.ehviewer.Settings;
import com.hippo.ehviewer.client.EhCacheKeyFactory;
import com.hippo.ehviewer.client.EhUtils;
import com.hippo.ehviewer.client.data.GalleryInfo;
import com.hippo.ehviewer.dao.DownloadInfo;
import com.hippo.ehviewer.dao.DownloadLabelRaw;
import com.hippo.ehviewer.download.DownloadInfo;
import com.hippo.ehviewer.download.DownloadManager;
import com.hippo.ehviewer.download.DownloadService;
import com.hippo.ehviewer.spider.SpiderDen;
@@ -77,7 +77,7 @@ import com.hippo.view.ViewTransition;
import com.hippo.widget.FabLayout;
import com.hippo.widget.LoadImageView;
import com.hippo.yorozuya.FileUtils;
import com.hippo.yorozuya.IntList;
import com.hippo.yorozuya.LongList;
import com.hippo.yorozuya.ObjectUtils;
import com.hippo.yorozuya.ResourcesUtils;
import com.hippo.yorozuya.ViewUtils;
@@ -410,7 +410,7 @@ public class DownloadScene extends ToolbarScene
Intent intent = new Intent(getActivity(), GalleryActivity.class);
intent.setAction(GalleryActivity.ACTION_EH);
intent.putExtra(GalleryActivity.KEY_GALLERY_INFO, list.get(position).galleryInfo);
intent.putExtra(GalleryActivity.KEY_GALLERY_INFO, list.get(position));
startActivity(intent);
return true;
}
@@ -453,17 +453,12 @@ public class DownloadScene extends ToolbarScene
return;
}
IntList gidList = null;
List<GalleryInfo> galleryInfoList = null;
LongList gidList = null;
List<DownloadInfo> downloadInfoList = null;
boolean collectGid = position == 1 || position == 2 || position == 3; // Start, Stop, Delete
boolean collectGalleryInfo = position == 3; // Delete
boolean collectDownloadInfo = position == 4; // Move
boolean collectDownloadInfo = position == 3 || position == 4; // Delete or Move
if (collectGid) {
gidList = new IntList();
}
if (collectGalleryInfo) {
galleryInfoList = new LinkedList<>();
gidList = new LongList();
}
if (collectDownloadInfo) {
downloadInfoList = new LinkedList<>();
@@ -476,12 +471,8 @@ public class DownloadScene extends ToolbarScene
if (collectDownloadInfo) {
downloadInfoList.add(info);
}
GalleryInfo gi = info.galleryInfo;
if (collectGalleryInfo) {
galleryInfoList.add(gi);
}
if (collectGid) {
gidList.add(gi.gid);
gidList.add(info.gid);
}
}
}
@@ -511,7 +502,7 @@ public class DownloadScene extends ToolbarScene
getString(R.string.download_remove_dialog_check_text),
Settings.getRemoveImageFiles());
DeleteRangeDialogHelper helper = new DeleteRangeDialogHelper(
galleryInfoList, gidList, builder);
downloadInfoList, gidList, builder);
builder.setTitle(R.string.download_remove_dialog_title)
.setPositiveButton(android.R.string.ok, helper)
.show();
@@ -744,13 +735,13 @@ public class DownloadScene extends ToolbarScene
private class DeleteRangeDialogHelper implements DialogInterface.OnClickListener {
private final List<GalleryInfo> mGalleryInfoList;
private final IntList mGidList;
private final List<DownloadInfo> mDownloadInfoList;
private final LongList mGidList;
private final CheckBoxDialogBuilder mBuilder;
public DeleteRangeDialogHelper(List<GalleryInfo> galleryInfoList,
IntList gidList, CheckBoxDialogBuilder builder) {
mGalleryInfoList = galleryInfoList;
public DeleteRangeDialogHelper(List<DownloadInfo> downloadInfoList,
LongList gidList, CheckBoxDialogBuilder builder) {
mDownloadInfoList = downloadInfoList;
mGidList = gidList;
mBuilder = builder;
}
@@ -776,13 +767,13 @@ public class DownloadScene extends ToolbarScene
boolean checked = mBuilder.isChecked();
Settings.putRemoveImageFiles(checked);
if (checked) {
UniFile[] files = new UniFile[mGalleryInfoList.size()];
UniFile[] files = new UniFile[mDownloadInfoList.size()];
int i = 0;
for (GalleryInfo gi: mGalleryInfoList) {
for (DownloadInfo info: mDownloadInfoList) {
// Remove download path
EhDB.removeDownloadDirname(gi.gid);
EhDB.removeDownloadDirname(info.gid);
// Put file
files[i] = SpiderDen.getGalleryDownloadDir(gi);
files[i] = SpiderDen.getGalleryDownloadDir(info);
i++;
}
// Delete file
@@ -878,7 +869,7 @@ public class DownloadScene extends ToolbarScene
if (thumb == v) {
Bundle args = new Bundle();
args.putString(GalleryDetailScene.KEY_ACTION, GalleryDetailScene.ACTION_GALLERY_INFO);
args.putParcelable(GalleryDetailScene.KEY_GALLERY_INFO, list.get(index).galleryInfo);
args.putParcelable(GalleryDetailScene.KEY_GALLERY_INFO, list.get(index));
Announcer announcer = new Announcer(GalleryDetailScene.class).setArgs(args);
if (ApiHelper.SUPPORT_TRANSITION) {
DownloadHolder holder = (DownloadHolder) recyclerView.getChildViewHolder(itemView);
@@ -888,15 +879,15 @@ public class DownloadScene extends ToolbarScene
} else if (start == v) {
Intent intent = new Intent(getActivity(), DownloadService.class);
intent.setAction(DownloadService.ACTION_START);
intent.putExtra(DownloadService.KEY_GALLERY_INFO, list.get(index).galleryInfo);
intent.putExtra(DownloadService.KEY_GALLERY_INFO, list.get(index));
getActivity().startService(intent);
} else if (stop == v) {
Intent intent = new Intent(getActivity(), DownloadService.class);
intent.setAction(DownloadService.ACTION_STOP);
intent.putExtra(DownloadService.KEY_GID, list.get(index).galleryInfo.gid);
intent.putExtra(DownloadService.KEY_GID, list.get(index).gid);
getActivity().startService(intent);
} else if (delete == v) {
GalleryInfo galleryInfo = list.get(index).galleryInfo;
GalleryInfo galleryInfo = list.get(index);
CheckBoxDialogBuilder builder = new CheckBoxDialogBuilder(getContext(),
getString(R.string.download_remove_dialog_message, galleryInfo.title),
getString(R.string.download_remove_dialog_check_text),
@@ -948,7 +939,7 @@ public class DownloadScene extends ToolbarScene
if (mList == null || position < 0 || position >= mList.size()) {
return 0;
}
return mList.get(position).galleryInfo.gid;
return mList.get(position).gid;
}
@Override
@@ -963,22 +954,21 @@ public class DownloadScene extends ToolbarScene
return;
}
DownloadInfo info = mList.get(position);
GalleryInfo gi = info.galleryInfo;
holder.thumb.load(EhCacheKeyFactory.getThumbKey(gi.gid), gi.thumb, true);
holder.title.setText(gi.title);
holder.uploader.setText(gi.uploader);
holder.rating.setRating(gi.rating);
holder.thumb.load(EhCacheKeyFactory.getThumbKey(info.gid), info.thumb, true);
holder.title.setText(info.title);
holder.uploader.setText(info.uploader);
holder.rating.setRating(info.rating);
TextView category = holder.category;
String newCategoryText = EhUtils.getCategory(gi.category);
String newCategoryText = EhUtils.getCategory(info.category);
if (!newCategoryText.equals(category.getText())) {
category.setText(newCategoryText);
category.setBackgroundColor(EhUtils.getCategoryColor(gi.category));
category.setBackgroundColor(EhUtils.getCategoryColor(info.category));
}
bindForState(holder, info);
// Update transition name
if (ApiHelper.SUPPORT_TRANSITION) {
int gid = gi.gid;
long gid = info.gid;
holder.thumb.setTransitionName(TransitionNameFactory.getThumbTransitionName(gid));
holder.title.setTransitionName(TransitionNameFactory.getTitleTransitionName(gid));
holder.uploader.setTransitionName(TransitionNameFactory.getUploaderTransitionName(gid));
@@ -803,7 +803,7 @@ public class FavoritesScene extends BaseScene implements
mRecyclerView.outOfCustomChoiceMode();
if (mUrlBuilder.getFavCat() == FavListUrlBuilder.FAV_CAT_LOCAL) { // Delete local fav
int[] gidArray = new int[mModifyGiList.size()];
long[] gidArray = new long[mModifyGiList.size()];
for (int i = 0, n = mModifyGiList.size(); i < n; i++) {
gidArray[i] = mModifyGiList.get(i).gid;
}
@@ -847,7 +847,7 @@ public class FavoritesScene extends BaseScene implements
mRecyclerView.outOfCustomChoiceMode();
if (srcCat == FavListUrlBuilder.FAV_CAT_LOCAL) { // Move from local to cloud
int[] gidArray = new int[mModifyGiList.size()];
long[] gidArray = new long[mModifyGiList.size()];
for (int i = 0, n = mModifyGiList.size(); i < n; i++) {
gidArray[i] = mModifyGiList.get(i).gid;
}
@@ -962,7 +962,7 @@ public class FavoritesScene extends BaseScene implements
// Update transition name
if (ApiHelper.SUPPORT_TRANSITION) {
int gid = gi.gid;
long gid = gi.gid;
holder.thumb.setTransitionName(TransitionNameFactory.getThumbTransitionName(gid));
holder.title.setTransitionName(TransitionNameFactory.getTitleTransitionName(gid));
holder.uploader.setTransitionName(TransitionNameFactory.getUploaderTransitionName(gid));
@@ -990,7 +990,7 @@ public class FavoritesScene extends BaseScene implements
boolean local = mUrlBuilder.getFavCat() == FavListUrlBuilder.FAV_CAT_LOCAL;
if (mModifyAdd) {
int[] gidArray = new int[mModifyGiList.size()];
long[] gidArray = new long[mModifyGiList.size()];
String[] tokenArray = new String[mModifyGiList.size()];
for (int i = 0, n = mModifyGiList.size(); i < n; i++) {
GalleryInfo gi = mModifyGiList.get(i);
@@ -1007,7 +1007,7 @@ public class FavoritesScene extends BaseScene implements
request.setArgs(gidArray, tokenArray, mModifyFavCat);
mClient.execute(request);
} else {
int[] gidArray = new int[mModifyGiList.size()];
long[] gidArray = new long[mModifyGiList.size()];
for (int i = 0, n = mModifyGiList.size(); i < n; i++) {
gidArray[i] = mModifyGiList.get(i).gid;
}
@@ -70,7 +70,7 @@ public final class GalleryCommentsScene extends ToolbarScene
public static final String KEY_TOKEN = "token";
public static final String KEY_COMMENTS = "comments";
private int mGid;
private long mGid;
private String mToken;
private GalleryComment[] mComments;
@@ -100,7 +100,7 @@ public final class GalleryCommentsScene extends ToolbarScene
return;
}
mGid = args.getInt(KEY_GID, -1);
mGid = args.getLong(KEY_GID, -1);
mToken = args.getString(KEY_TOKEN, null);
Parcelable[] parcelables = args.getParcelableArray(KEY_COMMENTS);
if (parcelables instanceof GalleryComment[]) {
@@ -113,7 +113,7 @@ public final class GalleryCommentsScene extends ToolbarScene
}
private void onRestore(@NonNull Bundle savedInstanceState) {
mGid = savedInstanceState.getInt(KEY_GID, -1);
mGid = savedInstanceState.getLong(KEY_GID, -1);
mToken = savedInstanceState.getString(KEY_TOKEN, null);
Parcelable[] parcelables = savedInstanceState.getParcelableArray(KEY_COMMENTS);
if (parcelables instanceof GalleryComment[]) {
@@ -124,7 +124,7 @@ public final class GalleryCommentsScene extends ToolbarScene
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putInt(KEY_GID, mGid);
outState.putLong(KEY_GID, mGid);
outState.putString(KEY_TOKEN, mToken);
outState.putParcelableArray(KEY_COMMENTS, mComments);
}
@@ -254,7 +254,7 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
private String mAction;
@Nullable
private GalleryInfo mGalleryInfo;
private int mGid;
private long mGid;
private String mToken;
@Nullable
@@ -278,14 +278,14 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
if (ACTION_GALLERY_INFO.equals(action)) {
mGalleryInfo = args.getParcelable(KEY_GALLERY_INFO);
} else if (ACTION_GID_TOKEN.equals(action)) {
mGid = args.getInt(KEY_GID);
mGid = args.getLong(KEY_GID);
mToken = args.getString(KEY_TOKEN);
}
}
@Nullable
private String getGalleryDetailUrl(boolean allComment) {
int gid;
long gid;
String token;
if (mGalleryDetail != null) {
gid = mGalleryDetail.gid;
@@ -303,7 +303,7 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
}
// -1 for error
private int getGid() {
private long getGid() {
if (mGalleryDetail != null) {
return mGalleryDetail.gid;
} else if (mGalleryInfo != null) {
@@ -366,7 +366,7 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
private void onRestore(Bundle savedInstanceState) {
mAction = savedInstanceState.getString(KEY_ACTION);
mGalleryInfo = savedInstanceState.getParcelable(KEY_GALLERY_INFO);
mGid = savedInstanceState.getInt(KEY_GID);
mGid = savedInstanceState.getLong(KEY_GID);
mToken = savedInstanceState.getString(KEY_TOKEN);
mGalleryDetail = savedInstanceState.getParcelable(KEY_GALLERY_DETAIL);
mRequestId = savedInstanceState.getInt(KEY_REQUEST_ID);
@@ -382,7 +382,7 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
if (mGalleryInfo != null) {
outState.putParcelable(KEY_GALLERY_INFO, mGalleryInfo);
}
outState.putInt(KEY_GID, mGid);
outState.putLong(KEY_GID, mGid);
if (mToken != null) {
outState.putString(KEY_TOKEN, mAction);
}
@@ -564,7 +564,7 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
return true;
}
int gid = getGid();
long gid = getGid();
if (gid == -1) {
return false;
}
@@ -913,7 +913,7 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void setTransitionName() {
int gid = getGid();
long gid = getGid();
if (gid != -1 && ApiHelper.SUPPORT_TRANSITION && mThumb != null &&
mTitle != null && mUploader != null && mCategory != null) {
@@ -1064,20 +1064,20 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
return;
}
Bundle args = new Bundle();
args.putInt(GalleryCommentsScene.KEY_GID, mGalleryDetail.gid);
args.putLong(GalleryCommentsScene.KEY_GID, mGalleryDetail.gid);
args.putString(GalleryCommentsScene.KEY_TOKEN, mGalleryDetail.token);
args.putParcelableArray(GalleryCommentsScene.KEY_COMMENTS, mGalleryDetail.comments);
startScene(new Announcer(GalleryCommentsScene.class)
.setArgs(args)
.setRequestCode(this, REQUEST_CODE_COMMENT_GALLERY));
} else if (mPreviews == v) {
int gid = getGid();
long gid = getGid();
String token = getToken();
if (gid == -1 || token == null) {
return;
}
Bundle args = new Bundle();
args.putInt(GalleryPreviewsScene.KEY_GID, gid);
args.putLong(GalleryPreviewsScene.KEY_GID, gid);
args.putString(GalleryPreviewsScene.KEY_TOKEN, token);
startScene(new Announcer(GalleryPreviewsScene.class).setArgs(args));
} else {
@@ -1446,9 +1446,9 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
private static class RateGalleryListener extends EhCallback<GalleryDetailScene, RateGalleryParser.Result> {
private final int mGid;
private final long mGid;
public RateGalleryListener(Context context, int stageId, String sceneTag, int gid) {
public RateGalleryListener(Context context, int stageId, String sceneTag, long gid) {
super(context, stageId, sceneTag);
mGid = gid;
}
@@ -81,7 +81,7 @@ public final class GalleryInfoScene extends ToolbarScene implements EasyRecycler
mKeys.add(resources.getString(R.string.header_key));
mValues.add(resources.getString(R.string.header_value));
mKeys.add(resources.getString(R.string.key_gid));
mValues.add(Integer.toString(gd.gid));
mValues.add(Long.toString(gd.gid));
mKeys.add(resources.getString(R.string.key_token));
mValues.add(gd.token);
mKeys.add(resources.getString(R.string.key_url));
@@ -625,10 +625,10 @@ public final class GalleryListScene extends BaseScene
return;
}
int gid;
long gid;
String token;
try {
gid = Integer.parseInt(query.substring(0, index));
gid = Long.parseLong(query.substring(0, index));
} catch (NumberFormatException e) {
Toast.makeText(getContext(), "Error", Toast.LENGTH_SHORT).show(); // TODO
return;
@@ -637,7 +637,7 @@ public final class GalleryListScene extends BaseScene
Bundle args = new Bundle();
args.putString(GalleryDetailScene.KEY_ACTION, GalleryDetailScene.ACTION_GID_TOKEN);
args.putInt(GalleryDetailScene.KEY_GID, gid);
args.putLong(GalleryDetailScene.KEY_GID, gid);
args.putString(GalleryDetailScene.KEY_TOKEN, token);
startScene(new Announcer(GalleryDetailScene.class).setArgs(args));
return;
@@ -785,7 +785,7 @@ public final class GalleryListScene extends BaseScene
// Update transition name
if (ApiHelper.SUPPORT_TRANSITION) {
int gid = gi.gid;
long gid = gi.gid;
holder.thumb.setTransitionName(TransitionNameFactory.getThumbTransitionName(gid));
holder.title.setTransitionName(TransitionNameFactory.getTitleTransitionName(gid));
holder.uploader.setTransitionName(TransitionNameFactory.getUploaderTransitionName(gid));
@@ -68,7 +68,7 @@ public class GalleryPreviewsScene extends ToolbarScene {
private GalleryPreviewAdapter mAdapter;
@Nullable
private GalleryPreviewHelper mHelper;
private int mGid = -1;
private long mGid = -1;
private String mToken = null;
private boolean mHasFirstRefresh = false;
@@ -89,7 +89,7 @@ public class GalleryPreviewsScene extends ToolbarScene {
return;
}
mGid = args.getInt(KEY_GID, -1);
mGid = args.getLong(KEY_GID, -1);
mToken = args.getString(KEY_TOKEN, null);
}
@@ -98,7 +98,7 @@ public class GalleryPreviewsScene extends ToolbarScene {
}
private void onRestore(@NonNull Bundle savedInstanceState) {
mGid = savedInstanceState.getInt(KEY_GID, -1);
mGid = savedInstanceState.getLong(KEY_GID, -1);
mToken = savedInstanceState.getString(KEY_TOKEN, null);
mHasFirstRefresh = savedInstanceState.getBoolean(KEY_HAS_FIRST_REFRESH);
}
@@ -106,7 +106,7 @@ public class GalleryPreviewsScene extends ToolbarScene {
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putInt(KEY_GID, mGid);
outState.putLong(KEY_GID, mGid);
outState.putString(KEY_TOKEN, mToken);
outState.putBoolean(KEY_HAS_FIRST_REFRESH, mHasFirstRefresh);
}
@@ -313,10 +313,10 @@ public class GalleryPreviewsScene extends ToolbarScene {
private static class GetLargePreviewSetListener extends EhCallback<GalleryPreviewsScene, Pair<LargePreviewSet, Integer>> {
private final int mTaskId;
private final int mGid;
private final long mGid;
private final int mPage;
public GetLargePreviewSetListener(Context context, int stageId, String sceneTag, int taskId, int gid, int page) {
public GetLargePreviewSetListener(Context context, int stageId, String sceneTag, int taskId, long gid, int page) {
super(context, stageId, sceneTag);
mTaskId = taskId;
mGid = gid;
@@ -56,7 +56,7 @@ public final class ProgressScene extends BaseScene implements View.OnClickListen
private String mAction;
private int mGid;
private long mGid;
private String mPToken;
private int mPage;
@@ -127,7 +127,7 @@ public final class ProgressScene extends BaseScene implements View.OnClickListen
mAction = savedInstanceState.getString(KEY_ACTION);
mGid = savedInstanceState.getInt(KEY_GID, -1);
mGid = savedInstanceState.getLong(KEY_GID, -1);
mPToken = savedInstanceState.getString(KEY_PTOKEN, null);
mPage = savedInstanceState.getInt(KEY_PAGE, -1);
}
@@ -140,7 +140,7 @@ public final class ProgressScene extends BaseScene implements View.OnClickListen
outState.putString(KEY_ACTION, mAction);
outState.putInt(KEY_GID, mGid);
outState.putLong(KEY_GID, mGid);
outState.putString(KEY_PTOKEN, mPToken);
outState.putInt(KEY_PAGE, mPage);
}
@@ -190,7 +190,7 @@ public final class ProgressScene extends BaseScene implements View.OnClickListen
private void onGetGalleryTokenSuccess(String result) {
Bundle arg = new Bundle();
arg.putString(GalleryDetailScene.KEY_ACTION, GalleryDetailScene.ACTION_GID_TOKEN);
arg.putInt(GalleryDetailScene.KEY_GID, mGid);
arg.putLong(GalleryDetailScene.KEY_GID, mGid);
arg.putString(GalleryDetailScene.KEY_TOKEN, result);
arg.putInt(GalleryDetailScene.KEY_PAGE, mPage);
startScene(new Announcer(GalleryDetailScene.class).setArgs(arg));
@@ -18,19 +18,19 @@ package com.hippo.ehviewer.ui.scene;
public final class TransitionNameFactory {
public static String getThumbTransitionName(int gid) {
public static String getThumbTransitionName(long gid) {
return "thumb:" + gid;
}
public static String getTitleTransitionName(int gid) {
public static String getTitleTransitionName(long gid) {
return "title:" + gid;
}
public static String getUploaderTransitionName(int gid) {
public static String getUploaderTransitionName(long gid) {
return "uploader:" + gid;
}
public static String getCategoryTransitionName(int gid) {
public static String getCategoryTransitionName(long gid) {
return "category:" + gid;
}
}