use of io.github.mthli.Bitocle.Bookmark.BookmarkItemAdapter 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;
}
}
});
}
Aggregations