Merge branch 'master' of git.reim.ar:ReiMerc/easyeat
This commit is contained in:
commit
b8026250cf
@ -98,7 +98,7 @@ data class UpdateUserRequest(val userName: String, val email: String)
|
|||||||
fun updateUser(ctx: Context, username: String, email: String) {
|
fun updateUser(ctx: Context, username: String, email: String) {
|
||||||
val request = UpdateUserRequest(username, email)
|
val request = UpdateUserRequest(username, email)
|
||||||
|
|
||||||
return requestJson<UpdateUserRequest, Unit>(ctx, "PUT", "/api/User/update", request)
|
requestJson<UpdateUserRequest, Boolean>(ctx, "PUT", "/api/User/update", request)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package tech.mercantec.easyeat.ui.profile
|
package tech.mercantec.easyeat.ui.profile
|
||||||
|
|
||||||
import android.app.ProgressDialog
|
import android.app.ProgressDialog
|
||||||
|
import android.content.Intent
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.widget.Button
|
import android.widget.Button
|
||||||
import android.widget.EditText
|
import android.widget.EditText
|
||||||
@ -43,6 +44,11 @@ class EditProfileActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val intent = Intent()
|
||||||
|
intent.putExtra("username", username)
|
||||||
|
intent.putExtra("email", email)
|
||||||
|
setResult(RESULT_OK, intent)
|
||||||
|
|
||||||
finish()
|
finish()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,15 @@
|
|||||||
package tech.mercantec.easyeat.ui.profile
|
package tech.mercantec.easyeat.ui.profile
|
||||||
|
|
||||||
|
import android.app.Activity
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
|
import androidx.activity.result.ActivityResultLauncher
|
||||||
|
import androidx.activity.result.contract.ActivityResultContracts
|
||||||
|
import androidx.core.view.children
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import tech.mercantec.easyeat.ui.auth.WelcomeActivity
|
import tech.mercantec.easyeat.ui.auth.WelcomeActivity
|
||||||
import tech.mercantec.easyeat.databinding.FragmentProfileBinding
|
import tech.mercantec.easyeat.databinding.FragmentProfileBinding
|
||||||
@ -16,8 +20,25 @@ import tech.mercantec.easyeat.helpers.logout
|
|||||||
import kotlin.concurrent.thread
|
import kotlin.concurrent.thread
|
||||||
|
|
||||||
class ProfileFragment : Fragment() {
|
class ProfileFragment : Fragment() {
|
||||||
|
private lateinit var launcher: ActivityResultLauncher<Intent>
|
||||||
|
private lateinit var binding: FragmentProfileBinding
|
||||||
|
|
||||||
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
|
super.onCreate(savedInstanceState)
|
||||||
|
|
||||||
|
launcher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) {
|
||||||
|
if (it.data == null || it.resultCode != Activity.RESULT_OK) return@registerForActivityResult
|
||||||
|
|
||||||
|
binding.username.text = it.data!!.getStringExtra("username")
|
||||||
|
binding.email.text = it.data!!.getStringExtra("email")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
|
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
|
||||||
val binding = FragmentProfileBinding.inflate(inflater, container, false)
|
binding = FragmentProfileBinding.inflate(inflater, container, false)
|
||||||
|
|
||||||
|
binding.layout.children.forEach { it.visibility = View.GONE }
|
||||||
|
binding.loading.visibility = View.VISIBLE
|
||||||
|
|
||||||
thread {
|
thread {
|
||||||
val userInfo: UserInfoResponse
|
val userInfo: UserInfoResponse
|
||||||
@ -29,6 +50,11 @@ class ProfileFragment : Fragment() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return@thread
|
return@thread
|
||||||
|
} finally {
|
||||||
|
activity?.runOnUiThread {
|
||||||
|
binding.layout.children.forEach { it.visibility = View.VISIBLE }
|
||||||
|
binding.loading.visibility = View.GONE
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
activity?.runOnUiThread {
|
activity?.runOnUiThread {
|
||||||
@ -37,9 +63,10 @@ class ProfileFragment : Fragment() {
|
|||||||
|
|
||||||
binding.editProfile.setOnClickListener {
|
binding.editProfile.setOnClickListener {
|
||||||
val intent = Intent(activity, EditProfileActivity::class.java)
|
val intent = Intent(activity, EditProfileActivity::class.java)
|
||||||
intent.putExtra("username", userInfo.userName)
|
intent.putExtra("username", binding.username.text)
|
||||||
intent.putExtra("email", userInfo.email)
|
intent.putExtra("email", binding.email.text)
|
||||||
startActivity(intent)
|
|
||||||
|
launcher.launch(intent)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:id="@+id/layout"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
@ -30,7 +31,6 @@
|
|||||||
android:textSize="24sp"
|
android:textSize="24sp"
|
||||||
android:textStyle="bold"
|
android:textStyle="bold"
|
||||||
android:textAlignment="center"
|
android:textAlignment="center"
|
||||||
android:text="@string/loading"
|
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
@ -40,7 +40,6 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:textSize="18sp"
|
android:textSize="18sp"
|
||||||
android:textAlignment="center"
|
android:textAlignment="center"
|
||||||
android:text="@string/loading"
|
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
|
@ -77,7 +77,7 @@ namespace API.DBAccess
|
|||||||
|
|
||||||
bool saved = await _context.SaveChangesAsync() == 1;
|
bool saved = await _context.SaveChangesAsync() == 1;
|
||||||
|
|
||||||
if (saved) { return new OkObjectResult(user); }
|
if (saved) { return new OkObjectResult(true); }
|
||||||
|
|
||||||
return new ConflictObjectResult(new { message = "Could not save to database" });
|
return new ConflictObjectResult(new { message = "Could not save to database" });
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user