diff options
Diffstat (limited to 'Client')
3 files changed, 136 insertions, 38 deletions
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 c03dbd3..4f48dc7 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 @@ -1,19 +1,15 @@  package com.example.brzodolokacije.Activities  import android.annotation.SuppressLint -import android.graphics.Color -import android.graphics.PorterDuff -import android.graphics.drawable.Drawable  import android.os.Bundle  import android.util.Log  import android.widget.*  import androidx.appcompat.app.AppCompatActivity -import androidx.core.content.ContextCompat +import androidx.core.view.isVisible  import androidx.fragment.app.Fragment  import com.bumptech.glide.Glide  import com.example.brzodolokacije.Fragments.FragmentShowUserPosts  import com.example.brzodolokacije.Models.UserReceive -import com.example.brzodolokacije.R  import com.example.brzodolokacije.R.*  import com.example.brzodolokacije.Services.RetrofitHelper  import com.example.brzodolokacije.Services.SharedPreferencesHelper @@ -21,7 +17,6 @@ import com.google.gson.Gson  import retrofit2.Call  import retrofit2.Callback  import retrofit2.Response -import java.security.AccessController.getContext  class ActivityUserProfile : AppCompatActivity() { @@ -35,9 +30,10 @@ class ActivityUserProfile : AppCompatActivity() {      private lateinit var fragmentContainer: FrameLayout      private lateinit var userObject:UserReceive      private lateinit var openChat:ImageButton - +    private lateinit var unfollowUser:Button      private lateinit var followersList: MutableList<UserReceive>      private lateinit var followingList: MutableList<UserReceive> +    private var follow:Boolean=false      override fun onCreate(savedInstanceState: Bundle?) {          super.onCreate(savedInstanceState) @@ -49,6 +45,7 @@ class ActivityUserProfile : AppCompatActivity() {          followingNumber=findViewById(id.tvActivityUserProfileFollowNo)          profilePicture=findViewById(id.tvActivityProfileProfilePicture)          followUser=findViewById(id.btnActivityUserProfileFollow) +        unfollowUser=findViewById(id.btnActivityUserProfileUnFollow)          showUserPosts=findViewById(id.btnActivityUserProfileShowPosts)          fragmentContainer=findViewById(id.flActivityProfileFragmentContainer)          openChat=findViewById(id.activityUserProfileOpenChat) @@ -74,31 +71,68 @@ class ActivityUserProfile : AppCompatActivity() {              }          } +          checkIfAlreadyFollow() +        updateUserData()          followUser.setOnClickListener{ +                val api = RetrofitHelper.getInstance() +                val token = SharedPreferencesHelper.getValue("jwt", this@ActivityUserProfile) +                var data = api.addFollower("Bearer " + token, userObject._id); +                data.enqueue(object : Callback<Boolean> { +                    override fun onResponse( +                        call: Call<Boolean>, +                        response: Response<Boolean> +                    ) { +                        unfollowUser.isVisible=true +                        unfollowUser.isClickable=true +                        unfollowUser.isEnabled=true +                        followUser.isVisible=false +                        followUser.isClickable=false +                        followUser.isEnabled=false +                        updateUserData() + +                        Toast.makeText( +                            this@ActivityUserProfile, "PRATITE KORISNIKA", Toast.LENGTH_LONG +                        ).show(); +                    } + +                    override fun onFailure(call: Call<Boolean>, t: Throwable) { +                        Toast.makeText( +                            this@ActivityUserProfile, t.toString(), Toast.LENGTH_LONG +                        ).show(); +                    } +                }) -            checkIfAlreadyFollow() - +        } +        unfollowUser.setOnClickListener { +                val api = RetrofitHelper.getInstance() +                val token = SharedPreferencesHelper.getValue("jwt", this@ActivityUserProfile) +                var data = api.unfollow("Bearer " + token, userObject._id); +                data.enqueue(object : Callback<Boolean> { +                    override fun onResponse( +                        call: Call<Boolean>, +                        response: Response<Boolean> +                    ) { +                        unfollowUser.isVisible=false +                        unfollowUser.isClickable=false +                        unfollowUser.isEnabled=false +                        followUser.isVisible=true +                        followUser.isClickable=true +                        followUser.isEnabled=true +                        updateUserData() +                        Toast.makeText( +                            this@ActivityUserProfile, "VIŠE NE PRATITE KORISNIKA", Toast.LENGTH_LONG +                        ).show(); +                    } + +                    override fun onFailure(call: Call<Boolean>, t: Throwable) { +                        Toast.makeText( +                            this@ActivityUserProfile, t.toString(), Toast.LENGTH_LONG +                        ).show(); +                    } +                }) -            val api = RetrofitHelper.getInstance() -            val token= SharedPreferencesHelper.getValue("jwt", this@ActivityUserProfile) -            var data=api.addFollower("Bearer "+token,userObject._id); -            data.enqueue(object : Callback<Boolean> { -                override fun onResponse( -                    call: Call<Boolean>, -                    response: Response<Boolean> -                ) { -                    Toast.makeText( -                        this@ActivityUserProfile, "PRATITE KORISNIKA", Toast.LENGTH_LONG -                    ).show(); -                } -                override fun onFailure(call: Call<Boolean>, t: Throwable) { -                    Toast.makeText( -                        this@ActivityUserProfile, t.toString(), Toast.LENGTH_LONG -                    ).show(); -                } -            })          } @@ -132,15 +166,34 @@ class ActivityUserProfile : AppCompatActivity() {                  }                  var follow = response.body()!!                  if(follow){ +                      Log.d("success","follow") -                    followUser.setCompoundDrawablesWithIntrinsicBounds(drawable.ic_outline_person_remove_24,0,0,0) +                    /*followUser.setCompoundDrawablesWithIntrinsicBounds(drawable.ic_outline_person_remove_24,0,0,0)                      followUser.text="Ne prati više" - +                    follow=false +                    */ +                    unfollowUser.isVisible=true +                    unfollowUser.isClickable=true +                    unfollowUser.isEnabled=true +                    followUser.isVisible=false +                    followUser.isClickable=false +                    followUser.isEnabled=false                  } -                if(!follow){ +                else{                      Log.d("success","not follow") -                    followUser.setCompoundDrawablesWithIntrinsicBounds(drawable.ic_outline_person_add_alt_24,0,0,0) +                    /*followUser.setCompoundDrawablesWithIntrinsicBounds(drawable.ic_outline_person_add_alt_24,0,0,0)                      followUser.text="Prati" +                    follow=true +                    */ + +                    unfollowUser.isVisible=false +                    unfollowUser.isClickable=false +                    unfollowUser.isEnabled=false +                    followUser.isVisible=true +                    followUser.isClickable=true +                    followUser.isEnabled=true + +                  }              } @@ -148,7 +201,28 @@ class ActivityUserProfile : AppCompatActivity() {      } -    fun checkIfAlreadyFollowChangeButton(){ +    fun updateUserData(){ +        val api = RetrofitHelper.getInstance() +        val token = SharedPreferencesHelper.getValue("jwt", this@ActivityUserProfile) +        var data = api.getProfileFromId("Bearer " + token, userObject._id); +        data.enqueue(object : Callback<UserReceive> { +            override fun onResponse( +                call: Call<UserReceive>, +                response: Response<UserReceive> +            ) { +                var userData=response.body()!! +                name.text=userData.name +                postsNumber.text=userData.postNumber.toString() +                followersNumber.text=userData.followersCount.toString() +                followingNumber.text=userData.followingCount.toString() +            } +            override fun onFailure(call: Call<UserReceive>, t: Throwable) { +                Toast.makeText( +                    this@ActivityUserProfile, t.toString(), Toast.LENGTH_LONG +                ).show(); +            } +        })      } +  }
\ 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 ce8d7e3..bc8c7ae 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 @@ -101,4 +101,7 @@ interface IBackendApi {      @GET("/api/user/{id}/checkIfAlreadyFollow")      fun checkIfAlreadyFollow(@Header("Authorization") authHeader:String,@Path("id") id:String):Call<Boolean> +    @GET("/api/user/{id}/unfollow") +    fun unfollow(@Header("Authorization") authHeader:String,@Path("id") id:String):Call<Boolean> +  }
\ No newline at end of file diff --git a/Client/BrzoDoLokacije/app/src/main/res/layout/activity_user_profile.xml b/Client/BrzoDoLokacije/app/src/main/res/layout/activity_user_profile.xml index a446f9a..0e90fc7 100644 --- a/Client/BrzoDoLokacije/app/src/main/res/layout/activity_user_profile.xml +++ b/Client/BrzoDoLokacije/app/src/main/res/layout/activity_user_profile.xml @@ -228,22 +228,44 @@                      <Button                          android:id="@+id/btnActivityUserProfileFollow" -                        android:layout_width="0dp" +                        android:layout_width="280dp"                          android:layout_height="30dp"                          android:layout_marginStart="16dp" -                        android:layout_marginEnd="8dp" +                        android:clickable="true"                          android:drawableLeft="@drawable/ic_outline_person_add_alt_24" -                        android:text="PRATI"                          android:insetTop="0dp"                          android:insetBottom="0dp" +                        android:backgroundTint="@color/button_main" +                        android:text="PRATI" +                        android:visibility="visible" +                        app:layout_constraintBottom_toBottomOf="parent" +                        app:layout_constraintStart_toStartOf="parent" +                        app:layout_constraintTop_toTopOf="parent" +                        app:layout_constraintVertical_bias="0.13"                          app:shapeAppearanceOverlay="@style/Circular" +                        tools:ignore="TouchTargetSizeCheck" /> + +                    <Button + +                        android:id="@+id/btnActivityUserProfileUnFollow" +                        android:layout_width="280dp" +                        android:layout_height="30dp" +                        android:layout_marginStart="16dp" +                        android:clickable="false" +                        android:drawableLeft="@drawable/ic_outline_person_remove_24" +                        android:insetTop="0dp" +                        android:insetBottom="0dp" +                        android:text="NE PRATI više" +                        android:backgroundTint="@color/unfollow" +                          app:layout_constraintBottom_toBottomOf="parent" -                        app:layout_constraintEnd_toStartOf="@+id/activityUserProfileOpenChat"                          app:layout_constraintStart_toStartOf="parent"                          app:layout_constraintTop_toTopOf="parent"                          app:layout_constraintVertical_bias="0.13" +                        app:shapeAppearanceOverlay="@style/Circular"                          tools:ignore="TouchTargetSizeCheck" /> +                      <ImageButton                          android:id="@+id/activityUserProfileOpenChat"                          android:layout_width="35dp" @@ -252,11 +274,10 @@                          android:layout_marginEnd="16dp"                          android:height="40dp"                          android:background="@drawable/rounded_button" -                        android:backgroundTint="#4DB6AC" +                        android:backgroundTint="@color/button_main"                          android:src="@drawable/ic_round_message_24"                          app:layout_constraintBottom_toBottomOf="parent"                          app:layout_constraintEnd_toEndOf="parent" -                        app:layout_constraintStart_toEndOf="@+id/btnActivityUserProfileFollow"                          app:layout_constraintTop_toTopOf="parent"                          app:layout_constraintVertical_bias="0.0"                          app:shapeAppearanceOverlay="@style/Circular"  | 
