Skip to content

Commit

Permalink
抽取出fragmentation-dialog-imageviewer模块
Browse files Browse the repository at this point in the history
  • Loading branch information
Z-P-J committed Nov 12, 2022
1 parent 9a258f1 commit 0ef7837
Show file tree
Hide file tree
Showing 33 changed files with 185 additions and 114 deletions.
1 change: 1 addition & 0 deletions demo/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,6 @@ dependencies {
implementation 'com.github.Z-P-J:ZCheckBox:1.0.0'
implementation 'com.github.Z-P-J:ZFragmentation:2.0.0'
implementation project(':fragmentation-dialog')
implementation project(':fragmentation-dialog-imageviewer')
}

Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import android.view.Gravity;
import android.view.View;
import android.widget.CompoundButton;
Expand All @@ -14,17 +12,21 @@
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.target.SimpleTarget;
import com.bumptech.glide.request.transition.Transition;
import com.zpj.fragmentation.SimpleFragment;
import com.zpj.fragmentation.demo.R;
import com.zpj.fragmentation.dialog.IDialog;
import com.zpj.fragmentation.dialog.ZDialog;
import com.zpj.fragmentation.dialog.imageviewer.ImageViewerDialogFragment;
import com.zpj.fragmentation.dialog.imageviewer.ZImageViewer;
import com.zpj.fragmentation.dialog.impl.ArrowMenuDialogFragment;
import com.zpj.fragmentation.dialog.impl.AttachListDialogFragment;
import com.zpj.fragmentation.dialog.impl.CheckDialogFragment;
import com.zpj.fragmentation.dialog.impl.ImageViewerDialogFragment;
import com.zpj.fragmentation.dialog.impl.InputDialogFragment;
import com.zpj.fragmentation.dialog.impl.LoadingDialogFragment;
import com.zpj.fragmentation.dialog.utils.DialogThemeUtils;
Expand Down Expand Up @@ -435,12 +437,12 @@ public void onSelect(AttachListDialogFragment<String> fragment, int position, St
});

ImageView imageView = findViewById(R.id.iv_test_image_viewer);
String url = "https://imgo.shouji.com.cn/share/2020/20210211/4871736527_s.jpg";
String originalUrl = "https://imgo.shouji.com.cn/share/2020/20210211/4871736527.png"; // "https://avatar.shouji.com.cn/20201005/1850813592.jpg"
String url = "https://img1.wallspic.com/previews/8/8/3/0/7/170388/170388-qi_fen-xing_zhi-zi_ran_jing_guan-x750.jpg";
String originalUrl = "https://img1.wallspic.com/attachments/originals/8/8/3/0/7/170388-qi_fen-xing_zhi-zi_ran_jing_guan-4016x6016.jpg";
imageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
new ImageViewerDialogFragment<String>()
ZImageViewer.create()
.setSingleSrcView(imageView, originalUrl)
.show(MainFragment.this);
}
Expand Down
2 changes: 1 addition & 1 deletion demo/src/main/res/layout/test_fragment_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@
<ImageView
android:id="@+id/iv_test_image_viewer"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_height="200dp"
android:layout_margin="16dp"
android:scaleType="centerCrop"
/>
Expand Down
1 change: 1 addition & 0 deletions fragmentation-dialog-imageviewer/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
54 changes: 54 additions & 0 deletions fragmentation-dialog-imageviewer/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
apply plugin: 'com.android.library'
apply plugin: 'maven-publish'

android {
compileSdkVersion 30


defaultConfig {
minSdkVersion 19
targetSdkVersion 30
versionCode 1
versionName "2.0.0"
}

compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}

}

dependencies {
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'androidx.transition:transition:1.4.1'
implementation 'androidx.exifinterface:exifinterface:1.3.2'

implementation 'com.github.bumptech.glide:glide:4.10.0'
implementation 'com.github.Z-P-J:ZFragmentation:2.0.0'
implementation 'com.github.Z-P-J:ZUtils:2.0.0'

implementation project(':fragmentation-dialog')

}

afterEvaluate {
publishing {
publications {
release(MavenPublication) {
from components.release

groupId = 'com.zpj.fragmentation'
artifactId = 'ZFragmentation-Dialog-ImageViewer'
version = '2.0.0'
}
debug(MavenPublication) {
from components.debug

groupId = 'com.zpj.fragmentation'
artifactId = 'ZFragmentation-Dialog-ImageViewer'
version = '2.0.0'
}
}
}
}
21 changes: 21 additions & 0 deletions fragmentation-dialog-imageviewer/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class courseName to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file courseName.
#-renamesourcefileattribute SourceFile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<manifest package="com.zpj.fragmentation.dialog.imageviewer" />
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
package com.zpj.fragmentation.dialog.utils;
package com.zpj.fragmentation.dialog.imageviewer;

