Search in sources :

Example 21 with Repository

use of com.meisolsson.githubsdk.model.Repository in project gh4a by slapperwan.

the class NotificationListFragment method scrollToInitialNotification.

private void scrollToInitialNotification(List<NotificationHolder> notifications) {
    Bundle extras = getActivity().getIntent().getExtras();
    if (extras == null) {
        return;
    }
    String repoOwner = extras.getString(EXTRA_INITIAL_REPO_OWNER);
    String repoName = extras.getString(EXTRA_INITIAL_REPO_NAME);
    extras.remove(EXTRA_INITIAL_REPO_OWNER);
    extras.remove(EXTRA_INITIAL_REPO_NAME);
    if (repoOwner == null || repoName == null) {
        return;
    }
    for (int i = 0; i < notifications.size(); i++) {
        NotificationHolder holder = notifications.get(i);
        if (holder.notification == null) {
            Repository repo = holder.repository;
            if (repoOwner.equals(repo.owner().login()) && repoName.equals(repo.name())) {
                scrollToAndHighlightPosition(i);
                break;
            }
        }
    }
}
Also used : Repository(com.meisolsson.githubsdk.model.Repository) Bundle(android.os.Bundle) NotificationHolder(com.gh4a.model.NotificationHolder)

Example 22 with Repository

use of com.meisolsson.githubsdk.model.Repository in project gh4a by slapperwan.

the class PullRequestFragment method newInstance.

public static PullRequestFragment newInstance(PullRequest pr, Issue issue, boolean isCollaborator, IntentUtils.InitialCommentMarker initialComment) {
    PullRequestFragment f = new PullRequestFragment();
    Repository repo = pr.base().repo();
    Bundle args = buildArgs(repo.owner().login(), repo.name(), issue, isCollaborator, initialComment);
    args.putParcelable("pr", pr);
    f.setArguments(args);
    return f;
}
Also used : Repository(com.meisolsson.githubsdk.model.Repository) Bundle(android.os.Bundle)

Example 23 with Repository

use of com.meisolsson.githubsdk.model.Repository in project gh4a by slapperwan.

the class NotificationAdapter method onBindViewHolder.

@Override
protected void onBindViewHolder(ViewHolder holder, NotificationHolder item) {
    holder.ivAction.setTag(item);
    float alpha = item.isRead() ? 0.5f : 1f;
    holder.tvTitle.setAlpha(alpha);
    if (item.notification == null) {
        holder.ivAction.setVisibility(item.isRead() ? View.GONE : View.VISIBLE);
        Repository repository = item.repository;
        holder.tvTitle.setText(repository.owner().login() + "/" + repository.name());
        User owner = item.repository.owner();
        AvatarHandler.assignAvatar(holder.ivAvatar, owner);
        holder.ivAvatar.setTag(owner);
        holder.ivAvatar.setAlpha(alpha);
        return;
    }
    holder.ivIcon.setAlpha(alpha);
    holder.tvTimestamp.setAlpha(alpha);
    holder.mPopupMenu.getMenu().findItem(R.id.mark_as_read).setVisible(!item.isRead());
    NotificationSubject subject = item.notification.subject();
    int iconResId = getIconResId(subject.type());
    if (iconResId > 0) {
        holder.ivIcon.setImageResource(iconResId);
        holder.ivIcon.setVisibility(View.VISIBLE);
    } else {
        holder.ivIcon.setVisibility(View.INVISIBLE);
    }
    holder.tvTitle.setText(subject.title());
    holder.tvTimestamp.setText(StringUtils.formatRelativeTime(mContext, item.notification.updatedAt(), true));
    ViewGroup.MarginLayoutParams layoutParams = (ViewGroup.MarginLayoutParams) holder.vNotificationContent.getLayoutParams();
    int bottomMargin = item.isLastRepositoryNotification() ? mBottomMargin : 0;
    layoutParams.setMargins(0, 0, 0, bottomMargin);
    holder.vNotificationContent.setLayoutParams(layoutParams);
    holder.vBottomShadow.setVisibility(item.isLastRepositoryNotification() ? View.VISIBLE : View.GONE);
}
Also used : Repository(com.meisolsson.githubsdk.model.Repository) User(com.meisolsson.githubsdk.model.User) NotificationSubject(com.meisolsson.githubsdk.model.NotificationSubject) ViewGroup(android.view.ViewGroup)

