Add delete download item
This commit is contained in:
1 parent
ce797bcf24
commit
a4b4de08da
11 files changed
+359
-81
No files matched your search
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* 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.app;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.hippo.ehviewer.R;
|
||||
|
||||
public class CheckBoxDialogBuilder extends AlertDialog.Builder {
|
||||
|
||||
private final CheckBox mCheckBox;
|
||||
|
||||
@SuppressLint("InflateParams")
|
||||
public CheckBoxDialogBuilder(Context context, String message, String checkText, boolean checked) {
|
||||
super(context);
|
||||
View view = LayoutInflater.from(context).inflate(R.layout.dialog_checkbox_builder, null);
|
||||
setView(view);
|
||||
TextView messageView = (TextView) view.findViewById(R.id.message);
|
||||
mCheckBox = (CheckBox) view.findViewById(R.id.checkbox);
|
||||
messageView.setText(message);
|
||||
mCheckBox.setText(checkText);
|
||||
mCheckBox.setChecked(checked);
|
||||
}
|
||||
|
||||
public boolean isChecked() {
|
||||
return mCheckBox.isChecked();
|
||||
}
|
||||
}
|
||||
@@ -20,12 +20,16 @@ import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.database.sqlite.SQLiteOpenHelper;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.util.Log;
|
||||
|
||||
import com.hippo.ehviewer.client.data.GalleryInfo;
|
||||
import com.hippo.ehviewer.client.data.ListUrlBuilder;
|
||||
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.DownloadLabelDao;
|
||||
@@ -268,7 +272,7 @@ public class EhDB {
|
||||
}
|
||||
}
|
||||
|
||||
private static void addGalleryInfo(GalleryInfo galleryInfo) {
|
||||
private static synchronized void addGalleryInfo(GalleryInfo galleryInfo) {
|
||||
GalleryInfoDao dao = sDaoSession.getGalleryInfoDao();
|
||||
GalleryInfoRaw raw = dao.load((long) galleryInfo.gid);
|
||||
if (raw == null) {
|
||||
@@ -291,7 +295,7 @@ public class EhDB {
|
||||
}
|
||||
}
|
||||
|
||||
private static void removeGalleryInfo(int gid) {
|
||||
private static synchronized void removeGalleryInfo(int gid) {
|
||||
GalleryInfoDao dao = sDaoSession.getGalleryInfoDao();
|
||||
GalleryInfoRaw raw = dao.load((long) gid);
|
||||
int reference = raw.getReference();
|
||||
@@ -305,7 +309,7 @@ public class EhDB {
|
||||
}
|
||||
}
|
||||
|
||||
public static GalleryInfo getGalleryInfo(int gid) {
|
||||
public static synchronized GalleryInfo getGalleryInfo(int gid) {
|
||||
GalleryInfoDao dao = sDaoSession.getGalleryInfoDao();
|
||||
GalleryInfoRaw raw = dao.load((long) gid);
|
||||
if (raw != null) {
|
||||
@@ -325,7 +329,8 @@ public class EhDB {
|
||||
}
|
||||
}
|
||||
|
||||
public static List<String> getAllDownloadLabelList() {
|
||||
@NonNull
|
||||
public static synchronized List<String> getAllDownloadLabelList() {
|
||||
DownloadLabelDao dao = sDaoSession.getDownloadLabelDao();
|
||||
List<DownloadLabelRaw> list = dao.queryBuilder().orderAsc(DownloadLabelDao.Properties.Time).list();
|
||||
List<String> result = new ArrayList<>(list.size());
|
||||
@@ -335,12 +340,12 @@ public class EhDB {
|
||||
return result;
|
||||
}
|
||||
|
||||
public static LazyList<DownloadInfoRaw> getDownloadInfoLazyList() {
|
||||
public static synchronized LazyList<DownloadInfoRaw> getDownloadInfoLazyList() {
|
||||
return sDaoSession.getDownloadInfoDao().queryBuilder()
|
||||
.orderAsc(DownloadInfoDao.Properties.Date).listLazy();
|
||||
}
|
||||
|
||||
public static void addDownloadInfo(DownloadInfo info) {
|
||||
public static synchronized void addDownloadInfo(DownloadInfo info) {
|
||||
// Add gallery info first
|
||||
addGalleryInfo(info.galleryInfo);
|
||||
// Add download info
|
||||
@@ -354,7 +359,7 @@ public class EhDB {
|
||||
dao.insert(raw);
|
||||
}
|
||||
|
||||
public static void updateDownloadInfo(DownloadInfo info) {
|
||||
public static synchronized void updateDownloadInfo(DownloadInfo info) {
|
||||
DownloadInfoDao dao = sDaoSession.getDownloadInfoDao();
|
||||
DownloadInfoRaw raw = dao.load((long) info.galleryInfo.gid);
|
||||
if (raw == null) {
|
||||
@@ -368,4 +373,45 @@ public class EhDB {
|
||||
dao.update(raw);
|
||||
}
|
||||
}
|
||||
|
||||
public static synchronized void removeDownloadInfo(int gid) {
|
||||
DownloadInfoDao dao = sDaoSession.getDownloadInfoDao();
|
||||
if (null != dao.load((long) gid)) {
|
||||
removeGalleryInfo(gid);
|
||||
dao.deleteByKey((long) gid);
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static synchronized String getDownloadDirname(int gid) {
|
||||
DownloadDirnameDao dao = sDaoSession.getDownloadDirnameDao();
|
||||
DownloadDirnameRaw raw = dao.load((long) gid);
|
||||
if (raw != null) {
|
||||
return raw.getDirname();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert or update
|
||||
*/
|
||||
public static synchronized void putDownloadDirname(int gid, String dirname) {
|
||||
DownloadDirnameDao dao = sDaoSession.getDownloadDirnameDao();
|
||||
DownloadDirnameRaw raw = dao.load((long) gid);
|
||||
if (raw != null) { // Update
|
||||
raw.setDirname(dirname);
|
||||
dao.update(raw);
|
||||
} else { // Insert
|
||||
raw = new DownloadDirnameRaw();
|
||||
raw.setGid((long) gid);
|
||||
raw.setDirname(dirname);
|
||||
dao.insert(raw);
|
||||
}
|
||||
}
|
||||
|
||||
public static synchronized void removeDownloadDirname(int gid) {
|
||||
DownloadDirnameDao dao = sDaoSession.getDownloadDirnameDao();
|
||||
dao.deleteByKey((long) gid);
|
||||
}
|
||||
}
|
||||
@@ -117,7 +117,7 @@ public class Settings {
|
||||
putBoolean(KEY_SHOW_WARNING, value);
|
||||
}
|
||||
|
||||
public static final String KEY_RECENT_DOWNLOAD_LABEL = "recent_download_label";
|
||||
private static final String KEY_RECENT_DOWNLOAD_LABEL = "recent_download_label";
|
||||
private static final String DEFAULT_RECENT_DOWNLOAD_LABEL = null;
|
||||
|
||||
public static String getRecentDownloadLabel() {
|
||||
@@ -128,6 +128,16 @@ public class Settings {
|
||||
putString(KEY_RECENT_DOWNLOAD_LABEL, value);
|
||||
}
|
||||
|
||||
private static final String KEY_REMOVE_IMAGE_FILES = "include_pic";
|
||||
private static final boolean DEFAULT_REMOVE_IMAGE_FILES = true;
|
||||
|
||||
public static boolean getRemoveImageFiles() {
|
||||
return getBoolean(KEY_REMOVE_IMAGE_FILES, DEFAULT_REMOVE_IMAGE_FILES);
|
||||
}
|
||||
|
||||
public static void putRemoveImageFiles(boolean value) {
|
||||
putBoolean(KEY_REMOVE_IMAGE_FILES, value);
|
||||
}
|
||||
|
||||
public static EhConfig getEhConfig() {
|
||||
return sEhConfig;
|
||||
|
||||
@@ -45,18 +45,21 @@ public class DownloadManager implements SpiderQueen.OnSpiderListener {
|
||||
|
||||
private final Context mContext;
|
||||
|
||||
@NonNull
|
||||
private final Map<String, LinkedList<DownloadInfo>> mMap;
|
||||
// All labels without default label
|
||||
@NonNull
|
||||
private final List<String> mLabelList;
|
||||
// Store download info with default label
|
||||
@NonNull
|
||||
private final LinkedList<DownloadInfo> mDefaultInfoList;
|
||||
// Store all download info
|
||||
private final LinkedList<DownloadInfo> mAllInfoList;
|
||||
// For quick search
|
||||
@NonNull
|
||||
private final SparseArray<DownloadInfo> mAllInfoMap;
|
||||
// Store download info wait to start
|
||||
@NonNull
|
||||
private final LinkedList<DownloadInfo> mWaitList;
|
||||
|
||||
@NonNull
|
||||
private final SpeedReminder mSpeedReminder;
|
||||
|
||||
private DownloadListener mDownloadListener;
|
||||
@@ -82,8 +85,6 @@ public class DownloadManager implements SpiderQueen.OnSpiderListener {
|
||||
}
|
||||
// Create default for non tag
|
||||
mDefaultInfoList = new LinkedList<>();
|
||||
// Create all download info list
|
||||
mAllInfoList = new LinkedList<>();
|
||||
// Create all download info map
|
||||
mAllInfoMap = new SparseArray<>();
|
||||
|
||||
@@ -95,18 +96,17 @@ public class DownloadManager implements SpiderQueen.OnSpiderListener {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Add to all info list
|
||||
mAllInfoList.add(info);
|
||||
// Add to all info map
|
||||
mAllInfoMap.put(info.galleryInfo.gid, info);
|
||||
|
||||
// Add to list
|
||||
List<DownloadInfo> list = null;
|
||||
if (info.label != null) {
|
||||
list = mMap.get(info.label);
|
||||
}
|
||||
LinkedList<DownloadInfo> list = getInfoListForLabel(info.label);
|
||||
if (list == null) {
|
||||
list = mDefaultInfoList;
|
||||
list = new LinkedList<>();
|
||||
mMap.put(info.label, list);
|
||||
if (!mLabelList.contains(info.label)) {
|
||||
mLabelList.add(info.label);
|
||||
}
|
||||
}
|
||||
list.add(info);
|
||||
}
|
||||
@@ -119,7 +119,7 @@ public class DownloadManager implements SpiderQueen.OnSpiderListener {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private DownloadInfo createDownloadInfo(DownloadInfoRaw raw) {
|
||||
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());
|
||||
@@ -139,6 +139,15 @@ public class DownloadManager implements SpiderQueen.OnSpiderListener {
|
||||
return info;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private LinkedList<DownloadInfo> getInfoListForLabel(String label) {
|
||||
if (label == null) {
|
||||
return mDefaultInfoList;
|
||||
} else {
|
||||
return mMap.get(label);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean containLabel(String label) {
|
||||
return mLabelList.contains(label);
|
||||
}
|
||||
@@ -148,11 +157,6 @@ public class DownloadManager implements SpiderQueen.OnSpiderListener {
|
||||
return mLabelList;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public List<DownloadInfo> getAllDownloadInfoList() {
|
||||
return mAllInfoList;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public List<DownloadInfo> getDefaultDownloadInfoList() {
|
||||
return mDefaultInfoList;
|
||||
@@ -198,8 +202,9 @@ public class DownloadManager implements SpiderQueen.OnSpiderListener {
|
||||
mDownloadListener.onStart(info);
|
||||
}
|
||||
// Notify state update
|
||||
if (mDownloadInfoListener != null) {
|
||||
mDownloadInfoListener.onUpdate(info);
|
||||
List<DownloadInfo> list = getInfoListForLabel(info.label);
|
||||
if (list != null && mDownloadInfoListener != null) {
|
||||
mDownloadInfoListener.onUpdate(info, list);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -221,8 +226,9 @@ public class DownloadManager implements SpiderQueen.OnSpiderListener {
|
||||
// Update in DB
|
||||
EhDB.updateDownloadInfo(info);
|
||||
// Notify state update
|
||||
if (mDownloadInfoListener != null) {
|
||||
mDownloadInfoListener.onUpdate(info);
|
||||
List<DownloadInfo> list = getInfoListForLabel(info.label);
|
||||
if (list != null && mDownloadInfoListener != null) {
|
||||
mDownloadInfoListener.onUpdate(info, list);
|
||||
}
|
||||
// Make sure download is running
|
||||
ensureDownload();
|
||||
@@ -234,33 +240,27 @@ public class DownloadManager implements SpiderQueen.OnSpiderListener {
|
||||
info.label = label;
|
||||
info.state = DownloadInfo.STATE_WAIT;
|
||||
info.date = System.currentTimeMillis();
|
||||
// Add to all download list and map
|
||||
mAllInfoList.add(info);
|
||||
mAllInfoMap.put(galleryInfo.gid, info);
|
||||
|
||||
// Add to label download list
|
||||
LinkedList<DownloadInfo> list;
|
||||
if (label == null) {
|
||||
list = mDefaultInfoList;
|
||||
} else {
|
||||
list = mMap.get(label);
|
||||
if (list == null) {
|
||||
Log.e(TAG, "Can't find download info list with label: " + label);
|
||||
list = new LinkedList<>();
|
||||
mMap.put(label, list);
|
||||
// Maybe label is missing in mLabelList
|
||||
if (!mLabelList.contains(label)) {
|
||||
mLabelList.add(label);
|
||||
}
|
||||
}
|
||||
LinkedList<DownloadInfo> list = getInfoListForLabel(info.label);
|
||||
if (list == null) {
|
||||
Log.e(TAG, "Can't find download info list with label: " + label);
|
||||
return;
|
||||
}
|
||||
list.add(info);
|
||||
|
||||
// Add to all download list and map
|
||||
mAllInfoMap.put(galleryInfo.gid, info);
|
||||
|
||||
// Add to wait list
|
||||
mWaitList.add(info);
|
||||
|
||||
// Save to
|
||||
EhDB.addDownloadInfo(info);
|
||||
|
||||
// Notify
|
||||
if (mDownloadInfoListener != null) {
|
||||
mDownloadInfoListener.onAdd(info);
|
||||
mDownloadInfoListener.onAdd(info, list, list.size() - 1);
|
||||
}
|
||||
// Make sure download is running
|
||||
ensureDownload();
|
||||
@@ -271,8 +271,9 @@ public class DownloadManager implements SpiderQueen.OnSpiderListener {
|
||||
DownloadInfo info = stopDownloadInternal(gid);
|
||||
if (info != null) {
|
||||
// Update listener
|
||||
if (mDownloadInfoListener != null) {
|
||||
mDownloadInfoListener.onUpdate(info);
|
||||
List<DownloadInfo> list = getInfoListForLabel(info.label);
|
||||
if (list != null && mDownloadInfoListener != null) {
|
||||
mDownloadInfoListener.onUpdate(info, list);
|
||||
}
|
||||
// Ensure download
|
||||
ensureDownload();
|
||||
@@ -283,8 +284,9 @@ public class DownloadManager implements SpiderQueen.OnSpiderListener {
|
||||
DownloadInfo info = stopCurrentDownloadInternal();
|
||||
if (info != null) {
|
||||
// Update listener
|
||||
if (mDownloadInfoListener != null) {
|
||||
mDownloadInfoListener.onUpdate(info);
|
||||
List<DownloadInfo> list = getInfoListForLabel(info.label);
|
||||
if (list != null && mDownloadInfoListener != null) {
|
||||
mDownloadInfoListener.onUpdate(info, list);
|
||||
}
|
||||
// Ensure download
|
||||
ensureDownload();
|
||||
@@ -309,6 +311,34 @@ public class DownloadManager implements SpiderQueen.OnSpiderListener {
|
||||
}
|
||||
}
|
||||
|
||||
void deleteDownload(int gid) {
|
||||
stopDownloadInternal(gid);
|
||||
DownloadInfo info = mAllInfoMap.get(gid);
|
||||
if (info != null) {
|
||||
// Remove from DB
|
||||
EhDB.removeDownloadInfo(info.galleryInfo.gid);
|
||||
|
||||
// Remove all list and map
|
||||
mAllInfoMap.remove(info.galleryInfo.gid);
|
||||
|
||||
// Remove label list
|
||||
LinkedList<DownloadInfo> list = getInfoListForLabel(info.label);
|
||||
if (list != null) {
|
||||
int index = list.indexOf(info);
|
||||
if (index >= 0) {
|
||||
list.remove(info);
|
||||
// Update listener
|
||||
if (mDownloadInfoListener != null) {
|
||||
mDownloadInfoListener.onRemove(info, list, index);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Ensure download
|
||||
ensureDownload();
|
||||
}
|
||||
}
|
||||
|
||||
// Update in DB
|
||||
// Update listener
|
||||
// No ensureDownload
|
||||
@@ -504,8 +534,9 @@ public class DownloadManager implements SpiderQueen.OnSpiderListener {
|
||||
Log.e(TAG, "Current task is null, but it should not be");
|
||||
} else {
|
||||
info.total = mPages;
|
||||
if (mDownloadInfoListener != null) {
|
||||
mDownloadInfoListener.onUpdate(info);
|
||||
List<DownloadInfo> list = getInfoListForLabel(info.label);
|
||||
if (list != null && mDownloadInfoListener != null) {
|
||||
mDownloadInfoListener.onUpdate(info, list);
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -530,8 +561,9 @@ public class DownloadManager implements SpiderQueen.OnSpiderListener {
|
||||
if (mDownloadListener != null) {
|
||||
mDownloadListener.onGetPage(info);
|
||||
}
|
||||
if (mDownloadInfoListener != null) {
|
||||
mDownloadInfoListener.onUpdate(info);
|
||||
List<DownloadInfo> list = getInfoListForLabel(info.label);
|
||||
if (list != null && mDownloadInfoListener != null) {
|
||||
mDownloadInfoListener.onUpdate(info, list);
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -543,8 +575,9 @@ public class DownloadManager implements SpiderQueen.OnSpiderListener {
|
||||
} else {
|
||||
info.download = mDownloaded;
|
||||
info.total = mTotal;
|
||||
if (mDownloadInfoListener != null) {
|
||||
mDownloadInfoListener.onUpdate(info);
|
||||
List<DownloadInfo> list = getInfoListForLabel(info.label);
|
||||
if (list != null && mDownloadInfoListener != null) {
|
||||
mDownloadInfoListener.onUpdate(info, list);
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -582,8 +615,9 @@ public class DownloadManager implements SpiderQueen.OnSpiderListener {
|
||||
if (mDownloadListener != null) {
|
||||
mDownloadListener.onFinish(info);
|
||||
}
|
||||
if (mDownloadInfoListener != null) {
|
||||
mDownloadInfoListener.onUpdate(info);
|
||||
List<DownloadInfo> list = getInfoListForLabel(info.label);
|
||||
if (list != null && mDownloadInfoListener != null) {
|
||||
mDownloadInfoListener.onUpdate(info, list);
|
||||
}
|
||||
// Start next download
|
||||
ensureDownload();
|
||||
@@ -629,8 +663,9 @@ public class DownloadManager implements SpiderQueen.OnSpiderListener {
|
||||
if (mDownloadListener != null) {
|
||||
mDownloadListener.onDownload(info);
|
||||
}
|
||||
if (mDownloadInfoListener != null) {
|
||||
mDownloadInfoListener.onUpdate(info);
|
||||
List<DownloadInfo> list = getInfoListForLabel(info.label);
|
||||
if (list != null && mDownloadInfoListener != null) {
|
||||
mDownloadInfoListener.onUpdate(info, list);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -642,13 +677,13 @@ public class DownloadManager implements SpiderQueen.OnSpiderListener {
|
||||
|
||||
public interface DownloadInfoListener {
|
||||
|
||||
void onAdd(DownloadInfo info);
|
||||
void onAdd(DownloadInfo info, List<DownloadInfo> list, int position);
|
||||
|
||||
void onUpdate(DownloadInfo info);
|
||||
void onUpdate(DownloadInfo info, List<DownloadInfo> list);
|
||||
|
||||
void onUpdateAll();
|
||||
|
||||
void onRemove(DownloadInfo info);
|
||||
void onRemove(DownloadInfo info, List<DownloadInfo> list, int position);
|
||||
}
|
||||
|
||||
public interface DownloadListener {
|
||||
|
||||
@@ -40,6 +40,7 @@ public class DownloadService extends Service implements DownloadManager.Download
|
||||
public static final String ACTION_STOP = "stop";
|
||||
public static final String ACTION_STOP_CURRENT = "stop_current";
|
||||
public static final String ACTION_STOP_ALL = "stop_all";
|
||||
public static final String ACTION_DELETE = "delete";
|
||||
|
||||
public static final String ACTION_CLEAR = "clear";
|
||||
|
||||
@@ -148,6 +149,11 @@ public class DownloadService extends Service implements DownloadManager.Download
|
||||
if (mDownloadManager != null) {
|
||||
mDownloadManager.stopAllDownload();
|
||||
}
|
||||
} else if (ACTION_DELETE.equals(action)) {
|
||||
int gid = intent.getIntExtra(KEY_GID, -1);
|
||||
if (gid != -1 && mDownloadManager != null) {
|
||||
mDownloadManager.deleteDownload(gid);
|
||||
}
|
||||
} else if (ACTION_CLEAR.equals(action)) {
|
||||
EhApplication.clearDownloadService(getApplicationContext(), this);
|
||||
}
|
||||
|
||||
@@ -62,11 +62,18 @@ public final class SpiderDen {
|
||||
public static UniFile getGalleryDownloadDir(GalleryInfo galleryInfo) {
|
||||
UniFile dir = Settings.getDownloadLocation();
|
||||
if (dir != null) {
|
||||
GalleryInfo info = EhDB.getGalleryInfo(galleryInfo.gid);
|
||||
if (info == null) {
|
||||
info = galleryInfo;
|
||||
// Read from DB
|
||||
String dirname = EhDB.getDownloadDirname(galleryInfo.gid);
|
||||
if (dirname == null) {
|
||||
GalleryInfo info = EhDB.getGalleryInfo(galleryInfo.gid);
|
||||
if (info == null) {
|
||||
info = galleryInfo;
|
||||
}
|
||||
dirname = FileUtils.sanitizeFilename(info.gid + "-" + info.title);
|
||||
// Put into DB
|
||||
EhDB.putDownloadDirname(info.gid, dirname);
|
||||
}
|
||||
return dir.subFile(FileUtils.sanitizeFilename(info.gid + "-" + info.title));
|
||||
return dir.subFile(dirname);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -19,7 +19,9 @@ package com.hippo.ehviewer.ui.scene;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.annotation.TargetApi;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
@@ -35,8 +37,10 @@ import android.view.ViewGroup;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.hippo.app.CheckBoxDialogBuilder;
|
||||
import com.hippo.easyrecyclerview.EasyRecyclerView;
|
||||
import com.hippo.ehviewer.EhApplication;
|
||||
import com.hippo.ehviewer.EhDB;
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.Settings;
|
||||
import com.hippo.ehviewer.client.EhCacheKeyFactory;
|
||||
@@ -45,11 +49,13 @@ import com.hippo.ehviewer.client.data.GalleryInfo;
|
||||
import com.hippo.ehviewer.download.DownloadInfo;
|
||||
import com.hippo.ehviewer.download.DownloadManager;
|
||||
import com.hippo.ehviewer.download.DownloadService;
|
||||
import com.hippo.ehviewer.spider.SpiderDen;
|
||||
import com.hippo.ehviewer.ui.GalleryActivity;
|
||||
import com.hippo.ehviewer.widget.SimpleRatingView;
|
||||
import com.hippo.rippleold.RippleSalon;
|
||||
import com.hippo.scene.Announcer;
|
||||
import com.hippo.scene.TransitionHelper;
|
||||
import com.hippo.unifile.UniFile;
|
||||
import com.hippo.util.ActivityHelper;
|
||||
import com.hippo.util.ApiHelper;
|
||||
import com.hippo.vector.VectorDrawable;
|
||||
@@ -57,7 +63,6 @@ import com.hippo.view.ViewTransition;
|
||||
import com.hippo.widget.LoadImageView;
|
||||
import com.hippo.widget.SimpleImageView;
|
||||
import com.hippo.yorozuya.FileUtils;
|
||||
import com.hippo.yorozuya.ObjectUtils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -221,23 +226,24 @@ public class DownloadScene extends ToolbarScene
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAdd(DownloadInfo info) {
|
||||
// TODO
|
||||
public void onAdd(DownloadInfo info, List<DownloadInfo> list, int position) {
|
||||
if (mList != list) {
|
||||
return;
|
||||
}
|
||||
if (mAdapter != null) {
|
||||
mAdapter.notifyItemInserted(position);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpdate(DownloadInfo info) {
|
||||
if (!ObjectUtils.equal(info.label, mLabel)) {
|
||||
public void onUpdate(DownloadInfo info, List<DownloadInfo> list) {
|
||||
if (mList != list) {
|
||||
return;
|
||||
}
|
||||
RecyclerView recyclerView = mRecyclerView;
|
||||
if (recyclerView == null) {
|
||||
return;
|
||||
}
|
||||
List<DownloadInfo> list = mList;
|
||||
if (list == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
int size = list.size();
|
||||
for (int i = 0, n = recyclerView.getChildCount(); i < n; i++) {
|
||||
@@ -276,8 +282,17 @@ public class DownloadScene extends ToolbarScene
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRemove(DownloadInfo info) {
|
||||
public void onRemove(DownloadInfo info, List<DownloadInfo> list, int position) {
|
||||
if (mList != list) {
|
||||
return;
|
||||
}
|
||||
if (mAdapter != null) {
|
||||
mAdapter.notifyItemRemoved(position);
|
||||
}
|
||||
|
||||
if (mList != null && mList.size() == 0 && mViewTransition != null) {
|
||||
mViewTransition.showView(1);
|
||||
}
|
||||
}
|
||||
|
||||
private void bindForState(DownloadHolder holder, DownloadInfo info) {
|
||||
@@ -344,6 +359,48 @@ public class DownloadScene extends ToolbarScene
|
||||
holder.speed.setText(FileUtils.humanReadableByteCount(speed, false) + "/S");
|
||||
}
|
||||
|
||||
private class DeleteDialogHelper implements DialogInterface.OnClickListener {
|
||||
|
||||
private final GalleryInfo mGalleryInfo;
|
||||
private final CheckBoxDialogBuilder mBuilder;
|
||||
|
||||
public DeleteDialogHelper(GalleryInfo galleryInfo, CheckBoxDialogBuilder builder) {
|
||||
mGalleryInfo = galleryInfo;
|
||||
mBuilder = builder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
if (which != DialogInterface.BUTTON_POSITIVE) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Delete
|
||||
Intent intent = new Intent(getActivity(), DownloadService.class);
|
||||
intent.setAction(DownloadService.ACTION_DELETE);
|
||||
intent.putExtra(DownloadService.KEY_GID, mGalleryInfo.gid);
|
||||
getActivity().startService(intent);
|
||||
|
||||
boolean checked = mBuilder.isChecked();
|
||||
Settings.putRemoveImageFiles(checked);
|
||||
if (checked) {
|
||||
// Remove download path
|
||||
EhDB.removeDownloadDirname(mGalleryInfo.gid);
|
||||
// Delete file
|
||||
UniFile file = SpiderDen.getGalleryDownloadDir(mGalleryInfo);
|
||||
new AsyncTask<UniFile, Void, Void>() {
|
||||
@Override
|
||||
protected Void doInBackground(UniFile... params) {
|
||||
for (UniFile file: params) {
|
||||
file.delete();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}.execute(file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class DownloadHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
|
||||
|
||||
public final LoadImageView thumb;
|
||||
@@ -421,7 +478,15 @@ public class DownloadScene extends ToolbarScene
|
||||
intent.putExtra(DownloadService.KEY_GID, list.get(index).galleryInfo.gid);
|
||||
getActivity().startService(intent);
|
||||
} else if (delete == v) {
|
||||
// TODO
|
||||
GalleryInfo galleryInfo = list.get(index).galleryInfo;
|
||||
CheckBoxDialogBuilder builder = new CheckBoxDialogBuilder(getContext(),
|
||||
getString(R.string.download_remove_dialog_message, galleryInfo.title),
|
||||
getString(R.string.download_remove_dialog_check_text),
|
||||
Settings.getRemoveImageFiles());
|
||||
DeleteDialogHelper helper = new DeleteDialogHelper(galleryInfo, builder);
|
||||
builder.setTitle(R.string.download_remove_dialog_title)
|
||||
.setPositiveButton(android.R.string.ok, helper)
|
||||
.show();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
~ 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.
|
||||
-->
|
||||
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<com.hippo.widget.IndicatingScrollView
|
||||
style="@style/IndicatingScrollView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/message"
|
||||
style="@style/TextAppearance.AppCompat.Subhead"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingLeft="?attr/dialogPreferredPadding"
|
||||
android:paddingTop="@dimen/abc_dialog_padding_top_material"
|
||||
android:paddingRight="?attr/dialogPreferredPadding"/>
|
||||
|
||||
</com.hippo.widget.IndicatingScrollView>
|
||||
|
||||
<android.support.v7.widget.AppCompatCheckBox
|
||||
android:id="@+id/checkbox"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="?attr/dialogPreferredPadding"
|
||||
android:layout_marginTop="@dimen/abc_dialog_padding_top_material"
|
||||
android:layout_marginRight="?attr/dialogPreferredPadding"/>
|
||||
|
||||
</LinearLayout>
|
||||
@@ -227,6 +227,9 @@
|
||||
<string name="stat_download_done_text_mix">%1$d succeeded, %2$d failed</string>
|
||||
<string name="stat_download_done_line_succeeded">Succeeded: %s</string>
|
||||
<string name="stat_download_done_line_failed">Failed: %s</string>
|
||||
<string name="download_remove_dialog_title">Remove Gallery</string>
|
||||
<string name="download_remove_dialog_message">Remove %s from download list ?</string>
|
||||
<string name="download_remove_dialog_check_text">Remove image files</string>
|
||||
|
||||
<!-- Gallery Activity -->
|
||||
<string name="page_menu_title">Page %d</string>
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@ buildscript {
|
||||
jcenter()
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:2.0.0-beta5'
|
||||
classpath 'com.android.tools.build:gradle:2.0.0-beta6'
|
||||
|
||||
// NOTE: Do not place your application dependencies here; they belong
|
||||
// in the individual module build.gradle files
|
||||
|
||||
@@ -40,6 +40,7 @@ public class EhDaoGenerator {
|
||||
addGalleryInfo(schema);
|
||||
addDownloadInfo(schema);
|
||||
addDownloadLabel(schema);
|
||||
addDownloadDirname(schema);
|
||||
addHistoryInfo(schema);
|
||||
addQuickSearch(schema);
|
||||
addLocalFavorite(schema);
|
||||
@@ -81,6 +82,14 @@ public class EhDaoGenerator {
|
||||
entity.addLongProperty("time");
|
||||
}
|
||||
|
||||
private static void addDownloadDirname(Schema schema) {
|
||||
Entity entity = schema.addEntity("DownloadDirnameRaw");
|
||||
entity.setTableName("DOWNLOAD_DIRNAME");
|
||||
entity.setClassNameDao("DownloadDirnameDao");
|
||||
entity.addLongProperty("gid").primaryKey();
|
||||
entity.addStringProperty("dirname");
|
||||
}
|
||||
|
||||
private static void addHistoryInfo(Schema schema) {
|
||||
Entity entity = schema.addEntity("HistoryInfoRaw");
|
||||
entity.setTableName("HISTORY_INFO");
|
||||
|
||||
Reference in new issue
Block a user