Skip to content

Commit

Permalink
Merge pull request #1765 from wordpress-mobile/issue/1762-share-inten…
Browse files Browse the repository at this point in the history
…t-empty-string-blog-title

fix #1762 show blog url in the share blog spinner if the blog title is an empty string
  • Loading branch information
nbradbury committed Aug 21, 2014
2 parents ecd3b24 + 753a40a commit 1886e15
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import org.wordpress.android.ui.accounts.WelcomeActivity;
import org.wordpress.android.ui.media.MediaBrowserActivity;
import org.wordpress.android.ui.posts.EditPostActivity;
import org.wordpress.android.util.StringUtils;
import org.wordpress.android.util.BlogUtils;
import org.wordpress.android.util.ToastUtils;

import java.util.ArrayList;
Expand Down Expand Up @@ -162,13 +162,9 @@ private String[] getBlogNames() {
mAccountIDs = new int[accounts.size()];
Blog blog;
for (int i = 0; i < accounts.size(); i++) {
Map<String, Object> curHash = accounts.get(i);
try {
blogNames[i] = StringUtils.unescapeHTML(curHash.get("blogName").toString());
} catch (Exception e) {
blogNames[i] = curHash.get("url").toString();
}
mAccountIDs[i] = (Integer) curHash.get("id");
Map<String, Object> account = accounts.get(i);
blogNames[i] = BlogUtils.getBlogNameFromAccountMap(account);
mAccountIDs[i] = (Integer) account.get("id");
blog = WordPress.wpDB.instantiateBlogByLocalId(mAccountIDs[i]);
if (blog == null) {
ToastUtils.showToast(this, R.string.blog_not_found, ToastUtils.Duration.SHORT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,11 @@
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.preference.PreferenceManager;
import android.support.v4.content.LocalBroadcastManager;
import android.view.LayoutInflater;
import android.view.MenuItem;
Expand All @@ -41,12 +39,14 @@
import org.wordpress.android.Constants;
import org.wordpress.android.R;
import org.wordpress.android.WordPress;
import org.wordpress.android.analytics.AnalyticsTracker;
import org.wordpress.android.models.Blog;
import org.wordpress.android.networking.SelfSignedSSLCertsManager;
import org.wordpress.android.ui.accounts.WelcomeActivity;
import org.wordpress.android.ui.comments.CommentsActivity;
import org.wordpress.android.ui.media.MediaBrowserActivity;
import org.wordpress.android.ui.notifications.NotificationsActivity;
import org.wordpress.android.ui.notifications.SimperiumUtils;
import org.wordpress.android.ui.posts.EditPostActivity;
import org.wordpress.android.ui.posts.PagesActivity;
import org.wordpress.android.ui.posts.PostsActivity;
Expand All @@ -57,13 +57,11 @@
import org.wordpress.android.util.AppLog;
import org.wordpress.android.util.AppLog.T;
import org.wordpress.android.util.AuthenticationDialogUtils;
import org.wordpress.android.util.BlogUtils;
import org.wordpress.android.util.DeviceUtils;
import org.wordpress.android.util.DisplayUtils;
import org.wordpress.android.ui.notifications.SimperiumUtils;
import org.wordpress.android.util.StringUtils;
import org.wordpress.android.util.ToastUtils;
import org.wordpress.android.util.ToastUtils.Duration;
import org.wordpress.android.analytics.AnalyticsTracker;
import org.wordpress.android.util.ptr.PullToRefreshHelper;
import org.xmlrpc.android.ApiHelper;
import org.xmlrpc.android.ApiHelper.ErrorType;
Expand Down Expand Up @@ -531,16 +529,7 @@ protected static String[] getBlogNames() {

for (int i = 0; i < blogCount; i++) {
Map<String, Object> account = accounts.get(i);
String name;
if (account.get("blogName") != null) {
name = StringUtils.unescapeHTML(account.get("blogName").toString());
if (name.trim().length() == 0) {
name = StringUtils.getHost(account.get("url").toString());
}
} else {
name = StringUtils.getHost(account.get("url").toString());
}
blogNames[i] = name;
blogNames[i] = BlogUtils.getBlogNameFromAccountMap(account);
blogIDs[i] = Integer.valueOf(account.get("id").toString());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
import org.wordpress.android.R;
import org.wordpress.android.WordPress;
import org.wordpress.android.networking.NetworkUtils;
import org.wordpress.android.util.BlogUtils;
import org.wordpress.android.util.ListScrollPositionManager;
import org.wordpress.android.util.MapUtils;
import org.wordpress.android.util.StringUtils;
import org.wordpress.android.util.ToastUtils;
import org.wordpress.android.util.ptr.PullToRefreshHelper;
import org.wordpress.android.util.ptr.PullToRefreshHelper.RefreshListener;
Expand Down Expand Up @@ -148,12 +148,7 @@ public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rowView = inflater.inflate(mResource, parent, false);
CheckedTextView nameView = (CheckedTextView) rowView.findViewById(R.id.blog_name);
String name = StringUtils.unescapeHTML(MapUtils.getMapStr(getItem(position), "blogName"));
if (name.trim().length() == 0) {
name = MapUtils.getMapStr(getItem(position), "url");
name = StringUtils.getHost(name);
}
nameView.setText(name);
nameView.setText(BlogUtils.getBlogNameFromAccountMap(getItem(position)));
nameView.setChecked(!MapUtils.getMapBool(getItem(position), "isHidden"));
return rowView;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import android.content.Context;
import android.os.AsyncTask;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
Expand All @@ -13,8 +12,8 @@
import org.wordpress.android.R;
import org.wordpress.android.WordPress;
import org.wordpress.android.ui.reader.actions.ReaderActions.DataLoadedListener;
import org.wordpress.android.util.BlogUtils;
import org.wordpress.android.util.DisplayUtils;
import org.wordpress.android.util.StringUtils;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -159,11 +158,7 @@ protected Boolean doInBackground(Void... voids) {
// don't add if this is the blog we're excluding (prevents reblogging to
// the same blog the post is from)
if (blogId != mExcludeBlogId) {
String blogName = StringUtils.unescapeHTML(curHash.get("blogName").toString());
if (TextUtils.isEmpty(blogName)) {
blogName = curHash.get("url").toString();
}

String blogName = BlogUtils.getBlogNameFromAccountMap(curHash);
SimpleAccountItem item = new SimpleAccountItem(blogId, blogName);

// if this is the current blog, insert it at the top so it's automatically selected
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,15 @@ public int compare(Object blog1, Object blog2) {
return blogName1.compareToIgnoreCase(blogName2);
}
};

/**
* Return a blog name or blog url (host part only) if trimmed name is an empty string
*/
public static String getBlogNameFromAccountMap(Map<String, Object> account) {
String blogName = StringUtils.unescapeHTML(MapUtils.getMapStr(account, "blogName"));
if (blogName.trim().length() == 0) {
blogName = StringUtils.getHost(MapUtils.getMapStr(account, "url"));
}
return blogName;
}
}

0 comments on commit 1886e15

Please sign in to comment.