Commit 7e52ba15 authored by Filipe de Lima Brito's avatar Filipe de Lima Brito

Fix login with deep link and activity lifecycle

parent 1a427032
...@@ -22,6 +22,8 @@ import kotlinx.android.synthetic.main.app_bar.* ...@@ -22,6 +22,8 @@ import kotlinx.android.synthetic.main.app_bar.*
import kotlinx.android.synthetic.main.fragment_authentication_on_boarding.* import kotlinx.android.synthetic.main.fragment_authentication_on_boarding.*
import javax.inject.Inject import javax.inject.Inject
fun newInstance() = OnBoardingFragment()
class OnBoardingFragment : Fragment(), OnBoardingView { class OnBoardingFragment : Fragment(), OnBoardingView {
@Inject @Inject
lateinit var presenter: OnBoardingPresenter lateinit var presenter: OnBoardingPresenter
...@@ -102,8 +104,4 @@ class OnBoardingFragment : Fragment(), OnBoardingView { ...@@ -102,8 +104,4 @@ class OnBoardingFragment : Fragment(), OnBoardingView {
getString(R.string.create_server_url) getString(R.string.create_server_url)
) )
} }
companion object {
fun newInstance() = OnBoardingFragment()
}
} }
...@@ -5,7 +5,6 @@ import chat.rocket.android.R ...@@ -5,7 +5,6 @@ import chat.rocket.android.R
import chat.rocket.android.analytics.event.ScreenViewEvent import chat.rocket.android.analytics.event.ScreenViewEvent
import chat.rocket.android.authentication.domain.model.LoginDeepLinkInfo import chat.rocket.android.authentication.domain.model.LoginDeepLinkInfo
import chat.rocket.android.authentication.ui.AuthenticationActivity import chat.rocket.android.authentication.ui.AuthenticationActivity
import chat.rocket.android.authentication.ui.newServerIntent
import chat.rocket.android.main.ui.MainActivity import chat.rocket.android.main.ui.MainActivity
import chat.rocket.android.server.ui.changeServerIntent import chat.rocket.android.server.ui.changeServerIntent
import chat.rocket.android.util.extensions.addFragmentBackStack import chat.rocket.android.util.extensions.addFragmentBackStack
...@@ -83,9 +82,4 @@ class AuthenticationNavigator(internal val activity: AuthenticationActivity) { ...@@ -83,9 +82,4 @@ class AuthenticationNavigator(internal val activity: AuthenticationActivity) {
activity.startActivity(activity.changeServerIntent(serverUrl)) activity.startActivity(activity.changeServerIntent(serverUrl))
activity.finish() activity.finish()
} }
fun toServerScreen() {
activity.startActivity(activity.newServerIntent())
activity.finish()
}
} }
...@@ -42,7 +42,6 @@ class AuthenticationPresenter @Inject constructor( ...@@ -42,7 +42,6 @@ class AuthenticationPresenter @Inject constructor(
callback(false) callback(false)
} else { } else {
callback(true) callback(true)
navigator.toChatList()
} }
} }
} }
...@@ -52,4 +51,6 @@ class AuthenticationPresenter @Inject constructor( ...@@ -52,4 +51,6 @@ class AuthenticationPresenter @Inject constructor(
fun privacyPolicy(toolbarTitle: String) = fun privacyPolicy(toolbarTitle: String) =
serverInteractor.get()?.let { navigator.toWebPage(it.privacyPolicyUrl(), toolbarTitle) } serverInteractor.get()?.let { navigator.toWebPage(it.privacyPolicyUrl(), toolbarTitle) }
fun toChatList() = navigator.toChatList()
} }
\ No newline at end of file
...@@ -64,9 +64,7 @@ class ServerPresenter @Inject constructor( ...@@ -64,9 +64,7 @@ class ServerPresenter @Inject constructor(
fun deepLink(deepLinkInfo: LoginDeepLinkInfo) { fun deepLink(deepLinkInfo: LoginDeepLinkInfo) {
connectToServer(deepLinkInfo.url) { connectToServer(deepLinkInfo.url) {
navigator.toLoginOptions( navigator.toLoginOptions(deepLinkInfo.url, deepLinkInfo)
deepLinkInfo.url, deepLinkInfo
)
} }
} }
} }
\ No newline at end of file
...@@ -9,14 +9,17 @@ import androidx.appcompat.app.AppCompatActivity ...@@ -9,14 +9,17 @@ import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import chat.rocket.android.R import chat.rocket.android.R
import chat.rocket.android.analytics.event.ScreenViewEvent import chat.rocket.android.analytics.event.ScreenViewEvent
import chat.rocket.android.authentication.onboarding.ui.OnBoardingFragment import chat.rocket.android.authentication.domain.model.LoginDeepLinkInfo
import chat.rocket.android.authentication.domain.model.getLoginDeepLinkInfo
import chat.rocket.android.authentication.presentation.AuthenticationPresenter import chat.rocket.android.authentication.presentation.AuthenticationPresenter
import chat.rocket.android.util.extensions.addFragment import chat.rocket.android.util.extensions.addFragment
import chat.rocket.common.util.ifNull
import dagger.android.AndroidInjection import dagger.android.AndroidInjection
import dagger.android.AndroidInjector import dagger.android.AndroidInjector
import dagger.android.DispatchingAndroidInjector import dagger.android.DispatchingAndroidInjector
import dagger.android.support.HasSupportFragmentInjector import dagger.android.support.HasSupportFragmentInjector
import kotlinx.android.synthetic.main.app_bar.* import kotlinx.android.synthetic.main.app_bar.*
import kotlinx.coroutines.experimental.Job
import javax.inject.Inject import javax.inject.Inject
class AuthenticationActivity : AppCompatActivity(), HasSupportFragmentInjector { class AuthenticationActivity : AppCompatActivity(), HasSupportFragmentInjector {
...@@ -24,12 +27,14 @@ class AuthenticationActivity : AppCompatActivity(), HasSupportFragmentInjector { ...@@ -24,12 +27,14 @@ class AuthenticationActivity : AppCompatActivity(), HasSupportFragmentInjector {
lateinit var fragmentDispatchingAndroidInjector: DispatchingAndroidInjector<Fragment> lateinit var fragmentDispatchingAndroidInjector: DispatchingAndroidInjector<Fragment>
@Inject @Inject
lateinit var presenter: AuthenticationPresenter lateinit var presenter: AuthenticationPresenter
val job = Job()
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
AndroidInjection.inject(this) AndroidInjection.inject(this)
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
setContentView(R.layout.activity_authentication) setContentView(R.layout.activity_authentication)
setupToolbar() setupToolbar()
loadCredentials()
} }
private fun setupToolbar() { private fun setupToolbar() {
...@@ -41,11 +46,6 @@ class AuthenticationActivity : AppCompatActivity(), HasSupportFragmentInjector { ...@@ -41,11 +46,6 @@ class AuthenticationActivity : AppCompatActivity(), HasSupportFragmentInjector {
supportActionBar?.setDisplayShowTitleEnabled(false) supportActionBar?.setDisplayShowTitleEnabled(false)
} }
override fun onStart() {
super.onStart()
loadCredentials()
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data) super.onActivityResult(requestCode, resultCode, data)
val currentFragment = supportFragmentManager.findFragmentById(R.id.fragment_container) val currentFragment = supportFragmentManager.findFragmentById(R.id.fragment_container)
...@@ -69,23 +69,41 @@ class AuthenticationActivity : AppCompatActivity(), HasSupportFragmentInjector { ...@@ -69,23 +69,41 @@ class AuthenticationActivity : AppCompatActivity(), HasSupportFragmentInjector {
} }
private fun loadCredentials() { private fun loadCredentials() {
val newServer = intent.getBooleanExtra(INTENT_ADD_NEW_SERVER, false) intent.getLoginDeepLinkInfo()?.let {
presenter.loadCredentials(newServer) { isAuthenticated -> showServerFragment(it)
if (!isAuthenticated) { }.ifNull {
showOnBoarding() val newServer = intent.getBooleanExtra(INTENT_ADD_NEW_SERVER, false)
presenter.loadCredentials(newServer) { isAuthenticated ->
if (isAuthenticated) {
showChatList()
} else {
showOnBoardingFragment()
}
} }
} }
} }
private fun showOnBoarding() { private fun showOnBoardingFragment() {
addFragment( addFragment(
ScreenViewEvent.OnBoarding.screenName, ScreenViewEvent.OnBoarding.screenName,
R.id.fragment_container, R.id.fragment_container,
allowStateLoss = true allowStateLoss = true
) { ) {
OnBoardingFragment.newInstance() chat.rocket.android.authentication.onboarding.ui.newInstance()
}
}
private fun showServerFragment(deepLinkInfo: LoginDeepLinkInfo) {
addFragment(
ScreenViewEvent.Server.screenName,
R.id.fragment_container,
allowStateLoss = true
) {
chat.rocket.android.authentication.server.ui.newInstance(deepLinkInfo)
} }
} }
private fun showChatList() = presenter.toChatList()
} }
const val INTENT_ADD_NEW_SERVER = "INTENT_ADD_NEW_SERVER" const val INTENT_ADD_NEW_SERVER = "INTENT_ADD_NEW_SERVER"
......
...@@ -27,7 +27,8 @@ fun View.fadeIn(startValue: Float = 0f, finishValue: Float = 1f, duration: Long ...@@ -27,7 +27,8 @@ fun View.fadeIn(startValue: Float = 0f, finishValue: Float = 1f, duration: Long
animate() animate()
.alpha(finishValue) .alpha(finishValue)
.setDuration(duration / 2) .setDuration(duration / 2)
.setInterpolator(AccelerateInterpolator()).start() .setInterpolator(AccelerateInterpolator())
.start()
}.start() }.start()
isVisible = true isVisible = true
...@@ -47,7 +48,8 @@ fun View.fadeOut(startValue: Float = 1f, finishValue: Float = 0f, duration: Long ...@@ -47,7 +48,8 @@ fun View.fadeOut(startValue: Float = 1f, finishValue: Float = 0f, duration: Long
animate() animate()
.alpha(finishValue) .alpha(finishValue)
.setDuration(duration) .setDuration(duration)
.setInterpolator(AccelerateInterpolator()).start() .setInterpolator(AccelerateInterpolator())
.start()
}.start() }.start()
isVisible = false isVisible = false
......
...@@ -3,10 +3,8 @@ package chat.rocket.android.util.extensions ...@@ -3,10 +3,8 @@ package chat.rocket.android.util.extensions
import chat.rocket.android.server.domain.model.Account import chat.rocket.android.server.domain.model.Account
import chat.rocket.android.server.infraestructure.RocketChatClientFactory import chat.rocket.android.server.infraestructure.RocketChatClientFactory
import chat.rocket.android.util.retryIO import chat.rocket.android.util.retryIO
import chat.rocket.core.RocketChatClient
import chat.rocket.core.internal.rest.registerPushToken import chat.rocket.core.internal.rest.registerPushToken
import kotlinx.coroutines.experimental.CommonPool import kotlinx.coroutines.experimental.CommonPool
import kotlinx.coroutines.experimental.launch
import kotlinx.coroutines.experimental.withContext import kotlinx.coroutines.experimental.withContext
import timber.log.Timber import timber.log.Timber
......
...@@ -33,9 +33,11 @@ ...@@ -33,9 +33,11 @@
android:textAllCaps="false" android:textAllCaps="false"
android:textColor="@color/colorPrimary" android:textColor="@color/colorPrimary"
android:textSize="16sp" android:textSize="16sp"
android:visibility="gone"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintTop_toTopOf="parent"
tools:visibility="visible" />
<Button <Button
android:id="@+id/button_github" android:id="@+id/button_github"
...@@ -53,9 +55,11 @@ ...@@ -53,9 +55,11 @@
android:textAllCaps="false" android:textAllCaps="false"
android:textColor="@color/colorPrimary" android:textColor="@color/colorPrimary"
android:textSize="16sp" android:textSize="16sp"
android:visibility="gone"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/button_facebook" /> app:layout_constraintTop_toBottomOf="@+id/button_facebook"
tools:visibility="visible" />
<Button <Button
android:id="@+id/button_google" android:id="@+id/button_google"
...@@ -73,9 +77,11 @@ ...@@ -73,9 +77,11 @@
android:textAllCaps="false" android:textAllCaps="false"
android:textColor="@color/colorPrimary" android:textColor="@color/colorPrimary"
android:textSize="16sp" android:textSize="16sp"
android:visibility="gone"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/button_github" /> app:layout_constraintTop_toBottomOf="@+id/button_github"
tools:visibility="visible" />
<Button <Button
android:id="@+id/button_linkedin" android:id="@+id/button_linkedin"
......
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