Skip to content

Commit 6493a67

Browse files
committed
修复档案下载在通知栏没有正确显示的bug
在下载档案时,在对应画廊添加了下载进度条
1 parent 122ce51 commit 6493a67

30 files changed

+339
-46
lines changed

app/src/main/AndroidManifest.xml

+3
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
<uses-permission android:name="android.permission.INTERNET" />
3131
<!-- 用于获取wifi状态 -->
3232
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
33+
<!-- 使用系统自带下载器 -->
34+
<uses-permission android:name="android.permission.ACCESS_DOWNLOAD_MANAGER" />
3335

3436
<uses-feature
3537
android:glEsVersion="0x00020000"
@@ -98,6 +100,7 @@
98100

99101
<intent-filter android:autoVerify="true">
100102
<action android:name="android.intent.action.VIEW" />
103+
101104
<category android:name="android.intent.category.DEFAULT" />
102105
<category android:name="android.intent.category.BROWSABLE" />
103106

app/src/main/java/com/hippo/ehviewer/Settings.java

+44-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616

1717
package com.hippo.ehviewer;
1818

19+
import static com.hippo.ehviewer.client.EhConfig.IMAGE_SIZE_780X;
20+
import static com.hippo.ehviewer.client.EhConfig.IMAGE_SIZE_980X;
21+
1922
import android.annotation.SuppressLint;
2023
import android.content.Context;
2124
import android.content.SharedPreferences;
@@ -26,9 +29,13 @@
2629
import androidx.annotation.DimenRes;
2730
import androidx.annotation.NonNull;
2831
import androidx.annotation.Nullable;
32+
33+
import com.alibaba.fastjson.JSONObject;
2934
import com.hippo.ehviewer.client.EhConfig;
3035
import com.hippo.ehviewer.client.EhUtils;
3136
import com.hippo.ehviewer.client.data.FavListUrlBuilder;
37+
import com.hippo.ehviewer.client.data.GalleryDetail;
38+
import com.hippo.ehviewer.client.data.GalleryInfo;
3239
import com.hippo.ehviewer.ui.CommonOperations;
3340
import com.hippo.ehviewer.ui.scene.gallery.list.GalleryListScene;
3441
import com.hippo.lib.glgallery.GalleryView;
@@ -38,6 +45,7 @@
3845
import com.hippo.yorozuya.FileUtils;
3946
import com.hippo.yorozuya.MathUtils;
4047
import com.hippo.yorozuya.NumberUtils;
48+
4149
import java.io.File;
4250
import java.util.Locale;
4351

