97 {
98 if (bookmarkLiveData.getValue() != null)
99 return;
100
101 executor.execute(() -> {
102 BookmarkBase bookmark = null;
103 boolean isNew = false;
104
105 if (bundle != null && bundle.containsKey(BookmarkActivity.PARAM_CONNECTION_REFERENCE))
106 {
107 String refStr = bundle.getString(BookmarkActivity.PARAM_CONNECTION_REFERENCE);
108
109 if (ConnectionReference.isBookmarkReference(refStr))
110 {
111 bookmark =
112 manualBookmarkGateway.findById(ConnectionReference.getBookmarkId(refStr));
113 isNew = false;
114 }
115 else if (ConnectionReference.isHostnameReference(refStr))
116 {
117 bookmark = new BookmarkBase();
118 bookmark.setLabel(ConnectionReference.getHostname(refStr));
119 bookmark.setHostname(ConnectionReference.getHostname(refStr));
120 isNew = true;
121 }
122 else if (ConnectionReference.isFileReference(refStr))
123 {
124 String file = ConnectionReference.getFile(refStr);
125 bookmark = new BookmarkBase();
126 bookmark.setLabel(file);
127 try
128 {
129 RDPFileParser rdpFile = new RDPFileParser(file);
130 updateBookmarkFromFile(bookmark, rdpFile);
131 bookmark.setLabel(new File(file).getName());
132 isNew = true;
133 }
134 catch (IOException e)
135 {
136 Log.e(TAG, "Failed reading RDP file", e);
137 }
138 }
139 }
140
141 if (bookmark == null)
142 {
143 bookmark = new BookmarkBase();
144 }
145
146 this.newBookmark = isNew;
147 this.settingsChanged = false;
148
149
150 prefs.edit().clear().apply();
151 bookmark.writeToSharedPreferences(prefs);
152
153
154 bookmarkLiveData.postValue(bookmark);
155 });
156 }