Commit 22043554 authored by wanglei's avatar wanglei

...

parent cad4c425
...@@ -59,6 +59,7 @@ class HomeFragment : BaseFragment<FragmentHome3Binding>() { ...@@ -59,6 +59,7 @@ class HomeFragment : BaseFragment<FragmentHome3Binding>() {
} }
} }
} }
showStorage()
} }
override fun setListener() { override fun setListener() {
...@@ -113,30 +114,32 @@ class HomeFragment : BaseFragment<FragmentHome3Binding>() { ...@@ -113,30 +114,32 @@ class HomeFragment : BaseFragment<FragmentHome3Binding>() {
super.onResume() super.onResume()
binding.lottie.resumeAnimation() binding.lottie.resumeAnimation()
if (requireContext().checkStorePermission()) { if (requireContext().checkStorePermission()) {
binding.llStorage.visibility = View.VISIBLE }
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
val storageStatsManager = requireContext().getSystemService(STORAGE_STATS_SERVICE) as StorageStatsManager
Thread {
val totalBytes = storageStatsManager.getTotalBytes(StorageManager.UUID_DEFAULT)
val usedBytes = totalBytes - storageStatsManager.getFreeBytes(StorageManager.UUID_DEFAULT)
binding.root.post {
binding.tvStorage.text = "${usedBytes.toFormatSize()} / ${totalBytes.toFormatSize()}"
}
}.start()
} else {
val path1: File = Environment.getDataDirectory()
val stat1 = StatFs(path1.path)
val path2: File = Environment.getExternalStorageDirectory()
val stat2 = StatFs(path2.path)
val totalSize = (stat1.totalBytes + stat2.totalBytes).toFormatSize()
val usedSize = ((stat1.totalBytes + stat2.totalBytes) - (stat1.availableBytes + stat2.availableBytes)).toFormatSize()
binding.tvStorage.text = "$usedSize / $totalSize"
}
@SuppressLint("SetTextI18n")
fun showStorage() {
binding.llStorage.visibility = View.VISIBLE
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
val storageStatsManager = requireContext().getSystemService(STORAGE_STATS_SERVICE) as StorageStatsManager
Thread {
val totalBytes = storageStatsManager.getTotalBytes(StorageManager.UUID_DEFAULT)
val usedBytes = totalBytes - storageStatsManager.getFreeBytes(StorageManager.UUID_DEFAULT)
binding.root.post {
binding.tvStorage.text = "${usedBytes.toFormatSize()} / ${totalBytes.toFormatSize()}"
}
}.start()
} else {
val path1: File = Environment.getDataDirectory()
val stat1 = StatFs(path1.path)
val path2: File = Environment.getExternalStorageDirectory()
val stat2 = StatFs(path2.path)
val totalSize = (stat1.totalBytes + stat2.totalBytes).toFormatSize()
val usedSize = ((stat1.totalBytes + stat2.totalBytes) - (stat1.availableBytes + stat2.availableBytes)).toFormatSize()
binding.tvStorage.text = "$usedSize / $totalSize"
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment