Skip to content

Commit

Permalink
Merge pull request #159 from maniac103/for-upstream
Browse files Browse the repository at this point in the history
More fixes
  • Loading branch information
slapperwan committed Mar 4, 2014
2 parents 00e67a5 + cc8c1b6 commit 8101b90
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 31 deletions.
5 changes: 4 additions & 1 deletion src/com/gh4a/activities/RepositoryActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ public void onResultReady(LoaderResult<Repository> result) {
boolean success = !result.handleError(RepositoryActivity.this);
if (success) {
mRepository = result.getData();
setTabsEnabled(true);
updateTitle();
setTabsEnabled(true);
}
setContentEmpty(!success);
setContentShown(true);
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -469,6 +471,7 @@ public void onClick(DialogInterface dialog, int which) {
}

private void refreshFragment() {
mRepositoryFragment = null;
mContentListFragment = null;
mCommitListFragment = null;
mGitModuleMap = null;
Expand Down
11 changes: 8 additions & 3 deletions src/com/gh4a/adapter/CommonFeedAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
Expand Down
22 changes: 20 additions & 2 deletions src/com/gh4a/feeds/FeedHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -93,4 +95,20 @@ public void endElement(String uri, String localName, String qName) throws SAXExc
public List<Feed> 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;
}
}
9 changes: 7 additions & 2 deletions src/com/gh4a/holder/Feed.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class Feed {
private String preview;
private String author;
private String gravatarId;
private String gravatarUrl;

public String getId() {
return id;
Expand Down Expand Up @@ -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;
}
}
11 changes: 8 additions & 3 deletions src/com/gh4a/utils/GravatarHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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<ImageView>();
request.views.add(view);
sRequests.put(requestId, request);
Expand Down Expand Up @@ -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";
}
}
20 changes: 0 additions & 20 deletions src/com/gh4a/utils/GravatarUtils.java

This file was deleted.

0 comments on commit 8101b90

Please sign in to comment.