@@ -48,11 +56,13 @@ public class Settings {
4856
@SuppressLint("StaticFieldLeak")
4957
private static Context sContext;
5058
private static SharedPreferences sSettingsPre;
59+
private static SharedPreferences sArchiverPre;
5160
private static EhConfig sEhConfig;
5261

5362
public static void initialize(Context context) {
5463
sContext = context.getApplicationContext();
5564
sSettingsPre = PreferenceManager.getDefaultSharedPreferences(sContext);
65+
sArchiverPre = context.getSharedPreferences("archiver_cache",Context.MODE_PRIVATE);
5666
sEhConfig = loadEhConfig();
5767
fixDefaultValue();
5868
}
@@ -83,6 +93,34 @@ private static EhConfig loadEhConfig() {
8393
return ehConfig;
8494
}
8595

96+
public static GalleryInfo getArchiverDownload(long downloadId){
97+
String s = sArchiverPre.getString(String.valueOf(downloadId),"");
98+
if (s.isEmpty()){
99+
return null;
100+
}
101+
return GalleryInfo.galleryInfoFromJson(JSONObject.parseObject(s));
102+
}
103+
104+
public static void putArchiverDownload(long downloadId,GalleryInfo info){
105+
sArchiverPre.edit().putString(String.valueOf(downloadId),info.toJson().toJSONString()).apply();
106+
}
107+
108+
public static boolean deleteArchiverDownload(long downloadId){
109+
return sArchiverPre.edit().remove(String.valueOf(downloadId)).commit();
110+
}
111+
112+
public static long getArchiverDownloadId(long gid){
113+
return sArchiverPre.getLong(gid+"DId",-1L);
114+
}
115+
116+
public static void putArchiverDownloadId(long gid,long downloadId){
117+
sArchiverPre.edit().putLong(gid+"DId",downloadId).apply();
118+
}
119+
120+
public static boolean deleteArchiverDownloadId(long gid){
121+
return sArchiverPre.edit().remove(gid+"DId").commit();
122+
}
123+
86124
public static boolean getBoolean(String key, boolean defValue) {
87125
try {
88126
return sSettingsPre.getBoolean(key, defValue);
@@ -745,7 +783,12 @@ public static void putPreloadImage(int value) {
745783
public static final String DEFAULT_IMAGE_RESOLUTION = EhConfig.IMAGE_SIZE_AUTO;
746784

747785
public static String getImageResolution() {
748-
return getString(KEY_IMAGE_RESOLUTION, DEFAULT_IMAGE_RESOLUTION);
786+
String result = getString(KEY_IMAGE_RESOLUTION, DEFAULT_IMAGE_RESOLUTION);
787+
if (result.equals(IMAGE_SIZE_980X)){
788+
putImageResolution(IMAGE_SIZE_780X);
789+
return IMAGE_SIZE_780X;
790+
}
791+
return result;
749792
}
750793

751794
public static void putImageResolution(String value) {

app/src/main/java/com/hippo/ehviewer/client/EhConfig.java

+3
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,10 @@ public class EhConfig implements Cloneable {
220220
public static final String IMAGE_SIZE_780X = "780";
221221
/**
222222
* Image Size 980x
223+
* 2024-09-11
224+
* - The 980x resample option has been retired due to a combination of performance/overhead issues and lack of use.
223225
*/
226+
@Deprecated
224227
public static final String IMAGE_SIZE_980X = "980";
225228
/**
226229
* Image Size 1280x

app/src/main/java/com/hippo/ehviewer/ui/dialog/ArchiverDownloadDialog.java

+18-23
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import com.hippo.ehviewer.client.EhUrl;
3535
import com.hippo.ehviewer.client.data.ArchiverData;
3636
import com.hippo.ehviewer.client.data.GalleryDetail;
37+
import com.hippo.ehviewer.client.data.GalleryInfo;
3738
import com.hippo.ehviewer.client.exception.NoHAtHClientException;
3839
import com.hippo.ehviewer.dao.DownloadInfo;
3940
import com.hippo.ehviewer.spider.SpiderDen;
@@ -206,36 +207,23 @@ public void onSuccess(String downloadUrl) {
206207
DownloadManager.Request request = new DownloadManager.Request(downloadUri);
207208
request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_MOBILE | DownloadManager.Request.NETWORK_WIFI);
208209
request.setAllowedOverRoaming(true);
209-
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
210+
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE);
210211
request.setTitle(galleryDetail.title);
211212
request.setDescription(context.getString(R.string.download_archive_started));
212213
request.setVisibleInDownloadsUi(true);
213-
// request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "EhviewerArchiver/"+galleryDetail.title + ".zip");
214-
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "EhviewerArchiver/"+"[Abe Nattsu] SEX de Wakaru Unmei no Hito ~ Karada no Aishou... Tameshite miru? ~ Ch. 1-6 [Chinese] [裸單騎漢化]" + ".zip");
214+
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "EhviewerArchiver/"+galleryDetail.title + ".zip");
215215
request.allowScanningByMediaScanner();
216216

217217
DownloadManager downloadManager = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
218-
myDownloadId = downloadManager.enqueue(request);
219218

220-
context.registerReceiver(downloadReceiver, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));
219+
// downloadManager.query(new DownloadManager.Query().setFilterByStatus(DownloadManager.STATUS_PAUSED));
221220

221+
myDownloadId = downloadManager.enqueue(request);
222+
Settings.putArchiverDownloadId(galleryDetail.gid,myDownloadId);
223+
Settings.putArchiverDownload(myDownloadId,galleryDetail);
224+
detailScene.bindArchiverProgress(galleryDetail);
222225

223-
// String path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getPath();
224-
// String name = galleryDetail.title + ".zip";
225-
// DownloadArchiverManager.Archiver archiver = new DownloadArchiverManager.Archiver(downloadUrl,path,name);
226-
// final DownloadArchiverManager manager = archiverDownloadDialog.downloadArchiverManager;
227-
// manager.addDownloadArchiverListener(this);
228-
//
229-
// NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
230-
// if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
231-
// NotificationChannel channel = new NotificationChannel(CHANNEL_ID,context.getString(R.string.download_service),NotificationManager.IMPORTANCE_LOW);
232-
// notificationManager.createNotificationChannel(channel);
233-
// }
234-
// NotificationCompat.Builder builder = new NotificationCompat.Builder(context,CHANNEL_ID)
235-
// .setContentTitle(context.getString(R.string.download))
236-
// .setContentText(archiver.name)
237-
// .setSmallIcon(R.mipmap.ic_launcher)
238-
// .setProgress(100,0,false);
226+
context.registerReceiver(downloadReceiver, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));
239227
}
240228

241229
@Override
@@ -322,18 +310,19 @@ private void unzipAndImportFile(Cursor cursor) throws IllegalArgumentException,
322310
if (tempDir == null) {
323311
return;
324312
}
313+
long downloadId = cursor.getLong(cursor.getColumnIndexOrThrow(DownloadManager.COLUMN_ID));
325314
String tempFilePath = tempDir.getPath() + "/" + galleryDetail.title;
326315
String zipFilePath = zipFile.getPath();
327316
new Thread(() -> {
328317
boolean result = GZIPUtils.UnZipFolder(zipFilePath, tempFilePath);
329318
if (!result) {
330319
return;
331320
}
332-
importGallery(tempFilePath);
321+
importGallery(tempFilePath,downloadId);
333322
}).start();
334323
}
335324

336-
private void importGallery(String tempFilePath) {
325+
private void importGallery(String tempFilePath, long downloadId) {
337326
if (tempFilePath.isEmpty() || context == null) {
338327
return;
339328
}
@@ -398,6 +387,12 @@ private void importGallery(String tempFilePath) {
398387
if (downloadReceiver != null) {
399388
context.unregisterReceiver(downloadReceiver);
400389
}
390+
GalleryInfo info = Settings.getArchiverDownload(downloadId);
391+
if (info==null){
392+
return;
393+
}
394+
Settings.deleteArchiverDownloadId(info.gid);
395+
Settings.deleteArchiverDownload(downloadId);
401396
});
402397
}
403398
}

app/src/main/java/com/hippo/ehviewer/ui/scene/download/DownloadsScene.java

-3
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@
1818

1919
import static com.hippo.ehviewer.spider.SpiderDen.getGalleryDownloadDir;
2020
import static com.hippo.ehviewer.spider.SpiderInfo.getSpiderInfo;
21-
import static com.hippo.ehviewer.ui.scene.gallery.detail.GalleryDetailScene.KEY_COME_FROM_DOWNLOAD;
2221

23-
import android.animation.Animator;
2422
import android.annotation.SuppressLint;
2523
import android.app.Activity;
2624
import android.content.Context;
@@ -1590,7 +1588,6 @@ public void onClick(View v) {
15901588
Bundle args = new Bundle();
15911589
args.putString(GalleryDetailScene.KEY_ACTION, GalleryDetailScene.ACTION_DOWNLOAD_GALLERY_INFO);
15921590
args.putParcelable(GalleryDetailScene.KEY_GALLERY_INFO, list.get(positionInList(index)));
1593-
args.putBoolean(KEY_COME_FROM_DOWNLOAD, true);
15941591
Announcer announcer = new Announcer(GalleryDetailScene.class).setArgs(args);
15951592
announcer.setTranHelper(new EnterGalleryDetailTransaction(thumb));
15961593
startScene(announcer);

app/src/main/java/com/hippo/ehviewer/ui/scene/gallery/detail/GalleryDetailScene.java

+12-17
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
import android.os.Looper;
3333
import android.os.Message;
3434
import android.text.TextUtils;
35-
import android.util.Log;
3635
import android.util.Pair;
3736
import android.view.Gravity;
3837
import android.view.LayoutInflater;
@@ -108,6 +107,7 @@
108107
import com.hippo.ehviewer.ui.scene.gallery.list.GalleryListScene;
109108
import com.hippo.ehviewer.util.AppCenterAnalytics;
110109
import com.hippo.ehviewer.util.ClipboardUtil;
110+
import com.hippo.ehviewer.widget.ArchiverDownloadProgress;
111111
import com.hippo.ehviewer.widget.GalleryRatingBar;
112112
import com.hippo.reveal.ViewAnimationUtils;
113113
import com.hippo.ripple.Ripple;
@@ -177,8 +177,6 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
177177
public static final String ACTION_GID_TOKEN = "action_gid_token";
178178

179179
public static final String KEY_GALLERY_INFO = "gallery_info";
180-
181-
public static final String KEY_COME_FROM_DOWNLOAD = "come_from_download";
182180
public static final String KEY_GID = "gid";
183181
public static final String KEY_TOKEN = "token";
184182
public static final String KEY_PAGE = "page";
@@ -282,6 +280,8 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
282280
@Nullable
283281
private View mProgress;
284282
@Nullable
283+
private ArchiverDownloadProgress mArchiverDownloadProgress;
284+
@Nullable
285285
private ViewTransition mViewTransition2;
286286
@Nullable
287287
private PopupMenu mPopupMenu;
@@ -327,8 +327,6 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
327327

328328
private boolean useNetWorkLoadThumb = false;
329329

330-
private boolean comeFromDownload = false;
331-
332330
private Context mContext;
333331
private MainActivity activity;
334332

@@ -368,7 +366,6 @@ private void handleArgs(Bundle args) {
368366
// Add history
369367

370368
}
371-
comeFromDownload = args.getBoolean(KEY_COME_FROM_DOWNLOAD);
372369
}
373370

374371
@Nullable
@@ -577,6 +574,7 @@ public boolean shouldBlockGesture(MotionEvent ev) {
577574
mActionGroup = (ViewGroup) ViewUtils.$$(mHeader, R.id.action_card);
578575
mDownload = (TextView) ViewUtils.$$(mActionGroup, R.id.download);
579576
mHaveNewVersion = (TextView) ViewUtils.$$(mHeader, R.id.new_version);
577+
mArchiverDownloadProgress = (ArchiverDownloadProgress) ViewUtils.$$(mHeader, R.id.archiver_download_progress);
580578
mRead = ViewUtils.$$(mActionGroup, R.id.read);
581579
Ripple.addRipple(mOtherActions, isDarkTheme);
582580
Ripple.addRipple(mDownload, isDarkTheme);
@@ -711,6 +709,7 @@ public void onDestroyView() {
711709
mHaveNewVersion = null;
712710
mRead = null;
713711
mBelowHeader = null;
712+
mArchiverDownloadProgress = null;
714713

715714
mInfo = null;
716715
mLanguage = null;
@@ -1029,12 +1028,18 @@ private void bindViewSecond() {
10291028
}
10301029

10311030
updateFavoriteDrawable();
1032-
1031+
bindArchiverProgress(gd);
10331032
bindTags(gd.tags);
10341033
bindComments(gd.comments.comments);
10351034
bindPreviews(gd);
10361035
}
10371036

1037+
public void bindArchiverProgress(GalleryDetail gd) {
1038+
if (mArchiverDownloadProgress != null) {
1039+
mArchiverDownloadProgress.initThread(gd);
1040+
}
1041+
}
1042+
10381043
private void bindReadProgress(GalleryInfo info) {
10391044
if (mContext == null) {
10401045
mContext = getEHContext();
@@ -1706,16 +1711,6 @@ public void startDownloadAsNew(String updateUrl) {
17061711
request(updateUrl, GetGalleryDetailListener.RESULT_DETAIL);
17071712
}
17081713

1709-
public void gotoNewVersion(GalleryDetail detail) {
1710-
Bundle args = new Bundle();
1711-
args.putString(GalleryDetailScene.KEY_ACTION, GalleryDetailScene.ACTION_DOWNLOAD_GALLERY_INFO);
1712-
args.putParcelable(KEY_GALLERY_INFO, detail);
1713-
args.putBoolean(KEY_COME_FROM_DOWNLOAD, true);
1714-
Announcer announcer = new Announcer(GalleryDetailScene.class).setArgs(args);
1715-
announcer.setTranHelper(new EnterGalleryDetailTransaction(mThumb));
1716-
startScene(announcer);
1717-
}
1718-
17191714
@Override
17201715
public void onBackPressed() {
17211716
if (mViewTransition != null && mThumb != null &&

0 commit comments

Comments
 (0)