BitlyCredsDialog
class implements a bit.ly credential dialog.
*
* @author Erik C. Thauvin
+ * @created March 28, 2012
* @since 1.0
*/
public class BitlyCredsDialog extends DialogPreference
{
private final Context context;
+ private EditText username;
private EditText apikey;
public BitlyCredsDialog(Context context, AttributeSet attrs)
@@ -62,15 +67,17 @@ public class BitlyCredsDialog extends DialogPreference
}
@Override
- protected void onBindDialogView(View view)
+ protected void onBindDialogView(@NonNull View view)
{
super.onBindDialogView(view);
final SharedPreferences sharedPrefs = getSharedPreferences();
- apikey = view.findViewById(R.id.bitly_accesstoken_edittext);
- final TextView textFld = view.findViewById(R.id.bitly_needtoken_textview);
+ username = (EditText) view.findViewById(R.id.bitly_username_edit);
+ apikey = (EditText) view.findViewById(R.id.bitly_apikey_edit);
+ final TextView textFld = (TextView) view.findViewById(R.id.bitly_text_fld);
- apikey.setText(sharedPrefs.getString(context.getString(R.string.prefs_key_bitly_apitoken), ""));
+ username.setText(sharedPrefs.getString(context.getString(R.string.prefs_key_bitly_username), ""));
+ apikey.setText(sharedPrefs.getString(context.getString(R.string.prefs_key_bitly_apikey), ""));
textFld.setOnClickListener(new View.OnClickListener()
{
@@ -92,9 +99,9 @@ public class BitlyCredsDialog extends DialogPreference
{
final SharedPreferences sharedPrefs = getSharedPreferences();
final Editor editor = sharedPrefs.edit();
-
- editor.putString(context.getString(R.string.prefs_key_bitly_apitoken), apikey.getText().toString());
- editor.apply();
+ editor.putString(context.getString(R.string.prefs_key_bitly_username), username.getText().toString());
+ editor.putString(context.getString(R.string.prefs_key_bitly_apikey), apikey.getText().toString());
+ editor.commit();
}
}
diff --git a/app/src/main/java/net/thauvin/erik/android/emaily/Emaily.java b/app/src/main/java/net/thauvin/erik/android/emaily/Emaily.java
index 877c755..727a865 100644
--- a/app/src/main/java/net/thauvin/erik/android/emaily/Emaily.java
+++ b/app/src/main/java/net/thauvin/erik/android/emaily/Emaily.java
@@ -1,64 +1,95 @@
/*
- * Emaily.java
+ * @(#)Emaily.java
*
- * Copyright (c) 2011-2020, Erik C. Thauvin (erik@thauvin.net)
+ * Copyright (c) 2011-2015 Erik C. Thauvin (http://erik.thauvin.net/)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
+ * modification, are permitted provided that the following conditions are
+ * met:
*
- * Redistributions of source code must retain the above copyright notice, this
- * list of conditions and the following disclaimer.
+ * Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
*
- * Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
*
- * Neither the name of this project nor the names of its contributors may be
- * used to endorse or promote products derived from this software without
- * specific prior written permission.
+ * Neither the name of the authors nor the names of its contributors may be
+ * used to endorse or promote products derived from this software without
+ * specific prior written permission.
*
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+ * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.thauvin.erik.android.emaily;
+import android.accounts.Account;
+import android.accounts.AccountManager;
+import android.accounts.AccountManagerCallback;
+import android.accounts.AccountManagerFuture;
+import android.accounts.OperationCanceledException;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.Context;
+import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
+import android.content.SharedPreferences.Editor;
+import android.content.pm.PackageManager.NameNotFoundException;
import android.os.AsyncTask;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.text.ClipboardManager;
+import android.text.Html;
import android.util.Log;
import android.widget.Toast;
-import net.thauvin.erik.bitly.Bitlinks;
-import net.thauvin.erik.isgd.Isgd;
+import com.google.api.client.googleapis.extensions.android2.auth.GoogleAccountManager;
+import com.google.api.client.googleapis.json.GoogleJsonError;
+import com.google.api.client.googleapis.json.GoogleJsonResponseException;
+import com.google.api.client.http.HttpTransport;
+import com.google.api.client.http.javanet.NetHttpTransport;
+import com.google.api.client.http.json.JsonHttpRequest;
+import com.google.api.client.http.json.JsonHttpRequestInitializer;
+import com.google.api.client.json.JsonFactory;
+import com.google.api.client.json.jackson.JacksonFactory;
+import com.google.api.services.urlshortener.Urlshortener;
+import com.google.api.services.urlshortener.UrlshortenerRequest;
+import com.google.api.services.urlshortener.model.Url;
+import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.UnknownHostException;
+import java.util.Date;
+
+import static com.rosaloves.bitlyj.Bitly.as;
+import static com.rosaloves.bitlyj.Bitly.shorten;
/**
* The Emaily
class implements a URL shortener intent.
*
* @author Erik C. Thauvin
+ * @created Oct 11, 2011
* @since 1.0
*/
-public class Emaily extends Activity {
+public class Emaily extends Activity
+{
+ private static final String ACCOUNT_TYPE = "com.google";
+ private static final String OAUTH_URL = "oauth2:https://www.googleapis.com/auth/urlshortener";
+
private String appName;
private SharedPreferences sharedPrefs;
@@ -66,34 +97,218 @@ public class Emaily extends Activity {
* Validates a string.
*
* @param s The string to validate.
- * @return returns true
if the string is not empty or null, false
- * otherwise.
+ * @return returns true
if the string is not empty or null, false
otherwise.
*/
- public static boolean isValid(String s) {
+ public static boolean isValid(String s)
+ {
return (s != null) && (!s.trim().isEmpty());
}
- /**
- * Returns the value of the specified shared reference based on the specified string id.
- *
- * @param id The string id.
- * @param defaultValue The default value, used if the preference is empty.
- * @return The preference value.
- */
- @SuppressWarnings("SameParameterValue")
- private boolean getBoolPref(int id, boolean defaultValue) {
- return sharedPrefs.getBoolean(getString(id), defaultValue);
+ @SuppressLint("CommitPrefEdits")
+ @Override
+ public void onCreate(Bundle savedInstanceState)
+ {
+ super.onCreate(savedInstanceState);
+
+ final Intent intent = getIntent();
+
+ appName = getString(R.string.app_name);
+ sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
+
+ if (Intent.ACTION_SEND.equals(intent.getAction()))
+ {
+ final boolean isGoogl = getBoolPref(R.string.prefs_key_googl_enabled, true);
+
+ if (isGoogl)
+ {
+ final String account = getPref(R.string.prefs_key_googl_account);
+
+ if (isValid(account))
+ {
+ startEmailyTask(intent, new Account(account, ACCOUNT_TYPE), false);
+ }
+ else
+ {
+ final AlertDialog.Builder builder = new AlertDialog.Builder(this, AlertDialog.THEME_DEVICE_DEFAULT_LIGHT);
+ builder.setTitle(R.string.dialog_accounts_title);
+
+ final Account[] accounts = AccountManager.get(this).getAccountsByType(ACCOUNT_TYPE);
+ final int size = accounts.length;
+ if (size > 0)
+ {
+ if (size == 1)
+ {
+ startEmailyTask(intent, accounts[0], false);
+ }
+ else
+ {
+ final CharSequence[] names = new CharSequence[size];
+ for (int i = 0; i < size; i++)
+ {
+ names[i] = accounts[i].name;
+ }
+
+ builder.setSingleChoiceItems(names, 0, new DialogInterface.OnClickListener()
+ {
+ @Override
+ public void onClick(DialogInterface dialog, int which)
+ {
+ dialog.dismiss();
+
+ final Editor editor = sharedPrefs.edit();
+ editor.putString(getString(R.string.prefs_key_googl_account), names[which].toString());
+ editor.putLong(getString(R.string.prefs_key_googl_token_expiry), 0L);
+ editor.commit();
+
+ startEmailyTask(intent, accounts[which], false);
+ }
+
+ });
+
+ builder.create().show();
+ }
+ }
+ else
+ {
+ //noinspection ConstantConditions
+ startEmailyTask(intent, isGoogl, false);
+ }
+ }
+ }
+ else
+ {
+ //noinspection ConstantConditions
+ startEmailyTask(intent, isGoogl, false);
+ }
+ }
+ else
+ {
+ Emaily.this.finish();
+ }
+
}
/**
- * Returns the value of the specified shared reference based on the specified string id. The
- * default value is an empty string.
+ * Starts the task.
+ *
+ * @param intent The original intent.
+ * @param isGoogl The goo.gl flag.
+ * @param isRetry The retry flag.
+ */
+ private void startEmailyTask(final Intent intent, final boolean isGoogl, final boolean isRetry)
+ {
+ final EmailyTask task;
+
+ if (isGoogl)
+ {
+ //noinspection ConstantConditions
+ task = new EmailyTask(getPref(R.string.prefs_key_googl_account), getPref(R.string.prefs_key_googl_token), isGoogl,
+ getBoolPref(R.string.prefs_key_html_chkbox), isRetry);
+ }
+ else
+ {
+ //noinspection ConstantConditions
+ task = new EmailyTask(getPref(R.string.prefs_key_bitly_username), getPref(R.string.prefs_key_bitly_apikey), isGoogl,
+ getBoolPref(R.string.prefs_key_html_chkbox), isRetry);
+ }
+
+ task.execute(intent);
+ }
+
+ /**
+ * Starts the task.
+ *
+ * @param intent The original intent.
+ * @param account The account.
+ * @param isRetry The retry flag.
+ */
+ private void startEmailyTask(final Intent intent, final Account account, final boolean isRetry)
+ {
+ final GoogleAccountManager googleAccountManager = new GoogleAccountManager(Emaily.this);
+
+ final long expiry = sharedPrefs.getLong(getString(R.string.prefs_key_googl_token_expiry), 0L);
+ final long now = System.currentTimeMillis();
+ final long maxLife = (60L * 55L) * 1000L; // 55 minutes
+
+ Log.d(appName, "Token Expires: " + new Date(expiry));
+
+ if (expiry >= (now + maxLife) || expiry <= now)
+ {
+ final String token = getPref(R.string.prefs_key_googl_token);
+ if (isValid(token))
+ {
+ googleAccountManager.manager.invalidateAuthToken(ACCOUNT_TYPE, token);
+
+ Log.d(appName, "Token Invalidated: " + token);
+ }
+ }
+
+ googleAccountManager.manager.getAuthToken(account, OAUTH_URL, null, Emaily.this, new AccountManagerCallbackfalse
.
*
- * @param intent The original intent.
- * @param isGd The is.gd flag.
+ * @param id The string id.
+ * @return The preference value.
*/
- private void startEmailyTask(final Intent intent, final boolean isGd) {
- final EmailyTask task;
-
- if (isGd) {
- //noinspection ConstantConditions
- task = new EmailyTask("", isGd);
- } else {
- //noinspection ConstantConditions
- task = new EmailyTask(getPref(R.string.prefs_key_bitly_apitoken), isGd);
- }
-
- task.execute(intent);
+ private boolean getBoolPref(int id)
+ {
+ return getBoolPref(id, false);
}
-
/**
- * The EmailyResult
class.
+ * Returns the value of the specified shared reference based on the specified string id.
+ *
+ * @param id The string id.
+ * @param defaultValue The default value, used if the preference is empty.
+ * @return The preference value.
*/
- private static class EmailyResult {
- private final Intent intent;
- private int code = 0;
- private String message;
-
- public EmailyResult(Intent intent) {
- this.intent = intent;
- }
-
- public int getCode() {
- return code;
- }
-
- @SuppressWarnings("unused")
- public Intent getIntent() {
- return intent;
- }
-
- public String getMessage() {
- if (isValid(message)) {
- return message;
- } else {
- return "";
- }
- }
-
- public boolean hasError() {
- return code != 0;
- }
-
- public void setCode(int code) {
- this.code = code;
- }
-
- public void setMessage(String message) {
- this.message = message;
- }
+ private boolean getBoolPref(int id, boolean defaultValue)
+ {
+ return sharedPrefs.getBoolean(getString(id), defaultValue);
}
/**
* The EmailyTask
class.
*/
- @SuppressLint("StaticFieldLeak")
- private class EmailyTask extends AsyncTaskEmailyResult
class.
+ */
+ private class EmailyResult
+ {
+ private final Intent intent;
+ private int code = 0;
+ private String message;
+ private boolean retry = false;
+
+ public EmailyResult(Intent intent)
+ {
+ this.intent = intent;
+ }
+
+ public int getCode()
+ {
+ return code;
+ }
+
+ public void setCode(int code)
+ {
+ this.code = code;
+ }
+
+ public String getMessage()
+ {
+ if (isValid(message))
+ {
+ return message;
+ }
+ else
+ {
+ return "";
+ }
+ }
+
+ public void setMessage(String message)
+ {
+ this.message = message;
+ }
+
+ public Intent getIntent()
+ {
+ return intent;
+ }
+
+ public boolean hasError()
+ {
+ return code != 0;
+ }
+
+ public boolean isRetry()
+ {
+ return retry;
+ }
+
+ public void setRetry(boolean retry)
+ {
+ this.retry = retry;
+ }
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/net/thauvin/erik/android/emaily/EmailyPrefs.java b/app/src/main/java/net/thauvin/erik/android/emaily/EmailyPrefs.java
index 9a5b94e..54b6a93 100644
--- a/app/src/main/java/net/thauvin/erik/android/emaily/EmailyPrefs.java
+++ b/app/src/main/java/net/thauvin/erik/android/emaily/EmailyPrefs.java
@@ -1,36 +1,40 @@
/*
- * EmailyPrefs.java
+ * @(#)EmailyPrefs.java
*
- * Copyright (c) 2011-2020, Erik C. Thauvin (erik@thauvin.net)
+ * Copyright (c) 2011-2015 Erik C. Thauvin (http://erik.thauvin.net/)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
+ * modification, are permitted provided that the following conditions are
+ * met:
*
- * Redistributions of source code must retain the above copyright notice, this
- * list of conditions and the following disclaimer.
+ * Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
*
- * Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
*
- * Neither the name of this project nor the names of its contributors may be
- * used to endorse or promote products derived from this software without
- * specific prior written permission.
+ * Neither the name of the authors nor the names of its contributors may be
+ * used to endorse or promote products derived from this software without
+ * specific prior written permission.
*
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+ * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.thauvin.erik.android.emaily;
+import java.util.Locale;
+
import android.annotation.SuppressLint;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
@@ -39,104 +43,128 @@ import android.content.pm.PackageManager.NameNotFoundException;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
+import android.preference.CheckBoxPreference;
import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.preference.PreferenceScreen;
-import android.preference.SwitchPreference;
-
-import java.util.Locale;
/**
* The EmailyPrefs
class implements a preferences screen.
- *
+ *
* @author Erik C. Thauvin
+ * @created Oct 11, 2011
* @since 1.0
*/
-@SuppressLint("ExportedPreferenceActivity")
@SuppressWarnings("deprecation")
-public class EmailyPrefs extends PreferenceActivity implements OnSharedPreferenceChangeListener {
- private BitlyCredsDialog bitlyCreds;
- private SwitchPreference isgdBox;
- private SharedPreferences sharedPrefs;
+public class EmailyPrefs extends PreferenceActivity implements OnSharedPreferenceChangeListener
+{
+ private SharedPreferences sharedPrefs;
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
+ private CheckBoxPreference googlBox;
+ private BitlyCredsDialog bitlyCreds;
- addPreferencesFromResource(R.xml.prefs);
+ @Override
+ public void onCreate(Bundle savedInstanceState)
+ {
+ super.onCreate(savedInstanceState);
- sharedPrefs = getPreferenceScreen().getSharedPreferences();
+ addPreferencesFromResource(R.xml.prefs);
- isgdBox = (SwitchPreference) findPreference(getString(R.string.prefs_key_isgd_chkbox));
- bitlyCreds = (BitlyCredsDialog) findPreference(getString(R.string.prefs_key_bitly_creds));
+ sharedPrefs = getPreferenceScreen().getSharedPreferences();
- setBitlyCredsSummary();
+ googlBox = (CheckBoxPreference) findPreference(getString(R.string.prefs_key_googl_chkbox));
+ bitlyCreds = (BitlyCredsDialog) findPreference(getString(R.string.prefs_key_bitly_creds));
- if (isgdBox.isChecked()) {
- bitlyCreds.setEnabled(false);
- }
+ setSummary(bitlyCreds, getString(R.string.prefs_key_bitly_username), getString(R.string.prefs_bitly_creds_summary));
+ setSummary(googlBox, getString(R.string.prefs_key_googl_account), "");
- final Preference version = findPreference(getString(R.string.prefs_key_version));
- final PreferenceScreen feedback =
- (PreferenceScreen) findPreference(getString(R.string.prefs_key_feedback));
- try {
- final String vNumber =
- getPackageManager().getPackageInfo(getPackageName(), 0).versionName;
+ if (googlBox.isChecked())
+ {
+ bitlyCreds.setEnabled(false);
+ }
- version.setTitle(getString(R.string.prefs_version_title) + ' ' + vNumber);
+ final Preference version = findPreference(getString(R.string.prefs_key_version));
+ final PreferenceScreen feedback = (PreferenceScreen) findPreference(getString(R.string.prefs_key_feedback));
+ try
+ {
+ final String vNumber = getPackageManager().getPackageInfo(getPackageName(), 0).versionName;
- feedback.getIntent().setData(
- Uri.parse(getString(R.string.prefs_feedback_url)
- + "?subject="
- + getString(R.string.prefs_feedback_subject,
- getString(R.string.app_name),
- vNumber,
- getString(R.string.prefs_feedback_title)
- .toLowerCase(Locale.getDefault()),
- Build.MANUFACTURER,
- Build.PRODUCT,
- Build.VERSION.RELEASE)));
+ version.setTitle(getString(R.string.prefs_version_title) + ' ' + vNumber);
- } catch (NameNotFoundException ignore) {
- // Do nothing.
- }
- }
+ feedback.getIntent().setData(
+ Uri.parse(getString(R.string.prefs_feedback_url)
+ + "?subject="
+ + getString(R.string.prefs_feedback_subject, getString(R.string.app_name), vNumber,
+ getString(R.string.prefs_feedback_title).toLowerCase(Locale.getDefault()), Build.MANUFACTURER,
+ Build.PRODUCT, Build.VERSION.RELEASE)));
- @Override
- protected void onResume() {
- super.onResume();
- sharedPrefs.registerOnSharedPreferenceChangeListener(this);
- }
+ }
+ catch (NameNotFoundException ignore)
+ {
+ // Do nothing.
+ }
+ }
- @Override
- protected void onPause() {
- super.onPause();
- sharedPrefs.unregisterOnSharedPreferenceChangeListener(this);
- }
+ @Override
+ protected void onResume()
+ {
+ super.onResume();
+ sharedPrefs.registerOnSharedPreferenceChangeListener(this);
+ }
- @Override
- public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
- if (key.equals(getString(R.string.prefs_key_bitly_apitoken))) {
- setBitlyCredsSummary();
- } else if (key.equals(getString(R.string.prefs_key_isgd_chkbox))) {
- final boolean checked = isgdBox.isChecked();
+ @Override
+ protected void onPause()
+ {
+ super.onPause();
+ sharedPrefs.unregisterOnSharedPreferenceChangeListener(this);
+ }
- bitlyCreds.setEnabled(!checked);
+ @SuppressLint("CommitPrefEdits")
+ @Override
+ public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key)
+ {
+ if (key.equals(getString(R.string.prefs_key_bitly_username)))
+ {
+ setSummary(bitlyCreds, key, getString(R.string.prefs_bitly_creds_summary));
+ }
+ else if (key.equals(getString(R.string.prefs_key_googl_chkbox)))
+ {
+ final boolean checked = googlBox.isChecked();
- final Editor editor = sharedPrefs.edit();
- editor.putBoolean(getString(R.string.prefs_key_isgd_enabled), checked);
- editor.apply();
- }
- }
+ bitlyCreds.setEnabled(!checked);
- /**
- * Sets the bit.ly credentials summary.
- */
- private void setBitlyCredsSummary() {
- if (Emaily.isValid(sharedPrefs.getString(getString(R.string.prefs_key_bitly_apitoken), ""))) {
- bitlyCreds.setSummary(getString(R.string.prefs_bitly_creds_summary_edit));
- } else {
- bitlyCreds.setSummary(getString(R.string.prefs_bitly_creds_summary_default));
- }
- }
+ final Editor editor = sharedPrefs.edit();
+ editor.putBoolean(getString(R.string.prefs_key_googl_enabled), checked);
+
+ if (!checked)
+ {
+ editor.putString(getString(R.string.prefs_key_googl_account), "");
+ editor.putLong(getString(R.string.prefs_key_googl_token_expiry), 0L);
+ googlBox.setSummary("");
+ }
+
+ editor.commit();
+ }
+ }
+
+ /**
+ * Sets a preference's summary.
+ *
+ * @param editPref The preference.
+ * @param key The preference key.
+ * @param defValue The default value.
+ */
+ private void setSummary(Preference editPref, String key, String defValue)
+ {
+ final String value = sharedPrefs.getString(key, defValue);
+
+ if (Emaily.isValid(value))
+ {
+ editPref.setSummary(value);
+ }
+ else
+ {
+ editPref.setSummary(defValue);
+ }
+ }
}
diff --git a/app/src/main/res/layout/bitlycreds.xml b/app/src/main/res/layout/bitlycreds.xml
index 859d613..b0bf4e5 100644
--- a/app/src/main/res/layout/bitlycreds.xml
+++ b/app/src/main/res/layout/bitlycreds.xml
@@ -1,34 +1,66 @@
-- -A simple app that makes things easier, and helps us to save some time.
- -
Emaily makes it easy to share shortened links from your phone.
-No copy/paste required. Long URLs are squeezed into fewer characters using is.gd or bit.ly.
--
-
To enable Bitly follow these steps:
-