From 0539d0b5a07252e7e11caee8e4a17f8e816242a4 Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Thu, 22 Dec 2016 15:14:54 +0900 Subject: [PATCH] Set proper default name for local device --- .../syncthingandroid/util/ConfigXml.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/main/java/com/nutomic/syncthingandroid/util/ConfigXml.java b/src/main/java/com/nutomic/syncthingandroid/util/ConfigXml.java index aa598c63..de2b3c19 100644 --- a/src/main/java/com/nutomic/syncthingandroid/util/ConfigXml.java +++ b/src/main/java/com/nutomic/syncthingandroid/util/ConfigXml.java @@ -72,6 +72,7 @@ public class ConfigXml { } if (isFirstStart) { + changeLocalDeviceName(); changeDefaultFolder(); generateLoginInfo(); } @@ -174,6 +175,23 @@ public class ConfigXml { .getElementsByTagName("gui").item(0); } + /** + * Set model name as device name for Syncthing. + * + * We need to iterate through XML nodes manually, as mConfig.getDocumentElement() will also + * return nested elements inside folder element. + */ + private void changeLocalDeviceName() { + NodeList childNodes = mConfig.getDocumentElement().getChildNodes(); + for (int i = 0; i < childNodes.getLength(); i++) { + Node node = childNodes.item(i); + if (node.getNodeName().equals("device")) { + ((Element) node).setAttribute("name", Build.MODEL); + } + } + saveChanges(); + } + /** * Change default folder id to camera and path to camera folder path. */