diff options
6 files changed, 243 insertions, 12 deletions
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 index 117a2c2..e439d0e 100644 --- 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 @@ -1,4 +1,42 @@ package com.example.brzodolokacije.Adapters -class FollowersAdapter { +import android.app.Activity +import android.util.Log +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.TextView +import androidx.recyclerview.widget.RecyclerView +import com.bumptech.glide.Glide +import com.example.brzodolokacije.Models.PostPreview +import com.example.brzodolokacije.Models.User +import com.example.brzodolokacije.Models.UserReceive +import com.example.brzodolokacije.R +import com.example.brzodolokacije.Services.RetrofitHelper + +class FollowersAdapter (var followers:MutableList<UserReceive>, val activity: Activity): + RecyclerView.Adapter<FollowersAdapter.FollowerViewHolder>() { + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): FollowersAdapter.FollowerViewHolder { + val view= LayoutInflater.from(parent.context).inflate(R.layout.follower_item,parent,false) + return FollowerViewHolder(view) + } + + override fun onBindViewHolder(holder: FollowersAdapter.FollowerViewHolder, position: Int) { + return holder.bindView(followers[position] ) + } + + override fun getItemCount(): Int { + return followers.size + } + + + inner class FollowerViewHolder(view: View): RecyclerView.ViewHolder(view){ + + private val name: TextView =view.findViewById(R.id.tvFollowerItemName) + private val username:TextView=view.findViewById(R.id.tvFolloewItemUsername) + fun bindView(follower: UserReceive){ + name.text=follower.name + username.text=follower.username + } + } }
\ 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 index da480f1..faa5748 100644 --- 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 @@ -6,6 +6,10 @@ import android.view.View import android.view.ViewGroup import android.widget.Toast import androidx.fragment.app.Fragment +import androidx.recyclerview.widget.LinearLayoutManager +import androidx.recyclerview.widget.RecyclerView +import com.example.brzodolokacije.Adapters.FollowersAdapter +import com.example.brzodolokacije.Adapters.ShowPostsHomePageAdapter import com.example.brzodolokacije.Interfaces.IBackendApi import com.example.brzodolokacije.Models.PostPreview import com.example.brzodolokacije.Models.UserReceive @@ -21,14 +25,16 @@ import retrofit2.converter.gson.GsonConverterFactory class FragmentFollowers : Fragment() { private lateinit var userId:String private lateinit var followers: MutableList<UserReceive> + private lateinit var followersRv:RecyclerView override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? ): View? { val view= inflater.inflate(R.layout.fragment_followers, container, false) - val bundle = this.arguments + followersRv=view.findViewById(R.id.rvFragmentShowFollowers) + val bundle = this.arguments if (bundle != null) { userId= bundle.getString("userId").toString() Toast.makeText( @@ -36,17 +42,15 @@ class FragmentFollowers : Fragment() { ).show(); } - getPosts() + getFollowers() return view } - fun getPosts(){ + fun getFollowers(){ val api = RetrofitHelper.getInstance() val data=api.getFollowers(userId) - - - data.enqueue(object : Callback<MutableList<UserReceive>> { + data.enqueue(object : Callback<MutableList<UserReceive>> { override fun onResponse( call: Call<MutableList<UserReceive>>, response: Response<MutableList<UserReceive>> @@ -54,14 +58,16 @@ class FragmentFollowers : Fragment() { if (response.body() == null) { return } - followers = response.body()!!.toMutableList<UserReceive>() + followersRv.apply { + layoutManager= LinearLayoutManager(activity, LinearLayoutManager.HORIZONTAL,false) + adapter= FollowersAdapter(followers,requireActivity()) + } } - override fun onFailure(call: Call<MutableList<UserReceive>>, t: Throwable) { Toast.makeText( - activity,"nema objava", Toast.LENGTH_LONG + activity,"nema pratilaca", Toast.LENGTH_LONG ).show(); } }) diff --git a/Client/BrzoDoLokacije/app/src/main/java/com/example/brzodolokacije/Fragments/FragmentFollowing.kt b/Client/BrzoDoLokacije/app/src/main/java/com/example/brzodolokacije/Fragments/FragmentFollowing.kt new file mode 100644 index 0000000..7fc56db --- /dev/null +++ b/Client/BrzoDoLokacije/app/src/main/java/com/example/brzodolokacije/Fragments/FragmentFollowing.kt @@ -0,0 +1,69 @@ +package com.example.brzodolokacije.Fragments + +import android.os.Bundle +import androidx.fragment.app.Fragment +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.Toast +import androidx.recyclerview.widget.LinearLayoutManager +import androidx.recyclerview.widget.RecyclerView +import com.example.brzodolokacije.Adapters.FollowersAdapter +import com.example.brzodolokacije.Models.UserReceive +import com.example.brzodolokacije.R +import com.example.brzodolokacije.Services.RetrofitHelper +import retrofit2.Call +import retrofit2.Callback +import retrofit2.Response + +class FragmentFollowing : Fragment() { + private lateinit var userId:String + private lateinit var following: MutableList<UserReceive> + private lateinit var followingRv: RecyclerView + override fun onCreateView( + inflater: LayoutInflater, container: ViewGroup?, + savedInstanceState: Bundle? + ): View? { + val view= inflater.inflate(R.layout.fragment_following, container, false) + + followingRv=view.findViewById(R.id.rvFragmentShowFollowing) + + val bundle = this.arguments + if (bundle != null) { + userId= bundle.getString("userId").toString() + Toast.makeText( + activity, bundle.getString("userId"), Toast.LENGTH_LONG + ).show(); + } + + getFollowing() + + return view + } + + fun getFollowing(){ + val api = RetrofitHelper.getInstance() + val data=api.getFollowers(userId) + data.enqueue(object : Callback<MutableList<UserReceive>> { + override fun onResponse( + call: Call<MutableList<UserReceive>>, + response: Response<MutableList<UserReceive>> + ) { + if (response.body() == null) { + return + } + following = response.body()!!.toMutableList<UserReceive>() + followingRv.apply { + layoutManager= LinearLayoutManager(activity, LinearLayoutManager.HORIZONTAL,false) + adapter= FollowersAdapter(following,requireActivity()) + + } + } + override fun onFailure(call: Call<MutableList<UserReceive>>, t: Throwable) { + Toast.makeText( + activity,"nema pracenja", Toast.LENGTH_LONG + ).show(); + } + }) + } +}
\ No newline at end of file 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 6b1bac9..2635adb 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 @@ -14,8 +14,12 @@ class FragmentUserProfile : Fragment() { inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? ): View? { - // Inflate the layout for this fragment - return inflater.inflate(R.layout.fragment_user_profile, container, false) + + val view= inflater.inflate(R.layout.fragment_user_profile, container, false) + + + + return view } diff --git a/Client/BrzoDoLokacije/app/src/main/res/layout/follower_item.xml b/Client/BrzoDoLokacije/app/src/main/res/layout/follower_item.xml new file mode 100644 index 0000000..bc43f1b --- /dev/null +++ b/Client/BrzoDoLokacije/app/src/main/res/layout/follower_item.xml @@ -0,0 +1,87 @@ +<?xml version="1.0" encoding="utf-8"?> +<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:id="@+id/tvFolloewItemUsername" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:layout_marginBottom="10dp"> + + <androidx.constraintlayout.widget.ConstraintLayout + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:orientation="horizontal" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintHorizontal_bias="1.0" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent"> + + + <androidx.cardview.widget.CardView + android:id="@+id/cvFragmentHomePageProfile" + android:layout_width="100dp" + android:layout_height="100dp" + android:layout_gravity="center" + + android:elevation="10dp" + app:cardCornerRadius="250dp" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent"> + + <ImageView + + android:id="@+id/tvFragmentProfileProfilePicture" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:elevation="10dp" + android:scaleType="centerCrop" + android:src="@drawable/ic_baseline_person_24" + tools:ignore="ContentDescription" /> + </androidx.cardview.widget.CardView> + + + <TextView + android:id="@+id/tvFollowerItemName" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_marginHorizontal="15dp" + android:layout_marginStart="24dp" + android:layout_marginTop="28dp" + android:text="Petar Petrovic" + android:textSize="17sp" + android:textStyle="bold" + app:layout_constraintEnd_toStartOf="@+id/materialButton" + app:layout_constraintHorizontal_bias="0.0" + app:layout_constraintStart_toEndOf="@+id/cvFragmentHomePageProfile" + app:layout_constraintTop_toTopOf="parent"> + + </TextView> + + <TextView + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="Petar Petrovic" + android:textSize="15sp" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintEnd_toStartOf="@+id/materialButton" + app:layout_constraintHorizontal_bias="0.656" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toBottomOf="@+id/tvFollowerItemName" + app:layout_constraintVertical_bias="0.0" /> + + <ImageButton + + android:id="@+id/materialButton" + android:layout_width="101dp" + android:layout_height="39dp" + android:layout_marginEnd="16dp" + android:background="@drawable/rounded_transparent_button" + android:foreground="@drawable/button_follow" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintTop_toTopOf="parent" + app:layout_constraintVertical_bias="0.508" + tools:ignore="TouchTargetSizeCheck" /> + + </androidx.constraintlayout.widget.ConstraintLayout> +</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file diff --git a/Client/BrzoDoLokacije/app/src/main/res/layout/fragment_following.xml b/Client/BrzoDoLokacije/app/src/main/res/layout/fragment_following.xml new file mode 100644 index 0000000..81f93a8 --- /dev/null +++ b/Client/BrzoDoLokacije/app/src/main/res/layout/fragment_following.xml @@ -0,0 +1,27 @@ +<?xml version="1.0" encoding="utf-8"?> +<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:tools="http://schemas.android.com/tools" + android:layout_width="match_parent" + android:layout_height="match_parent" + tools:context=".Fragments.FragmentFollowing"> + + <LinearLayout + android:layout_width="match_parent" + android:layout_height="match_parent" + android:orientation="vertical"> + + <TextView + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_gravity="left" + android:text="Prati" + android:textSize="20sp" + android:textStyle="bold" /> + + <androidx.recyclerview.widget.RecyclerView + android:id="@+id/rvFragmentShowFollowing" + android:layout_width="match_parent" + android:layout_height="match_parent" /> + </LinearLayout> + +</FrameLayout>
\ No newline at end of file |