From 7e49900a593de00b147451b074e510b581df1bc4 Mon Sep 17 00:00:00 2001 From: Fahim Masud Choudhury Date: Wed, 20 Nov 2024 16:45:22 +0600 Subject: [PATCH] refactor: reduce # of API calls on Home screen on config change Moved API calls to MainActivityViewModel's init{} block. Having them on MainActivity's onCreate was causing unnecessary API calls on configuration changes. --- app/src/main/java/foundation/e/apps/ui/MainActivity.kt | 7 ------- .../java/foundation/e/apps/ui/MainActivityViewModel.kt | 8 ++++++-- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/foundation/e/apps/ui/MainActivity.kt b/app/src/main/java/foundation/e/apps/ui/MainActivity.kt index eb27c0ac6..91848af3e 100644 --- a/app/src/main/java/foundation/e/apps/ui/MainActivity.kt +++ b/app/src/main/java/foundation/e/apps/ui/MainActivity.kt @@ -98,11 +98,8 @@ class MainActivity : AppCompatActivity() { bottomNavigationView.selectedItemId = R.id.updatesFragment } - viewModel.createNotificationChannels() - - viewModel.setupConnectivityManager(this.applicationContext) observeInternetConnections() @@ -125,10 +122,6 @@ class MainActivity : AppCompatActivity() { showNoInternet() } - viewModel.updateAppWarningList() - viewModel.updateContentRatings() - viewModel.fetchUpdatableSystemAppsList() - observeEvents() checkGPlayLoginRequest(intent) diff --git a/app/src/main/java/foundation/e/apps/ui/MainActivityViewModel.kt b/app/src/main/java/foundation/e/apps/ui/MainActivityViewModel.kt index b06e667e2..1de981227 100644 --- a/app/src/main/java/foundation/e/apps/ui/MainActivityViewModel.kt +++ b/app/src/main/java/foundation/e/apps/ui/MainActivityViewModel.kt @@ -21,8 +21,6 @@ package foundation.e.apps.ui import android.content.Context import android.content.Intent import android.net.ConnectivityManager -import android.os.Build -import androidx.annotation.RequiresApi import androidx.appcompat.app.AlertDialog import androidx.lifecycle.LiveData import androidx.lifecycle.MutableLiveData @@ -69,6 +67,12 @@ class MainActivityViewModel @Inject constructor( private val systemAppsUpdatesRepository: SystemAppsUpdatesRepository, ) : ViewModel() { + init { + updateAppWarningList() + updateContentRatings() + fetchUpdatableSystemAppsList() + } + val tocStatus: LiveData = appLoungeDataStore.tocStatus.asLiveData() private val _purchaseAppLiveData: MutableLiveData = MutableLiveData() -- GitLab