Commit c9399aa4 authored by Filipe de Lima Brito's avatar Filipe de Lima Brito

Delete ProgressDialog (in favor of our custom indicator). Override functions.

parent e041b5b8
...@@ -11,12 +11,23 @@ import chat.rocket.android.R ...@@ -11,12 +11,23 @@ import chat.rocket.android.R
import chat.rocket.android.helper.KeyboardHelper import chat.rocket.android.helper.KeyboardHelper
import chat.rocket.android.authentication.signup.presentation.SignupPresenter import chat.rocket.android.authentication.signup.presentation.SignupPresenter
import chat.rocket.android.authentication.signup.presentation.SignupView import chat.rocket.android.authentication.signup.presentation.SignupView
import chat.rocket.android.helper.AnimationHelper
import chat.rocket.android.util.setVisibility
import chat.rocket.android.util.textContent import chat.rocket.android.util.textContent
import dagger.android.support.AndroidSupportInjection import dagger.android.support.AndroidSupportInjection
import kotlinx.android.synthetic.main.fragment_authentication_sign_up.* import kotlinx.android.synthetic.main.fragment_authentication_sign_up.*
import javax.inject.Inject import javax.inject.Inject
class SignupFragment : Fragment(), SignupView { class SignupFragment : Fragment(), SignupView {
@Inject lateinit var presenter: SignupPresenter
lateinit var serverUrl: String
private val layoutListener = ViewTreeObserver.OnGlobalLayoutListener {
if (KeyboardHelper.isSoftKeyboardShown(constraint_layout.rootView)) {
text_new_user_agreement.visibility = View.GONE
} else {
text_new_user_agreement.visibility = View.VISIBLE
}
}
companion object { companion object {
private const val SERVER_URL = "server_url" private const val SERVER_URL = "server_url"
...@@ -28,11 +39,6 @@ class SignupFragment : Fragment(), SignupView { ...@@ -28,11 +39,6 @@ class SignupFragment : Fragment(), SignupView {
} }
} }
@Inject
lateinit var presenter: SignupPresenter
var progress: ProgressDialog? = null
lateinit var serverUrl: String
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
AndroidSupportInjection.inject(this) AndroidSupportInjection.inject(this)
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
...@@ -55,18 +61,31 @@ class SignupFragment : Fragment(), SignupView { ...@@ -55,18 +61,31 @@ class SignupFragment : Fragment(), SignupView {
setupGlobalLayoutListener() setupGlobalLayoutListener()
button_sign_up.setOnClickListener { button_sign_up.setOnClickListener {
val email = text_email.textContent presenter.signup(text_name, text_email, text_username, text_password)
val name = text_name.textContent
val username = text_username.textContent
val password = text_password.textContent
presenter.signup(email, name, username, password)
} }
} }
override fun onDestroyView() { override fun onDestroyView() {
constraint_layout.viewTreeObserver.removeOnGlobalLayoutListener(layoutListener)
super.onDestroyView() super.onDestroyView()
constraint_layout.viewTreeObserver.removeOnGlobalLayoutListener(layoutListener)
}
override fun showLoading() {
view_loading.setVisibility(true)
}
override fun hideLoading() {
view_loading.setVisibility(false)
}
override fun showMessage(message: String) {
Toast.makeText(activity, message, Toast.LENGTH_SHORT).show()
}
override fun shakeView(viewToShake: View) {
AnimationHelper.vibrate(viewToShake.context)
AnimationHelper.shakeView(viewToShake)
} }
private fun tintEditTextDrawableStart() { private fun tintEditTextDrawableStart() {
...@@ -86,31 +105,4 @@ class SignupFragment : Fragment(), SignupView { ...@@ -86,31 +105,4 @@ class SignupFragment : Fragment(), SignupView {
private fun setupGlobalLayoutListener() { private fun setupGlobalLayoutListener() {
constraint_layout.viewTreeObserver.addOnGlobalLayoutListener(layoutListener) constraint_layout.viewTreeObserver.addOnGlobalLayoutListener(layoutListener)
} }
val layoutListener = ViewTreeObserver.OnGlobalLayoutListener {
if (KeyboardHelper.isSoftKeyboardShown(constraint_layout.rootView)) {
text_new_user_agreement.visibility = View.GONE
} else {
text_new_user_agreement.visibility = View.VISIBLE
}
}
override fun showLoading() {
// TODO - change for a proper progress indicator
progress = ProgressDialog.show(activity, "Authenticating",
"Registering user", true, true)
}
override fun hideLoading() {
progress?.apply {
cancel()
}
progress = null
}
override fun onSignupError(message: String?) {
// TODO - show a proper error message
Toast.makeText(activity, message, Toast.LENGTH_LONG).show()
}
} }
\ No newline at end of file
package chat.rocket.android.authentication.twofactor.ui package chat.rocket.android.authentication.twofactor.ui
import DrawableHelper import DrawableHelper
import android.app.ProgressDialog
import android.os.Build import android.os.Build
import android.os.Bundle import android.os.Bundle
import android.support.v4.app.Fragment import android.support.v4.app.Fragment
...@@ -13,12 +12,18 @@ import android.widget.Toast ...@@ -13,12 +12,18 @@ import android.widget.Toast
import chat.rocket.android.R import chat.rocket.android.R
import chat.rocket.android.authentication.twofactor.presentation.TwoFAPresenter import chat.rocket.android.authentication.twofactor.presentation.TwoFAPresenter
import chat.rocket.android.authentication.twofactor.presentation.TwoFAView import chat.rocket.android.authentication.twofactor.presentation.TwoFAView
import chat.rocket.android.helper.AnimationHelper
import chat.rocket.android.util.setVisibility
import chat.rocket.android.util.textContent import chat.rocket.android.util.textContent
import dagger.android.support.AndroidSupportInjection import dagger.android.support.AndroidSupportInjection
import kotlinx.android.synthetic.main.fragment_authentication_two_fa.* import kotlinx.android.synthetic.main.fragment_authentication_two_fa.*
import javax.inject.Inject import javax.inject.Inject
class TwoFAFragment : Fragment(), TwoFAView { class TwoFAFragment : Fragment(), TwoFAView {
@Inject lateinit var presenter: TwoFAPresenter
lateinit var serverUrl: String
lateinit var username: String
lateinit var password: String
companion object { companion object {
private const val SERVER_URL = "server_url" private const val SERVER_URL = "server_url"
...@@ -34,14 +39,6 @@ class TwoFAFragment : Fragment(), TwoFAView { ...@@ -34,14 +39,6 @@ class TwoFAFragment : Fragment(), TwoFAView {
} }
} }
var progress: ProgressDialog? = null
lateinit var serverUrl: String
lateinit var username: String
lateinit var password: String
@Inject
lateinit var presenter: TwoFAPresenter
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
AndroidSupportInjection.inject(this) AndroidSupportInjection.inject(this)
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
...@@ -64,10 +61,27 @@ class TwoFAFragment : Fragment(), TwoFAView { ...@@ -64,10 +61,27 @@ class TwoFAFragment : Fragment(), TwoFAView {
} }
button_log_in.setOnClickListener { button_log_in.setOnClickListener {
presenter.authenticate(username, password, text_two_factor_auth.textContent) presenter.authenticate(username, password, text_two_factor_auth)
} }
} }
override fun showLoading() {
view_loading.setVisibility(true)
}
override fun hideLoading() {
view_loading.setVisibility(false)
}
override fun showMessage(message: String) {
Toast.makeText(activity, message, Toast.LENGTH_SHORT).show()
}
override fun shakeView(viewToShake: View) {
AnimationHelper.vibrate(viewToShake.context)
AnimationHelper.shakeView(viewToShake)
}
private fun tintEditTextDrawableStart() { private fun tintEditTextDrawableStart() {
activity?.applicationContext?.apply { activity?.applicationContext?.apply {
val lockDrawable = DrawableHelper.getDrawableFromId(R.drawable.ic_vpn_key_black_24dp, this) val lockDrawable = DrawableHelper.getDrawableFromId(R.drawable.ic_vpn_key_black_24dp, this)
...@@ -77,22 +91,4 @@ class TwoFAFragment : Fragment(), TwoFAView { ...@@ -77,22 +91,4 @@ class TwoFAFragment : Fragment(), TwoFAView {
DrawableHelper.compoundDrawable(text_two_factor_auth, lockDrawable) DrawableHelper.compoundDrawable(text_two_factor_auth, lockDrawable)
} }
} }
override fun showLoading() {
// TODO - change for a proper progress indicator
progress = ProgressDialog.show(activity, "Authenticating",
"Verifying user credentials", true, true)
}
override fun hideLoading() {
progress?.apply {
cancel()
}
progress = null
}
override fun showMessage(message: String) {
// TODO - show a proper error message
Toast.makeText(activity, message, Toast.LENGTH_LONG).show()
}
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment