Skip to content

Commit

Permalink
Exit objective screen with result
Browse files Browse the repository at this point in the history
  • Loading branch information
irfano committed Oct 15, 2024
1 parent 9e6fec2 commit 3f22f83
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.viewModels
import androidx.navigation.fragment.findNavController
import com.woocommerce.android.extensions.navigateBackWithResult
import com.woocommerce.android.ui.base.BaseFragment
import com.woocommerce.android.ui.compose.composeView
import com.woocommerce.android.ui.main.AppBarStatus
import com.woocommerce.android.viewmodel.MultiLiveEvent
import com.woocommerce.android.viewmodel.MultiLiveEvent.Event.ExitWithResult
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
Expand All @@ -33,7 +35,12 @@ class BlazeCampaignObjectiveFragment : BaseFragment() {
viewModel.event.observe(viewLifecycleOwner) { event ->
when (event) {
is MultiLiveEvent.Event.Exit -> findNavController().navigateUp()
is ExitWithResult<*> -> navigateBackWithResult(BLAZE_OBJECTIVE_SELECTION_RESULT, event.data)
}
}
}

companion object {
const val BLAZE_OBJECTIVE_SELECTION_RESULT = "blaze_objective_selection_result"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import androidx.lifecycle.asLiveData
import androidx.lifecycle.viewModelScope
import com.woocommerce.android.ui.blaze.BlazeRepository
import com.woocommerce.android.viewmodel.MultiLiveEvent.Event.Exit
import com.woocommerce.android.viewmodel.MultiLiveEvent.Event.ExitWithResult
import com.woocommerce.android.viewmodel.ScopedViewModel
import com.woocommerce.android.viewmodel.getNullableStateFlow
import com.woocommerce.android.viewmodel.navArgs
Expand All @@ -14,6 +15,7 @@ import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.update
import kotlinx.parcelize.Parcelize
import javax.inject.Inject

@HiltViewModel
Expand Down Expand Up @@ -49,6 +51,9 @@ class BlazeCampaignObjectiveViewModel @Inject constructor(
}

fun onSaveTapped() {
selectedId.value?.let { triggerEvent(ExitWithResult(ObjectiveResult(it))) }
TODO("Track")
// analyticsTrackerWrapper.track(BLAZE_...)
}

data class ObjectiveViewState(
Expand All @@ -66,4 +71,7 @@ class BlazeCampaignObjectiveViewModel @Inject constructor(
val description: String,
val suitableForDescription: String,
)

@Parcelize
data class ObjectiveResult(val objectiveId: String) : Parcelable
}
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ class BlazeCampaignCreationPreviewFragment : BaseFragment() {
handleResult<EditAdResult>(BlazeCampaignCreationEditAdFragment.EDIT_AD_RESULT) {
viewModel.onAdUpdated(it.tagline, it.description, it.campaignImage)
}
handleResult<ObjectiveResult>(BlazeCampaignObjectiveFragment.BLAZE_OBJECTIVE_SELECTION_RESULT) {
viewModel.onObjectiveUpdated(it.objectiveId)
}
handleResult<Budget>(BlazeCampaignBudgetFragment.EDIT_BUDGET_AND_DURATION_RESULT) {
viewModel.onBudgetAndDurationUpdated(it)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ class BlazeCampaignCreationPreviewViewModel @Inject constructor(
}
}

fun onObjectiveUpdated(objectiveId: String) {
campaignDetails.update { it?.copy(objectiveId = objectiveId) }
}

fun onBudgetAndDurationUpdated(updatedBudget: BlazeRepository.Budget) {
campaignDetails.update { it?.copy(budget = updatedBudget) }
}
Expand Down

0 comments on commit 3f22f83

Please sign in to comment.