Skip to content

Latest commit

 

History

History
193 lines (148 loc) · 6.25 KB

File metadata and controls

193 lines (148 loc) · 6.25 KB

AvatarView-Glide


AvatarView supports loading profile images with fractional style, borders, indicators, and initials for Android.


License API Build Status Android Weekly


Download

Maven Central

Gradle

Add the below codes to your root build.gradle file (not your module build.gradle file).

allprojects {
    repositories {
        mavenCentral()
    }
}

Next, add the below dependency to your module's build.gradle file.

dependencies {
    implementation "io.getstream:avatarview-glide:$version_avatarview"
}

The io.getstream.avatarview-glide dependency includes Glide to load images internally. So if you're using Glide in your project, please make sure your project is using the same Glide version or exclude Glide dependencies to adapt yours.

Usage

First, add the following XML namespace inside your XML layout file.

xmlns:app="http://schemas.android.com/apk/res-auto"

AvatarView in XML layout

You can customize AvatarView in your XML layout by setting attributes.

<io.getstream.avatarview.AvatarView
    android:layout_width="110dp"
    android:layout_height="110dp"
    app:avatarViewBorderColor="@color/yellow"
    app:avatarViewBorderWidth="3dp"
    app:avatarViewIndicatorBorderColor="@color/white"
    app:avatarViewIndicatorBorderSizeCriteria="10"
    app:avatarViewIndicatorColor="@color/md_green_100"
    app:avatarViewIndicatorEnabled="true"
    app:avatarViewIndicatorPosition="bottomRight"
    app:avatarViewIndicatorSizeCriteria="9"
    app:avatarViewInitialsTextStyle="bold"
    app:avatarViewShape="circle" />

Loading Single Image

You can load an image on your AvatarView by using the loadImage method as in the example below:

avatarView.loadImage(data)

The default supported data types are String, Uri, HttpUrl , File, DrawableRes, Drawable, and Bitmap.
You can also set a place holder and request listeners as in the example below:

avatarView.loadImage(
    data = data,
    placeholder = drawable,
    crossFadeEnabled = true,
    requestListener = myRequestListener,
    requestOptions = myRequestOptions
)

Loading Images with Fractional Style

AvatarView supports loading up to four images with the fractional style as in the example below:

avatarView.loadImage(
  data = listof(url1, url2, url3, url4) 
)

We can set the maximum section size of the avatar when we load multiple images by using the avatarViewMaxSectionSize attribute as in the exmample below:

app:avatarViewMaxSectionSize="4"

The default value is 4, and you can set the fractional styles to your taste.

PlaceHolder

We can set a placeholder to show a placeholder when loading an image as in the example below:

app:avatarViewPlaceholder="@drawable/stream"

Or we can set a drawable manually on the AvatarView.

avatarView.placeholder = drawable

ErrorPlaceHolder

We can set an error placeholder to show a placeholder when the request failed as in the example below:

app:avatarViewErrorPlaceholder="@drawable/stream"

Or we can set a drawable manually on the AvatarView.

avatarView.errorPlaceholder = drawable

Custom RequestBuilder

You can customize the RequestBuilder and provide additional information to load an image as in the example below:

avatarView.loadImage(
    data = cats,
    requestBuilder = Glide.with(avatarView4)
        .asDrawable()
        .override(120, 120)
        .centerCrop()
        .addListener(object : RequestListener<Drawable> {
            override fun onLoadFailed(
                e: GlideException?,
                model: Any?,
                target: Target<Drawable>?,
                isFirstResource: Boolean
              ): Boolean {
                 // do something //
                 return true
              }

              override fun onResourceReady(
                  resource: Drawable?,
                  model: Any?,
                  target: Target<Drawable>?,
                  dataSource: DataSource?,
                  isFirstResource: Boolean
              ): Boolean {
                 // do something //
                 return false
              }
          })
)
Copyright 2021 Stream.IO, Inc. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.