use of android.database.SQLException in project Bitocle by mthli.
the class AddTask method onPostExecute.
@Override
protected void onPostExecute(Boolean result) {
pull.setRefreshing(false);
if (result) {
RAction action = new RAction(context);
try {
action.openDatabase(true);
} catch (SQLException s) {
SuperToast.create(fragment.getActivity(), context.getString(R.string.repo_add_failed), SuperToast.Duration.VERY_SHORT, Style.getStyle(Style.RED)).show();
return;
}
List<Repo> repos = action.listRepos();
Collections.sort(repos);
List<Map<String, String>> autoList = new ArrayList<Map<String, String>>();
list.clear();
autoList.clear();
for (Repo r : repos) {
list.add(new RepoItem(r.getName(), r.getDate(), r.getDescription(), r.getLang(), r.getStar(), r.getFork(), r.getOwner(), r.getGit()));
Map<String, String> map = new HashMap<String, String>();
map.put("owner", r.getOwner());
map.put("name", r.getName());
autoList.add(map);
}
action.closeDatabase();
SimpleAdapter autoAdapter = new SimpleAdapter(context, autoList, R.layout.auto_item, new String[] { "owner", "name" }, new int[] { R.id.auto_item_owner, R.id.auto_item_name });
autoAdapter.notifyDataSetChanged();
fragment.getSearch().setAdapter(autoAdapter);
if (list.size() <= 0) {
fragment.setContentEmpty(true);
fragment.setEmptyText(R.string.repo_empty_list);
fragment.setContentShown(true);
} else {
int position = 0;
for (RepoItem r : list) {
if (r.getGit().equals(git)) {
break;
}
position++;
}
fragment.setContentEmpty(false);
adapter.notifyDataSetChanged();
fragment.setContentShown(true);
listView.smoothScrollToPosition(position);
SuperToast.create(fragment.getActivity(), context.getString(R.string.repo_add_successful), SuperToast.Duration.VERY_SHORT, Style.getStyle(Style.BLUE)).show();
}
} else {
SuperToast.create(fragment.getActivity(), context.getString(R.string.repo_add_failed), SuperToast.Duration.VERY_SHORT, Style.getStyle(Style.RED)).show();
}
}
use of android.database.SQLException in project Bitocle by mthli.
the class AddTask method doInBackground.
@Override
protected Boolean doInBackground(Void... params) {
String[] arr = query.split("/");
if (arr.length < 2) {
return false;
}
String owner = arr[0].toLowerCase();
String name = arr[1].toLowerCase();
Repository r;
try {
r = service.getRepository(owner, name);
} catch (IOException i) {
return false;
}
if (isCancelled()) {
return false;
}
RAction action = new RAction(context);
try {
action.openDatabase(true);
} catch (SQLException s) {
action.closeDatabase();
return false;
}
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
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());
git = r.getGitUrl();
action.addRepo(repo);
}
action.closeDatabase();
if (isCancelled()) {
return false;
}
return true;
}
use of android.database.SQLException in project Bitocle by mthli.
the class RepoTask method onPostExecute.
@Override
protected void onPostExecute(Boolean result) {
if (result) {
RAction action = new RAction(context);
try {
action.openDatabase(true);
} catch (SQLException s) {
fragment.setContentEmpty(true);
fragment.setEmptyText(R.string.repo_empty_error);
fragment.setContentShown(true);
return;
}
List<Repo> repos = action.listRepos();
Collections.sort(repos);
List<Map<String, String>> autoList = new ArrayList<Map<String, String>>();
list.clear();
autoList.clear();
for (Repo r : repos) {
list.add(new RepoItem(r.getName(), r.getDate(), r.getDescription(), r.getLang(), r.getStar(), r.getFork(), r.getOwner(), r.getGit()));
Map<String, String> map = new HashMap<String, String>();
map.put("owner", r.getOwner());
map.put("name", r.getName());
autoList.add(map);
}
action.closeDatabase();
SimpleAdapter autoAdapter = new SimpleAdapter(context, autoList, R.layout.auto_item, new String[] { "owner", "name" }, new int[] { R.id.auto_item_owner, R.id.auto_item_name });
autoAdapter.notifyDataSetChanged();
fragment.getSearch().setAdapter(autoAdapter);
if (list.size() <= 0) {
fragment.setContentEmpty(true);
fragment.setEmptyText(R.string.repo_empty_list);
fragment.setContentShown(true);
} else {
fragment.setContentEmpty(false);
adapter.notifyDataSetChanged();
fragment.setContentShown(true);
}
if (flag == Flag.REPO_REFRESH) {
SuperToast.create(context, context.getString(R.string.repo_refresh_successful), SuperToast.Duration.VERY_SHORT, Style.getStyle(Style.BLUE)).show();
}
} else {
fragment.setContentEmpty(true);
fragment.setEmptyText(R.string.repo_empty_error);
fragment.setContentShown(true);
}
}
use of android.database.SQLException 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 android.database.SQLException in project Bitocle by mthli.
the class StarItemAdapter method getView.
@Override
public View getView(final int position, final View convertView, ViewGroup viewGroup) {
Holder holder;
View view = convertView;
if (view == null) {
LayoutInflater inflater = ((Activity) context).getLayoutInflater();
view = inflater.inflate(layoutResId, viewGroup, false);
holder = new Holder();
holder.icon = (ImageView) view.findViewById(R.id.repo_item_icon);
holder.name = (TextView) view.findViewById(R.id.repo_item_name);
holder.date = (TextView) view.findViewById(R.id.repo_item_date);
holder.description = (TextView) view.findViewById(R.id.repo_item_description);
holder.info = (TextView) view.findViewById(R.id.repo_item_info);
holder.owner = (TextView) view.findViewById(R.id.repo_item_owner);
holder.overflow = (ImageButton) view.findViewById(R.id.repo_item_overflow);
view.setTag(holder);
} else {
holder = (Holder) view.getTag();
}
final StarItem starItem = list.get(position);
holder.icon.setImageDrawable(context.getResources().getDrawable(R.drawable.ic_type_repo));
holder.name.setText(starItem.getName());
holder.date.setText(starItem.getDate());
String description;
try {
description = starItem.getDescription();
if (description.length() == 0) {
description = context.getString(R.string.repo_empty_description);
}
} catch (NullPointerException n) {
description = context.getString(R.string.repo_empty_description);
}
holder.description.setText(description);
String lang;
try {
lang = starItem.getLang();
if (lang.equals("null")) {
lang = context.getString(R.string.repo_item_unknown);
}
} catch (NullPointerException n) {
lang = context.getString(R.string.repo_item_unknown);
}
holder.info.setText(lang + " " + context.getString(R.string.repo_item_star) + " " + starItem.getStar() + " " + context.getString(R.string.repo_item_fork) + " " + starItem.getFork());
holder.owner.setText(starItem.getOwner());
final PopupMenu menu = new PopupMenu(context, holder.overflow);
menu.getMenuInflater().inflate(R.menu.star_item_overflow, menu.getMenu());
holder.overflow.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
menu.show();
}
});
menu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
switch(item.getItemId()) {
case R.id.star_item_overflow_commit:
fragment.setLocation(position);
fragment.changeToCommit(Flag.STAR_COMMIT_FIRST);
break;
case R.id.star_item_overflow_add:
RAction action = new RAction(context);
try {
action.openDatabase(true);
} catch (SQLException s) {
action.closeDatabase();
SuperToast.create(context, context.getString(R.string.overflow_add_failed), SuperToast.Duration.VERY_SHORT, Style.getStyle(Style.RED)).show();
return false;
}
if (!action.checkRepo(starItem.getGit())) {
Repo repo = new Repo();
repo.setName(starItem.getName());
repo.setDate(starItem.getDate());
repo.setDescription(starItem.getDescription());
if (starItem.getLang() == null) {
repo.setLang(context.getString(R.string.repo_item_unknown));
} else {
repo.setLang(starItem.getLang());
}
repo.setStar(starItem.getStar());
repo.setFork(starItem.getFork());
repo.setOwner(starItem.getOwner());
repo.setGit(starItem.getGit());
action.addRepo(repo);
}
action.closeDatabase();
SuperToast.create(context, context.getString(R.string.overflow_add_successful), SuperToast.Duration.VERY_SHORT, Style.getStyle(Style.BLUE)).show();
break;
default:
break;
}
//
return true;
}
});
return view;
}
Aggregations