Skip to content

Commit

Permalink
Custom image settings with glide requestOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
utkukutlu committed Apr 28, 2019
1 parent 5c02bb1 commit fc3d27e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 34 deletions.
Original file line number Diff line number Diff line change
@@ -1,27 +1,10 @@
package com.utkukutlu.library.cherryslider

class CherrySliderModel {

var imageUrl: String? = null
var imagePath: Int? = 0
var title: String? = null

constructor (imageUrl: String) {
this.imageUrl = imageUrl
}

constructor (imagePath: Int) {
this.imagePath = imagePath
}

constructor (imageUrl: String, title: String?) {
this.imageUrl = imageUrl
this.title = title
}

constructor (imagePath: Int, title: String?) {
this.imagePath = imagePath
this.title = title
}

}
import com.bumptech.glide.request.RequestOptions

data class CherrySliderModel(
var imageUrl: String? = null,
var imagePath: Int? = null,
var title: String? = null,
var opts: RequestOptions? = null
)
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import android.widget.LinearLayout
import android.widget.RelativeLayout
import android.widget.TextView
import com.bumptech.glide.Glide
import com.bumptech.glide.request.RequestOptions

class ViewPagerAdapter(context: Context?, imageList: List<CherrySliderModel>) : PagerAdapter() {

Expand Down Expand Up @@ -44,15 +43,17 @@ class ViewPagerAdapter(context: Context?, imageList: List<CherrySliderModel>) :
}

if (imageList?.get(position)?.imageUrl == null) {
Glide.with(imageView.context)
.load(imageList?.get(position)?.imagePath)
.apply(RequestOptions.fitCenterTransform().fitCenter())
.into(imageView)
val img = Glide.with(imageView.context).load(imageList?.get(position)?.imagePath)
imageList?.get(position)?.opts?.let {
img.apply(it)
}
img.into(imageView)
} else {
Glide.with(imageView.context)
.load(imageList?.get(position)?.imageUrl)
.apply(RequestOptions.fitCenterTransform().fitCenter())
.into(imageView)
val img = Glide.with(imageView.context).load(imageList?.get(position)?.imageUrl)
imageList?.get(position)?.opts?.let {
img.apply(it)
}
img.into(imageView)
}

container.addView(itemView)
Expand Down

0 comments on commit fc3d27e

Please sign in to comment.