Search in sources :

Example 6 with RxUtils

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

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

the class UserPasswordLoginDialogFragment method makeRequestSingle.

private Single<LoginService.AuthorizationRequest> makeRequestSingle() {
    String description = "Octodroid - " + Build.MANUFACTURER + " " + Build.MODEL;
    String fingerprint = getHashedDeviceId();
    LoginService service = getService();
    String scopes = getArguments().getString("scopes");
    return service.getAuthorizations().map(ApiHelpers::throwOnFailure).compose(RxUtils::doInBackground).retryWhen(handler -> handler.flatMap(error -> {
        if (error instanceof ApiRequestException) {
            ApiRequestException are = (ApiRequestException) error;
            if (are.getStatus() == 401 && are.getResponse().message().contains("OTP code")) {
                mWaitingForOtpCode = true;
                mHandler.post(() -> updateContainerVisibility(false));
                // getAuthorizations() doesn't trigger the OTP SMS for whatever reason,
                // so make a dummy create request (which we know will fail) just to
                // actually trigger SMS sending
                LoginService.AuthorizationRequest dummyRequest = new LoginService.AuthorizationRequest("", "dummy", "");
                service.createAuthorization(dummyRequest).compose(RxUtils::doInBackground).subscribe(ignoredResponse -> {
                }, ignoredError -> {
                });
            }
        }
        if (!mWaitingForOtpCode) {
            mRetryProcessor.onError(error);
        }
        return mRetryProcessor;
    })).compose(RxUtils.filter(authorization -> {
        String note = authorization.note();
        return note != null && note.startsWith(description);
    })).flatMap(existingAuthorizations -> {
        Single<Void> deleteSingle = null;
        Iterator<LoginService.AuthorizationResponse> iter = existingAuthorizations.iterator();
        while (iter.hasNext()) {
            LoginService.AuthorizationResponse auth = iter.next();
            if (fingerprint.equals(auth.fingerprint())) {
                deleteSingle = service.deleteAuthorization(auth.id()).map(ApiHelpers::throwOnFailure).compose(RxUtils::doInBackground);
                iter.remove();
            }
        }
        String finalDescription = description;
        if (!existingAuthorizations.isEmpty()) {
            finalDescription += " #" + (existingAuthorizations.size() + 1);
        }
        LoginService.AuthorizationRequest request = new LoginService.AuthorizationRequest(scopes, finalDescription, fingerprint);
        if (deleteSingle != null) {
            return deleteSingle.map(response -> request);
        } else {
            return Single.just(request);
        }
    });
}
Also used : Context(android.content.Context) Bundle(android.os.Bundle) MessageDigest(java.security.MessageDigest) Dialog(android.app.Dialog) NonNull(android.support.annotation.NonNull) DialogFragment(android.support.v4.app.DialogFragment) Single(io.reactivex.Single) Editable(android.text.Editable) TextInputLayout(android.support.design.widget.TextInputLayout) User(com.meisolsson.githubsdk.model.User) Locale(java.util.Locale) Handler(android.os.Handler) R(com.gh4a.R) View(android.view.View) Button(android.widget.Button) Settings(android.provider.Settings) ApiRequestException(com.gh4a.ApiRequestException) Build(android.os.Build) DialogInterface(android.content.DialogInterface) ApiHelpers(com.gh4a.utils.ApiHelpers) Iterator(java.util.Iterator) LayoutInflater(android.view.LayoutInflater) TextUtils(android.text.TextUtils) UserService(com.meisolsson.githubsdk.service.users.UserService) IdRes(android.support.annotation.IdRes) AlertDialog(android.support.v7.app.AlertDialog) RxUtils(com.gh4a.utils.RxUtils) Pair(android.support.v4.util.Pair) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) TextInputEditText(android.support.design.widget.TextInputEditText) ServiceFactory(com.gh4a.ServiceFactory) PublishProcessor(io.reactivex.processors.PublishProcessor) UnsupportedEncodingException(java.io.UnsupportedEncodingException) LoginService(com.gh4a.ServiceFactory.LoginService) TextWatcher(android.text.TextWatcher) RxUtils(com.gh4a.utils.RxUtils) LoginService(com.gh4a.ServiceFactory.LoginService) ApiRequestException(com.gh4a.ApiRequestException) ApiHelpers(com.gh4a.utils.ApiHelpers)

Example 8 with RxUtils

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

the class IssueListActivity method filterAssignee.

private void filterAssignee() {
    if (mAssignees != null) {
        showAssigneesDialog();
    } else {
        final IssueAssigneeService service = ServiceFactory.get(IssueAssigneeService.class, false);
        registerTemporarySubscription(ApiHelpers.PageIterator.toSingle(page -> service.getAssignees(mRepoOwner, mRepoName, page)).compose(RxUtils::doInBackground).compose(RxUtils.wrapWithProgressDialog(this, R.string.loading_msg)).subscribe(assignees -> {
            mAssignees = assignees;
            showAssigneesDialog();
        }, this::handleLoadFailure));
    }
}
Also used : IssueAssigneeService(com.meisolsson.githubsdk.service.issues.IssueAssigneeService) 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 9 with RxUtils

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

