commit
d9cab51094
19 changed files with 472 additions and 147 deletions
10
OsmAnd/res/drawable/ic_action_alert_circle.xml
Normal file
10
OsmAnd/res/drawable/ic_action_alert_circle.xml
Normal file
|
@ -0,0 +1,10 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:pathData="M12,22C17.5228,22 22,17.5228 22,12C22,6.4771 17.5228,2 12,2C6.4771,2 2,6.4771 2,12C2,17.5228 6.4771,22 12,22ZM11,14V7H13V14H11ZM11,18V16H13V18H11Z"
|
||||
android:fillColor="#ffffff"
|
||||
android:fillType="evenOdd"/>
|
||||
</vector>
|
18
OsmAnd/res/drawable/ic_action_cellular.xml
Normal file
18
OsmAnd/res/drawable/ic_action_cellular.xml
Normal file
|
@ -0,0 +1,18 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:pathData="M20,12C20,15.4738 17.7859,18.4304 14.692,19.5358L14.9449,21.5593C19.0304,20.3022 22,16.4979 22,12C22,6.4771 17.5228,2 12,2C6.4771,2 2,6.4771 2,12C2,16.4979 4.9696,20.3022 9.0551,21.5593L9.308,19.5358C6.2141,18.4304 4,15.4738 4,12C4,7.5817 7.5817,4 12,4C16.4183,4 20,7.5817 20,12Z"
|
||||
android:fillColor="#ffffff"/>
|
||||
<path
|
||||
android:pathData="M18,12C18,14.4466 16.5357,16.5511 14.4356,17.485L14.1701,15.3607C15.2713,14.6482 16,13.4092 16,12C16,9.7909 14.2091,8 12,8C9.7909,8 8,9.7909 8,12C8,13.4092 8.7287,14.6482 9.8299,15.3607L9.5644,17.485C7.4643,16.5511 6,14.4466 6,12C6,8.6863 8.6863,6 12,6C15.3137,6 18,8.6863 18,12Z"
|
||||
android:fillColor="#ffffff"/>
|
||||
<path
|
||||
android:pathData="M14,12C14,13.1046 13.1046,14 12,14C10.8954,14 10,13.1046 10,12C10,10.8954 10.8954,10 12,10C13.1046,10 14,10.8954 14,12Z"
|
||||
android:fillColor="#ffffff"/>
|
||||
<path
|
||||
android:pathData="M11,15V22H13V15H11Z"
|
||||
android:fillColor="#ffffff"/>
|
||||
</vector>
|
15
OsmAnd/res/drawable/ic_action_cellular_disable.xml
Normal file
15
OsmAnd/res/drawable/ic_action_cellular_disable.xml
Normal file
|
@ -0,0 +1,15 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:pathData="M22.0001,12C22.0001,13.9623 21.4349,15.7926 20.4583,17.337L18.9991,15.8777C19.6369,14.7291 20.0001,13.407 20.0001,12C20.0001,7.5817 16.4183,4 12.0001,4C10.5931,4 9.271,4.3632 8.1223,5.0009L6.6631,3.5417C8.2075,2.5652 10.0378,2 12.0001,2C17.5229,2 22.0001,6.4771 22.0001,12Z"
|
||||
android:fillColor="#ffffff"/>
|
||||
<path
|
||||
android:pathData="M18.0001,12C18.0001,12.8478 17.8242,13.6545 17.507,14.3857L15.9203,12.7989C15.9726,12.5407 16.0001,12.2736 16.0001,12C16.0001,9.7909 14.2092,8 12.0001,8C11.7265,8 11.4593,8.0275 11.2012,8.0798L9.6144,6.493C10.3456,6.1758 11.1523,6 12.0001,6C15.3138,6 18.0001,8.6863 18.0001,12Z"
|
||||
android:fillColor="#ffffff"/>
|
||||
<path
|
||||
android:pathData="M14.3449,16.759L14.4357,17.485C14.5806,17.4206 14.7225,17.3506 14.8611,17.2752L16.3203,18.7344C15.8138,19.0599 15.2682,19.33 14.692,19.5358L14.945,21.5593C15.9623,21.2463 16.9105,20.7753 17.7609,20.1749L21.293,23.7071L22.7072,22.2928L2.7072,2.2929L1.293,3.7071L3.8251,6.2392C2.6754,7.8677 2.0001,9.855 2.0001,12C2.0001,16.4979 4.9696,20.3022 9.0552,21.5593L9.3081,19.5358C6.2141,18.4304 4.0001,15.4738 4.0001,12C4.0001,10.4087 4.4647,8.9258 5.2657,7.6798L6.7248,9.1389C6.2626,9.9894 6.0001,10.964 6.0001,12C6.0001,14.4466 7.4644,16.5511 9.5644,17.485L9.83,15.3607C8.7288,14.6482 8.0001,13.4092 8.0001,12C8.0001,11.5256 8.0826,11.0705 8.2342,10.6483L10.0555,12.4696C10.2305,13.197 10.8031,13.7695 11.5305,13.9446L12.5859,15H11.0001V22H13.0001V15.4142L14.3449,16.759Z"
|
||||
android:fillColor="#ffffff"/>
|
||||
</vector>
|
9
OsmAnd/res/drawable/ic_action_cloud.xml
Normal file
9
OsmAnd/res/drawable/ic_action_cloud.xml
Normal file
|
@ -0,0 +1,9 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:pathData="M6,18V17.9725C3.75,17.7238 2,15.8163 2,13.5C2,11.0147 4.0147,9 6.5,9C6.5998,9 6.6989,9.0033 6.7971,9.0097C7.8332,7.2109 9.7752,6 12,6C15.3137,6 18,8.6863 18,12C18,12.0574 17.9992,12.1146 17.9976,12.1716C18.3111,12.0605 18.6485,12 19,12C20.6569,12 22,13.3431 22,15C22,16.6569 20.6569,18 19,18H6Z"
|
||||
android:fillColor="#ffffff"/>
|
||||
</vector>
|
10
OsmAnd/res/drawable/ic_action_cloud_alert.xml
Normal file
10
OsmAnd/res/drawable/ic_action_cloud_alert.xml
Normal file
|
@ -0,0 +1,10 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:pathData="M6,17.9725V18H19C20.6569,18 22,16.6569 22,15C22,13.3431 20.6569,12 19,12C18.6485,12 18.3111,12.0605 17.9976,12.1716C17.9992,12.1146 18,12.0574 18,12C18,8.6863 15.3137,6 12,6C9.7752,6 7.8332,7.2109 6.7971,9.0097C6.6989,9.0033 6.5998,9 6.5,9C4.0147,9 2,11.0147 2,13.5C2,15.8163 3.75,17.7238 6,17.9725ZM11,13V8H13V13H11ZM11,17V15H13V17H11Z"
|
||||
android:fillColor="#ffffff"
|
||||
android:fillType="evenOdd"/>
|
||||
</vector>
|
9
OsmAnd/res/drawable/ic_action_cloud_upload.xml
Normal file
9
OsmAnd/res/drawable/ic_action_cloud_upload.xml
Normal file
|
@ -0,0 +1,9 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:pathData="M14,18V15H16.5L12.5,10L8.5,15H11V18H6V17.9725C3.75,17.7238 2,15.8163 2,13.5C2,11.0147 4.0147,9 6.5,9C6.5998,9 6.6989,9.0033 6.7971,9.0097C7.8332,7.2109 9.7752,6 12,6C15.3137,6 18,8.6863 18,12C18,12.0574 17.9992,12.1146 17.9976,12.1716C18.3111,12.0605 18.6485,12 19,12C20.6569,12 22,13.3431 22,15C22,16.6569 20.6569,18 19,18H14Z"
|
||||
android:fillColor="#ffffff"/>
|
||||
</vector>
|
12
OsmAnd/res/drawable/ic_action_cloud_upload_colored.xml
Normal file
12
OsmAnd/res/drawable/ic_action_cloud_upload_colored.xml
Normal file
|
@ -0,0 +1,12 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:pathData="M6,18V17.9725C3.75,17.7238 2,15.8163 2,13.5C2,11.0147 4.0147,9 6.5,9C6.5998,9 6.6989,9.0033 6.7971,9.0097C7.8332,7.2109 9.7752,6 12,6C15.3137,6 18,8.6863 18,12C18,12.0574 17.9992,12.1146 17.9976,12.1716C18.3111,12.0605 18.6485,12 19,12C20.6569,12 22,13.3431 22,15C22,16.6569 20.6569,18 19,18H6Z"
|
||||
android:fillColor="#6C19FF"/>
|
||||
<path
|
||||
android:pathData="M11,15H8.5L12.5,9.5L16.5,15H14V20H11V15Z"
|
||||
android:fillColor="#FFC30D"/>
|
||||
</vector>
|
15
OsmAnd/res/drawable/ic_action_read_from_file.xml
Normal file
15
OsmAnd/res/drawable/ic_action_read_from_file.xml
Normal file
|
@ -0,0 +1,15 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:pathData="M14,2L20,8H16C14.8954,8 14,7.1046 14,6V2Z"
|
||||
android:strokeAlpha="0.5"
|
||||
android:fillColor="#ffffff"
|
||||
android:fillAlpha="0.5"/>
|
||||
<path
|
||||
android:pathData="M4,4C4,2.8954 4.8954,2 6,2H14V6C14,7.1046 14.8954,8 16,8H20V20C20,21.1046 19.1046,22 18,22H6C4.8954,22 4,21.1046 4,20V4ZM11,18H13V13H15L12,9L9,13H11V18Z"
|
||||
android:fillColor="#ffffff"
|
||||
android:fillType="evenOdd"/>
|
||||
</vector>
|
37
OsmAnd/res/drawable/ic_action_restore.xml
Normal file
37
OsmAnd/res/drawable/ic_action_restore.xml
Normal file
|
@ -0,0 +1,37 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:aapt="http://schemas.android.com/aapt"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:pathData="M12,5C12.5523,5 13,4.5523 13,4H17V8.0549C16.6717,8.0186 16.338,8 16,8C11.0294,8 7,12.0294 7,17V4H11C11,4.5523 11.4477,5 12,5Z"
|
||||
android:strokeAlpha="0.3"
|
||||
android:fillColor="#ffffff"
|
||||
android:fillAlpha="0.3"/>
|
||||
<path
|
||||
android:pathData="M7,17C7,18.0519 7.1805,19.0617 7.5121,20H7V17Z"
|
||||
android:strokeAlpha="0.3"
|
||||
android:fillColor="#ffffff"
|
||||
android:fillAlpha="0.3"/>
|
||||
<path
|
||||
android:pathData="M17,2.01L7,2C5.9,2 5,2.9 5,4V20C5,21.1 5.9,22 7,22H8.5155C8.1025,21.383 7.7638,20.7121 7.5121,20H7V4H11C11,4.5523 11.4477,5 12,5C12.5523,5 13,4.5523 13,4H17V8.0549C17.6935,8.1316 18.3632,8.287 19,8.5121V4C19,2.9 18.1,2.01 17,2.01Z"
|
||||
android:strokeAlpha="0.7"
|
||||
android:fillColor="#ffffff"
|
||||
android:fillAlpha="0.7"/>
|
||||
<path
|
||||
android:pathData="M16,21C18.2091,21 20,19.2091 20,17C20,14.7909 18.2091,13 16,13C13.7909,13 12,14.7909 12,17H14L11,20L8,17H10C10,13.6863 12.6863,11 16,11C19.3137,11 22,13.6863 22,17C22,20.3137 19.3137,23 16,23C14.598,23 13.3082,22.5191 12.2868,21.7132L13.7159,20.2841C14.3635,20.7354 15.1508,21 16,21Z"
|
||||
android:fillType="evenOdd">
|
||||
<aapt:attr name="android:fillColor">
|
||||
<gradient
|
||||
android:gradientRadius="6.36396"
|
||||
android:centerX="16"
|
||||
android:centerY="17"
|
||||
android:type="radial">
|
||||
<item android:offset="0" android:color="#FFFFFFFF"/>
|
||||
<item android:offset="0.8125" android:color="#FFFFFFFF"/>
|
||||
<item android:offset="1" android:color="#00FFFFFF"/>
|
||||
</gradient>
|
||||
</aapt:attr>
|
||||
</path>
|
||||
</vector>
|
15
OsmAnd/res/drawable/ic_action_user_folder.xml
Normal file
15
OsmAnd/res/drawable/ic_action_user_folder.xml
Normal file
|
@ -0,0 +1,15 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:pathData="M6,3C4.8954,3 4,3.8954 4,5V7H20C20,5.8954 19.1046,5 18,5H13L11.4,3H6Z"
|
||||
android:strokeAlpha="0.5"
|
||||
android:fillColor="#ffffff"
|
||||
android:fillAlpha="0.5"/>
|
||||
<path
|
||||
android:pathData="M2,7C2,5.8954 2.8954,5 4,5H10L12,7H20C21.1046,7 22,7.8954 22,9V19C22,20.1046 21.1046,21 20,21H4C2.8954,21 2,20.1046 2,19V7ZM17,12C17,13.1046 16.1046,14 15,14C13.8954,14 13,13.1046 13,12C13,10.8954 13.8954,10 15,10C16.1046,10 17,10.8954 17,12ZM10,17.5V19H20V17.5C20,15.5 17,15 15,15C13,15 10,15.5 10,17.5Z"
|
||||
android:fillColor="#ffffff"
|
||||
android:fillType="evenOdd"/>
|
||||
</vector>
|
|
@ -48,13 +48,14 @@ public class AndroidNetworkUtils {
|
|||
private static final Log LOG = PlatformUtil.getLog(AndroidNetworkUtils.class);
|
||||
|
||||
public interface OnRequestResultListener {
|
||||
void onResult(String result);
|
||||
void onResult(@Nullable String result, @Nullable String error);
|
||||
}
|
||||
|
||||
public interface OnFilesUploadCallback {
|
||||
@Nullable
|
||||
Map<String, String> getAdditionalParams(@NonNull File file);
|
||||
void onFileUploadProgress(@NonNull File file, int percent);
|
||||
void onFileUploadDone(@NonNull File file);
|
||||
void onFilesUploadDone(@NonNull Map<File, String> errors);
|
||||
}
|
||||
|
||||
|
@ -64,16 +65,26 @@ public class AndroidNetworkUtils {
|
|||
void onFileDownloadProgress(@NonNull File file, int percent);
|
||||
@WorkerThread
|
||||
void onFileDownloadedAsync(@NonNull File file);
|
||||
|
||||
void onFileDownloadDone(@NonNull File file);
|
||||
void onFilesDownloadDone(@NonNull Map<File, String> errors);
|
||||
}
|
||||
|
||||
public static class RequestResponse {
|
||||
private Request request;
|
||||
private String response;
|
||||
private final Request request;
|
||||
private final String response;
|
||||
private final String error;
|
||||
|
||||
RequestResponse(@NonNull Request request, @Nullable String response) {
|
||||
this.request = request;
|
||||
this.response = response;
|
||||
this.error = null;
|
||||
}
|
||||
|
||||
RequestResponse(@NonNull Request request, @Nullable String response, @Nullable String error) {
|
||||
this.request = request;
|
||||
this.response = response;
|
||||
this.error = error;
|
||||
}
|
||||
|
||||
public Request getRequest() {
|
||||
|
@ -83,6 +94,10 @@ public class AndroidNetworkUtils {
|
|||
public String getResponse() {
|
||||
return response;
|
||||
}
|
||||
|
||||
public String getError() {
|
||||
return error;
|
||||
}
|
||||
}
|
||||
|
||||
public interface OnSendRequestsListener {
|
||||
|
@ -109,11 +124,18 @@ public class AndroidNetworkUtils {
|
|||
for (Request request : requests) {
|
||||
RequestResponse requestResponse;
|
||||
try {
|
||||
String response = sendRequest(ctx, request.getUrl(), request.getParameters(),
|
||||
request.getUserOperation(), request.isToastAllowed(), request.isPost());
|
||||
requestResponse = new RequestResponse(request, response);
|
||||
final String[] response = {null, null};
|
||||
sendRequest(ctx, request.getUrl(), request.getParameters(),
|
||||
request.getUserOperation(), request.isToastAllowed(), request.isPost(), new OnRequestResultListener() {
|
||||
@Override
|
||||
public void onResult(@Nullable String result, @Nullable String error) {
|
||||
response[0] = result;
|
||||
response[1] = error;
|
||||
}
|
||||
});
|
||||
requestResponse = new RequestResponse(request, response[0], response[1]);
|
||||
} catch (Exception e) {
|
||||
requestResponse = new RequestResponse(request, null);
|
||||
requestResponse = new RequestResponse(request, null, "Unexpected error");
|
||||
}
|
||||
responses.add(requestResponse);
|
||||
publishProgress(requestResponse);
|
||||
|
@ -157,21 +179,29 @@ public class AndroidNetworkUtils {
|
|||
final boolean post,
|
||||
final OnRequestResultListener listener,
|
||||
final Executor executor) {
|
||||
new AsyncTask<Void, Void, String>() {
|
||||
new AsyncTask<Void, Void, String[]>() {
|
||||
|
||||
@Override
|
||||
protected String doInBackground(Void... params) {
|
||||
protected String[] doInBackground(Void... params) {
|
||||
final String[] res = {null, null};
|
||||
try {
|
||||
return sendRequest(ctx, url, parameters, userOperation, toastAllowed, post);
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
sendRequest(ctx, url, parameters, userOperation, toastAllowed, post, new OnRequestResultListener() {
|
||||
@Override
|
||||
public void onResult(@Nullable String result, @Nullable String error) {
|
||||
res[0] = result;
|
||||
res[1] = error;
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
// ignore
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(String response) {
|
||||
protected void onPostExecute(String[] response) {
|
||||
if (listener != null) {
|
||||
listener.onResult(response);
|
||||
listener.onResult(response[0], response[1]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -255,7 +285,7 @@ public class AndroidNetworkUtils {
|
|||
} catch (Exception e) {
|
||||
errors.put(file, e.getMessage());
|
||||
}
|
||||
publishProgress(file, Integer.MAX_VALUE);
|
||||
publishProgress(file, -1);
|
||||
}
|
||||
return errors;
|
||||
}
|
||||
|
@ -263,7 +293,13 @@ public class AndroidNetworkUtils {
|
|||
@Override
|
||||
protected void onProgressUpdate(Object... objects) {
|
||||
if (callback != null) {
|
||||
callback.onFileDownloadProgress((File) objects[0], (Integer) objects[1]);
|
||||
File file = (File) objects[0];
|
||||
Integer progress = (Integer) objects[1];
|
||||
if (progress >= 0) {
|
||||
callback.onFileDownloadProgress(file, progress);
|
||||
} else {
|
||||
callback.onFileDownloadDone(file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -280,9 +316,17 @@ public class AndroidNetworkUtils {
|
|||
public static String sendRequest(@Nullable OsmandApplication ctx, @NonNull String url,
|
||||
@Nullable Map<String, String> parameters,
|
||||
@Nullable String userOperation, boolean toastAllowed, boolean post) {
|
||||
return sendRequest(ctx, url, parameters, userOperation, toastAllowed, post, null);
|
||||
}
|
||||
|
||||
public static String sendRequest(@Nullable OsmandApplication ctx, @NonNull String url,
|
||||
@Nullable Map<String, String> parameters,
|
||||
@Nullable String userOperation, boolean toastAllowed, boolean post,
|
||||
@Nullable OnRequestResultListener listener) {
|
||||
String result = null;
|
||||
String error = null;
|
||||
HttpURLConnection connection = null;
|
||||
try {
|
||||
|
||||
String params = null;
|
||||
if (parameters != null && parameters.size() > 0) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
@ -312,68 +356,66 @@ public class AndroidNetworkUtils {
|
|||
output.write(params.getBytes("UTF-8"));
|
||||
output.flush();
|
||||
output.close();
|
||||
|
||||
} else {
|
||||
|
||||
connection.setRequestMethod("GET");
|
||||
connection.connect();
|
||||
}
|
||||
|
||||
if (connection.getResponseCode() != HttpURLConnection.HTTP_OK) {
|
||||
if (ctx != null) {
|
||||
error = (!Algorithms.isEmpty(userOperation) ? userOperation + " " : "")
|
||||
+ ctx.getString(R.string.failed_op) + ": " + connection.getResponseMessage();
|
||||
} else {
|
||||
error = (!Algorithms.isEmpty(userOperation) ? userOperation + " " : "")
|
||||
+ "failed: " + connection.getResponseMessage();
|
||||
}
|
||||
if (toastAllowed && ctx != null) {
|
||||
String msg = (!Algorithms.isEmpty(userOperation) ? userOperation + " " : "")
|
||||
+ ctx.getString(R.string.failed_op) + ": "
|
||||
+ connection.getResponseMessage();
|
||||
showToast(ctx, msg);
|
||||
showToast(ctx, error);
|
||||
}
|
||||
InputStream errorStream = connection.getErrorStream();
|
||||
if (errorStream != null) {
|
||||
error = streamToString(errorStream);
|
||||
}
|
||||
} else {
|
||||
StringBuilder responseBody = new StringBuilder();
|
||||
responseBody.setLength(0);
|
||||
InputStream i = connection.getInputStream();
|
||||
if (i != null) {
|
||||
BufferedReader in = new BufferedReader(new InputStreamReader(i, "UTF-8"), 256);
|
||||
String s;
|
||||
boolean f = true;
|
||||
while ((s = in.readLine()) != null) {
|
||||
if (!f) {
|
||||
responseBody.append("\n");
|
||||
} else {
|
||||
f = false;
|
||||
result = streamToString(connection.getInputStream());
|
||||
}
|
||||
responseBody.append(s);
|
||||
}
|
||||
try {
|
||||
in.close();
|
||||
i.close();
|
||||
} catch (Exception e) {
|
||||
// ignore exception
|
||||
}
|
||||
}
|
||||
return responseBody.toString();
|
||||
}
|
||||
|
||||
} catch (NullPointerException e) {
|
||||
// that's tricky case why NPE is thrown to fix that problem httpClient could be used
|
||||
if (ctx != null) {
|
||||
error = ctx.getString(R.string.auth_failed);
|
||||
} else {
|
||||
error = "Authorization failed";
|
||||
}
|
||||
if (toastAllowed && ctx != null) {
|
||||
String msg = ctx.getString(R.string.auth_failed);
|
||||
showToast(ctx, msg);
|
||||
showToast(ctx, error);
|
||||
}
|
||||
} catch (MalformedURLException e) {
|
||||
if (ctx != null) {
|
||||
error = MessageFormat.format(ctx.getResources().getString(R.string.shared_string_action_template)
|
||||
+ ": " + ctx.getResources().getString(R.string.shared_string_unexpected_error), userOperation);
|
||||
} else {
|
||||
error = "Action " + userOperation + ": Unexpected error";
|
||||
}
|
||||
if (toastAllowed && ctx != null) {
|
||||
showToast(ctx, MessageFormat.format(ctx.getResources().getString(R.string.shared_string_action_template)
|
||||
+ ": " + ctx.getResources().getString(R.string.shared_string_unexpected_error), userOperation));
|
||||
showToast(ctx, error);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
if (ctx != null) {
|
||||
error = MessageFormat.format(ctx.getResources().getString(R.string.shared_string_action_template)
|
||||
+ ": " + ctx.getResources().getString(R.string.shared_string_io_error), userOperation);
|
||||
} else {
|
||||
error = "Action " + userOperation + ": I/O error";
|
||||
}
|
||||
if (toastAllowed && ctx != null) {
|
||||
showToast(ctx, MessageFormat.format(ctx.getResources().getString(R.string.shared_string_action_template)
|
||||
+ ": " + ctx.getResources().getString(R.string.shared_string_io_error), userOperation));
|
||||
showToast(ctx, error);
|
||||
}
|
||||
} finally {
|
||||
if (connection != null) {
|
||||
connection.disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
if (listener != null) {
|
||||
listener.onResult(result, error);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -401,12 +443,16 @@ public class AndroidNetworkUtils {
|
|||
public static String downloadFile(@NonNull String url, @NonNull File fileToSave, boolean gzip, @Nullable IProgress progress) {
|
||||
String error = null;
|
||||
try {
|
||||
URLConnection connection = NetworkUtils.getHttpURLConnection(url);
|
||||
HttpURLConnection connection = NetworkUtils.getHttpURLConnection(url);
|
||||
connection.setConnectTimeout(CONNECTION_TIMEOUT);
|
||||
connection.setReadTimeout(CONNECTION_TIMEOUT);
|
||||
if (gzip) {
|
||||
connection.setRequestProperty("Accept-Encoding", "deflate, gzip");
|
||||
}
|
||||
connection.connect();
|
||||
if (connection.getResponseCode() != HttpURLConnection.HTTP_OK) {
|
||||
return streamToString(connection.getErrorStream());
|
||||
} else {
|
||||
InputStream inputStream = gzip
|
||||
? new GZIPInputStream(connection.getInputStream())
|
||||
: new BufferedInputStream(connection.getInputStream(), 8 * 1024);
|
||||
|
@ -420,6 +466,7 @@ public class AndroidNetworkUtils {
|
|||
Algorithms.closeStream(inputStream);
|
||||
Algorithms.closeStream(stream);
|
||||
}
|
||||
}
|
||||
} catch (UnknownHostException e) {
|
||||
error = e.getMessage();
|
||||
LOG.error("UnknownHostException, cannot download file " + url + " " + error);
|
||||
|
@ -430,6 +477,30 @@ public class AndroidNetworkUtils {
|
|||
return error;
|
||||
}
|
||||
|
||||
private static String streamToString(InputStream inputStream) throws IOException {
|
||||
StringBuilder result = new StringBuilder();
|
||||
if (inputStream != null) {
|
||||
BufferedReader in = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"), 256);
|
||||
String buffer;
|
||||
boolean f = true;
|
||||
while ((buffer = in.readLine()) != null) {
|
||||
if (!f) {
|
||||
result.append("\n");
|
||||
} else {
|
||||
f = false;
|
||||
}
|
||||
result.append(buffer);
|
||||
}
|
||||
try {
|
||||
in.close();
|
||||
inputStream.close();
|
||||
} catch (Exception e) {
|
||||
// ignore exception
|
||||
}
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
private static final String BOUNDARY = "CowMooCowMooCowCowCow";
|
||||
|
||||
public static String uploadFile(@NonNull String urlText, @NonNull File file, boolean gzip,
|
||||
|
@ -444,7 +515,6 @@ public class AndroidNetworkUtils {
|
|||
@NonNull Map<String, String> additionalParams,
|
||||
@Nullable Map<String, String> headers,
|
||||
@Nullable IProgress progress) {
|
||||
URL url;
|
||||
try {
|
||||
boolean firstPrm = !urlText.contains("?");
|
||||
StringBuilder sb = new StringBuilder(urlText);
|
||||
|
@ -455,7 +525,7 @@ public class AndroidNetworkUtils {
|
|||
urlText = sb.toString();
|
||||
|
||||
LOG.info("Start uploading file to " + urlText + " " + fileName);
|
||||
url = new URL(urlText);
|
||||
URL url = new URL(urlText);
|
||||
|
||||
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
|
||||
conn.setDoInput(true);
|
||||
|
@ -496,6 +566,10 @@ public class AndroidNetworkUtils {
|
|||
LOG.info("Finish uploading file " + fileName);
|
||||
LOG.info("Response code and message : " + conn.getResponseCode() + " " + conn.getResponseMessage());
|
||||
if (conn.getResponseCode() != 200) {
|
||||
InputStream errorStream = conn.getErrorStream();
|
||||
if (errorStream != null) {
|
||||
return streamToString(errorStream);
|
||||
}
|
||||
return conn.getResponseMessage();
|
||||
}
|
||||
InputStream is = conn.getInputStream();
|
||||
|
@ -575,7 +649,7 @@ public class AndroidNetworkUtils {
|
|||
} catch (Exception e) {
|
||||
errors.put(file, e.getMessage());
|
||||
}
|
||||
publishProgress(file, Integer.MAX_VALUE);
|
||||
publishProgress(file, -1);
|
||||
}
|
||||
return errors;
|
||||
}
|
||||
|
@ -583,7 +657,13 @@ public class AndroidNetworkUtils {
|
|||
@Override
|
||||
protected void onProgressUpdate(Object... objects) {
|
||||
if (callback != null) {
|
||||
callback.onFileUploadProgress((File) objects[0], (Integer) objects[1]);
|
||||
File file = (File) objects[0];
|
||||
Integer progress = (Integer) objects[1];
|
||||
if (progress >= 0) {
|
||||
callback.onFileUploadProgress(file, progress);
|
||||
} else {
|
||||
callback.onFileUploadDone(file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -602,11 +682,11 @@ public class AndroidNetworkUtils {
|
|||
}
|
||||
|
||||
public static class Request {
|
||||
private String url;
|
||||
private Map<String, String> parameters;
|
||||
private String userOperation;
|
||||
private boolean toastAllowed;
|
||||
private boolean post;
|
||||
private final String url;
|
||||
private final Map<String, String> parameters;
|
||||
private final String userOperation;
|
||||
private final boolean toastAllowed;
|
||||
private final boolean post;
|
||||
|
||||
public Request(String url, Map<String, String> parameters, String userOperation, boolean toastAllowed, boolean post) {
|
||||
this.url = url;
|
||||
|
|
|
@ -225,7 +225,7 @@ public class CustomRegion extends WorldRegion {
|
|||
&& app.getSettings().isInternetConnectionAvailable()) {
|
||||
OnRequestResultListener resultListener = new OnRequestResultListener() {
|
||||
@Override
|
||||
public void onResult(String result) {
|
||||
public void onResult(@Nullable String result, @Nullable String error) {
|
||||
if (!Algorithms.isEmpty(result)) {
|
||||
if ("json".equalsIgnoreCase(dynamicDownloadItems.format)) {
|
||||
dynamicItemsJson = mapJsonItems(result);
|
||||
|
|
|
@ -37,6 +37,7 @@ import java.util.ArrayList;
|
|||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
@ -65,10 +66,6 @@ public class BackupHelper {
|
|||
public final static int STATUS_EMPTY_RESPONSE_ERROR = 2;
|
||||
public final static int STATUS_SERVER_ERROR = 3;
|
||||
|
||||
public interface OnResultListener {
|
||||
void onResult(int status, @Nullable String message, @Nullable JSONObject json);
|
||||
}
|
||||
|
||||
public interface OnRegisterUserListener {
|
||||
void onRegisterUser(int status, @Nullable String message);
|
||||
}
|
||||
|
@ -83,7 +80,6 @@ public class BackupHelper {
|
|||
|
||||
public interface OnCollectLocalFilesListener {
|
||||
void onFileCollected(@NonNull GpxFileInfo fileInfo);
|
||||
|
||||
void onFilesCollected(@NonNull List<GpxFileInfo> fileInfos);
|
||||
}
|
||||
|
||||
|
@ -93,20 +89,21 @@ public class BackupHelper {
|
|||
|
||||
public interface OnUploadFilesListener {
|
||||
void onFileUploadProgress(@NonNull File file, int progress);
|
||||
|
||||
void onFileUploadDone(@NonNull File file);
|
||||
void onFilesUploadDone(@NonNull Map<File, String> errors);
|
||||
}
|
||||
|
||||
public interface OnDeleteFilesListener {
|
||||
void onFileDeleteProgress(@NonNull UserFile file);
|
||||
|
||||
void onFilesDeleteDone(@NonNull Map<UserFile, String> errors);
|
||||
}
|
||||
|
||||
public interface OnDownloadFileListener {
|
||||
void onFileDownloadProgress(@NonNull UserFile userFile, int progress);
|
||||
|
||||
@WorkerThread
|
||||
void onFileDownloadedAsync(@NonNull File file);
|
||||
void onFileDownloaded(@NonNull File file);
|
||||
void onFilesDownloadDone(@NonNull Map<File, String> errors);
|
||||
}
|
||||
|
||||
|
@ -174,20 +171,22 @@ public class BackupHelper {
|
|||
params.put("orderid", orderId);
|
||||
}
|
||||
params.put("deviceid", app.getUserAndroidId());
|
||||
AndroidNetworkUtils.sendRequestAsync(app, USER_REGISTER_URL, params, "Register user", true, true, new OnRequestResultListener() {
|
||||
AndroidNetworkUtils.sendRequestAsync(app, USER_REGISTER_URL, params, "Register user", false, true, new OnRequestResultListener() {
|
||||
@Override
|
||||
public void onResult(String resultJson) {
|
||||
public void onResult(@Nullable String resultJson, @Nullable String error) {
|
||||
int status;
|
||||
String message;
|
||||
if (!Algorithms.isEmpty(resultJson)) {
|
||||
if (!Algorithms.isEmpty(error)) {
|
||||
message = "User registration error: " + parseServerError(error);
|
||||
status = STATUS_SERVER_ERROR;
|
||||
} else if (!Algorithms.isEmpty(resultJson)) {
|
||||
try {
|
||||
JSONObject result = new JSONObject(resultJson);
|
||||
String statusStr = result.getString("status");
|
||||
if (statusStr.equals("ok")) {
|
||||
if (result.has("status") && "ok".equals(result.getString("status"))) {
|
||||
message = "You have been registered successfully. Please check for email with activation code.";
|
||||
status = STATUS_SUCCESS;
|
||||
} else {
|
||||
message = "User registration error: " + statusStr;
|
||||
message = "User registration error: unknown";
|
||||
status = STATUS_SERVER_ERROR;
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
|
@ -217,12 +216,15 @@ public class BackupHelper {
|
|||
params.put("deviceid", androidId);
|
||||
}
|
||||
params.put("token", token);
|
||||
AndroidNetworkUtils.sendRequestAsync(app, DEVICE_REGISTER_URL, params, "Register device", true, true, new OnRequestResultListener() {
|
||||
AndroidNetworkUtils.sendRequestAsync(app, DEVICE_REGISTER_URL, params, "Register device", false, true, new OnRequestResultListener() {
|
||||
@Override
|
||||
public void onResult(String resultJson) {
|
||||
public void onResult(@Nullable String resultJson, @Nullable String error) {
|
||||
int status;
|
||||
String message;
|
||||
if (!Algorithms.isEmpty(resultJson)) {
|
||||
if (!Algorithms.isEmpty(error)) {
|
||||
message = "Device registration error: " + parseServerError(error);
|
||||
status = STATUS_SERVER_ERROR;
|
||||
} else if (!Algorithms.isEmpty(resultJson)) {
|
||||
try {
|
||||
JSONObject result = new JSONObject(resultJson);
|
||||
settings.BACKUP_DEVICE_ID.set(result.getString("id"));
|
||||
|
@ -230,8 +232,9 @@ public class BackupHelper {
|
|||
settings.BACKUP_NATIVE_DEVICE_ID.set(result.getString("deviceid"));
|
||||
settings.BACKUP_ACCESS_TOKEN.set(result.getString("accesstoken"));
|
||||
settings.BACKUP_ACCESS_TOKEN_UPDATE_TIME.set(result.getString("udpatetime"));
|
||||
status = STATUS_SUCCESS;
|
||||
|
||||
message = "Device have been registered successfully";
|
||||
status = STATUS_SUCCESS;
|
||||
} catch (JSONException e) {
|
||||
message = "Device registration error: json parsing";
|
||||
status = STATUS_PARSE_JSON_ERROR;
|
||||
|
@ -271,14 +274,6 @@ public class BackupHelper {
|
|||
additionaParams.put("name", gpxFileInfo.getFileName(true));
|
||||
additionaParams.put("type", Algorithms.getFileExtension(file));
|
||||
gpxFileInfo.uploadTime = System.currentTimeMillis();
|
||||
if (file.equals(favoritesFile)) {
|
||||
favouritesHelper.setLastUploadedTime(gpxFileInfo.uploadTime);
|
||||
} else {
|
||||
GpxDataItem gpxItem = gpxHelper.getItem(file);
|
||||
if (gpxItem != null) {
|
||||
gpxHelper.updateLastUploadedTime(gpxItem, gpxFileInfo.uploadTime);
|
||||
}
|
||||
}
|
||||
additionaParams.put("clienttime", String.valueOf(gpxFileInfo.uploadTime));
|
||||
}
|
||||
return additionaParams;
|
||||
|
@ -291,13 +286,31 @@ public class BackupHelper {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFileUploadDone(@NonNull File file) {
|
||||
if (listener != null) {
|
||||
GpxFileInfo gpxFileInfo = gpxInfos.get(file);
|
||||
if (gpxFileInfo != null) {
|
||||
if (file.equals(favoritesFile)) {
|
||||
favouritesHelper.setLastUploadedTime(gpxFileInfo.uploadTime);
|
||||
} else {
|
||||
GpxDataItem gpxItem = gpxHelper.getItem(file);
|
||||
if (gpxItem != null) {
|
||||
gpxHelper.updateLastUploadedTime(gpxItem, gpxFileInfo.uploadTime);
|
||||
}
|
||||
}
|
||||
}
|
||||
listener.onFileUploadDone(file);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFilesUploadDone(@NonNull Map<File, String> errors) {
|
||||
if (errors.isEmpty()) {
|
||||
settings.BACKUP_LAST_UPLOADED_TIME.set(System.currentTimeMillis() + 1);
|
||||
}
|
||||
if (listener != null) {
|
||||
listener.onFilesUploadDone(errors);
|
||||
listener.onFilesUploadDone(resolveServerErrors(errors));
|
||||
}
|
||||
}
|
||||
}, EXECUTOR);
|
||||
|
@ -338,17 +351,29 @@ public class BackupHelper {
|
|||
for (RequestResponse response : results) {
|
||||
UserFile userFile = filesMap.get(response.getRequest());
|
||||
if (userFile != null) {
|
||||
String responseStr = response.getResponse();
|
||||
boolean success;
|
||||
String message = null;
|
||||
String errorStr = response.getError();
|
||||
if (!Algorithms.isEmpty(errorStr)) {
|
||||
message = parseServerError(errorStr);
|
||||
success = false;
|
||||
} else {
|
||||
String responseStr = response.getResponse();
|
||||
try {
|
||||
JSONObject json = new JSONObject(responseStr);
|
||||
String status = json.getString("status");
|
||||
success = status.equalsIgnoreCase("ok");
|
||||
} catch (JSONException e) {
|
||||
JSONObject result = new JSONObject(responseStr);
|
||||
if (result.has("status") && "ok".equals(result.getString("status"))) {
|
||||
success = true;
|
||||
} else {
|
||||
message = "Unknown error";
|
||||
success = false;
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
message = "Json parsing error";
|
||||
success = false;
|
||||
}
|
||||
}
|
||||
if (!success) {
|
||||
errors.put(userFile, responseStr);
|
||||
errors.put(userFile, message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -364,13 +389,16 @@ public class BackupHelper {
|
|||
Map<String, String> params = new HashMap<>();
|
||||
params.put("deviceid", getDeviceId());
|
||||
params.put("accessToken", getAccessToken());
|
||||
AndroidNetworkUtils.sendRequestAsync(app, LIST_FILES_URL, params, "Download file list", true, false, new OnRequestResultListener() {
|
||||
AndroidNetworkUtils.sendRequestAsync(app, LIST_FILES_URL, params, "Download file list", false, false, new OnRequestResultListener() {
|
||||
@Override
|
||||
public void onResult(String resultJson) {
|
||||
public void onResult(@Nullable String resultJson, @Nullable String error) {
|
||||
int status;
|
||||
String message;
|
||||
List<UserFile> userFiles = new ArrayList<>();
|
||||
if (!Algorithms.isEmpty(resultJson)) {
|
||||
if (!Algorithms.isEmpty(error)) {
|
||||
status = STATUS_SERVER_ERROR;
|
||||
message = "Download file list error: " + parseServerError(error);
|
||||
} else if (!Algorithms.isEmpty(resultJson)) {
|
||||
try {
|
||||
JSONObject result = new JSONObject(resultJson);
|
||||
String totalZipSize = result.getString("totalZipSize");
|
||||
|
@ -425,6 +453,13 @@ public class BackupHelper {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFileDownloadDone(@NonNull File file) {
|
||||
if (listener != null) {
|
||||
listener.onFileDownloaded(file);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFileDownloadedAsync(@NonNull File file) {
|
||||
if (listener != null) {
|
||||
|
@ -435,7 +470,7 @@ public class BackupHelper {
|
|||
@Override
|
||||
public void onFilesDownloadDone(@NonNull Map<File, String> errors) {
|
||||
if (listener != null) {
|
||||
listener.onFilesDownloadDone(errors);
|
||||
listener.onFilesDownloadDone(resolveServerErrors(errors));
|
||||
}
|
||||
}
|
||||
}, EXECUTOR);
|
||||
|
@ -523,6 +558,36 @@ public class BackupHelper {
|
|||
task.executeOnExecutor(EXECUTOR);
|
||||
}
|
||||
|
||||
private Map<File, String> resolveServerErrors(@NonNull Map<File, String> errors) {
|
||||
Map<File, String> resolvedErrors = new HashMap<>();
|
||||
for (Entry<File, String> fileError : errors.entrySet()) {
|
||||
File file = fileError.getKey();
|
||||
String errorStr = fileError.getValue();
|
||||
try {
|
||||
JSONObject errorJson = new JSONObject(errorStr);
|
||||
JSONObject error = errorJson.getJSONObject("error");
|
||||
errorStr = "Error " + error.getInt("errorCode") + " (" + error.getString("message") + ")";
|
||||
} catch (JSONException e) {
|
||||
// ignore
|
||||
}
|
||||
resolvedErrors.put(file, errorStr);
|
||||
}
|
||||
return resolvedErrors;
|
||||
}
|
||||
|
||||
private String parseServerError(@NonNull String error) {
|
||||
try {
|
||||
JSONObject resultError = new JSONObject(error);
|
||||
if (resultError.has("error")) {
|
||||
JSONObject errorObj = resultError.getJSONObject("error");
|
||||
return errorObj.getInt("errorCode") + " (" + errorObj.getString("message") + ")";
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
// ignore
|
||||
}
|
||||
return error;
|
||||
}
|
||||
|
||||
@SuppressLint("StaticFieldLeak")
|
||||
public void generateBackupInfo(@NonNull final List<GpxFileInfo> localFiles, @NonNull final List<UserFile> remoteFiles,
|
||||
@Nullable final OnGenerateBackupInfoListener listener) {
|
||||
|
|
|
@ -179,6 +179,11 @@ public class BackupTask {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFileUploadDone(@NonNull File file) {
|
||||
onTaskProgressDone();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFilesUploadDone(@NonNull Map<File, String> errors) {
|
||||
uploadErrors = errors;
|
||||
|
@ -223,6 +228,11 @@ public class BackupTask {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFileDownloaded(@NonNull File file) {
|
||||
onTaskProgressDone();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFileDownloadedAsync(@NonNull File file) {
|
||||
UserFile userFile = filesMap.get(file);
|
||||
|
@ -299,7 +309,7 @@ public class BackupTask {
|
|||
progress.startTask((String) objects[0], -1);
|
||||
} else if (objects[0] instanceof Integer) {
|
||||
int progressValue = (Integer) objects[0];
|
||||
if (progressValue < Integer.MAX_VALUE) {
|
||||
if (progressValue >= 0) {
|
||||
progress.progress(progressValue);
|
||||
} else {
|
||||
progress.finishTask();
|
||||
|
@ -312,6 +322,13 @@ public class BackupTask {
|
|||
}
|
||||
}
|
||||
|
||||
private void onTaskProgressDone() {
|
||||
Context ctx = contextRef.get();
|
||||
if (ctx instanceof Activity && AndroidUtils.isActivityNotDestroyed((Activity) ctx) && progress != null) {
|
||||
progress.finishTask();
|
||||
}
|
||||
}
|
||||
|
||||
private void onError(@NonNull String message) {
|
||||
this.error = message;
|
||||
runningTasks.clear();
|
||||
|
|
|
@ -137,6 +137,7 @@ public class TestBackupActivity extends OsmandActionBarActivity {
|
|||
a.buttonVerify.setVisibility(View.VISIBLE);
|
||||
a.buttonVerify.setEnabled(status == BackupHelper.STATUS_SUCCESS);
|
||||
a.tokenEditText.requestFocus();
|
||||
a.infoView.setText(message);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -162,11 +163,12 @@ public class TestBackupActivity extends OsmandActionBarActivity {
|
|||
a.progressBar.setVisibility(View.GONE);
|
||||
a.buttonVerify.setEnabled(status != BackupHelper.STATUS_SUCCESS);
|
||||
if (status == BackupHelper.STATUS_SUCCESS) {
|
||||
tokenEdit.setVisibility(View.GONE);
|
||||
buttonVerify.setVisibility(View.GONE);
|
||||
}
|
||||
a.tokenEdit.setVisibility(View.GONE);
|
||||
a.buttonVerify.setVisibility(View.GONE);
|
||||
a.prepareBackup();
|
||||
}
|
||||
a.infoView.setText(message);
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
|
@ -196,15 +198,19 @@ public class TestBackupActivity extends OsmandActionBarActivity {
|
|||
String description;
|
||||
if (error != null) {
|
||||
description = error;
|
||||
} else if (uploadErrors == null && downloadErrors == null) {
|
||||
} else if (uploadErrors == null && deleteErrors == null) {
|
||||
description = "No data";
|
||||
} else {
|
||||
description = getBackupErrorsDescription(uploadErrors, downloadErrors, deleteErrors, error);
|
||||
}
|
||||
a.infoView.setText(description);
|
||||
a.infoView.requestFocus();
|
||||
a.prepareBackup();
|
||||
a.buttonBackup.setEnabled(true);
|
||||
if (Algorithms.isEmpty(description)) {
|
||||
a.prepareBackup();
|
||||
} else {
|
||||
a.backupInfo = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -233,8 +239,12 @@ public class TestBackupActivity extends OsmandActionBarActivity {
|
|||
}
|
||||
a.infoView.setText(description);
|
||||
a.infoView.requestFocus();
|
||||
a.prepareBackup();
|
||||
a.buttonRestore.setEnabled(true);
|
||||
if (Algorithms.isEmpty(description)) {
|
||||
a.prepareBackup();
|
||||
} else {
|
||||
a.backupInfo = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -249,21 +259,21 @@ public class TestBackupActivity extends OsmandActionBarActivity {
|
|||
private String getBackupErrorsDescription(@Nullable Map<File, String> uploadErrors, @Nullable Map<File, String> downloadErrors, @Nullable Map<UserFile, String> deleteErrors, @Nullable String error) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
if (!Algorithms.isEmpty(uploadErrors)) {
|
||||
sb.append("--- Upload errors ---").append("\n");
|
||||
sb.append("--- Upload errors ---").append("\n\n");
|
||||
for (Entry<File, String> uploadEntry : uploadErrors.entrySet()) {
|
||||
sb.append(uploadEntry.getKey().getName()).append(": ").append(uploadEntry.getValue()).append("\n");
|
||||
sb.append(uploadEntry.getKey().getName()).append(": ").append(uploadEntry.getValue()).append("\n\n");
|
||||
}
|
||||
}
|
||||
if (!Algorithms.isEmpty(downloadErrors)) {
|
||||
sb.append("--- Download errors ---").append("\n");
|
||||
sb.append("--- Download errors ---").append("\n\n");
|
||||
for (Entry<File, String> downloadEntry : downloadErrors.entrySet()) {
|
||||
sb.append(downloadEntry.getKey().getName()).append(": ").append(downloadEntry.getValue()).append("\n");
|
||||
sb.append(downloadEntry.getKey().getName()).append(": ").append(downloadEntry.getValue()).append("\n\n");
|
||||
}
|
||||
}
|
||||
if (!Algorithms.isEmpty(deleteErrors)) {
|
||||
sb.append("--- Delete errors ---").append("\n");
|
||||
sb.append("--- Delete errors ---").append("\n\n");
|
||||
for (Entry<UserFile, String> deleteEntry : deleteErrors.entrySet()) {
|
||||
sb.append(deleteEntry.getKey().getName()).append(": ").append(deleteEntry.getValue()).append("\n");
|
||||
sb.append(deleteEntry.getKey().getName()).append(": ").append(deleteEntry.getValue()).append("\n\n");
|
||||
}
|
||||
}
|
||||
return sb.length() == 0 ? "OK" : sb.toString();
|
||||
|
@ -272,32 +282,32 @@ public class TestBackupActivity extends OsmandActionBarActivity {
|
|||
private String getBackupDescription(@NonNull BackupInfo backupInfo) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
if (!Algorithms.isEmpty(backupInfo.filesToUpload)) {
|
||||
sb.append("\n").append("--- Upload ---").append("\n");
|
||||
sb.append("\n").append("--- Upload ---").append("\n\n");
|
||||
for (GpxFileInfo info : backupInfo.filesToUpload) {
|
||||
sb.append(info.getFileName(true))
|
||||
.append(" L: ").append(DF.format(new Date(info.getFileDate())))
|
||||
.append(" U: ").append(DF.format(new Date(info.uploadTime)))
|
||||
.append("\n");
|
||||
.append("\n\n");
|
||||
}
|
||||
}
|
||||
if (!Algorithms.isEmpty(backupInfo.filesToDownload)) {
|
||||
sb.append("\n").append("--- Download ---").append("\n");
|
||||
sb.append("\n").append("--- Download ---").append("\n\n");
|
||||
for (UserFile userFile : backupInfo.filesToDownload) {
|
||||
sb.append(userFile.getName())
|
||||
.append(" R: ").append(DF.format(new Date(userFile.getClienttimems())))
|
||||
.append("\n");
|
||||
.append("\n\n");
|
||||
}
|
||||
}
|
||||
if (!Algorithms.isEmpty(backupInfo.filesToDelete)) {
|
||||
sb.append("\n").append("--- Delete ---").append("\n");
|
||||
sb.append("\n").append("--- Delete ---").append("\n\n");
|
||||
for (UserFile userFile : backupInfo.filesToDelete) {
|
||||
sb.append(userFile.getName())
|
||||
.append(" R: ").append(DF.format(new Date(userFile.getClienttimems())))
|
||||
.append("\n");
|
||||
.append("\n\n");
|
||||
}
|
||||
}
|
||||
if (!Algorithms.isEmpty(backupInfo.filesToMerge)) {
|
||||
sb.append("\n").append("--- Conflicts ---").append("\n");
|
||||
sb.append("\n").append("--- Conflicts ---").append("\n\n");
|
||||
for (Pair<GpxFileInfo, UserFile> localRemote : backupInfo.filesToMerge) {
|
||||
GpxFileInfo local = localRemote.first;
|
||||
UserFile remote = localRemote.second;
|
||||
|
@ -305,7 +315,7 @@ public class TestBackupActivity extends OsmandActionBarActivity {
|
|||
.append(" L: ").append(DF.format(new Date(local.getFileDate())))
|
||||
.append(" U: ").append(DF.format(new Date(local.uploadTime)))
|
||||
.append(" R: ").append(DF.format(new Date(remote.getClienttimems())))
|
||||
.append("\n");
|
||||
.append("\n\n");
|
||||
}
|
||||
}
|
||||
return sb.toString();
|
||||
|
|
|
@ -8,6 +8,9 @@ import android.os.AsyncTask;
|
|||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import net.osmand.AndroidNetworkUtils;
|
||||
import net.osmand.AndroidNetworkUtils.OnRequestResultListener;
|
||||
import net.osmand.AndroidNetworkUtils.OnSendRequestsListener;
|
||||
|
@ -41,9 +44,6 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
public abstract class InAppPurchaseHelper {
|
||||
// Debug tag, for logging
|
||||
protected static final org.apache.commons.logging.Log LOG = PlatformUtil.getLog(InAppPurchaseHelper.class);
|
||||
|
@ -466,7 +466,7 @@ public abstract class InAppPurchaseHelper {
|
|||
protected void onSkuDetailsResponseDone(List<PurchaseInfo> purchaseInfoList) {
|
||||
final AndroidNetworkUtils.OnRequestResultListener listener = new AndroidNetworkUtils.OnRequestResultListener() {
|
||||
@Override
|
||||
public void onResult(String result) {
|
||||
public void onResult(@Nullable String result, @Nullable String error) {
|
||||
notifyDismissProgress(InAppPurchaseTaskType.REQUEST_INVENTORY);
|
||||
notifyGetItems();
|
||||
stop(true);
|
||||
|
@ -477,7 +477,7 @@ public abstract class InAppPurchaseHelper {
|
|||
if (purchaseInfoList.size() > 0) {
|
||||
sendTokens(purchaseInfoList, listener);
|
||||
} else {
|
||||
listener.onResult("OK");
|
||||
listener.onResult("OK", null);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -503,7 +503,7 @@ public abstract class InAppPurchaseHelper {
|
|||
liveUpdatesPurchase.setState(ctx, SubscriptionState.UNDEFINED);
|
||||
sendTokens(Collections.singletonList(info), new OnRequestResultListener() {
|
||||
@Override
|
||||
public void onResult(String result) {
|
||||
public void onResult(@Nullable String result, @Nullable String error) {
|
||||
boolean active = ctx.getSettings().LIVE_UPDATES_PURCHASED.get();
|
||||
ctx.getSettings().LIVE_UPDATES_PURCHASED.set(true);
|
||||
ctx.getSettings().getCustomRenderBooleanProperty("depthContours").set(true);
|
||||
|
@ -642,7 +642,7 @@ public abstract class InAppPurchaseHelper {
|
|||
}
|
||||
}
|
||||
if (listener != null) {
|
||||
listener.onResult("OK");
|
||||
listener.onResult("OK", null);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -695,7 +695,7 @@ public abstract class InAppPurchaseHelper {
|
|||
} catch (Exception e) {
|
||||
logError("SendToken Error", e);
|
||||
if (listener != null) {
|
||||
listener.onResult("Error");
|
||||
listener.onResult("Error", null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ import android.content.Context;
|
|||
import android.os.AsyncTask;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import net.osmand.AndroidNetworkUtils;
|
||||
import net.osmand.AndroidNetworkUtils.OnRequestResultListener;
|
||||
|
@ -194,7 +195,7 @@ public class PerformLiveUpdateAsyncTask
|
|||
AndroidNetworkUtils.sendRequestAsync(
|
||||
app, LiveUpdatesFragment.URL, null, "Requesting map updates info...", false, false, new OnRequestResultListener() {
|
||||
@Override
|
||||
public void onResult(String result) {
|
||||
public void onResult(@Nullable String result, @Nullable String error) {
|
||||
if (!Algorithms.isEmpty(result)) {
|
||||
SimpleDateFormat source = new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.US);
|
||||
source.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||
|
|
|
@ -208,7 +208,7 @@ public class SubscriptionFragment extends BaseOsmAndDialogFragment implements In
|
|||
"https://osmand.net/subscription/update",
|
||||
parameters, "Sending data...", true, true, new AndroidNetworkUtils.OnRequestResultListener() {
|
||||
@Override
|
||||
public void onResult(String result) {
|
||||
public void onResult(@Nullable String result, @Nullable String error) {
|
||||
dismissProgress(null);
|
||||
OsmandApplication app = getMyApplication();
|
||||
if (result != null) {
|
||||
|
|
|
@ -6,6 +6,8 @@ import android.view.View;
|
|||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import net.osmand.AndroidNetworkUtils;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
|
@ -71,7 +73,7 @@ public class SendSearchQueryBottomSheet extends MenuBottomSheetDialogFragment {
|
|||
AndroidNetworkUtils.sendRequestAsync(app, "https://osmand.net/api/missing_search", params,
|
||||
null, true, true, new AndroidNetworkUtils.OnRequestResultListener() {
|
||||
@Override
|
||||
public void onResult(String result) {
|
||||
public void onResult(@Nullable String result, @Nullable String error) {
|
||||
if (result != null && isAdded()) {
|
||||
try {
|
||||
JSONObject obj = new JSONObject(result);
|
||||
|
|
Loading…
Reference in a new issue