From 05453c539cb3b98002707487b4f9aa81587dcfdd Mon Sep 17 00:00:00 2001 From: xiaojie Date: Fri, 1 Mar 2024 16:12:28 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=BB=E5=BB=8A=E6=9B=B4=E6=96=B0=E9=80=BB?= =?UTF-8?q?=E8=BE=91=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hippo/ehviewer/ui/CommonOperations.java | 53 +++++++-------- .../gallery/detail/GalleryDetailScene.java | 68 +++++++++++-------- .../detail/GetGalleryDetailListener.java | 3 - app/src/main/res/values-de/strings.xml | 2 +- app/src/main/res/values-en/strings.xml | 2 +- app/src/main/res/values-zh-rCN/strings.xml | 2 +- app/src/main/res/values/strings.xml | 2 +- 7 files changed, 70 insertions(+), 62 deletions(-) diff --git a/app/src/main/java/com/hippo/ehviewer/ui/CommonOperations.java b/app/src/main/java/com/hippo/ehviewer/ui/CommonOperations.java index c5a38ee7f..0bce5e128 100644 --- a/app/src/main/java/com/hippo/ehviewer/ui/CommonOperations.java +++ b/app/src/main/java/com/hippo/ehviewer/ui/CommonOperations.java @@ -348,36 +348,33 @@ public static void startDownload(final MainActivity activity, final List { + String label1; + if (position == 0) { + label1 = null; + } else { + label1 = items[position]; + if (!dm.containLabel(label1)) { + label1 = null; } - // Notify - activity.showTip(R.string.added_to_download_list, BaseScene.LENGTH_SHORT); } + // Start download + for (GalleryInfo gi : toAdd) { + Intent intent = new Intent(activity, DownloadService.class); + intent.setAction(DownloadService.ACTION_START); + intent.putExtra(DownloadService.KEY_LABEL, label1); + intent.putExtra(DownloadService.KEY_GALLERY_INFO, gi); + activity.startService(intent); + } + // Save settings + if (builder.isChecked()) { + Settings.putHasDefaultDownloadLabel(true); + Settings.putDefaultDownloadLabel(label1); + } else { + Settings.putHasDefaultDownloadLabel(false); + } + // Notify + activity.showTip(R.string.added_to_download_list, BaseScene.LENGTH_SHORT); }, activity.getString(R.string.remember_download_label), false) .setTitle(R.string.download) .show(); diff --git a/app/src/main/java/com/hippo/ehviewer/ui/scene/gallery/detail/GalleryDetailScene.java b/app/src/main/java/com/hippo/ehviewer/ui/scene/gallery/detail/GalleryDetailScene.java index c00a0e154..e6ce3f2ed 100644 --- a/app/src/main/java/com/hippo/ehviewer/ui/scene/gallery/detail/GalleryDetailScene.java +++ b/app/src/main/java/com/hippo/ehviewer/ui/scene/gallery/detail/GalleryDetailScene.java @@ -802,35 +802,35 @@ private void setActionDrawable(TextView text, Drawable drawable) { private void ensureActionDrawable(Context context) { Drawable heart = DrawableManager.getVectorDrawable(context, R.drawable.v_heart_primary_x48); - if (mHeart!=null){ + if (mHeart != null) { setActionDrawable(mHeart, heart); } Drawable heartOutline = DrawableManager.getVectorDrawable(context, R.drawable.v_heart_outline_primary_x48); - if (mHeartOutline!=null){ + if (mHeartOutline != null) { setActionDrawable(mHeartOutline, heartOutline); } Drawable torrent = DrawableManager.getVectorDrawable(context, R.drawable.v_utorrent_primary_x48); - if (mTorrent!=null){ + if (mTorrent != null) { setActionDrawable(mTorrent, torrent); } Drawable archive = DrawableManager.getVectorDrawable(context, R.drawable.v_archive_primary_x48); - if (mArchive!=null){ + if (mArchive != null) { setActionDrawable(mArchive, archive); } Drawable share = DrawableManager.getVectorDrawable(context, R.drawable.v_share_primary_x48); - if (mShare!=null){ + if (mShare != null) { setActionDrawable(mShare, share); } Drawable rate = DrawableManager.getVectorDrawable(context, R.drawable.v_thumb_up_primary_x48); - if (mRate!=null){ + if (mRate != null) { setActionDrawable(mRate, rate); } Drawable similar = DrawableManager.getVectorDrawable(context, R.drawable.v_similar_primary_x48); - if (mSimilar!=null){ + if (mSimilar != null) { setActionDrawable(mSimilar, similar); } Drawable searchCover = DrawableManager.getVectorDrawable(context, R.drawable.v_file_find_primary_x48); - if (mSearchCover!=null){ + if (mSearchCover != null) { setActionDrawable(mSearchCover, searchCover); } } @@ -843,7 +843,11 @@ private boolean createCircularReveal() { int w = mColorBg.getWidth(); int h = mColorBg.getHeight(); if (ViewCompat.isAttachedToWindow(mColorBg) && w != 0 && h != 0) { - Resources resources = getEHContext().getResources(); + Context context = getEHContext(); + if (context == null) { + return false; + } + Resources resources = context.getResources(); int keylineMargin = resources.getDimensionPixelSize(R.dimen.keyline_margin); int thumbWidth = resources.getDimensionPixelSize(R.dimen.gallery_detail_thumb_width); int thumbHeight = resources.getDimensionPixelSize(R.dimen.gallery_detail_thumb_height); @@ -899,9 +903,12 @@ private void adjustViewVisibility(int state, boolean animation) { mViewTransition.showView(2, animation); break; } - + Context context = getEHContext(); + if (context == null) { + return; + } if ((oldState == STATE_INIT || oldState == STATE_FAILED || oldState == STATE_REFRESH) && - (state == STATE_NORMAL || state == STATE_REFRESH_HEADER) && AttrResources.getAttrBoolean(getEHContext(), androidx.appcompat.R.attr.isLightTheme)) { + (state == STATE_NORMAL || state == STATE_REFRESH_HEADER) && AttrResources.getAttrBoolean(context, androidx.appcompat.R.attr.isLightTheme)) { if (!createCircularReveal()) { SimpleHandler.getInstance().post(this::createCircularReveal); } @@ -1003,18 +1010,18 @@ private void bindViewSecond() { bindPreviews(gd); } - private void bindReadProgress(GalleryInfo info){ - if (mContext== null){ + private void bindReadProgress(GalleryInfo info) { + if (mContext == null) { mContext = getEHContext(); - if (mContext==null){ + if (mContext == null) { return; } } - if (executorService == null){ + if (executorService == null) { executorService = EhApplication.getExecutorService(mContext); } - executorService.submit(()->{ + executorService.submit(() -> { int startPage = SpiderQueen.findStartPage(this.mContext, info); int pages = info.pages; String text; @@ -1023,8 +1030,8 @@ private void bindReadProgress(GalleryInfo info){ } else { text = "0/" + pages + "P"; } - handler.post(()->{ - if (mPages==null){ + handler.post(() -> { + if (mPages == null) { return; } mPages.setText(text); @@ -1122,7 +1129,7 @@ private void bindComments(GalleryComment[] comments) { user.setText(comment.user); TextView time = v.findViewById(R.id.time); time.setText(ReadableTime.getTimeAgo(comment.time)); - ObservedTextView c = v.findViewById(R.id.comment); + ObservedTextView c = v.findViewById(R.id.comment); c.setMaxLines(5); c.setText(Html.fromHtml(comment.comment, new URLImageGetter(c, EhApplication.getConaco(context)), null)); @@ -1159,7 +1166,7 @@ private void bindPreviews(GalleryDetail gd) { previewSet.load(image, gd.gid, i); image.setTag(R.id.index, i); image.setOnClickListener(this); - TextView text = view.findViewById(R.id.text); + TextView text = view.findViewById(R.id.text); text.setText(Integer.toString(previewSet.getPosition(i) + 1)); } } @@ -1229,7 +1236,7 @@ private void setTransitionName() { @SuppressLint("NonConstantResourceId") private void ensurePopMenu() { - if (mPopupMenu != null) { + if (mPopupMenu != null || mOtherActions == null) { return; } @@ -1818,8 +1825,9 @@ protected void onGetGalleryDetailSuccess(GalleryDetail result) { } adjustViewVisibility(STATE_NORMAL, true); bindViewSecond(); - if (myUpdateDialog!=null&&myUpdateDialog.autoDownload){ + if (myUpdateDialog != null && myUpdateDialog.autoDownload) { myUpdateDialog.autoDownload = false; + mDownloadState = DownloadInfo.STATE_INVALID; onDownload(false); } } @@ -1930,7 +1938,6 @@ private void onModifyFavoritesCancel(boolean addOrRemove) { * 2022/4/7 * 心情不好 * 这个方法写的跟屎一样 - * */ @SuppressLint("SetTextI18n") private void showTorrentDownloadDialog(String url, String name, int progress, boolean success) { @@ -1984,6 +1991,9 @@ private void showTorrentDownloadDialog(String url, String name, int progress, bo } return; } + if (torrentDownloadView==null){ + return; + } View detail = torrentDownloadView.findViewById(R.id.download_detail); View progressView = torrentDownloadView.findViewById(R.id.progress_view); detail.setVisibility(View.GONE); @@ -2017,9 +2027,10 @@ private void dismissTorrentDialog() { @SuppressLint("HandlerLeak") private class TorrentDownloadHandler extends Handler { - public TorrentDownloadHandler(){ + public TorrentDownloadHandler() { super(Looper.getMainLooper()); } + @Override public void handleMessage(Message msg) { TorrentDownloadMessage message = msg.getData().getParcelable("torrent_download_message"); @@ -2160,7 +2171,7 @@ private class ArchiveListDialogHelper implements AdapterView.OnItemClickListener private Dialog mDialog; public void setDialog(@Nullable Dialog dialog, String url) { - if (dialog==null){ + if (dialog == null) { return; } mDialog = dialog; @@ -2212,7 +2223,7 @@ public void onItemClick(AdapterView parent, View view, int position, long id) Context context = getEHContext(); MainActivity activity = getActivity2(); if (null != context && null != activity && null != mArchiveList && position < mArchiveList.length) { - if (mGalleryDetail==null) + if (mGalleryDetail == null) return; String res = mArchiveList[position].first; EhRequest request = new EhRequest(); @@ -2285,7 +2296,7 @@ private class TorrentListDialogHelper implements AdapterView.OnItemClickListener private OkHttpClient okHttpClient; public void setDialog(@Nullable Dialog dialog, String url, OkHttpClient okHttpClient) { - if (dialog==null) + if (dialog == null) return; mDialog = dialog; this.okHttpClient = okHttpClient; @@ -2302,6 +2313,9 @@ public void setDialog(@Nullable Dialog dialog, String url, OkHttpClient okHttpCl mRequest = new EhRequest().setMethod(EhClient.METHOD_GET_TORRENT_LIST) .setArgs(url, mGid, mToken) .setCallback(this); + if (mRequest==null){ + return; + } EhApplication.getEhClient(context).execute(mRequest); } else { bind(mTorrentList); diff --git a/app/src/main/java/com/hippo/ehviewer/ui/scene/gallery/detail/GetGalleryDetailListener.java b/app/src/main/java/com/hippo/ehviewer/ui/scene/gallery/detail/GetGalleryDetailListener.java index ba2585d32..e6616fc68 100644 --- a/app/src/main/java/com/hippo/ehviewer/ui/scene/gallery/detail/GetGalleryDetailListener.java +++ b/app/src/main/java/com/hippo/ehviewer/ui/scene/gallery/detail/GetGalleryDetailListener.java @@ -4,15 +4,12 @@ import com.hippo.ehviewer.EhApplication; import com.hippo.ehviewer.EhDB; -import com.hippo.ehviewer.Settings; import com.hippo.ehviewer.client.EhUtils; import com.hippo.ehviewer.client.data.GalleryDetail; -import com.hippo.ehviewer.spider.SpiderDen; import com.hippo.ehviewer.spider.SpiderInfo; import com.hippo.ehviewer.sync.GalleryDetailTagsSyncTask; import com.hippo.ehviewer.ui.scene.EhCallback; import com.hippo.scene.SceneFragment; -import com.hippo.unifile.UniFile; import com.hippo.yorozuya.FileUtils; public class GetGalleryDetailListener extends EhCallback { diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index df473b098..066d559b6 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -571,7 +571,7 @@ Import from clipboard No valid data found from clipboard Update method - + Overwrite old gallery: Only the downloaded version will be kept, the old version will be deleted.\nDownload as new gallery: The downloaded gallery will exist as a new gallery, and both the new gallery and the old gallery will be saved. Download as new Overwrite old diff --git a/app/src/main/res/values-en/strings.xml b/app/src/main/res/values-en/strings.xml index bee96f9a5..65557721c 100644 --- a/app/src/main/res/values-en/strings.xml +++ b/app/src/main/res/values-en/strings.xml @@ -798,7 +798,7 @@ Import from clipboard No valid data found from clipboard Update method - + Overwrite old gallery: Only the downloaded version will be kept, the old version will be deleted.\nDownload as new gallery: The downloaded gallery will exist as a new gallery, and both the new gallery and the old gallery will be saved. Download as new Overwrite old diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml index 9595940e3..8c276e3e8 100644 --- a/app/src/main/res/values-zh-rCN/strings.xml +++ b/app/src/main/res/values-zh-rCN/strings.xml @@ -900,7 +900,7 @@ 从剪切板导入 未从剪切板中找到有效数据 更新方式 - + 覆盖旧画廊:只保留下载版本,旧版本将被删除。\n下载为新画廊:下载画廊将以新画廊形式存在,新画廊与旧画廊均会被保存。 下载为新 覆盖下载 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 404693209..b0d2d38ae 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -970,7 +970,7 @@ Import from clipboard No valid data found from clipboard Update method - + Overwrite old gallery: Only the downloaded version will be kept, the old version will be deleted.\nDownload as new gallery: The downloaded gallery will exist as a new gallery, and both the new gallery and the old gallery will be saved. Download as new Overwrite old