import android.content.ContentResolver;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.util.Log;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import android.util.Log;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.gif.GifDrawable;
import com.bumptech.glide.request.target.SimpleTarget;
import com.bumptech.glide.request.transition.Transition;
import com.davemorrissey.labs.subscaleview.ImageSource;
import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView;
import com.zpj.fragmentation.dialog.widget.ImageViewContainer;

import java.io.File;
import java.util.HashMap;
Expand All @@ -22,11 +22,11 @@
public class DefaultImageLoader<T> implements ImageLoader<T> {
private static final Pattern webPattern = Pattern.compile("http[s]*://[[[^/:]&&[a-zA-Z_0-9]]\\.]+(:\\d+)?(/[a-zA-Z_0-9]+)*(/[a-zA-Z_0-9]*([a-zA-Z_0-9]+\\.[a-zA-Z_0-9]+)*)?(\\?(&?[a-zA-Z_0-9]+=[%[a-zA-Z_0-9]-]*)*)*(#[[a-zA-Z_0-9]|-]+)?(.jpg|.png|.gif|.jpeg)?");
private static final String ASSET_PATH_SEGMENT = "android_asset";
private static final HashMap<String, ImageLoader.LoadCallback> loadCallbackMap = new HashMap<>();
private static final HashMap<String, LoadCallback> loadCallbackMap = new HashMap<>();
private static final HashMap<String, ImageFetcher.ImageDownLoadListener> imageDownLoadListenerMap = new HashMap<>();

@Override
public void loadImage(final T url, final ImageLoader.LoadCallback callback, final ImageViewContainer imageView, final String unique) {
public void loadImage(final T url, final LoadCallback callback, final ImageViewContainer imageView, final String unique) {
addLoadCallback(unique, callback);
String link = url.toString();
Uri uri = Uri.parse(link);
Expand Down Expand Up @@ -63,6 +63,7 @@ public void onError(Throwable e) {

@Override
public void onSuccess() {

loadImageFromLocal(ImageFetcher.getCachedPath(url), unique, imageView);
}

Expand Down Expand Up @@ -100,8 +101,6 @@ public void onLoadFailed(@Nullable Drawable errorDrawable) {
onLoadFailed(errorDrawable);
}
});
// imageView.showGif(new File(path));
// onFinishLoad(unique, null);
} else {
imageView.getPhotoView().setOnImageEventListener(new SubsamplingScaleImageView.OnImageEventListener() {
@Override
Expand Down Expand Up @@ -142,7 +141,7 @@ public void onPreviewReleased() {

}

public static void addLoadCallback(String unique, ImageLoader.LoadCallback callback) {
public static void addLoadCallback(String unique, LoadCallback callback) {
loadCallbackMap.put(unique, callback);
}

Expand All @@ -151,14 +150,14 @@ public static void removeLoadCallback(String unique) {
}

public static void onFinishLoad(String unique, Drawable drawable) {
ImageLoader.LoadCallback loadCallback = loadCallbackMap.remove(unique);
LoadCallback loadCallback = loadCallbackMap.remove(unique);
if (loadCallback != null) {
loadCallback.loadFinish(drawable);
}
}

public static void onProgress(String unique, float progress) {
ImageLoader.LoadCallback loadCallback = loadCallbackMap.get(unique);
LoadCallback loadCallback = loadCallbackMap.get(unique);
if (loadCallback != null) {
loadCallback.progress(progress);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package com.zpj.fragmentation.dialog.widget;
package com.zpj.fragmentation.dialog.imageviewer;

import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.viewpager.widget.ViewPager;
import android.util.AttributeSet;
import android.view.MotionEvent;

/**
* see issues for PhotoView: https://github.com/chrisbanes/PhotoView
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.zpj.fragmentation.dialog.interfaces;
package com.zpj.fragmentation.dialog.imageviewer;

import android.content.Context;
import android.view.View;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.zpj.fragmentation.dialog.utils;
package com.zpj.fragmentation.dialog.imageviewer;

import android.graphics.BitmapFactory;
import android.os.Handler;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package com.zpj.fragmentation.dialog.utils;
package com.zpj.fragmentation.dialog.imageviewer;

import android.graphics.drawable.Drawable;

import com.zpj.fragmentation.dialog.widget.ImageViewContainer;

public interface ImageLoader<T> {
/**
* 加载图片
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
package com.zpj.fragmentation.dialog.widget;
package com.zpj.fragmentation.dialog.imageviewer;

import android.content.Context;
import android.graphics.drawable.Drawable;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.bumptech.glide.load.resource.gif.GifDrawable;
import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView;
import com.zpj.fragmentation.dialog.interfaces.IProgressViewHolder;

public class ImageViewContainer extends FrameLayout {

Expand Down
Loading

0 comments on commit 0ef7837

Please sign in to comment.