Search in sources :

Example 1 with NameParser

use of com.fastaccess.data.dao.NameParser in project FastHub by k0shk0sh.

the class GithubHelper method getLinkBaseUrl.

@NonNull
private static String getLinkBaseUrl(@NonNull String baseUrl) {
    NameParser nameParser = new NameParser(baseUrl);
    String owner = nameParser.getUsername();
    String repoName = nameParser.getName();
    Uri uri = Uri.parse(baseUrl);
    ArrayList<String> paths = new ArrayList<>(uri.getPathSegments());
    StringBuilder builder = new StringBuilder();
    builder.append("https://").append(uri.getAuthority()).append("/").append(owner).append("/").append(repoName).append("/");
    boolean containsMaster = paths.size() > 3 && paths.get(2).equalsIgnoreCase("blob");
    if (!containsMaster) {
        builder.append("blob/master/");
    }
    paths.remove(owner);
    paths.remove(repoName);
    for (String path : paths) {
        if (!path.equalsIgnoreCase(uri.getLastPathSegment())) {
            builder.append(path).append("/");
        }
    }
    return builder.toString();
}
Also used : ArrayList(java.util.ArrayList) Uri(android.net.Uri) NameParser(com.fastaccess.data.dao.NameParser) NonNull(android.support.annotation.NonNull)

Example 2 with NameParser

use of com.fastaccess.data.dao.NameParser in project FastHub by k0shk0sh.

the class RepoFilesActivity method getIntent.

public static Intent getIntent(@NonNull Context context, @NonNull String url) {
    boolean isEnterprise = LinkParserHelper.isEnterprise(url);
    if (isEnterprise) {
        url = url.replace("api/v3/", "");
        if (url.contains("/raw")) {
            url = url.replace("/raw", "");
        }
    }
    Uri uri = Uri.parse(url);
    if (uri.getPathSegments() != null && uri.getPathSegments().size() > 3) {
        String login = null;
        String repoId = null;
        String branch = null;
        StringBuilder path = new StringBuilder();
        boolean startWithRepo = false;
        if (uri.getPathSegments().get(0).equalsIgnoreCase("repos")) {
            login = uri.getPathSegments().get(1);
            repoId = uri.getPathSegments().get(2);
            branch = uri.getQueryParameter("ref");
            startWithRepo = true;
        } else if (uri.getPathSegments().get(0).equalsIgnoreCase("repositories")) {
            String id = uri.getPathSegments().get(1);
            try {
                long longRepoId = Long.valueOf(id);
                if (longRepoId != 0) {
                    Repo repo = AbstractRepo.getRepo(longRepoId);
                    if (repo != null) {
                        NameParser nameParser = new NameParser(repo.getHtmlUrl());
                        if (nameParser.getUsername() != null && nameParser.getName() != null) {
                            login = nameParser.getUsername();
                            repoId = nameParser.getName();
                            branch = uri.getQueryParameter("ref");
                        }
                    }
                }
            } catch (NumberFormatException ignored) {
                return new Intent(context, MainActivity.class);
            }
        } else {
            login = uri.getPathSegments().get(0);
            repoId = uri.getPathSegments().get(1);
            branch = uri.getPathSegments().get(2);
        }
        for (int i = startWithRepo ? 4 : 3; i < uri.getPathSegments().size() - 1; i++) {
            String appendedPath = uri.getPathSegments().get(i);
            path.append("/").append(appendedPath);
        }
        if (!InputHelper.isEmpty(repoId) && !InputHelper.isEmpty(login)) {
            Intent intent = new Intent(context, RepoFilesActivity.class);
            intent.putExtras(Bundler.start().put(BundleConstant.ID, repoId).put(BundleConstant.EXTRA, login).put(BundleConstant.EXTRA_TWO, path.toString()).put(BundleConstant.EXTRA_THREE, branch).put(BundleConstant.IS_ENTERPRISE, isEnterprise).end());
            return intent;
        }
        return new Intent(context, MainActivity.class);
    }
    return new Intent(context, MainActivity.class);
}
Also used : Repo(com.fastaccess.data.dao.model.Repo) AbstractRepo(com.fastaccess.data.dao.model.AbstractRepo) Intent(android.content.Intent) Uri(android.net.Uri) NameParser(com.fastaccess.data.dao.NameParser)

Example 3 with NameParser

use of com.fastaccess.data.dao.NameParser in project FastHub by k0shk0sh.

the class FeedsPresenter method onItemClick.

