diff options
author | TAMARA JERINIC <tamara.jerinic@gmail.com> | 2022-12-06 13:36:06 +0100 |
---|---|---|
committer | TAMARA JERINIC <tamara.jerinic@gmail.com> | 2022-12-06 13:36:06 +0100 |
commit | 494e54cf82c559e4c1a5c84e489b7aa0246d5026 (patch) | |
tree | 04aa3294c6ca2850e887daec410af4f38e457ec2 | |
parent | 5cef3f0d894034eade424bff5c1fef5fe0c44b39 (diff) |
Izmenjena struktura i izgled ActivitySinglePage. Povezan fragment za prikaz detalja o objavi. Povezan fragment za prikaz i dodavanje komentara.
8 files changed, 408 insertions, 329 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 2483e7e..df5de58 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,48 +1,38 @@ 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.ViewGroup -import android.view.ViewGroup.LayoutParams -import android.widget.Button - -import android.view.inputmethod.InputMethodManager -import android.widget.EditText - +import android.widget.FrameLayout import android.widget.ImageView import android.widget.TextView -import android.widget.Toast import androidx.appcompat.app.AppCompatActivity import androidx.constraintlayout.widget.ConstraintLayout import androidx.core.content.ContextCompat import androidx.core.view.isGone import androidx.core.view.isVisible +import androidx.fragment.app.FragmentTransaction import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView -import com.auth0.android.jwt.JWT import com.example.brzodolokacije.Adapters.CommentsAdapter import com.example.brzodolokacije.Adapters.PostImageAdapter -import com.example.brzodolokacije.Models.* +import com.example.brzodolokacije.Fragments.FragmentSinglePostComments +import com.example.brzodolokacije.Fragments.FragmentSinglePostDescription +import com.example.brzodolokacije.Models.CommentSend +import com.example.brzodolokacije.Models.PostImage +import com.example.brzodolokacije.Models.PostPreview +import com.example.brzodolokacije.Models.UserReceive import com.example.brzodolokacije.R -import com.example.brzodolokacije.Services.RetrofitHelper -import com.example.brzodolokacije.Services.SharedPreferencesHelper import com.example.brzodolokacije.databinding.ActivitySinglePostBinding -import com.google.android.material.bottomsheet.BottomSheetDialog import com.google.gson.Gson -import kotlinx.android.synthetic.main.activity_single_post.view.* +import kotlinx.android.synthetic.main.fragment_single_post_description.* import org.osmdroid.config.Configuration import org.osmdroid.tileprovider.tilesource.TileSourceFactory import org.osmdroid.util.GeoPoint import org.osmdroid.views.MapView import org.osmdroid.views.overlay.Marker -import retrofit2.Call -import retrofit2.Response class ActivitySinglePost : AppCompatActivity() { @@ -53,22 +43,27 @@ class ActivitySinglePost : AppCompatActivity() { private var adapterComments: RecyclerView.Adapter<CommentsAdapter.ViewHolder>? = null private var recyclerViewImages: RecyclerView?=null private var recyclerViewComments: RecyclerView?=null - private var favouriteImage:ImageView?=null - public lateinit var post:PostPreview + private var favouriteImage: ImageView?=null + public lateinit var post: PostPreview + + private var comments:MutableList<CommentSend>?=mutableListOf() private var starNumber:Number=0 - private lateinit var userData:UserReceive - private lateinit var user:TextView - private lateinit var linearLayout2:ConstraintLayout + private lateinit var userData: UserReceive + private lateinit var user: TextView + private lateinit var linearLayout2: ConstraintLayout private lateinit var btnChangeHeightUp:ImageView private lateinit var btnChangeHeightDown:ImageView - + private lateinit var fragmentContainer: FrameLayout override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) binding=ActivitySinglePostBinding.inflate(layoutInflater) setContentView(binding.root) + //get post -------------------------------- post= intent.extras?.getParcelable("selectedPost")!! + + btnChangeHeightUp=findViewById(R.id.activitySinglePostChangeHeightUp) btnChangeHeightDown=findViewById(R.id.activitySinglePostChangeHeightDown) @@ -90,7 +85,11 @@ class ActivitySinglePost : AppCompatActivity() { adapterImages= PostImageAdapter(this@ActivitySinglePost, post.images as MutableList<PostImage>) layoutManagerImages= LinearLayoutManager(this,LinearLayoutManager.HORIZONTAL,false) recyclerViewImages = binding.rvMain + + + loadTextComponents() /* + buildRecyclerViewComments() requestGetComments() favouriteImage=binding.ivFavourite @@ -98,7 +97,7 @@ class ActivitySinglePost : AppCompatActivity() { recyclerViewImages?.setHasFixedSize(true) recyclerViewImages?.layoutManager = layoutManagerImages recyclerViewImages?.adapter = adapterImages - loadTextComponents() + setRatingListeners() translateOwnerIdToName(post.ownerId) loadFavourite() @@ -107,8 +106,8 @@ class ActivitySinglePost : AppCompatActivity() { */ binding.tvUser.setOnClickListener { val intent: Intent = Intent(this@ActivitySinglePost,ActivityUserProfile::class.java) - var b= Bundle() - intent.putExtra("user", Gson().toJson(userData)) + var args= Bundle() + args.putString("post", Gson().toJson(post)) this.startActivity(intent) } binding.tvLocationType.setOnClickListener{ @@ -140,10 +139,32 @@ class ActivitySinglePost : AppCompatActivity() { linearLayout2.getLayoutParams().height= ViewGroup.LayoutParams.WRAP_CONTENT; } - favouriteImage!!.setOnClickListener{ + /*favouriteImage!!.setOnClickListener{ addRemoveFavourite() } +*/ + binding.btnActivitySinglePostDescription.setOnClickListener { + var fm: FragmentTransaction =supportFragmentManager.beginTransaction() + val fragment = FragmentSinglePostDescription() + val b = Bundle() + b.putString("post", Gson().toJson(post)) + fragment.arguments = b + fm.replace(R.id.flSinglePostFragmentContainer, fragment) + fm.commit() + } + binding.btnActivitySinglePostComments.setOnClickListener{ + var fm: FragmentTransaction =supportFragmentManager.beginTransaction() + val fragment = FragmentSinglePostComments() + val b = Bundle() + b.putString("post", Gson().toJson(post)) + fragment.arguments = b + fm.replace(R.id.flSinglePostFragmentContainer, fragment) + fm.commit() + } + + } + /* fun loadFavourite(){ if(post.favourites!=null){ var jwtString=SharedPreferencesHelper.getValue("jwt",this) @@ -178,6 +199,8 @@ class ActivitySinglePost : AppCompatActivity() { } + */ + fun getMap(){ /*val mapDialogue = BottomSheetDialog(this@ActivitySinglePost, android.R.style.Theme_Black_NoTitleBar) mapDialogue.getWindow()?.setBackgroundDrawable(ColorDrawable(Color.argb(100, 0, 0, 0))) @@ -205,211 +228,6 @@ class ActivitySinglePost : AppCompatActivity() { } -/* - fun buildRecyclerViewComments(){ - recyclerViewComments=binding.rvComments - adapterComments=CommentsAdapter(comments as MutableList<CommentSend>,this@ActivitySinglePost) - layoutManagerComments= LinearLayoutManager(this@ActivitySinglePost,LinearLayoutManager.VERTICAL,false) - recyclerViewComments!!.setHasFixedSize(false) - 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 - val fullStar = R.drawable.full_star - /*var starlist: ArrayList<ImageButton> = arrayListOf() - starlist.add(findViewById(R.id.rateStar1) as ImageButton) - starlist.add(findViewById(R.id.rateStar2) as ImageButton) - starlist.add(findViewById(R.id.rateStar3) as ImageButton) - starlist.add(findViewById(R.id.rateStar4) as ImageButton) - starlist.add(findViewById(R.id.rateStar5) as ImageButton) - for (i in 0..4) { - starlist[i].setOnClickListener { - for (j in 1..i) { - starlist[j].setImageResource(fullStar) - } - for (k in i..5) { - starlist[k].setImageResource(emptyStar) - } - starNumber = i+1; - } - }*/ - - binding.rateStar1.setOnClickListener { - //Toast.makeText(this,"kliknuta prva zvezdica",Toast.LENGTH_SHORT).show() - binding.rateStar1.setImageResource(fullStar) - binding.rateStar2.setImageResource(emptyStar) - binding.rateStar3.setImageResource(emptyStar) - binding.rateStar4.setImageResource(emptyStar) - binding.rateStar5.setImageResource(emptyStar) - starNumber=1 - } - binding.rateStar2.setOnClickListener { - //Toast.makeText(this,"kliknuta druga zvezdica",Toast.LENGTH_SHORT).show() - binding.rateStar1.setImageResource(fullStar) - binding.rateStar2.setImageResource(fullStar) - binding.rateStar3.setImageResource(emptyStar) - binding.rateStar4.setImageResource(emptyStar) - binding.rateStar5.setImageResource(emptyStar) - starNumber=2 - } - binding.rateStar3.setOnClickListener { - //Toast.makeText(this,"kliknuta treca zvezdica",Toast.LENGTH_SHORT).show() - binding.rateStar1.setImageResource(fullStar) - binding.rateStar2.setImageResource(fullStar) - binding.rateStar3.setImageResource(fullStar) - binding.rateStar4.setImageResource(emptyStar) - binding.rateStar5.setImageResource(emptyStar) - starNumber=3 - } - binding.rateStar4.setOnClickListener { - //Toast.makeText(this,"kliknuta cetvrta zvezdica",Toast.LENGTH_SHORT).show() - binding.rateStar1.setImageResource(fullStar) - binding.rateStar2.setImageResource(fullStar) - binding.rateStar3.setImageResource(fullStar) - binding.rateStar4.setImageResource(fullStar) - binding.rateStar5.setImageResource(emptyStar) - starNumber=4 - } - binding.rateStar5.setOnClickListener { - //Toast.makeText(this,"kliknuta peta zvezdica",Toast.LENGTH_SHORT).show() - binding.rateStar1.setImageResource(fullStar) - binding.rateStar2.setImageResource(fullStar) - binding.rateStar3.setImageResource(fullStar) - binding.rateStar4.setImageResource(fullStar) - binding.rateStar5.setImageResource(fullStar) - starNumber=5 - } - binding.submitRating.setOnClickListener{ - if(starNumber.toInt()>0){ - val rating= RatingReceive(starNumber.toInt(),post._id) - requestAddRating(rating) - Toast.makeText(this,"poslato",Toast.LENGTH_SHORT).show() - } - } - binding.btnPostComment.setOnClickListener { - if(binding.NewComment.text.isNotEmpty()){ - val comment=CommentReceive(binding.NewComment.text.toString(),"") - requestAddComment(comment) - - - } - else{ - Toast.makeText(this@ActivitySinglePost,"Unesite tekst komentara.",Toast.LENGTH_LONG).show() - } - } - addView() - - } - - fun requestAddComment(comment:CommentReceive){ - val postApi= RetrofitHelper.getInstance() - val token= SharedPreferencesHelper.getValue("jwt", this@ActivitySinglePost) - val request=postApi.addComment("Bearer "+token,post._id,comment) - request.enqueue(object : retrofit2.Callback<CommentSend?> { - override fun onResponse(call: Call<CommentSend?>, response: Response<CommentSend?>) { - if(response.isSuccessful){ - - var newComment=response.body()!! - requestGetComments(newComment) - binding.NewComment.text.clear() - hideKeyboard(binding.NewComment) - }else{ - if(response.errorBody()!=null) - Log.d("main1",response.message().toString()) - } - - - } - - override fun onFailure(call: Call<CommentSend?>, t: Throwable) { - Log.d("main2",t.message.toString()) - } - }) - } - fun requestGetComments(newComment:CommentSend?=null){ - if(newComment==null){ - val postApi= RetrofitHelper.getInstance() - val token= SharedPreferencesHelper.getValue("jwt", this@ActivitySinglePost) - val request=postApi.getComments("Bearer "+token,post._id) - request.enqueue(object : retrofit2.Callback<MutableList<CommentSend>?> { - override fun onResponse(call: Call<MutableList<CommentSend>?>, response: Response<MutableList<CommentSend>?>) { - if(response.isSuccessful){ - comments= response.body()!! - if(comments!=null && comments!!.isNotEmpty()){ - buildRecyclerViewComments() - if(comments!=null) - binding.tvCommentCount.text=countComments(comments!!).toString() - else - binding.tvCommentCount.text="12" - } - }else{ - if(response.errorBody()!=null) - Log.d("main1",response.message().toString()) - } - - - } - - override fun onFailure(call: Call<MutableList<CommentSend>?>, t: Throwable) { - Log.d("main2",t.message.toString()) - } - }) - } - else{ - (adapterComments as CommentsAdapter).items.add(0,newComment) - recyclerViewComments?.adapter=adapterComments - addedComment() - } - } - - fun requestAddRating(rating:RatingReceive){ - val postApi= RetrofitHelper.getInstance() - val token= SharedPreferencesHelper.getValue("jwt", this@ActivitySinglePost) - val request=postApi.addRating("Bearer "+token,post._id,rating) - request.enqueue(object : retrofit2.Callback<RatingData?> { - override fun onResponse(call: Call<RatingData?>, response: Response<RatingData?>) { - if(response.isSuccessful){ - var data=response.body()!! - binding.tvRating.text=String.format("%.2f",data.ratings) - binding.tvNumberOfRatings.text=String.format("%d",data.ratingscount) - Log.d("--------------",data.ratings.toString()+" "+data.ratingscount.toString()) - when(data.myrating){ - 1->binding.rateStar1.performClick() - 2->binding.rateStar2.performClick() - 3->binding.rateStar3.performClick() - 4->binding.rateStar4.performClick() - 5->binding.rateStar5.performClick() - else->{ - val emptyStar = R.drawable.empty_star - binding.rateStar1.setImageResource(emptyStar) - binding.rateStar2.setImageResource(emptyStar) - binding.rateStar3.setImageResource(emptyStar) - binding.rateStar4.setImageResource(emptyStar) - binding.rateStar5.setImageResource(emptyStar) - } - } - /*Toast.makeText( - this@ActivitySinglePost, "prosao zahtev", Toast.LENGTH_LONG - ).show()*/ - }else{ - if(response.errorBody()!=null) - Log.d("main1",response.errorBody().toString()) - } - - - } - - override fun onFailure(call: Call<RatingData?>, t: Throwable) { - Log.d("main2",t.message.toString()) - } - }) - } private fun loadTextComponents() { binding.apply { @@ -430,6 +248,7 @@ class ActivitySinglePost : AppCompatActivity() { } } + /* fun addView() { var token= SharedPreferencesHelper.getValue("jwt", this).toString() val Api= RetrofitHelper.getInstance() @@ -466,20 +285,6 @@ class ActivitySinglePost : AppCompatActivity() { } }) } - fun countComments(comments:List<CommentSend>):Int{ - var count:Int=0 - for(c in comments){ - if(c.replies!=null) - count=count+countComments(c.replies!!) - count=count+1 - } - return count - } - - public fun addedComment(){ - binding.tvCommentCount.text=(Integer.parseInt(binding.tvCommentCount.text.toString())+1).toString() - binding.tvCommentCount.invalidate() - } - */ +*/ } diff --git a/Client/BrzoDoLokacije/app/src/main/java/com/example/brzodolokacije/Activities/ActivityUserProfile.kt b/Client/BrzoDoLokacije/app/src/main/java/com/example/brzodolokacije/Activities/ActivityUserProfile.kt index d0b86cb..85e342c 100644 --- a/Client/BrzoDoLokacije/app/src/main/java/com/example/brzodolokacije/Activities/ActivityUserProfile.kt +++ b/Client/BrzoDoLokacije/app/src/main/java/com/example/brzodolokacije/Activities/ActivityUserProfile.kt @@ -141,26 +141,27 @@ class ActivityUserProfile : AppCompatActivity() { } }) } - showFollowers.setOnClickListener { - val bundle = Bundle() - bundle.putString("userId", userObject._id.toString()) - bundle.putString("show","followers") - bundle.putString("showMy","no") - val intent = Intent(this@ActivityUserProfile,ActivityShowFollowersAndFollowing::class.java) - intent.putExtras(bundle) - startActivity(intent) - } + showFollowers.setOnClickListener { + val bundle = Bundle() + bundle.putString("userId", userObject._id.toString()) + bundle.putString("show","followers") + bundle.putString("showMy","no") + val intent = Intent(this@ActivityUserProfile,ActivityShowFollowersAndFollowing::class.java) + intent.putExtras(bundle) + startActivity(intent) - showFollowing.setOnClickListener { - val bundle = Bundle() - bundle.putString("userId", userObject._id.toString()) - bundle.putString("show","following") - bundle.putString("showMy","no") - val intent = Intent(this@ActivityUserProfile,ActivityShowFollowersAndFollowing::class.java) - intent.putExtras(bundle) - startActivity(intent) - } + } + + showFollowing.setOnClickListener { + val bundle = Bundle() + bundle.putString("userId", userObject._id.toString()) + bundle.putString("show","following") + bundle.putString("showMy","no") + val intent = Intent(this@ActivityUserProfile,ActivityShowFollowersAndFollowing::class.java) + intent.putExtras(bundle) + startActivity(intent) + } diff --git a/Client/BrzoDoLokacije/app/src/main/java/com/example/brzodolokacije/Fragments/FragmentSinglePostComments.kt b/Client/BrzoDoLokacije/app/src/main/java/com/example/brzodolokacije/Fragments/FragmentSinglePostComments.kt new file mode 100644 index 0000000..43c1967 --- /dev/null +++ b/Client/BrzoDoLokacije/app/src/main/java/com/example/brzodolokacije/Fragments/FragmentSinglePostComments.kt @@ -0,0 +1,153 @@ +package com.example.brzodolokacije.Fragments + +import android.content.Context +import android.os.Bundle +import android.util.Log +import androidx.fragment.app.Fragment +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.view.inputmethod.InputMethodManager +import android.widget.EditText +import android.widget.ImageView +import android.widget.TextView +import androidx.recyclerview.widget.LinearLayoutManager +import androidx.recyclerview.widget.RecyclerView +import com.example.brzodolokacije.Adapters.CommentsAdapter +import com.example.brzodolokacije.Adapters.PostImageAdapter +import com.example.brzodolokacije.Models.CommentReceive +import com.example.brzodolokacije.Models.CommentSend +import com.example.brzodolokacije.Models.PostPreview +import com.example.brzodolokacije.R +import com.example.brzodolokacije.Services.RetrofitHelper +import com.example.brzodolokacije.Services.SharedPreferencesHelper +import com.google.android.material.internal.ViewUtils.hideKeyboard +import com.google.gson.Gson +import org.w3c.dom.Text +import retrofit2.Call +import retrofit2.Response + +class FragmentSinglePostComments : Fragment() { + + private lateinit var commentsContainer:RecyclerView + private lateinit var commentsCount: TextView + private lateinit var newComment: EditText + private lateinit var postComment: ImageView + private lateinit var post:PostPreview + + private var layoutManagerComments: RecyclerView.LayoutManager? = null + private var adapterComments: RecyclerView.Adapter<CommentsAdapter.ViewHolder>? = null + private var recyclerViewComments: RecyclerView?=null + private var comments:MutableList<CommentSend>?=mutableListOf() + + override fun onCreateView( + inflater: LayoutInflater, container: ViewGroup?, + savedInstanceState: Bundle? + ): View? { + // Inflate the layout for this fragment + var view= inflater.inflate(R.layout.fragment_single_post_comments, container, false) + + var args = arguments + var jsonPostObject = args!!.getString("post") + post= Gson().fromJson(jsonPostObject, PostPreview::class.java) + + commentsContainer=view.findViewById(R.id.rvComments) + commentsCount=view.findViewById(R.id.tvCommentCount) + newComment=view.findViewById(R.id.NewComment) + postComment=view.findViewById(R.id.btnPostComment) + + + return view + } + + fun requestAddComment(comment: CommentReceive){ + val postApi= RetrofitHelper.getInstance() + val token= SharedPreferencesHelper.getValue("jwt", requireActivity()) + val request=postApi.addComment("Bearer "+token,post._id,comment) + request.enqueue(object : retrofit2.Callback<CommentSend?> { + override fun onResponse(call: Call<CommentSend?>, response: Response<CommentSend?>) { + if(response.isSuccessful){ + + var newComment=response.body()!! + requestGetComments(newComment) + //newComment.text.clear() + //hideKeyboard(newComment) + + }else{ + if(response.errorBody()!=null) + Log.d("main1",response.message().toString()) + } + + + } + + override fun onFailure(call: Call<CommentSend?>, t: Throwable) { + Log.d("main2",t.message.toString()) + } + }) + } + fun requestGetComments(newComment:CommentSend?=null){ + if(newComment==null){ + val postApi= RetrofitHelper.getInstance() + val token= SharedPreferencesHelper.getValue("jwt", requireActivity()) + val request=postApi.getComments("Bearer "+token,post._id) + request.enqueue(object : retrofit2.Callback<MutableList<CommentSend>?> { + override fun onResponse(call: Call<MutableList<CommentSend>?>, response: Response<MutableList<CommentSend>?>) { + if(response.isSuccessful){ + comments= response.body()!! + if(comments!=null && comments!!.isNotEmpty()){ + buildRecyclerViewComments() + if(comments!=null) + commentsCount.text=countComments(comments!!).toString() + else + commentsCount.text="12" + } + }else{ + if(response.errorBody()!=null) + Log.d("main1",response.message().toString()) + } + + + } + + override fun onFailure(call: Call<MutableList<CommentSend>?>, t: Throwable) { + Log.d("main2",t.message.toString()) + } + }) + } + else{ + (adapterComments as CommentsAdapter).items.add(0,newComment) + recyclerViewComments?.adapter=adapterComments + addedComment() + } + } + + fun buildRecyclerViewComments(){ + recyclerViewComments=commentsContainer + adapterComments=CommentsAdapter(comments as MutableList<CommentSend>,requireActivity()) + layoutManagerComments= LinearLayoutManager(requireActivity(),LinearLayoutManager.VERTICAL,false) + recyclerViewComments!!.setHasFixedSize(false) + 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 countComments(comments:List<CommentSend>):Int{ + var count:Int=0 + for(c in comments){ + if(c.replies!=null) + count=count+countComments(c.replies!!) + count=count+1 + } + return count + } + + public fun addedComment(){ + commentsCount.text=(Integer.parseInt(commentsCount.text.toString())+1).toString() + commentsCount.invalidate() + } + +} diff --git a/Client/BrzoDoLokacije/app/src/main/java/com/example/brzodolokacije/Fragments/FragmentSinglePostDescription.kt b/Client/BrzoDoLokacije/app/src/main/java/com/example/brzodolokacije/Fragments/FragmentSinglePostDescription.kt index 1a7e7da..63e7b6a 100644 --- a/Client/BrzoDoLokacije/app/src/main/java/com/example/brzodolokacije/Fragments/FragmentSinglePostDescription.kt +++ b/Client/BrzoDoLokacije/app/src/main/java/com/example/brzodolokacije/Fragments/FragmentSinglePostDescription.kt @@ -1,60 +1,169 @@ package com.example.brzodolokacije.Fragments import android.os.Bundle -import androidx.fragment.app.Fragment +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 android.widget.Toast +import androidx.fragment.app.Fragment +import com.example.brzodolokacije.Models.* import com.example.brzodolokacije.R +import com.example.brzodolokacije.Services.RetrofitHelper +import com.example.brzodolokacije.Services.SharedPreferencesHelper +import com.google.gson.Gson +import org.w3c.dom.Text +import retrofit2.Call +import retrofit2.Response -// TODO: Rename parameter arguments, choose names that match -// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER -private const val ARG_PARAM1 = "param1" -private const val ARG_PARAM2 = "param2" -/** - * A simple [Fragment] subclass. - * Use the [FragmentSinglePostDescription.newInstance] factory method to - * create an instance of this fragment. - */ class FragmentSinglePostDescription : Fragment() { - // TODO: Rename and change types of parameters - private var param1: String? = null - private var param2: String? = null - - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) - arguments?.let { - param1 = it.getString(ARG_PARAM1) - param2 = it.getString(ARG_PARAM2) - } - } + + private lateinit var descriptionContainer:TextView + private lateinit var star1:ImageView + private lateinit var star2:ImageView + private lateinit var star3:ImageView + private lateinit var star4:ImageView + private lateinit var star5:ImageView + private var starNumber:Number=0 + private lateinit var post:PostPreview override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? ): View? { - // Inflate the layout for this fragment - return inflater.inflate(R.layout.fragment_single_post_description, container, false) + + var view=inflater.inflate(R.layout.fragment_single_post_description, container, false) + + //uzmi post prosledjen iz single post + var args = arguments + var jsonPostObject = args!!.getString("post") + post= Gson().fromJson(jsonPostObject, PostPreview::class.java) + + //setuj opis + descriptionContainer=view.findViewById(R.id.tvDescription) + descriptionContainer.text=post.description.toString() + + //setuj zvezdice + star1=view.findViewById(R.id.rateStar1) + star2=view.findViewById(R.id.rateStar2) + star3=view.findViewById(R.id.rateStar3) + star4=view.findViewById(R.id.rateStar4) + star5=view.findViewById(R.id.rateStar5) + + fun setRatingListeners() { + val emptyStar = R.drawable.ic_round_star_outline_24 + val fullStar = R.drawable.ic_baseline_star_rate_24 + + star1.setOnClickListener { + //Toast.makeText(this,"kliknuta prva zvezdica",Toast.LENGTH_SHORT).show() + star1.setImageResource(fullStar) + star2.setImageResource(emptyStar) + star3.setImageResource(emptyStar) + star4.setImageResource(emptyStar) + star5.setImageResource(emptyStar) + starNumber=1 + rate(starNumber) + } + star1.setOnClickListener { + //Toast.makeText(this,"kliknuta druga zvezdica",Toast.LENGTH_SHORT).show() + star1.setImageResource(fullStar) + star2.setImageResource(fullStar) + star3.setImageResource(emptyStar) + star4.setImageResource(emptyStar) + star5.setImageResource(emptyStar) + starNumber=2 + rate(starNumber) + } + star1.setOnClickListener { + //Toast.makeText(this,"kliknuta treca zvezdica",Toast.LENGTH_SHORT).show() + star1.setImageResource(fullStar) + star2.setImageResource(fullStar) + star3.setImageResource(fullStar) + star4.setImageResource(emptyStar) + star5.setImageResource(emptyStar) + starNumber=3 + rate(starNumber) + } + star1.setOnClickListener { + Toast.makeText(requireActivity(),"kliknuta cetvrta zvezdica",Toast.LENGTH_SHORT).show() + star1.setImageResource(fullStar) + star2.setImageResource(fullStar) + star3.setImageResource(fullStar) + star4.setImageResource(fullStar) + star5.setImageResource(emptyStar) + starNumber=4 + rate(starNumber) + } + star1.setOnClickListener { + //Toast.makeText(this,"kliknuta peta zvezdica",Toast.LENGTH_SHORT).show() + star1.setImageResource(fullStar) + star2.setImageResource(fullStar) + star3.setImageResource(fullStar) + star4.setImageResource(fullStar) + star5.setImageResource(fullStar) + starNumber=5 + rate(starNumber) + } + + + } + + return view } - companion object { - /** - * Use this factory method to create a new instance of - * this fragment using the provided parameters. - * - * @param param1 Parameter 1. - * @param param2 Parameter 2. - * @return A new instance of fragment FragmentSinglePostDescription. - */ - // TODO: Rename and change types and number of parameters - @JvmStatic - fun newInstance(param1: String, param2: String) = - FragmentSinglePostDescription().apply { - arguments = Bundle().apply { - putString(ARG_PARAM1, param1) - putString(ARG_PARAM2, param2) + fun rate(starNumber:Number){ + if(starNumber.toInt()>0){ + val rating= RatingReceive(starNumber.toInt(),post._id) + requestAddRating(rating) + } + } + + fun requestAddRating(rating:RatingReceive) { + val postApi = RetrofitHelper.getInstance() + val token = SharedPreferencesHelper.getValue("jwt", requireActivity()) + val request = postApi.addRating("Bearer " + token, post._id, rating) + request.enqueue(object : retrofit2.Callback<RatingData?> { + override fun onResponse(call: Call<RatingData?>, response: Response<RatingData?>) { + if (response.isSuccessful) { + var data = response.body()!! + //binding.tvRating.text=String.format("%.2f",data.ratings) + //binding.tvNumberOfRatings.text=String.format("%d",data.ratingscount) + Log.d( + "--------------", + data.ratings.toString() + " " + data.ratingscount.toString() + ) + when (data.myrating) { + 1 -> star1.performClick() + 2 -> star1.performClick() + 3 -> star3.performClick() + 4 -> star4.performClick() + 5 -> star5.performClick() + else -> { + val emptyStar = R.drawable.empty_star + star1.setImageResource(emptyStar) + star2.setImageResource(emptyStar) + star3.setImageResource(emptyStar) + star4.setImageResource(emptyStar) + star5.setImageResource(emptyStar) + } + } + /*Toast.makeText( + this@ActivitySinglePost, "prosao zahtev", Toast.LENGTH_LONG + ).show()*/ + } else { + if (response.errorBody() != null) + Log.d("main1", response.errorBody().toString()) } + + + } + + override fun onFailure(call: Call<RatingData?>, t: Throwable) { + Log.d("main2", t.message.toString()) } + }) } }
\ No newline at end of file diff --git a/Client/BrzoDoLokacije/app/src/main/res/drawable/ic_baseline_send_24.xml b/Client/BrzoDoLokacije/app/src/main/res/drawable/ic_baseline_send_24.xml new file mode 100644 index 0000000..bcba56a --- /dev/null +++ b/Client/BrzoDoLokacije/app/src/main/res/drawable/ic_baseline_send_24.xml @@ -0,0 +1,5 @@ +<vector android:autoMirrored="true" android:height="24dp" + android:tint="#747474" android:viewportHeight="24" + android:viewportWidth="24" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android"> + <path android:fillColor="@android:color/white" android:pathData="M2.01,21L23,12 2.01,3 2,10l15,2 -15,2z"/> +</vector> 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 744a2a2..108e1cf 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 @@ -23,12 +23,13 @@ <androidx.constraintlayout.widget.ConstraintLayout android:id="@+id/linearLayout2" - android:layout_width="408dp" - android:layout_height="723dp" - android:layout_marginBottom="8dp" + android:layout_width="match_parent" + android:layout_height="match_parent" android:background="@drawable/view_top_corner_radius" android:elevation="30dp" - android:padding="16dp" + android:paddingBottom="0dp" + android:paddingTop="16dp" + android:paddingHorizontal="16dp" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="0.0" @@ -37,13 +38,13 @@ <TextView android:id="@+id/tvTitle" + style="@style/title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="24dp" android:gravity="top|start" android:padding="@dimen/text_padding" android:text="Naslov" - style="@style/title" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" /> @@ -142,9 +143,11 @@ app:layout_constraintTop_toBottomOf="@+id/tvUser" /> <androidx.constraintlayout.widget.ConstraintLayout + android:id="@+id/singlePostDetail" android:layout_width="match_parent" - android:layout_height="400dp" + android:layout_height="0dp" android:layout_marginTop="8dp" + app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/MapDialogueMapView"> @@ -160,7 +163,6 @@ android:stateListAnimator="@null" android:text="opis" android:textColor="@color/cardview_dark_background" - app:layout_constraintBottom_toTopOf="@+id/flFragmentProfileFragmentContainer" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" /> @@ -175,14 +177,14 @@ android:stateListAnimator="@null" android:text="Komentari" android:textColor="@color/cardview_dark_background" - app:layout_constraintBottom_toTopOf="@+id/flFragmentProfileFragmentContainer" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintTop_toTopOf="parent" /> <FrameLayout - android:id="@+id/flFragmentProfileFragmentContainer" - android:layout_width="409dp" - android:layout_height="330dp" + android:id="@+id/flSinglePostFragmentContainer" + android:layout_width="match_parent" + android:layout_height="0dp" + android:paddingHorizontal="16dp" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" @@ -191,4 +193,4 @@ </androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout> - </androidx.constraintlayout.widget.ConstraintLayout> +</androidx.constraintlayout.widget.ConstraintLayout> diff --git a/Client/BrzoDoLokacije/app/src/main/res/layout/fragment_single_post_comments.xml b/Client/BrzoDoLokacije/app/src/main/res/layout/fragment_single_post_comments.xml index cb5db29..bd4d760 100644 --- a/Client/BrzoDoLokacije/app/src/main/res/layout/fragment_single_post_comments.xml +++ b/Client/BrzoDoLokacije/app/src/main/res/layout/fragment_single_post_comments.xml @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="utf-8"?> -<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" +<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:orientation="vertical" @@ -8,18 +8,20 @@ tools:context=".FragmentSinglePostComments"> <androidx.constraintlayout.widget.ConstraintLayout + android:id="@+id/constraintLayout" android:layout_width="match_parent" - android:layout_height="wrap_content"> + android:layout_height="wrap_content" + app:layout_constraintTop_toTopOf="parent"> <TextView android:id="@+id/tvCommentLabel" + style="@style/title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="@dimen/text_padding" android:text="Komentari" android:textStyle="bold" - style="@style/title" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" /> @@ -44,7 +46,7 @@ android:nestedScrollingEnabled="false" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" - tools:layout_editor_absoluteY="282dp"> + app:layout_constraintTop_toBottomOf="@+id/constraintLayout"> </androidx.recyclerview.widget.RecyclerView> @@ -52,7 +54,8 @@ android:id="@+id/postCommentLayout" android:layout_width="match_parent" android:layout_height="wrap_content" - android:orientation="horizontal"> + android:orientation="horizontal" + app:layout_constraintBottom_toBottomOf="parent"> <EditText android:id="@+id/NewComment" @@ -61,14 +64,14 @@ android:layout_weight="1" android:hint="Unesite komentar ovde" /> - <ImageButton + <ImageView android:id="@+id/btnPostComment" - android:layout_width="50dp" - android:layout_height="50dp" + android:layout_width="30dp" + android:layout_height="30dp" android:backgroundTint="@color/white" android:scaleType="fitCenter" - android:src="@drawable/post_comment" /> + android:src="@drawable/ic_baseline_send_24" /> </LinearLayout> -</LinearLayout>
\ No newline at end of file +</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file diff --git a/Client/BrzoDoLokacije/app/src/main/res/layout/fragment_single_post_description.xml b/Client/BrzoDoLokacije/app/src/main/res/layout/fragment_single_post_description.xml index c2ad49b..e2973ca 100644 --- a/Client/BrzoDoLokacije/app/src/main/res/layout/fragment_single_post_description.xml +++ b/Client/BrzoDoLokacije/app/src/main/res/layout/fragment_single_post_description.xml @@ -18,7 +18,8 @@ android:id="@+id/tvDescriptionLabel" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_marginStart="8dp" + android:layout_marginStart="16dp" + android:layout_marginTop="16dp" android:layout_marginEnd="362dp" android:gravity="top|start" android:padding="@dimen/text_padding" |