Commit 34704608 authored by 周文华's avatar 周文华

【调整】1.调整部分UI。2.新增存储权限申请时机用以计算清理大小。

parent 9fb5de39
......@@ -73,7 +73,7 @@ object ActivityJumpHelps {
fun requestPermission(
context: Context,
launcher: ActivityLauncher,
block: (() -> Unit?)? = null
block: (() -> Unit)? = null
) {
if (PermissionHelps.checkFilesAccessPermission(context)) {
block?.invoke()
......
......@@ -124,47 +124,49 @@ class HomeFragment : BaseFragment<FragmentHomeBinding>(FragmentHomeBinding::infl
}
private fun initData() {
lifecycleScope.launch(Dispatchers.IO) {
val totalStorage = async { AppHelps.getTotalExternalSize() }
val availableStorage = async { AppHelps.getAvailableExternalSize() }
val totalStorageSize = totalStorage.await()
val availableStorageSize = availableStorage.await()
val usedMemoryStorageSize = totalStorageSize - availableStorageSize
val usedMemoryStorageScale = usedMemoryStorageSize * 100 / totalStorageSize
ActivityJumpHelps.requestPermission(requireContext(), launcher) {
lifecycleScope.launch(Dispatchers.IO) {
val totalStorage = async { AppHelps.getTotalExternalSize() }
val availableStorage = async { AppHelps.getAvailableExternalSize() }
val totalStorageSize = totalStorage.await()
val availableStorageSize = availableStorage.await()
val usedMemoryStorageSize = totalStorageSize - availableStorageSize
val usedMemoryStorageScale = usedMemoryStorageSize * 100 / totalStorageSize
val totalMemoryUsed = async { AppHelps.getMemTotal(requireContext()) }
val availableMemoryUsed = async { AppHelps.getMemAvailable(requireContext()) }
val totalMemoryUsedSize = totalMemoryUsed.await()
val availableMemoryUsedSize = availableMemoryUsed.await()
val usedMemoryUsedSize = totalMemoryUsedSize - availableMemoryUsedSize
val usedMemoryUsedScale: Long = usedMemoryUsedSize * 100 / totalMemoryUsedSize
withContext(Dispatchers.Main) {
binding.tvStorageUsed.text = "${usedMemoryStorageScale.toInt()}%"
binding.tvMemoryUsed.text = "${usedMemoryUsedScale.toInt()}%"
binding.llStorageUsed.visibility = View.VISIBLE
binding.llMemoryUsed.visibility = View.VISIBLE
AnimationHelps.progress(binding.pbStorageUsed, usedMemoryStorageScale.toInt())
AnimationHelps.progress(binding.pbMemoryUsed, usedMemoryUsedScale.toInt())
val totalMemoryUsed = async { AppHelps.getMemTotal(requireContext()) }
val availableMemoryUsed = async { AppHelps.getMemAvailable(requireContext()) }
val totalMemoryUsedSize = totalMemoryUsed.await()
val availableMemoryUsedSize = availableMemoryUsed.await()
val usedMemoryUsedSize = totalMemoryUsedSize - availableMemoryUsedSize
val usedMemoryUsedScale: Long = usedMemoryUsedSize * 100 / totalMemoryUsedSize
withContext(Dispatchers.Main) {
binding.tvStorageUsed.text = "${usedMemoryStorageScale.toInt()}%"
binding.tvMemoryUsed.text = "${usedMemoryUsedScale.toInt()}%"
binding.llStorageUsed.visibility = View.VISIBLE
binding.llMemoryUsed.visibility = View.VISIBLE
AnimationHelps.progress(binding.pbStorageUsed, usedMemoryStorageScale.toInt())
AnimationHelps.progress(binding.pbMemoryUsed, usedMemoryUsedScale.toInt())
}
}
}
lifecycleScope.launch(Dispatchers.IO) {
val emptyFoldersDeferred = async { FileHelps.findEmptyFolders(lifecycleScope) }
val filesDeferred = async { MediaHelps.findSpecifiedFiles(requireContext()) }
val emptyFolder = emptyFoldersDeferred.await()
val files = filesDeferred.await()
val emptyLength = emptyFolder.sumOf { it.length }
val filesLength = files.sumOf { it.length }
val totalLength = emptyLength + filesLength
val totalSize = Utils.getSize(totalLength)
withContext(Dispatchers.Main) {
val sp = SpannableString("$totalSize\n${getString(R.string.junk_files)}")
sp.setSpan(
AbsoluteSizeSpan(16, true),
sp.indexOf("\n"),
sp.length,
SpannableString.SPAN_EXCLUSIVE_EXCLUSIVE
)
binding.tvJunkFiles.text = sp
lifecycleScope.launch(Dispatchers.IO) {
val emptyFoldersDeferred = async { FileHelps.findEmptyFolders(lifecycleScope) }
val filesDeferred = async { MediaHelps.findSpecifiedFiles(requireContext()) }
val emptyFolder = emptyFoldersDeferred.await()
val files = filesDeferred.await()
val emptyLength = emptyFolder.sumOf { it.length }
val filesLength = files.sumOf { it.length }
val totalLength = emptyLength + filesLength
val totalSize = Utils.getSize(totalLength)
withContext(Dispatchers.Main) {
val sp = SpannableString("$totalSize\n${getString(R.string.junk_files)}")
sp.setSpan(
AbsoluteSizeSpan(16, true),
sp.indexOf("\n"),
sp.length,
SpannableString.SPAN_EXCLUSIVE_EXCLUSIVE
)
binding.tvJunkFiles.text = sp
}
}
}
}
......
......@@ -10,7 +10,7 @@
android:id="@+id/iv_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:layout_marginTop="10dp"
android:src="@mipmap/icon_junk_scan"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
......
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