Skip to content

Added How to use Coil Image Loading Library. #117

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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 android/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ android {
}

dependencies {

implementation("io.coil-kt:coil:0.9.1")
implementation(Kotlin.stdlib)
implementation(AndroidX.core.ktx)
implementation(AndroidX.appCompat)
Expand Down
53 changes: 52 additions & 1 deletion android/src/main/java/playground/android/CoilFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,17 @@ import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import coil.api.load
import coil.transform.BlurTransformation
import coil.transform.CircleCropTransformation
import coil.transform.GrayscaleTransformation
import coil.transform.RoundedCornersTransformation
import java.io.File


class CoilFragment : Fragment() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add links to the project repo and documentation?
That will greatly add new comers

/**
* jetbrains/markdown : Multiplatform Markdown processor written in Kotlin
*
* - [Website](https://github.com/JetBrains/markdown)
* - [Github](https://github.com/JetBrains/markdown)
*/
fun main(){
generateHtml()
}

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have now added the references.



override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
Expand All @@ -18,4 +24,49 @@ class CoilFragment : Fragment() {
return inflater.inflate(R.layout.fragment_coil, container, false)
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

// initializing the imageViews

val ivFile: ImageView = view.findViewById(R.id.ivFile)
val ivUrl: ImageView = view.findViewById(R.id.ivUrl)
val ivDrawable: ImageView = view.findViewById(R.id.ivDrawable)

// loading image into imageView through coil using different methods

//Loading from a URL
ivUrl.load("https://via.placeholder.com/600/92c952")

//Loading from an image drawable
ivDrawable.load(R.drawable.placeholder_img)

// Loading from a file
ivFile.load(File("/path/to/some_image_placeholder.png"))

//adding placeholder to loading images
ivUrl.load("https://via.placeholder.com/600/92c952") {
placeholder(R.drawable.placeholder_img)
}

//applying some basic transformations to image using coil

ivUrl.load("https://via.placeholder.com/600/92c952") {
transformations(CircleCropTransformation()) // Crops and centres the image into a circle.
}

ivUrl.load("https://via.placeholder.com/600/92c952") {
transformations(BlurTransformation(requireContext())) // Applies a Gaussian Blur.
}

ivUrl.load("https://via.placeholder.com/600/92c952") {
transformations(GrayscaleTransformation()) // Shades the image into grayscale.
}

ivUrl.load("https://via.placeholder.com/600/92c952") {
transformations(RoundedCornersTransformation()) // Crops the image to fit the target's dimensions and rounds the corners of the image.
}

}

}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 22 additions & 8 deletions android/src/main/res/layout/fragment_coil.xml
Original file line number Diff line number Diff line change
@@ -1,14 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".CoilFragment">


<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/hello_blank_fragment" />

</FrameLayout>
<ImageView
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_above="@id/ivDrawable"
android:layout_centerHorizontal="true"
android:layout_marginBottom="15dp"
android:id="@+id/ivFile" />
<ImageView
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_alignParentEnd="true"
android:layout_marginEnd="50dp"
android:layout_centerVertical="true"
android:id="@+id/ivUrl" />
<ImageView
android:layout_centerVertical="true"
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_marginStart="50dp"
android:id="@+id/ivDrawable" />
</RelativeLayout>
2 changes: 2 additions & 0 deletions kotlin-jvm/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ dependencies {
implementation("com.apollographql.apollo:apollo-runtime:_")
implementation(KotlinX.serialization.json)
implementation(KotlinX.serialization.properties)
implementation("io.coil-kt:coil:0.9.1")

// Keep dependencies sorted to minimize merge conflicts on pull-requests!
}

Expand Down