Search in sources :

Example 56 with Repository

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

the class PullRequestFragment method loadHeadReference.

private void loadHeadReference(boolean force) {
    GitService service = ServiceFactory.get(GitService.class, force);
    PullRequestMarker head = mPullRequest.head();
    Repository repo = head.repo();
    Single<Optional<GitReference>> refSingle = repo == null ? Single.just(Optional.absent()) : service.getGitReference(repo.owner().login(), repo.name(), head.ref()).map(ApiHelpers::throwOnFailure).map(Optional::of).compose(RxUtils.mapFailureToValue(HttpURLConnection.HTTP_NOT_FOUND, Optional.<GitReference>absent())).compose(makeLoaderSingle(ID_LOADER_HEAD_REF, force));
    refSingle.subscribe(refOpt -> {
        mHeadReference = refOpt.orNull();
        mHasLoadedHeadReference = true;
        getActivity().invalidateOptionsMenu();
        bindSpecialViews(mListHeaderView);
    }, this::handleLoadFailure);
}
Also used : Repository(com.meisolsson.githubsdk.model.Repository) Optional(com.gh4a.utils.Optional) GitService(com.meisolsson.githubsdk.service.git.GitService) ApiHelpers(com.gh4a.utils.ApiHelpers) PullRequestMarker(com.meisolsson.githubsdk.model.PullRequestMarker) GitReference(com.meisolsson.githubsdk.model.git.GitReference) CreateGitReference(com.meisolsson.githubsdk.model.request.git.CreateGitReference)

Example 57 with Repository

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

the class EventListFragment method onItemClick.

