Cleanup error messages.

This commit is contained in:
Erik C. Thauvin 2020-07-31 13:55:22 -07:00
parent 49aaed0ef5
commit 5c7b2d1db8
6 changed files with 37 additions and 22 deletions

View file

@ -21,5 +21,10 @@
<option name="name" value="Google" /> <option name="name" value="Google" />
<option name="url" value="https://dl.google.com/dl/android/maven2/" /> <option name="url" value="https://dl.google.com/dl/android/maven2/" />
</remote-repository> </remote-repository>
<remote-repository>
<option name="id" value="MavenLocal" />
<option name="name" value="MavenLocal" />
<option name="url" value="file:$PROJECT_DIR$/../../maven/repository/" />
</remote-repository>
</component> </component>
</project> </project>

View file

@ -1,4 +1,4 @@
Copyright (c) 2020, Erik C. Thauvin (erik@thauvin.net) Copyright (c) 2011-2020, Erik C. Thauvin (erik@thauvin.net)
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without

View file

@ -27,7 +27,7 @@ dependencies {
//implementation 'androidx.appcompat:appcompat:1.1.0' //implementation 'androidx.appcompat:appcompat:1.1.0'
//implementation 'androidx.preference:preference:1.1.1' //implementation 'androidx.preference:preference:1.1.1'
implementation 'net.thauvin.erik:bitly-shorten:0.9.2' implementation 'net.thauvin.erik:bitly-shorten:0.9.3'
implementation 'net.thauvin.erik:isgd-shorten:0.9.1' implementation 'net.thauvin.erik:isgd-shorten:0.9.1'
testImplementation 'junit:junit:4.13' testImplementation 'junit:junit:4.13'

View file

@ -45,14 +45,13 @@ import android.text.ClipboardManager;
import android.util.Log; import android.util.Log;
import android.widget.Toast; import android.widget.Toast;
import net.thauvin.erik.bitly.Bitly; import net.thauvin.erik.bitly.Bitlinks;
import net.thauvin.erik.isgd.Isgd; import net.thauvin.erik.isgd.Isgd;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import java.net.UnknownHostException; import java.net.UnknownHostException;
/** /**
* The <code>Emaily</code> class implements a URL shortener intent. * The <code>Emaily</code> class implements a URL shortener intent.
* *
@ -110,7 +109,6 @@ public class Emaily extends Activity {
return sharedPrefs.getString(getString(id), defaultValue); return sharedPrefs.getString(getString(id), defaultValue);
} }
@SuppressLint("CommitPrefEdits")
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
@ -246,12 +244,15 @@ public class Emaily extends Activity {
Log.d(appName, "is.gd -> " + item); Log.d(appName, "is.gd -> " + item);
shortUrl.append(Isgd.shorten(item)); shortUrl.append(Isgd.shorten(item));
} else { } else {
final Bitly bitly = new Bitly(keytoken); final Bitlinks bitlinks = new Bitlinks(keytoken);
shortUrl.append(bitly.bitlinks().shorten(item)); shortUrl.append(bitlinks.shorten(item));
if (shortUrl.toString().equals(item)) { if (!bitlinks.getLastCallResponse().isSuccessful()) {
final int resultCode = bitlinks.getLastCallResponse()
.getResultCode();
result.setCode(R.string.alert_error); result.setCode(R.string.alert_error);
//@TODO fixme result.setMessage(String.format(
result.setMessage("TBD"); getString(R.string.alert_http_status_code),
resultCode));
} }
} }
} catch (Exception e) { } catch (Exception e) {
@ -262,7 +263,11 @@ public class Emaily extends Activity {
result.setMessage(cause.getMessage()); result.setMessage(cause.getMessage());
} else { } else {
result.setCode(R.string.alert_error); result.setCode(R.string.alert_error);
result.setMessage(e.getMessage()); if (cause != null) {
result.setMessage(cause.getMessage());
} else {
result.setMessage(e.getMessage());
}
} }
} }
@ -282,8 +287,8 @@ public class Emaily extends Activity {
} }
if (shortUrl.length() > 0) { if (shortUrl.length() > 0) {
emailIntent.putExtra(Intent.EXTRA_TEXT, shortUrl.toString()); emailIntent.putExtra(Intent.EXTRA_TEXT, shortUrl.toString());
Log.d(appName, "URL: " + emailIntent.getStringExtra(Intent.EXTRA_TEXT)); Log.d(appName, "URL: " + emailIntent.getStringExtra(Intent.EXTRA_TEXT));
if (!isValid(pageTitle) && textBefore.length() > 0) { if (!isValid(pageTitle) && textBefore.length() > 0) {
emailIntent.putExtra(Intent.EXTRA_SUBJECT, textBefore.toString()); emailIntent.putExtra(Intent.EXTRA_SUBJECT, textBefore.toString());
@ -313,8 +318,11 @@ public class Emaily extends Activity {
} }
result.setCode(R.string.alert_notfound_clip); result.setCode(R.string.alert_notfound_clip);
result.setMessage(getString(R.string.alert_notfound_clip));
} else { } else {
result.setCode(R.string.alert_notfound); result.setCode(R.string.alert_notfound);
result.setMessage(getString(R.string.alert_notfound));
} }
} }
@ -334,14 +342,14 @@ public class Emaily extends Activity {
} }
if (result.hasError()) { if (result.hasError()) {
Toast.makeText( final String msg = getString(result.getCode(),
getApplicationContext(), result.getMessage(),
getString(result.getCode(), isGd ? getString(R.string.prefs_isgd_title)
result.getMessage(), : getString(R.string.prefs_bitly_title));
isGd ? getString(R.string.prefs_isgd_title) Log.d(appName, msg);
: getString(R.string.prefs_bitly_title)), Toast.LENGTH_LONG) Toast.makeText(getApplicationContext(),
.show(); getString(result.getCode(), result.getMessage(), msg),
Toast.LENGTH_LONG).show();
} }
Emaily.this.finish(); Emaily.this.finish();

View file

@ -1,8 +1,9 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<resources> <resources>
<string name="alert_error">Sorry. An error was returned by %2$s while shortening the url: %1$s</string> <string name="alert_error">Sorry. An error was returned by %2$s while shortening the url: %1$s</string>
<string name="alert_http_status_code">HTTP Status Code %d</string>
<string name="alert_nocreds">Please provide your credentials to shorten urls.</string> <string name="alert_nocreds">Please provide your credentials to shorten urls.</string>
<string name="alert_nohost">Sorry. Could not connect to %1$s.</string> <string name="alert_nohost">Sorry. Could not connect to %1$s: %2$s</string>
<string name="alert_notfound">Sorry. No applications can perform this action.</string> <string name="alert_notfound">Sorry. No applications can perform this action.</string>
<string name="alert_notfound_clip">Sorry. No applications can perform this action. The shortened url has been copied to the clipboard.</string> <string name="alert_notfound_clip">Sorry. No applications can perform this action. The shortened url has been copied to the clipboard.</string>
<string name="app_name">Emaily</string> <string name="app_name">Emaily</string>

View file

@ -14,6 +14,7 @@ buildscript {
allprojects { allprojects {
repositories { repositories {
mavenLocal()
google() google()
jcenter() jcenter()
} }