Skip to content

Commit

Permalink
Added BlurHash support
Browse files Browse the repository at this point in the history
  • Loading branch information
TalbotGooday committed Jan 17, 2022
1 parent 531d005 commit 9a880f7
Show file tree
Hide file tree
Showing 8 changed files with 506 additions and 196 deletions.
4 changes: 4 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 13 additions & 2 deletions app/src/main/java/com/goodayapps/avatarview/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import coil.decode.ImageDecoderDecoder
import coil.decode.SvgDecoder
import coil.load
import coil.request.CachePolicy
import coil.util.DebugLogger
import com.goodayapps.widget.AvatarDrawable
import com.goodayapps.widget.AvatarView
import kotlinx.android.synthetic.main.activity_main.*
Expand All @@ -27,7 +28,13 @@ class MainActivity : AppCompatActivity() {
initViews()

// avatar111.load("https://media4.giphy.com/media/f8hd7QP9LT31Rk2NG1/giphy.gif")
avatar111.load("https://comunitee.b-cdn.net/staging/avatars/users/hlHkulpffffqQr3NWcVKxI6GbSB3/65E808E7-3098-45CE-B0D6-E50B12912751_1640027738.jpeg")
// avatar111.load("https://data.whicdn.com/images/337953887/original.gif"){
// placeholder(R.drawable.ic_circle)
//// crossfade(false)
// error(R.drawable.ic_circle)
// }

avatar111.blurHash = "UBIEhD?d01D%0MbcIVWA0gIpV[f69zSO-o%2"
}

private fun initViews() {
Expand Down Expand Up @@ -130,7 +137,7 @@ class MainActivity : AppCompatActivity() {

private fun initCoil(context: Context): ImageLoader {
val builder = ImageLoader.Builder(context)
.memoryCachePolicy(CachePolicy.ENABLED)
.memoryCachePolicy(CachePolicy.DISABLED)
.crossfade(true)
.componentRegistry {
if (Build.VERSION.SDK_INT >= 28) {
Expand All @@ -141,6 +148,10 @@ class MainActivity : AppCompatActivity() {
add(SvgDecoder(context))
}

if (BuildConfig.DEBUG) {
builder.logger(DebugLogger())
}

val imageLoader = builder.build()

Coil.setImageLoader(imageLoader)
Expand Down
8 changes: 8 additions & 0 deletions app/src/main/res/drawable/ic_circle.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:innerRadius="0dp"
android:shape="oval"
android:useLevel="false">
<size android:height="24dp" android:width="24dp"/>
<solid android:color="@color/colorPrimaryDark" />
</shape>
6 changes: 3 additions & 3 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@
app:avBorderColorSecondary="#FF9D00"
app:avBorderGradientAngle="135"
app:avBorderWidth="5dp"
app:iconDrawableScale=".3"
app:iconDrawableScale="1"
app:placeholderText="OMG" />

<!--
<com.goodayapps.widget.AvatarView
style="@style/AvatarStyleHelper"
android:layout_width="@dimen/avatar_size"
Expand Down Expand Up @@ -108,7 +108,7 @@
app:avBorderColor="@color/colorAccent"
app:avBorderWidth="5dp"
app:iconDrawableScale=".7"
app:placeholderText="AV" />
app:placeholderText="AV" />-->
</GridLayout>

<LinearLayout
Expand Down
10 changes: 7 additions & 3 deletions avatar-view/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,11 @@ project.afterEvaluate {
}

dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.4.0'
api 'androidx.core:core-ktx:1.7.0'
api 'androidx.appcompat:appcompat:1.4.1'

//Coroutines
api 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.2'
api 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.2'

}
Loading

0 comments on commit 9a880f7

Please sign in to comment.