@Override
public void onItemClick(GitHubEvent event) {
    if (EventAdapter.hasInvalidPayload(event)) {
        return;
    }
    GitHubEvent.RepoIdentifier eventRepo = event.repo();
    String repoOwner = "";
    String repoName = "";
    Intent intent = null;
    Single<Optional<Intent>> intentSingle = null;
    if (eventRepo != null) {
        String[] repoNamePart = eventRepo.repoWithUserName().split("/");
        if (repoNamePart.length == 2) {
            repoOwner = repoNamePart[0];
            repoName = repoNamePart[1];
        }
    }
    if (Arrays.binarySearch(REPO_EVENTS, event.type()) >= 0 && eventRepo == null) {
        Toast.makeText(getActivity(), R.string.repo_not_found_toast, Toast.LENGTH_LONG).show();
        return;
    }
    switch(event.type()) {
        case CommitCommentEvent:
            {
                CommitCommentPayload payload = (CommitCommentPayload) event.payload();
                GitComment comment = payload.comment();
                if (comment != null) {
                    intentSingle = CommitCommentLoadTask.load(getActivity(), repoOwner, repoName, comment.commitId(), new IntentUtils.InitialCommentMarker(comment.id()));
                }
                break;
            }
        case CreateEvent:
            {
                CreatePayload payload = (CreatePayload) event.payload();
                String ref = null;
                if (payload.refType() == ReferenceType.Branch || payload.refType() == ReferenceType.Tag) {
                    ref = payload.ref();
                }
                intent = RepositoryActivity.makeIntent(getActivity(), repoOwner, repoName, ref);
                break;
            }
        case DeleteEvent:
            intent = RepositoryActivity.makeIntent(getActivity(), repoOwner, repoName);
            break;
        case DownloadEvent:
            {
                DownloadPayload payload = (DownloadPayload) event.payload();
                Download download = payload.download();
                UiUtils.enqueueDownloadWithPermissionCheck((BaseActivity) getActivity(), download.htmlUrl(), download.contentType(), download.name(), download.description(), null);
                break;
            }
        case FollowEvent:
            {
                FollowPayload payload = (FollowPayload) event.payload();
                intent = UserActivity.makeIntent(getActivity(), payload.target());
                break;
            }
        case ForkEvent:
            {
                ForkPayload payload = (ForkPayload) event.payload();
                Repository forkee = payload.forkee();
                if (forkee != null) {
                    intent = RepositoryActivity.makeIntent(getActivity(), forkee);
                } else {
                    Toast.makeText(getActivity(), R.string.repo_not_found_toast, Toast.LENGTH_LONG).show();
                }
                break;
            }
        case ForkApplyEvent:
            intent = RepositoryActivity.makeIntent(getActivity(), repoOwner, repoName);
            break;
        case GistEvent:
            {
                GistPayload payload = (GistPayload) event.payload();
                intent = GistActivity.makeIntent(getActivity(), payload.gist().id());
                break;
            }
        case GollumEvent:
            {
                GollumPayload payload = (GollumPayload) event.payload();
                intent = WikiListActivity.makeIntent(getActivity(), repoOwner, repoName, payload.pages().isEmpty() ? null : payload.pages().get(0));
                break;
            }
        case IssueCommentEvent:
            {
                IssueCommentPayload payload = (IssueCommentPayload) event.payload();
                Issue issue = payload.issue();
                PullRequest request = issue != null ? issue.pullRequest() : null;
                IntentUtils.InitialCommentMarker initialComment = payload.comment() != null ? new IntentUtils.InitialCommentMarker(payload.comment().id()) : null;
                if (request != null && request.htmlUrl() != null) {
                    intent = PullRequestActivity.makeIntent(getActivity(), repoOwner, repoName, issue.number(), initialComment != null ? PullRequestActivity.PAGE_CONVERSATION : -1, initialComment);
                } else if (issue != null) {
                    intent = IssueActivity.makeIntent(getActivity(), repoOwner, repoName, issue.number(), initialComment);
                }
                break;
            }
        case IssuesEvent:
            {
                IssuesPayload payload = (IssuesPayload) event.payload();
                startActivity(IssueActivity.makeIntent(getActivity(), repoOwner, repoName, payload.issue().number()));
                break;
            }
        case MemberEvent:
            intent = RepositoryActivity.makeIntent(getActivity(), repoOwner, repoName);
            break;
        case PublicEvent:
            intent = RepositoryActivity.makeIntent(getActivity(), repoOwner, repoName);
            break;
        case PullRequestEvent:
            {
                PullRequestPayload payload = (PullRequestPayload) event.payload();
                intent = PullRequestActivity.makeIntent(getActivity(), repoOwner, repoName, payload.number());
                break;
            }
        case PullRequestReviewCommentEvent:
            {
                PullRequestReviewCommentPayload payload = (PullRequestReviewCommentPayload) event.payload();
                PullRequest pr = payload.pullRequest();
                ReviewComment comment = payload.comment();
                IntentUtils.InitialCommentMarker initialComment = comment != null ? new IntentUtils.InitialCommentMarker(comment.id()) : null;
                if (pr != null) {
                    if (initialComment != null) {
                        intentSingle = PullRequestReviewCommentLoadTask.load(getActivity(), repoOwner, repoName, pr.number(), initialComment);
                    } else {
                        intent = PullRequestActivity.makeIntent(getActivity(), repoOwner, repoName, pr.number(), -1, null);
                    }
                } else if (comment != null) {
                    intent = CommitActivity.makeIntent(getActivity(), repoOwner, repoName, comment.commitId(), initialComment);
                }
                break;
            }
        case PushEvent:
            {
                PushPayload payload = (PushPayload) event.payload();
                List<GitCommit> commits = payload.commits();
                if (commits != null && !commits.isEmpty()) {
                    if (commits.size() > 1) {
                        // if commit > 1, then show compare activity
                        intent = CompareActivity.makeIntent(getActivity(), repoOwner, repoName, payload.before(), payload.head());
                    } else {
                        // only 1 commit, then show the commit details
                        intent = CommitActivity.makeIntent(getActivity(), repoOwner, repoName, commits.get(0).sha());
                    }
                } else {
                    intent = RepositoryActivity.makeIntent(getActivity(), repoOwner, repoName);
                }
                break;
            }
        case ReleaseEvent:
            {
                ReleasePayload payload = (ReleasePayload) event.payload();
                Release release = payload.release();
                if (release != null) {
                    intent = ReleaseInfoActivity.makeIntent(getActivity(), repoOwner, repoName, release.id());
                }
                break;
            }
        case WatchEvent:
            intent = RepositoryActivity.makeIntent(getActivity(), repoOwner, repoName);
            break;
    }
    if (intent != null) {
        startActivity(intent);
    } else if (intentSingle != null) {
        intentSingle.compose(RxUtils::doInBackground).compose(RxUtils.wrapWithProgressDialog(getActivity(), R.string.loading_msg)).subscribe(result -> {
            if (result.isPresent() && isAdded()) {
                startActivity(result.get());
            }
        }, error -> Log.d(Gh4Application.LOG_TAG, "Loading click intent failed", error));
    }
}
Also used : ForkPayload(com.meisolsson.githubsdk.model.payload.ForkPayload) CommitCommentLoadTask(com.gh4a.resolver.CommitCommentLoadTask) CommitCommentPayload(com.meisolsson.githubsdk.model.payload.CommitCommentPayload) Arrays(java.util.Arrays) Uri(android.net.Uri) PullRequest(com.meisolsson.githubsdk.model.PullRequest) UserActivity(com.gh4a.activities.UserActivity) WikiListActivity(com.gh4a.activities.WikiListActivity) EventAdapter(com.gh4a.adapter.EventAdapter) Issue(com.meisolsson.githubsdk.model.Issue) View(android.view.View) PullRequestReviewCommentPayload(com.meisolsson.githubsdk.model.payload.PullRequestReviewCommentPayload) Log(android.util.Log) IntentUtils(com.gh4a.utils.IntentUtils) ReferenceType(com.meisolsson.githubsdk.model.ReferenceType) IssueCommentPayload(com.meisolsson.githubsdk.model.payload.IssueCommentPayload) GistPayload(com.meisolsson.githubsdk.model.payload.GistPayload) IssuesPayload(com.meisolsson.githubsdk.model.payload.IssuesPayload) ReleaseInfoActivity(com.gh4a.activities.ReleaseInfoActivity) GistActivity(com.gh4a.activities.GistActivity) GitCommit(com.meisolsson.githubsdk.model.git.GitCommit) List(java.util.List) RxUtils(com.gh4a.utils.RxUtils) CommitActivity(com.gh4a.activities.CommitActivity) PullRequestPayload(com.meisolsson.githubsdk.model.payload.PullRequestPayload) Optional(com.gh4a.utils.Optional) GitHubEvent(com.meisolsson.githubsdk.model.GitHubEvent) IssueListActivity(com.gh4a.activities.IssueListActivity) Release(com.meisolsson.githubsdk.model.Release) ContextMenu(android.view.ContextMenu) FollowPayload(com.meisolsson.githubsdk.model.payload.FollowPayload) Repository(com.meisolsson.githubsdk.model.Repository) ReleasePayload(com.meisolsson.githubsdk.model.payload.ReleasePayload) ContextMenuInfo(android.view.ContextMenu.ContextMenuInfo) Intent(android.content.Intent) Download(com.meisolsson.githubsdk.model.Download) Single(io.reactivex.Single) PushPayload(com.meisolsson.githubsdk.model.payload.PushPayload) MenuItem(android.view.MenuItem) PullRequestReviewCommentLoadTask(com.gh4a.resolver.PullRequestReviewCommentLoadTask) UiUtils(com.gh4a.utils.UiUtils) User(com.meisolsson.githubsdk.model.User) ContextMenuAwareRecyclerView(com.gh4a.widget.ContextMenuAwareRecyclerView) Toast(android.widget.Toast) Menu(android.view.Menu) R(com.gh4a.R) GollumPayload(com.meisolsson.githubsdk.model.payload.GollumPayload) GitHubWikiPage(com.meisolsson.githubsdk.model.GitHubWikiPage) CompareActivity(com.gh4a.activities.CompareActivity) LayoutInflater(android.view.LayoutInflater) IssueActivity(com.gh4a.activities.IssueActivity) ReviewComment(com.meisolsson.githubsdk.model.ReviewComment) DownloadPayload(com.meisolsson.githubsdk.model.payload.DownloadPayload) PullRequestActivity(com.gh4a.activities.PullRequestActivity) CreatePayload(com.meisolsson.githubsdk.model.payload.CreatePayload) RecyclerView(android.support.v7.widget.RecyclerView) RootAdapter(com.gh4a.adapter.RootAdapter) ReleaseAsset(com.meisolsson.githubsdk.model.ReleaseAsset) GitComment(com.meisolsson.githubsdk.model.git.GitComment) RepositoryActivity(com.gh4a.activities.RepositoryActivity) Gh4Application(com.gh4a.Gh4Application) BaseActivity(com.gh4a.BaseActivity) GitHubEventType(com.meisolsson.githubsdk.model.GitHubEventType) ForkPayload(com.meisolsson.githubsdk.model.payload.ForkPayload) GollumPayload(com.meisolsson.githubsdk.model.payload.GollumPayload) ReleasePayload(com.meisolsson.githubsdk.model.payload.ReleasePayload) FollowPayload(com.meisolsson.githubsdk.model.payload.FollowPayload) Issue(com.meisolsson.githubsdk.model.Issue) PullRequest(com.meisolsson.githubsdk.model.PullRequest) GistPayload(com.meisolsson.githubsdk.model.payload.GistPayload) IssueCommentPayload(com.meisolsson.githubsdk.model.payload.IssueCommentPayload) PullRequestPayload(com.meisolsson.githubsdk.model.payload.PullRequestPayload) List(java.util.List) GitComment(com.meisolsson.githubsdk.model.git.GitComment) Download(com.meisolsson.githubsdk.model.Download) Release(com.meisolsson.githubsdk.model.Release) PushPayload(com.meisolsson.githubsdk.model.payload.PushPayload) Optional(com.gh4a.utils.Optional) ReviewComment(com.meisolsson.githubsdk.model.ReviewComment) IssuesPayload(com.meisolsson.githubsdk.model.payload.IssuesPayload) Intent(android.content.Intent) GitHubEvent(com.meisolsson.githubsdk.model.GitHubEvent) PullRequestReviewCommentPayload(com.meisolsson.githubsdk.model.payload.PullRequestReviewCommentPayload) CommitCommentPayload(com.meisolsson.githubsdk.model.payload.CommitCommentPayload) CreatePayload(com.meisolsson.githubsdk.model.payload.CreatePayload) Repository(com.meisolsson.githubsdk.model.Repository) IntentUtils(com.gh4a.utils.IntentUtils) BaseActivity(com.gh4a.BaseActivity) DownloadPayload(com.meisolsson.githubsdk.model.payload.DownloadPayload)

