mirror of
https://github.com/SimpleMobileTools/Simple-File-Manager.git
synced 2025-04-24 23:18:50 +02:00
adding some storage stat fetchers into the storage fragment
This commit is contained in:
parent
997a44f857
commit
a246ca514f
@ -1,10 +1,14 @@
|
|||||||
package com.simplemobiletools.filemanager.pro.fragments
|
package com.simplemobiletools.filemanager.pro.fragments
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint
|
||||||
|
import android.app.usage.StorageStatsManager
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.os.Environment
|
import android.os.Environment
|
||||||
|
import android.os.storage.StorageManager
|
||||||
import android.provider.MediaStore
|
import android.provider.MediaStore
|
||||||
import android.util.AttributeSet
|
import android.util.AttributeSet
|
||||||
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import com.simplemobiletools.commons.extensions.getLongValue
|
import com.simplemobiletools.commons.extensions.getLongValue
|
||||||
import com.simplemobiletools.commons.extensions.getProperSize
|
import com.simplemobiletools.commons.extensions.getProperSize
|
||||||
import com.simplemobiletools.commons.extensions.queryCursor
|
import com.simplemobiletools.commons.extensions.queryCursor
|
||||||
@ -42,4 +46,29 @@ class StorageFragment(context: Context, attributeSet: AttributeSet) : MyViewPage
|
|||||||
|
|
||||||
return totalSize
|
return totalSize
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressLint("NewApi")
|
||||||
|
private fun getStorageStats() {
|
||||||
|
if (activity == null) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
val externalDirs = activity!!.getExternalFilesDirs(null)
|
||||||
|
val storageManager = activity!!.getSystemService(AppCompatActivity.STORAGE_SERVICE) as StorageManager
|
||||||
|
|
||||||
|
externalDirs.forEach { file ->
|
||||||
|
val storageVolume = storageManager.getStorageVolume(file) ?: return
|
||||||
|
if (storageVolume.isPrimary) {
|
||||||
|
// internal storage
|
||||||
|
val storageStatsManager = activity!!.getSystemService(AppCompatActivity.STORAGE_STATS_SERVICE) as StorageStatsManager
|
||||||
|
val uuid = StorageManager.UUID_DEFAULT
|
||||||
|
val totalSpace = storageStatsManager.getTotalBytes(uuid)
|
||||||
|
val freeSpace = storageStatsManager.getFreeBytes(uuid)
|
||||||
|
} else {
|
||||||
|
// sd card
|
||||||
|
val totalSpace = file.totalSpace
|
||||||
|
val freeSpace = file.freeSpace
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user