Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
7 changes: 7 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,19 @@ buildscript {
androidTargerSdkVersion = androidCompileSdkVersion

libDynamicColorVersion = '1.0.0'
libDynamicImageVersion = '1.0.0'
Comment thread
TomasValenta marked this conversation as resolved.
Outdated
libDynamicImageCoilVersion = '1.0.0'
libDynamicImageGlideVersion = '1.0.0'
libDynamicImagePicassoVersion = '1.0.0'
libDynamicTextVersion = '3.0.0'

kotlinVersion = '1.4.21'
androidXCoreVersion = '1.3.2'
annotationVersion = '1.1.0'
commonExtensionsVersion = '1.0.0'
coilVersion = '1.1.0'
glideVersion = '4.11.0'
picassoVersion = '2.71828'

junitVersion = '4.13.1'
androidTestRunnerVersion = '1.3.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,7 @@ open class DynamicColor : Parcelable {
parcel.writeInt(attrRes ?: NO_ID)
}

override fun describeContents(): Int {
return 0
}
override fun describeContents() = 0

override fun equals(other: Any?): Boolean {
if (this === other) return true
Expand Down
3 changes: 0 additions & 3 deletions dynamic/color/src/main/res/values/strings.xml

This file was deleted.

1 change: 1 addition & 0 deletions dynamic/image-coil/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
56 changes: 56 additions & 0 deletions dynamic/image-coil/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'

ext.bintrayPublishVersion = libDynamicImageCoilVersion
apply from: '../../bintray-publish-config.gradle'

android {
compileSdkVersion androidCompileSdkVersion

defaultConfig {
minSdkVersion androidMinSdkVersion
targetSdkVersion androidTargerSdkVersion
versionName libDynamicImageCoilVersion

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles 'consumer-rules.pro'
}

buildTypes {
release {
minifyEnabled false
Comment thread
TomasValenta marked this conversation as resolved.
Outdated
}
}

buildFeatures {
dataBinding = true
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

kotlinOptions {
jvmTarget = JavaVersion.VERSION_1_8.toString()
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])

api project(':dynamic:image')

implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlinVersion"
implementation "androidx.annotation:annotation:$annotationVersion"
implementation "androidx.core:core-ktx:$androidXCoreVersion"
implementation "com.twocoders.extensions:common:$commonExtensionsVersion"

implementation "io.coil-kt:coil:$coilVersion"

androidTestImplementation "androidx.test:runner:$androidTestRunnerVersion"
androidTestImplementation "androidx.test.ext:junit:$androidJunitVersion"

testImplementation "junit:junit:$junitVersion"
}
Empty file.
1 change: 1 addition & 0 deletions dynamic/image-coil/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<manifest package="com.twocoders.dynamic.image.coil" />
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
package com.twocoders.dynamic.image.coil

import android.content.Context
import android.graphics.drawable.Drawable
import android.graphics.drawable.VectorDrawable
import android.os.Parcel
import android.os.Parcelable
import android.widget.ImageView
import androidx.annotation.ColorInt
import androidx.annotation.DrawableRes
import coil.Coil
import coil.ImageLoader
import coil.load
import coil.request.ImageRequest
import com.twocoders.dynamic.image.BaseDynamicImage
import com.twocoders.dynamic.image.component.UriComponent

/**
*
* Handy class which can be used to bind image data to views using them.
Comment thread
TomasValenta marked this conversation as resolved.
Outdated
* Data can be in [DrawableRes], [Drawable], or [UriComponent] format.
*
* Use one of [DynamicImage.from] creator methods to create the data
* and [DynamicImage.getDrawable] to obtain the final [Drawable] output. Or you can
* provide target [ImageView] class into the [DynamicImage.loadDrawableInto] method.
*
* This [DynamicImage] implementation uses [Coil], for other implementations please visit our GitHub.
Comment thread
TomasValenta marked this conversation as resolved.
Outdated
*
*/
@Suppress("unused", "MemberVisibilityCanBePrivate")
open class DynamicImage : BaseDynamicImage {

protected constructor(
@ColorInt imageRes: Int? = null,
imageDrawable: Drawable? = null,
imageUri: UriComponent? = null
) : super(imageRes, imageDrawable, imageUri)

protected constructor(parcel: Parcel) : super(parcel)

companion object {

val EMPTY = DynamicImage()

@JvmStatic
fun from(@DrawableRes imageRes: Int) = DynamicImage(imageRes = imageRes)

@JvmStatic
fun from(imageDrawable: Drawable) = DynamicImage(imageDrawable = imageDrawable)

@JvmStatic
fun from(imageUri: UriComponent) = DynamicImage(imageUri = imageUri)

@JvmField
val CREATOR = object : Parcelable.Creator<DynamicImage> {
override fun createFromParcel(parcel: Parcel) = DynamicImage(parcel)
override fun newArray(size: Int): Array<DynamicImage?> = arrayOfNulls(size)
}
}

override suspend fun getDrawable(context: Context): Drawable? {
imageUri?.let { uri ->
val request = ImageRequest.Builder(context)
.data(uri)
.build()
return ImageLoader(context).execute(request).drawable
}

return super.getDrawable(context)
}

override fun getDrawable(context: Context, callback: (drawable: Drawable) -> Unit) {
imageUri?.let { imageUriComponent ->
val request = ImageRequest.Builder(context)
.data(imageUriComponent.image)
.target { callback(it) }
.build()
ImageLoader(context).enqueue(request)
}

super.getDrawable(context, callback)
}

override fun loadDrawableInto(
imageView: ImageView,
withCrossFade: Boolean
) {
imageUri?.let { imageUriComponent ->
imageView.load(imageUriComponent.image) {
crossfade(withCrossFade)
imageUriComponent.placeholderImage?.let { placeholder(it) }
imageUriComponent.errorImage?.let { error(it) }
}
}

imageDrawable?.let {
// Note: Coil has currently issue with loading vectors
if (it is VectorDrawable) {
imageView.setImageDrawable(it)
} else {
imageView.load(it) {
crossfade(withCrossFade)
}
}
}

imageRes?.let {
// We need to get drawable before setting it to imageView through Coil,
// there is a problem with background tint from theme attribute
getDrawable(imageView.context) { drawable ->
// Note: Coil has currently issue with loading vectors
if (drawable is VectorDrawable) {
imageView.setImageDrawable(drawable)
} else {
imageView.load(drawable) {
crossfade(withCrossFade)
}
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.twocoders.dynamic.image.coil

import android.widget.ImageView
import androidx.databinding.BindingAdapter

@BindingAdapter(value = ["android:src", "loadWithCrossFade"], requireAll = false)
fun ImageView.loadDynamicImage(image: DynamicImage, withCrossFade: Boolean = false) =
image.loadDrawableInto(this, withCrossFade)
1 change: 1 addition & 0 deletions dynamic/image-glide/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
56 changes: 56 additions & 0 deletions dynamic/image-glide/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'

ext.bintrayPublishVersion = libDynamicImageGlideVersion
apply from: '../../bintray-publish-config.gradle'

android {
compileSdkVersion androidCompileSdkVersion

defaultConfig {
minSdkVersion androidMinSdkVersion
targetSdkVersion androidTargerSdkVersion
versionName libDynamicImageGlideVersion

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles 'consumer-rules.pro'
}

buildTypes {
release {
minifyEnabled false
}
}

buildFeatures {
dataBinding = true
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

kotlinOptions {
jvmTarget = JavaVersion.VERSION_1_8.toString()
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])

api project(':dynamic:image')

implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlinVersion"
implementation "androidx.annotation:annotation:$annotationVersion"
implementation "androidx.core:core-ktx:$androidXCoreVersion"
implementation "com.twocoders.extensions:common:$commonExtensionsVersion"

implementation "com.github.bumptech.glide:glide:$glideVersion"

androidTestImplementation "androidx.test:runner:$androidTestRunnerVersion"
androidTestImplementation "androidx.test.ext:junit:$androidJunitVersion"

testImplementation "junit:junit:$junitVersion"
}
Empty file.
1 change: 1 addition & 0 deletions dynamic/image-glide/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<manifest package="com.twocoders.dynamic.image.glide" />
Loading