Skip to content

Commit f6b8624

Browse files
[controller] improve dashboard layout and information displayed
1 parent 1c636e6 commit f6b8624

9 files changed

Lines changed: 124 additions & 154 deletions

File tree

‎controller/.gitignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ app/release/
1717

1818
# Ignore all native compiled libraries inside jniLibs directory
1919
**/jniLibs/**/*.so
20+
app/src/main/jniLibs/
2021

2122
*store.properties
2223
*.jks

‎controller/app/src/main/java/org/iiab/controller/DashboardFragment.java‎

Lines changed: 18 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ public class DashboardFragment extends Fragment {
4343

4444
private TextView txtDeviceName;
4545
private TextView txtAndroidVersion;
46-
private TextView txtWifiIp, txtHotspotIp, txtUptime, txtBattery, badgeStatus, txtTermuxState;
46+
private TextView txtHostArch;
47+
private TextView txtWifiIp, txtHotspotIp, txtUptime, badgeStatus, txtTermuxState;
4748

4849
// --- GAUGE VARIABLES ---
4950
private ResourceGaugeView gaugeStorage, gaugeRam, gaugeSwap, gaugeBattery;
@@ -106,6 +107,7 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
106107
// Bindings
107108
txtDeviceName = view.findViewById(R.id.dash_text_device_name);
108109
txtAndroidVersion = view.findViewById(R.id.dash_text_android_version);
110+
txtHostArch = view.findViewById(R.id.dash_text_host_arch);
109111

110112
// --- DIAGNOSTIC BYPASS (AGGRESSIVE ALERT DIALOG) ---
111113
txtDeviceName.setOnClickListener(v -> {
@@ -135,7 +137,6 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
135137
txtWifiIp = view.findViewById(R.id.dash_text_wifi_ip);
136138
txtHotspotIp = view.findViewById(R.id.dash_text_hotspot_ip);
137139
txtUptime = view.findViewById(R.id.dash_text_uptime);
138-
txtBattery = view.findViewById(R.id.dash_text_battery);
139140
badgeStatus = view.findViewById(R.id.dash_badge_status);
140141

141142
gaugeStorage = view.findViewById(R.id.gauge_storage);
@@ -217,9 +218,14 @@ private void updateSystemStats() {
217218
// --- FETCH AND DISPLAY BASE ANDROID VERSION ---
218219
String androidRelease = android.os.Build.VERSION.RELEASE;
219220
int sdkVersion = android.os.Build.VERSION.SDK_INT;
220-
txtAndroidVersion.setText(getString(R.string.dash_android_version_value, androidRelease, String.valueOf(sdkVersion)));
221+
txtAndroidVersion.setText(getString(R.string.dash_android_version_value, "v" + androidRelease, String.valueOf(sdkVersion)));
221222

222-
// --- 0. CALCULATE SERVER UPTIME ---
223+
// --- FETCH AND DISPLAY HOST ARCHITECTURE ---
224+
if (txtHostArch != null) {
225+
txtHostArch.setText(getTermuxArch());
226+
}
227+
228+
// --- CALCULATE SERVER UPTIME ---
223229
long uptimeMillis = android.os.SystemClock.elapsedRealtime();
224230
long minutes = (uptimeMillis / (1000 * 60)) % 60;
225231
long hours = (uptimeMillis / (1000 * 60 * 60)) % 24;
@@ -234,23 +240,15 @@ private void updateSystemStats() {
234240
txtWifiIp.setText(getWifiIp());
235241
txtHotspotIp.setText(getHotspotIp());
236242

237-
int batteryLevelText = getBatteryPercentage();
238-
if (batteryLevelText >= 0) {
239-
txtBattery.setText(getString(R.string.dash_format_pct, batteryLevelText));
240-
} else {
241-
txtBattery.setText(R.string.dash_format_pct_na);
242-
}
243-
244-
// --- 1. GET REAL RAM AND SWAP FROM LINUX ---
243+
// --- GET REAL RAM AND SWAP FROM LINUX ---
245244
long memTotal = 0, memAvailable = 0, swapTotal = 0, swapFree = 0;
246245
try (BufferedReader br = new BufferedReader(new FileReader("/proc/meminfo"))) {
247246
String line;
248247
while ((line = br.readLine()) != null) {
249248
if (line.startsWith("MemTotal:")) memTotal = parseMemLine(line);
250249
else if (line.startsWith("MemAvailable:")) memAvailable = parseMemLine(line);
251-
// If phone is old and doesn't have "MemAvailable", use "MemFree"
252-
else if (memAvailable == 0 && line.startsWith("MemFree:"))
253-
memAvailable = parseMemLine(line);
250+
// If phone is old and doesn't have "MemAvailable", use "MemFree"
251+
else if (memAvailable == 0 && line.startsWith("MemFree:")) memAvailable = parseMemLine(line);
254252
else if (line.startsWith("SwapTotal:")) swapTotal = parseMemLine(line);
255253
else if (line.startsWith("SwapFree:")) swapFree = parseMemLine(line);
256254
}
@@ -268,7 +266,7 @@ else if (memAvailable == 0 && line.startsWith("MemFree:"))
268266
int swapProgress = swapTotal > 0 ? (int) (((swapTotal - swapFree) * 100) / swapTotal) : 0;
269267

270268
File path = android.os.Environment.getDataDirectory();
271-
long totalSpace = path.getTotalSpace() / (1024 * 1024 * 1024); // To GB
269+
long totalSpace = path.getTotalSpace() / (1024 * 1024 * 1024);
272270
long freeSpace = path.getFreeSpace() / (1024 * 1024 * 1024);
273271
long usedSpace = totalSpace - freeSpace;
274272

@@ -348,16 +346,10 @@ else if (memAvailable == 0 && line.startsWith("MemFree:"))
348346
// Only add the lightning bolt if isCharging is true
349347
String batStr = isCharging ? getString(R.string.dash_format_pct_charging, batLevel) : getString(R.string.dash_format_pct, batLevel);
350348
gaugeBattery.updateData(batLevel, batStr, getString(R.string.dash_battery_title), colorBattery);
351-
352-
// Update the small text above as well ("Battery: 95%")
353-
if (txtBattery != null) {
354-
txtBattery.setText(getString(R.string.dash_format_pct, batLevel));
355-
}
356349
} else {
357350
// Default fallback if we can't read the battery
358351
colorBattery = ContextCompat.getColor(requireContext(), R.color.dash_text_secondary);
359352
gaugeBattery.updateData(0, getString(R.string.dash_format_pct_na), getString(R.string.dash_battery_title), colorBattery);
360-
if (txtBattery != null) txtBattery.setText(R.string.dash_format_pct_na);
361353
}
362354
}
363355
}
@@ -384,7 +376,7 @@ private void createModuleViews() {
384376
java.util.List<IiabModule> activeModules = new java.util.ArrayList<>();
385377
for (IiabModule module : MASTER_ROSTER) {
386378
if (module.requires64Bit && !is64Bit) {
387-
continue; // Skip this module entirely for 32-bit devices
379+
continue;
388380
}
389381
activeModules.add(module);
390382
}
@@ -418,7 +410,7 @@ private void createModuleViews() {
418410
cell.setLayoutParams(cellParams);
419411

420412
if (index < activeModules.size()) {
421-
IiabModule currentMod = activeModules.get(index); // Get the module object
413+
IiabModule currentMod = activeModules.get(index);
422414

423415
cell.setOrientation(LinearLayout.HORIZONTAL);
424416
cell.setBackgroundResource(R.drawable.rounded_button);
@@ -450,9 +442,8 @@ private void createModuleViews() {
450442
// The background ping thread relies on this tag to check the URL!
451443
cell.setTag(currentMod.endpoint);
452444
} else {
453-
cell.setVisibility(View.INVISIBLE); // Fill empty spaces to keep grid aligned
445+
cell.setVisibility(View.INVISIBLE);
454446
}
455-
456447
rowLayout.addView(cell);
457448
}
458449
modulesContainer.addView(rowLayout);
@@ -527,7 +518,7 @@ private void checkServerAndModules() {
527518
txtTermuxState.setText(getString(R.string.dash_state_installer));
528519
txtTermuxState.setTextColor(androidx.core.content.ContextCompat.getColor(requireContext(), R.color.dash_text_primary));
529520
break;
530-
case TERMUX_ONLY: // Fallthrough intended
521+
case TERMUX_ONLY: // Fallthrough intended; no longer used
531522
case NONE:
532523
ledTermuxState.setBackgroundResource(R.drawable.led_off);
533524
txtTermuxState.setText(getString(R.string.dash_state_none));
@@ -617,21 +608,6 @@ private String getIpByInterface(String interfaceName) {
617608
return "--";
618609
}
619610

620-
private int getBatteryPercentage() {
621-
try {
622-
IntentFilter iFilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
623-
Intent batteryStatus = requireContext().registerReceiver(null, iFilter);
624-
if (batteryStatus != null) {
625-
int level = batteryStatus.getIntExtra(BatteryManager.EXTRA_LEVEL, -1);
626-
int scale = batteryStatus.getIntExtra(BatteryManager.EXTRA_SCALE, -1);
627-
return (int) ((level / (float) scale) * 100);
628-
}
629-
} catch (Exception e) {
630-
e.printStackTrace();
631-
}
632-
return -1;
633-
}
634-
635611
// --- METHODS FOR OBTAINING THE DEVICE NAME ---
636612
private String getDeviceName() {
637613
String manufacturer = android.os.Build.MANUFACTURER;

0 commit comments

Comments
 (0)