@Override
public void onItemClick(int position, View v, Event item) {
    if (item.getType() == EventsType.ForkEvent) {
        NameParser parser = new NameParser(item.getPayload().getForkee().getHtmlUrl());
        RepoPagerActivity.startRepoPager(v.getContext(), parser);
    } else {
        PayloadModel payloadModel = item.getPayload();
        if (payloadModel != null) {
            if (payloadModel.getHead() != null) {
                if (payloadModel.getCommits() != null && payloadModel.getCommits().size() > 1) {
                    sendToView(view -> view.onOpenCommitChooser(payloadModel.getCommits()));
                } else {
                    Repo repoModel = item.getRepo();
                    NameParser nameParser = new NameParser(repoModel.getUrl());
                    Intent intent = CommitPagerActivity.createIntent(v.getContext(), nameParser.getName(), nameParser.getUsername(), payloadModel.getHead(), true, LinkParserHelper.isEnterprise(repoModel.getUrl()));
                    v.getContext().startActivity(intent);
                }
            } else if (payloadModel.getIssue() != null) {
                SchemeParser.launchUri(v.getContext(), Uri.parse(payloadModel.getIssue().getHtmlUrl()), true);
            } else if (payloadModel.getPullRequest() != null) {
                SchemeParser.launchUri(v.getContext(), Uri.parse(payloadModel.getPullRequest().getHtmlUrl()), true);
            } else if (payloadModel.getComment() != null) {
                SchemeParser.launchUri(v.getContext(), Uri.parse(payloadModel.getComment().getHtmlUrl()), true);
            } else if (item.getType() == EventsType.ReleaseEvent && payloadModel.getRelease() != null) {
                NameParser nameParser = new NameParser(payloadModel.getRelease().getHtmlUrl());
                v.getContext().startActivity(ReleasesListActivity.getIntent(v.getContext(), nameParser.getUsername(), nameParser.getName(), payloadModel.getRelease().getId(), LinkParserHelper.isEnterprise(payloadModel.getRelease().getHtmlUrl())));
            } else if (item.getType() == EventsType.CreateEvent && "tag".equalsIgnoreCase(payloadModel.getRefType())) {
                Repo repoModel = item.getRepo();
                NameParser nameParser = new NameParser(repoModel.getUrl());
                v.getContext().startActivity(ReleasesListActivity.getIntent(v.getContext(), nameParser.getUsername(), nameParser.getName(), payloadModel.getRef(), LinkParserHelper.isEnterprise(repoModel.getUrl())));
            } else if (item.getType() == EventsType.GollumEvent) {
                Repo repoModel = item.getRepo();
                NameParser parser = new NameParser(repoModel.getUrl());
                v.getContext().startActivity(WikiActivity.Companion.getWiki(v.getContext(), parser.getName(), parser.getUsername()));
            } else {
                Repo repoModel = item.getRepo();
                NameParser parser = new NameParser(repoModel.getUrl());
                RepoPagerActivity.startRepoPager(v.getContext(), parser);
            }
        }
    }
}
Also used : Repo(com.fastaccess.data.dao.model.Repo) Intent(android.content.Intent) NameParser(com.fastaccess.data.dao.NameParser) PayloadModel(com.fastaccess.data.dao.PayloadModel)

Example 4 with NameParser

use of com.fastaccess.data.dao.NameParser in project FastHub by k0shk0sh.

the class FeedsPresenter method onItemLongClick.

@Override
public void onItemLongClick(int position, View v, Event item) {
    if (item.getType() == EventsType.ForkEvent) {
        if (getView() != null) {
            getView().onOpenRepoChooser(Stream.of(new SimpleUrlsModel(item.getRepo().getName(), item.getRepo().getUrl()), new SimpleUrlsModel(item.getPayload().getForkee().getFullName(), item.getPayload().getForkee().getHtmlUrl())).collect(Collectors.toCollection(ArrayList::new)));
        }
    } else {
        Repo repo = item.getRepo();
        if (repo != null) {
            NameParser parser = new NameParser(repo.getUrl());
            RepoPagerActivity.startRepoPager(v.getContext(), parser);
        }
    }
}
Also used : SimpleUrlsModel(com.fastaccess.data.dao.SimpleUrlsModel) Repo(com.fastaccess.data.dao.model.Repo) ArrayList(java.util.ArrayList) NameParser(com.fastaccess.data.dao.NameParser)

Example 5 with NameParser

use of com.fastaccess.data.dao.NameParser in project FastHub by k0shk0sh.

the class CommitPagerActivity method onNavToRepoClicked.

@Override
public void onNavToRepoClicked() {
    NameParser nameParser = new NameParser("");
    nameParser.setName(getPresenter().getRepoId());
    nameParser.setUsername(getPresenter().getLogin());
    nameParser.setEnterprise(isEnterprise());
    RepoPagerActivity.startRepoPager(this, nameParser);
    finish();
}
Also used : NameParser(com.fastaccess.data.dao.NameParser)

Aggregations

NameParser (com.fastaccess.data.dao.NameParser)8 Uri (android.net.Uri)3 Repo (com.fastaccess.data.dao.model.Repo)3 ArrayList (java.util.ArrayList)3 Intent (android.content.Intent)2 NonNull (android.support.annotation.NonNull)2 CommentRequestModel (com.fastaccess.data.dao.CommentRequestModel)1 PayloadModel (com.fastaccess.data.dao.PayloadModel)1 SimpleUrlsModel (com.fastaccess.data.dao.SimpleUrlsModel)1 AbstractRepo (com.fastaccess.data.dao.model.AbstractRepo)1