Search in sources :

Example 1 with Gh4Application

use of com.gh4a.Gh4Application in project gh4a by slapperwan.

the class Github4AndroidActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Gh4Application app = Gh4Application.get();
    if (app.isAuthorized()) {
        if (!handleIntent(getIntent())) {
            goToToplevelActivity();
        }
        finish();
    } else {
        setContentView(R.layout.main);
        AppBarLayout abl = findViewById(R.id.header);
        abl.setEnabled(false);
        FrameLayout contentContainer = (FrameLayout) findViewById(R.id.content).getParent();
        contentContainer.setForeground(null);
        findViewById(R.id.oauth_login_button).setOnClickListener(this);
        findViewById(R.id.user_pw_login_button).setOnClickListener(this);
        mContent = findViewById(R.id.welcome_container);
        mProgress = findViewById(R.id.login_progress_container);
        handleIntent(getIntent());
    }
}
Also used : FrameLayout(android.widget.FrameLayout) AppBarLayout(android.support.design.widget.AppBarLayout) Gh4Application(com.gh4a.Gh4Application)

Example 2 with Gh4Application

use of com.gh4a.Gh4Application in project gh4a by slapperwan.

the class CommitFragment method fillHeader.

private void fillHeader() {
    final Activity activity = getActivity();
    final Gh4Application app = Gh4Application.get();
    ImageView ivGravatar = mContentView.findViewById(R.id.iv_gravatar);
    User author = mCommit.author();
    if (author != null) {
        AvatarHandler.assignAvatar(ivGravatar, author);
    } else {
        GitUser commitAuthor = mCommit.commit().author();
        String email = commitAuthor != null ? commitAuthor.email() : null;
        ivGravatar.setImageDrawable(new AvatarHandler.DefaultAvatarDrawable(null, email));
    }
    String login = ApiHelpers.getAuthorLogin(mCommit);
    if (login != null) {
        ivGravatar.setOnClickListener(this);
        ivGravatar.setTag(login);
    }
    TextView tvMessage = mContentView.findViewById(R.id.tv_message);
    TextView tvTitle = mContentView.findViewById(R.id.tv_title);
    String message = mCommit.commit().message();
    int pos = message.indexOf('\n');
    String title = pos > 0 ? message.substring(0, pos) : message;
    title = EmojiParser.parseToUnicode(title);
    int length = message.length();
    while (pos > 0 && pos < length && Character.isWhitespace(message.charAt(pos))) {
        pos++;
    }
    message = pos > 0 && pos < length ? message.substring(pos) : null;
    if (message != null) {
        message = EmojiParser.parseToUnicode(message);
    }
    tvTitle.setText(title);
    tvMessage.setText(message);
    tvTitle.setVisibility(StringUtils.isBlank(title) ? View.GONE : View.VISIBLE);
    tvMessage.setVisibility(StringUtils.isBlank(message) ? View.GONE : View.VISIBLE);
    tvMessage.setMovementMethod(UiUtils.CHECKING_LINK_METHOD);
    GitCommit commit = mCommit.commit();
    TextView tvAuthor = mContentView.findViewById(R.id.tv_author);
    tvAuthor.setText(ApiHelpers.getAuthorName(app, mCommit));
    TextView tvTimestamp = mContentView.findViewById(R.id.tv_timestamp);
    tvTimestamp.setText(StringUtils.formatRelativeTime(activity, commit.author().date(), true));
    View committerContainer = mContentView.findViewById(R.id.committer);
    if (!ApiHelpers.authorEqualsCommitter(mCommit)) {
        ImageView commitGravatar = mContentView.findViewById(R.id.iv_commit_gravatar);
        StyleableTextView commitExtra = mContentView.findViewById(R.id.tv_commit_extra);
        AvatarHandler.assignAvatar(commitGravatar, mCommit.committer());
        String committerText = getString(R.string.commit_details, ApiHelpers.getCommitterName(app, mCommit), StringUtils.formatRelativeTime(activity, commit.committer().date(), true));
        StringUtils.applyBoldTagsAndSetText(commitExtra, committerText);
        committerContainer.setVisibility(View.VISIBLE);
    } else {
        committerContainer.setVisibility(View.GONE);
    }
}
Also used : User(com.meisolsson.githubsdk.model.User) GitUser(com.meisolsson.githubsdk.model.git.GitUser) GitCommit(com.meisolsson.githubsdk.model.git.GitCommit) CommitDiffViewerActivity(com.gh4a.activities.CommitDiffViewerActivity) FileViewerActivity(com.gh4a.activities.FileViewerActivity) UserActivity(com.gh4a.activities.UserActivity) Activity(android.app.Activity) ImageView(android.widget.ImageView) View(android.view.View) StyleableTextView(com.gh4a.widget.StyleableTextView) TextView(android.widget.TextView) GitUser(com.meisolsson.githubsdk.model.git.GitUser) StyleableTextView(com.gh4a.widget.StyleableTextView) TextView(android.widget.TextView) ImageView(android.widget.ImageView) AvatarHandler(com.gh4a.utils.AvatarHandler) Gh4Application(com.gh4a.Gh4Application) StyleableTextView(com.gh4a.widget.StyleableTextView)

Example 3 with Gh4Application

use of com.gh4a.Gh4Application in project gh4a by slapperwan.

the class NewsFeedFactory method loadOrganizations.

