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 { try {
if (isGd) { if (isGd) {
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 Bitlinks bitlinks = new Bitlinks(keytoken); if (Emaily.isValid(keytoken)) {
shortUrl.append(bitlinks.shorten(item)); final Bitlinks bitlinks = new Bitlinks(keytoken);
if (!bitlinks.getLastCallResponse().isSuccessful()) { shortUrl.append(bitlinks.shorten(item));
final int resultCode = bitlinks.getLastCallResponse() if (!bitlinks.getLastCallResponse().isSuccessful()) {
.getResultCode(); result.setCode(R.string.alert_error);
result.setCode(R.string.alert_error); result.setMessage(String.format(
result.setMessage(String.format( getString(R.string.alert_http_status_code),
getString(R.string.alert_http_status_code), bitlinks.getLastCallResponse().getResultCode()));
resultCode)); }
} else {
shortUrl.append(item);
result.setCode(R.string.alert_notoken);
} }
} }
} catch (Exception e) { } catch (Exception e) {
@ -273,7 +276,7 @@ public class Emaily extends Activity {
break; break;
} catch (MalformedURLException mue) { } 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) { if (textBefore.length() > 0) {
textBefore.append(" "); textBefore.append(" ");
@ -283,12 +286,11 @@ public class Emaily extends Activity {
} }
} }
} else { } else {
result.setCode(R.string.alert_nocreds); result.setCode(R.string.alert_nourl);
} }
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));
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());
@ -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 { try {
startActivity(emailIntent); startActivity(emailIntent);
@ -316,13 +320,10 @@ public class Emaily extends Activity {
//noinspection deprecation //noinspection deprecation
clip.setText(shortUrl); clip.setText(shortUrl);
} }
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));
} }
} }
@ -346,10 +347,8 @@ public class Emaily extends Activity {
result.getMessage(), result.getMessage(),
isGd ? getString(R.string.prefs_isgd_title) isGd ? getString(R.string.prefs_isgd_title)
: getString(R.string.prefs_bitly_title)); : getString(R.string.prefs_bitly_title));
Log.d(appName, msg); Log.d(appName, "Toast --> " + msg);
Toast.makeText(getApplicationContext(), Toast.makeText(getApplicationContext(), msg, Toast.LENGTH_LONG).show();
getString(result.getCode(), result.getMessage(), msg),
Toast.LENGTH_LONG).show();
} }
Emaily.this.finish(); Emaily.this.finish();

View file

@ -2,10 +2,11 @@
<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_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 %2$s: %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="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="app_name">Emaily</string>
<string name="prefs_about_title">About</string> <string name="prefs_about_title">About</string>
<string name="prefs_author_url">https://m.thauvin.net/android/</string> <string name="prefs_author_url">https://m.thauvin.net/android/</string>