Skip to content

Implemented Coil Library #1

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 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: 2 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -84,5 +84,7 @@ dependencies {
// Glide
annotationProcessor 'com.github.bumptech.glide:compiler:4.11.0'
}
//coil library
implementation("io.coil-kt:coil:2.0.0-rc03")
}
apply plugin: 'com.google.gms.google-services'
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.mikhaellopez.circularimageview.CircularImageView
import coil.load
import coil.request.CachePolicy
import coil.transform.RoundedCornersTransformation
import com.thecodework.firebaseandroid.R
import com.thecodework.firebaseandroid.model.ModelDbshow

Expand All @@ -35,8 +37,12 @@ class DatabaseAdapter(
holder.tvEmail.text = arrayList[position].email
Log.d("url", arrayList[position].url.toString())
if (context != null) {
Glide.with(context).load(arrayList[position].url).placeholder(R.drawable.profile)
.into(holder.imageProfile)
holder.imageProfile.load(arrayList[position].url) {
crossfade(true)
placeholder(R.drawable.profile)
memoryCachePolicy(CachePolicy.ENABLED)
transformations(RoundedCornersTransformation(20f))
}
}
}

Expand All @@ -45,6 +51,6 @@ class DatabaseAdapter(
val tvNumber: TextView = itemView.findViewById(R.id.tvNumber)
val tvAddress: TextView = itemView.findViewById(R.id.tvAddress)
val tvEmail: TextView = itemView.findViewById(R.id.tvEmail)
val imageProfile: CircularImageView = itemView.findViewById(R.id.imageProfile)
val imageProfile: ImageView = itemView.findViewById(R.id.imageProfile)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.mikhaellopez.circularimageview.CircularImageView
import coil.load
import coil.transform.CircleCropTransformation
import com.thecodework.firebaseandroid.R
import com.thecodework.firebaseandroid.model.ModelDbshow

Expand All @@ -32,15 +33,18 @@ class FirestormsAdapter(
holder.tvNumber.text = arrayList[position].number
holder.tvAddress.text = arrayList[position].address
holder.tvEmail.text = arrayList[position].email
Glide.with(context).load(arrayList[position].url).placeholder(R.drawable.profile)
.into(holder.imageProfile)
holder.imageProfile.load(arrayList[position].url) {
crossfade(true)
placeholder(R.drawable.profile)
transformations(CircleCropTransformation())
}
}

class Holder(itemView: View) : RecyclerView.ViewHolder(itemView) {
val tvName: TextView = itemView.findViewById(R.id.tvName)
val tvNumber: TextView = itemView.findViewById(R.id.tvNumber)
val tvAddress: TextView = itemView.findViewById(R.id.tvAddress)
val tvEmail: TextView = itemView.findViewById(R.id.tvEmail)
val imageProfile: CircularImageView = itemView.findViewById(R.id.imageProfile)
val imageProfile: ImageView = itemView.findViewById(R.id.imageProfile)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package com.thecodework.firebaseandroid.ui
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.Fragment
import com.google.android.material.navigation.NavigationBarView
import com.thecodework.firebaseandroid.R
import com.thecodework.firebaseandroid.databinding.ActivityBottomnavBinding
import com.thecodework.firebaseandroid.util.Utils
Expand All @@ -19,7 +18,7 @@ class BottomnavActivity : AppCompatActivity() {
}

private fun setlistener() {
binding.bottomNav.setOnItemSelectedListener(NavigationBarView.OnItemSelectedListener { item ->
binding.bottomNav.setOnItemSelectedListener { item ->
var f: Fragment? = null
when (item.itemId) {
R.id.menu_student -> f = StudentFragment()
Expand All @@ -28,7 +27,7 @@ class BottomnavActivity : AppCompatActivity() {
}
supportFragmentManager.beginTransaction().replace(R.id.main_Layout, f!!).commit()
true
})
}
}

private fun initailizer() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
package com.thecodework.firebaseandroid.ui

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import com.google.firebase.firestore.FirebaseFirestore
import com.thecodework.firebaseandroid.R
import com.thecodework.firebaseandroid.adapter.DatabaseAdapter
import com.thecodework.firebaseandroid.adapter.FirestormsAdapter
import com.thecodework.firebaseandroid.databinding.ActivityShowFirestoreBinding
import com.thecodework.firebaseandroid.model.ModelDbshow
import com.thecodework.firebaseandroid.util.Utils
import java.util.ArrayList

class ShowFirestoreActivity : AppCompatActivity() {
lateinit var binding: ActivityShowFirestoreBinding
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import android.view.View
import android.view.ViewGroup
import android.widget.Toast
import androidx.fragment.app.Fragment
import com.google.android.gms.tasks.OnFailureListener
import com.google.firebase.database.FirebaseDatabase
import com.google.firebase.storage.FirebaseStorage
import com.google.firebase.storage.StorageReference
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class StudentListFragment : Fragment() {
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
): View {
binding = FragmentStudentListBinding.inflate(inflater, container, false)
initializer()
return binding.root
Expand Down
Original file line number Diff line number Diff line change
@@ -1,34 +1,31 @@
package com.thecodework.firebaseandroid.ui

import android.app.Activity
import android.content.ContentValues
import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.provider.MediaStore
import android.util.Log
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Toast
import com.google.android.gms.tasks.OnFailureListener
import androidx.fragment.app.Fragment
import com.google.firebase.firestore.FirebaseFirestore
import com.google.firebase.storage.FirebaseStorage
import com.google.firebase.storage.StorageReference
import com.thecodework.firebaseandroid.R
import com.thecodework.firebaseandroid.databinding.FragmentTeacherBinding
import java.io.IOException
import java.util.*
import kotlin.collections.HashMap

class TeacherFragment : Fragment() {
private lateinit var binding: FragmentTeacherBinding
lateinit var name: String
lateinit var number: String
lateinit var email: String
lateinit var address: String
val imageRequest = 1
private val imageRequest = 1
private var firebaseStore: FirebaseStorage? = null
private var storageReference: StorageReference? = null
private var filePath: Uri? = null
Expand All @@ -42,7 +39,7 @@ class TeacherFragment : Fragment() {
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
): View {
binding = FragmentTeacherBinding.inflate(inflater, container, false)
initializer()
setClickListener()
Expand All @@ -55,86 +52,114 @@ class TeacherFragment : Fragment() {
}

private fun setClickListener() {
binding.tvUpload.setOnClickListener(View.OnClickListener {
val intent = Intent()
intent.type = "image/*"
intent.action = Intent.ACTION_GET_CONTENT
startActivityForResult(
Intent.createChooser(intent, "Select Picture"),
imageRequest
)
})
binding.btnSave.setOnClickListener(View.OnClickListener {
binding.btnSave.setOnClickListener {
binding.progress.visibility = View.VISIBLE
if (filePath != null) {
val ref = storageReference?.child("uploads/" + UUID.randomUUID().toString())
ref?.putFile(filePath!!)?.addOnSuccessListener { taskSnapshot ->
taskSnapshot.storage.downloadUrl.addOnSuccessListener {
binding.progress.visibility = View.GONE
binding.imageProfile.setImageResource(R.drawable.ic_launcher_foreground)
var imageUrl = it.toString()
binding.imageProfile.setImageResource(R.drawable.profile)
val imageUrl = it.toString()
Log.d("TAG", "url$imageUrl")
name = binding.edName.text.toString()
number = binding.edNumber.text.toString()
address = binding.edAddress.text.toString()
email = binding.edEmail.text.toString()
if (name.isEmpty() || number.isEmpty() || address.isEmpty() || email.isEmpty()) {
Log.d(
"TAG",
"Enter if"
)
Toast.makeText(
activity, "Enter All Field",
Toast.LENGTH_LONG
).show()
binding.progress.visibility = View.GONE
} else {
var hashMap: HashMap<String, String> = HashMap<String, String>()
Log.d(
"TAG",
"1"
)
val hashMap: HashMap<String, String> = HashMap<String, String>()
hashMap.put("name", name)
hashMap.put("number", number)
hashMap.put("address", address)
hashMap.put("email", email)
hashMap.put("url", imageUrl)
Log.d(
"TAG",
"2"
)
FirebaseFirestore.getInstance().collection("users")
.add(hashMap)
.addOnSuccessListener { documentReference ->
Log.d(
ContentValues.TAG,
"TAG",
"DocumentSnapshot added with ID: ${documentReference.id}"
)
Toast.makeText(
activity, "Save",
Toast.LENGTH_LONG
).show()
Log.d(
"TAG",
"Save data"
)
startActivity(
Intent(
activity,
context,
ShowFirestoreActivity::class.java
)
)
Log.d(
"TAG",
"3"
)
binding.edName.text.clear()
binding.edNumber.text.clear()
binding.edAddress.text.clear()
binding.edEmail.text.clear()
Log.d(
"TAG",
"4"
)
}
.addOnFailureListener { e ->
Log.d(ContentValues.TAG, "Error adding document", e)
Toast.makeText(
activity, "Error" + e.message,
Toast.LENGTH_LONG
).show()
Log.d("TAG", "Error adding document", e)
}
}
}
}

?.addOnFailureListener(OnFailureListener { e ->
?.addOnFailureListener { e ->
Toast.makeText(
activity, e.message,
Toast.LENGTH_LONG
).show()
Log.d("TAG", e.message.toString())
})
}


} else {
Toast.makeText(activity, "Please Upload an Image", Toast.LENGTH_SHORT).show()
binding.progress.visibility = View.GONE
}

})
}
binding.tvUpload.setOnClickListener {
val intent = Intent()
intent.type = "image/*"
intent.action = Intent.ACTION_GET_CONTENT
startActivityForResult(
Intent.createChooser(intent, "Select Picture"),
imageRequest
)
}
}

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
Expand Down
Binary file added app/src/main/res/drawable/profilecircle.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 1 addition & 2 deletions app/src/main/res/layout/fragment_student_list.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/black"
tools:context=".ui.ShowActivity">

>
<TextView
android:id="@+id/tvEmpty"
android:layout_width="wrap_content"
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/fragment_teacher.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="ui.HomeActivity">
>

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/row_dbshow.xml
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
android:textStyle="bold" />
</LinearLayout>

<com.mikhaellopez.circularimageview.CircularImageView
<ImageView
android:id="@+id/imageProfile"
android:layout_width="@dimen/space_100"
android:layout_height="@dimen/space_100"
Expand Down