use of io.github.mthli.Bitocle.Database.Bookmark.BAction in project Bitocle by mthli.
the class MainActivity method logoutAction.
private void logoutAction() {
RAction rAction = new RAction(MainActivity.this);
BAction bAction = new BAction(MainActivity.this);
try {
rAction.openDatabase(true);
bAction.openDatabase(true);
rAction.deleteAll();
bAction.unMarkAll();
rAction.closeDatabase();
bAction.closeDatabase();
} catch (SQLException s) {
rAction.closeDatabase();
bAction.closeDatabase();
SuperToast.create(MainActivity.this, getString(R.string.main_logout_failed), SuperToast.Duration.VERY_SHORT, Style.getStyle(Style.RED)).show();
}
SharedPreferences preferences = getSharedPreferences(getString(R.string.login_sp), MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
editor.remove(getString(R.string.login_sp_oauth));
editor.remove(getString(R.string.login_sp_username));
editor.remove(getString(R.string.login_sp_highlight_num));
editor.remove(getString(R.string.login_sp_highlight_css));
editor.commit();
fragment.allTaskDown();
Intent intent = new Intent(MainActivity.this, LoginActivity.class);
startActivity(intent);
MainActivity.this.finish();
}
use of io.github.mthli.Bitocle.Database.Bookmark.BAction in project Bitocle by mthli.
the class MainFragment method clickWhenActionItem.
private boolean clickWhenActionItem(MenuItem item, Context context) {
BAction action = new BAction(context);
try {
action.openDatabase(true);
} catch (SQLException s) {
SuperToast.create(context, getString(R.string.content_database_error), SuperToast.Duration.VERY_SHORT, Style.getStyle(Style.RED)).show();
return false;
}
SparseBooleanArray array = listView.getCheckedItemPositions();
switch(item.getItemId()) {
case R.id.content_choice_add:
for (int i = 0; i < array.size(); i++) {
if (array.valueAt(i)) {
ContentItem c = contentItemAdapter.getItem(array.keyAt(i));
TreeEntry e = c.getEntry();
if (!action.checkBookmark(e.getSha())) {
Bookmark b = new Bookmark();
String[] arr = e.getPath().split("/");
b.setTitle(arr[arr.length - 1]);
b.setType(e.getType());
b.setOwner(owner);
b.setName(name);
if (toggle) {
if (prefix.equals("/")) {
b.setPath(e.getPath());
} else {
b.setPath(prefix + "/" + e.getPath());
}
} else {
b.setPath(e.getPath());
}
b.setSha(e.getSha());
b.setKey(owner + "/" + name);
action.addBookmark(b);
}
listView.setItemChecked(i, false);
}
}
SuperToast.create(context, getString(R.string.content_add_successful), SuperToast.Duration.VERY_SHORT, Style.getStyle(Style.BLUE)).show();
break;
case R.id.bookmark_choice_remove:
for (int i = 0; i < array.size(); i++) {
if (array.valueAt(i)) {
BookmarkItem b = bookmarkItemAdapter.getItem(array.keyAt(i));
action.unMarkBySha(b.getSha());
listView.setItemChecked(i, false);
}
}
SuperToast.create(context, getString(R.string.bookmark_remove_successful), SuperToast.Duration.VERY_SHORT, Style.getStyle(Style.BLUE)).show();
bookmarkTask = new BookmarkTask(MainFragment.this);
bookmarkTask.execute();
break;
default:
break;
}
action.closeDatabase();
return true;
}
use of io.github.mthli.Bitocle.Database.Bookmark.BAction in project Bitocle by mthli.
the class RepoItemAdapter 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 RepoItem repoItem = list.get(position);
holder.icon.setImageDrawable(context.getResources().getDrawable(R.drawable.ic_type_repo));
holder.name.setText(repoItem.getName());
holder.date.setText(repoItem.getDate());
String description;
try {
description = repoItem.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 = repoItem.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) + " " + repoItem.getStar() + " " + context.getString(R.string.repo_item_fork) + " " + repoItem.getFork());
holder.owner.setText(repoItem.getOwner());
final PopupMenu menu = new PopupMenu(context, holder.overflow);
menu.getMenuInflater().inflate(R.menu.repo_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.repo_item_overflow_commit:
fragment.setLocation(position);
fragment.changeToCommit(Flag.REPO_COMMIT_FIRST);
break;
case R.id.repo_item_overflow_remove:
RAction rAction = new RAction(context);
BAction bAction = new BAction(context);
try {
rAction.openDatabase(true);
bAction.openDatabase(true);
} catch (SQLException s) {
rAction.closeDatabase();
bAction.closeDatabase();
SuperToast.create(context, context.getString(R.string.overflow_remove_failed), SuperToast.Duration.VERY_SHORT, Style.getStyle(Style.RED)).show();
return false;
}
rAction.deleteRepo(repoItem.getGit());
String key = repoItem.getOwner() + "/" + repoItem.getName();
bAction.unMarkByKey(key);
rAction.closeDatabase();
bAction.closeDatabase();
list.remove(position);
List<Map<String, String>> autoList = new ArrayList<Map<String, String>>();
autoList.clear();
for (RepoItem r : list) {
Map<String, String> map = new HashMap<String, String>();
map.put("owner", r.getOwner());
map.put("name", r.getName());
autoList.add(map);
}
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);
fragment.getRepoItemAdapter().notifyDataSetChanged();
fragment.setContentShown(true);
SuperToast.create(context, context.getString(R.string.overflow_remove_successful), SuperToast.Duration.VERY_SHORT, Style.getStyle(Style.BLUE)).show();
}
break;
default:
break;
}
return true;
}
});
return view;
}
use of io.github.mthli.Bitocle.Database.Bookmark.BAction in project Bitocle by mthli.
the class BookmarkTask method doInBackground.
@Override
protected Boolean doInBackground(Void... params) {
BAction action = new BAction(context);
try {
action.openDatabase(true);
} catch (SQLException s) {
action.closeDatabase();
return false;
}
bookmarks = action.listBookmarks();
Collections.sort(bookmarks);
action.closeDatabase();
if (isCancelled()) {
return false;
}
return true;
}
Aggregations