Search in sources :

Example 6 with Repository

use of org.eclipse.egit.github.core.Repository in project Bitocle by mthli.

the class RepoTask method doInBackground.

@Override
protected Boolean doInBackground(Void... params) {
    if (flag == Flag.REPO_FIRST) {
        RAction action = new RAction(context);
        try {
            action.openDatabase(true);
        } catch (SQLException s) {
            action.closeDatabase();
            return false;
        }
        List<Repository> repositories;
        try {
            repositories = service.getRepositories();
        } catch (IOException i) {
            action.closeDatabase();
            return false;
        }
        if (isCancelled()) {
            action.closeDatabase();
            return false;
        }
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        if (flag == Flag.REPO_FIRST) {
            for (Repository r : repositories) {
                if (!action.checkRepo(r.getGitUrl())) {
                    Repo repo = new Repo();
                    repo.setName(r.getName());
                    repo.setDate(format.format(r.getCreatedAt()));
                    repo.setDescription(r.getDescription());
                    repo.setLang(r.getLanguage());
                    repo.setStar(r.getWatchers());
                    repo.setFork(r.getForks());
                    repo.setOwner(r.getOwner().getLogin());
                    repo.setGit(r.getGitUrl());
                    action.addRepo(repo);
                }
            }
        }
        action.closeDatabase();
    }
    if (isCancelled()) {
        return false;
    }
    return true;
}
Also used : Repository(org.eclipse.egit.github.core.Repository) Repo(io.github.mthli.Bitocle.Database.Repo.Repo) SQLException(android.database.SQLException) RAction(io.github.mthli.Bitocle.Database.Repo.RAction) IOException(java.io.IOException) SimpleDateFormat(java.text.SimpleDateFormat)

Example 7 with Repository

use of org.eclipse.egit.github.core.Repository in project camel by apache.

the class MockRepositoryService method getRepository.

@Override
public Repository getRepository(final String owner, final String name) throws IOException {
    Repository repository = new Repository();
    repository.setName(name);
    return repository;
}
Also used : Repository(org.eclipse.egit.github.core.Repository)

Example 8 with Repository

use of org.eclipse.egit.github.core.Repository in project Bitocle by mthli.

the class WatchTask method doInBackground.

@Override
protected Boolean doInBackground(Void... params) {
    PageIterator<Repository> pageIterator = watcherService.pageWatched(20);
    Iterator<Repository> iterator = pageIterator.next().iterator();
    if (isCancelled()) {
        return false;
    }
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
    watchItemList.clear();
    while (iterator.hasNext()) {
        Repository r = iterator.next();
        String date = simpleDateFormat.format(r.getCreatedAt());
        String lang;
        if (r.getLanguage() == null) {
            lang = context.getString(R.string.repo_lang_unknown);
        } else {
            lang = r.getLanguage();
        }
        String info = lang + "   " + context.getString(R.string.watch_item_info_star) + " " + r.getWatchers() + "   " + context.getString(R.string.watch_item_info_fork) + " " + r.getForks();
        watchItemList.add(new WatchItem(context.getResources().getDrawable(R.drawable.ic_type_repo), r.getName(), date, r.getDescription(), info, r.getOwner().getLogin(), r.getGitUrl()));
    }
    if (isCancelled()) {
        return false;
    }
    return true;
}
Also used : Repository(org.eclipse.egit.github.core.Repository) SimpleDateFormat(java.text.SimpleDateFormat)

Example 9 with Repository

use of org.eclipse.egit.github.core.Repository in project Bitocle by mthli.

the class StarTask method onPostExecute.

@Override
protected void onPostExecute(Boolean result) {
    if (result) {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        list.clear();
        while (iterator.hasNext()) {
            Repository r = iterator.next();
            list.add(new StarItem(r.getName(), format.format(r.getCreatedAt()), r.getDescription(), r.getLanguage(), r.getWatchers(), r.getForks(), r.getOwner().getLogin(), r.getGitUrl()));
        }
        if (list.size() <= 0) {
            bookmark.setVisible(false);
            fragment.setContentEmpty(true);
            fragment.setEmptyText(R.string.repo_empty_list);
            fragment.setContentShown(true);
        } else {
            bookmark.setVisible(true);
            fragment.setContentEmpty(false);
            adapter.notifyDataSetChanged();
            fragment.setContentShown(true);
        }
    } else {
        bookmark.setVisible(false);
        fragment.setContentEmpty(true);
        fragment.setEmptyText(R.string.repo_empty_error);
        fragment.setContentShown(true);
    }
}
Also used : Repository(org.eclipse.egit.github.core.Repository) SimpleDateFormat(java.text.SimpleDateFormat)

Example 10 with Repository

use of org.eclipse.egit.github.core.Repository in project hubroid by EddieRingle.

the class RequestCache method getRepository.

public static Repository getRepository(final BaseActivity context, final String owner, final String name, final boolean forceUpdate) {
    Repository repo = null;
    boolean shouldRefresh = false;
    final File dir = new File(context.getCacheDir(), ROOT_DIR + REPOSITORY_DIR);
    if (!dir.exists() || !dir.isDirectory()) {
        dir.mkdirs();
    }
    final File f = new File(dir, owner + "_" + name + ".json");
    if (!forceUpdate && f.exists()) {
        /* Check if the cached JSON is really old */
        final Date d = new Date();
        final long elderCheck = d.getTime() - (KEEP_LENGTH);
        if (f.lastModified() < elderCheck) {
            shouldRefresh = true;
        } else {
            try {
                final FileInputStream in = new FileInputStream(f);
                repo = GsonUtils.fromJson(new BufferedReader(new InputStreamReader(in)), Repository.class);
                in.close();
                return repo;
            } catch (Exception e) {
                shouldRefresh = true;
            }
        }
    } else {
        shouldRefresh = true;
    }
    if (shouldRefresh || forceUpdate) {
        try {
            final RepositoryService rs = new RepositoryService(context.getGHClient());
            repo = rs.getRepository(owner, name);
            if (repo != null) {
                putRepository(context, repo);
            }
        } catch (Exception e) {
            repo = null;
            e.printStackTrace();
        }
    }
    return repo;
}
Also used : Repository(org.eclipse.egit.github.core.Repository) InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) File(java.io.File) Date(java.util.Date) FileInputStream(java.io.FileInputStream) RepositoryService(org.eclipse.egit.github.core.service.RepositoryService)

Aggregations

Repository (org.eclipse.egit.github.core.Repository)10 SimpleDateFormat (java.text.SimpleDateFormat)4 IOException (java.io.IOException)3 SQLException (android.database.SQLException)2 RAction (io.github.mthli.Bitocle.Database.Repo.RAction)2 Repo (io.github.mthli.Bitocle.Database.Repo.Repo)2 RepositoryService (org.eclipse.egit.github.core.service.RepositoryService)2 Account (android.accounts.Account)1 AccountsException (android.accounts.AccountsException)1 Intent (android.content.Intent)1 Bundle (android.os.Bundle)1 BufferedReader (java.io.BufferedReader)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 InputStreamReader (java.io.InputStreamReader)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 List (java.util.List)1 OAuthUserProvider (net.idlesoft.android.apps.github.authenticator.OAuthUserProvider)1