Skip to content

Commit

Permalink
Fixed issue with some application shares - URLs being handled incorre…
Browse files Browse the repository at this point in the history
…ctly, increased timeout.
  • Loading branch information
ScrewTSW committed Nov 6, 2018
1 parent 42a1409 commit 5d10c05
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ android {
applicationId "eu.dasancti.reversee"
minSdkVersion 21
targetSdkVersion 28
versionCode 2
versionName "ALPHA v0.3"
versionCode 3
versionName "ALPHA v0.4"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
Expand Down
22 changes: 21 additions & 1 deletion app/src/main/java/eu/dasancti/reversee/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AlertDialog;
Expand Down Expand Up @@ -63,7 +64,8 @@ protected void onCreate(Bundle savedInstanceState) {
}
if (action.equals(Intent.ACTION_SEND)) {
if (intent.hasExtra(Intent.EXTRA_TEXT)) {
String intentExtraText = intent.getParcelableExtra(Intent.EXTRA_TEXT).toString();
String intentExtraText = getSharedURL(intent);
if (intentExtraText == null) return;
progressStatus.setText(getString(R.string.progress_status_parsing_link));
if (intentExtraText.endsWith(".jpg") ||
intentExtraText.endsWith(".png") ||
Expand Down Expand Up @@ -114,6 +116,23 @@ protected void onCreate(Bundle savedInstanceState) {
}
}

@Nullable
private String getSharedURL(Intent intent) {
Bundle extras = intent.getExtras();
if (extras == null) {
Toast.makeText(MainActivity.this, "Failed to get shared URL, incorrect format.", Toast.LENGTH_SHORT).show();
this.finish();
return null;
}
String intentExtraText = extras.getString(Intent.EXTRA_TEXT);
if (intentExtraText == null) {
Toast.makeText(MainActivity.this, "Failed to get URL from bundle, URL is empty or malformed", Toast.LENGTH_SHORT).show();
this.finish();
return null;
}
return intentExtraText;
}

@Override
public void onRequestPermissionsResult(int requestCode,
@NonNull String permissions[],
Expand Down Expand Up @@ -142,6 +161,7 @@ private void handleImageSearch(Uri imageUri) throws FileNotFoundException {
AtomicReference<String> reverseSearchRedirectURL = new AtomicReference<>();
AsyncHttpClient asyncHttpClient = new AsyncHttpClient();
asyncHttpClient.addHeader(API_USER_AGENT_KEY, FAKE_USER_AGENT);
asyncHttpClient.setTimeout(30_000);
RequestParams requestParams = new RequestParams();
requestParams.put(API_SCH_KEY, API_SCH_VALUE);
requestParams.put(API_ENCODED_IMAGE_KEY, Objects.requireNonNull(getContentResolver().openInputStream(imageUri)));
Expand Down

0 comments on commit 5d10c05

Please sign in to comment.