Skip to content
Snippets Groups Projects
Commit 2eba483c authored by Taras's avatar Taras
Browse files

Remove context

parent 6d80051c
No related branches found
No related tags found
No related merge requests found
package org.futo.circles.auth.feature.uia package org.futo.circles.auth.feature.uia
import android.content.Context
import androidx.lifecycle.MutableLiveData import androidx.lifecycle.MutableLiveData
import org.futo.circles.auth.R
import org.futo.circles.auth.feature.uia.flow.LoginStagesDataSource import org.futo.circles.auth.feature.uia.flow.LoginStagesDataSource
import org.futo.circles.auth.feature.uia.flow.SignUpStagesDataSource import org.futo.circles.auth.feature.uia.flow.SignUpStagesDataSource
import org.futo.circles.auth.feature.uia.flow.reauth.ReAuthStagesDataSource import org.futo.circles.auth.feature.uia.flow.reauth.ReAuthStagesDataSource
import org.futo.circles.auth.model.UIAFlowType
import org.futo.circles.auth.model.UIANavigationEvent import org.futo.circles.auth.model.UIANavigationEvent
import org.futo.circles.core.base.SingleEventLiveData import org.futo.circles.core.base.SingleEventLiveData
import org.futo.circles.core.extensions.Response import org.futo.circles.core.extensions.Response
...@@ -18,7 +17,7 @@ import org.matrix.android.sdk.api.util.JsonDict ...@@ -18,7 +17,7 @@ import org.matrix.android.sdk.api.util.JsonDict
import javax.inject.Inject import javax.inject.Inject
import kotlin.coroutines.Continuation import kotlin.coroutines.Continuation
abstract class UIADataSource(private val context: Context) { abstract class UIADataSource {
class Factory @Inject constructor( class Factory @Inject constructor(
private val loginStagesDataSource: LoginStagesDataSource, private val loginStagesDataSource: LoginStagesDataSource,
...@@ -34,7 +33,7 @@ abstract class UIADataSource(private val context: Context) { ...@@ -34,7 +33,7 @@ abstract class UIADataSource(private val context: Context) {
} }
val subtitleLiveData = MutableLiveData<String>() val subtitleLiveData = MutableLiveData<Pair<Int, Int>>()
val navigationLiveData = SingleEventLiveData<UIANavigationEvent>() val navigationLiveData = SingleEventLiveData<UIANavigationEvent>()
val finishUIAEventLiveData = SingleEventLiveData<Session>() val finishUIAEventLiveData = SingleEventLiveData<Session>()
...@@ -107,9 +106,7 @@ abstract class UIADataSource(private val context: Context) { ...@@ -107,9 +106,7 @@ abstract class UIADataSource(private val context: Context) {
val event = when (val stage = currentStage) { val event = when (val stage = currentStage) {
is Stage.Terms -> UIANavigationEvent.AcceptTerm is Stage.Terms -> UIANavigationEvent.AcceptTerm
is Stage.Other -> handleStageOther(stage.type) is Stage.Other -> handleStageOther(stage.type)
else -> throw IllegalArgumentException( else -> throw IllegalArgumentException("Not supported stage $stage")
context.getString(R.string.not_supported_stage_format, stage.toString())
)
} }
event?.let { navigationLiveData.postValue(it) } event?.let { navigationLiveData.postValue(it) }
updatePageSubtitle() updatePageSubtitle()
...@@ -135,9 +132,8 @@ abstract class UIADataSource(private val context: Context) { ...@@ -135,9 +132,8 @@ abstract class UIADataSource(private val context: Context) {
REGISTRATION_BSSPEKE_SAVE_TYPE -> null REGISTRATION_BSSPEKE_SAVE_TYPE -> null
LOGIN_BSSPEKE_VERIFY_TYPE -> null LOGIN_BSSPEKE_VERIFY_TYPE -> null
else -> throw IllegalArgumentException( else -> throw IllegalArgumentException("Not supported stage $type")
context.getString(R.string.not_supported_stage_format, type)
)
} }
private fun getCurrentStageIndex() = private fun getCurrentStageIndex() =
...@@ -146,8 +142,7 @@ abstract class UIADataSource(private val context: Context) { ...@@ -146,8 +142,7 @@ abstract class UIADataSource(private val context: Context) {
private fun updatePageSubtitle() { private fun updatePageSubtitle() {
val size = stagesToComplete.size val size = stagesToComplete.size
val number = getCurrentStageIndex() + 1 val number = getCurrentStageIndex() + 1
val subtitle = context.getString(R.string.sign_up_stage_subtitle_format, number, size) subtitleLiveData.postValue(number to size)
subtitleLiveData.postValue(subtitle)
} }
companion object { companion object {
......
...@@ -15,6 +15,7 @@ import org.futo.circles.auth.databinding.DialogFragmentUiaBinding ...@@ -15,6 +15,7 @@ import org.futo.circles.auth.databinding.DialogFragmentUiaBinding
import org.futo.circles.auth.feature.pass_phrase.recovery.EnterPassPhraseDialog import org.futo.circles.auth.feature.pass_phrase.recovery.EnterPassPhraseDialog
import org.futo.circles.auth.feature.pass_phrase.recovery.EnterPassPhraseDialogListener import org.futo.circles.auth.feature.pass_phrase.recovery.EnterPassPhraseDialogListener
import org.futo.circles.auth.feature.uia.flow.reauth.ReAuthCancellationListener import org.futo.circles.auth.feature.uia.flow.reauth.ReAuthCancellationListener
import org.futo.circles.auth.model.UIAFlowType
import org.futo.circles.auth.model.UIANavigationEvent import org.futo.circles.auth.model.UIANavigationEvent
import org.futo.circles.core.base.NetworkObserver import org.futo.circles.core.base.NetworkObserver
import org.futo.circles.core.base.fragment.BackPressOwner import org.futo.circles.core.base.fragment.BackPressOwner
...@@ -78,8 +79,9 @@ class UIADialogFragment : ...@@ -78,8 +79,9 @@ class UIADialogFragment :
viewModel.navigationLiveData.observeData(this) { event -> viewModel.navigationLiveData.observeData(this) { event ->
handleNavigation(event) handleNavigation(event)
} }
viewModel.subtitleLiveData.observeData(this) { viewModel.subtitleLiveData.observeData(this) { (number, size) ->
binding.toolbar.subtitle = it binding.toolbar.subtitle =
getString(R.string.sign_up_stage_subtitle_format, number, size)
} }
viewModel.restoreKeysLiveData.observeResponse( viewModel.restoreKeysLiveData.observeResponse(
this, this,
......
package org.futo.circles.auth.feature.uia package org.futo.circles.auth.feature.uia
import android.net.Uri import android.net.Uri
import androidx.lifecycle.LiveData
import androidx.lifecycle.ViewModel import androidx.lifecycle.ViewModel
import dagger.hilt.android.lifecycle.HiltViewModel import dagger.hilt.android.lifecycle.HiltViewModel
import org.futo.circles.auth.R import org.futo.circles.auth.R
...@@ -33,7 +34,7 @@ class UIAViewModel @Inject constructor( ...@@ -33,7 +34,7 @@ class UIAViewModel @Inject constructor(
val uiaDataSource = UIADataSourceProvider.getDataSourceOrThrow() val uiaDataSource = UIADataSourceProvider.getDataSourceOrThrow()
val subtitleLiveData = uiaDataSource.subtitleLiveData val subtitleLiveData: LiveData<Pair<Int, Int>> = uiaDataSource.subtitleLiveData
val navigationLiveData = uiaDataSource.navigationLiveData val navigationLiveData = uiaDataSource.navigationLiveData
val restoreKeysLiveData = SingleEventLiveData<Response<Unit>>() val restoreKeysLiveData = SingleEventLiveData<Response<Unit>>()
val passPhraseLoadingLiveData = restoreBackupDataSource.loadingLiveData val passPhraseLoadingLiveData = restoreBackupDataSource.loadingLiveData
......
...@@ -16,7 +16,7 @@ import javax.inject.Singleton ...@@ -16,7 +16,7 @@ import javax.inject.Singleton
@Singleton @Singleton
class LoginStagesDataSource @Inject constructor( class LoginStagesDataSource @Inject constructor(
@ApplicationContext private val context: Context @ApplicationContext private val context: Context
) : UIADataSource(context) { ) : UIADataSource() {
var userPassword: String = "" var userPassword: String = ""
......
...@@ -15,7 +15,7 @@ import javax.inject.Singleton ...@@ -15,7 +15,7 @@ import javax.inject.Singleton
@Singleton @Singleton
class SignUpStagesDataSource @Inject constructor( class SignUpStagesDataSource @Inject constructor(
@ApplicationContext private val context: Context @ApplicationContext private val context: Context
) : UIADataSource(context) { ) : UIADataSource() {
override suspend fun performUIAStage( override suspend fun performUIAStage(
authParams: JsonDict, authParams: JsonDict,
......
package org.futo.circles.auth.feature.uia.flow.reauth package org.futo.circles.auth.feature.uia.flow.reauth
import android.content.Context
import dagger.hilt.android.qualifiers.ApplicationContext
import org.futo.circles.auth.feature.uia.UIADataSource import org.futo.circles.auth.feature.uia.UIADataSource
import org.futo.circles.auth.model.CustomUIAuth import org.futo.circles.auth.model.CustomUIAuth
import org.futo.circles.core.extensions.Response import org.futo.circles.core.extensions.Response
...@@ -19,9 +17,7 @@ import kotlin.coroutines.resume ...@@ -19,9 +17,7 @@ import kotlin.coroutines.resume
import kotlin.coroutines.suspendCoroutine import kotlin.coroutines.suspendCoroutine
@Singleton @Singleton
class ReAuthStagesDataSource @Inject constructor( class ReAuthStagesDataSource @Inject constructor() : UIADataSource() {
@ApplicationContext context: Context,
) : UIADataSource(context) {
private var authPromise: Continuation<UIABaseAuth>? = null private var authPromise: Continuation<UIABaseAuth>? = null
private var sessionId: String = "" private var sessionId: String = ""
......
...@@ -16,7 +16,6 @@ ...@@ -16,7 +16,6 @@
<string name="eu_server_format"><![CDATA[<b>EU</b> - (%s)]]></string> <string name="eu_server_format"><![CDATA[<b>EU</b> - (%s)]]></string>
<string name="sign_up_using_active_subscription">Sign Up using your active subscription</string> <string name="sign_up_using_active_subscription">Sign Up using your active subscription</string>
<string name="sign_up">Sign Up</string> <string name="sign_up">Sign Up</string>
<string name="not_supported_stage_format">Not supported stage %s</string>
<string name="sign_up_stage_subtitle_format">Stage %1$d of %2$d</string> <string name="sign_up_stage_subtitle_format">Stage %1$d of %2$d</string>
<string name="no_backup_message">Keys backup not found</string> <string name="no_backup_message">Keys backup not found</string>
<string name="username_can_not_be_empty">Username can not be empty.</string> <string name="username_can_not_be_empty">Username can not be empty.</string>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment