From 6b63a4bee7ff094eade5eb903f065dafa19d490b Mon Sep 17 00:00:00 2001 From: Hasib Prince Date: Tue, 26 Mar 2024 23:46:04 +0600 Subject: [PATCH 1/2] style: improved coding styles --- .../install/download/DownloadManagerUtils.kt | 2 +- .../receivers/DumpAppInstallStatusReceiver.kt | 33 ++++++++++--------- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/foundation/e/apps/install/download/DownloadManagerUtils.kt b/app/src/main/java/foundation/e/apps/install/download/DownloadManagerUtils.kt index c95380f97..94e10df97 100644 --- a/app/src/main/java/foundation/e/apps/install/download/DownloadManagerUtils.kt +++ b/app/src/main/java/foundation/e/apps/install/download/DownloadManagerUtils.kt @@ -123,9 +123,9 @@ class DownloadManagerUtils @Inject constructor( val numberOfDownloadedItems = fusedDownload.downloadIdMap.values.filter { it }.size + Timber.d("===> updateDownloadStatus: ${fusedDownload.name}: $downloadId: $numberOfDownloadedItems/${fusedDownload.downloadIdMap.size}") - // if download status code is unknown (-1), consider installation is failed. val areAllFilesDownloaded = areAllFilesDownloaded( numberOfDownloadedItems, fusedDownload diff --git a/app/src/main/java/foundation/e/apps/receivers/DumpAppInstallStatusReceiver.kt b/app/src/main/java/foundation/e/apps/receivers/DumpAppInstallStatusReceiver.kt index e21cd022b..a9301e018 100644 --- a/app/src/main/java/foundation/e/apps/receivers/DumpAppInstallStatusReceiver.kt +++ b/app/src/main/java/foundation/e/apps/receivers/DumpAppInstallStatusReceiver.kt @@ -48,6 +48,7 @@ class DumpAppInstallStatusReceiver : BroadcastReceiver() { @Inject lateinit var downloadManager: DownloadManager + override fun onReceive(context: Context?, intent: Intent?) { if (intent?.action == null) { return @@ -56,38 +57,40 @@ class DumpAppInstallStatusReceiver : BroadcastReceiver() { MainScope().launch { val gson = Gson() val appList = fusedDownloadRepository.getDownloadList() - Timber.tag(Constants.TAG_APP_INSTALL_STATE) - .i("App install status: ${gson.toJson(appList)}") + val appInstallStatusLog = "App install status: ${gson.toJson(appList)}" + val deviceStatusLog = logDeviceStatus(context) + val downloadStatusLog = logDownloadStatusFromDownloadManager(appList) - logDownloadStatusFromDownloadManager(appList) - logDeviceStatus(context) + Timber.tag(Constants.TAG_APP_INSTALL_STATE) + .e("%s\n\n%s\n\n%s", deviceStatusLog, appInstallStatusLog, downloadStatusLog) } } - private fun logDeviceStatus(context: Context?) { + private fun logDeviceStatus(context: Context?): String? { context?.let { val bm = context.getSystemService(BATTERY_SERVICE) as BatteryManager val batteryLevel = bm.getIntProperty(BatteryManager.BATTERY_PROPERTY_CAPACITY) - Timber.tag(Constants.TAG_APP_INSTALL_STATE) - .i( - "Available Space: ${StorageComputer.calculateAvailableDiskSpace()}" + - "\nInternet: ${ - NetworkStatusManager.init(context).value - }\nBattery level: $batteryLevel" - ) + return "Available Space: ${StorageComputer.calculateAvailableDiskSpace()}" + + "\nInternet: ${ + NetworkStatusManager.init(context).value + }\nBattery level: $batteryLevel" } + + return null } - private fun logDownloadStatusFromDownloadManager(appList: List) { + private fun logDownloadStatusFromDownloadManager(appList: List): String { + var downloadStatusLog = "" appList.forEach { if (listOf(Status.DOWNLOADING, Status.DOWNLOADED).contains(it.status)) { it.downloadIdMap.keys.forEach { downloadId -> val downloadStatus = downloadManager.isDownloadSuccessful(downloadId) - Timber.tag(Constants.TAG_APP_INSTALL_STATE) - .i("DownloadStatus: ${it.name}: Id: $downloadId: ${downloadStatus.second}") + downloadStatusLog += "DownloadStatus: ${it.name}: Id: $downloadId: ${downloadStatus.second}\n" } } } + + return downloadStatusLog } } -- GitLab From 273554d64bed1ede947a2506119d1ce512f5cd4a Mon Sep 17 00:00:00 2001 From: Hasib Prince Date: Wed, 27 Mar 2024 13:39:31 +0600 Subject: [PATCH 2/2] refactor: renamed methods --- .../e/apps/receivers/DumpAppInstallStatusReceiver.kt | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/foundation/e/apps/receivers/DumpAppInstallStatusReceiver.kt b/app/src/main/java/foundation/e/apps/receivers/DumpAppInstallStatusReceiver.kt index a9301e018..f28ada6a4 100644 --- a/app/src/main/java/foundation/e/apps/receivers/DumpAppInstallStatusReceiver.kt +++ b/app/src/main/java/foundation/e/apps/receivers/DumpAppInstallStatusReceiver.kt @@ -31,7 +31,6 @@ import foundation.e.apps.data.DownloadManager import foundation.e.apps.data.enums.Status import foundation.e.apps.data.fusedDownload.FusedDownloadRepository import foundation.e.apps.data.fusedDownload.models.FusedDownload -import foundation.e.apps.install.download.DownloadManagerUtils import foundation.e.apps.utils.NetworkStatusManager import foundation.e.apps.utils.StorageComputer import kotlinx.coroutines.MainScope @@ -58,15 +57,15 @@ class DumpAppInstallStatusReceiver : BroadcastReceiver() { val gson = Gson() val appList = fusedDownloadRepository.getDownloadList() val appInstallStatusLog = "App install status: ${gson.toJson(appList)}" - val deviceStatusLog = logDeviceStatus(context) - val downloadStatusLog = logDownloadStatusFromDownloadManager(appList) + val deviceStatusLog = getDeviceInfo(context) + val downloadStatusLog = getDownloadStatus(appList) Timber.tag(Constants.TAG_APP_INSTALL_STATE) .e("%s\n\n%s\n\n%s", deviceStatusLog, appInstallStatusLog, downloadStatusLog) } } - private fun logDeviceStatus(context: Context?): String? { + private fun getDeviceInfo(context: Context?): String? { context?.let { val bm = context.getSystemService(BATTERY_SERVICE) as BatteryManager val batteryLevel = bm.getIntProperty(BatteryManager.BATTERY_PROPERTY_CAPACITY) @@ -80,7 +79,7 @@ class DumpAppInstallStatusReceiver : BroadcastReceiver() { return null } - private fun logDownloadStatusFromDownloadManager(appList: List): String { + private fun getDownloadStatus(appList: List): String { var downloadStatusLog = "" appList.forEach { if (listOf(Status.DOWNLOADING, Status.DOWNLOADED).contains(it.status)) { -- GitLab