use of com.meisolsson.githubsdk.model.User in project PocketHub by pockethub.
the class AvatarLoader method bind.
/**
* Sets the logo on the {@link ActionBar} to the user's avatar.
*
* @param actionBar An ActionBar object on which you're placing the user's avatar.
* @param userReference An AtomicReference that points to the desired user.
* @return this helper
*/
public void bind(final ActionBar actionBar, final AtomicReference<User> userReference) {
if (userReference == null) {
return;
}
final User user = userReference.get();
if (user == null) {
return;
}
String avatarUrl = user.avatarUrl();
if (TextUtils.isEmpty(avatarUrl)) {
return;
}
// Remove the URL params as they are not needed and break cache
if (avatarUrl.contains("?") && !avatarUrl.contains("gravatar")) {
avatarUrl = avatarUrl.substring(0, avatarUrl.indexOf("?"));
}
final String url = avatarUrl;
new FetchAvatarTask(context) {
@Override
public BitmapDrawable call() throws Exception {
Bitmap image = Bitmap.createScaledBitmap(p.load(url).get(), avatarSize, avatarSize, false);
return new BitmapDrawable(context.getResources(), ImageUtils.roundCorners(image, cornerRadius));
}
@Override
protected void onSuccess(BitmapDrawable image) throws Exception {
// compute inset in pixels
int insetPx = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, context.getResources().getDisplayMetrics());
actionBar.setLogo(new InsetDrawable(image, 0, 0, insetPx, 0));
}
}.execute();
}
use of com.meisolsson.githubsdk.model.User in project PocketHub by pockethub.
the class ConvertUtilsTest method setup.
@Before
public void setup() {
User user = User.builder().login(REPO_OWNER_LOGIN).build();
repo = Repository.builder().name(REPO_NAME).owner(user).build();
}
use of com.meisolsson.githubsdk.model.User in project PocketHub by pockethub.
the class CommitUtils method getAuthor.
/**
* Get author of commit
* <p>
* This checks both the {@link Commit} and the underlying
* {@link Commit} to retrieve a name
*
* @param commit
* @return author name or null if missing
*/
public static String getAuthor(final Commit commit) {
User author = commit.author();
if (author != null) {
return author.login();
}
GitCommit rawCommit = commit.commit();
if (rawCommit == null) {
return null;
}
GitUser commitAuthor = rawCommit.author();
return commitAuthor != null ? commitAuthor.name() : null;
}
use of com.meisolsson.githubsdk.model.User in project PocketHub by pockethub.
the class NewsFragment method onListItemLongClick.
@Override
public boolean onListItemLongClick(ListView l, View v, int position, long itemId) {
if (!isUsable()) {
return false;
}
final GitHubEvent event = (GitHubEvent) l.getItemAtPosition(position);
final Repository repo = ConvertUtils.eventRepoToRepo(event.repo());
final User user = event.actor();
if (repo != null && user != null) {
final MaterialDialog.Builder builder = new MaterialDialog.Builder(getActivity()).title(R.string.navigate_to);
// Hacky but necessary since material dialogs has a different API
final MaterialDialog[] dialogHolder = new MaterialDialog[1];
View view = getActivity().getLayoutInflater().inflate(R.layout.nav_dialog, null);
ViewFinder finder = new ViewFinder(view);
avatars.bind(finder.imageView(R.id.iv_user_avatar), user);
avatars.bind(finder.imageView(R.id.iv_repo_avatar), repo.owner());
finder.setText(R.id.tv_login, user.login());
finder.setText(R.id.tv_repo_name, InfoUtils.createRepoId(repo));
finder.onClick(R.id.ll_user_area, new OnClickListener() {
@Override
public void onClick(View v) {
dialogHolder[0].dismiss();
viewUser(user);
}
});
finder.onClick(R.id.ll_repo_area, new OnClickListener() {
@Override
public void onClick(View v) {
dialogHolder[0].dismiss();
viewRepository(repo);
}
});
builder.customView(view, false);
MaterialDialog dialog = builder.build();
dialogHolder[0] = dialog;
dialog.setCanceledOnTouchOutside(true);
dialog.show();
return true;
}
return false;
}
use of com.meisolsson.githubsdk.model.User in project PocketHub by pockethub.
the class Organizations method store.
@Override
public void store(SQLiteDatabase db, List<User> orgs) {
db.delete("orgs", null, null);
if (orgs.isEmpty()) {
return;
}
ContentValues values = new ContentValues(3);
for (User user : orgs) {
values.clear();
values.put("id", user.id());
db.replace("orgs", null, values);
values.put("name", user.login());
values.put("avatarurl", user.avatarUrl());
db.replace("users", null, values);
}
}
Aggregations