diff --git a/app/build.gradle b/app/build.gradle index ec81a71..53763ed 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -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' \ No newline at end of file diff --git a/app/src/main/java/com/thecodework/firebaseandroid/adapter/DatabaseAdapter.kt b/app/src/main/java/com/thecodework/firebaseandroid/adapter/DatabaseAdapter.kt index b95bbd8..3962b63 100644 --- a/app/src/main/java/com/thecodework/firebaseandroid/adapter/DatabaseAdapter.kt +++ b/app/src/main/java/com/thecodework/firebaseandroid/adapter/DatabaseAdapter.kt @@ -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 @@ -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)) + } } } @@ -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) } } \ No newline at end of file diff --git a/app/src/main/java/com/thecodework/firebaseandroid/adapter/FirestormsAdapter.kt b/app/src/main/java/com/thecodework/firebaseandroid/adapter/FirestormsAdapter.kt index fb9f014..e39355c 100644 --- a/app/src/main/java/com/thecodework/firebaseandroid/adapter/FirestormsAdapter.kt +++ b/app/src/main/java/com/thecodework/firebaseandroid/adapter/FirestormsAdapter.kt @@ -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 @@ -32,8 +33,11 @@ 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) { @@ -41,6 +45,6 @@ class FirestormsAdapter( 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) } } \ No newline at end of file diff --git a/app/src/main/java/com/thecodework/firebaseandroid/ui/BottomnavActivity.kt b/app/src/main/java/com/thecodework/firebaseandroid/ui/BottomnavActivity.kt index 9d6ed49..0198c3b 100644 --- a/app/src/main/java/com/thecodework/firebaseandroid/ui/BottomnavActivity.kt +++ b/app/src/main/java/com/thecodework/firebaseandroid/ui/BottomnavActivity.kt @@ -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 @@ -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() @@ -28,7 +27,7 @@ class BottomnavActivity : AppCompatActivity() { } supportFragmentManager.beginTransaction().replace(R.id.main_Layout, f!!).commit() true - }) + } } private fun initailizer() { diff --git a/app/src/main/java/com/thecodework/firebaseandroid/ui/ShowFirestoreActivity.kt b/app/src/main/java/com/thecodework/firebaseandroid/ui/ShowFirestoreActivity.kt index e9892ad..17b7164 100644 --- a/app/src/main/java/com/thecodework/firebaseandroid/ui/ShowFirestoreActivity.kt +++ b/app/src/main/java/com/thecodework/firebaseandroid/ui/ShowFirestoreActivity.kt @@ -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 diff --git a/app/src/main/java/com/thecodework/firebaseandroid/ui/StudentFragment.kt b/app/src/main/java/com/thecodework/firebaseandroid/ui/StudentFragment.kt index a3b61b7..2973fab 100644 --- a/app/src/main/java/com/thecodework/firebaseandroid/ui/StudentFragment.kt +++ b/app/src/main/java/com/thecodework/firebaseandroid/ui/StudentFragment.kt @@ -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 diff --git a/app/src/main/java/com/thecodework/firebaseandroid/ui/StudentListFragment.kt b/app/src/main/java/com/thecodework/firebaseandroid/ui/StudentListFragment.kt index 3b56907..b07908d 100644 --- a/app/src/main/java/com/thecodework/firebaseandroid/ui/StudentListFragment.kt +++ b/app/src/main/java/com/thecodework/firebaseandroid/ui/StudentListFragment.kt @@ -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 diff --git a/app/src/main/java/com/thecodework/firebaseandroid/ui/TeacherFragment.kt b/app/src/main/java/com/thecodework/firebaseandroid/ui/TeacherFragment.kt index 14c2aab..66a0d67 100644 --- a/app/src/main/java/com/thecodework/firebaseandroid/ui/TeacherFragment.kt +++ b/app/src/main/java/com/thecodework/firebaseandroid/ui/TeacherFragment.kt @@ -1,18 +1,16 @@ 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 @@ -20,7 +18,6 @@ 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 @@ -28,7 +25,7 @@ class TeacherFragment : Fragment() { 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 @@ -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() @@ -55,78 +52,97 @@ 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 = HashMap() + Log.d( + "TAG", + "1" + ) + val hashMap: HashMap = HashMap() 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 { @@ -134,7 +150,16 @@ class TeacherFragment : Fragment() { 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?) { diff --git a/app/src/main/res/drawable/profilecircle.png b/app/src/main/res/drawable/profilecircle.png new file mode 100644 index 0000000..db741fc Binary files /dev/null and b/app/src/main/res/drawable/profilecircle.png differ diff --git a/app/src/main/res/layout/fragment_student_list.xml b/app/src/main/res/layout/fragment_student_list.xml index 488db82..8d1fcb5 100644 --- a/app/src/main/res/layout/fragment_student_list.xml +++ b/app/src/main/res/layout/fragment_student_list.xml @@ -5,8 +5,7 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/black" - tools:context=".ui.ShowActivity"> - + > + > -