diff --git a/app/src/main/java/com/amaze/fileutilities/home_page/ui/analyse/ReviewAnalysisAdapter.kt b/app/src/main/java/com/amaze/fileutilities/home_page/ui/analyse/ReviewAnalysisAdapter.kt index 908dc356..4ec92041 100644 --- a/app/src/main/java/com/amaze/fileutilities/home_page/ui/analyse/ReviewAnalysisAdapter.kt +++ b/app/src/main/java/com/amaze/fileutilities/home_page/ui/analyse/ReviewAnalysisAdapter.kt @@ -30,7 +30,9 @@ import com.amaze.fileutilities.home_page.ui.files.MediaInfoRecyclerViewHolder import com.amaze.fileutilities.utilis.AbstractMediaFilesAdapter import com.amaze.fileutilities.utilis.EmptyViewHolder import com.amaze.fileutilities.utilis.FileUtils +import com.amaze.fileutilities.utilis.Utils import java.lang.ref.WeakReference +import java.util.concurrent.TimeUnit class ReviewAnalysisAdapter( val context: Context, @@ -99,6 +101,11 @@ class ReviewAnalysisAdapter( } else { holder.infoSummary.text = totalSize } + } else if (analysisType == ReviewImagesFragment.TYPE_MOST_USED_APPS) { + val timeForeground = Utils.convertMillisToHoursMinutes(this.mediaFileInfo?.extraInfo?.apkMetaData?.timeForeground ?: 0L) + val size = this.mediaFileInfo?.getFormattedSize(context) + holder.infoSummary.text = "${context.getString(R.string.size)}: $size" + holder.extraInfo.text = "${context.getString(R.string.usage)}: $timeForeground" } else { holder.infoSummary.text = this.mediaFileInfo?.getFormattedSize(context) } diff --git a/app/src/main/java/com/amaze/fileutilities/home_page/ui/files/FilesViewModel.kt b/app/src/main/java/com/amaze/fileutilities/home_page/ui/files/FilesViewModel.kt index acc28eb7..26489952 100644 --- a/app/src/main/java/com/amaze/fileutilities/home_page/ui/files/FilesViewModel.kt +++ b/app/src/main/java/com/amaze/fileutilities/home_page/ui/files/FilesViewModel.kt @@ -1665,7 +1665,7 @@ class FilesViewModel(val applicationContext: Application) : !usageStatsPackages.contains(it.first.packageName) }?.mapNotNull { MediaFileInfo.fromApplicationInfo(applicationContext, it.first, it.second) - } + }?.sortedByDescending { it.longSize } unusedAppsLiveData?.postValue(unusedAppsList?.let { ArrayList(it) }) } } @@ -1742,14 +1742,12 @@ class FilesViewModel(val applicationContext: Application) : usageStats.filter { it.lastTimeUsed != 0L }.forEach { - if (!freqMap.contains(it.packageName)) { - freqMap[it.packageName] = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) - it.totalTimeVisible else it.totalTimeInForeground - } else { - freqMap[it.packageName] = freqMap[it.packageName]!! + - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) - it.totalTimeVisible else it.totalTimeInForeground + var timeForeground = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) + it.totalTimeVisible else it.totalTimeInForeground + if (freqMap[it.packageName] != null) { + timeForeground += freqMap[it.packageName]!! } + freqMap[it.packageName] = timeForeground } val mostUsedAppsListRaw = arrayListOf() freqMap.entries.stream() @@ -1765,7 +1763,8 @@ class FilesViewModel(val applicationContext: Application) : }?.let { MediaFileInfo.fromApplicationInfo( applicationContext, - it.first, it.second + it.first, it.second, + timeForeground = freqMap[appName] ?: 0L, )?.let { mediaFileInfo -> mostUsedApps.add(mediaFileInfo) @@ -2365,7 +2364,7 @@ class FilesViewModel(val applicationContext: Application) : Utils.applicationIsGame(it.first) }?.mapNotNull { MediaFileInfo.fromApplicationInfo(applicationContext, it.first, it.second) - }?.let { + }?.sortedByDescending { it.longSize }?.let { gamesInstalledLiveData?.postValue(ArrayList(it)) } } diff --git a/app/src/main/java/com/amaze/fileutilities/home_page/ui/files/MediaFileInfo.kt b/app/src/main/java/com/amaze/fileutilities/home_page/ui/files/MediaFileInfo.kt index f6ce9db8..6dbbc671 100644 --- a/app/src/main/java/com/amaze/fileutilities/home_page/ui/files/MediaFileInfo.kt +++ b/app/src/main/java/com/amaze/fileutilities/home_page/ui/files/MediaFileInfo.kt @@ -150,7 +150,8 @@ data class MediaFileInfo( context: Context, applicationInfo: ApplicationInfo, packageInfo: PackageInfo?, - sizeDiff: Long = -1 + sizeDiff: Long = -1, + timeForeground: Long = 0L ): MediaFileInfo? { if (applicationInfo.sourceDir == null) { return null @@ -173,7 +174,7 @@ data class MediaFileInfo( applicationInfo.packageName, packageManager.getApplicationIcon(applicationInfo.packageName), Utils.getApplicationNetworkBytes(context, applicationInfo), - sizeDiff + sizeDiff, timeForeground ) ) mediaFileInfo.extraInfo = extraInfo @@ -409,7 +410,8 @@ data class MediaFileInfo( val packageName: String, val drawable: Drawable?, val networkBytes: Long, - val sizeDiff: Long = -1 + val sizeDiff: Long = -1, + val timeForeground: Long = 0 ) data class ExtraMetaData(val checksum: String) data class Playlist(var id: Long, var name: String) diff --git a/app/src/main/java/com/amaze/fileutilities/utilis/Utils.kt b/app/src/main/java/com/amaze/fileutilities/utilis/Utils.kt index 335fe70c..d09d2197 100644 --- a/app/src/main/java/com/amaze/fileutilities/utilis/Utils.kt +++ b/app/src/main/java/com/amaze/fileutilities/utilis/Utils.kt @@ -1543,6 +1543,13 @@ class Utils { ) } + fun convertMillisToHoursMinutes(millis: Long): String { + val hours = TimeUnit.MILLISECONDS.toHours(millis) + val minutes = TimeUnit.MILLISECONDS.toMinutes(millis) % 60 + + return String.format("%02d:%02d", hours, minutes) + } + private fun findApplicationInfoSizeFallback(applicationInfo: ApplicationInfo): Long { var cacheSize = 0L File(applicationInfo.sourceDir).parentFile?.let { diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 5e1156bb..31da1269 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1043,4 +1043,6 @@ Sort By Terms and Conditions + + Usage (hrs)