Skip to content

Commit

Permalink
Merge pull request #1767 from crankycoder/features/bug-1763
Browse files Browse the repository at this point in the history
Features/bug 1763
  • Loading branch information
crankycoder committed Apr 13, 2016
2 parents 12e4fd6 + 8487522 commit 37f8036
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import android.content.Intent;
import android.content.IntentFilter;
import android.support.v4.content.LocalBroadcastManager;
import android.text.TextUtils;

import org.mozilla.mozstumbler.service.Prefs;
import org.mozilla.mozstumbler.service.stumblerthread.Reporter;
Expand All @@ -23,7 +24,7 @@ class UploadingOccurringReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// Guard against LeaderBoard intents when we're not logged into FxA
if (Prefs.getInstance(context).getBearerToken() == null) {
if (TextUtils.isEmpty(Prefs.getInstance(context).getBearerToken())) {
return;
}

Expand Down Expand Up @@ -56,7 +57,7 @@ public LBStumblerBundleReceiver(Context c) {
@Override
public void onReceive(Context context, Intent intent) {
// Guard against LeaderBoard intents when we're not logged into FxA
if (Prefs.getInstance(context).getBearerToken() != null) {
if (!TextUtils.isEmpty(Prefs.getInstance(context).getBearerToken())) {
final StumblerBundle bundle = intent.getParcelableExtra(Reporter.NEW_BUNDLE_ARG_BUNDLE);
if (bundle.hasRadioData()) {
mStorage.insert(bundle.getGpsPosition());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ protected HashMap<String, String> getHeaders(AsyncUploadParam param) {
String bearerToken = Prefs.getInstanceWithoutContext().getBearerToken();
headers.put("Content-Encoding", "gzip");

if (bearerToken != null) {
if (!TextUtils.isEmpty(bearerToken)) {
headers.put(FxAService.BEARER_HEADER, "Bearer " + bearerToken);
}
return headers;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ protected void onStart() {
final Activity activity = this;
mWebView.setWebChromeClient(new WebChromeClient() {
public void onProgressChanged(WebView view, int progress) {
//activity.setProgress(progress * 100);
setSupportProgress(progress * 100);
if (progress > 45 && !mHasError) {
mWebView.setVisibility(View.VISIBLE);
Expand Down Expand Up @@ -77,24 +76,19 @@ public void onPageFinished(WebView webview, String url) {
});

setProgress(0);
ClientPrefs prefs = ClientPrefs.getInstance(getApplicationContext());
ClientPrefs prefs = ClientPrefs.getInstance(this);
URI tmpURI = null;
String url = null;

try {
tmpURI = new URI(getPrefs().getLbBaseURI() + "/?profile=" + getPrefs().getLeaderboardUID());
tmpURI = new URI(prefs.getLbBaseURI() + "/?profile=" + prefs.getLeaderboardUID());
url = tmpURI.normalize().toString();
} catch (URISyntaxException e) {
Log.e(LOG_TAG, "Error normalizing URL", e);
url = getPrefs().getLbBaseURI();
url = prefs.getLbBaseURI();
}

mWebView.loadUrl(url);
}


private ClientPrefs getPrefs() {
return ClientPrefs.getInstance(this);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@
import org.mozilla.mozstumbler.svclocator.services.log.ILogger;
import org.mozilla.mozstumbler.svclocator.services.log.LoggerUtil;

import java.util.Random;
import java.util.concurrent.ThreadLocalRandom;

public class PreferencesScreen extends PreferenceActivity implements IFxACallbacks{

private static final String LOG_TAG = LoggerUtil.makeLogTag(PreferencesScreen.class);
Expand Down Expand Up @@ -531,7 +534,8 @@ private void setFxANickname(String displayName) {
}

private String defaultDisplayName() {
return "user_" + Integer.toString(Math.abs(getPrefs().getEmail().hashCode()));
Random rand = new Random(System.currentTimeMillis() % 1000);
return "user_" + rand.nextInt(Integer.MAX_VALUE-1) + 1;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ protected static void apply(SharedPreferences.Editor editor) {
///
public synchronized String getUserAgent() {
String s = getStringPref(USER_AGENT_PREF);
return (s == null) ? AppGlobals.appName + "/" + AppGlobals.appVersionName : s;
return (TextUtils.isEmpty(s)) ? AppGlobals.appName + "/" + AppGlobals.appVersionName : s;
}

///
Expand All @@ -129,7 +129,7 @@ public synchronized void setFirefoxScanEnabled(boolean on) {

public synchronized String getMozApiKey() {
String s = getStringPref(MOZ_API_KEY);
return (s == null) ? "no-mozilla-api-key" : s;
return (TextUtils.isEmpty(s)) ? "no-mozilla-api-key" : s;
}

public synchronized void setMozApiKey(String s) {
Expand All @@ -150,10 +150,10 @@ public synchronized void setLastAttemptedUploadTime(long time) {

public synchronized String getNickname() {
String nickname = getStringPref(NICKNAME_PREF);
if (nickname != null) {
nickname = nickname.trim();
if (!TextUtils.isEmpty(nickname)) {
return nickname.trim();
}
return TextUtils.isEmpty(nickname) ? null : nickname;
return TextUtils.isEmpty(nickname) ? "" : nickname;
}

public synchronized void setNickname(String nick) {
Expand All @@ -168,7 +168,7 @@ public synchronized String getLeaderboardUID() {
if (!TextUtils.isEmpty(uid)) {
return uid;
}
return null;
return "";
}

public synchronized void setLeaderboardUID(String uid) {
Expand All @@ -179,10 +179,10 @@ public synchronized void setLeaderboardUID(String uid) {

public synchronized String getEmail() {
String email = getStringPref(EMAIL_PREF);
if (email != null) {
if (!TextUtils.isEmpty(email)) {
email = email.trim();
}
return TextUtils.isEmpty(email) ? null : email;
return TextUtils.isEmpty(email) ? "" : email;
}

public synchronized void setEmail(String email) {
Expand Down Expand Up @@ -214,7 +214,7 @@ public synchronized void setSaveStumbleLogs(boolean state) {
///

protected String getStringPref(String key) {
return getPrefs().getString(key, null);
return getPrefs().getString(key, "");
}

protected boolean getBoolPrefWithDefault(String key, boolean def) {
Expand Down Expand Up @@ -353,9 +353,9 @@ public void setBearerToken(String bearerToken) {

public String getBearerToken() {
String bearerToken = getStringPref(FXA_LOGIN_PREF);
if (bearerToken != null) {
if (!TextUtils.isEmpty(bearerToken)) {
bearerToken = bearerToken.trim();
}
return TextUtils.isEmpty(bearerToken) ? null : bearerToken;
return TextUtils.isEmpty(bearerToken) ? "" : bearerToken;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

package org.mozilla.mozstumbler.service.uploadthread;

import android.text.TextUtils;

public class AsyncUploadParam {

final boolean useWifiOnly;
Expand All @@ -16,11 +18,11 @@ public AsyncUploadParam(boolean wifiOnly,
String nick,
String email) {

if (email == null) {
if (TextUtils.isEmpty(email)) {
email = "";
}

if (nick == null) {
if (TextUtils.isEmpty(nick)) {
nick = "";
}

Expand Down

0 comments on commit 37f8036

Please sign in to comment.