Skip to content

Commit

Permalink
Merge pull request #172 from TeamAmaze/feature-140
Browse files Browse the repository at this point in the history
Feature 140 Show usage hours in most used apps analyisis
  • Loading branch information
VishalNehra authored Jul 14, 2024
2 parents 383b104 + ad783c0 commit 13a7b02
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ 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

class ReviewAnalysisAdapter(
Expand Down Expand Up @@ -99,6 +100,16 @@ 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
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,9 @@ import com.amaze.fileutilities.R
import com.amaze.fileutilities.databinding.GenericPagerViewerActivityBinding
import com.amaze.fileutilities.utilis.Utils.Companion.showProcessingDialog
import com.amaze.fileutilities.utilis.showToastInCenter
import java.io.File
import org.slf4j.Logger
import org.slf4j.LoggerFactory

import java.io.File

class ImageViewerActivity : PermissionsActivity() {

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 13a7b02

Please sign in to comment.