Skip to content
This repository has been archived by the owner. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ android {
}

dependencies {

implementation 'io.coil-kt:coil:2.0.0-rc03'
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'com.google.android.material:material:1.5.0'
Expand Down
35 changes: 25 additions & 10 deletions app/src/main/java/com/epic/asyncworkexample/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,35 +1,49 @@
package com.epic.asyncworkexample

import android.graphics.Bitmap
import android.graphics.BitmapFactory
import android.os.AsyncTask
import android.os.Bundle
import android.widget.Button
import android.widget.ImageView
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import coil.load
import coil.request.ErrorResult
import coil.request.ImageRequest
import coil.transform.RoundedCornersTransformation

class MainActivity : AppCompatActivity() {

companion object {
private const val GITHUB_LOGO_IMAGE_URL =
private const val GITHUB_LOGO_IMAGE_URL_VAL =
"https://github.githubassets.com/images/modules/logos_page/Octocat.png"
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)

val imageView = findViewById<ImageView>(R.id.image_view)

findViewById<Button>(R.id.button_view).setOnClickListener {
DownloadImageAsyncTask(
object : DownloadImageAsyncTask.Callback {
override fun onSuccess(result: Bitmap) {
findViewById<ImageView>(R.id.image_view).setImageBitmap(result)
imageView.load(GITHUB_LOGO_IMAGE_URL_VAL) {
listener(
onError = { _: ImageRequest, result: ErrorResult ->
Toast.makeText(
applicationContext,
"Error: ${result.throwable.message}. ",
Toast.LENGTH_SHORT
).show()
}
}
).execute(GITHUB_LOGO_IMAGE_URL)
)
crossfade(8500)
transformations(
RoundedCornersTransformation(180F)
)
error(findViewById<ImageView>(R.id.image_view).drawable)
}
}
}

/*
class DownloadImageAsyncTask(
private val callback: Callback
): AsyncTask<String, Unit, Bitmap>() {
Expand Down Expand Up @@ -64,4 +78,5 @@ class MainActivity : AppCompatActivity() {
callback.onSuccess(result)
}
}
*/
}