Màn hình đăng ký tài khoản

Một phần của tài liệu đồ án tốt nghiệp ứng dụng quản lý phòng trọ (Trang 67 - 75)

Tại màn hình dưới đây cho phép người dùng tạo một tài khoản mới. Người dùng cần cung cấp Email, Display name (tên hiển thị), Password (mật khẩu).

Bảng 3.4. Bảng mô tả màn hình đăng kí STT Tên 1 imgIconUser 2 3 edtUserName 4 edtDisplayName 5 edtPassword 6 btnRegister 7

Code xử lý đăng ký (đã kiểm tra các dữ liệu đầu vào) như sau:

auth.createUserWithEmailAndPassword(email, password)

.addOnCompleteListener(this) { task ->

progressBar.visibility = View.GONE

if (!task.isSuccessful) {

Snackbar.make(

it,

"Your email is already!. Try again, Please",

Snackbar.LENGTH_LONG

).show() } else {

if (hasAvatar){

val output = ByteArrayOutputStream()

val storeRef =

FirebaseStorage.getInstance().reference.child("avatar/$

{auth.currentUser?.uid }")

imageBitmap!!.compress(Bitmap.CompressFormat.JPEG, 100,

output)

val image = output.toByteArray()

val upload = storeRef.putBytes(image)

imgIconUser.visibility = View.INVISIBLE

upload.addOnCompleteListener { task ->

if (task.isSuccessful) {

storeRef.downloadUrl.addOnCompleteListener { urlTask ->

urlTask.result?.let{

imageUri = it

imgIconUser.visibility = View.VISIBLE

imgIconUser.setImageBitmap(imageBitmap)

}

} else {

Toast.makeText(this, "Upload Fail",

Toast.LENGTH_LONG).show() } } }else{ updateDisplayName(displayName) } }

Nếu người dùng cần thay đổi ảnh hình đại diện, có hai cách để thay đổi ảnh: Chụp ảnh mới, tải lên một ảnh có sẵn.

Hình 3.7. Màn hình lựa chọn phương thức cập nhật ảnh đại diện

Nếu người dùng tải lên một ảnh mới từ camera thì cần cung cấp quyền truy cập camera từ thiết bị:

Code xin quyền như sau:

if (ContextCompat.checkSelfPermission(

this,

Manifest.permission.CAMERA

) ==

PackageManager.PERMISSION_DENIED ) {

Toast.makeText(this, "Please allow permission access camera!",

Toast.LENGTH_LONG).show();

if (ActivityCompat.shouldShowRequestPermissionRationale( this,

Manifest.permission.CAMERA

)){

ActivityCompat.requestPermissions(

this,

arrayOf(Manifest.permission.CAMERA), 1999

) }else{

val alert: AlertDialog.Builder= AlertDialog.Builder(this)

alert.setMessage("To use the camera, you need to allow camera permissions.You can follow these steps!\n\n1.Press button go to setting(app info).\n\n2.Choose Permission.\n\n3.Choose permission Camera & allow.")

val textView = TextView(this)

textView.text = "Error! Permission denied" textView.setPadding(20, 30, 20, 30)

textView.textSize = 20f

textView.setBackgroundColor(Color.parseColor("#0087FE"))

textView.setTextColor(Color.WHITE)

alert.setCustomTitle(textView)

alert.setNegativeButton("Cancel"){ dialogInterface, which ->

dialogInterface.dismiss()

}

alert.setPositiveButton("Go to setting"){ dialogInterface, which->

dialogInterface.dismiss()

val intent =

Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS)

intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)

val uri = Uri.fromParts("package", packageName,

null) intent.data = uri

startActivity(intent)

}

val alertDialog: AlertDialog = alert.create()

alertDialog.setCancelable(false)

alertDialog.setOnShowListener {

Khi người dùng chọn Allow (cho phép) thiết bị sẽ mở giao diện chụp hình của người dùng. Tuy nhiên nếu sẽ có khi thiết bị người dùng chặn quyền truy cập Camera thì giao diện sẽ hiển thị một thông báo như màn hình dưới đây:

Hình 3.9. Màn hình thông báo lỗi khi người dùng chặn quyền truy cập camera

Nếu trường hợp đã có sẵn ảnh trong thiết bị chỉ cần sử chức năng thứ hai (Select profile picture) trong hình 3.7. Sau đó thiết bị sẽ hiển thị các ứng dụng quản lý tệp tin ví dụ như hình.

Hình 3.10. Màn hình cho người dùng lựa chọn ứng dụng quản lý file

Sau khi chọn ảnh thành công hệ thống sẽ hiển thị giao diện cắt ảnh. Khi người dùng thực hiện xong. Giao diện đăng ký sẽ quay trở lại và tải ảnh lên hệ thống ứng dụng.

Hình 3.11. Màn hình cắt ảnh trước khi tải lên ứng dụng

Một phần của tài liệu đồ án tốt nghiệp ứng dụng quản lý phòng trọ (Trang 67 - 75)