mirror of
https://github.com/vernu/textbee.git
synced 2026-02-20 07:34:00 -05:00
feat(android): allow setting custom device name
This commit is contained in:
@@ -23,4 +23,5 @@ public class AppConstants {
|
||||
public static final String SHARED_PREFS_HEARTBEAT_ENABLED_KEY = "HEARTBEAT_ENABLED";
|
||||
public static final String SHARED_PREFS_HEARTBEAT_INTERVAL_MINUTES_KEY = "HEARTBEAT_INTERVAL_MINUTES";
|
||||
public static final String SHARED_PREFS_SMS_FILTER_CONFIG_KEY = "SMS_FILTER_CONFIG";
|
||||
public static final String SHARED_PREFS_DEVICE_NAME_KEY = "DEVICE_NAME";
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ public class MainActivity extends AppCompatActivity {
|
||||
|
||||
private Context mContext;
|
||||
private Switch gatewaySwitch, receiveSMSSwitch, stickyNotificationSwitch;
|
||||
private EditText apiKeyEditText, fcmTokenEditText, deviceIdEditText;
|
||||
private EditText apiKeyEditText, fcmTokenEditText, deviceIdEditText, deviceNameEditText;
|
||||
private Button registerDeviceBtn, grantSMSPermissionBtn, scanQRBtn, checkUpdatesBtn, configureFilterBtn;
|
||||
private ImageButton copyDeviceIdImgBtn;
|
||||
private TextView deviceBrandAndModelTxt, deviceIdTxt, appVersionNameTxt, appVersionCodeTxt;
|
||||
@@ -72,6 +72,7 @@ public class MainActivity extends AppCompatActivity {
|
||||
apiKeyEditText = findViewById(R.id.apiKeyEditText);
|
||||
fcmTokenEditText = findViewById(R.id.fcmTokenEditText);
|
||||
deviceIdEditText = findViewById(R.id.deviceIdEditText);
|
||||
deviceNameEditText = findViewById(R.id.deviceNameEditText);
|
||||
registerDeviceBtn = findViewById(R.id.registerDeviceBtn);
|
||||
grantSMSPermissionBtn = findViewById(R.id.grantSMSPermissionBtn);
|
||||
scanQRBtn = findViewById(R.id.scanQRButton);
|
||||
@@ -147,6 +148,12 @@ public class MainActivity extends AppCompatActivity {
|
||||
});
|
||||
|
||||
apiKeyEditText.setText(SharedPreferenceHelper.getSharedPreferenceString(mContext, AppConstants.SHARED_PREFS_API_KEY_KEY, ""));
|
||||
String storedDeviceName = SharedPreferenceHelper.getSharedPreferenceString(mContext, AppConstants.SHARED_PREFS_DEVICE_NAME_KEY, "");
|
||||
if (storedDeviceName.isEmpty()) {
|
||||
deviceNameEditText.setText(Build.BRAND + " " + Build.MODEL);
|
||||
} else {
|
||||
deviceNameEditText.setText(storedDeviceName);
|
||||
}
|
||||
gatewaySwitch.setChecked(SharedPreferenceHelper.getSharedPreferenceBoolean(mContext, AppConstants.SHARED_PREFS_GATEWAY_ENABLED_KEY, false));
|
||||
gatewaySwitch.setOnCheckedChangeListener((compoundButton, isCheked) -> {
|
||||
View view = compoundButton.getRootView();
|
||||
@@ -425,6 +432,13 @@ public class MainActivity extends AppCompatActivity {
|
||||
registerDeviceInput.setAppVersionCode(BuildConfig.VERSION_CODE);
|
||||
registerDeviceInput.setAppVersionName(BuildConfig.VERSION_NAME);
|
||||
|
||||
// Get device name from input field or default to "brand model"
|
||||
String deviceName = deviceNameEditText.getText().toString().trim();
|
||||
if (deviceName.isEmpty()) {
|
||||
deviceName = Build.BRAND + " " + Build.MODEL;
|
||||
}
|
||||
registerDeviceInput.setName(deviceName);
|
||||
|
||||
// Collect SIM information
|
||||
SimInfoCollectionDTO simInfoCollection = new SimInfoCollectionDTO();
|
||||
simInfoCollection.setLastUpdated(System.currentTimeMillis());
|
||||
@@ -467,6 +481,14 @@ public class MainActivity extends AppCompatActivity {
|
||||
}
|
||||
}
|
||||
|
||||
// Sync device name from server response
|
||||
if (response.body().data.get("name") != null) {
|
||||
String deviceName = response.body().data.get("name").toString();
|
||||
SharedPreferenceHelper.setSharedPreferenceString(mContext, AppConstants.SHARED_PREFS_DEVICE_NAME_KEY, deviceName);
|
||||
deviceNameEditText.setText(deviceName);
|
||||
Log.d(TAG, "Synced device name from server: " + deviceName);
|
||||
}
|
||||
|
||||
// Schedule heartbeat if device is enabled
|
||||
if (registerDeviceInput.isEnabled()) {
|
||||
HeartbeatManager.scheduleHeartbeat(mContext);
|
||||
@@ -525,6 +547,14 @@ public class MainActivity extends AppCompatActivity {
|
||||
}
|
||||
}
|
||||
|
||||
// Sync device name from server response
|
||||
if (response.body().data.get("name") != null) {
|
||||
String deviceName = response.body().data.get("name").toString();
|
||||
SharedPreferenceHelper.setSharedPreferenceString(mContext, AppConstants.SHARED_PREFS_DEVICE_NAME_KEY, deviceName);
|
||||
deviceNameEditText.setText(deviceName);
|
||||
Log.d(TAG, "Synced device name from server: " + deviceName);
|
||||
}
|
||||
|
||||
// Schedule heartbeat if device is enabled
|
||||
if (registerDeviceInput.isEnabled()) {
|
||||
HeartbeatManager.scheduleHeartbeat(mContext);
|
||||
@@ -581,6 +611,13 @@ public class MainActivity extends AppCompatActivity {
|
||||
updateDeviceInput.setAppVersionCode(BuildConfig.VERSION_CODE);
|
||||
updateDeviceInput.setAppVersionName(BuildConfig.VERSION_NAME);
|
||||
|
||||
// Get device name from input field or default to "brand model"
|
||||
String deviceName = deviceNameEditText.getText().toString().trim();
|
||||
if (deviceName.isEmpty()) {
|
||||
deviceName = Build.BRAND + " " + Build.MODEL;
|
||||
}
|
||||
updateDeviceInput.setName(deviceName);
|
||||
|
||||
// Collect SIM information
|
||||
SimInfoCollectionDTO simInfoCollection = new SimInfoCollectionDTO();
|
||||
simInfoCollection.setLastUpdated(System.currentTimeMillis());
|
||||
@@ -617,6 +654,14 @@ public class MainActivity extends AppCompatActivity {
|
||||
}
|
||||
}
|
||||
|
||||
// Sync device name from server response
|
||||
if (response.body().data.get("name") != null) {
|
||||
String deviceName = response.body().data.get("name").toString();
|
||||
SharedPreferenceHelper.setSharedPreferenceString(mContext, AppConstants.SHARED_PREFS_DEVICE_NAME_KEY, deviceName);
|
||||
deviceNameEditText.setText(deviceName);
|
||||
Log.d(TAG, "Synced device name from server: " + deviceName);
|
||||
}
|
||||
|
||||
// Schedule heartbeat if device is enabled
|
||||
if (updateDeviceInput.isEnabled()) {
|
||||
HeartbeatManager.scheduleHeartbeat(mContext);
|
||||
|
||||
@@ -4,4 +4,5 @@ public class HeartbeatResponseDTO {
|
||||
public boolean success;
|
||||
public boolean fcmTokenUpdated;
|
||||
public long lastHeartbeat;
|
||||
public String name;
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ public class RegisterDeviceInputDTO {
|
||||
private String brand;
|
||||
private String manufacturer;
|
||||
private String model;
|
||||
private String name;
|
||||
private String serial;
|
||||
private String buildId;
|
||||
private String os;
|
||||
@@ -61,6 +62,14 @@ public class RegisterDeviceInputDTO {
|
||||
this.model = model;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getSerial() {
|
||||
return serial;
|
||||
}
|
||||
|
||||
@@ -153,6 +153,17 @@ public class HeartbeatHelper {
|
||||
if (responseBody.fcmTokenUpdated) {
|
||||
Log.d(TAG, "FCM token was updated during heartbeat");
|
||||
}
|
||||
|
||||
// Sync device name from heartbeat response (ignore if blank)
|
||||
if (responseBody.name != null && !responseBody.name.trim().isEmpty()) {
|
||||
SharedPreferenceHelper.setSharedPreferenceString(
|
||||
context,
|
||||
AppConstants.SHARED_PREFS_DEVICE_NAME_KEY,
|
||||
responseBody.name
|
||||
);
|
||||
Log.d(TAG, "Synced device name from heartbeat: " + responseBody.name);
|
||||
}
|
||||
|
||||
Log.d(TAG, "Heartbeat sent successfully");
|
||||
return true;
|
||||
} else {
|
||||
|
||||
@@ -252,6 +252,25 @@
|
||||
android:textIsSelectable="true" />
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
|
||||
<com.google.android.material.textfield.TextInputLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="16dp"
|
||||
android:hint="Device name (optional)"
|
||||
app:boxBackgroundColor="@android:color/transparent"
|
||||
app:boxStrokeColor="?attr/colorPrimary"
|
||||
app:hintTextColor="?attr/colorPrimary"
|
||||
app:endIconTint="?attr/colorPrimary">
|
||||
|
||||
<com.google.android.material.textfield.TextInputEditText
|
||||
android:id="@+id/deviceNameEditText"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:inputType="text"
|
||||
android:textColor="@color/text_primary"
|
||||
android:textIsSelectable="true" />
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
|
||||
<EditText
|
||||
android:id="@+id/fcmTokenEditText"
|
||||
android:layout_width="wrap_content"
|
||||
|
||||
Reference in New Issue
Block a user