新增首页storage,battery
This commit is contained in:
parent
fee044b500
commit
076b2d7086
@ -135,4 +135,13 @@ object SetNumberOrWordUtils {
|
||||
this < 1000*1000*1000 -> "%.1f MB".format(this/(1000.0*1000))
|
||||
else -> "%.1f GB".format(this/(1000.0*1000*1000))
|
||||
}
|
||||
fun formatBytes(bytes: Long): String {
|
||||
return when {
|
||||
bytes < 1024 -> "$bytes B"
|
||||
bytes < 1024 * 1024 -> String.format(java.util.Locale.US, "%.1f KB", bytes / 1024.0)
|
||||
bytes < 1024 * 1024 * 1024 -> String.format(java.util.Locale.US, "%.1f MB", bytes / (1024.0 * 1024))
|
||||
else -> String.format(java.util.Locale.US, "%.1f GB", bytes / (1024.0 * 1024 * 1024))
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -2,6 +2,7 @@ package com.xyzshell.myphoneinfo.dashboard
|
||||
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
@ -9,8 +10,14 @@ import androidx.fragment.app.activityViewModels
|
||||
import androidx.recyclerview.widget.GridLayoutManager
|
||||
import com.xyzshell.andinfo.libs.BatteryDetails
|
||||
import com.xyzshell.andinfo.libs.BuildInfo
|
||||
import com.xyzshell.andinfo.libs.MemInfo
|
||||
import com.xyzshell.andinfo.libs.MemoryInfo
|
||||
import com.xyzshell.andinfo.libs.NetworkInfo
|
||||
import com.xyzshell.andinfo.libs.StorageInfo
|
||||
import com.xyzshell.myphoneinfo.R
|
||||
import com.xyzshell.myphoneinfo.base.BaseFragment
|
||||
import com.xyzshell.myphoneinfo.custom.RefreshManager.stop
|
||||
import com.xyzshell.myphoneinfo.custom.SetNumberOrWordUtils.formatBytes
|
||||
import com.xyzshell.myphoneinfo.databinding.FragmentDashboardBinding
|
||||
import com.xyzshell.myphoneinfo.dialog.DialogAppInstall
|
||||
import com.xyzshell.myphoneinfo.dialog.DialogBattery
|
||||
@ -40,6 +47,7 @@ class DashboardFragment : BaseFragment<FragmentDashboardBinding>() {
|
||||
private val mainViewModel: MainViewModel by activityViewModels()
|
||||
private lateinit var buildDialogInfo: BuildInfo
|
||||
private lateinit var batteryDialogInfo: BatteryDetails
|
||||
private lateinit var memInfo: MemoryInfo
|
||||
|
||||
|
||||
companion object {
|
||||
@ -108,11 +116,48 @@ class DashboardFragment : BaseFragment<FragmentDashboardBinding>() {
|
||||
else->binding.layoutCenter.iconBattery.setImageResource(R.mipmap.property_1full)
|
||||
}
|
||||
binding.layoutCenter.seekbar.progress=it!!.percentage
|
||||
binding.layoutCenter.seekbar.setOnTouchListener { _, _ -> true }
|
||||
binding.layoutCenter.percent.text=it.percentage.toString()+"%"
|
||||
binding.layoutCenter.batteryContent.text="${it.temperature}°C"
|
||||
}
|
||||
}
|
||||
|
||||
mainViewModel.storageInfo.observe(viewLifecycleOwner) {storagesInfo ->
|
||||
storagesInfo?.let {
|
||||
val breakdown = storagesInfo.getInternalStorageBreakdown()
|
||||
val stoUsed = formatBytes(breakdown.usedSpace)
|
||||
val stoFree = formatBytes(breakdown.freeSpace)
|
||||
val stoTotal = formatBytes(breakdown.totalSpace)
|
||||
binding.layoutCenter.percent1.text=String.format("%.1f%%", breakdown.usedPercentage)
|
||||
binding.layoutCenter.seekbar1.progress=breakdown.usedPercentage.toInt()
|
||||
binding.layoutCenter.seekbar1.setOnTouchListener { _, _ -> true }
|
||||
binding.layoutCenter.storageContent.text="Free:${stoFree}, Total:${stoTotal}"
|
||||
}
|
||||
}
|
||||
mainViewModel.memInfo.observe(viewLifecycleOwner) {memsInfo ->
|
||||
if (memsInfo != null) {
|
||||
memInfo=memsInfo.getMemoryInfo()
|
||||
}
|
||||
}
|
||||
|
||||
mainViewModel.networkStatus.observe(viewLifecycleOwner) {networkStatus ->
|
||||
Log.d("NetworkFragment", "setObservers: $networkStatus")
|
||||
when (networkStatus) {
|
||||
NetworkInfo.NetworkType.WIFI -> {
|
||||
binding.layoutCenter.network1.text = getString(R.string.wifi)
|
||||
|
||||
}
|
||||
|
||||
NetworkInfo.NetworkType.MOBILE -> {
|
||||
binding.layoutCenter.network1.text = getString(R.string.mobile)
|
||||
}
|
||||
|
||||
else -> {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
private fun initCpu() {
|
||||
binding.layoutCpu.run {
|
||||
@ -167,7 +212,7 @@ class DashboardFragment : BaseFragment<FragmentDashboardBinding>() {
|
||||
dialogMemory?.show(parentFragmentManager, "")
|
||||
}
|
||||
relayoutStorage.setOnClickListener {
|
||||
dialogStorage = dialogStorage ?: DialogStorage()
|
||||
dialogStorage = dialogStorage ?: DialogStorage(memInfo)
|
||||
dialogStorage?.show(parentFragmentManager, "")
|
||||
}
|
||||
}
|
||||
|
||||
@ -25,6 +25,7 @@ import com.xyzshell.myphoneinfo.R
|
||||
import com.xyzshell.myphoneinfo.custom.RefreshManager.load
|
||||
import com.xyzshell.myphoneinfo.custom.RefreshManager.stop
|
||||
import com.xyzshell.myphoneinfo.custom.SetNumberOrWordUtils.convertToApproximateAspectRatio
|
||||
import com.xyzshell.myphoneinfo.custom.SetNumberOrWordUtils.formatBytes
|
||||
import com.xyzshell.myphoneinfo.databinding.FragmentHardWareBinding
|
||||
import com.xyzshell.myphoneinfo.dialog.DialogBlueTooth
|
||||
import com.xyzshell.myphoneinfo.dialog.DialogDiskPart
|
||||
@ -174,6 +175,7 @@ class HardWareFragment : Fragment() {
|
||||
(memUsed.substringBefore(" ").toDouble() / memTotal
|
||||
.substringBefore(" ")
|
||||
.toDouble() * 100).toInt()
|
||||
binding.memoryLayout.seekbar.setOnTouchListener { _, _ -> true }
|
||||
//zarm
|
||||
|
||||
binding.memoryLayout.memText3.textTitle.text = getString(R.string.zram)
|
||||
@ -183,6 +185,7 @@ class HardWareFragment : Fragment() {
|
||||
binding.memoryLayout.seekbar2.progress =
|
||||
(zramTotal.substringBefore(" ").toDouble() / zramTotal.substringBefore(" ")
|
||||
.toDouble() * 100).toInt()
|
||||
binding.memoryLayout.seekbar2.setOnTouchListener { _, _ -> true }
|
||||
}
|
||||
}
|
||||
|
||||
@ -192,9 +195,9 @@ class HardWareFragment : Fragment() {
|
||||
mainViewModel.storageInfo.observe(viewLifecycleOwner){storageInfo ->
|
||||
storageInfo?.let {
|
||||
val breakdown = storageInfo.getInternalStorageBreakdown()
|
||||
val stoUsed = storageInfo.formatBytes(breakdown.usedSpace)
|
||||
val stoFree = storageInfo.formatBytes(breakdown.freeSpace)
|
||||
val stoTotal = storageInfo.formatBytes(breakdown.totalSpace)
|
||||
val stoUsed = formatBytes(breakdown.usedSpace)
|
||||
val stoFree = formatBytes(breakdown.freeSpace)
|
||||
val stoTotal = formatBytes(breakdown.totalSpace)
|
||||
//appsAndData
|
||||
val appsAndData = storageInfo.getFormattedAppsAndDataSize()
|
||||
val system = storageInfo.getFormattedSystemSize()
|
||||
@ -211,11 +214,12 @@ class HardWareFragment : Fragment() {
|
||||
binding.memoryLayout.seekbarr2.progress =
|
||||
// (breakdown.appsAndDataSize.toDouble() / breakdown.totalSpace.toDouble() * 100).toInt()
|
||||
50
|
||||
binding.memoryLayout.seekbarr2.setOnTouchListener { _, _ -> true }
|
||||
//system
|
||||
binding.memoryLayout.seekbarr1.progress =
|
||||
// ((50+storageInfo.systemSize).toDouble() / breakdown.totalSpace.toDouble() * 100).toInt()
|
||||
70
|
||||
|
||||
binding.memoryLayout.seekbarr1.setOnTouchListener { _, _ -> true }
|
||||
//internalStorage
|
||||
val interUsed = storageInfo.getInternalStorageBreakdown().usedSpace
|
||||
val interFree = storageInfo.getInternalStorageBreakdown().freeSpace
|
||||
@ -226,13 +230,14 @@ class HardWareFragment : Fragment() {
|
||||
binding.memoryLayout.interText1.textContent.text =
|
||||
storageInfo.internalStorageFileSystemType.toString()
|
||||
binding.memoryLayout.interText2.textTitle.text = getString(R.string.block_size)
|
||||
binding.memoryLayout.interText2.textContent.text = storageInfo.formatBytes(interTotal)
|
||||
binding.memoryLayout.interText2.textContent.text = formatBytes(interTotal)
|
||||
binding.memoryLayout.interText3.textTitle.text = "/data"
|
||||
binding.memoryLayout.interText3.textContent.text = storageInfo.formatBytes(storageInfo.dataDirectoryTotalSpace)
|
||||
binding.memoryLayout.stor3.text = "${storageInfo.formatBytes(interUsed)} used"
|
||||
binding.memoryLayout.stor4.text = "${storageInfo.formatBytes(interFree)} free"
|
||||
binding.memoryLayout.interText3.textContent.text = formatBytes(storageInfo.dataDirectoryTotalSpace)
|
||||
binding.memoryLayout.stor3.text = "${formatBytes(interUsed)} used"
|
||||
binding.memoryLayout.stor4.text = "${formatBytes(interFree)} free"
|
||||
binding.memoryLayout.seekbar5.progress =
|
||||
(interUsed.toDouble() / interTotal.toDouble() * 100).toInt()
|
||||
binding.memoryLayout.seekbar5.setOnTouchListener { _, _ -> true }
|
||||
storageInfo.abOtaPartitions?.forEach { text ->
|
||||
Log.d("TTTTTTTT","disk part:${text}")
|
||||
|
||||
|
||||
@ -2,17 +2,54 @@ package com.xyzshell.myphoneinfo.dialog
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import com.xyzshell.andinfo.libs.MemInfo
|
||||
import com.xyzshell.andinfo.libs.MemoryInfo
|
||||
import com.xyzshell.andinfo.libs.StorageInfo
|
||||
import com.xyzshell.myphoneinfo.R
|
||||
import com.xyzshell.myphoneinfo.base.BaseDialogFragment
|
||||
import com.xyzshell.myphoneinfo.custom.SetNumberOrWordUtils.formatBytes
|
||||
import com.xyzshell.myphoneinfo.databinding.DialogStorageBinding
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
|
||||
class DialogStorage :BaseDialogFragment<DialogStorageBinding>(DialogStorageBinding::inflate){
|
||||
class DialogStorage(val memory: MemoryInfo) :BaseDialogFragment<DialogStorageBinding>(DialogStorageBinding::inflate){
|
||||
override fun getTitle(): String = resources.getString(R.string.storage)
|
||||
|
||||
override fun getIconRes(): Int? =8
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
viewLifecycleOwner.lifecycleScope.launch {
|
||||
delay(50) // 短暂延迟确保UI完成布局
|
||||
withContext(Dispatchers.Main) {
|
||||
memory.let {
|
||||
val memUsed = formatBytes(it.usedRam)
|
||||
val memFree = formatBytes(it.availableRam)
|
||||
val memTotal = formatBytes(it.totalRam)
|
||||
|
||||
val zramTotal = formatBytes(it.zramTotal)
|
||||
val zramUsed = formatBytes(it.zramUsed)
|
||||
val zramFree = formatBytes(it.zramTotal - it.zramUsed)
|
||||
|
||||
binding.tvRamSize.setValue(memTotal)
|
||||
binding.memUsed.text = "$memUsed used"
|
||||
binding.memFree.text = "$memFree free"
|
||||
binding.seekbar3.progress =
|
||||
(memUsed.substringBefore(" ").toDouble() / memTotal
|
||||
.substringBefore(" ")
|
||||
.toDouble() * 100).toInt()
|
||||
binding.seekbar3.setOnTouchListener { _, _ -> true }
|
||||
binding.seekbar5.setOnTouchListener { _, _ -> true }
|
||||
binding.zramUsed.text = "$zramUsed used"
|
||||
binding.zramFree.text = "$zramFree free"
|
||||
binding.seekbar5.progress =
|
||||
(zramTotal.substringBefore(" ").toDouble() / zramTotal.substringBefore(" ")
|
||||
.toDouble() * 100).toInt()
|
||||
}
|
||||
}}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -20,7 +20,7 @@
|
||||
app:layout_constraintTop_toTopOf="parent">
|
||||
<ImageView
|
||||
android:id="@+id/icon_battery"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_width="40dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerVertical="true"
|
||||
android:src="@mipmap/property_1full" />
|
||||
@ -72,7 +72,7 @@
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/apps"
|
||||
android:textSize="10sp"
|
||||
android:textSize="11sp"
|
||||
android:layout_marginStart="@dimen/each_item_padding_horizontal"
|
||||
/>
|
||||
</LinearLayout>
|
||||
@ -93,8 +93,8 @@
|
||||
app:layout_constraintTop_toBottomOf="@id/relayout_battery">
|
||||
<ImageView
|
||||
android:id="@+id/icon_storage"
|
||||
android:layout_width="33dp"
|
||||
android:layout_height="33dp"
|
||||
android:layout_width="40dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="5dp"
|
||||
android:layout_centerVertical="true"
|
||||
android:src="@mipmap/stroke_bg" />
|
||||
@ -141,13 +141,13 @@
|
||||
android:textSize="12sp" />
|
||||
</LinearLayout>
|
||||
<com.google.android.material.textview.MaterialTextView
|
||||
android:layout_marginStart="@dimen/each_item_padding_horizontal"
|
||||
android:id="@+id/storage_content"
|
||||
style="@style/LeftContent"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/apps"
|
||||
tools:ignore="RelativeOverlap" />
|
||||
android:textSize="11sp"
|
||||
android:layout_marginStart="@dimen/each_item_padding_horizontal" />
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
@ -190,17 +190,29 @@
|
||||
android:layout_height="33dp"
|
||||
android:layout_below="@id/title_network"
|
||||
android:src="@mipmap/wifi_ic" />
|
||||
|
||||
<com.google.android.material.textview.MaterialTextView
|
||||
android:id="@+id/network_content"
|
||||
style="@style/LeftContent"
|
||||
android:layout_width="wrap_content"
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignTop="@id/icon_network"
|
||||
android:layout_marginStart="@dimen/dashboard_icon_content_interval"
|
||||
android:layout_toEndOf="@id/icon_network"
|
||||
android:text="@string/apps"
|
||||
tools:ignore="RelativeOverlap" />
|
||||
android:orientation="vertical">
|
||||
<com.google.android.material.textview.MaterialTextView
|
||||
android:id="@+id/network1"
|
||||
style="@style/LeftContent"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="12sp"
|
||||
android:text="@string/apps" />
|
||||
<com.google.android.material.textview.MaterialTextView
|
||||
android:id="@+id/network2"
|
||||
style="@style/LeftContent"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="12sp"
|
||||
android:text="@string/apps" />
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
@ -45,9 +45,9 @@
|
||||
|
||||
<com.google.android.material.textview.MaterialTextView
|
||||
style="@style/LeftContent"
|
||||
android:id="@+id/memUsed"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="28.01 GB used"
|
||||
android:textSize="14sp" />
|
||||
|
||||
<View
|
||||
@ -56,11 +56,10 @@
|
||||
android:layout_weight="1" />
|
||||
|
||||
<com.google.android.material.textview.MaterialTextView
|
||||
android:id="@+id/stor1"
|
||||
android:id="@+id/memFree"
|
||||
style="@style/LeftContent"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="128 GB total"
|
||||
android:textSize="14sp" />
|
||||
</LinearLayout>
|
||||
|
||||
@ -123,9 +122,9 @@
|
||||
|
||||
<com.google.android.material.textview.MaterialTextView
|
||||
style="@style/LeftContent"
|
||||
android:id="@+id/zramUsed"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="2.22 GB used"
|
||||
android:textSize="14sp" />
|
||||
|
||||
<View
|
||||
@ -134,11 +133,10 @@
|
||||
android:layout_weight="1" />
|
||||
|
||||
<com.google.android.material.textview.MaterialTextView
|
||||
android:id="@+id/stor3"
|
||||
android:id="@+id/zramFree"
|
||||
style="@style/LeftContent"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="3.75 GB free"
|
||||
android:textSize="14sp" />
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user