Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plans in site creation: Plan selection screen #19304

Merged
merged 27 commits into from
Oct 15, 2023
Merged
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
5442558
Update SiteCreationStep.kt
ravishanker Oct 5, 2023
ad2692a
Create SiteCreationPlansUiState.kt
ravishanker Oct 5, 2023
012d532
Create SiteCreationPlansWebViewClient.kt
ravishanker Oct 5, 2023
363aa9a
Update strings.xml
ravishanker Oct 5, 2023
7ca8666
Update SiteCreationMainVM.kt
ravishanker Oct 5, 2023
71969f0
Create SiteCreationPlansFragment.kt
ravishanker Oct 5, 2023
8e68b03
Create SiteCreationPlansViewModel.kt
ravishanker Oct 5, 2023
3f62e76
Update SiteCreationActivity.kt
ravishanker Oct 5, 2023
62c0f59
Add params to request
ravishanker Oct 6, 2023
3b54c20
Merge branch 'trunk' into Plans-in-site-creation-Plan-Selection-Screen
ravishanker Oct 8, 2023
fb4dbd7
Detect plan selection in site creation flow
irfano Oct 12, 2023
68559c3
Update SiteCreationPlansViewModel.kt
ravishanker Oct 13, 2023
44c8e2b
Update SiteCreationPlansWebViewClient.kt
ravishanker Oct 13, 2023
3cf4396
Update DomainRegistrationCheckoutWebViewNavigationDelegate.kt
ravishanker Oct 13, 2023
fc30b40
Update SiteCreationProgressViewModel.kt
ravishanker Oct 13, 2023
b91069b
Remove unused
ravishanker Oct 13, 2023
7b80db6
Update SiteCreationFixtures.kt
ravishanker Oct 13, 2023
69fb18b
Create PlansScreenListener.kt
ravishanker Oct 13, 2023
fac06f3
Update SiteCreationPlansWebViewClient.kt
ravishanker Oct 13, 2023
f336392
Update SiteCreationPlansViewModel.kt
ravishanker Oct 13, 2023
8356847
Update SiteCreationPlansFragment.kt
ravishanker Oct 13, 2023
b92f5a8
Update SiteCreationActivity.kt
ravishanker Oct 13, 2023
a5ac692
Update SiteCreationMainVM.kt
ravishanker Oct 13, 2023
63015e7
Update SiteCreationPlansWebViewClient.kt
ravishanker Oct 14, 2023
b094d59
Update SiteCreationPlansViewModel.kt
ravishanker Oct 14, 2023
782b7b4
Update SiteCreationProgressViewModel.kt
ravishanker Oct 14, 2023
05d9682
handle free plan selection
ravishanker Oct 15, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update SiteCreationPlansViewModel.kt
  • Loading branch information
ravishanker committed Oct 13, 2023
commit f336392eb3e0a6cbd2bf2bbde603c7454c5028cb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import android.text.TextUtils
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.receiveAsFlow
import kotlinx.coroutines.launch
import org.wordpress.android.WordPress
import org.wordpress.android.fluxc.model.SiteModel
Expand All @@ -28,15 +30,27 @@ class SiteCreationPlansViewModel @Inject constructor(
private val _uiState = MutableStateFlow<SiteCreationPlansUiState>(SiteCreationPlansUiState.Preparing)
val uiState = _uiState as StateFlow<SiteCreationPlansUiState>

private val _actionEvents = Channel<SiteCreationPlansActionEvent>(Channel.BUFFERED)
val actionEvents = _actionEvents.receiveAsFlow()

private lateinit var domainName: DomainModel

fun start(siteCreationState: SiteCreationState) {
domainName = requireNotNull(siteCreationState.domain)
showPlans()
}

fun onPlanSelected(url: String) {
AppLog.d(AppLog.T.PLANS, url)
fun onPlanSelected(uri: Uri) {
AppLog.d(AppLog.T.PLANS, uri.toString())

val planModel = PlanModel(
productId = uri.getQueryParameter(PLAN_ID_PARAM)?.toInt(),
productSlug = uri.getQueryParameter(PLAN_SLUG_PARAM),
productName = "",
isCurrentPlan = false,
hasDomainCredit = false
)
postActionEvent(SiteCreationPlansActionEvent.CreateSite(planModel))
}

fun onUrlLoaded() {
Expand Down Expand Up @@ -135,6 +149,12 @@ class SiteCreationPlansViewModel @Inject constructor(
}
}

private fun postActionEvent(actionEvent: SiteCreationPlansActionEvent) {
viewModelScope.launch {
_actionEvents.send(actionEvent)
}
}

companion object {
const val WPCOM_LOGIN_URL = "https://wordpress.com/wp-login.php"
const val WPCOM_DOMAIN = ".wordpress.com"
Expand All @@ -150,6 +170,5 @@ class SiteCreationPlansViewModel @Inject constructor(
}

sealed class SiteCreationPlansActionEvent {
object FinishActivity : SiteCreationPlansActionEvent()
data class LaunchExternalBrowser(val url: String) : SiteCreationPlansActionEvent()
data class CreateSite(val planModel: PlanModel) : SiteCreationPlansActionEvent()
}