This commit is contained in:
2026-06-16 11:24:21 +03:00
parent 3399e81447
commit 64607def4a
9 changed files with 346 additions and 72 deletions
@@ -13,6 +13,7 @@ public class SettingsRepository {
private static final String KEY_RANGE_REGEX = "range_regex";
private static final String KEY_TELNET_ENABLED = "telnet_enabled";
private static final String KEY_DEVICE_ID = "device_id";
private static final String KEY_DEVICE_LABEL = "device_label";
public static final String DEFAULT_SERVER = "https://lora.grigowashere.ru";
private static final String LEGACY_SERVER_HTTP = "http://grigowashere.ru:7634";
@@ -106,4 +107,16 @@ public class SettingsRepository {
}
return id;
}
public String getDeviceLabel() {
return prefs.getString(KEY_DEVICE_LABEL, null);
}
public void setDeviceLabel(String label) {
if (label == null) {
prefs.edit().remove(KEY_DEVICE_LABEL).apply();
} else {
prefs.edit().putString(KEY_DEVICE_LABEL, label.trim()).apply();
}
}
}
@@ -317,7 +317,11 @@ public class TelemetryUploader implements TelnetClient.Listener {
});
}
private static String phoneLabel() {
private String phoneLabel() {
String custom = settings.getDeviceLabel();
if (custom != null && !custom.isBlank()) {
return custom.trim();
}
String manufacturer = Build.MANUFACTURER != null ? Build.MANUFACTURER : "";
String model = Build.MODEL != null ? Build.MODEL : "";
String label = (manufacturer + " " + model).trim();
@@ -42,6 +42,7 @@ public class SettingsFragment extends Fragment {
TextInputEditText editPort = view.findViewById(R.id.editTelnetPort);
TextInputEditText editRssi = view.findViewById(R.id.editRssiRegex);
TextInputEditText editRange = view.findViewById(R.id.editRangeRegex);
TextInputEditText editDeviceLabel = view.findViewById(R.id.editDeviceLabel);
SwitchMaterial switchTelnet = view.findViewById(R.id.switchTelnet);
TextView deviceIdLabel = view.findViewById(R.id.deviceIdLabel);
Button save = view.findViewById(R.id.btnSaveSettings);
@@ -51,6 +52,10 @@ public class SettingsFragment extends Fragment {
editPort.setText(String.valueOf(settings.getTelnetPort()));
editRssi.setText(settings.getRssiRegex());
editRange.setText(settings.getRangeRegex());
String savedLabel = settings.getDeviceLabel();
if (savedLabel != null) {
editDeviceLabel.setText(savedLabel);
}
switchTelnet.setChecked(settings.isTelnetEnabled());
deviceIdLabel.setText(getString(R.string.device_id_label, settings.getOrCreateDeviceId()));
@@ -64,8 +69,10 @@ public class SettingsFragment extends Fragment {
}
settings.setRssiRegex(textOf(editRssi, SettingsRepository.DEFAULT_RSSI_REGEX));
settings.setRangeRegex(textOf(editRange, SettingsRepository.DEFAULT_RANGE_REGEX));
settings.setDeviceLabel(textOf(editDeviceLabel, ""));
settings.setTelnetEnabled(switchTelnet.isChecked());
uploader.refreshApi();
uploader.registerPresence();
if (switchTelnet.isChecked()) {
uploader.startTelnet();
} else {
@@ -73,6 +73,19 @@
android:inputType="text" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:hint="@string/device_display_name">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/editDeviceLabel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textCapWords" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.switchmaterial.SwitchMaterial
android:id="@+id/switchTelnet"
android:layout_width="match_parent"
+1
View File
@@ -17,6 +17,7 @@
<string name="range_regex">Range regex</string>
<string name="telnet_enabled">Подключить telnet</string>
<string name="device_id_label">ID устройства: %1$s</string>
<string name="device_display_name">Имя на карте (realme, OPPO…)</string>
<string name="save">Сохранить</string>
<string name="saved">Сохранено</string>
<string name="chat_hint">Сообщение…</string>