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