Search in sources :

Example 1 with RxUtils

use of com.gh4a.utils.RxUtils in project gh4a by slapperwan.

the class IssueListActivity method filterMilestone.

private void filterMilestone() {
    if (mMilestones != null) {
        showMilestonesDialog();
    } else {
        final IssueMilestoneService service = ServiceFactory.get(IssueMilestoneService.class, false);
        registerTemporarySubscription(ApiHelpers.PageIterator.toSingle(page -> service.getRepositoryMilestones(mRepoOwner, mRepoName, "open", page)).compose(RxUtils::doInBackground).compose(RxUtils.wrapWithProgressDialog(this, R.string.loading_msg)).subscribe(milestones -> {
            mMilestones = milestones;
            showMilestonesDialog();
        }, this::handleLoadFailure));
    }
}
Also used : IssueMilestoneService(com.meisolsson.githubsdk.service.issues.IssueMilestoneService) Context(android.content.Context) CoordinatorLayout(android.support.design.widget.CoordinatorLayout) Bundle(android.os.Bundle) SearchView(android.support.v7.widget.SearchView) IssueMilestoneService(com.meisolsson.githubsdk.service.issues.IssueMilestoneService) Intent(android.content.Intent) StringRes(android.support.annotation.StringRes) NonNull(android.support.annotation.NonNull) MenuItem(android.view.MenuItem) UiUtils(com.gh4a.utils.UiUtils) User(com.meisolsson.githubsdk.model.User) IssueListFragment(com.gh4a.fragment.IssueListFragment) IssueState(com.meisolsson.githubsdk.model.IssueState) Milestone(com.meisolsson.githubsdk.model.Milestone) Label(com.meisolsson.githubsdk.model.Label) Locale(java.util.Locale) Menu(android.view.Menu) R(com.gh4a.R) Issue(com.meisolsson.githubsdk.model.Issue) View(android.view.View) IssueAssigneeService(com.meisolsson.githubsdk.service.issues.IssueAssigneeService) DialogInterface(android.content.DialogInterface) FloatingActionButton(android.support.design.widget.FloatingActionButton) ApiHelpers(com.gh4a.utils.ApiHelpers) BaseFragmentPagerActivity(com.gh4a.BaseFragmentPagerActivity) Fragment(android.support.v4.app.Fragment) IssueLabelService(com.meisolsson.githubsdk.service.issues.IssueLabelService) TextUtils(android.text.TextUtils) LoadingListFragmentBase(com.gh4a.fragment.LoadingListFragmentBase) RecyclerView(android.support.v7.widget.RecyclerView) List(java.util.List) AlertDialog(android.support.v7.app.AlertDialog) RxUtils(com.gh4a.utils.RxUtils) Gh4Application(com.gh4a.Gh4Application) SingleFactory(com.gh4a.utils.SingleFactory) Nullable(android.support.annotation.Nullable) ServiceFactory(com.gh4a.ServiceFactory) Activity(android.app.Activity)

Example 2 with RxUtils

use of com.gh4a.utils.RxUtils in project gh4a by slapperwan.

the class IssueEditActivity method loadMilestones.

