Skip to content

Commit

Permalink
Merge pull request #20107 from wordpress-mobile/issue/19051-blaze-cam…
Browse files Browse the repository at this point in the history
…paigns-null-pointer-exception

Fixes: Campaign listing viewmodel crash on returning from background
  • Loading branch information
AjeshRPai authored Feb 2, 2024
2 parents 6621e43 + d1cdbf1 commit 7ee1ff0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ class CampaignListingFragment : Fragment() {
}
}
}
viewModel.onSelectedSiteMissing.observe(viewLifecycleOwner) {
requireActivity().finish()
}
}

private fun getPageSource(): CampaignListingPageSource {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.asSharedFlow
import org.wordpress.android.Result
import org.wordpress.android.R
import org.wordpress.android.Result
import org.wordpress.android.fluxc.model.SiteModel
import org.wordpress.android.modules.BG_THREAD
import org.wordpress.android.ui.blaze.BlazeFeatureUtils
Expand Down Expand Up @@ -47,12 +47,20 @@ class CampaignListingViewModel @Inject constructor(
private val _snackbar = MutableSharedFlow<String>()
val snackBar = _snackbar.asSharedFlow()

private val _onSelectedSiteMissing = MutableLiveData<Unit>()
val onSelectedSiteMissing = _onSelectedSiteMissing as LiveData<Unit>

private var page = 1
private var limitPerPage: Int = 10
private var isLastPage: Boolean = false

fun start(campaignListingPageSource: CampaignListingPageSource) {
this.site = selectedSiteRepository.getSelectedSite()!!
val site = selectedSiteRepository.getSelectedSite()
if (site == null) {
_onSelectedSiteMissing.value = Unit
return
}
this.site = site
blazeFeatureUtils.trackCampaignListingPageShown(campaignListingPageSource)
loadCampaigns()
}
Expand Down

0 comments on commit 7ee1ff0

Please sign in to comment.