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;
}
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;
}
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;
}
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);
}
}
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;
}
Aggregations