Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #815 from QuickBlox/rc-1.3.0-ui-kit
1.3.0-ui-kit
- Loading branch information
Showing
11 changed files
with
547 additions
and
150 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
122 changes: 122 additions & 0 deletions
122
android-ui-kit-sample/app/src/main/java/com/example/android_ui_kit_sample/SignUpActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
/* | ||
* Created by Injoit on 6.7.2023. | ||
* Copyright © 2023 Quickblox. All rights reserved. | ||
* | ||
*/ | ||
|
||
package com.example.android_ui_kit_sample | ||
|
||
import android.content.Context | ||
import android.content.Intent | ||
import android.os.Bundle | ||
import android.view.MenuItem | ||
import android.widget.Toast | ||
import androidx.activity.OnBackPressedCallback | ||
import androidx.appcompat.app.AppCompatActivity | ||
import com.example.android_ui_kit_sample.databinding.ActivitySignupBinding | ||
import com.quickblox.android_ui_kit.QuickBloxUiKit | ||
import com.quickblox.android_ui_kit.presentation.screens.dialogs.DialogsActivity | ||
import com.quickblox.core.QBEntityCallback | ||
import com.quickblox.core.exception.QBResponseException | ||
import com.quickblox.users.QBUsers | ||
import com.quickblox.users.model.QBUser | ||
|
||
class SignUpActivity : AppCompatActivity() { | ||
private lateinit var binding: ActivitySignupBinding | ||
|
||
companion object { | ||
fun show(context: Context) { | ||
val intent = Intent(context, SignUpActivity::class.java) | ||
context.startActivity(intent) | ||
} | ||
} | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
|
||
binding = ActivitySignupBinding.inflate(layoutInflater) | ||
setContentView(binding.root) | ||
|
||
configureToolbar() | ||
onBackPressedClickListener() | ||
|
||
signUpClickListener() | ||
} | ||
|
||
private fun configureToolbar() { | ||
setSupportActionBar(binding.toolbar) | ||
if (supportActionBar != null) { | ||
supportActionBar?.setDisplayHomeAsUpEnabled(true) | ||
supportActionBar?.setDisplayShowHomeEnabled(true) | ||
supportActionBar?.title = getString(R.string.signup) | ||
} | ||
} | ||
|
||
private fun onBackPressedClickListener() { | ||
onBackPressedDispatcher.addCallback(this, object : OnBackPressedCallback(true) { | ||
override fun handleOnBackPressed() { | ||
finish() | ||
} | ||
}) | ||
} | ||
|
||
private fun signUpClickListener() { | ||
binding.btnSignUp.setOnClickListener { | ||
binding.btnSignUp.isEnabled = false | ||
|
||
val user = buildUser() | ||
signUp(user) | ||
} | ||
} | ||
|
||
private fun buildUser(): QBUser { | ||
val user = QBUser() | ||
user.login = binding.etLogin.text.toString().trim() | ||
user.fullName = binding.etDisplayName.text.toString().trim() | ||
user.password = binding.etPassword.text.toString().trim() | ||
return user | ||
} | ||
|
||
private fun signUp(user: QBUser) { | ||
QBUsers.signUp(user).performAsync(object : QBEntityCallback<QBUser> { | ||
override fun onSuccess(userFromRest: QBUser, bundle: Bundle) { | ||
logIn(user) | ||
} | ||
|
||
override fun onError(exception: QBResponseException) { | ||
Toast.makeText(this@SignUpActivity, exception.message, Toast.LENGTH_LONG).show() | ||
binding.btnSignUp.isEnabled = true | ||
} | ||
}) | ||
} | ||
|
||
private fun logIn(user: QBUser) { | ||
QBUsers.signIn(user).performAsync(object : QBEntityCallback<QBUser> { | ||
override fun onSuccess(user: QBUser?, bundle: Bundle?) { | ||
binding.btnSignUp.isEnabled = true | ||
initAndShowQBUiKit() | ||
finish() | ||
} | ||
|
||
override fun onError(exception: QBResponseException) { | ||
binding.btnSignUp.isEnabled = true | ||
Toast.makeText(this@SignUpActivity, exception.message, Toast.LENGTH_LONG).show() | ||
} | ||
}) | ||
} | ||
|
||
private fun initAndShowQBUiKit() { | ||
QuickBloxUiKit.init(applicationContext) | ||
DialogsActivity.show(this) | ||
} | ||
|
||
override fun onOptionsItemSelected(item: MenuItem): Boolean { | ||
return when (item.itemId) { | ||
android.R.id.home -> { | ||
finish() | ||
true | ||
} | ||
else -> super.onOptionsItemSelected(item) | ||
} | ||
} | ||
} |
Oops, something went wrong.