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;
}
}
}
}
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;
}
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);
}
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);
}
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);
}
}
Aggregations