Skip to content

Commit

Permalink
Show usage hours in most used apps analyisis
Browse files Browse the repository at this point in the history
  • Loading branch information
VishalNehra committed Jul 14, 2024
1 parent 383b104 commit a143c3c
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) })
}
}
Expand Down Expand Up @@ -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<String>()
freqMap.entries.stream()
Expand All @@ -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)
Expand Down Expand Up @@ -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))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -173,7 +174,7 @@ data class MediaFileInfo(
applicationInfo.packageName,
packageManager.getApplicationIcon(applicationInfo.packageName),
Utils.getApplicationNetworkBytes(context, applicationInfo),
sizeDiff
sizeDiff, timeForeground
)
)
mediaFileInfo.extraInfo = extraInfo
Expand Down Expand Up @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/java/com/amaze/fileutilities/utilis/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1043,4 +1043,6 @@
<string name="sort_by">Sort By</string>
<!-- subscription terms in purchase dialog -->
<string name="terms_and_conditions">Terms and Conditions</string>
<!-- usage app opened in most used apps analysis -->
<string name="usage">Usage (hrs)</string>
</resources>

0 comments on commit a143c3c

Please sign in to comment.