diff --git a/src/com/gh4a/activities/RepositoryActivity.java b/src/com/gh4a/activities/RepositoryActivity.java index fb88b53af..2940d94af 100644 --- a/src/com/gh4a/activities/RepositoryActivity.java +++ b/src/com/gh4a/activities/RepositoryActivity.java @@ -74,8 +74,8 @@ public void onResultReady(LoaderResult result) { boolean success = !result.handleError(RepositoryActivity.this); if (success) { mRepository = result.getData(); - setTabsEnabled(true); updateTitle(); + setTabsEnabled(true); } setContentEmpty(!success); setContentShown(true); @@ -261,6 +261,8 @@ protected boolean fragmentNeedsRefresh(Fragment fragment) { } } else if (fragment instanceof CommitListFragment && mCommitListFragment == null) { return true; + } else if (fragment instanceof RepositoryFragment && mRepositoryFragment == null) { + return true; } return false; } @@ -469,6 +471,7 @@ public void onClick(DialogInterface dialog, int which) { } private void refreshFragment() { + mRepositoryFragment = null; mContentListFragment = null; mCommitListFragment = null; mGitModuleMap = null; diff --git a/src/com/gh4a/adapter/CommonFeedAdapter.java b/src/com/gh4a/adapter/CommonFeedAdapter.java index 95374b96a..0989231e7 100644 --- a/src/com/gh4a/adapter/CommonFeedAdapter.java +++ b/src/com/gh4a/adapter/CommonFeedAdapter.java @@ -17,6 +17,7 @@ import android.content.Context; import android.graphics.Typeface; +import android.text.TextUtils; import android.text.format.DateFormat; import android.view.Gravity; import android.view.LayoutInflater; @@ -76,18 +77,22 @@ protected void bindView(View v, Feed feed) { viewHolder.tvDesc.setText(feed.getPreview()); viewHolder.tvDesc.setGravity(mShowExtra ? Gravity.TOP : Gravity.CENTER_VERTICAL); - if (mShowExtra) { - GravatarHandler.assignGravatar(viewHolder.ivGravatar, feed.getGravatarId()); + if (mShowExtra && !TextUtils.isEmpty(feed.getGravatarId())) { + GravatarHandler.assignGravatar(viewHolder.ivGravatar, + feed.getGravatarId(), feed.getGravatarUrl()); viewHolder.ivGravatar.setTag(feed); viewHolder.ivGravatar.setVisibility(View.VISIBLE); + } else { + viewHolder.ivGravatar.setVisibility(View.GONE); + } + if (mShowExtra) { String published = feed.getPublished() != null ? DateFormat.getMediumDateFormat(mContext).format(feed.getPublished()) : ""; viewHolder.tvExtra.setText(mContext.getString(R.string.feed_extradata, feed.getAuthor(), published)); viewHolder.tvExtra.setVisibility(View.VISIBLE); } else { - viewHolder.ivGravatar.setVisibility(View.GONE); viewHolder.tvExtra.setVisibility(View.GONE); } } diff --git a/src/com/gh4a/feeds/FeedHandler.java b/src/com/gh4a/feeds/FeedHandler.java index 4b03caaa5..767f7d6c8 100644 --- a/src/com/gh4a/feeds/FeedHandler.java +++ b/src/com/gh4a/feeds/FeedHandler.java @@ -10,8 +10,10 @@ import org.xml.sax.SAXException; import org.xml.sax.helpers.DefaultHandler; +import android.net.Uri; +import android.text.TextUtils; + import com.gh4a.holder.Feed; -import com.gh4a.utils.GravatarUtils; public class FeedHandler extends DefaultHandler { @@ -49,7 +51,7 @@ public void startElement(String uri, String localName, String qName, Attributes } else if (localName.equalsIgnoreCase("thumbnail")) { String gravatarUrl = attributes.getValue("url"); if (gravatarUrl != null) { - mFeed.setGravatarId(GravatarUtils.extractGravatarId(gravatarUrl)); + mFeed.setGravatar(extractGravatarId(gravatarUrl), gravatarUrl); } } else if (localName.equalsIgnoreCase("link")) { String url = attributes.getValue("href"); @@ -93,4 +95,20 @@ public void endElement(String uri, String localName, String qName) throws SAXExc public List getFeeds() { return mFeeds; } + + private static String extractGravatarId(String url) { + Uri uri = Uri.parse(url); + String idParam = uri.getQueryParameter("gravatar_id"); + if (idParam != null) { + return idParam; + } + // Construct fake IDs for github's own avatars, they're only used + // for identification purposes in GravatarHandler + if (TextUtils.equals(uri.getHost(), "avatars.githubusercontent.com")) { + if (uri.getPathSegments().size() == 2) { + return "github_" + uri.getLastPathSegment(); + } + } + return null; + } } diff --git a/src/com/gh4a/holder/Feed.java b/src/com/gh4a/holder/Feed.java index 68c1777b0..cf0070fb8 100644 --- a/src/com/gh4a/holder/Feed.java +++ b/src/com/gh4a/holder/Feed.java @@ -28,6 +28,7 @@ public class Feed { private String preview; private String author; private String gravatarId; + private String gravatarUrl; public String getId() { return id; @@ -86,7 +87,11 @@ public void setAuthor(String author) { public String getGravatarId() { return gravatarId; } - public void setGravatarId(String gravatarId) { - this.gravatarId = gravatarId; + public String getGravatarUrl() { + return gravatarUrl; + } + public void setGravatar(String id, String url) { + this.gravatarId = id; + this.gravatarUrl = url; } } diff --git a/src/com/gh4a/utils/GravatarHandler.java b/src/com/gh4a/utils/GravatarHandler.java index 5986e14e5..5c782d890 100644 --- a/src/com/gh4a/utils/GravatarHandler.java +++ b/src/com/gh4a/utils/GravatarHandler.java @@ -88,7 +88,6 @@ private void processResult(int requestId, Bitmap bitmap) { } }; - public static void assignGravatar(ImageView view, User user) { if (user == null) { assignGravatar(view, null, null); @@ -135,7 +134,7 @@ public static void assignGravatar(ImageView view, String gravatarId, String url) int requestId = sNextRequestId++; request = new Request(); request.id = gravatarId; - request.url = TextUtils.isEmpty(url) ? GravatarUtils.getGravatarUrl(gravatarId) : url; + request.url = TextUtils.isEmpty(url) ? getGravatarUrl(gravatarId) : url; request.views = new ArrayList(); request.views.add(view); sRequests.put(requestId, request); @@ -241,13 +240,19 @@ public void handleMessage(Message msg) { Bitmap bitmap = null; try { bitmap = fetchBitmap(url); - bitmap = getRoundedCornerResizedBitmap(bitmap); } catch (IOException e) { Log.e(TAG, "Couldn't fetch gravatar from URL " + url, e); } + if (bitmap != null) { + bitmap = getRoundedCornerResizedBitmap(bitmap); + } sHandler.obtainMessage(MSG_LOADED, msg.arg1, 0, bitmap).sendToTarget(); break; } } } + + private static String getGravatarUrl(String gravatarId) { + return "http://www.gravatar.com/avatar.php?gravatar_id=" + gravatarId + "&size=60&d=mm"; + } } \ No newline at end of file diff --git a/src/com/gh4a/utils/GravatarUtils.java b/src/com/gh4a/utils/GravatarUtils.java deleted file mode 100644 index 63741b5bd..000000000 --- a/src/com/gh4a/utils/GravatarUtils.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.gh4a.utils; - -public class GravatarUtils { - - public static String getGravatarUrl(String gravatarId) { - return "http://www.gravatar.com/avatar.php?gravatar_id=" + gravatarId + "&size=60&d=mm"; - } - - public static String extractGravatarId(String url) { - String[] urlParts = url.split("/"); - if (urlParts.length >= 5) { - int pos = urlParts[4].indexOf('?'); - if (pos < 0) { - return urlParts[4]; - } - return urlParts[4].substring(0, pos); - } - return null; - } -}