104 {
105 if (bookmarkLiveData.getValue() != null)
106 return;
107
108 executor.execute(() -> {
109 BookmarkBase bookmark = null;
110 boolean isNew = false;
111
112 if (bundle != null && bundle.containsKey(BookmarkActivity.PARAM_CONNECTION_REFERENCE))
113 {
114 String refStr = bundle.getString(BookmarkActivity.PARAM_CONNECTION_REFERENCE);
115
116 if (ConnectionReference.isBookmarkReference(refStr))
117 {
118 bookmark =
119 manualBookmarkGateway.findById(ConnectionReference.getBookmarkId(refStr));
120 isNew = false;
121 }
122 else if (ConnectionReference.isHostnameReference(refStr))
123 {
124 bookmark = new BookmarkBase();
125 bookmark.setLabel(ConnectionReference.getHostname(refStr));
126 bookmark.setHostname(ConnectionReference.getHostname(refStr));
127 isNew = true;
128 }
129 else if (ConnectionReference.isFileReference(refStr))
130 {
131 String fileRef = ConnectionReference.getFile(refStr);
132 bookmark = new BookmarkBase();
133 String name = Uri.decode(new File(fileRef).getName());
134 String lower = name.toLowerCase(java.util.Locale.ROOT);
135 if (lower.endsWith(".rdp"))
136 name = name.substring(0, name.length() - 4);
137 else if (lower.endsWith(".rdpw"))
138 name = name.substring(0, name.length() - 5);
139 bookmark.setLabel(name);
140 try
141 {
142 Uri uri = Uri.parse(fileRef);
143 RDPFileHelper.importFrom(
144 getApplication().getContentResolver().openInputStream(uri), bookmark);
145 }
146 catch (IOException e)
147 {
148 Log.e(TAG, "Failed reading RDP file", e);
149 }
150 isNew = true;
151 }
152 }
153
154 if (bookmark == null)
155 {
156 bookmark = new BookmarkBase();
157 }
158
159 this.newBookmark = isNew;
160 this.settingsChanged = false;
161
162
163 prefs.edit().clear().apply();
164 bookmark.writeToSharedPreferences(prefs);
165
166
167 bookmarkLiveData.postValue(bookmark);
168 });
169 }