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

Remove context from presenter and create InternetView interface

parent f5a13b4e
...@@ -2,6 +2,7 @@ package chat.rocket.android.authentication.login.presentation ...@@ -2,6 +2,7 @@ package chat.rocket.android.authentication.login.presentation
import chat.rocket.android.authentication.presentation.AuthenticationNavigator import chat.rocket.android.authentication.presentation.AuthenticationNavigator
import chat.rocket.android.core.lifecycle.CancelStrategy import chat.rocket.android.core.lifecycle.CancelStrategy
import chat.rocket.android.helper.NetworkHelper
import chat.rocket.android.util.launchUI import chat.rocket.android.util.launchUI
import chat.rocket.common.RocketChatException import chat.rocket.common.RocketChatException
import chat.rocket.common.RocketChatTwoFactorException import chat.rocket.common.RocketChatTwoFactorException
...@@ -26,6 +27,7 @@ class LoginPresenter @Inject constructor(private val view: LoginView, ...@@ -26,6 +27,7 @@ class LoginPresenter @Inject constructor(private val view: LoginView,
else -> { else -> {
launchUI(strategy) { launchUI(strategy) {
view.showLoading() view.showLoading()
if (NetworkHelper.hasInternetAccess()) {
try { try {
val token = client.login(usernameOrEmail, password) val token = client.login(usernameOrEmail, password)
Timber.d("Created token: $token") Timber.d("Created token: $token")
...@@ -45,6 +47,9 @@ class LoginPresenter @Inject constructor(private val view: LoginView, ...@@ -45,6 +47,9 @@ class LoginPresenter @Inject constructor(private val view: LoginView,
} finally { } finally {
view.hideLoading() view.hideLoading()
} }
} else {
view.showNoInternetConnection()
}
} }
} }
} }
......
package chat.rocket.android.authentication.login.presentation package chat.rocket.android.authentication.login.presentation
import chat.rocket.android.core.behaviours.InternetView
import chat.rocket.android.core.behaviours.LoadingView import chat.rocket.android.core.behaviours.LoadingView
import chat.rocket.android.core.behaviours.MessageView import chat.rocket.android.core.behaviours.MessageView
interface LoginView : LoadingView, MessageView { interface LoginView : LoadingView, MessageView, InternetView {
/** /**
* Shows the oauth view if the server settings allow the login via social accounts. * Shows the oauth view if the server settings allow the login via social accounts.
......
...@@ -182,6 +182,10 @@ class LoginFragment : Fragment(), LoginView { ...@@ -182,6 +182,10 @@ class LoginFragment : Fragment(), LoginView {
Toast.makeText(activity, message, Toast.LENGTH_SHORT).show() Toast.makeText(activity, message, Toast.LENGTH_SHORT).show()
} }
override fun showNoInternetConnection() {
Toast.makeText(activity, getString(R.string.msg_no_internet_connection), Toast.LENGTH_SHORT).show()
}
private fun tintEditTextDrawableStart() { private fun tintEditTextDrawableStart() {
activity?.applicationContext?.apply { activity?.applicationContext?.apply {
val personDrawable = DrawableHelper.getDrawableFromId(R.drawable.ic_assignment_ind_black_24dp, this) val personDrawable = DrawableHelper.getDrawableFromId(R.drawable.ic_assignment_ind_black_24dp, this)
......
package chat.rocket.android.authentication.server.presentation package chat.rocket.android.authentication.server.presentation
import android.content.Context
import chat.rocket.android.R
import chat.rocket.android.authentication.presentation.AuthenticationNavigator import chat.rocket.android.authentication.presentation.AuthenticationNavigator
import chat.rocket.android.core.lifecycle.CancelStrategy import chat.rocket.android.core.lifecycle.CancelStrategy
import chat.rocket.android.helper.NetworkHelper import chat.rocket.android.helper.NetworkHelper
...@@ -14,7 +12,7 @@ class ServerPresenter @Inject constructor(private val view: ServerView, ...@@ -14,7 +12,7 @@ class ServerPresenter @Inject constructor(private val view: ServerView,
private val navigator: AuthenticationNavigator) { private val navigator: AuthenticationNavigator) {
@Inject lateinit var client: RocketChatClient @Inject lateinit var client: RocketChatClient
fun connect(context: Context, server: String) { fun connect(server: String) {
launchUI(strategy) { launchUI(strategy) {
if (NetworkHelper.hasInternetAccess()) { if (NetworkHelper.hasInternetAccess()) {
view.showLoading() view.showLoading()
...@@ -25,7 +23,7 @@ class ServerPresenter @Inject constructor(private val view: ServerView, ...@@ -25,7 +23,7 @@ class ServerPresenter @Inject constructor(private val view: ServerView,
view.hideLoading() view.hideLoading()
navigator.toLogin(server) navigator.toLogin(server)
} else { } else {
view.showMessage(context.getString(R.string.msg_no_internet_connection)) view.showNoInternetConnection()
} }
} }
} }
......
package chat.rocket.android.authentication.server.presentation package chat.rocket.android.authentication.server.presentation
import chat.rocket.android.core.behaviours.InternetView
import chat.rocket.android.core.behaviours.LoadingView import chat.rocket.android.core.behaviours.LoadingView
import chat.rocket.android.core.behaviours.MessageView import chat.rocket.android.core.behaviours.MessageView
interface ServerView : LoadingView, MessageView interface ServerView : LoadingView, MessageView, InternetView
\ No newline at end of file \ No newline at end of file
...@@ -43,7 +43,7 @@ class ServerFragment : Fragment(), ServerView { ...@@ -43,7 +43,7 @@ class ServerFragment : Fragment(), ServerView {
activity?.applicationContext?.apply { activity?.applicationContext?.apply {
button_connect.setOnClickListener { button_connect.setOnClickListener {
val url = text_server_url.textContent.ifEmpty(text_server_url.hintContent) val url = text_server_url.textContent.ifEmpty(text_server_url.hintContent)
presenter.connect(this, text_server_protocol.textContent + url) presenter.connect(text_server_protocol.textContent + url)
} }
} }
} }
...@@ -68,4 +68,8 @@ class ServerFragment : Fragment(), ServerView { ...@@ -68,4 +68,8 @@ class ServerFragment : Fragment(), ServerView {
override fun showMessage(message: String) { override fun showMessage(message: String) {
Toast.makeText(activity, message, Toast.LENGTH_SHORT).show() Toast.makeText(activity, message, Toast.LENGTH_SHORT).show()
} }
override fun showNoInternetConnection() {
Toast.makeText(activity, getString(R.string.msg_no_internet_connection), Toast.LENGTH_SHORT).show()
}
} }
\ No newline at end of file
...@@ -2,6 +2,7 @@ package chat.rocket.android.authentication.signup.presentation ...@@ -2,6 +2,7 @@ package chat.rocket.android.authentication.signup.presentation
import chat.rocket.android.authentication.presentation.AuthenticationNavigator import chat.rocket.android.authentication.presentation.AuthenticationNavigator
import chat.rocket.android.core.lifecycle.CancelStrategy import chat.rocket.android.core.lifecycle.CancelStrategy
import chat.rocket.android.helper.NetworkHelper
import chat.rocket.android.util.launchUI import chat.rocket.android.util.launchUI
import chat.rocket.common.RocketChatException import chat.rocket.common.RocketChatException
import chat.rocket.core.RocketChatClient import chat.rocket.core.RocketChatClient
...@@ -31,6 +32,7 @@ class SignupPresenter @Inject constructor(private val view: SignupView, ...@@ -31,6 +32,7 @@ class SignupPresenter @Inject constructor(private val view: SignupView,
} }
else -> { else -> {
launchUI(strategy) { launchUI(strategy) {
if (NetworkHelper.hasInternetAccess()) {
view.showLoading() view.showLoading()
try { try {
val user = client.signup(email, name, username, password) val user = client.signup(email, name, username, password)
...@@ -48,6 +50,9 @@ class SignupPresenter @Inject constructor(private val view: SignupView, ...@@ -48,6 +50,9 @@ class SignupPresenter @Inject constructor(private val view: SignupView,
} finally { } finally {
view.hideLoading() view.hideLoading()
} }
} else {
view.showNoInternetConnection()
}
} }
} }
} }
......
package chat.rocket.android.authentication.signup.presentation package chat.rocket.android.authentication.signup.presentation
import chat.rocket.android.core.behaviours.InternetView
import chat.rocket.android.core.behaviours.LoadingView import chat.rocket.android.core.behaviours.LoadingView
import chat.rocket.android.core.behaviours.MessageView import chat.rocket.android.core.behaviours.MessageView
interface SignupView : LoadingView, MessageView { interface SignupView : LoadingView, MessageView, InternetView {
/** /**
* Alerts the user about a blank name. * Alerts the user about a blank name.
......
...@@ -116,6 +116,10 @@ class SignupFragment : Fragment(), SignupView { ...@@ -116,6 +116,10 @@ class SignupFragment : Fragment(), SignupView {
Toast.makeText(activity, message, Toast.LENGTH_SHORT).show() Toast.makeText(activity, message, Toast.LENGTH_SHORT).show()
} }
override fun showNoInternetConnection() {
Toast.makeText(activity, getString(R.string.msg_no_internet_connection), Toast.LENGTH_SHORT).show()
}
private fun tintEditTextDrawableStart() { private fun tintEditTextDrawableStart() {
val personDrawable = DrawableHelper.getDrawableFromId(R.drawable.ic_person_black_24dp, appContext) val personDrawable = DrawableHelper.getDrawableFromId(R.drawable.ic_person_black_24dp, appContext)
val atDrawable = DrawableHelper.getDrawableFromId(R.drawable.ic_at_black_24dp, appContext) val atDrawable = DrawableHelper.getDrawableFromId(R.drawable.ic_at_black_24dp, appContext)
......
package chat.rocket.android.authentication.twofactor.presentation package chat.rocket.android.authentication.twofactor.presentation
import chat.rocket.android.core.behaviours.InternetView
import chat.rocket.android.core.behaviours.LoadingView import chat.rocket.android.core.behaviours.LoadingView
import chat.rocket.android.core.behaviours.MessageView import chat.rocket.android.core.behaviours.MessageView
interface TwoFAView : LoadingView, MessageView { interface TwoFAView : LoadingView, MessageView, InternetView {
/** /**
* Alerts the user about a blank two factor authentication code. * Alerts the user about a blank two factor authentication code.
......
...@@ -84,6 +84,10 @@ class TwoFAFragment : Fragment(), TwoFAView { ...@@ -84,6 +84,10 @@ class TwoFAFragment : Fragment(), TwoFAView {
Toast.makeText(activity, message, Toast.LENGTH_SHORT).show() Toast.makeText(activity, message, Toast.LENGTH_SHORT).show()
} }
override fun showNoInternetConnection() {
Toast.makeText(activity, getString(R.string.msg_no_internet_connection), Toast.LENGTH_SHORT).show()
}
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)
......
package chat.rocket.android.core.behaviours
interface InternetView {
fun showNoInternetConnection()
}
\ No newline at end of file
package chat.rocket.android.core.behaviours package chat.rocket.android.core.behaviours
interface LoadingView { interface LoadingView {
fun showLoading() fun showLoading()
fun hideLoading() fun hideLoading()
} }
\ No newline at end of file
package chat.rocket.android.core.behaviours package chat.rocket.android.core.behaviours
interface MessageView { interface MessageView {
fun showMessage(message: String) fun showMessage(message: String)
} }
\ 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