Skip to content

Commit

Permalink
Merge pull request #81 from TheInsightDevelopers/profile-image-chat
Browse files Browse the repository at this point in the history
Fixes : #78 Profile image chat
  • Loading branch information
E13ctron authored May 3, 2021
2 parents bc12241 + 362986f commit fd24a75
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 14 deletions.
26 changes: 16 additions & 10 deletions app/src/main/java/com/example/insights/ForumnActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,22 @@ class ForumnActivity : AppCompatActivity() {
if (message.isNotEmpty()) {
var current_time =
SimpleDateFormat("yyyyMMddHHmmss").format(Date()).toString()
var data = hashMapOf(
"message" to message,
"time" to current_time,
"sender" to name,
"uid" to currentUser.uid,
"type" to type
)
// Sending Message to Firestore
db.collection("message")
.document(current_time).set(data)
FirebaseFirestore.getInstance()
.collection("ProfileImages")
.document(currentUser.uid).get().addOnSuccessListener { ImageSnapshot ->
val imageUrl = ImageSnapshot?.data?.get("url").toString()
var data = hashMapOf(
"message" to message,
"time" to current_time,
"sender" to name,
"uid" to currentUser.uid,
"type" to type,
"profileimageurl" to imageUrl
)
// Sending Message to Firestore
db.collection("message")
.document(current_time).set(data)
}
}
}

Expand Down
15 changes: 15 additions & 0 deletions app/src/main/java/com/example/insights/adapters/forumadapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ 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.example.insights.R


Expand All @@ -26,12 +28,23 @@ class forumadapter(val context: Context, val items: ArrayList<HashMap<String, St
val item = items.get(position)
holder.tv_item.text = item["message"]
holder.sender.text = item["sender"] + "(" + item["type"] + ")"
//TimeStamp
val time = item["time"].toString()
val month = time.substring(4, 6)
val date = time.substring(6, 8)
val hour = time.substring(8, 10)
val minute = time.substring(10, 12)
holder.timeStamp.text = hour + ":" + minute + " " + date + "-" + month
//Sender Image
val imageUrl = item["profileimageurl"].toString()
val senderImageView = holder.senderImage
Glide.with(senderImageView)
.load(imageUrl)
.centerCrop()
.placeholder(R.drawable.send_ic)
.error(R.drawable.ic_profile_btn)
.fallback(R.drawable.ic_baseline_menu_book_24)
.into(senderImageView)
}

override fun getItemCount(): Int {
Expand All @@ -44,6 +57,8 @@ class forumadapter(val context: Context, val items: ArrayList<HashMap<String, St
val sender = view.findViewById<TextView>(R.id.forum_sender_tv)

val timeStamp: TextView = view.findViewById(R.id.chat_time_stamp)

val senderImage: ImageView = view.findViewById(R.id.sender_image)
}

}
2 changes: 1 addition & 1 deletion app/src/main/java/com/example/insights/student_profile.kt
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ class student_profile : AppCompatActivity() {
private fun launchImageCrop(uri: Uri) {
CropImage.activity(uri)
.setGuidelines(CropImageView.Guidelines.ON)
.setAspectRatio(1920, 1080)
.setAspectRatio(1080, 1080)
.setCropShape(CropImageView.CropShape.RECTANGLE)
.start(this)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@
android:layout_gravity="center_horizontal"
android:background="@color/transparent"
android:importantForAccessibility="no"
android:visibility="gone"
android:text="@string/delete_account"
android:textColor="#FF0000" />

Expand Down
13 changes: 11 additions & 2 deletions app/src/main/res/layout/forum_custom_row.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,17 @@
android:id="@+id/chat_time_stamp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="12sp"
android:text="@string/Time" />

<com.google.android.material.imageview.ShapeableImageView
android:layout_width="60dp"
android:layout_height="60dp"
app:shapeAppearance="@style/ShapeAppearanceOverlay.App.CornerSize50Percent"
android:background="@color/transparent"
android:scaleType="fitXY"
android:id="@+id/sender_image"
android:src="@mipmap/ic_launcher_foreground"
android:layout_gravity="start"/>
<TextView
android:id="@+id/forum_sender_tv"
android:layout_width="wrap_content"
Expand All @@ -45,7 +54,7 @@
android:layout_gravity="end"
android:text="message"
android:textIsSelectable="true"
android:textSize="15sp" />
android:textSize="18sp" />
</LinearLayout>
</androidx.cardview.widget.CardView>

Expand Down

0 comments on commit fd24a75

Please sign in to comment.