private void loadMilestones() {
    final IssueMilestoneService service = ServiceFactory.get(IssueMilestoneService.class, false);
    registerTemporarySubscription(ApiHelpers.PageIterator.toSingle(page -> service.getRepositoryMilestones(mRepoOwner, mRepoName, "open", page)).compose(RxUtils::doInBackground).compose(RxUtils.wrapWithProgressDialog(this, R.string.loading_msg)).subscribe(result -> {
        mAllMilestone = result;
        showMilestonesDialog();
    }, this::handleLoadFailure));
}
Also used : IssueMilestoneService(com.meisolsson.githubsdk.service.issues.IssueMilestoneService) HttpURLConnection(java.net.HttpURLConnection) Bundle(android.os.Bundle) ImageView(android.widget.ImageView) IssueMilestoneService(com.meisolsson.githubsdk.service.issues.IssueMilestoneService) TextInputLayout(android.support.design.widget.TextInputLayout) MarkdownPreviewWebView(com.gh4a.widget.MarkdownPreviewWebView) IssueState(com.meisolsson.githubsdk.model.IssueState) Label(com.meisolsson.githubsdk.model.Label) Locale(java.util.Locale) ContentType(com.meisolsson.githubsdk.model.ContentType) Issue(com.meisolsson.githubsdk.model.Issue) View(android.view.View) StringUtils(com.gh4a.utils.StringUtils) FloatingActionButton(android.support.design.widget.FloatingActionButton) ContextCompat(android.support.v4.content.ContextCompat) IssueLabelService(com.meisolsson.githubsdk.service.issues.IssueLabelService) ViewGroup(android.view.ViewGroup) RepositoryContentService(com.meisolsson.githubsdk.service.repositories.RepositoryContentService) List(java.util.List) TextView(android.widget.TextView) RxUtils(com.gh4a.utils.RxUtils) Optional(com.gh4a.utils.Optional) Nullable(android.support.annotation.Nullable) Typeface(android.graphics.Typeface) Context(android.content.Context) AppBarLayout(android.support.design.widget.AppBarLayout) CoordinatorLayout(android.support.design.widget.CoordinatorLayout) MarkdownButtonsBar(com.gh4a.widget.MarkdownButtonsBar) BasePagerActivity(com.gh4a.BasePagerActivity) Intent(android.content.Intent) Response(retrofit2.Response) Single(io.reactivex.Single) UiUtils(com.gh4a.utils.UiUtils) ArrayList(java.util.ArrayList) User(com.meisolsson.githubsdk.model.User) AvatarHandler(com.gh4a.utils.AvatarHandler) Milestone(com.meisolsson.githubsdk.model.Milestone) Content(com.meisolsson.githubsdk.model.Content) R(com.gh4a.R) IssueRequest(com.meisolsson.githubsdk.model.request.issue.IssueRequest) IssueService(com.meisolsson.githubsdk.service.issues.IssueService) RepositoryCollaboratorService(com.meisolsson.githubsdk.service.repositories.RepositoryCollaboratorService) DialogInterface(android.content.DialogInterface) ApiHelpers(com.gh4a.utils.ApiHelpers) LayoutInflater(android.view.LayoutInflater) PagerAdapter(android.support.v4.view.PagerAdapter) IdRes(android.support.annotation.IdRes) AlertDialog(android.support.v7.app.AlertDialog) Gh4Application(com.gh4a.Gh4Application) ObjectsCompat(android.support.v4.util.ObjectsCompat) SingleFactory(com.gh4a.utils.SingleFactory) ServiceFactory(com.gh4a.ServiceFactory) EditText(android.widget.EditText)

Example 3 with RxUtils

use of com.gh4a.utils.RxUtils in project gh4a by slapperwan.

the class UserPasswordLoginDialogFragment method makeLoginSingle.

private Single<Pair<String, User>> makeLoginSingle(LoginService.AuthorizationRequest request) {
    return getService().createAuthorization(request).map(ApiHelpers::throwOnFailure).compose(RxUtils::doInBackground).flatMap(response -> {
        UserService userService = ServiceFactory.get(UserService.class, true, null, response.token(), null);
        Single<User> userSingle = userService.getUser().map(ApiHelpers::throwOnFailure).compose(RxUtils::doInBackground);
        return Single.zip(Single.just(response), userSingle, (r, user) -> Pair.create(r.token(), user));
    });
}
Also used : User(com.meisolsson.githubsdk.model.User) RxUtils(com.gh4a.utils.RxUtils) UserService(com.meisolsson.githubsdk.service.users.UserService) ApiHelpers(com.gh4a.utils.ApiHelpers)

Example 4 with RxUtils

use of com.gh4a.utils.RxUtils in project gh4a by slapperwan.

the class ReactionBar method toggleReaction.

