From 4c6172aa80d5b8a8d12f45d1d91ce4e778d9412a Mon Sep 17 00:00:00 2001 From: TAMARA JERINIC Date: Mon, 21 Nov 2022 23:53:25 +0100 Subject: Dodato praćenje korisnika na back-u. Dodati fragmenti za praćenje korisnika na front-u. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../.idea/deploymentTargetDropDown.xml | 4 +- .../brzodolokacije/Adapters/FollowersAdapter.kt | 4 ++ .../brzodolokacije/Fragments/FragmentFollowers.kt | 69 ++++++++++++++++++++++ .../Fragments/FragmentHomePageMainScroll.kt | 3 - .../brzodolokacije/Fragments/FragmentProfile.kt | 56 +++++++++++++----- .../Fragments/FragmentUserProfile.kt | 40 +------------ .../brzodolokacije/Interfaces/IBackendApi.kt | 10 ++++ .../java/com/example/brzodolokacije/Models/User.kt | 12 +++- .../app/src/main/res/layout/fragment_followers.xml | 26 ++++++++ .../app/src/main/res/layout/fragment_profile.xml | 1 + 10 files changed, 162 insertions(+), 63 deletions(-) create mode 100644 Client/BrzoDoLokacije/app/src/main/java/com/example/brzodolokacije/Adapters/FollowersAdapter.kt create mode 100644 Client/BrzoDoLokacije/app/src/main/java/com/example/brzodolokacije/Fragments/FragmentFollowers.kt create mode 100644 Client/BrzoDoLokacije/app/src/main/res/layout/fragment_followers.xml (limited to 'Client') diff --git a/Client/BrzoDoLokacije/.idea/deploymentTargetDropDown.xml b/Client/BrzoDoLokacije/.idea/deploymentTargetDropDown.xml index d34d986..6fac072 100644 --- a/Client/BrzoDoLokacije/.idea/deploymentTargetDropDown.xml +++ b/Client/BrzoDoLokacije/.idea/deploymentTargetDropDown.xml @@ -7,11 +7,11 @@ - + - + \ No newline at end of file diff --git a/Client/BrzoDoLokacije/app/src/main/java/com/example/brzodolokacije/Adapters/FollowersAdapter.kt b/Client/BrzoDoLokacije/app/src/main/java/com/example/brzodolokacije/Adapters/FollowersAdapter.kt new file mode 100644 index 0000000..117a2c2 --- /dev/null +++ b/Client/BrzoDoLokacije/app/src/main/java/com/example/brzodolokacije/Adapters/FollowersAdapter.kt @@ -0,0 +1,4 @@ +package com.example.brzodolokacije.Adapters + +class FollowersAdapter { +} \ No newline at end of file diff --git a/Client/BrzoDoLokacije/app/src/main/java/com/example/brzodolokacije/Fragments/FragmentFollowers.kt b/Client/BrzoDoLokacije/app/src/main/java/com/example/brzodolokacije/Fragments/FragmentFollowers.kt new file mode 100644 index 0000000..da480f1 --- /dev/null +++ b/Client/BrzoDoLokacije/app/src/main/java/com/example/brzodolokacije/Fragments/FragmentFollowers.kt @@ -0,0 +1,69 @@ +package com.example.brzodolokacije.Fragments + +import android.os.Bundle +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.Toast +import androidx.fragment.app.Fragment +import com.example.brzodolokacije.Interfaces.IBackendApi +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 retrofit2.Call +import retrofit2.Callback +import retrofit2.Response +import retrofit2.Retrofit +import retrofit2.converter.gson.GsonConverterFactory + +class FragmentFollowers : Fragment() { + private lateinit var userId:String + private lateinit var followers: MutableList + override fun onCreateView( + inflater: LayoutInflater, container: ViewGroup?, + savedInstanceState: Bundle? + ): View? { + val view= inflater.inflate(R.layout.fragment_followers, container, false) + + val bundle = this.arguments + + if (bundle != null) { + userId= bundle.getString("userId").toString() + Toast.makeText( + activity, bundle.getString("userId"), Toast.LENGTH_LONG + ).show(); + } + + getPosts() + + return view + } + + fun getPosts(){ + val api = RetrofitHelper.getInstance() + val data=api.getFollowers(userId) + + + data.enqueue(object : Callback> { + override fun onResponse( + call: Call>, + response: Response> + ) { + if (response.body() == null) { + return + } + + followers = response.body()!!.toMutableList() + + } + + override fun onFailure(call: Call>, t: Throwable) { + Toast.makeText( + activity,"nema objava", Toast.LENGTH_LONG + ).show(); + } + }) + } +} \ No newline at end of file diff --git a/Client/BrzoDoLokacije/app/src/main/java/com/example/brzodolokacije/Fragments/FragmentHomePageMainScroll.kt b/Client/BrzoDoLokacije/app/src/main/java/com/example/brzodolokacije/Fragments/FragmentHomePageMainScroll.kt index bde4dd2..cf811df 100644 --- a/Client/BrzoDoLokacije/app/src/main/java/com/example/brzodolokacije/Fragments/FragmentHomePageMainScroll.kt +++ b/Client/BrzoDoLokacije/app/src/main/java/com/example/brzodolokacije/Fragments/FragmentHomePageMainScroll.kt @@ -77,9 +77,6 @@ class FragmentHomePageMainScroll : Fragment() { var fragment=FragmentShowPostsByLocation() location_spa.setOnClickListener { - Toast.makeText( - activity, "BANJAAAAAAAAAAAAAAA", Toast.LENGTH_LONG - ).show(); filter=LocationType.BANJA filterString=filter.toString() bundle.putString("data",filterString) diff --git a/Client/BrzoDoLokacije/app/src/main/java/com/example/brzodolokacije/Fragments/FragmentProfile.kt b/Client/BrzoDoLokacije/app/src/main/java/com/example/brzodolokacije/Fragments/FragmentProfile.kt index a792598..03cb4fa 100644 --- a/Client/BrzoDoLokacije/app/src/main/java/com/example/brzodolokacije/Fragments/FragmentProfile.kt +++ b/Client/BrzoDoLokacije/app/src/main/java/com/example/brzodolokacije/Fragments/FragmentProfile.kt @@ -1,5 +1,6 @@ package com.example.brzodolokacije.Fragments + import android.content.Intent import android.net.Uri import android.os.Bundle @@ -19,7 +20,6 @@ import com.example.brzodolokacije.R import com.example.brzodolokacije.Services.RetrofitHelper import com.example.brzodolokacije.Services.SharedPreferencesHelper import com.google.android.material.button.MaterialButton -import com.google.android.material.imageview.ShapeableImageView import okhttp3.MediaType.Companion.toMediaTypeOrNull import okhttp3.MultipartBody import okhttp3.RequestBody @@ -28,6 +28,7 @@ import retrofit2.Call import retrofit2.Response import java.io.File + // TODO: Rename parameter arguments, choose names that match // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER private const val ARG_PARAM1 = "param1" @@ -38,7 +39,7 @@ private const val ARG_PARAM2 = "param2" * Use the [FragmentProfile.newInstance] factory method to * create an instance of this fragment. */ -class FragmentProfile : Fragment(R.layout.fragment_profile) { +class FragmentProfile : Fragment(com.example.brzodolokacije.R.layout.fragment_profile) { // TODO: Rename and change types of parameters private lateinit var username: TextView private lateinit var name: TextView @@ -55,22 +56,31 @@ class FragmentProfile : Fragment(R.layout.fragment_profile) { private lateinit var showMyRecensions: Button private lateinit var profilePicture: ImageView private lateinit var profilePicturePlus: MaterialButton + private lateinit var showFollowers: TextView + + var userId:String = "1" + + override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? ): View? { + Toast.makeText( + activity, "MOJ PROFILLLLLLLLLLLLLLL", Toast.LENGTH_LONG + ).show(); // Inflate the layout for this fragment - val view:View= inflater.inflate(R.layout.fragment_profile, container, false) - name = view.findViewById(R.id.tvFragmentProfileName) as TextView - username = view.findViewById(R.id.tvFragmentProfileUserName) as TextView - postsCount = view.findViewById(R.id.tvFragmentProfilePostsNo) as TextView - followersCount = view.findViewById(R.id.tvFragmentProfileFollowersNo) as TextView - followingCount = view.findViewById(R.id.tvFragmentProfileFollowNo) as TextView - showMyPosts=view.findViewById(R.id.btnFragmentProfileShowMyPosts) as Button - showMyData=view.findViewById(R.id.btnFragmentProfileShowMyData) as Button - showMyRecensions=view.findViewById(R.id.btnFragmentProfileShowMyRecensions) as Button - profilePicture=view.findViewById(R.id.tvFragmentProfileProfilePicture) as ImageView - profilePicturePlus=view.findViewById(R.id.btnFragmentProfileProfilePicturePlus) as MaterialButton + val view:View= inflater.inflate(com.example.brzodolokacije.R.layout.fragment_profile, container, false) + name = view.findViewById(com.example.brzodolokacije.R.id.tvFragmentProfileName) as TextView + username = view.findViewById(com.example.brzodolokacije.R.id.tvFragmentProfileUserName) as TextView + postsCount = view.findViewById(com.example.brzodolokacije.R.id.tvFragmentProfilePostsNo) as TextView + followersCount = view.findViewById(com.example.brzodolokacije.R.id.tvFragmentProfileFollowersNo) as TextView + followingCount = view.findViewById(com.example.brzodolokacije.R.id.tvFragmentProfileFollowNo) as TextView + showMyPosts=view.findViewById(com.example.brzodolokacije.R.id.btnFragmentProfileShowMyPosts) as Button + showMyData=view.findViewById(com.example.brzodolokacije.R.id.btnFragmentProfileShowMyData) as Button + showMyRecensions=view.findViewById(com.example.brzodolokacije.R.id.btnFragmentProfileShowMyRecensions) as Button + profilePicture=view.findViewById(com.example.brzodolokacije.R.id.tvFragmentProfileProfilePicture) as ImageView + profilePicturePlus=view.findViewById(com.example.brzodolokacije.R.id.btnFragmentProfileProfilePicturePlus) as MaterialButton + showFollowers=view.findViewById(com.example.brzodolokacije.R.id.tvFragmentProfileFollowers) //podaci iz baze @@ -85,7 +95,7 @@ class FragmentProfile : Fragment(R.layout.fragment_profile) { var fm: FragmentTransaction =childFragmentManager.beginTransaction() - fm.replace(R.id.flFragmentProfileFragmentContainer, FragmentMyProfileInfo()) + fm.replace(com.example.brzodolokacije.R.id.flFragmentProfileFragmentContainer, FragmentMyProfileInfo()) fm.commit() } @@ -93,12 +103,24 @@ class FragmentProfile : Fragment(R.layout.fragment_profile) { getProfileInfo() var fm: FragmentTransaction =childFragmentManager.beginTransaction() - fm.replace(R.id.flFragmentProfileFragmentContainer, FragmentMyRecensions()) + fm.replace(com.example.brzodolokacije.R.id.flFragmentProfileFragmentContainer, FragmentMyRecensions()) fm.commit() } profilePicturePlus.setOnClickListener{ addProfilePicture() } + + showFollowers.setOnClickListener { + val bundle = Bundle() + bundle.putString("userId",userId ) // Put anything what you want + val fragmentFollowers = FragmentFollowers() + fragmentFollowers.setArguments(bundle) + + fragmentManager + ?.beginTransaction() + ?.replace(com.example.brzodolokacije.R.id.flNavigationFragment,fragmentFollowers) + ?.commit() + } getProfileInfo() openMyPosts() return view @@ -106,7 +128,7 @@ class FragmentProfile : Fragment(R.layout.fragment_profile) { fun openMyPosts(){ var fm: FragmentTransaction =childFragmentManager.beginTransaction() - fm.replace(R.id.flFragmentProfileFragmentContainer, FragmentUserPosts()) + fm.replace(com.example.brzodolokacije.R.id.flFragmentProfileFragmentContainer, FragmentUserPosts()) fm.commit() } @@ -181,6 +203,8 @@ class FragmentProfile : Fragment(R.layout.fragment_profile) { followersCount.setText("to do") followingCount.setText("to do") + userId=user._id + //Add Profile image if(user.pfp!=null) { Glide.with(requireActivity()) diff --git a/Client/BrzoDoLokacije/app/src/main/java/com/example/brzodolokacije/Fragments/FragmentUserProfile.kt b/Client/BrzoDoLokacije/app/src/main/java/com/example/brzodolokacije/Fragments/FragmentUserProfile.kt index 8ab5276..6b1bac9 100644 --- a/Client/BrzoDoLokacije/app/src/main/java/com/example/brzodolokacije/Fragments/FragmentUserProfile.kt +++ b/Client/BrzoDoLokacije/app/src/main/java/com/example/brzodolokacije/Fragments/FragmentUserProfile.kt @@ -7,28 +7,8 @@ import android.view.View import android.view.ViewGroup import com.example.brzodolokacije.R -// 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 [FragmentUserProfile.newInstance] factory method to - * create an instance of this fragment. - */ class FragmentUserProfile : 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) - } - } override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, @@ -38,23 +18,5 @@ class FragmentUserProfile : Fragment() { return inflater.inflate(R.layout.fragment_user_profile, container, false) } - 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 FragmentUserProfile. - */ - // TODO: Rename and change types and number of parameters - @JvmStatic - fun newInstance(param1: String, param2: String) = - FragmentUserProfile().apply { - arguments = Bundle().apply { - putString(ARG_PARAM1, param1) - putString(ARG_PARAM2, param2) - } - } - } + } \ No newline at end of file diff --git a/Client/BrzoDoLokacije/app/src/main/java/com/example/brzodolokacije/Interfaces/IBackendApi.kt b/Client/BrzoDoLokacije/app/src/main/java/com/example/brzodolokacije/Interfaces/IBackendApi.kt index d8daf14..f7bb9b6 100644 --- a/Client/BrzoDoLokacije/app/src/main/java/com/example/brzodolokacije/Interfaces/IBackendApi.kt +++ b/Client/BrzoDoLokacije/app/src/main/java/com/example/brzodolokacije/Interfaces/IBackendApi.kt @@ -69,4 +69,14 @@ interface IBackendApi { fun getMyHistory(@Header("Authorization") authHeader:String):Call> //@POST("putanja") //fun add(@Body obj:Post,@Header("Authorization") authHeader:String):Call + + @POST("/api/user/{id}/followers") + fun getFollowers(@Path("id") id:String):Call > + + @POST("/api/user{id}/following") + fun getFollowing(@Path("id") id:String):Call > + + @POST("/api/user{id}/addFollower") + fun addFollower(@Header("Authorization") authHeader:String,@Path("id") id:String):Call + } \ No newline at end of file diff --git a/Client/BrzoDoLokacije/app/src/main/java/com/example/brzodolokacije/Models/User.kt b/Client/BrzoDoLokacije/app/src/main/java/com/example/brzodolokacije/Models/User.kt index c726978..46338b3 100644 --- a/Client/BrzoDoLokacije/app/src/main/java/com/example/brzodolokacije/Models/User.kt +++ b/Client/BrzoDoLokacije/app/src/main/java/com/example/brzodolokacije/Models/User.kt @@ -14,9 +14,9 @@ data class User ( //profil var followers:List, - var followersNumber:Int, + var followersCount:Int, var following:List, - var followingNumber:Int, + var followingCount:Int, var postIds:List, var postNumber:Int @@ -28,5 +28,11 @@ data class UserReceive( var email:String, var creationDate: Date, var pfp:PostImage?, - var postcount:Int + var postcount:Int, + var followers:List, + var followersNumber:Int, + var following:List, + var followingNumber:Int, + var postIds:List, + var postNumber:Int ) \ No newline at end of file diff --git a/Client/BrzoDoLokacije/app/src/main/res/layout/fragment_followers.xml b/Client/BrzoDoLokacije/app/src/main/res/layout/fragment_followers.xml new file mode 100644 index 0000000..deef1f8 --- /dev/null +++ b/Client/BrzoDoLokacije/app/src/main/res/layout/fragment_followers.xml @@ -0,0 +1,26 @@ + + + + + + + + + + \ No newline at end of file diff --git a/Client/BrzoDoLokacije/app/src/main/res/layout/fragment_profile.xml b/Client/BrzoDoLokacije/app/src/main/res/layout/fragment_profile.xml index 138d068..ec78de6 100644 --- a/Client/BrzoDoLokacije/app/src/main/res/layout/fragment_profile.xml +++ b/Client/BrzoDoLokacije/app/src/main/res/layout/fragment_profile.xml @@ -151,6 +151,7 @@