Skip to content

Commit

Permalink
Divide OnUpdateListener
Browse files Browse the repository at this point in the history
close #10
  • Loading branch information
danielpassos committed Dec 6, 2015
1 parent 221bd32 commit 4a2eed4
Show file tree
Hide file tree
Showing 4 changed files with 520 additions and 466 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,15 @@ public interface OnItemClickListener {
/**
* Delegate the click event to the listener and check if selection MULTI enabled.<br/>
* If yes, call toggleActivation.
*
* @param position
* @return true if MULTI selection is enabled, false for SINGLE selection
*/
boolean onListItemClick(int position);

/**
* This always calls toggleActivation after listener event is consumed.
*
* @param position
*/
void onListItemLongClick(int position);
Expand All @@ -56,15 +58,16 @@ public interface OnItemClickListener {
mSelectAll = false;

public ExampleAdapter(Object activity, String listId) {
super(activity);
this.mContext = (Context) activity;
this.mClickListener = (OnItemClickListener) activity;
this.onLoadCompleteListener = (OnLoadCompleteListener) activity;
// updateDataSet(listId);
updateDataSetAsync(listId);
}

/**
* Param, in this example, is not used.
*
* @param param A custom parameter to filter the type of the DataSet
*/
@Override
Expand All @@ -88,7 +91,7 @@ public void setMode(int mode) {
super.setMode(mode);
if (mode == MODE_SINGLE) mLastItemInActionMode = true;
}

@Override
public void selectAll() {
mSelectAll = true;
Expand Down Expand Up @@ -135,7 +138,7 @@ public void onBindViewHolder(SimpleViewHolder holder, final int position) {
//IMPORTANT: Example View finishes here!!
return;
}

//When user scrolls this bind the correct selection status
holder.itemView.setActivated(isSelected(position));

Expand Down Expand Up @@ -199,9 +202,8 @@ private void setHighlightText(TextView textView, String text, String searchText)
/**
* Custom filter.
*
* @param myObject The item to filter
* @param myObject The item to filter
* @param constraint the current searchText
*
* @return true if a match exists in the title or in the subtitle, false if no match found.
*/
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
public class MainActivity extends AppCompatActivity implements
ActionMode.Callback, EditItemDialog.OnEditItemListener,
SearchView.OnQueryTextListener,
FlexibleAdapter.OnUpdateListener,
FlexibleAdapter.OnLoadCompleteListener,
FlexibleAdapter.OnDeleteCompleteListener,
ExampleAdapter.OnItemClickListener {

public static final String TAG = MainActivity.class.getSimpleName();
Expand All @@ -63,21 +64,21 @@ public class MainActivity extends AppCompatActivity implements
private ProgressBar mProgressBar;
private SwipeRefreshLayout mSwipeRefreshLayout;
private final Handler mSwipeHandler = new Handler(Looper.getMainLooper(), new Handler.Callback() {
public boolean handleMessage(Message message) {
switch(message.what) {
case 0: //Stop
mSwipeRefreshLayout.setRefreshing(false);
mSwipeRefreshLayout.setEnabled(true);
return true;
case 1: //1 Start
mSwipeRefreshLayout.setRefreshing(true);
mSwipeRefreshLayout.setEnabled(false);
return true;
default:
return false;
}
public boolean handleMessage(Message message) {
switch (message.what) {
case 0: //Stop
mSwipeRefreshLayout.setRefreshing(false);
mSwipeRefreshLayout.setEnabled(true);
return true;
case 1: //1 Start
mSwipeRefreshLayout.setRefreshing(true);
mSwipeRefreshLayout.setEnabled(false);
return true;
default:
return false;
}
});
}
});
/**
* FAB
*/
Expand Down Expand Up @@ -120,7 +121,8 @@ public void onClick(View v) {
if (!DatabaseService.getInstance().getListById(null).contains(item)) {
DatabaseService.getInstance().addItem(i, item);//This is the original list
//TODO: Use userLearnedSelection from settings
if (!DatabaseService.userLearnedSelection) i++;//Fixing exampleAdapter for new position :-)
if (!DatabaseService.userLearnedSelection)
i++;//Fixing exampleAdapter for new position :-)
mAdapter.addItem(i, item);//Adapter's list is a copy, to animate the item you must call addItem on the new position
Log.d(TAG, "Added New " + item.getTitle());

Expand Down Expand Up @@ -289,7 +291,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
getString(R.string.about_title),
getString(R.string.about_body,
Utils.getVersionName(this),
Utils.getVersionCode(this)) )
Utils.getVersionCode(this)))
.show(getFragmentManager(), MessageDialog.TAG);
return true;
}
Expand All @@ -301,7 +303,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
* Handling RecyclerView when empty.
* <br/><br/>
* <b>Note:</b> The order how the 3 Views (RecyclerView, EmptyView, FastScroller)
* are placed in the Layout is important!
* are placed in the Layout is important!
*/
private void updateEmptyView() {
FastScroller fastScroller = (FastScroller) findViewById(R.id.fast_scroller);
Expand Down Expand Up @@ -367,7 +369,7 @@ public void onListItemLongClick(int position) {
Log.d(TAG, "onListItemLongClick actionMode activated!");
mActionMode = startSupportActionMode(this);
}
Toast.makeText(this, "ImageClick or LongClick on "+mAdapter.getItem(position).getTitle(), Toast.LENGTH_SHORT).show();
Toast.makeText(this, "ImageClick or LongClick on " + mAdapter.getItem(position).getTitle(), Toast.LENGTH_SHORT).show();
toggleSelection(position);
}

Expand All @@ -387,7 +389,7 @@ private void toggleSelection(int position) {
Log.d(TAG, "toggleSelection finish the actionMode");
mActionMode.finish();
} else {
Log.d(TAG, "toggleSelection update title after selection count="+count);
Log.d(TAG, "toggleSelection update title after selection count=" + count);
setContextTitle(count);
mActionMode.invalidate();
}
Expand Down Expand Up @@ -465,7 +467,7 @@ public void onClick(View v) {
}
});
mSnackBar.show();
mAdapter.startUndoTimer(7000L+200L);//+200: Using Snackbar, user can still click on the action button while bar is dismissing for a fraction of time
mAdapter.startUndoTimer(7000L + 200L, this);//+200: Using Snackbar, user can still click on the action button while bar is dismissing for a fraction of time
mSwipeHandler.sendEmptyMessage(1);
mSwipeHandler.sendEmptyMessageDelayed(0, 7000L);
mActionMode.finish();
Expand All @@ -491,6 +493,7 @@ public void onDestroyActionMode(ActionMode mode) {

/**
* Utility method called from MainActivity on BackPressed
*
* @return true if ActionMode was active (in case it is also terminated), false otherwise
*/
public boolean destroyActionModeIfNeeded() {
Expand Down
Loading

0 comments on commit 4a2eed4

Please sign in to comment.