private static Single<Optional<Reaction>> toggleReaction(String content, long id, List<Reaction> existingDetails, Callback callback, Item item, ReactionDetailsCache cache) {
    final Single<Optional<Reaction>> resultSingle;
    if (id == 0) {
        resultSingle = callback.addReaction(item, content).map(Optional::of);
    } else {
        ReactionService service = ServiceFactory.get(ReactionService.class, false);
        resultSingle = service.deleteReaction(id).map(response -> Optional.absent());
    }
    return resultSingle.compose(RxUtils::doInBackground).doOnSuccess(reactionOpt -> {
        if (reactionOpt.isPresent()) {
            existingDetails.add(reactionOpt.get());
        } else {
            for (int i = 0; i < existingDetails.size(); i++) {
                Reaction reaction = existingDetails.get(i);
                if (reaction.id() == id) {
                    existingDetails.remove(i);
                    break;
                }
            }
        }
        cache.putEntry(item, existingDetails);
    });
}
Also used : Context(android.content.Context) LinearLayout(android.widget.LinearLayout) MenuBuilder(android.support.v7.view.menu.MenuBuilder) DrawableCompat(android.support.v4.graphics.drawable.DrawableCompat) ImageView(android.widget.ImageView) HashMap(java.util.HashMap) NonNull(android.support.annotation.NonNull) Drawable(android.graphics.drawable.Drawable) Single(io.reactivex.Single) MenuItem(android.view.MenuItem) UserActivity(com.gh4a.activities.UserActivity) UiUtils(com.gh4a.utils.UiUtils) ArrayList(java.util.ArrayList) User(com.meisolsson.githubsdk.model.User) AttributeSet(android.util.AttributeSet) Reaction(com.meisolsson.githubsdk.model.Reaction) AvatarHandler(com.gh4a.utils.AvatarHandler) MenuPopupHelper(android.support.v7.view.menu.MenuPopupHelper) Menu(android.view.Menu) R(com.gh4a.R) View(android.view.View) Reactions(com.meisolsson.githubsdk.model.Reactions) Log(android.util.Log) Parcelable(android.os.Parcelable) ApiHelpers(com.gh4a.utils.ApiHelpers) ReactionService(com.meisolsson.githubsdk.service.reactions.ReactionService) LayoutInflater(android.view.LayoutInflater) PopupMenu(android.support.v7.widget.PopupMenu) TextUtils(android.text.TextUtils) PorterDuff(android.graphics.PorterDuff) ViewGroup(android.view.ViewGroup) IdRes(android.support.annotation.IdRes) ColorInt(android.support.annotation.ColorInt) List(java.util.List) TextView(android.widget.TextView) RxUtils(com.gh4a.utils.RxUtils) BaseAdapter(android.widget.BaseAdapter) Gh4Application(com.gh4a.Gh4Application) LayoutRes(android.support.annotation.LayoutRes) Optional(com.gh4a.utils.Optional) Nullable(android.support.annotation.Nullable) ServiceFactory(com.gh4a.ServiceFactory) ListPopupWindow(android.support.v7.widget.ListPopupWindow) Optional(com.gh4a.utils.Optional) ReactionService(com.meisolsson.githubsdk.service.reactions.ReactionService) Reaction(com.meisolsson.githubsdk.model.Reaction)

Example 5 with RxUtils

use of com.gh4a.utils.RxUtils 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)

Aggregations

RxUtils (com.gh4a.utils.RxUtils)13 View (android.view.View)12 R (com.gh4a.R)12 ApiHelpers (com.gh4a.utils.ApiHelpers)12 User (com.meisolsson.githubsdk.model.User)12 Context (android.content.Context)11 ServiceFactory (com.gh4a.ServiceFactory)11 UiUtils (com.gh4a.utils.UiUtils)11 Bundle (android.os.Bundle)10 Gh4Application (com.gh4a.Gh4Application)10 List (java.util.List)10 Intent (android.content.Intent)9 Nullable (android.support.annotation.Nullable)9 AlertDialog (android.support.v7.app.AlertDialog)9 LayoutInflater (android.view.LayoutInflater)9 Single (io.reactivex.Single)9 DialogInterface (android.content.DialogInterface)8 Issue (com.meisolsson.githubsdk.model.Issue)8 Locale (java.util.Locale)8 CoordinatorLayout (android.support.design.widget.CoordinatorLayout)7