Skip to content

Commit

Permalink
option to not check server url response
Browse files Browse the repository at this point in the history
helper method to open app in Play Store app
  • Loading branch information
2math committed Oct 23, 2018
1 parent c7f9d22 commit 5d44b51
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class Action {
File file;
ArrayList<File> files;
ArrayList<String> fileFields;
boolean isFullUrl = false;
boolean isFullUrl = false, isCheckServerUrl = true;
int priority = NORMAL_PRIORITY;

public Action() {
Expand Down Expand Up @@ -182,4 +182,9 @@ public Action setPriority(int priority) {
this.priority = priority;
return this;
}

public Action setIsChecjServerUrl(boolean checkServerUrl) {
isCheckServerUrl = checkServerUrl;
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,7 @@ static NetworkResponse downloadFile(String fileURL, File file)
outputStream.close();
inputStream.close();
networkResponse = new NetworkResponse<File>(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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
}

Expand All @@ -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:"));
Expand Down Expand Up @@ -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);
}
}

0 comments on commit 5d44b51

Please sign in to comment.