Example 58 with Repository

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

the class SearchFragment method onItemClick.

@Override
public void onItemClick(Object item) {
    if (item instanceof Repository) {
        Repository repository = (Repository) item;
        startActivity(RepositoryActivity.makeIntent(getActivity(), repository));
    } else if (item instanceof SearchCode) {
        openFileViewer((SearchCode) item, -1);
    } else {
        User user = (User) item;
        startActivity(UserActivity.makeIntent(getActivity(), user));
    }
}
Also used : Repository(com.meisolsson.githubsdk.model.Repository) User(com.meisolsson.githubsdk.model.User) SearchCode(com.meisolsson.githubsdk.model.SearchCode)

Example 59 with Repository

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

the class SearchFragment method makeRepoSearchSingle.

private Single<Response<Page<Object>>> makeRepoSearchSingle(long page, boolean bypassCache) {
    SearchService service = ServiceFactory.get(SearchService.class, bypassCache);
    String params = mQuery + " fork:true";
    return service.searchRepositories(params, null, null, page).compose(result -> RxUtils.<Repository, Object>searchPageAdapter(result, item -> item)).compose(RxUtils.mapFailureToValue(422, Response.success(new ApiHelpers.DummyPage<>())));
}
Also used : SuggestionsProvider(com.gh4a.db.SuggestionsProvider) Context(android.content.Context) FilterQueryProvider(android.widget.FilterQueryProvider) Repository(com.meisolsson.githubsdk.model.Repository) Bundle(android.os.Bundle) FileViewerActivity(com.gh4a.activities.FileViewerActivity) SearchView(android.support.v7.widget.SearchView) Uri(android.net.Uri) ImageView(android.widget.ImageView) StringRes(android.support.annotation.StringRes) Response(retrofit2.Response) Single(io.reactivex.Single) UserActivity(com.gh4a.activities.UserActivity) UiUtils(com.gh4a.utils.UiUtils) SearchCode(com.meisolsson.githubsdk.model.SearchCode) CursorAdapter(android.support.v4.widget.CursorAdapter) User(com.meisolsson.githubsdk.model.User) ContentResolver(android.content.ContentResolver) MenuInflater(android.view.MenuInflater) Page(com.meisolsson.githubsdk.model.Page) SearchService(com.meisolsson.githubsdk.service.search.SearchService) Menu(android.view.Menu) R(com.gh4a.R) View(android.view.View) AdapterView(android.widget.AdapterView) TextMatch(com.meisolsson.githubsdk.model.TextMatch) Cursor(android.database.Cursor) StringUtils(com.gh4a.utils.StringUtils) SpinnerAdapter(android.widget.SpinnerAdapter) SearchAdapter(com.gh4a.adapter.SearchAdapter) ApiHelpers(com.gh4a.utils.ApiHelpers) LayoutInflater(android.view.LayoutInflater) TextUtils(android.text.TextUtils) ViewGroup(android.view.ViewGroup) Spinner(android.widget.Spinner) MergeCursor(android.database.MergeCursor) RecyclerView(android.support.v7.widget.RecyclerView) RootAdapter(com.gh4a.adapter.RootAdapter) TextView(android.widget.TextView) RepositoryActivity(com.gh4a.activities.RepositoryActivity) RxUtils(com.gh4a.utils.RxUtils) BaseAdapter(android.widget.BaseAdapter) LayoutRes(android.support.annotation.LayoutRes) MatrixCursor(android.database.MatrixCursor) ContentValues(android.content.ContentValues) Nullable(android.support.annotation.Nullable) ServiceFactory(com.gh4a.ServiceFactory) Repository(com.meisolsson.githubsdk.model.Repository) SearchService(com.meisolsson.githubsdk.service.search.SearchService) ApiHelpers(com.gh4a.utils.ApiHelpers)

