From 5d44b5194929af15ce0262dcf0c7d4ef3e0d7002 Mon Sep 17 00:00:00 2001 From: Galeen <2math@mail.bg> Date: Tue, 23 Oct 2018 13:58:56 +0300 Subject: [PATCH] option to not check server url response helper method to open app in Play Store app --- .../repository/network/Action.java | 7 +++++- .../network/NetworkRequestHelper.java | 1 + .../repository/network/ServerOperation.java | 7 +++--- .../base_library/utils/IntentUtils.java | 23 +++++++++++++++---- 4 files changed, 29 insertions(+), 9 deletions(-) diff --git a/core_library/src/main/java/com/futurist_labs/android/base_library/repository/network/Action.java b/core_library/src/main/java/com/futurist_labs/android/base_library/repository/network/Action.java index 1ce0204..9a236ab 100644 --- a/core_library/src/main/java/com/futurist_labs/android/base_library/repository/network/Action.java +++ b/core_library/src/main/java/com/futurist_labs/android/base_library/repository/network/Action.java @@ -28,7 +28,7 @@ public class Action { File file; ArrayList files; ArrayList fileFields; - boolean isFullUrl = false; + boolean isFullUrl = false, isCheckServerUrl = true; int priority = NORMAL_PRIORITY; public Action() { @@ -182,4 +182,9 @@ public Action setPriority(int priority) { this.priority = priority; return this; } + + public Action setIsChecjServerUrl(boolean checkServerUrl) { + isCheckServerUrl = checkServerUrl; + return this; + } } diff --git a/core_library/src/main/java/com/futurist_labs/android/base_library/repository/network/NetworkRequestHelper.java b/core_library/src/main/java/com/futurist_labs/android/base_library/repository/network/NetworkRequestHelper.java index d9f75d2..cef85c6 100644 --- a/core_library/src/main/java/com/futurist_labs/android/base_library/repository/network/NetworkRequestHelper.java +++ b/core_library/src/main/java/com/futurist_labs/android/base_library/repository/network/NetworkRequestHelper.java @@ -610,6 +610,7 @@ static NetworkResponse downloadFile(String fileURL, File file) outputStream.close(); inputStream.close(); networkResponse = new NetworkResponse(responseCode, file); + networkResponse.url = url.toString(); LogUtils.d("downloadFile", "File downloaded"); } else { networkResponse = new NetworkResponse("No file to download. Server replied HTTP code: " + responseCode, responseCode); diff --git a/core_library/src/main/java/com/futurist_labs/android/base_library/repository/network/ServerOperation.java b/core_library/src/main/java/com/futurist_labs/android/base_library/repository/network/ServerOperation.java index bb91f88..893d8a5 100644 --- a/core_library/src/main/java/com/futurist_labs/android/base_library/repository/network/ServerOperation.java +++ b/core_library/src/main/java/com/futurist_labs/android/base_library/repository/network/ServerOperation.java @@ -70,11 +70,12 @@ protected NetworkResponse doInBackground(Action... params) { } } - if(res != null && res.isResponsePositive()){ - if(res.url != null && res.url.startsWith(NetConstants.SERVER_ADDRESS)){//we can use the url from action too + if (res != null && res.isResponsePositive()) { + if (!action.isCheckServerUrl || (res.url != null && res.url.startsWith(NetConstants.SERVER_ADDRESS))) { + //we can use the url from action too if (mCallback != null) mCallback.inTheEndOfDoInBackground(res); - }else{//not from our server + } else {//not from our server res.responseCode = NetworkResponse.ERROR_WRONG_SERVER; } } diff --git a/core_library/src/main/java/com/futurist_labs/android/base_library/utils/IntentUtils.java b/core_library/src/main/java/com/futurist_labs/android/base_library/utils/IntentUtils.java index 71798e9..e67de68 100644 --- a/core_library/src/main/java/com/futurist_labs/android/base_library/utils/IntentUtils.java +++ b/core_library/src/main/java/com/futurist_labs/android/base_library/utils/IntentUtils.java @@ -16,16 +16,19 @@ public class IntentUtils { /** * Please use {@link IntentUtils#openDialer(Context, String)} instead - * @param atv activity + * + * @param atv activity * @param phone the phone number to be populated */ @Deprecated public static void openDailer(Context atv, String phone) { openDialer(atv, phone); } + /** * Opens call app with the phone number populated - * @param atv activity + * + * @param atv activity * @param phone the phone number to be populated */ public static void openDialer(Context atv, String phone) { @@ -105,10 +108,10 @@ public static boolean sendEmailMessageToContacts(Context context, Uri attachmentUri) { Intent mailIntent = new Intent(); mailIntent.putExtra(Intent.EXTRA_SUBJECT, subject); - if (htmlBody!=null) { + if (htmlBody != null) { mailIntent.putExtra(Intent.EXTRA_HTML_TEXT, htmlBody);// SystemUtils.parseHtml(bodyText)); mailIntent.putExtra(Intent.EXTRA_TEXT, SystemUtils.parseHtml(htmlBody)); - }else{ + } else { mailIntent.putExtra(Intent.EXTRA_TEXT, bodyText); } @@ -130,7 +133,7 @@ public static boolean sendEmailMessageToContacts(Context context, Intent.FLAG_GRANT_READ_URI_PERMISSION); } } - }else{ + } else { mailIntent.setAction(Intent.ACTION_SENDTO); // For only email app should handle this intent mailIntent.setData(Uri.parse("mailto:")); @@ -386,4 +389,14 @@ public static Intent findFacebookClient(Context context) { } return null; } + + public static void openAppInPlayStore(Context ctx, String appId) { + Intent intent = new Intent(Intent.ACTION_VIEW); + intent.setData(Uri.parse(appId)); + intent.setPackage("com.android.vending");//Play store app + if(intent.resolveActivity(ctx.getPackageManager()) == null){ + intent.setPackage(null);// open in browser + } + ctx.startActivity(intent); + } }