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

Glide replaced and set current slide bug fixed #19

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 9 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 README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Banner slider is an easy to use library for making beautiful sliders in your and
### Gradle
add this line to your module build.gradle dependecies block:

compile 'com.ss.bannerslider:bannerslider:1.6.1'
compile 'com.github.MohammadRezaei92:Banner-Slider:54dd0dab17'

### Maven

Expand Down
6 changes: 4 additions & 2 deletions bannerslider/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ android {

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:25.0.1'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.github.bumptech.glide:glide:4.0.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.0.0'
compile 'com.android.support:support-v4:25.3.1'
}


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package ss.com.bannerslider;

import com.bumptech.glide.annotation.GlideModule;
import com.bumptech.glide.module.AppGlideModule;

/**
* Created by USER on 8/9/2017.
*/

@GlideModule
public final class SliderGlideModule extends AppGlideModule {
@Override
public boolean isManifestParsingEnabled() {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
public class Banner implements Parcelable {
private int id;
private int position;
private ImageView.ScaleType scaleType = ImageView.ScaleType.CENTER_CROP;
private ImageView.ScaleType scaleType = ImageView.ScaleType.CENTER_INSIDE;
private OnBannerClickListener onBannerClickListener;
private View.OnTouchListener onTouchListener;

Expand Down Expand Up @@ -97,4 +97,4 @@ public View.OnTouchListener getOnTouchListener() {
public void setOnTouchListener(View.OnTouchListener onTouchListener) {
this.onTouchListener = onTouchListener;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package ss.com.bannerslider.banners;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.Parcel;
import android.os.Parcelable;
import android.support.annotation.DrawableRes;

/**
* @author S.Shahini
Expand All @@ -14,7 +13,7 @@

public class RemoteBanner extends Banner implements Parcelable {
private String url;
private Drawable placeHolder;
private int placeHolder = 0;
private Drawable errorDrawable;

public RemoteBanner(String url) {
Expand All @@ -25,11 +24,11 @@ public String getUrl() {
return url;
}

public Drawable getPlaceHolder() {
public int getPlaceHolder() {
return placeHolder;
}

public RemoteBanner setPlaceHolder(Drawable placeHolder) {
public RemoteBanner setPlaceHolder(@DrawableRes int placeHolder) {
this.placeHolder = placeHolder;
return this;
}
Expand All @@ -45,7 +44,7 @@ public RemoteBanner setErrorDrawable(Drawable errorDrawable) {

protected RemoteBanner(Parcel in) {
url = in.readString();
placeHolder = (Drawable) in.readValue(Drawable.class.getClassLoader());
placeHolder = in.readInt();
errorDrawable = (Drawable) in.readValue(Drawable.class.getClassLoader());
}

Expand All @@ -57,8 +56,8 @@ public int describeContents() {
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(url);
if (placeHolder!=null) {
dest.writeParcelable(((BitmapDrawable) placeHolder).getBitmap(), flags);
if (placeHolder!=0) {
dest.writeInt(placeHolder);
}
if (errorDrawable!=null) {
dest.writeParcelable(((BitmapDrawable) errorDrawable).getBitmap(), flags);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@
import ss.com.bannerslider.R;
import ss.com.bannerslider.banners.Banner;
import ss.com.bannerslider.events.OnBannerClickListener;
import ss.com.bannerslider.views.BannerAdapter;
import ss.com.bannerslider.views.IAttributeChange;
import ss.com.bannerslider.views.SlideIndicatorsGroup;
import ss.com.bannerslider.views.indicators.IndicatorShape;

/**
Expand Down Expand Up @@ -393,7 +390,7 @@ public void setCurrentSlide(final int position) {
@Override
public void run() {
if (viewPager != null) {
viewPager.setCurrentItem(position);
viewPager.setCurrentItem((mustLoopSlides) ? (position + 1) : position);
}
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.Toast;

import com.squareup.picasso.Picasso;
import com.bumptech.glide.Glide;

import ss.com.bannerslider.GlideApp;
import ss.com.bannerslider.banners.Banner;
import ss.com.bannerslider.banners.DrawableBanner;
import ss.com.bannerslider.banners.RemoteBanner;
Expand Down Expand Up @@ -47,18 +45,18 @@ public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
imageView.setScaleType(banner.getScaleType());
if (banner instanceof DrawableBanner) {
DrawableBanner drawableBanner = (DrawableBanner) banner;
Picasso.with(getContext()).load(drawableBanner.getDrawable()).into(imageView);
Glide.with(getContext()).load(drawableBanner.getDrawable()).into(imageView);
} else {
final RemoteBanner remoteBanner = (RemoteBanner) banner;
if (remoteBanner.getErrorDrawable() == null && remoteBanner.getPlaceHolder() == null) {
Picasso.with(getActivity()).load(remoteBanner.getUrl()).into(imageView);
if (remoteBanner.getErrorDrawable() == null && remoteBanner.getPlaceHolder() == 0) {
Glide.with(this).load(remoteBanner.getUrl()).into(imageView);
} else {
if (remoteBanner.getPlaceHolder() != null && remoteBanner.getErrorDrawable() != null) {
Picasso.with(getActivity()).load(remoteBanner.getUrl()).placeholder(remoteBanner.getPlaceHolder()).error(remoteBanner.getErrorDrawable()).into(imageView);
if (remoteBanner.getPlaceHolder() != 0 && remoteBanner.getErrorDrawable() != null) {
GlideApp.with(this).load(remoteBanner.getUrl()).placeholder(remoteBanner.getPlaceHolder()).error(remoteBanner.getErrorDrawable()).into(imageView);
} else if (remoteBanner.getErrorDrawable() != null) {
Picasso.with(getActivity()).load(remoteBanner.getUrl()).error(remoteBanner.getErrorDrawable()).into(imageView);
} else if (remoteBanner.getPlaceHolder() != null) {
Picasso.with(getActivity()).load(remoteBanner.getUrl()).placeholder(remoteBanner.getPlaceHolder()).into(imageView);
GlideApp.with(this).load(remoteBanner.getUrl()).error(remoteBanner.getErrorDrawable()).into(imageView);
} else if (remoteBanner.getPlaceHolder() != 0) {
GlideApp.with(this).load(remoteBanner.getUrl()).placeholder(remoteBanner.getPlaceHolder()).into(imageView);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.1'
classpath 'com.android.tools.build:gradle:2.3.3'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7'
classpath "com.github.dcendents:android-maven-gradle-plugin:1.5"
// NOTE: Do not place your application dependencies here; they belong
Expand Down