Example 60 with Repository

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

the class NotificationsJob method showRepoNotification.

private void showRepoNotification(NotificationManagerCompat nm, List<NotificationThread> notifications, long lastCheck) {
    Repository repository = notifications.get(0).repository();
    final int id = repository.id().intValue();
    String title = repository.owner().login() + "/" + repository.name();
    // notifications are sorted by time descending
    long when = notifications.get(0).updatedAt().getTime();
    String text = getContext().getResources().getQuantityString(R.plurals.unread_notifications_summary_text, notifications.size(), notifications.size());
    Intent intent = NotificationHandlingService.makeOpenNotificationActionIntent(getContext(), repository.owner().login(), repository.name());
    PendingIntent contentIntent = PendingIntent.getService(getContext(), id, intent, PendingIntent.FLAG_UPDATE_CURRENT);
    PendingIntent deleteIntent = PendingIntent.getService(getContext(), id, NotificationHandlingService.makeHandleDismissIntent(getContext(), id), PendingIntent.FLAG_UPDATE_CURRENT);
    Intent markReadIntent = NotificationHandlingService.makeMarkReposNotificationsAsReadActionIntent(getContext(), id, repository.owner().login(), repository.name());
    PendingIntent markReadPendingIntent = PendingIntent.getService(getContext(), id, markReadIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    NotificationCompat.Action markReadAction = new NotificationCompat.Action(R.drawable.mark_read, getContext().getString(R.string.mark_as_read), markReadPendingIntent);
    android.app.Notification publicVersion = makeBaseBuilder().setContentTitle(getContext().getString(R.string.unread_notifications_summary_title)).setContentText(text).setNumber(notifications.size()).setVisibility(NotificationCompat.VISIBILITY_PUBLIC).build();
    NotificationCompat.Builder builder = makeBaseBuilder().setLargeIcon(loadRoundUserAvatar(repository.owner())).setGroup(GROUP_ID_GITHUB).setGroupAlertBehavior(NotificationCompat.GROUP_ALERT_SUMMARY).setWhen(when).setShowWhen(true).setNumber(notifications.size()).setPublicVersion(publicVersion).setVisibility(NotificationCompat.VISIBILITY_PRIVATE).setContentTitle(title).setContentIntent(contentIntent).setDeleteIntent(deleteIntent).setAutoCancel(true).addAction(markReadAction).setContentText(text);
    boolean hasNewNotification = false;
    NotificationCompat.MessagingStyle style = new NotificationCompat.MessagingStyle("").setConversationTitle(title);
    for (int i = notifications.size() - 1; i >= 0; i--) {
        NotificationThread n = notifications.get(i);
        style.addMessage(n.subject().title(), n.updatedAt().getTime(), determineNotificationTypeLabel(n));
        hasNewNotification = hasNewNotification || n.updatedAt().getTime() > lastCheck;
    }
    builder.setStyle(style);
    if (!hasNewNotification) {
        builder.setOnlyAlertOnce(true);
    }
    nm.notify(id, builder.build());
}
Also used : NotificationThread(com.meisolsson.githubsdk.model.NotificationThread) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) Paint(android.graphics.Paint) Repository(com.meisolsson.githubsdk.model.Repository) NotificationCompat(android.support.v4.app.NotificationCompat) Notification(android.app.Notification) PendingIntent(android.app.PendingIntent)

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