Better error handling. Share the original content if not a URL.

This commit is contained in:
Sadique Ali 2013-07-21 10:31:03 -07:00
parent 2b7c887a12
commit a6c8687a13
4 changed files with 20 additions and 11 deletions

View File

@ -1,14 +1,14 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="in.sdqali.sharewithtitle" package="in.sdqali.sharewithtitle"
android:versionCode="2" android:versionCode="3"
android:versionName="1.1" > android:versionName="1.15" >
<uses-permission android:name="android.permission.INTERNET"></uses-permission> <uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-sdk <uses-sdk
android:minSdkVersion="14" android:minSdkVersion="11"
android:targetSdkVersion="16" /> android:targetSdkVersion="18" />
<application <application
android:allowBackup="true" android:allowBackup="true"

View File

@ -23,7 +23,13 @@ public class ReshareCallback implements TitleGrabCallback{
@Override @Override
public void onSuccess(String titleAndLink) { public void onSuccess(String titleAndLink) {
progressBar.setVisibility(View.VISIBLE); progressBar.setVisibility(View.VISIBLE);
Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND); showToast("Successfully grabbed title!");
reShare(titleAndLink);
cleanUp();
}
private void reShare(String titleAndLink) {
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
sharingIntent.setType("text/plain"); sharingIntent.setType("text/plain");
sharingIntent.putExtra(Intent.EXTRA_TEXT, titleAndLink); sharingIntent.putExtra(Intent.EXTRA_TEXT, titleAndLink);
@ -41,11 +47,15 @@ public class ReshareCallback implements TitleGrabCallback{
} }
@Override @Override
public void showError(String errorMessage) { public void showError(String errorMessage, String urlText) {
showToast(errorMessage);
reShare(urlText);
cleanUp();
}
private void showToast(String errorMessage) {
int duration = Toast.LENGTH_SHORT; int duration = Toast.LENGTH_SHORT;
Toast toast = Toast.makeText(activity.getApplicationContext(), errorMessage, duration); Toast toast = Toast.makeText(activity.getApplicationContext(), errorMessage, duration);
toast.show(); toast.show();
progressBar.setVisibility(View.GONE);
activity.finish();
} }
} }

View File

@ -7,5 +7,5 @@ public interface TitleGrabCallback {
public void onSuccess(String title); public void onSuccess(String title);
public void onProgress(); public void onProgress();
public void cleanUp(); public void cleanUp();
public void showError(String errorMessage); public void showError(String errorMessage, String urlText);
} }

View File

@ -17,7 +17,7 @@ public class TitleRetriever {
if(isValidUrl(urlText)) { if(isValidUrl(urlText)) {
new DownloadTaskNew(callback).execute(urlText); new DownloadTaskNew(callback).execute(urlText);
} else { } else {
callback.showError("Not a valid url. Could not load title!"); callback.showError("Not a valid url. Could not load title!", urlText);
} }
} }
@ -47,7 +47,6 @@ public class TitleRetriever {
output = title + " " + urlText; output = title + " " + urlText;
} }
callback.onSuccess(output); callback.onSuccess(output);
callback.cleanUp();
} }
} }
} }