use of org.eclipse.egit.github.core.client.GitHubClient in project Bitocle by mthli.
the class StarContentTask method onPreExecute.
@Override
protected void onPreExecute() {
context = fragment.getContentView().getContext();
flag = fragment.getFlag();
adapter = fragment.getContentItemAdapter();
list = fragment.getContentItemList();
bookmark = fragment.getBookmark();
GitHubClient client = fragment.getClient();
dataService = new DataService(client);
owner = fragment.getOwner();
name = fragment.getName();
root = fragment.getRoot();
entry = fragment.getEntry();
if (flag == Flag.STAR_CONTENT_FIRST || flag == Flag.STAR_CONTENT_REFRESH) {
fragment.setContentEmpty(false);
fragment.setContentShown(false);
bookmark.setVisible(false);
}
}
use of org.eclipse.egit.github.core.client.GitHubClient in project Bitocle by mthli.
the class MainFragment method onActivityCreated.
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
setContentView(R.layout.main_fragment);
view = getContentView();
setContentEmpty(false);
setContentShown(true);
listView = (ListView) view.findViewById(R.id.main_fragment_listview);
actionBar = getActivity().getActionBar();
ViewGroup group = (ViewGroup) view;
pull = new PullToRefreshLayout(group.getContext());
ActionBarPullToRefresh.from(getActivity()).insertLayoutInto(group).setup(pull);
imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
final Drawable searchIcon = getResources().getDrawable(R.drawable.ic_action_cancel);
search.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (searchIcon != null && event.getAction() == MotionEvent.ACTION_UP) {
int eventX = (int) event.getRawX();
int eventY = (int) event.getRawY();
Rect rectR = new Rect();
search.getGlobalVisibleRect(rectR);
rectR.left = rectR.right - 100;
if (rectR.contains(eventX, eventY)) {
search.setText("");
}
}
return false;
}
});
search.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_SEND) {
String query = search.getText().toString();
if (query.length() > 0) {
if (addTask != null && addTask.getStatus() == AsyncTask.Status.FINISHED) {
addTask = new AddTask(MainFragment.this, query);
addTask.execute();
} else if (addTask == null) {
addTask = new AddTask(MainFragment.this, query);
addTask.execute();
} else {
/* Do nothing */
}
}
}
return false;
}
});
search.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
clickWhenSearchItem(view);
}
});
repoItemAdapter = new RepoItemAdapter(MainFragment.this, view.getContext(), R.layout.repo_item, repoItemList);
repoItemAdapter.notifyDataSetChanged();
listView.setAdapter(repoItemAdapter);
starItemAdapter = new StarItemAdapter(MainFragment.this, view.getContext(), R.layout.repo_item, starItemList);
starItemAdapter.notifyDataSetChanged();
bookmarkItemAdapter = new BookmarkItemAdapter(view.getContext(), R.layout.bookmark_item, bookmarkItemList);
bookmarkItemAdapter.notifyDataSetChanged();
contentItemAdapter = new ContentItemAdapter(view.getContext(), R.layout.content_item, contentItemList);
contentItemAdapter.notifyDataSetChanged();
commitItemAdapter = new CommitItemAdapter(view.getContext(), R.layout.commit_item, commitItemList);
commitItemAdapter.notifyDataSetChanged();
sp = getActivity().getSharedPreferences(getString(R.string.login_sp), Context.MODE_PRIVATE);
String OAuth = sp.getString(getString(R.string.login_sp_oauth), null);
client = new GitHubClient();
client.setOAuth2Token(OAuth);
Intent intent = getActivity().getIntent();
if (intent.getBooleanExtra(getString(R.string.login_intent), false)) {
flag = Flag.REPO_FIRST;
repoTask = new RepoTask(MainFragment.this);
repoTask.execute();
} else {
flag = Flag.REPO_SECOND;
repoTask = new RepoTask(MainFragment.this);
repoTask.execute();
}
currentId = REPO_ID;
toggle = false;
listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);
listView.setMultiChoiceModeListener(new AbsListView.MultiChoiceModeListener() {
@Override
public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) {
Integer integer = listView.getCheckedItemCount();
mode.setTitle(integer.toString());
}
@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
MenuInflater inflater = getActivity().getMenuInflater();
switch(currentId) {
case BOOKMARK_ID:
inflater.inflate(R.menu.bookmark_choice_menu, menu);
return true;
case REPO_CONTENT_ID:
inflater.inflate(R.menu.content_choice_menu, menu);
return true;
case STAR_CONTENT_ID:
inflater.inflate(R.menu.content_choice_menu, menu);
return true;
default:
break;
}
return false;
}
@Override
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
/* Do nothing */
return false;
}
@Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
return clickWhenActionItem(item, view.getContext());
}
@Override
public void onDestroyActionMode(ActionMode mode) {
SparseBooleanArray array = listView.getCheckedItemPositions();
for (int i = 0; i < array.size(); i++) {
if (array.valueAt(i)) {
listView.setItemChecked(i, false);
}
}
}
});
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
switch(currentId) {
case REPO_ID:
clickWhenRepo(position);
break;
case STAR_ID:
clickWhenStar(position);
break;
case BOOKMARK_ID:
clickWhenBookmark(position);
break;
case REPO_CONTENT_ID:
clickWhenRepoContent(position);
break;
case STAR_CONTENT_ID:
clickWhenStarContent(position);
break;
default:
break;
}
}
});
}
use of org.eclipse.egit.github.core.client.GitHubClient in project Bitocle by mthli.
the class StarTask method onPreExecute.
@Override
protected void onPreExecute() {
adapter = fragment.getStarItemAdapter();
list = fragment.getStarItemList();
bookmark = fragment.getBookmark();
GitHubClient client = fragment.getClient();
service = new WatcherService(client);
fragment.setContentEmpty(false);
fragment.setContentShown(false);
bookmark.setVisible(false);
}
use of org.eclipse.egit.github.core.client.GitHubClient in project Bitocle by mthli.
the class CommitTask method onPreExecute.
@Override
protected void onPreExecute() {
flag = fragment.getFlag();
GitHubClient client = fragment.getClient();
commitService = new CommitService(client);
adapter = fragment.getCommitItemAdapter();
list = fragment.getCommitItemList();
fragment.setContentShown(false);
}
use of org.eclipse.egit.github.core.client.GitHubClient in project Bitocle by mthli.
the class WebViewTask method doInBackground.
@Override
protected Boolean doInBackground(Void... params) {
GitHubClient client = fragment.getClient();
RepositoryId id = RepositoryId.create(owner, name);
DataService dataService = new DataService(client);
MarkdownService markdownService = new MarkdownService(client);
Blob blob;
try {
blob = dataService.getBlob(id, sha);
} catch (IOException i) {
return false;
}
if (isCancelled()) {
return false;
}
String base64 = blob.getContent();
if (!MimeType.isImage(filename)) {
byte[] bytes = EncodingUtils.fromBase64(base64);
content = new String(bytes);
}
if (MimeType.isImage(filename)) {
String imageUrl = GetImage.getImageUrl(base64, MimeType.getImageExtension(filename));
image = GetImage.getImage(imageUrl);
} else if (MimeType.isMarkdown(filename)) {
try {
content = markdownService.getHtml(content, MarkdownService.MODE_GFM);
content = StyleMarkdown.styleMarkdown(content);
} catch (IOException i) {
return false;
}
} else {
content = SyntaxCode.syntaxCode(content, css);
}
if (isCancelled()) {
return false;
}
return true;
}
Aggregations