|
12 | 12 | import android.content.pm.PackageManager;
|
13 | 13 | import android.content.pm.ResolveInfo;
|
14 | 14 | import androidx.annotation.NonNull;
|
| 15 | +import androidx.annotation.Nullable; |
| 16 | + |
15 | 17 | import android.util.Log;
|
16 | 18 |
|
17 | 19 | import java.io.File;
|
@@ -191,10 +193,52 @@ public Void then(Task<Void> task) {
|
191 | 193 | }
|
192 | 194 | }
|
193 | 195 |
|
| 196 | + //region Server URL |
| 197 | + |
| 198 | + /** |
| 199 | + * Sets the server URL. This can be used to update the server URL after this client has been |
| 200 | + * initialized, without having to {@link Parse#destroy()} this client. |
| 201 | + * @param server The server URL to set. |
| 202 | + */ |
| 203 | + public static void setServer(@NonNull String server) { |
| 204 | + try { |
| 205 | + ParseRESTCommand.server = new URL(validateServerUrl(server)); |
| 206 | + } catch (MalformedURLException ex) { |
| 207 | + throw new RuntimeException(ex); |
| 208 | + } |
| 209 | + } |
| 210 | + |
| 211 | + /** |
| 212 | + * Returns the current server URL. |
| 213 | + */ |
| 214 | + public static @Nullable String getServer() { |
| 215 | + URL server = ParseRESTCommand.server; |
| 216 | + return server == null ? null : server.toString(); |
| 217 | + } |
| 218 | + |
| 219 | + /** |
| 220 | + * Validates the server URL. |
| 221 | + * @param server The server URL to validate. |
| 222 | + * @return The validated server URL. |
| 223 | + */ |
| 224 | + private static @Nullable String validateServerUrl(@Nullable String server) { |
| 225 | + |
| 226 | + // Add an extra trailing slash so that Parse REST commands include |
| 227 | + // the path as part of the server URL (i.e. http://api.myhost.com/parse) |
| 228 | + if (server != null && !server.endsWith("/")) { |
| 229 | + server = server + "/"; |
| 230 | + } |
| 231 | + |
| 232 | + return server; |
| 233 | + } |
| 234 | + |
| 235 | + //endregion |
| 236 | + |
194 | 237 | /**
|
195 | 238 | * Destroys this client and erases its local data store.
|
196 |
| - * Calling this after {@code Parse.initialize} allows you to re-initialize this client |
197 |
| - * with a new configuration. |
| 239 | + * Calling this after {@link Parse#initialize} allows you to re-initialize this client with a |
| 240 | + * new configuration. Calling this while server requests are in progress can cause undefined |
| 241 | + * behavior. |
198 | 242 | */
|
199 | 243 | public static void destroy() {
|
200 | 244 | ParseObject.unregisterParseSubclasses();
|
@@ -577,14 +621,7 @@ public Builder clientKey(String clientKey) {
|
577 | 621 | * @return The same builder, for easy chaining.
|
578 | 622 | */
|
579 | 623 | public Builder server(String server) {
|
580 |
| - |
581 |
| - // Add an extra trailing slash so that Parse REST commands include |
582 |
| - // the path as part of the server URL (i.e. http://api.myhost.com/parse) |
583 |
| - if (server != null && !server.endsWith("/")) { |
584 |
| - server = server + "/"; |
585 |
| - } |
586 |
| - |
587 |
| - this.server = server; |
| 624 | + this.server = validateServerUrl(server); |
588 | 625 | return this;
|
589 | 626 | }
|
590 | 627 |
|
|
0 commit comments