Skip to content

Commit ae8bc1a

Browse files
authored
Merge pull request #33 from jpage4500/feature/01-21
- allow phone number to be overridden since adb can't always fetch this value
2 parents 7783285 + 082ae31 commit ae8bc1a

File tree

4 files changed

+41
-17
lines changed

4 files changed

+41
-17
lines changed

src/main/java/com/jpage4500/devicemanager/data/Device.java

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public class Device {
2222
public final static String CUSTOM_PROP_X = "custom";
2323
public final static String CUST_PROP_1 = "custom1";
2424
public final static String CUST_PROP_2 = "custom2";
25+
public final static String CUST_PROP_PHONE = "phone_number";
2526

2627
public enum PowerStatus {
2728
POWER_NONE,

src/main/java/com/jpage4500/devicemanager/manager/DeviceManager.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -690,7 +690,8 @@ public void setProperty(Device device, String key, String value, TaskListener li
690690
commandExecutorService.submit(() -> {
691691
if (device.customPropertyMap == null) device.customPropertyMap = new HashMap<>();
692692
// update property
693-
device.customPropertyMap.put(key, value);
693+
if (TextUtils.isEmpty(value)) device.customPropertyMap.remove(key);
694+
else device.customPropertyMap.put(key, value);
694695
// turn into key=value string
695696
StringBuilder sb = new StringBuilder();
696697
for (Map.Entry<String, String> entry : device.customPropertyMap.entrySet()) {

src/main/java/com/jpage4500/devicemanager/table/DeviceTableModel.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,11 @@ public String deviceValue(Device device, int column) {
170170
case MODEL -> device.getProperty(Device.PROP_MODEL);
171171
case OS -> device.getProperty(Device.PROP_OS);
172172
case CARRIER -> device.getCarrier();
173-
case PHONE -> device.phone;
173+
case PHONE -> {
174+
String customPhone = device.getCustomProperty(Device.CUST_PROP_PHONE);
175+
if (TextUtils.notEmpty(customPhone)) yield customPhone;
176+
else yield device.phone;
177+
}
174178
case IMEI -> device.imei;
175179
case FREE -> FileUtils.bytesToGigDisplayString(device.freeSpace);
176180
case BATTERY -> {

src/main/java/com/jpage4500/devicemanager/ui/DeviceScreen.java

+33-15
Original file line numberDiff line numberDiff line change
@@ -313,13 +313,24 @@ public void setupTable() {
313313
table.setDoubleClickListener((row, column, e) -> {
314314
if (column == DeviceTableModel.Columns.CUSTOM1.ordinal()) {
315315
// edit custom 1 field
316-
handleSetProperty(1);
316+
handleSetProperty(Device.CUSTOM_PROP_X + 1, DeviceTableModel.Columns.CUSTOM1.toString());
317+
return;
317318
} else if (column == DeviceTableModel.Columns.CUSTOM2.ordinal()) {
318319
// edit custom 1 field
319-
handleSetProperty(2);
320-
} else {
321-
handleMirrorCommand();
320+
handleSetProperty(Device.CUSTOM_PROP_X + 2, DeviceTableModel.Columns.CUSTOM2.toString());
321+
return;
322+
} else if (column == DeviceTableModel.Columns.PHONE.ordinal()) {
323+
Device device = getFirstSelectedDevice();
324+
if (device != null) {
325+
if (TextUtils.isEmpty(device.phone)) {
326+
// edit phone number field
327+
handleSetProperty(Device.CUST_PROP_PHONE, "Device Phone Number");
328+
return;
329+
}
330+
}
322331
}
332+
// default double-click action
333+
handleMirrorCommand();
323334
});
324335

325336
// support drag and drop of files IN TO deviceView
@@ -405,6 +416,18 @@ private JPopupMenu getPopupMenu(int row, int column) {
405416
JPopupMenu popupMenu = new JPopupMenu();
406417

407418
if (device.isOnline) {
419+
DeviceTableModel.Columns columnType = model.getColumnType(column);
420+
if (columnType == DeviceTableModel.Columns.CUSTOM1) {
421+
UiUtils.addPopupMenuItem(popupMenu, "Edit Custom Field 1...", actionEvent -> handleSetProperty(Device.CUSTOM_PROP_X + 1, DeviceTableModel.Columns.CUSTOM1.toString()));
422+
popupMenu.addSeparator();
423+
} else if (columnType == DeviceTableModel.Columns.CUSTOM2) {
424+
UiUtils.addPopupMenuItem(popupMenu, "Edit Custom Field 2...", actionEvent -> handleSetProperty(Device.CUSTOM_PROP_X + 2, DeviceTableModel.Columns.CUSTOM2.toString()));
425+
popupMenu.addSeparator();
426+
} else if (columnType == DeviceTableModel.Columns.PHONE) {
427+
UiUtils.addPopupMenuItem(popupMenu, "Edit Phone Number...", actionEvent -> handleSetProperty(Device.CUST_PROP_PHONE, "Device Phone Number"));
428+
popupMenu.addSeparator();
429+
}
430+
408431
UiUtils.addPopupMenuItem(popupMenu, "Copy Field to Clipboard", actionEvent -> handleCopyClipboardFieldCommand());
409432
UiUtils.addPopupMenuItem(popupMenu, "Copy Line to Clipboard", actionEvent -> handleCopyClipboardCommand());
410433
popupMenu.addSeparator();
@@ -414,8 +437,6 @@ private JPopupMenu getPopupMenu(int row, int column) {
414437
UiUtils.addPopupMenuItem(popupMenu, "Capture Screenshot", actionEvent -> handleScreenshotCommand());
415438
UiUtils.addPopupMenuItem(popupMenu, "Restart Device", actionEvent -> handleRestartCommand());
416439
UiUtils.addPopupMenuItem(popupMenu, "Open Terminal", actionEvent -> handleTermCommand());
417-
UiUtils.addPopupMenuItem(popupMenu, "Edit Custom Field 1...", actionEvent -> handleSetProperty(1));
418-
UiUtils.addPopupMenuItem(popupMenu, "Edit Custom Field 2...", actionEvent -> handleSetProperty(2));
419440

420441
if (device.isWireless()) {
421442
popupMenu.addSeparator();
@@ -787,30 +808,27 @@ private void installFiles(List<Device> selectedDeviceList, List<File> apkList) {
787808
* set device property
788809
* uses "persist.dm.custom[number]" for key and prompts user for value
789810
*/
790-
private void handleSetProperty(int number) {
811+
private void handleSetProperty(String property, String description) {
791812
List<Device> selectedDeviceList = getSelectedDevices(true);
792813
if (selectedDeviceList.isEmpty()) return;
793814
String customValue = "";
794815
String message;
795816
if (selectedDeviceList.size() == 1) {
796817
Device device = selectedDeviceList.get(0);
797-
customValue = device.getCustomProperty(Device.CUSTOM_PROP_X + number);
798-
message = "Enter Custom Note";
818+
customValue = device.getCustomProperty(property);
819+
message = "Enter " + description;
799820
} else {
800-
message = "Enter Custom Note for " + selectedDeviceList.size() + " devices";
821+
message = "Enter " + description + " for " + selectedDeviceList.size() + " devices";
801822
}
802823

803-
String result = DialogHelper.showInputDialog(this, "Custom Note (" + number + ")", message, customValue);
824+
String result = DialogHelper.showInputDialog(this, description, message, customValue);
804825
// allow empty input to go through (clear current value)
805826
if (result == null) return;
806827

807828
for (Device device : selectedDeviceList) {
808-
String prop = "custom" + number;
809-
DeviceManager.getInstance().setProperty(device, prop, result, (isSuccess, error) -> {
829+
DeviceManager.getInstance().setProperty(device, property, result, (isSuccess, error) -> {
810830

811831
});
812-
device.setCustomProperty(Device.CUSTOM_PROP_X + number, result);
813-
model.updateDevice(device);
814832
}
815833
}
816834

0 commit comments

Comments
 (0)