NTP-54347 | Sohan | NAE handling for homepage api (#15858)

This commit is contained in:
Sohan Reddy Atukula
2025-04-23 15:56:36 +05:30
committed by GitHub
parent d0858b684b
commit 0439f7e737
4 changed files with 24 additions and 6 deletions

View File

@@ -12,6 +12,7 @@ import com.navi.common.alchemist.model.AlchemistScreenRequest
import com.navi.common.checkmate.model.MetricInfo
import com.navi.common.model.ModuleNameV2
import com.navi.common.network.models.RepoResult
import com.navi.common.network.models.isSuccess
import com.navi.common.utils.Constants.GZIP
import com.naviapp.models.response.NotificationSettings
import com.naviapp.models.response.NotificationSettingsContent
@@ -28,6 +29,7 @@ constructor(@SuperAppRetroFit private val superAppRetrofitService: RetrofitServi
availableAppVersionCode: Int?,
naviUpiDeviceFingerprint: String,
ssid: String,
shouldShowNae: Boolean,
request: AlchemistScreenRequest,
naeScreenName: String,
): RepoResult<AlchemistScreenDefinition> =
@@ -41,7 +43,11 @@ constructor(@SuperAppRetroFit private val superAppRetrofitService: RetrofitServi
verticalType = ModuleNameV2.ALCHEMIST.name,
request = request,
),
metricInfo = MetricInfo.AppMetric(screen = naeScreenName, isNae = { false }),
metricInfo =
MetricInfo.AppMetric(
screen = naeScreenName,
isNae = { it.isFromCache.not() && it.isSuccess().not() && shouldShowNae },
),
)
suspend fun fetchHomeFeature(type: String, naeScreenName: String) =

View File

@@ -36,6 +36,7 @@ constructor(
connectivityObserver: ConnectivityObserver,
screenHash: String? = null,
naeScreenName: String,
shouldShowNae: Boolean,
noInternetCallback: () -> Unit,
onFailure:
suspend (apiErrorMessage: ErrorMessage?, errors: List<GenericErrorResponse>?) -> Unit,
@@ -60,6 +61,7 @@ constructor(
availableAppVersionCode = availableAppVersionCode,
naviUpiDeviceFingerprint = deviceInfoDetails.deviceFingerPrint,
ssid = deviceInfoDetails.provider.ssid,
shouldShowNae = shouldShowNae,
request =
AlchemistScreenRequest(
screenName = HOME_SCREEN_IN_CAPS,

View File

@@ -78,7 +78,7 @@ constructor(
context(CoroutineScope)
fun syncHomeContentData(
isFirstTimeRender: Boolean,
fetchHomeContent: suspend () -> NaviCacheAltSourceEntity,
fetchHomeContent: suspend (shouldShowNae: Boolean) -> NaviCacheAltSourceEntity,
onContentSynchronized: () -> Unit,
onHomeFetchSuccessFromNetwork: () -> Unit,
onSelectiveRefreshStateChange: (SelectiveRefreshState) -> Unit,
@@ -96,7 +96,7 @@ constructor(
)
} else {
performIncrementalContentSync(
fetchHomeContent,
{ fetchHomeContent(false) },
onContentSynchronized,
eventHandler,
onSelectiveRefreshStateChange,
@@ -106,7 +106,7 @@ constructor(
}
private fun CoroutineScope.initializeFirstTimeContentSync(
fetchHomeContent: suspend () -> NaviCacheAltSourceEntity,
fetchHomeContent: suspend (shouldShowNae: Boolean) -> NaviCacheAltSourceEntity,
onContentSynchronized: () -> Unit,
eventHandler: (HpEvents) -> Unit,
onSelectiveRefreshStateChange: (SelectiveRefreshState) -> Unit,
@@ -123,7 +123,10 @@ constructor(
)
initiateNetworkSyncAndProcess(
fetchHomeContent = fetchHomeContent,
fetchHomeContent = {
val cachedHomeContent = naviCacheRepository.get(NaviSharedDbKeys.HOME_TAB.name)
fetchHomeContent(cachedHomeContent?.value.isNullOrEmpty())
},
cacheLoadOperation = cacheLoadOperation,
cacheDataLoaded = cacheDataLoaded,
onContentSynchronized = onContentSynchronized,

View File

@@ -19,6 +19,7 @@ import com.navi.base.sharedpref.PreferenceManager
import com.navi.base.utils.BaseUtils
import com.navi.base.utils.ConnectivityObserver
import com.navi.base.utils.isNotNullAndNotEmpty
import com.navi.base.utils.orFalse
import com.navi.common.basemvi.BaseMviViewModel
import com.navi.common.model.ModuleNameV2
import com.navi.common.uitron.helper.VideoViewHelper
@@ -130,12 +131,17 @@ constructor(
}
}
private suspend fun fetchHomeDataFromApi(naeScreenName: String, screenHash: String? = null) =
private suspend fun fetchHomeDataFromApi(
naeScreenName: String,
screenHash: String? = null,
shouldShowNae: Boolean? = false,
) =
fetchHomeItemsUseCase.fetchHomeItemFromAPI(
connectivityObserver = connectivityObserver,
availableAppVersionCode =
PreferenceManager.getIntPreferenceApp(CURRENT_VERSION_IN_STORE),
screenHash = screenHash,
shouldShowNae = shouldShowNae.orFalse(),
naeScreenName = naeScreenName,
onFailure = { errorMessage, errors ->
setEffect { HpEffects.OnApiFailure(errorMessage, errors) }
@@ -205,6 +211,7 @@ constructor(
fetchHomeDataFromApi(
naeScreenName = naeScreenName,
screenHash = screenHash,
shouldShowNae = it,
)
},
onHomeFetchSuccessFromNetwork = ::onHomeFetchSuccessFromNetwork,