aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTAMARA JERINIC <tamara.jerinic@gmail.com>2022-12-06 09:58:07 +0100
committerTAMARA JERINIC <tamara.jerinic@gmail.com>2022-12-06 09:58:57 +0100
commit287662ae7ad688229c222d5d81d1c4386faf0e71 (patch)
tree35aa2a8327d1a7891c42095d4b3b37d9b1dba00d
parent4b12698a4516065d3ad1c6e74c701d6a5e6b8468 (diff)
Povezana promena korisničkog imena, imena i profilne slike.
-rw-r--r--Backend/Api/Api/Controllers/UserController.cs4
-rw-r--r--Client/BrzoDoLokacije/app/src/main/java/com/example/brzodolokacije/Activities/ActivityChangeUserData.kt214
-rw-r--r--Client/BrzoDoLokacije/app/src/main/java/com/example/brzodolokacije/Interfaces/IBackendApi.kt3
-rw-r--r--Client/BrzoDoLokacije/app/src/main/res/drawable/ic_outline_password_24.xml5
-rw-r--r--Client/BrzoDoLokacije/app/src/main/res/layout/activity_change_user_data.xml38
5 files changed, 209 insertions, 55 deletions
diff --git a/Backend/Api/Api/Controllers/UserController.cs b/Backend/Api/Api/Controllers/UserController.cs
index 4937467..73d32ea 100644
--- a/Backend/Api/Api/Controllers/UserController.cs
+++ b/Backend/Api/Api/Controllers/UserController.cs
@@ -147,7 +147,7 @@ namespace Api.Controllers
return BadRequest();
}
- [HttpGet("{newUsername}/profile/changeMyUsername")]
+ [HttpGet("{newUsername}/changeMyUsername")]
[Authorize(Roles = "User")]
public async Task<ActionResult<int>> ChangeMyProfileUsername(string newUsername)
{
@@ -155,7 +155,7 @@ namespace Api.Controllers
}
- [HttpGet("{id}/changeMyName")]
+ [HttpGet("{newName}/changeMyName")]
[Authorize(Roles = "User")]
public async Task<ActionResult<bool>> ChangeMyProfileName(string newName)
{
diff --git a/Client/BrzoDoLokacije/app/src/main/java/com/example/brzodolokacije/Activities/ActivityChangeUserData.kt b/Client/BrzoDoLokacije/app/src/main/java/com/example/brzodolokacije/Activities/ActivityChangeUserData.kt
index 3dee6ac..d84b850 100644
--- a/Client/BrzoDoLokacije/app/src/main/java/com/example/brzodolokacije/Activities/ActivityChangeUserData.kt
+++ b/Client/BrzoDoLokacije/app/src/main/java/com/example/brzodolokacije/Activities/ActivityChangeUserData.kt
@@ -1,6 +1,8 @@
package com.example.brzodolokacije.Activities
+import android.content.Intent
import android.graphics.Color
+import android.net.Uri
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
@@ -10,13 +12,20 @@ import android.widget.TextView
import android.widget.Toast
import androidx.core.view.isGone
import androidx.core.view.isVisible
+import com.bumptech.glide.Glide
+import com.exam.DBHelper.Companion.activity
import com.example.brzodolokacije.Models.UserReceive
import com.example.brzodolokacije.R
import com.example.brzodolokacije.Services.RetrofitHelper
import com.example.brzodolokacije.Services.SharedPreferencesHelper
+import okhttp3.MediaType.Companion.toMediaTypeOrNull
+import okhttp3.MultipartBody
+import okhttp3.RequestBody
+import okhttp3.ResponseBody
import retrofit2.Call
import retrofit2.Callback
import retrofit2.Response
+import java.io.File
class ActivityChangeUserData : AppCompatActivity() {
private lateinit var username:EditText
@@ -27,11 +36,15 @@ class ActivityChangeUserData : AppCompatActivity() {
private lateinit var confirmUsername:ImageView
private lateinit var errorName:TextView
private lateinit var errorUsername:TextView
+ private lateinit var back:ImageView
+ private lateinit var profilePicture:ImageView
+ private lateinit var changeProfilePicture:ImageView
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_change_user_data)
+ //finish()
username=findViewById(R.id.tvActivityChangeUserDataUsername)
name=findViewById(R.id.tvActivityChangeUserDataName)
editName=findViewById(R.id.btnActivityChangeUserDataName)
@@ -40,6 +53,9 @@ class ActivityChangeUserData : AppCompatActivity() {
confirmUsername=findViewById(R.id.btnActivityChangeUserDataUsernameConfirm)
errorName=findViewById(R.id.btnActivityChangeUserDataNameError)
errorUsername=findViewById(R.id.btnActivityChangeUserDataUsernameError)
+ back=findViewById(R.id.btnBackToUser)
+ profilePicture=findViewById(R.id.tvActivityChangeUserDataProfilePicture)
+ changeProfilePicture=findViewById(R.id.ChangeProfileEditImageEdit)
editUsername.isClickable=true
editUsername.isVisible=true
@@ -49,7 +65,17 @@ class ActivityChangeUserData : AppCompatActivity() {
confirmUsername.isVisible=false
confirmUsername.isEnabled=false
confirmUsername.isGone=true
+ errorUsername.isVisible=false
+ editName.isClickable=true
+ editName.isVisible=true
+ editName.isEnabled=true
+ editName.isGone=false
+ confirmName.isClickable=false
+ confirmName.isVisible=false
+ confirmName.isEnabled=false
+ confirmName.isGone=true
+ errorName.isVisible=false
getUser()
editUsername.setOnClickListener{
@@ -64,44 +90,38 @@ class ActivityChangeUserData : AppCompatActivity() {
confirmUsername.isGone=false
//dodati on change listener
+
confirmUsername.setOnClickListener {
- val api = RetrofitHelper.getInstance()
- val token = SharedPreferencesHelper.getValue("jwt", this@ActivityChangeUserData)
- var data = api.changeMyUsername("Bearer " + token,username.toString().trim());
- data.enqueue(object : Callback<Int> {
- override fun onResponse(
- call: Call<Int>,
- response: Response<Int>
- ) {
- var res=response.body()!!
- Log.d("res",res.toString())
- if(res==-1){
- errorUsername.setText("Izaberite drugo korisničko ime")
- errorUsername.setTextColor(Color.RED)
- }
- else if(res==-2){
- errorUsername.setText("Nije moguće promeniti korisničko ime")
- errorUsername.setTextColor(Color.RED)
- }
- else if(res==1){
- errorUsername.setText("Korisničko ime je promenjeno")
- errorUsername.setTextColor(Color.GREEN)
- confirmUsername.isClickable=false
- confirmUsername.isVisible=false
- editUsername.isClickable=true
- editUsername.isVisible=true
- }
- }
+ changeUsername()
+ getUser()
- override fun onFailure(call: Call<Int>, t: Throwable) {
- Log.d("changeUsername","failllllllllllllllllllllll")
+ }
+ }
- }
- })
+ changeProfilePicture.setOnClickListener {
+ addProfilePicture()
+ }
+
+ editName.setOnClickListener{
+ name.setText("")
+ editName.isClickable=false
+ editName.isVisible=false
+ editName.isEnabled=false
+ editName.isGone=true
+ confirmName.isClickable=true
+ confirmName.isVisible=true
+ confirmName.isEnabled=true
+ confirmName.isGone=false
+
+ confirmName.setOnClickListener {
+ changeName()
}
}
+ back.setOnClickListener {
+ finish()
+ }
}
@@ -116,12 +136,144 @@ class ActivityChangeUserData : AppCompatActivity() {
response: Response<UserReceive>
) {
var user=response.body()!!
+
username.setText(user.username)
name.setText(user.name)
+ if(user.pfp!=null) {
+ Glide.with(this@ActivityChangeUserData)
+ .load(RetrofitHelper.baseUrl + "/api/post/image/" + user.pfp!!._id)
+ .circleCrop()//Round image
+ .into(profilePicture)
+ }
}
override fun onFailure(call: Call<UserReceive>, t: Throwable) {}
})
}
+
+ fun changeUsername(){
+ val api = RetrofitHelper.getInstance()
+ val token = SharedPreferencesHelper.getValue("jwt", this@ActivityChangeUserData)
+ var data = api.changeMyUsername("Bearer " + token,username.text.trim().toString());
+ data.enqueue(object : Callback<Int> {
+ override fun onResponse(
+ call: Call<Int>,
+ response: Response<Int>
+ ) {
+ var res=response.body()!!
+ Log.d("res",res.toString())
+ if(res==-1){
+ errorUsername.isVisible=true
+ errorUsername.isVisible=true
+ errorUsername.setText("Izaberite drugo korisničko ime")
+ errorUsername.setTextColor(Color.RED)
+ }
+ else if(res==-2){
+ errorUsername.isVisible=true
+ errorUsername.isVisible=true
+ errorUsername.setText("Nije moguće promeniti korisničko ime")
+ errorUsername.setTextColor(Color.RED)
+ }
+ else if(res==1){
+ errorUsername.isVisible=true
+ errorUsername.isVisible=true
+ errorUsername.setText("Korisničko ime je promenjeno")
+ errorUsername.setTextColor(Color.GREEN)
+ confirmUsername.isClickable=false
+ confirmUsername.isVisible=false
+ confirmUsername.isEnabled=false
+ confirmUsername.isGone=true
+ editUsername.isClickable=true
+ editUsername.isVisible=true
+ editUsername.isEnabled=true
+ editUsername.isGone=false
+ getUser()
+ }
+ }
+
+ override fun onFailure(call: Call<Int>, t: Throwable) {
+ Log.d("changeUsername","failllllllllllllllllllllll")
+
+ }
+ })
+ }
+
+ fun changeName(){
+ val api = RetrofitHelper.getInstance()
+ val token = SharedPreferencesHelper.getValue("jwt", this@ActivityChangeUserData)
+ var data = api.changeMyName("Bearer " + token,name.text.trim().toString());
+ data.enqueue(object : Callback<Boolean> {
+ override fun onResponse(
+ call: Call<Boolean>,
+ response: Response<Boolean>
+ ) {
+ var res=response.body()!!
+ Log.d("res",res.toString())
+ if(res==false){
+ errorName.isVisible=true
+ errorName.isVisible=true
+ errorName.setText("Nije moguće promeniti ime")
+ errorName.setTextColor(Color.RED)
+ }
+ else if(res){
+ errorName.isVisible=true
+ errorName.isVisible=true
+ errorName.setText("Ime je promenjeno")
+ errorName.setTextColor(Color.GREEN)
+ confirmName.isClickable=false
+ confirmName.isVisible=false
+ confirmName.isEnabled=false
+ confirmName.isGone=true
+ editName.isClickable=true
+ editName.isVisible=true
+ editName.isEnabled=true
+ editName.isGone=false
+ getUser()
+ }
+ }
+
+ override fun onFailure(call: Call<Boolean>, t: Throwable) {
+ Log.d("changename","faillllllllll")
+
+ }
+ })
+ }
+ private fun addProfilePicture(){
+ val intent= Intent(Intent.ACTION_PICK)
+ intent.action = Intent.ACTION_GET_CONTENT
+ intent.type="image/*"
+ startActivityForResult(Intent.createChooser(intent,"Izaberi profilnu sliku"),201)
+ }
+ override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
+ super.onActivityResult(requestCode, resultCode, data)
+ //nakon otvaranja
+ if(requestCode==201 && resultCode== AppCompatActivity.RESULT_OK) {
+ var imageUri = data!!.data
+
+ val api =RetrofitHelper.getInstance()
+ var inputStream=(imageUri?.let {
+ this@ActivityChangeUserData.getContentResolver().openInputStream(
+ it
+ )
+ })
+ val file: File = File.createTempFile("temp","pfp")
+ file!!.writeBytes(inputStream!!.readBytes())
+ var imageReq= RequestBody.create("image/*".toMediaTypeOrNull(),file)
+ val imageBody: MultipartBody.Part = MultipartBody.Part.createFormData("image", file.name, imageReq)
+ val token= SharedPreferencesHelper.getValue("jwt", this@ActivityChangeUserData)
+ val req=api.setPfp("Bearer "+token,imageBody)
+
+ req.enqueue(object : retrofit2.Callback<ResponseBody?> {
+ override fun onResponse(call: Call<ResponseBody?>, response: Response<ResponseBody?>) {
+ if(response.isSuccessful()){
+ getUser()
+ }
+ }
+ override fun onFailure(call: Call<ResponseBody?>, t: Throwable) {
+
+ }
+ })
+ }
+ }
} \ 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 39527f2..7ddf047 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
@@ -115,4 +115,7 @@ interface IBackendApi {
@GET("/api/user/{newUsername}/changeMyUsername")
fun changeMyUsername(@Header("Authorization") authHeader:String,@Path("newUsername") newUsername:String):Call<Int>
+ @GET("/api/user/{newName}/changeMyName")
+ fun changeMyName(@Header("Authorization") authHeader:String,@Path("newName") newName:String):Call<Boolean>
+
} \ No newline at end of file
diff --git a/Client/BrzoDoLokacije/app/src/main/res/drawable/ic_outline_password_24.xml b/Client/BrzoDoLokacije/app/src/main/res/drawable/ic_outline_password_24.xml
new file mode 100644
index 0000000..267f930
--- /dev/null
+++ b/Client/BrzoDoLokacije/app/src/main/res/drawable/ic_outline_password_24.xml
@@ -0,0 +1,5 @@
+<vector 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,17h20v2H2V17zM3.15,12.95L4,11.47l0.85,1.48l1.3,-0.75L5.3,10.72H7v-1.5H5.3l0.85,-1.47L4.85,7L4,8.47L3.15,7l-1.3,0.75L2.7,9.22H1v1.5h1.7L1.85,12.2L3.15,12.95zM9.85,12.2l1.3,0.75L12,11.47l0.85,1.48l1.3,-0.75l-0.85,-1.48H15v-1.5h-1.7l0.85,-1.47L12.85,7L12,8.47L11.15,7l-1.3,0.75l0.85,1.47H9v1.5h1.7L9.85,12.2zM23,9.22h-1.7l0.85,-1.47L20.85,7L20,8.47L19.15,7l-1.3,0.75l0.85,1.47H17v1.5h1.7l-0.85,1.48l1.3,0.75L20,11.47l0.85,1.48l1.3,-0.75l-0.85,-1.48H23V9.22z"/>
+</vector>
diff --git a/Client/BrzoDoLokacije/app/src/main/res/layout/activity_change_user_data.xml b/Client/BrzoDoLokacije/app/src/main/res/layout/activity_change_user_data.xml
index 39362b7..2ade677 100644
--- a/Client/BrzoDoLokacije/app/src/main/res/layout/activity_change_user_data.xml
+++ b/Client/BrzoDoLokacije/app/src/main/res/layout/activity_change_user_data.xml
@@ -8,7 +8,7 @@
tools:context=".Activities.ActivityChangeUserData">
<ImageView
- android:id="@+id/btnActivityShowFollowersAndFollowingBackToUser"
+ android:id="@+id/btnBackToUser"
android:layout_width="35dp"
android:layout_height="35dp"
android:clickable="true"
@@ -25,10 +25,11 @@
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_gravity="center"
- android:layout_marginTop="2dp"
+ android:layout_marginStart="8dp"
+ android:layout_marginTop="4dp"
android:text="Izmeni profil"
- app:layout_constraintStart_toEndOf="@+id/btnActivityShowFollowersAndFollowingBackToUser"
+ app:layout_constraintStart_toEndOf="@+id/btnBackToUser"
app:layout_constraintTop_toTopOf="parent" />
<androidx.cardview.widget.CardView
@@ -45,7 +46,7 @@
<ImageView
- android:id="@+id/tvActivityProfileProfilePicture"
+ android:id="@+id/tvActivityChangeUserDataProfilePicture"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:elevation="10dp"
@@ -58,8 +59,8 @@
<androidx.cardview.widget.CardView
android:id="@+id/ChangeProfileEditImage"
- android:layout_width="50dp"
- android:layout_height="50dp"
+ android:layout_width="40dp"
+ android:layout_height="40dp"
android:layout_gravity="center"
android:layout_marginTop="90dp"
android:elevation="5dp"
@@ -69,8 +70,10 @@
app:layout_constraintTop_toTopOf="@+id/cvFragmentHomePageProfile">
<ImageView
- android:layout_width="50dp"
- android:layout_height="50dp"
+ android:id="@+id/ChangeProfileEditImageEdit"
+ android:clickable="true"
+ android:layout_width="40dp"
+ android:layout_height="40dp"
android:layout_gravity="bottom|right"
android:background="@color/white"
android:elevation="20dp"
@@ -129,23 +132,14 @@
android:layout_height="wrap_content"
android:layout_marginTop="140dp"
android:text="Izmeni lozinku"
- app:shapeAppearanceOverlay="@style/Circular"
-
+ app:layout_constraintBottom_toBottomOf="parent"
+ android:drawableLeft="@drawable/ic_outline_password_24"
+ android:drawableTint="@color/white"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
- app:layout_constraintTop_toBottomOf="@+id/tvActivityChangeUserDataUsername" />
-
- <Button
- android:id="@+id/button2"
- android:layout_width="0dp"
- android:layout_height="wrap_content"
- android:layout_marginTop="4dp"
- app:shapeAppearanceOverlay="@style/Circular"
+ app:layout_constraintTop_toBottomOf="@+id/tvActivityChangeUserDataUsername"
+ app:shapeAppearanceOverlay="@style/Circular" />
- android:text="Sačuvaj izmene"
- app:layout_constraintEnd_toEndOf="parent"
- app:layout_constraintStart_toStartOf="parent"
- app:layout_constraintTop_toBottomOf="@+id/button" />
<ImageView
android:clickable="true"