Skip to content

Commit

Permalink
准备使用fresco
Browse files Browse the repository at this point in the history
  • Loading branch information
liuzipengWally committed Feb 23, 2017
1 parent d9e9386 commit 9587ebb
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ import com.twobbble.application.App
* Created by liuzipeng on 2017/2/15.
*/

val View.ctx: Context
get() = context

fun Activity.showSnackBar(view: View, msg: String, time: Int = Snackbar.LENGTH_SHORT) {
Snackbar.make(view, msg, time).show()
}
Expand Down
16 changes: 12 additions & 4 deletions app/src/main/java/com/twobbble/tools/ImageLoad.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.twobbble.tools

import android.content.Context
import android.widget.ImageView
import com.bumptech.glide.Glide
import com.bumptech.glide.load.engine.DiskCacheStrategy
Expand All @@ -12,13 +13,20 @@ import jp.wasabeef.glide.transformations.CropCircleTransformation
*/
class ImageLoad {
companion object {
fun loadNormal(imageView: ImageView, url: String) {
Glide.with(App.instance).load(url).placeholder(R.drawable.img_default).diskCacheStrategy(DiskCacheStrategy.ALL)
fun loadNormal(context: Context, imageView: ImageView, url: String) {
Glide.with(context).load(url).thumbnail(0.1f).placeholder(R.drawable.img_default).
error(R.mipmap.img_network_error_2).diskCacheStrategy(DiskCacheStrategy.ALL)
.crossFade().centerCrop().into(imageView)
}

fun loadCircle(imageView: ImageView, url: String) {
Glide.with(App.instance).load(url).placeholder(R.mipmap.ic_user_placeholder).diskCacheStrategy(DiskCacheStrategy.ALL)
fun loadGif(context: Context, imageView: ImageView, url: String) {
Glide.with(context).load(url).asGif().thumbnail(0.1f).placeholder(R.drawable.img_default).
error(R.mipmap.img_network_error_2).diskCacheStrategy(DiskCacheStrategy.ALL)
.crossFade().centerCrop().into(imageView)
}

fun loadCircle(context: Context, imageView: ImageView, url: String) {
Glide.with(context).load(url).placeholder(R.mipmap.ic_user_placeholder).diskCacheStrategy(DiskCacheStrategy.ALL)
.crossFade().bitmapTransform(CropCircleTransformation(App.instance)).into(imageView)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import com.twobbble.R
import com.twobbble.application.App
import com.twobbble.entity.ShotList
import com.twobbble.tools.ImageLoad
import com.twobbble.tools.ctx
import com.twobbble.tools.log
import kotlinx.android.synthetic.main.item_card_bottom.view.*
import kotlinx.android.synthetic.main.item_card_head.view.*
Expand All @@ -31,8 +32,8 @@ class ItemShotAdapter(val mShotList: List<ShotList>) : RecyclerView.Adapter<Item
inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
fun bindShots(shotList: ShotList) {
with(shotList) {
ImageLoad.loadCircle(itemView.mAvatarImg, shotList.user?.avatar_url.toString())
ImageLoad.loadNormal(itemView.mContentImg, shotList.images?.normal.toString())
ImageLoad.loadCircle(itemView.ctx, itemView.mAvatarImg, shotList.user?.avatar_url.toString())
ImageLoad.loadNormal(itemView.ctx, itemView.mContentImg, shotList.images?.normal.toString())
itemView.mTitleText.text = shotList.title
itemView.mAuthorText.text = shotList.user?.name
itemView.mLikeCountText.text = shotList.likes_count.toString()
Expand Down

0 comments on commit 9587ebb

Please sign in to comment.