Skip to content

Commit

Permalink
画廊更新逻辑修复
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaojieonly committed Mar 1, 2024
1 parent cb2ba6a commit 05453c5
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 62 deletions.
53 changes: 25 additions & 28 deletions app/src/main/java/com/hippo/ehviewer/ui/CommonOperations.java
Original file line number Diff line number Diff line change
Expand Up @@ -348,36 +348,33 @@ public static void startDownload(final MainActivity activity, final List<Gallery
}

new ListCheckBoxDialogBuilder(activity, items,
new ListCheckBoxDialogBuilder.OnItemClickListener() {
@Override
public void onItemClick(ListCheckBoxDialogBuilder builder, AlertDialog dialog, int position) {
String label;
if (position == 0) {
label = null;
} else {
label = items[position];
if (!dm.containLabel(label)) {
label = null;
}
}
// Start download
for (GalleryInfo gi : toAdd) {
Intent intent = new Intent(activity, DownloadService.class);
intent.setAction(DownloadService.ACTION_START);
intent.putExtra(DownloadService.KEY_LABEL, label);
intent.putExtra(DownloadService.KEY_GALLERY_INFO, gi);
activity.startService(intent);
}
// Save settings
if (builder.isChecked()) {
Settings.putHasDefaultDownloadLabel(true);
Settings.putDefaultDownloadLabel(label);
} else {
Settings.putHasDefaultDownloadLabel(false);
(builder, dialog, position) -> {
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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand All @@ -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);
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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));
}
}
Expand Down Expand Up @@ -1229,7 +1236,7 @@ private void setTransitionName() {

@SuppressLint("NonConstantResourceId")
private void ensurePopMenu() {
if (mPopupMenu != null) {
if (mPopupMenu != null || mOtherActions == null) {
return;
}

Expand Down Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<GalleryDetailScene, GalleryDetail> {
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@
<string name="cookie_login_import_in_clipboard">Import from clipboard</string>
<string name="no_cookie_in_clipboard">No valid data found from clipboard</string>
<string name="gallery_update_dialog_title">Update method</string>
<string name="gallery_update_dialog_message"><![CDATA[Overwrite old gallery: Only the downloaded version will be kept, the old version will be deleted.&#xA;Download as new gallery: The downloaded gallery will exist as a new gallery, and both the new gallery and the old gallery will be saved.]]></string>
<string name="gallery_update_dialog_message">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.</string>
<string name="gallery_update_download_as_new">Download as new</string>
<string name="gallery_update_override_old">Overwrite old</string>

Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-en/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -798,7 +798,7 @@
<string name="cookie_login_import_in_clipboard">Import from clipboard</string>
<string name="no_cookie_in_clipboard">No valid data found from clipboard</string>
<string name="gallery_update_dialog_title">Update method</string>
<string name="gallery_update_dialog_message"><![CDATA[Overwrite old gallery: Only the downloaded version will be kept, the old version will be deleted.&#xA;Download as new gallery: The downloaded gallery will exist as a new gallery, and both the new gallery and the old gallery will be saved.]]></string>
<string name="gallery_update_dialog_message">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.</string>
<string name="gallery_update_download_as_new">Download as new</string>
<string name="gallery_update_override_old">Overwrite old</string>

Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-zh-rCN/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -900,7 +900,7 @@
<string name="cookie_login_import_in_clipboard">从剪切板导入</string>
<string name="no_cookie_in_clipboard">未从剪切板中找到有效数据</string>
<string name="gallery_update_dialog_title">更新方式</string>
<string name="gallery_update_dialog_message"><![CDATA[覆盖旧画廊:只保留下载版本,旧版本将被删除。&#xA;下载为新画廊:下载画廊将以新画廊形式存在,新画廊与旧画廊均会被保存。]]></string>
<string name="gallery_update_dialog_message">覆盖旧画廊:只保留下载版本,旧版本将被删除。\n下载为新画廊:下载画廊将以新画廊形式存在,新画廊与旧画廊均会被保存。</string>
<string name="gallery_update_download_as_new">下载为新</string>
<string name="gallery_update_override_old">覆盖下载</string>

Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -970,7 +970,7 @@
<string name="cookie_login_import_in_clipboard">Import from clipboard</string>
<string name="no_cookie_in_clipboard">No valid data found from clipboard</string>
<string name="gallery_update_dialog_title">Update method</string>
<string name="gallery_update_dialog_message"><![CDATA[Overwrite old gallery: Only the downloaded version will be kept, the old version will be deleted.&#xA;Download as new gallery: The downloaded gallery will exist as a new gallery, and both the new gallery and the old gallery will be saved.]]></string>
<string name="gallery_update_dialog_message">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.</string>
<string name="gallery_update_download_as_new">Download as new</string>
<string name="gallery_update_override_old">Overwrite old</string>

Expand Down

0 comments on commit 05453c5

Please sign in to comment.