the class IssueListActivity method filterLabel.

private void filterLabel() {
    if (mLabels != null) {
        showLabelsDialog();
    } else {
        final IssueLabelService service = ServiceFactory.get(IssueLabelService.class, false);
        registerTemporarySubscription(ApiHelpers.PageIterator.toSingle(page -> service.getRepositoryLabels(mRepoOwner, mRepoName, page)).compose(RxUtils::doInBackground).compose(RxUtils.wrapWithProgressDialog(this, R.string.loading_msg)).subscribe(labels -> {
            mLabels = labels;
            showLabelsDialog();
        }, this::handleLoadFailure));
    }
}
Also used : 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) IssueLabelService(com.meisolsson.githubsdk.service.issues.IssueLabelService)

Example 10 with RxUtils

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

the class RepositoryActivity method loadOrShowRefSelection.

private void loadOrShowRefSelection() {
    if (mBranches != null) {
        showRefSelectionDialog();
    } else {
        final RepositoryBranchService branchService = ServiceFactory.get(RepositoryBranchService.class, false);
        final RepositoryService repoService = ServiceFactory.get(RepositoryService.class, false);
        Single<List<Branch>> branchSingle = ApiHelpers.PageIterator.toSingle(page -> branchService.getBranches(mRepoOwner, mRepoName, page));
        Single<List<Branch>> tagSingle = ApiHelpers.PageIterator.toSingle(page -> repoService.getTags(mRepoOwner, mRepoName, page));
        registerTemporarySubscription(Single.zip(branchSingle, tagSingle, Pair::create).compose(RxUtils::doInBackground).compose(RxUtils.wrapWithProgressDialog(this, R.string.loading_msg)).subscribe(result -> {
            mBranches = result.first;
            mTags = result.second;
            showRefSelectionDialog();
        }, this::handleLoadFailure));
    }
}
Also used : HttpURLConnection(java.net.HttpURLConnection) Context(android.content.Context) ContentListContainerFragment(com.gh4a.fragment.ContentListContainerFragment) Repository(com.meisolsson.githubsdk.model.Repository) Bundle(android.os.Bundle) StarringService(com.meisolsson.githubsdk.service.activity.StarringService) Uri(android.net.Uri) ImageView(android.widget.ImageView) RepositoryEventListFragment(com.gh4a.fragment.RepositoryEventListFragment) Intent(android.content.Intent) RepositoryFragment(com.gh4a.fragment.RepositoryFragment) Response(retrofit2.Response) Single(io.reactivex.Single) MenuItem(android.view.MenuItem) UiUtils(com.gh4a.utils.UiUtils) ArrayList(java.util.ArrayList) Commit(com.meisolsson.githubsdk.model.Commit) MenuInflater(android.view.MenuInflater) Menu(android.view.Menu) R(com.gh4a.R) View(android.view.View) ActionBar(android.support.v7.app.ActionBar) IntentUtils(com.gh4a.utils.IntentUtils) Subscription(com.meisolsson.githubsdk.model.Subscription) RepositoryBranchService(com.meisolsson.githubsdk.service.repositories.RepositoryBranchService) ApiHelpers(com.gh4a.utils.ApiHelpers) BaseFragmentPagerActivity(com.gh4a.BaseFragmentPagerActivity) LayoutInflater(android.view.LayoutInflater) Fragment(android.support.v4.app.Fragment) RepositoryService(com.meisolsson.githubsdk.service.repositories.RepositoryService) TextUtils(android.text.TextUtils) WatchingService(com.meisolsson.githubsdk.service.activity.WatchingService) ViewGroup(android.view.ViewGroup) List(java.util.List) AlertDialog(android.support.v7.app.AlertDialog) TextView(android.widget.TextView) RxUtils(com.gh4a.utils.RxUtils) BaseAdapter(android.widget.BaseAdapter) Gh4Application(com.gh4a.Gh4Application) CommitListFragment(com.gh4a.fragment.CommitListFragment) Pair(android.support.v4.util.Pair) Branch(com.meisolsson.githubsdk.model.Branch) ServiceFactory(com.gh4a.ServiceFactory) BookmarksProvider(com.gh4a.db.BookmarksProvider) SubscriptionRequest(com.meisolsson.githubsdk.model.request.activity.SubscriptionRequest) ArrayList(java.util.ArrayList) List(java.util.List) RepositoryBranchService(com.meisolsson.githubsdk.service.repositories.RepositoryBranchService) RepositoryService(com.meisolsson.githubsdk.service.repositories.RepositoryService) Pair(android.support.v4.util.Pair)

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