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) {
|
||||
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
|
||||
|
@ -1,6 +1,7 @@
|
||||
package tech.mercantec.easyeat.ui.profile
|
||||
|
||||
import android.app.ProgressDialog
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.widget.Button
|
||||
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()
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,15 @@
|
||||
package tech.mercantec.easyeat.ui.profile
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
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 tech.mercantec.easyeat.ui.auth.WelcomeActivity
|
||||
import tech.mercantec.easyeat.databinding.FragmentProfileBinding
|
||||
@ -16,8 +20,25 @@ import tech.mercantec.easyeat.helpers.logout
|
||||
import kotlin.concurrent.thread
|
||||
|
||||
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 {
|
||||
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 {
|
||||
val userInfo: UserInfoResponse
|
||||
@ -29,6 +50,11 @@ class ProfileFragment : Fragment() {
|
||||
}
|
||||
|
||||
return@thread
|
||||
} finally {
|
||||
activity?.runOnUiThread {
|
||||
binding.layout.children.forEach { it.visibility = View.VISIBLE }
|
||||
binding.loading.visibility = View.GONE
|
||||
}
|
||||
}
|
||||
|
||||
activity?.runOnUiThread {
|
||||
@ -37,9 +63,10 @@ class ProfileFragment : Fragment() {
|
||||
|
||||
binding.editProfile.setOnClickListener {
|
||||
val intent = Intent(activity, EditProfileActivity::class.java)
|
||||
intent.putExtra("username", userInfo.userName)
|
||||
intent.putExtra("email", userInfo.email)
|
||||
startActivity(intent)
|
||||
intent.putExtra("username", binding.username.text)
|
||||
intent.putExtra("email", binding.email.text)
|
||||
|
||||
launcher.launch(intent)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
@ -30,7 +31,6 @@
|
||||
android:textSize="24sp"
|
||||
android:textStyle="bold"
|
||||
android:textAlignment="center"
|
||||
android:text="@string/loading"
|
||||
/>
|
||||
|
||||
<TextView
|
||||
@ -40,7 +40,6 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="18sp"
|
||||
android:textAlignment="center"
|
||||
android:text="@string/loading"
|
||||
/>
|
||||
|
||||
<LinearLayout
|
||||
|
@ -77,7 +77,7 @@ namespace API.DBAccess
|
||||
|
||||
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" });
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user