Skip to content

Commit

Permalink
Merge pull request #504 from LoxiaLiSA/master
Browse files Browse the repository at this point in the history
二级详情 HDImageView 换成 SubsamplingScaleImageView
  • Loading branch information
CeuiLiSA authored Feb 25, 2023
2 parents 5fc8f86 + e23eae4 commit 816093c
Show file tree
Hide file tree
Showing 7 changed files with 125 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@
import ceui.lisa.helper.PageTransformerHelper;
import ceui.lisa.models.IllustsBean;
import ceui.lisa.utils.Common;
import ceui.lisa.utils.Params;
import ceui.lisa.utils.PixivOperate;
import ceui.loxia.ImageFragment;

/**
* 图片二级详情
Expand Down Expand Up @@ -57,11 +55,7 @@ protected void initView() {
baseBind.viewPager.setAdapter(new FragmentPagerAdapter(getSupportFragmentManager()) {
@Override
public Fragment getItem(int i) {
if (mIllustsBean.getPage_count() > 1) {
return ImageFragment.Companion.newInstance(mIllustsBean.getMeta_pages().get(i).getImage_urls().getMaxImage());
} else {
return ImageFragment.Companion.newInstance(mIllustsBean.getMeta_single_page().getOriginal());
}
return FragmentImageDetail.newInstance(mIllustsBean, i);
}

@Override
Expand Down
5 changes: 0 additions & 5 deletions app/src/main/java/ceui/lisa/activities/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -442,11 +442,6 @@ protected void onResume() {
initDrawerHeader();
Dev.refreshUser = false;
}

if (Dev.isDev) {
Intent intent = new Intent(mContext, NavActivity.class);
startActivity(intent);
}
}

@Override
Expand Down
3 changes: 1 addition & 2 deletions app/src/main/java/ceui/lisa/activities/TemplateActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@
import ceui.lisa.utils.Local;
import ceui.lisa.utils.Params;
import ceui.lisa.utils.ReverseResult;
import ceui.loxia.ImageFragment;

public class TemplateActivity extends BaseActivity<ActivityFragmentBinding> implements ColorPickerDialogListener {

Expand Down Expand Up @@ -199,7 +198,7 @@ protected Fragment createNewFragment() {
case "小说详情":
return FragmentNovelHolder.newInstance((NovelBean) intent.getSerializableExtra(Params.CONTENT));
case "图片详情":
return ImageFragment.Companion.newInstance(intent.getStringExtra(Params.URL));
return FragmentImageDetail.newInstance(intent.getStringExtra(Params.URL));
case "绑定邮箱":
return new FragmentEditAccount();
case "编辑个人资料":
Expand Down
3 changes: 1 addition & 2 deletions app/src/main/java/ceui/lisa/activities/VActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import ceui.lisa.utils.Common;
import ceui.lisa.utils.Params;
import ceui.lisa.utils.PixivOperate;
import ceui.loxia.ImageFragment;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;
Expand Down Expand Up @@ -60,7 +59,7 @@ protected void initView() {
public Fragment getItem(int position) {
IllustsBean illustsBean = pageData.getList().get(position);
if (illustsBean.getId() == 0 || !illustsBean.isVisible()) {
return ImageFragment.Companion.newInstance(illustsBean.getImage_urls().getMaxImage());
return FragmentImageDetail.newInstance(illustsBean.getImage_urls().getMaxImage());
} else if (illustsBean.isGif()) {
return FragmentSingleUgora.newInstance(illustsBean);
} else {
Expand Down
118 changes: 66 additions & 52 deletions app/src/main/java/ceui/lisa/fragments/FragmentImageDetail.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import com.bumptech.glide.request.target.CustomViewTarget;
import com.bumptech.glide.request.target.Target;
import com.bumptech.glide.request.transition.Transition;
import com.davemorrissey.labs.subscaleview.ImageSource;
import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView;

import java.io.File;

Expand Down Expand Up @@ -72,31 +74,32 @@ public void initLayout() {

@Override
protected void initView() {
baseBind.realIllustImage.setOnBitmapLoadListener(new OnBitmapLoadListener() {
@Override
public void onBitmapLoadReady() {

}

@Override
public void onBitmapLoaded(int width, int height) {
imageWidth = width;
imageHeight = height;
}

@Override
public void onBitmapLoadError(Exception e) {

}
});

baseBind.realIllustImage.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
@Override
public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
adjustAutoScale();
}
});

// baseBind.realIllustImage.setOnBitmapLoadListener(new OnBitmapLoadListener() {
// @Override
// public void onBitmapLoadReady() {
//
// }
//
// @Override
// public void onBitmapLoaded(int width, int height) {
// imageWidth = width;
// imageHeight = height;
// }
//
// @Override
// public void onBitmapLoadError(Exception e) {
//
// }
// });
//
// baseBind.realIllustImage.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
// @Override
// public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
// adjustAutoScale();
// }
// });
baseBind.emptyActionButton.setOnClickListener(v -> loadImage());
baseBind.bigImage.setDoubleTapZoomDuration(250);
//插画二级详情保持屏幕常亮
if (Shaft.sSettings.isIllustDetailKeepScreenOn()) {
baseBind.getRoot().setKeepScreenOn(true);
Expand All @@ -109,6 +112,8 @@ protected void initData() {
}

private void loadImage() {
baseBind.emptyFrame.setVisibility(View.GONE);
baseBind.progressLayout.getRoot().setVisibility(View.VISIBLE);
String imageUrl;
if (mIllustsBean == null && !TextUtils.isEmpty(url)) {
imageUrl = url;
Expand All @@ -121,8 +126,12 @@ private void loadImage() {
imageUrl = url;
} else {
if (Shaft.sSettings.isShowOriginalImage()) {
baseBind.bigImage.setMaxScale(4F);
baseBind.bigImage.setDoubleTapZoomScale(2F);
imageUrl = IllustDownload.getUrl(mIllustsBean, index, Params.IMAGE_RESOLUTION_ORIGINAL);
} else {
baseBind.bigImage.setMaxScale(8F);
baseBind.bigImage.setDoubleTapZoomScale(4F);
imageUrl = IllustDownload.getUrl(mIllustsBean, index, Params.IMAGE_RESOLUTION_LARGE);
}
}
Expand All @@ -145,25 +154,30 @@ public void onError(long id, Exception e) {
.listener(new RequestListener<File>() {
@Override
public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<File> target, boolean isFirstResource) {
baseBind.progressLayout.donutProgress.setVisibility(View.INVISIBLE);
baseBind.progressLayout.getRoot().setVisibility(View.GONE);
baseBind.emptyFrame.setVisibility(View.VISIBLE);
if (e != null) {
baseBind.emptyTitle.setText(e.getMessage());
}
return false;
}

@Override
public boolean onResourceReady(File resource, Object model, Target<File> target, DataSource dataSource, boolean isFirstResource) {
baseBind.progressLayout.donutProgress.setVisibility(View.INVISIBLE);
baseBind.progressLayout.getRoot().setVisibility(View.GONE);
baseBind.emptyFrame.setVisibility(View.GONE);
Common.showLog("onResourceReady " + resource.getPath());
return false;
}
})
.into(new CustomViewTarget<HDImageView, File>(baseBind.realIllustImage) {
.into(new CustomViewTarget<SubsamplingScaleImageView, File>(baseBind.bigImage) {
@Override
public void onLoadFailed(@Nullable Drawable errorDrawable) {
}

@Override
public void onResourceReady(@NonNull File resource, @Nullable Transition<? super File> transition) {
view.setImageURI(Uri.fromFile(resource));
baseBind.bigImage.setImage(ImageSource.uri(Uri.fromFile(resource)));
}

@Override
Expand All @@ -179,27 +193,27 @@ public void onSaveInstanceState(@NonNull Bundle outState) {
outState.putInt("index", index);
}

public void adjustAutoScale() {
if (imageWidth <= 0 || imageHeight <= 0) {
return;
}

int viewWidth = baseBind.realIllustImage.getWidth();
int viewHeight = baseBind.realIllustImage.getHeight();

float scale_w = (float) imageWidth / viewWidth;
float scale_h = (float) imageHeight / viewHeight;

float scale_init_inner = Math.min(viewWidth / (float) imageWidth, viewHeight / (float) imageHeight); // 内部处理后的初始Scale,minScale()
float scale_init_side = Math.max(scale_w, scale_h); // 初始scale 此时吸附scale较大的一边
float scale_max = scale_init_inner * scale_init_side; // 最大scale,显示原图级别
float scale_other_side = scale_max / Math.min(scale_w, scale_h); // 目标scale,吸附另一边

if (scale_w > 1.0f && scale_h > 1.0f) {
baseBind.realIllustImage.setMaxScale(scale_max);
} else {
baseBind.realIllustImage.setMaxScale(scale_other_side);
}
baseBind.realIllustImage.setDoubleTapZoomScale(scale_other_side);
}
// public void adjustAutoScale() {
// if (imageWidth <= 0 || imageHeight <= 0) {
// return;
// }
//
// int viewWidth = baseBind.realIllustImage.getWidth();
// int viewHeight = baseBind.realIllustImage.getHeight();
//
// float scale_w = (float) imageWidth / viewWidth;
// float scale_h = (float) imageHeight / viewHeight;
//
// float scale_init_inner = Math.min(viewWidth / (float) imageWidth, viewHeight / (float) imageHeight); // 内部处理后的初始Scale,minScale()
// float scale_init_side = Math.max(scale_w, scale_h); // 初始scale 此时吸附scale较大的一边
// float scale_max = scale_init_inner * scale_init_side; // 最大scale,显示原图级别
// float scale_other_side = scale_max / Math.min(scale_w, scale_h); // 目标scale,吸附另一边
//
// if (scale_w > 1.0f && scale_h > 1.0f) {
// baseBind.realIllustImage.setMaxScale(scale_max);
// } else {
// baseBind.realIllustImage.setMaxScale(scale_other_side);
// }
// baseBind.realIllustImage.setDoubleTapZoomScale(scale_other_side);
// }
}
6 changes: 6 additions & 0 deletions app/src/main/java/ceui/loxia/ImageFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import androidx.core.os.bundleOf
import androidx.core.view.isVisible
import androidx.lifecycle.lifecycleScope
import ceui.lisa.R
import ceui.lisa.activities.Shaft
import ceui.lisa.core.GlideApp
import ceui.lisa.databinding.FragmentImageBinding
import ceui.refactor.viewBinding
Expand Down Expand Up @@ -49,6 +50,11 @@ class ImageFragment : NavFragment(R.layout.fragment_image) {
}
}
}

//插画二级详情保持屏幕常亮
if (Shaft.sSettings.isIllustDetailKeepScreenOn) {
binding.root.keepScreenOn = true
}
}

companion object {
Expand Down
54 changes: 50 additions & 4 deletions app/src/main/res/layout/fragment_image_detail.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,60 @@
android:background="@color/black"
android:layout_height="match_parent">

<xyz.zpayh.hdimage.HDImageView
<com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView
android:id="@+id/big_image"
android:layout_width="match_parent"
android:id="@+id/real_illust_image"
android:transitionName="big_image"
android:scaleType="fitCenter"
android:layout_height="match_parent" />

<!-- <xyz.zpayh.hdimage.HDImageView-->
<!-- android:layout_width="match_parent"-->
<!-- android:id="@+id/real_illust_image"-->
<!-- android:transitionName="big_image"-->
<!-- android:scaleType="fitCenter"-->
<!-- android:layout_height="match_parent" />-->

<LinearLayout
android:id="@+id/empty_frame"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:visibility="gone"
android:orientation="vertical">

<Button
android:id="@+id/empty_action_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="12dp"
android:background="@drawable/refresh_button_background"
android:gravity="center"
android:minHeight="0dp"
android:paddingHorizontal="20dp"
android:paddingVertical="8dp"
android:stateListAnimator="@animator/button_press_alpha"
android:text="@string/refresh"
android:textAllCaps="false"
android:textColor="@color/colorWhite60"
android:textSize="15sp" />

<TextView
android:id="@+id/empty_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:ellipsize="end"
android:gravity="center"
android:maxLines="5"
android:minLines="1"
android:text="@string/empty_content_here"
android:textAlignment="center"
android:textColor="@color/colorWhite60"
android:textSize="14sp" />
</LinearLayout>

<include
android:visibility="gone"
android:id="@+id/progress_layout"
layout="@layout/item_progress" />

Expand Down

0 comments on commit 816093c

Please sign in to comment.