private void loadOrganizations(boolean force) {
    final Gh4Application app = Gh4Application.get();
    final OrganizationService service = ServiceFactory.get(OrganizationService.class, force);
    mOrganizationSubscription = ApiHelpers.PageIterator.toSingle(page -> ApiHelpers.loginEquals(mUserLogin, app.getAuthLogin()) ? service.getMyOrganizations(page) : service.getUserPublicOrganizations(mUserLogin, page)).compose(mActivity.makeLoaderSingle(ID_LOADER_ORGS, force)).subscribe(result -> {
        mUserScopes = result.isEmpty() ? null : result;
        mActivity.supportInvalidateOptionsMenu();
    }, mActivity::handleLoadFailure);
}
Also used : OrganizationService(com.meisolsson.githubsdk.service.organizations.OrganizationService) Context(android.content.Context) ApiHelpers(com.gh4a.utils.ApiHelpers) OrganizationService(com.meisolsson.githubsdk.service.organizations.OrganizationService) LayoutInflater(android.view.LayoutInflater) Fragment(android.support.v4.app.Fragment) ImageView(android.widget.ImageView) StringRes(android.support.annotation.StringRes) PrivateEventListFragment(com.gh4a.fragment.PrivateEventListFragment) ViewGroup(android.view.ViewGroup) Spinner(android.widget.Spinner) Gravity(android.view.Gravity) User(com.meisolsson.githubsdk.model.User) List(java.util.List) Disposable(io.reactivex.disposables.Disposable) TextView(android.widget.TextView) BaseAdapter(android.widget.BaseAdapter) Gh4Application(com.gh4a.Gh4Application) AvatarHandler(com.gh4a.utils.AvatarHandler) Menu(android.view.Menu) R(com.gh4a.R) View(android.view.View) AdapterView(android.widget.AdapterView) ServiceFactory(com.gh4a.ServiceFactory) Gh4Application(com.gh4a.Gh4Application)

Example 4 with Gh4Application

use of com.gh4a.Gh4Application in project gh4a by slapperwan.

the class SingleFactory method isAppUserRepoCollaborator.

public static Single<Boolean> isAppUserRepoCollaborator(String repoOwner, String repoName, boolean bypassCache) {
    Gh4Application app = Gh4Application.get();
    RepositoryCollaboratorService service = ServiceFactory.get(RepositoryCollaboratorService.class, bypassCache);
    if (!app.isAuthorized()) {
        return Single.just(false);
    }
    return service.isUserCollaborator(repoOwner, repoName, app.getAuthLogin()).map(ApiHelpers::throwOnFailure).compose(RxUtils.mapFailureToValue(403, false)).map(result -> true);
}
Also used : RepositoryCollaboratorService(com.meisolsson.githubsdk.service.repositories.RepositoryCollaboratorService) Gh4Application(com.gh4a.Gh4Application)

Example 5 with Gh4Application

use of com.gh4a.Gh4Application in project gh4a by slapperwan.

the class PullRequestActivity method onCreateOptionsMenu.

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.pullrequest_menu, menu);
    Gh4Application app = Gh4Application.get();
    boolean authorized = app.isAuthorized();
    boolean isCreator = mPullRequest != null && ApiHelpers.loginEquals(mPullRequest.user(), app.getAuthLogin());
    boolean isClosed = mPullRequest != null && mPullRequest.state() == IssueState.Closed;
    boolean isCollaborator = mIsCollaborator != null && mIsCollaborator;
    boolean closerIsCreator = mIssue != null && ApiHelpers.userEquals(mIssue.user(), mIssue.closedBy());
    boolean canClose = mPullRequest != null && authorized && (isCreator || isCollaborator);
    boolean canOpen = canClose && (isCollaborator || closerIsCreator);
    boolean canMerge = canClose && isCollaborator;
    if (!canClose || isClosed) {
        menu.removeItem(R.id.pull_close);
    }
    if (!canOpen || !isClosed) {
        menu.removeItem(R.id.pull_reopen);
    } else if (isClosed && mPullRequest.merged()) {
        menu.findItem(R.id.pull_reopen).setEnabled(false);
    }
    if (!canMerge) {
        menu.removeItem(R.id.pull_merge);
    } else if (mPullRequest.merged() || mPullRequest.mergeable() == null || !mPullRequest.mergeable()) {
        MenuItem mergeItem = menu.findItem(R.id.pull_merge);
        mergeItem.setEnabled(false);
    }
    if (mPullRequest == null) {
        menu.removeItem(R.id.share);
        menu.removeItem(R.id.browser);
        menu.removeItem(R.id.copy_number);
    }
    if (!mPendingReviewLoaded || mPullRequest == null || isClosed) {
        menu.removeItem(R.id.pull_review);
    }
    return super.onCreateOptionsMenu(menu);
}
Also used : MenuItem(android.view.MenuItem) Gh4Application(com.gh4a.Gh4Application)

Aggregations

Gh4Application (com.gh4a.Gh4Application)5 View (android.view.View)2 ImageView (android.widget.ImageView)2 TextView (android.widget.TextView)2 AvatarHandler (com.gh4a.utils.AvatarHandler)2 User (com.meisolsson.githubsdk.model.User)2 Activity (android.app.Activity)1 Context (android.content.Context)1 StringRes (android.support.annotation.StringRes)1 AppBarLayout (android.support.design.widget.AppBarLayout)1 Fragment (android.support.v4.app.Fragment)1 Gravity (android.view.Gravity)1 LayoutInflater (android.view.LayoutInflater)1 Menu (android.view.Menu)1 MenuItem (android.view.MenuItem)1 ViewGroup (android.view.ViewGroup)1 AdapterView (android.widget.AdapterView)1 BaseAdapter (android.widget.BaseAdapter)1 FrameLayout (android.widget.FrameLayout)1 Spinner (android.widget.Spinner)1