Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for custom PipelineDraweeControllerBuilder #78

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion frescoimageviewer/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,5 @@ dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:25.1.1'
compile 'me.relex:photodraweeview:1.1.0'
provided 'com.facebook.fresco:fresco:0.12.0'
provided 'com.facebook.fresco:fresco:1.8.1'
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
import android.view.KeyEvent;
import android.view.View;

import com.facebook.drawee.backends.pipeline.Fresco;
import com.facebook.drawee.backends.pipeline.PipelineDraweeControllerBuilder;
import com.facebook.drawee.generic.GenericDraweeHierarchyBuilder;
import com.facebook.imagepipeline.request.ImageRequestBuilder;

Expand Down Expand Up @@ -72,6 +74,7 @@ private void createDialog() {
viewer = new ImageViewerView(builder.context);
viewer.setCustomImageRequestBuilder(builder.customImageRequestBuilder);
viewer.setCustomDraweeHierarchyBuilder(builder.customHierarchyBuilder);
viewer.setCustomDraweeControllerBuilder(builder.customDraweeControllerBuilder);
viewer.allowZooming(builder.isZoomingAllowed);
viewer.allowSwipeToDismiss(builder.isSwipeToDismissAllowed);
viewer.setOnDismissListener(this);
Expand Down Expand Up @@ -135,6 +138,13 @@ public static ImageRequestBuilder createImageRequestBuilder() {
return ImageRequestBuilder.newBuilderWithSource(Uri.parse(""));
}

/**
* Creates new {@code PipelineDraweeControllerBuilder}.
*/
public static PipelineDraweeControllerBuilder createPipelineDraweeControllerBuilder() {
return Fresco.newDraweeControllerBuilder();
}

/**
* Interface definition for a callback to be invoked when image was changed
*/
Expand Down Expand Up @@ -208,6 +218,7 @@ public static class Builder<T> {
private int[] containerPaddingPixels = new int[4];
private ImageRequestBuilder customImageRequestBuilder;
private GenericDraweeHierarchyBuilder customHierarchyBuilder;
private PipelineDraweeControllerBuilder customDraweeControllerBuilder;
private boolean shouldStatusBarHide = true;
private boolean isZoomingAllowed = true;
private boolean isSwipeToDismissAllowed = true;
Expand Down Expand Up @@ -416,6 +427,17 @@ public Builder setCustomDraweeHierarchyBuilder(GenericDraweeHierarchyBuilder cus
return this;
}

/**
* Set {@link PipelineDraweeControllerBuilder} for drawees inside viewer.
* Use {@link ImageViewer#createPipelineDraweeControllerBuilder()} to create its new instance.
*
* @return This Builder object to allow for chaining of calls to set methods
*/
public Builder setCustomDraweeControllerBuilder(PipelineDraweeControllerBuilder customDraweeControllerBuilder) {
this.customDraweeControllerBuilder = customDraweeControllerBuilder;
return this;
}

/**
* Creates a {@link ImageViewer} with the arguments supplied to this builder. It does not
* {@link ImageViewer#show()} the dialog. This allows the user to do any extra processing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,19 @@ class ImageViewerAdapter
private HashSet<ImageViewHolder> holders;
private ImageRequestBuilder imageRequestBuilder;
private GenericDraweeHierarchyBuilder hierarchyBuilder;
private PipelineDraweeControllerBuilder controllerBuilder;
private boolean isZoomingAllowed;

ImageViewerAdapter(Context context, ImageViewer.DataSet<?> dataSet,
ImageRequestBuilder imageRequestBuilder,
GenericDraweeHierarchyBuilder hierarchyBuilder,
PipelineDraweeControllerBuilder controllerBuilder,
boolean isZoomingAllowed) {
this.context = context;
this.dataSet = dataSet;
this.holders = new HashSet<>();
this.imageRequestBuilder = imageRequestBuilder;
this.controllerBuilder = controllerBuilder;
this.hierarchyBuilder = hierarchyBuilder;
this.isZoomingAllowed = isZoomingAllowed;
}
Expand Down Expand Up @@ -141,15 +144,19 @@ private void tryToSetHierarchy() {
}

private void setController(String url) {
PipelineDraweeControllerBuilder controllerBuilder = Fresco.newDraweeControllerBuilder();
controllerBuilder.setUri(url);
controllerBuilder.setOldController(drawee.getController());
controllerBuilder.setControllerListener(getDraweeControllerListener(drawee));
PipelineDraweeControllerBuilder builder = controllerBuilder;
if (builder == null) {
builder = Fresco.newDraweeControllerBuilder();
}

builder.setUri(url);
builder.setOldController(drawee.getController());
builder.setControllerListener(getDraweeControllerListener(drawee));
if (imageRequestBuilder != null) {
imageRequestBuilder.setSource(Uri.parse(url));
controllerBuilder.setImageRequest(imageRequestBuilder.build());
builder.setImageRequest(imageRequestBuilder.build());
}
drawee.setController(controllerBuilder.build());
drawee.setController(builder.build());
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import android.view.ViewGroup;
import android.widget.RelativeLayout;

import com.facebook.drawee.backends.pipeline.PipelineDraweeControllerBuilder;
import com.facebook.drawee.generic.GenericDraweeHierarchyBuilder;
import com.facebook.imagepipeline.request.ImageRequestBuilder;

Expand All @@ -52,6 +53,7 @@ class ImageViewerView extends RelativeLayout

private ImageRequestBuilder customImageRequestBuilder;
private GenericDraweeHierarchyBuilder customDraweeHierarchyBuilder;
private PipelineDraweeControllerBuilder customDraweeControllerBuilder;

private boolean wasScaled;
private OnDismissListener onDismissListener;
Expand All @@ -77,7 +79,8 @@ public ImageViewerView(Context context, AttributeSet attrs, int defStyleAttr) {

public void setUrls(ImageViewer.DataSet<?> dataSet, int startPosition) {
adapter = new ImageViewerAdapter(
getContext(), dataSet, customImageRequestBuilder, customDraweeHierarchyBuilder, isZoomingAllowed);
getContext(), dataSet, customImageRequestBuilder, customDraweeHierarchyBuilder,
customDraweeControllerBuilder, isZoomingAllowed);
pager.setAdapter(adapter);
setStartPosition(startPosition);
}
Expand All @@ -90,6 +93,10 @@ public void setCustomDraweeHierarchyBuilder(GenericDraweeHierarchyBuilder custom
this.customDraweeHierarchyBuilder = customDraweeHierarchyBuilder;
}

public void setCustomDraweeControllerBuilder(PipelineDraweeControllerBuilder customDraweeControllerBuilder) {
this.customDraweeControllerBuilder = customDraweeControllerBuilder;
}

@Override
public void setBackgroundColor(int color) {
findViewById(R.id.backgroundView)
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Tue Apr 11 09:58:14 EEST 2017
#Wed Sep 06 11:04:56 UYT 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
46 changes: 21 additions & 25 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,12 @@
##
##############################################################################

# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`"/$link"
fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >/dev/null
APP_HOME="`pwd -P`"
cd "$SAVED" >/dev/null
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS=""

APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS=""

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"

Expand All @@ -48,7 +30,6 @@ die ( ) {
cygwin=false
msys=false
darwin=false
nonstop=false
case "`uname`" in
CYGWIN* )
cygwin=true
Expand All @@ -59,11 +40,26 @@ case "`uname`" in
MINGW* )
msys=true
;;
NONSTOP* )
nonstop=true
;;
esac

# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`"/$link"
fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >/dev/null
APP_HOME="`pwd -P`"
cd "$SAVED" >/dev/null

CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar

# Determine the Java command to use to start the JVM.
Expand All @@ -89,7 +85,7 @@ location of your Java installation."
fi

# Increase the maximum file descriptors if we can.
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
MAX_FD_LIMIT=`ulimit -H -n`
if [ $? -eq 0 ] ; then
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
Expand Down
8 changes: 4 additions & 4 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal

@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS=

set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%

@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS=

@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome

Expand Down Expand Up @@ -46,7 +46,7 @@ echo location of your Java installation.
goto fail

:init
@rem Get command-line arguments, handling Windows variants
@rem Get command-line arguments, handling Windowz variants

if not "%OS%" == "Windows_NT" goto win9xME_args
if "%@eval[2+2]" == "4" goto 4NT_args
Expand Down
2 changes: 1 addition & 1 deletion sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ android {

ext {
supportVersion = '25.1.1'
frescoVersion = '1.2.0'
frescoVersion = '1.8.1'
}

dependencies {
Expand Down