Skip to content

Commit

Permalink
Fixed crashes and updated libraries
Browse files Browse the repository at this point in the history
  • Loading branch information
marek-guran committed Dec 27, 2023
1 parent ef43510 commit 6f6f4ae
Show file tree
Hide file tree
Showing 12 changed files with 86 additions and 94 deletions.
17 changes: 5 additions & 12 deletions APP/.idea/deploymentTargetDropDown.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions APP/.idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions APP/.idea/migrations.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions APP/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ android {
applicationId "com.marekguran.serverinfo"
minSdk 23
targetSdk 34
versionCode 7
versionName "1.0.7"
versionCode 8
versionName "1.0.10"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand All @@ -39,17 +39,17 @@ dependencies {

implementation 'androidx.core:core-ktx:1.12.0'
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.10.0'
implementation 'com.google.android.material:material:1.11.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.6.2'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.6.2'
implementation 'androidx.navigation:navigation-fragment-ktx:2.7.5'
implementation 'androidx.navigation:navigation-ui-ktx:2.7.5'
implementation 'androidx.navigation:navigation-fragment-ktx:2.7.6'
implementation 'androidx.navigation:navigation-ui-ktx:2.7.6'
implementation 'androidx.core:core-ktx:1.12.0'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'

implementation 'com.google.android.material:material:1.10.0'
implementation 'com.google.android.material:material:1.11.0'
implementation 'com.squareup.okhttp3:okhttp:4.10.0'
}
Binary file added APP/app/release/app-release.aab
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class ApiAddressManager(context: Context) {
private const val KEY_API_ADDRESS = ""

// Default API address
private const val DEFAULT_API_ADDRESS = "http://10.0.1.1:9000/system_info.json"
private const val DEFAULT_API_ADDRESS = "http://10.0.1.1:9002/api"
}

private val sharedPreferences: SharedPreferences = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class MainActivity : AppCompatActivity() {
fetchDataAndUpdateIcon(navView)
handler.postDelayed(this, 5000) // 5000 milliseconds = 5 seconds
}
}, 5000) // Initial delay also set to 5 seconds
}, 5000) // Initial delay set to 5 seconds
}

@RequiresApi(Build.VERSION_CODES.TIRAMISU)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.marekguran.serverinfo.ui.hardware