Example 24 with Repository

use of com.meisolsson.githubsdk.model.Repository in project gh4a by slapperwan.

the class SingleFactory method notificationsToResult.

private static NotificationListLoadResult notificationsToResult(List<NotificationThread> notifications) {
    // group notifications by repo
    final HashMap<Repository, ArrayList<NotificationThread>> notificationsByRepo = new HashMap<>();
    for (NotificationThread n : notifications) {
        ArrayList<NotificationThread> list = notificationsByRepo.get(n.repository());
        if (list == null) {
            list = new ArrayList<>();
            notificationsByRepo.put(n.repository(), list);
        }
        list.add(n);
    }
    // sort each group by updatedAt
    for (ArrayList<NotificationThread> list : notificationsByRepo.values()) {
        Collections.sort(list, (lhs, rhs) -> rhs.updatedAt().compareTo(lhs.updatedAt()));
    }
    // sort groups by updatedAt of top notification
    ArrayList<Repository> reposByTimestamp = new ArrayList<>(notificationsByRepo.keySet());
    Collections.sort(reposByTimestamp, (lhs, rhs) -> {
        NotificationThread lhsNotification = notificationsByRepo.get(lhs).get(0);
        NotificationThread rhsNotification = notificationsByRepo.get(rhs).get(0);
        return rhsNotification.updatedAt().compareTo(lhsNotification.updatedAt());
    });
    // add to list
    List<NotificationHolder> result = new ArrayList<>();
    for (Repository repo : reposByTimestamp) {
        ArrayList<NotificationThread> notifsForRepo = notificationsByRepo.get(repo);
        boolean hasUnread = false;
        int count = notifsForRepo.size();
        NotificationHolder repoItem = new NotificationHolder(repo);
        result.add(repoItem);
        for (int i = 0; i < count; i++) {
            NotificationHolder item = new NotificationHolder(notifsForRepo.get(i));
            hasUnread |= item.notification.unread();
            item.setIsLastRepositoryNotification(i == count - 1);
            result.add(item);
        }
        repoItem.setIsRead(!hasUnread);
    }
    return new NotificationListLoadResult(result);
}
Also used : NotificationThread(com.meisolsson.githubsdk.model.NotificationThread) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) NotificationHolder(com.gh4a.model.NotificationHolder) Repository(com.meisolsson.githubsdk.model.Repository) NotificationListLoadResult(com.gh4a.model.NotificationListLoadResult)

Example 25 with Repository

use of com.meisolsson.githubsdk.model.Repository in project gh4a by slapperwan.

the class RepositoryListContainerFragment method onActivityCreated.

@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    FragmentManager fm = getChildFragmentManager();
    mMainFragment = (PagedDataBaseFragment<Repository>) fm.findFragmentByTag("main");
    mSearchFragment = (RepositorySearchFragment) fm.findFragmentByTag("search");
    if (mMainFragment == null) {
        applyFilterTypeAndSortOrder();
        addSearchFragment();
    } else {
        setSearchVisibility(mSearchVisible);
    }
}
Also used : FragmentManager(android.support.v4.app.FragmentManager) Repository(com.meisolsson.githubsdk.model.Repository)

Aggregations

Repository (com.meisolsson.githubsdk.model.Repository)68 User (com.meisolsson.githubsdk.model.User)18 GitHubEvent (com.meisolsson.githubsdk.model.GitHubEvent)9 Issue (com.meisolsson.githubsdk.model.Issue)9 Intent (android.content.Intent)8 View (android.view.View)8 TextView (android.widget.TextView)6 Bundle (android.os.Bundle)5 ImageView (android.widget.ImageView)5 LayoutInflater (android.view.LayoutInflater)4 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)4 Test (org.junit.Test)4 Uri (android.net.Uri)3 Menu (android.view.Menu)3 ViewGroup (android.view.ViewGroup)3 LinearLayout (android.widget.LinearLayout)3 R (com.gh4a.R)3 RepositoryActivity (com.gh4a.activities.RepositoryActivity)3 UserActivity (com.gh4a.activities.UserActivity)3 ApiHelpers (com.gh4a.utils.ApiHelpers)3