Search in sources :

Example 51 with User

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();
}
Also used : Bitmap(android.graphics.Bitmap) User(com.meisolsson.githubsdk.model.User) InsetDrawable(android.graphics.drawable.InsetDrawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) IOException(java.io.IOException)

Example 52 with User

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();
}
Also used : User(com.meisolsson.githubsdk.model.User) Before(org.junit.Before)

Example 53 with User

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;
}
Also used : GitUser(com.meisolsson.githubsdk.model.git.GitUser) User(com.meisolsson.githubsdk.model.User) GitCommit(com.meisolsson.githubsdk.model.git.GitCommit) GitUser(com.meisolsson.githubsdk.model.git.GitUser)

Example 54 with User

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;
}
Also used : Repository(com.meisolsson.githubsdk.model.Repository) User(com.meisolsson.githubsdk.model.User) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) ViewFinder(com.github.kevinsawicki.wishlist.ViewFinder) OnClickListener(android.view.View.OnClickListener) GitHubEvent(com.meisolsson.githubsdk.model.GitHubEvent) View(android.view.View) ListView(android.widget.ListView)

Example 55 with User

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);
    }
}
Also used : ContentValues(android.content.ContentValues) User(com.meisolsson.githubsdk.model.User)

Aggregations

User (com.meisolsson.githubsdk.model.User)97 Repository (com.meisolsson.githubsdk.model.Repository)15 View (android.view.View)14 Intent (android.content.Intent)13 TextView (android.widget.TextView)11 ImageView (android.widget.ImageView)10 ArrayList (java.util.ArrayList)10 Test (org.junit.Test)10 Label (com.meisolsson.githubsdk.model.Label)9 Milestone (com.meisolsson.githubsdk.model.Milestone)8 Bundle (android.os.Bundle)7 ApiHelpers (com.gh4a.utils.ApiHelpers)7 GitHubEvent (com.meisolsson.githubsdk.model.GitHubEvent)7 UserService (com.meisolsson.githubsdk.service.users.UserService)7 SmallTest (androidx.test.filters.SmallTest)6 List (java.util.List)6 ViewGroup (android.view.ViewGroup)5 AvatarHandler (com.gh4a.utils.AvatarHandler)5 UiUtils (com.gh4a.utils.UiUtils)5 Issue (com.meisolsson.githubsdk.model.Issue)5