use of org.eclipse.egit.github.core.TreeEntry 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 org.eclipse.egit.github.core.TreeEntry in project Bitocle by mthli.
the class MainFragment method clickWhenStarContent.
private void clickWhenStarContent(int position) {
allTaskDown();
ContentItem item = contentItemList.get(position);
if (item.getEntry().getType().equals("tree")) {
entry = item.getEntry();
String[] arr = entry.getPath().split("/");
title = arr[arr.length - 1];
if (toggle) {
if (prefix.equals("/")) {
subTitle = name + "/" + entry.getPath();
} else {
subTitle = name + "/" + prefix + "/" + entry.getPath();
}
} else {
subTitle = name + "/" + entry.getPath();
}
actionBar.setTitle(title);
actionBar.setSubtitle(subTitle);
actionBar.setDisplayHomeAsUpEnabled(true);
flag = Flag.STAR_CONTENT_SECOND;
currentId = STAR_CONTENT_ID;
starContentTask = new StarContentTask(MainFragment.this);
starContentTask.execute();
} else {
TreeEntry e = item.getEntry();
String[] a = e.getPath().split("/");
String t = a[a.length - 1];
if (MimeType.isUnSupport(t)) {
SuperToast.create(view.getContext(), getString(R.string.webview_unsupport), SuperToast.Duration.VERY_SHORT, Style.getStyle(Style.RED)).show();
} else {
String s;
if (toggle) {
if (prefix.equals("/")) {
s = name + "/" + e.getPath();
} else {
s = name + "/" + prefix + "/" + e.getPath();
}
} else {
s = name + "/" + e.getPath();
}
Intent intent = new Intent(getActivity(), WebViewActivity.class);
intent.putExtra(getString(R.string.webview_intent_title), t);
intent.putExtra(getString(R.string.webview_intent_subtitle), s);
intent.putExtra(getString(R.string.webview_intent_owner), owner);
intent.putExtra(getString(R.string.webview_intent_name), name);
intent.putExtra(getString(R.string.webview_intent_sha), item.getEntry().getSha());
startActivityForResult(intent, 0);
}
}
}
use of org.eclipse.egit.github.core.TreeEntry in project Bitocle by mthli.
the class MainFragment method clickWhenRepoContent.
private void clickWhenRepoContent(int position) {
allTaskDown();
ContentItem item = contentItemList.get(position);
if (item.getEntry().getType().equals("tree")) {
entry = item.getEntry();
String[] arr = entry.getPath().split("/");
title = arr[arr.length - 1];
if (toggle) {
if (prefix.equals("/")) {
subTitle = name + "/" + entry.getPath();
} else {
subTitle = name + "/" + prefix + "/" + entry.getPath();
}
} else {
subTitle = name + "/" + entry.getPath();
}
actionBar.setTitle(title);
actionBar.setSubtitle(subTitle);
actionBar.setDisplayHomeAsUpEnabled(true);
flag = Flag.REPO_CONTENT_SECOND;
currentId = REPO_CONTENT_ID;
repoContentTask = new RepoContentTask(MainFragment.this);
repoContentTask.execute();
} else {
TreeEntry e = item.getEntry();
String[] a = e.getPath().split("/");
String t = a[a.length - 1];
if (MimeType.isUnSupport(t)) {
SuperToast.create(view.getContext(), getString(R.string.webview_unsupport), SuperToast.Duration.VERY_SHORT, Style.getStyle(Style.RED)).show();
} else {
String s;
if (toggle) {
if (prefix.equals("/")) {
s = name + "/" + e.getPath();
} else {
s = name + "/" + prefix + "/" + e.getPath();
}
} else {
s = name + "/" + e.getPath();
}
Intent intent = new Intent(getActivity(), WebViewActivity.class);
intent.putExtra(getString(R.string.webview_intent_title), t);
intent.putExtra(getString(R.string.webview_intent_subtitle), s);
intent.putExtra(getString(R.string.webview_intent_owner), owner);
intent.putExtra(getString(R.string.webview_intent_name), name);
intent.putExtra(getString(R.string.webview_intent_sha), item.getEntry().getSha());
startActivityForResult(intent, 0);
}
}
}
use of org.eclipse.egit.github.core.TreeEntry in project Bitocle by mthli.
the class RepoContentTask method onPostExecute.
@Override
protected void onPostExecute(Boolean result) {
if (result) {
if (flag == Flag.REPO_CONTENT_FIRST || flag == Flag.REPO_CONTENT_REFRESH) {
fragment.setRoot(root);
}
List<TreeEntry> entries = root.getTree();
if (flag == Flag.REPO_CONTENT_FIRST || flag == Flag.REPO_CONTENT_REFRESH) {
list.clear();
for (TreeEntry e : entries) {
String[] a = e.getPath().split("/");
if (a.length == 1) {
list.add(new ContentItem(e));
}
}
Collections.sort(list);
if (list.size() <= 0) {
bookmark.setVisible(false);
fragment.setContentEmpty(true);
fragment.setEmptyText(R.string.content_empty_list);
fragment.setContentShown(true);
} else {
bookmark.setVisible(true);
fragment.setContentEmpty(false);
adapter.notifyDataSetChanged();
fragment.setContentShown(true);
}
} else {
list.clear();
String[] a = entry.getPath().split("/");
for (TreeEntry e : entries) {
String[] r = e.getPath().split("/");
if ((r.length - 1 == a.length) && e.getPath().startsWith(entry.getPath())) {
list.add(new ContentItem(e));
}
}
Collections.sort(list);
if (list.size() <= 0) {
bookmark.setVisible(false);
fragment.setContentEmpty(true);
fragment.setEmptyText(R.string.content_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.content_empty_error);
fragment.setContentShown(true);
}
}
use of org.eclipse.egit.github.core.TreeEntry in project Bitocle by mthli.
the class MainFragment method backToPrevious.
public void backToPrevious() {
allTaskDown();
String path;
try {
path = entry.getPath();
} catch (NullPointerException n) {
switch(currentId) {
case REPO_CONTENT_ID:
changeToRepo(Flag.REPO_SECOND);
break;
case STAR_CONTENT_ID:
changeToStar(false);
break;
default:
break;
}
return;
}
contentItemList.clear();
if (path.split("/").length <= 1) {
for (TreeEntry e : root.getTree()) {
String[] a = e.getPath().split("/");
if (a.length == 1) {
contentItemList.add(new ContentItem(e));
}
}
if (toggle) {
title = prefix.split("/")[prefix.split("/").length - 1];
subTitle = name + "/" + prefix;
} else {
title = name;
subTitle = name;
}
actionBar.setTitle(title);
actionBar.setSubtitle(subTitle);
actionBar.setDisplayHomeAsUpEnabled(true);
entry = null;
} else {
String[] a = path.split("/");
String str = a[0];
for (int i = 1; i < a.length - 1; i++) {
str = str + "/" + a[i];
}
for (TreeEntry e : root.getTree()) {
String[] r = e.getPath().split("/");
if ((r.length - 1 == str.split("/").length) && e.getPath().startsWith(str)) {
contentItemList.add(new ContentItem(e));
}
if (e.getPath().equals(str)) {
entry = e;
}
}
title = str.split("/")[str.split("/").length - 1];
if (toggle) {
subTitle = name + "/" + prefix + "/" + str;
} else {
subTitle = name + "/" + str;
}
actionBar.setTitle(title);
actionBar.setSubtitle(subTitle);
actionBar.setDisplayHomeAsUpEnabled(true);
}
Collections.sort(contentItemList);
contentItemAdapter.notifyDataSetChanged();
}
Aggregations