import android.annotation.SuppressLint
import android.content.Context
import android.graphics.Color
import android.os.AsyncTask
Expand Down Expand Up @@ -209,7 +210,7 @@ class HardwareFragment : Fragment() {
val networkNameTextView = TextView(context)
networkNameTextView.text = name
networkNameTextView.setTextColor(Color.parseColor("#f2f2fb"))
networkNameTextView.setTextSize(16F)
networkNameTextView.textSize = 16F

val networkSpeedTextView = TextView(context)
val runningLabel = context.getString(R2.string.running)
Expand All @@ -218,7 +219,7 @@ class HardwareFragment : Fragment() {
networkSpeedTextView.text = "$runningLabel $isUp\n$speedLabel $speed"
networkSpeedTextView.setTextColor(Color.parseColor("#f2f2fb"))
networkSpeedTextView.setPadding(0, 0, 0, 10)
networkSpeedTextView.setTextSize(16F)
networkSpeedTextView.textSize = 16F

networkContainer.addView(networkNameTextView)
networkContainer.addView(networkSpeedTextView)
Expand Down Expand Up @@ -246,7 +247,7 @@ class HardwareFragment : Fragment() {
storageNameTextView.text = "$name \n$mounted $mountedStorage\n" +
"$fs $fstypeStorage"
storageNameTextView.setTextColor(Color.parseColor("#f2f2fb"))
storageNameTextView.setTextSize(16F)
storageNameTextView.textSize = 16F
storageNameTextView.setPadding(0, 0, 0, 5)

val progressBar = ProgressBar(
Expand All @@ -271,7 +272,7 @@ class HardwareFragment : Fragment() {
val progressBarTextView = TextView(context)
progressBarTextView.text = "$storage1 $usedStorage $storage2 $totalStorage"
progressBarTextView.setTextColor(Color.parseColor("#f2f2fb"))
progressBarTextView.setTextSize(16F)
progressBarTextView.textSize = 16F
progressBarTextView.setPadding(0, 5, 0, 10)

storageContainer.addView(storageNameTextView)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package com.marekguran.serverinfo.ui.settings

import android.content.Intent
import android.content.pm.PackageInfo
import android.content.pm.PackageManager
import android.net.Uri
import android.os.AsyncTask
import android.os.Bundle
Expand All @@ -12,7 +10,6 @@ import android.view.View
import android.view.ViewGroup
import android.widget.Button
import android.widget.EditText
import android.widget.Switch
import android.widget.TextView
import android.widget.Toast
import androidx.fragment.app.Fragment
Expand Down Expand Up @@ -58,8 +55,7 @@ class SettingsFragment : Fragment() {

darkModeSwitch?.setOnCheckedChangeListener { _, isChecked ->
// Convert isChecked (true or false) to a boolean
val isEnabled = isChecked
darkMode.setDarkModeEnabled(isEnabled)
darkMode.setDarkModeEnabled(isChecked)
requireActivity().recreate()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ class SystemFragment : Fragment() {
savedInstanceState: Bundle?
): View {
_binding = FragmentSystemBinding.inflate(inflater, container, false)

return binding.root
}

Expand Down Expand Up @@ -76,7 +75,7 @@ class SystemFragment : Fragment() {
fetchDataAndUpdateViews()
handler.postDelayed(this, 1000) // Update every 1 second
}
}, 1000) // Initial delay also set to 1 second
}, 500) // Initial delay also set to 500 mili-seconds
}

private inner class FetchJsonDataTask : AsyncTask<String, Void, JSONObject>() {
Expand Down Expand Up @@ -111,44 +110,58 @@ class SystemFragment : Fragment() {
@SuppressLint("SetTextI18n")
@Deprecated("Deprecated in Java")
override fun onPostExecute(jsonObject: JSONObject?) {
if (binding != null) {
val localBinding = _binding
if (localBinding == null || jsonObject == null) {
super.onPostExecute(jsonObject)
jsonObject?.let {
val os = jsonObject.getJSONObject("os")
return
}

with(localBinding) {
jsonObject?.let { json ->
// Parse OS information
val os = json.getJSONObject("os")
val distribution = os.getString("distribution")
val kernel = os.getString("kernel_version")
val cpuName = jsonObject.getJSONObject("cpu").getString("hardware")
val cpuArchitecture = jsonObject.getJSONObject("cpu").getString("architecture")
val cpuArchitectureType =
jsonObject.getJSONObject("cpu").getString("architecture_type")
val cpuType = jsonObject.getJSONObject("cpu").getString("type")
val cpuCores = jsonObject.getJSONObject("cpu").getString("cores")
val uptimeInSeconds = os.getString("uptime")
val networkDevices = jsonObject.getJSONObject("network")

val distributionText = context?.getString(R2.string.distribution)
val kernelText = context?.getString(R2.string.kernel)
val uptimeText = context?.getString(R2.string.uptime)
val cpuText = context?.getString(R2.string.cpu_sys)
val architectureText = context?.getString(R2.string.architecture)
val typeText = context?.getString(R2.string.type)
val coresText = context?.getString(R2.string.cores)
val networkDevicesText = context?.getString(R2.string.network_devices)
// Parse CPU information
val cpu = json.getJSONObject("cpu")
val coresJson = cpu.getJSONObject("cores")
var coreCount = 0
val keys = coresJson.keys()
val cpuName = cpu.getString("hardware")
val cpuArchitecture = cpu.getString("architecture")
val cpuArchitectureType = cpu.getString("architecture_type")
val cpuType = cpu.getString("type")
val cpuCores = cpu.getString("cores")

// Parse network information
val networkJson = json.getJSONObject("network")
var networkDeviceCount = 0
val networkkeys = networkJson.keys()

while (networkkeys.hasNext()) {
networkkeys.next() // Move to the next key
networkDeviceCount++
}

val networkDevicesText = getString(R2.string.network_devices)
val networkDevicesDisplay = "$networkDevicesText $networkDeviceCount"
NetworkDevices.text = networkDevicesDisplay

// Update UI components with the parsed data
if (!TextUtils.isEmpty(distribution)) {
binding!!.Distribution?.text = "$distributionText $distribution"
Distribution.text = "${getString(R2.string.distribution)} $distribution"
}
if (!TextUtils.isEmpty(kernel)) {
binding.Kernel.text = "$kernelText $kernel"
Kernel.text = "${getString(R2.string.kernel)} $kernel"
}
if (!TextUtils.isEmpty(uptimeInSeconds)) {
val uptimeSplit = uptimeInSeconds.split(".")
val uptimeInSecondsInt = uptimeSplit[0].toLong()
val uptimeFraction =
uptimeSplit[1].substring(0, 2).toLong() // Extract seconds as well
val uptimeFraction = if (uptimeSplit.size > 1) uptimeSplit[1].substring(0, 2).toLong() else 0L

val timestamp =
uptimeInSecondsInt * 1000 + uptimeFraction // Convert to milliseconds
val timestamp = uptimeInSecondsInt * 1000 + uptimeFraction // Convert to milliseconds
val currentTimeMillis = System.currentTimeMillis()
val uptimeMillis = currentTimeMillis - timestamp

Expand All @@ -157,48 +170,27 @@ class SystemFragment : Fragment() {
val minutes = TimeUnit.MILLISECONDS.toMinutes(uptimeMillis) % 60
val seconds = TimeUnit.MILLISECONDS.toSeconds(uptimeMillis) % 60

val formattedUptime =
String.format("%02d:%02d:%02d:%02d", days, hours, minutes, seconds)
binding.Uptime.text = "$uptimeText $formattedUptime"
val formattedUptime = String.format("%02d:%02d:%02d:%02d", days, hours, minutes, seconds)
Uptime.text = "${getString(R2.string.uptime)} $formattedUptime"
}
if (!TextUtils.isEmpty(cpuName)) {
binding.CpuName.text = "$cpuText $cpuName"
CpuName.text = "${getString(R2.string.cpu_sys)} $cpuName"
}
if (!TextUtils.isEmpty(cpuArchitecture)) {
binding.CpuArchitecture.text =
"$architectureText $cpuArchitectureType - $cpuArchitecture"
CpuArchitecture.text = "${getString(R2.string.architecture)} $cpuArchitectureType - $cpuArchitecture"
}
if (!TextUtils.isEmpty(cpuType)) {
binding.CpuType.text = "$typeText $cpuType"
CpuType.text = "${getString(R2.string.type)} $cpuType"
}
if (!TextUtils.isEmpty(cpuCores)) {
val coresJson = jsonObject.getJSONObject("cpu").getJSONObject("cores")
var coreCount = 0
val keys = coresJson.keys()

while (keys.hasNext()) {
val key = keys.next()
if (key.startsWith("core_")) {
coreCount++
}
while (keys.hasNext()) {
val key = keys.next()
if (key.startsWith("core_")) {
coreCount++
}

val cpuCores = "$coresText $coreCount"
binding.CpuCores.text = cpuCores
}
if (!TextUtils.isEmpty(networkDevices.toString())) {
val networkJson = jsonObject.getJSONObject("network")
var networkDeviceCount = 0
val keys = networkJson.keys()

while (keys.hasNext()) {
keys.next() // Move to the next key
networkDeviceCount++
}

val networkDevices = "$networkDevicesText $networkDeviceCount"
binding.NetworkDevices.text = networkDevices
}
CpuCores.text = "${getString(R2.string.cores)} $coreCount"

val distributionImageResource = when {
distribution.toLowerCase(Locale.ROOT)
.contains("ubuntu") -> R.drawable.sys_ubuntu
Expand Down Expand Up @@ -226,6 +218,7 @@ class SystemFragment : Fragment() {
binding.cpuImage.setImageResource(cpuImageResource)
}
}

}
}
}
}
4 changes: 2 additions & 2 deletions APP/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ buildscript {
}
}// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id 'com.android.application' version '8.1.4' apply false
id 'com.android.library' version '8.1.4' apply false
id 'com.android.application' version '8.2.0' apply false
id 'com.android.library' version '8.2.0' apply false
id 'org.jetbrains.kotlin.android' version '1.8.0' apply false
}
2 changes: 1 addition & 1 deletion APP/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Fri Apr 28 09:59:53 CEST 2023
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

0 comments on commit 6f6f4ae

Please sign in to comment.