aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJelena Petrovic <jelenapetrovic.7119@gmail.com>2022-12-04 01:28:02 +0100
committerJelena Petrovic <jelenapetrovic.7119@gmail.com>2022-12-04 01:28:02 +0100
commit87e5c9620e959fcfae0b5189f89ea44259469109 (patch)
tree05de7c4e0b357093416ddada4b545f2255599ebc
parenteb024ae9f03eb9720a8745174eef53246ee02b03 (diff)
Ucitavaju se slike korisnika, onemogucen odgovor na odgovor, resen problem dodavanja odgovora na pogresan komentar #67
-rw-r--r--Client/BrzoDoLokacije/app/src/main/java/com/example/brzodolokacije/Activities/ActivitySinglePost.kt8
-rw-r--r--Client/BrzoDoLokacije/app/src/main/java/com/example/brzodolokacije/Adapters/CommentsAdapter.kt99
-rw-r--r--Client/BrzoDoLokacije/app/src/main/res/layout/activity_single_post.xml11
-rw-r--r--Client/BrzoDoLokacije/app/src/main/res/layout/single_comment.xml111
4 files changed, 154 insertions, 75 deletions
diff --git a/Client/BrzoDoLokacije/app/src/main/java/com/example/brzodolokacije/Activities/ActivitySinglePost.kt b/Client/BrzoDoLokacije/app/src/main/java/com/example/brzodolokacije/Activities/ActivitySinglePost.kt
index 5f99766..c9ed2f7 100644
--- a/Client/BrzoDoLokacije/app/src/main/java/com/example/brzodolokacije/Activities/ActivitySinglePost.kt
+++ b/Client/BrzoDoLokacije/app/src/main/java/com/example/brzodolokacije/Activities/ActivitySinglePost.kt
@@ -1,11 +1,14 @@
package com.example.brzodolokacije.Activities
+import android.content.Context
import android.content.Intent
import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.os.Bundle
import android.preference.PreferenceManager
import android.util.Log
+import android.view.inputmethod.InputMethodManager
+import android.widget.EditText
import android.widget.ImageView
import android.widget.TextView
import android.widget.Toast
@@ -155,6 +158,10 @@ class ActivitySinglePost : AppCompatActivity() {
recyclerViewComments!!.layoutManager=layoutManagerComments
recyclerViewComments!!.adapter= adapterComments
}
+ fun hideKeyboard(item: EditText){
+ var imm: InputMethodManager =this.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
+ imm.hideSoftInputFromWindow(item.windowToken, InputMethodManager.HIDE_NOT_ALWAYS)
+ }
fun setRatingListeners() {
val emptyStar = R.drawable.empty_star
@@ -255,6 +262,7 @@ class ActivitySinglePost : AppCompatActivity() {
var newComment=response.body()!!
requestGetComments(newComment)
binding.NewComment.text.clear()
+ hideKeyboard(binding.NewComment)
}else{
if(response.errorBody()!=null)
Log.d("main1",response.message().toString())
diff --git a/Client/BrzoDoLokacije/app/src/main/java/com/example/brzodolokacije/Adapters/CommentsAdapter.kt b/Client/BrzoDoLokacije/app/src/main/java/com/example/brzodolokacije/Adapters/CommentsAdapter.kt
index 06713ec..731566f 100644
--- a/Client/BrzoDoLokacije/app/src/main/java/com/example/brzodolokacije/Adapters/CommentsAdapter.kt
+++ b/Client/BrzoDoLokacije/app/src/main/java/com/example/brzodolokacije/Adapters/CommentsAdapter.kt
@@ -8,15 +8,19 @@ import android.view.View
import android.view.ViewGroup
import android.view.inputmethod.InputMethodManager
import android.widget.EditText
+import android.widget.Toast
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
+import com.bumptech.glide.Glide
import com.example.brzodolokacije.Activities.ActivitySinglePost
+import com.example.brzodolokacije.Interfaces.IBackendApi
import com.example.brzodolokacije.Models.CommentReceive
import com.example.brzodolokacije.Models.CommentSend
-import com.example.brzodolokacije.R
+import com.example.brzodolokacije.Models.UserReceive
import com.example.brzodolokacije.Services.RetrofitHelper
import com.example.brzodolokacije.Services.SharedPreferencesHelper
import com.example.brzodolokacije.databinding.SingleCommentBinding
+import kotlinx.android.synthetic.main.single_comment.view.*
import retrofit2.Call
import retrofit2.Response
@@ -24,10 +28,14 @@ class CommentsAdapter (val items : MutableList<CommentSend>,val activity: Activi
: RecyclerView.Adapter<CommentsAdapter.ViewHolder>(){
//constructer has one argument - list of objects that need to be displayed
//it is bound to xml of single item
+ private var api: IBackendApi?=null
+ private var token:String?=null
private lateinit var binding: SingleCommentBinding
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val inflater = LayoutInflater.from(parent.context)
binding=SingleCommentBinding.inflate(inflater,parent,false)
+ api=RetrofitHelper.getInstance()
+ token=SharedPreferencesHelper.getValue("jwt",activity)
return ViewHolder(binding)
}
override fun onBindViewHolder(holder: ViewHolder, position: Int){
@@ -46,24 +54,37 @@ class CommentsAdapter (val items : MutableList<CommentSend>,val activity: Activi
binding.apply {
tvCommentAuthor.text=item.username
tvCommentText.text=item.comment
- etReply.visibility= View.GONE
- etReply.forceLayout()
+ Log.d("info",tvCommentText.text.toString()+binding.toString())
+ requestProfilePic(item)
+ llReply.visibility=View.GONE
+ llReply.forceLayout()
+ if(item.parentId!=""){
+ btnReply.visibility=View.GONE
+ btnReply.forceLayout()
+ }
+ else{
+ btnReply.setOnClickListener {
+ llReply.visibility=View.VISIBLE
+ llReply.forceLayout()
+ etReply.requestFocus()
+ }
+ }
etReply.showSoftInputOnFocus=true
etReply.setOnFocusChangeListener { _, focused ->
if(!focused){
- etReply.visibility= View.GONE
- etReply.forceLayout()
- btnReply.setImageResource(R.drawable.reply)
+ llReply.visibility= View.GONE
+ llReply.forceLayout()
+ //btnReply.setImageResource(R.drawable.)
hideKeyboard(etReply)
}
else{
showKeyboard(etReply)
- btnReply.setImageResource(R.drawable.post_comment)
- btnReply.setOnClickListener{
+ btnPostReply.setOnClickListener{
if(etReply.text.isNotEmpty()){
val postId=(activity as ActivitySinglePost).post._id
+ Log.d("main",binding.toString())
val comment= CommentReceive(etReply.text.toString(),item._id)
- requestAddComment(binding,comment,postId)
+ requestAddComment(comment,postId)
}
else{
Log.d("komentari","greska")
@@ -71,14 +92,10 @@ class CommentsAdapter (val items : MutableList<CommentSend>,val activity: Activi
}
}
}
- btnReply.setOnClickListener {
- etReply.visibility=View.VISIBLE
- etReply.forceLayout()
- etReply.requestFocus()
- }
+
var rv: RecyclerView = rvReplies
- rv.setHasFixedSize(false)
+ rv.setHasFixedSize(true)
rv.layoutManager=LinearLayoutManager(activity,LinearLayoutManager.VERTICAL,false)
if(item.replies!=null)
rv.adapter=CommentsAdapter(item.replies as MutableList<CommentSend>,activity)
@@ -88,14 +105,14 @@ class CommentsAdapter (val items : MutableList<CommentSend>,val activity: Activi
}
fun showKeyboard(item:EditText){
var imm:InputMethodManager=activity.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
- imm.showSoftInput(item,InputMethodManager.SHOW_FORCED)
+ imm.showSoftInput(item,InputMethodManager.SHOW_IMPLICIT)
}
fun hideKeyboard(item: EditText){
var imm:InputMethodManager=activity.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
- imm.hideSoftInputFromWindow(item.windowToken,InputMethodManager.HIDE_IMPLICIT_ONLY)
+ imm.hideSoftInputFromWindow(item.windowToken,InputMethodManager.HIDE_NOT_ALWAYS)
}
- fun requestAddComment(binding:SingleCommentBinding,comment:CommentReceive,postId:String){
+ fun requestAddComment(comment:CommentReceive,postId:String){
val postApi= RetrofitHelper.getInstance()
val token= SharedPreferencesHelper.getValue("jwt", activity)
val request=postApi.addComment("Bearer "+token,postId,comment)
@@ -103,9 +120,10 @@ class CommentsAdapter (val items : MutableList<CommentSend>,val activity: Activi
override fun onResponse(call: Call<CommentSend?>, response: Response<CommentSend?>) {
if(response.isSuccessful){
var newComment=response.body()!!
- requestGetComments(binding,newComment)
- binding.etReply.text.clear()
- hideKeyboard(binding.etReply)
+ requestGetComments(newComment)
+ itemView.etReply.text.clear()
+ hideKeyboard(itemView.etReply)
+ itemView.etReply.clearFocus()
}else{
if(response.errorBody()!=null)
Log.d("main1",response.message().toString())
@@ -120,12 +138,47 @@ class CommentsAdapter (val items : MutableList<CommentSend>,val activity: Activi
})
}
- private fun requestGetComments(binding:SingleCommentBinding,newComment: CommentSend) {
- var rv: RecyclerView = binding.rvReplies
+ private fun requestGetComments(newComment: CommentSend) {
+ var rv: RecyclerView = itemView.rvReplies
var adapter:CommentsAdapter=rv.adapter as CommentsAdapter
adapter.items.add(0,newComment)
rv.adapter=adapter
(activity as ActivitySinglePost).addedComment()
}
+
+ private fun requestProfilePic(item:CommentSend){
+ val request2=api?.getProfileFromId("Bearer "+token,
+ item.userId
+ )
+ request2?.enqueue(object : retrofit2.Callback<UserReceive?> {
+ override fun onResponse(
+ call: Call<UserReceive?>,
+ response: Response<UserReceive?>
+ ) {
+ if (response.isSuccessful) {
+ var user = response.body()!!
+ if (user.pfp != null) {
+ Glide.with(activity)
+ .load(RetrofitHelper.baseUrl + "/api/post/image/compress/" + user.pfp!!._id)
+ .circleCrop()
+ .into(itemView.ivPfp)
+ }
+ } else {
+ Toast.makeText(
+ activity, "los id",
+ Toast.LENGTH_LONG
+ ).show()
+ itemView.tvCommentAuthor.text = "nije nadjen korisnik"
+ }
+ }
+
+ override fun onFailure(call: Call<UserReceive?>, t: Throwable) {
+ Toast.makeText(
+ activity, "neuspesan zahtev",
+ Toast.LENGTH_LONG
+ ).show()
+ }
+ })
+ }
}
} \ No newline at end of file
diff --git a/Client/BrzoDoLokacije/app/src/main/res/layout/activity_single_post.xml b/Client/BrzoDoLokacije/app/src/main/res/layout/activity_single_post.xml
index e07345b..3824f69 100644
--- a/Client/BrzoDoLokacije/app/src/main/res/layout/activity_single_post.xml
+++ b/Client/BrzoDoLokacije/app/src/main/res/layout/activity_single_post.xml
@@ -5,17 +5,17 @@
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
- android:layout_height="match_parent"
+ android:layout_height="wrap_content"
android:padding="@dimen/component_padding"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context=".Activities.ActivitySinglePost">
- <ScrollView
+ <androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
- android:layout_height="match_parent">
+ android:layout_height="wrap_content">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rvMain"
android:layout_width="match_parent"
@@ -30,7 +30,6 @@
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
- android:gravity="bottom"
app:layout_constraintTop_toBottomOf="@id/rvMain"
tools:layout_editor_absoluteX="0dp">
@@ -310,7 +309,7 @@
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rvComments"
android:layout_width="match_parent"
- android:layout_height="wrap_content"
+ android:layout_height="0dp"
android:nestedScrollingEnabled="false"
app:layout_constraintTop_toBottomOf="@id/tvCommentLabel">
@@ -319,5 +318,5 @@
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
-</ScrollView>
+</androidx.core.widget.NestedScrollView>
</androidx.constraintlayout.widget.ConstraintLayout>
diff --git a/Client/BrzoDoLokacije/app/src/main/res/layout/single_comment.xml b/Client/BrzoDoLokacije/app/src/main/res/layout/single_comment.xml
index 51d9079..5e0dc03 100644
--- a/Client/BrzoDoLokacije/app/src/main/res/layout/single_comment.xml
+++ b/Client/BrzoDoLokacije/app/src/main/res/layout/single_comment.xml
@@ -3,66 +3,85 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
+ android:orientation="vertical"
android:padding="@dimen/component_padding"
xmlns:app="http://schemas.android.com/apk/res-auto">
-
- <ImageView
- android:layout_width="50dp"
- android:layout_height="50dp"
- android:src="@drawable/ic_nav_profile"
- app:layout_constraintEnd_toStartOf="@+id/tvCommentText"
- app:layout_constraintHorizontal_bias="0.0"
- app:layout_constraintStart_toStartOf="parent"
- tools:layout_editor_absoluteY="27dp" />
-
<androidx.appcompat.widget.LinearLayoutCompat
- android:layout_width="wrap_content"
+ android:layout_width="match_parent"
android:layout_height="wrap_content"
- android:orientation="vertical"
- android:layout_weight="1">
+ android:orientation="horizontal">
- <TextView
- android:id="@+id/tvCommentAuthor"
+ <ImageView
+ android:id="@+id/ivPfp"
+ android:layout_width="50dp"
+ android:layout_height="50dp"
+ android:src="@drawable/ic_nav_profile"
+ app:layout_constraintEnd_toStartOf="@+id/tvCommentText"
+ app:layout_constraintHorizontal_bias="0.0"
+ app:layout_constraintStart_toStartOf="parent"
+ android:scaleType="centerCrop"
+ tools:layout_editor_absoluteY="27dp" />
+ <androidx.appcompat.widget.LinearLayoutCompat
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:text="autor"
- android:textStyle="bold"
- android:padding="@dimen/text_padding"/>
+ android:orientation="vertical"
+ android:layout_weight="1">
- <TextView
- android:id="@+id/tvCommentText"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:padding="@dimen/text_padding"
- app:layout_constraintTop_toBottomOf="@id/tvCommentAuthor"
- tools:layout_editor_absoluteX="54dp" />
- <androidx.appcompat.widget.LinearLayoutCompat
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:orientation="horizontal"
- android:layoutDirection="rtl">
- <ImageButton
- android:layout_width="50dp"
- android:layout_height="50dp"
- android:src="@drawable/reply"
- android:layout_weight="0"
- android:id="@+id/btnReply"
- android:layout_gravity="end"
- android:backgroundTint="@color/white"
- android:scaleType="centerCrop"/>
+ <TextView
+ android:id="@+id/tvCommentAuthor"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="autor"
+ android:textStyle="bold"
+ android:padding="@dimen/text_padding"/>
- <EditText
+ <TextView
+ android:id="@+id/tvCommentText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
- android:layout_weight="1"
- android:id="@+id/etReply"
- android:layoutDirection="ltr"
- android:hint="odgovor na komentar"/>
+ android:padding="@dimen/text_padding"
+ app:layout_constraintTop_toBottomOf="@id/tvCommentAuthor"
+ tools:layout_editor_absoluteX="54dp" />
+
</androidx.appcompat.widget.LinearLayoutCompat>
- <androidx.recyclerview.widget.RecyclerView
+ <ImageButton
+ android:id="@+id/btnReply"
+ android:layout_width="50dp"
+ android:layout_height="50dp"
+ android:layout_gravity="end"
+ android:layout_weight="0"
+ android:backgroundTint="@color/white"
+ android:scaleType="centerCrop"
+ android:src="@drawable/reply" />
+
+
+
+ </androidx.appcompat.widget.LinearLayoutCompat>
+ <androidx.appcompat.widget.LinearLayoutCompat
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:orientation="horizontal"
+ android:id="@+id/llReply">
+
+ <EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
- android:id="@+id/rvReplies"/>
+ android:layout_weight="1"
+ android:id="@+id/etReply"
+ android:hint="odgovor na komentar"/>
+ <ImageButton
+ android:id="@+id/btnPostReply"
+ android:layout_width="50dp"
+ android:layout_height="50dp"
+ android:layout_gravity="end"
+ android:layout_weight="0"
+ android:backgroundTint="@color/white"
+ android:scaleType="centerCrop"
+ android:src="@drawable/post_comment" />
</androidx.appcompat.widget.LinearLayoutCompat>
+ <androidx.recyclerview.widget.RecyclerView
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:id="@+id/rvReplies"/>
</androidx.appcompat.widget.LinearLayoutCompat> \ No newline at end of file