Skip to content

Commit

Permalink
优化album显示
Browse files Browse the repository at this point in the history
  • Loading branch information
hss01248 committed Aug 17, 2021
1 parent 7759c44 commit 8eca30f
Show file tree
Hide file tree
Showing 7 changed files with 125 additions and 16 deletions.
1 change: 1 addition & 0 deletions bigimageviewpager/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,5 @@ dependencies {
api 'com.github.bumptech.glide:okhttp3-integration:4.11.0' // 新增

implementation 'androidx.viewpager:viewpager:1.0.0'
api 'com.github.hss01248.metadata:metadata:1.1.2'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.hss01248.bigimageviewpager;

import android.text.TextUtils;

import androidx.annotation.Keep;

import com.hss01248.media.metadata.ExifUtil;

import java.util.Map;
import java.util.TreeMap;

@Keep
public class LargeImageInfo {

public String uri;
public String localPathOrUri;
public Throwable throwable;


public String getInfo(){
Map map = new TreeMap();
map.put("000-uri",uri);
if(throwable != null){
map.put("00-exception",throwable.getClass()+" "+throwable.getMessage());
}
String str = map.toString().replace(",","\n");
if(!TextUtils.isEmpty(localPathOrUri)){
str += ExifUtil.getExifStr(localPathOrUri);
}
return str;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class MyLargeImageView extends FrameLayout {
ItemLargeImgBinding largeImgBinding;

StatefulFrameLayout stateManager;

LargeImageInfo info = new LargeImageInfo();

public float getMaxScaleRatio() {
return maxScaleRatio;
Expand All @@ -59,6 +59,13 @@ public void setMaxScaleRatio(float maxScaleRatio) {
public static float defaultMaxScaleRatio = 8f;
float maxScaleRatio = defaultMaxScaleRatio;

public void setShowScale(boolean showScale) {
this.showScale = showScale;
}

boolean showScale = true;


public MyLargeImageView(@NonNull Context context) {
super(context);
try {
Expand Down Expand Up @@ -96,13 +103,15 @@ public boolean isFirstStateLoading() {
jpgView.setOnScaleChangeListener(new MyLargeJpgView.OnScaleChangeListener() {
@Override
public void onScaleChanged(int percent, float scale) {
if(showScale)
tvScale.setText(percent+"%");
}
});

gifView.setOnScaleChangeListener(new MyLargeJpgView.OnScaleChangeListener() {
@Override
public void onScaleChanged(int percent, float scale) {
if(showScale)
tvScale.setText(percent+"%");
}
});
Expand All @@ -128,14 +137,14 @@ public MyLargeImageView(@NonNull Context context, @Nullable AttributeSet attrs,
}

private void reload() {
loadUri(tmlUrl);
loadUri(info.uri);

}

String tmlUrl;

public void loadUrl(String url) {
tmlUrl = url;

private void loadUrl(String url) {

stateManager.showLoading();
UrlLoader.download(getContext(), ivHelper, url, new UrlLoader.LoadListener() {
@Override
Expand All @@ -151,13 +160,15 @@ public void onProgress(int progress) {

@Override
public void onFail(Throwable throwable) {
tmlUrl = url;

if (throwable != null) {
info.throwable = throwable;
throwable.printStackTrace();
//toastMsg(throwable.getMessage());
stateManager.showError(throwable.getMessage());
} else {
//toastMsg("fail download");
info.throwable = new Throwable("fail download");
stateManager.showError("fail download");

}
Expand All @@ -169,11 +180,11 @@ public void onFail(Throwable throwable) {

}

public void loadFile(String filePath) {
private void loadFile(String filePath) {
loadFile(filePath, false);
}

public void loadFile(String filePath, boolean isGif) {
private void loadFile(String filePath, boolean isGif) {
loadLocal(filePath, isGif);
}

Expand All @@ -182,6 +193,7 @@ private void toastMsg(String message) {
}

public void loadUri(String uri) {
info.uri = uri;
//if(uri.startsWith("file://") || uri.startsWith("/storage/"))
if (uri.startsWith("http")) {
loadUrl(uri);
Expand All @@ -199,11 +211,14 @@ public void loadUri(String uri) {
loadLocal(uri, false);
return;
}
}


public String getInfo(){
return info.getInfo();
}

private void loadLocal(String uri, boolean isGif) {
info.localPathOrUri = uri;
if (uri.contains(".gif") || isGif) {
gifView.setVisibility(VISIBLE);
jpgView.setVisibility(GONE);
Expand Down Expand Up @@ -241,7 +256,7 @@ public void accept(InputStreamBitmapDecoderFactory inputStreamBitmapDecoderFacto
public void accept(Throwable throwable) throws Exception {
throwable.printStackTrace();
//toastMsg(throwable.getMessage());
tmlUrl = uri;
info.throwable = throwable;
stateManager.showError(throwable.getMessage());
}
})
Expand Down
3 changes: 2 additions & 1 deletion imagelist/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ dependencies {
implementation 'com.futuremind.recyclerfastscroll:fastscroll:0.2.5'

implementation 'com.github.fondesa:recycler-view-divider:3.5.0'
implementation 'com.yqritc:recyclerview-flexibledivider:1.4.0'
//implementation 'com.yqritc:recyclerview-flexibledivider:1.4.0'
api 'com.github.hss01248.metadata:metadata:1.1.2'
//implementation 'com.wuhenzhizao:titlebar:1.1.4'
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,13 @@
import com.blankj.utilcode.util.LogUtils;
import com.blankj.utilcode.util.SizeUtils;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.fondesa.recyclerviewdivider.BaseDividerItemDecoration;
import com.fondesa.recyclerviewdivider.DividerDecoration;
import com.fondesa.recyclerviewdivider.StaggeredDividerDecoration;
import com.futuremind.recyclerviewfastscroll.FastScroller;
import com.hss01248.image.ImageLoader;
import com.hss01248.image.interfaces.FileGetter;
import com.hss01248.imagelist.NormalCallback;
import com.hss01248.imagelist.R;
import com.yqritc.recyclerviewflexibledivider.HorizontalDividerItemDecoration;


import org.apache.commons.io.FileUtils;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.blankj.utilcode.util.LogUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.hss01248.bigimageviewpager.LargeImageViewer;
import com.hss01248.bigimageviewpager.MyLargeImageView;
import com.hss01248.bigimageviewpager.MyViewPager;
import com.hss01248.image.ImageLoader;
import com.hss01248.image.MyUtil;
Expand Down Expand Up @@ -267,13 +271,24 @@ public static void showViewAsDialog(View view) {
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.WHITE));//背景颜色一定要有,看自己需求
dialog.getWindow().setLayout(view.getResources().getDisplayMetrics().widthPixels, view.getResources().getDisplayMetrics().heightPixels);//宽高最大
dialog.show();
ImageView ivClose = view.findViewById(R.id.iv_back);
if(ivClose != null){
ivClose.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
}
});
}
}


private static View buildBigIamgeView(final Context context, final List<String> urls, int position) {
View view = View.inflate(context, R.layout.activity_img_big, null);
final MyViewPager viewPager = (MyViewPager) view.findViewById(R.id.viewpager);
Button fab = view.findViewById(R.id.fbtn);
TextView tvTitle = view.findViewById(R.id.tv_title);

final TextView textView = view.findViewById(R.id.tv_indicator);
//ImageLoader.loadBigImages(viewPager, urls);
LargeImageViewer.showBig(context,viewPager,urls,position);
Expand All @@ -289,6 +304,8 @@ public void onPageScrolled(int position, float positionOffset, int positionOffse
public void onPageSelected(int position) {
String text = (position + 1) + " / " + urls.size() + "\n";
textView.setText(text);
String uri = urls.get(position);
tvTitle.setText(uri.substring(uri.lastIndexOf("/")+1));
}

@Override
Expand All @@ -300,10 +317,33 @@ public void onPageScrollStateChanged(int state) {
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
showFileInfo(viewPager, urls, context);
//showFileInfo(viewPager, urls, context);
int position = viewPager.getCurrentItem();
View childAt = viewPager.getChildAt(1);
LogUtils.w("child at is "+childAt+", "+position);
if(childAt instanceof MyLargeImageView){
MyLargeImageView largeImageView = (MyLargeImageView) childAt;
String text = largeImageView.getInfo();

View view = View.inflate(context, R.layout.html, null);
TextView textView = view.findViewById(R.id.tv_html);
textView.setText(text);
new AlertDialog.Builder(context)
.setView(view)
.create().show();
}else {
ToastUtils.showShort("child not MyLargeImageView");
}



}
});
viewPager.setCurrentItem(position);
String text = (position + 1) + " / " + urls.size() + "\n";
textView.setText(text);
String uri = urls.get(position);
tvTitle.setText(uri.substring(uri.lastIndexOf("/")+1));
return view;
}

Expand Down
23 changes: 22 additions & 1 deletion imagelist/src/main/res/layout/activity_img_big.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,27 @@
android:textColor="#00ffff"
android:id="@+id/tv_indicator"
android:layout_marginLeft="20dp"
android:layout_marginBottom="20dp"
android:layout_height="wrap_content" />

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="50dp">

<TextView
android:id="@+id/tv_title"
android:textColor="#ffffff"
android:background="#99999999"
android:gravity="center"
android:paddingLeft="60dp"
android:paddingRight="20dp"
android:layout_centerInParent="true"
android:layout_width="match_parent"
android:layout_height="50dp"/>
<ImageView
android:src="@android:drawable/ic_menu_close_clear_cancel"
android:id="@+id/iv_back"
android:scaleType="centerInside"
android:layout_width="50dp"
android:layout_height="50dp"/>
</RelativeLayout>
</RelativeLayout>

0 comments on commit 8eca30f

Please sign in to comment.