More logic cleanup.

This commit is contained in:
Erik C. Thauvin 2020-07-31 18:02:53 -07:00
parent 5c7b2d1db8
commit e456ee6ee7
2 changed files with 22 additions and 22 deletions

View file

@ -241,18 +241,21 @@ public class Emaily extends Activity {
try {
if (isGd) {
Log.d(appName, "is.gd -> " + item);
Log.d(appName, "is.gd --> " + item);
shortUrl.append(Isgd.shorten(item));
} else {
final Bitlinks bitlinks = new Bitlinks(keytoken);
shortUrl.append(bitlinks.shorten(item));
if (!bitlinks.getLastCallResponse().isSuccessful()) {
final int resultCode = bitlinks.getLastCallResponse()
.getResultCode();
result.setCode(R.string.alert_error);
result.setMessage(String.format(
getString(R.string.alert_http_status_code),
resultCode));
if (Emaily.isValid(keytoken)) {
final Bitlinks bitlinks = new Bitlinks(keytoken);
shortUrl.append(bitlinks.shorten(item));
if (!bitlinks.getLastCallResponse().isSuccessful()) {
result.setCode(R.string.alert_error);
result.setMessage(String.format(
getString(R.string.alert_http_status_code),
bitlinks.getLastCallResponse().getResultCode()));
}
} else {
shortUrl.append(item);
result.setCode(R.string.alert_notoken);
}
}
} catch (Exception e) {
@ -273,7 +276,7 @@ public class Emaily extends Activity {
break;
} catch (MalformedURLException mue) {
Log.d(appName, "Attempted to process an invalid URL: " + item, mue);
Log.d(appName, "Attempted to process an invalid URL --> " + item, mue);
if (textBefore.length() > 0) {
textBefore.append(" ");
@ -283,12 +286,11 @@ public class Emaily extends Activity {
}
}
} else {
result.setCode(R.string.alert_nocreds);
result.setCode(R.string.alert_nourl);
}
if (shortUrl.length() > 0) {
emailIntent.putExtra(Intent.EXTRA_TEXT, shortUrl.toString());
Log.d(appName, "URL: " + emailIntent.getStringExtra(Intent.EXTRA_TEXT));
if (!isValid(pageTitle) && textBefore.length() > 0) {
emailIntent.putExtra(Intent.EXTRA_SUBJECT, textBefore.toString());
@ -304,6 +306,8 @@ public class Emaily extends Activity {
}
}
}
Log.d(appName, "EXTRA_TXT --> " + emailIntent.getStringExtra(Intent.EXTRA_TEXT));
Log.d(appName, "EXTRA_SUBJECT --> " + emailIntent.getStringExtra(Intent.EXTRA_SUBJECT));
try {
startActivity(emailIntent);
@ -316,13 +320,10 @@ public class Emaily extends Activity {
//noinspection deprecation
clip.setText(shortUrl);
}
result.setCode(R.string.alert_notfound_clip);
result.setMessage(getString(R.string.alert_notfound_clip));
} else {
result.setCode(R.string.alert_notfound);
result.setMessage(getString(R.string.alert_notfound));
}
}
@ -346,10 +347,8 @@ public class Emaily extends Activity {
result.getMessage(),
isGd ? getString(R.string.prefs_isgd_title)
: getString(R.string.prefs_bitly_title));
Log.d(appName, msg);
Toast.makeText(getApplicationContext(),
getString(result.getCode(), result.getMessage(), msg),
Toast.LENGTH_LONG).show();
Log.d(appName, "Toast --> " + msg);
Toast.makeText(getApplicationContext(), msg, Toast.LENGTH_LONG).show();
}
Emaily.this.finish();

View file

@ -2,10 +2,11 @@
<resources>
<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_nohost">Sorry. Could not connect to %1$s: %2$s</string>
<string name="alert_nohost">Sorry. Could not connect to %2$s: %1$s</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_notoken">Please specify a valid API access token.</string>
<string name="alert_nourl">Could not find a URL to shorten.</string>
<string name="app_name">Emaily</string>
<string name="prefs_about_title">About</string>
<string name="prefs_author_url">https://m.thauvin.net/android/</string>