Skip to content

Commit

Permalink
v4.2.0 Removed static declaration from the search methods
Browse files Browse the repository at this point in the history
  • Loading branch information
davideas committed Dec 10, 2015
1 parent 955dccf commit 0ac3e92
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 37 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,14 +157,15 @@ public class YourAdapterClass extends FlexibleAdapter<ExampleAdapter.SimpleViewH
```

# Change Log
###### v4.2.0 - 2015.12.10
###### v4.2.0 - 2015.12.12
- Added _isEmpty()_.
- Added new constructor to initialize list items [See #12].
- Moved _onDeletedConfirmed()_ in a new listener to pass as parameter to the method _startUndoTimer()_ [See #10].
- Deprecated _OnUpdateListener_ and some relative functions.
- **Note:** _updateDataSetAsync()_ has been **deprecated** and will be removed soon from next major version. Use _updateDataSet()_
instead. **FilterAsyncTask** will not be used anymore to load data at startup: there's no advantage to use an Asynchronous loading,
usually the list is already loaded Asynchronously somewhere else.
- Removed _static_ declaration from the following methods: _hasSearchText(); getSearchText(); setSearchText(String searchText)_.
- Adapted example App accordingly.

###### v4.1.0 - 2015.11.29
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ ext {
//Library
libraryCode = 10
libraryVersion = '4.2.0'
libraryDate = " of 2015.12.10"
libraryDate = " of 2015.12.12"
libraryDescription = 'A pattern for every RecyclerView'
libraryName = 'FlexibleAdapter'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,27 +225,27 @@ public boolean onPrepareOptionsMenu(Menu menu) {
Log.v(TAG, "onPrepareOptionsMenu called!");
SearchView searchView = (SearchView) menu.findItem(R.id.action_search).getActionView();
//Has searchText?
if (!ExampleAdapter.hasSearchText()) {
if (!mAdapter.hasSearchText()) {
Log.d(TAG, "onPrepareOptionsMenu Clearing SearchView!");
searchView.setIconified(true);// This also clears the text in SearchView widget
} else {
searchView.setQuery(ExampleAdapter.getSearchText(), false);
searchView.setQuery(mAdapter.getSearchText(), false);
searchView.setIconified(false);
}
return super.onPrepareOptionsMenu(menu);
}

@Override
public boolean onQueryTextChange(String newText) {
if (!ExampleAdapter.hasSearchText()
|| !ExampleAdapter.getSearchText().equalsIgnoreCase(newText)) {
if (!mAdapter.hasSearchText()
|| !mAdapter.getSearchText().equalsIgnoreCase(newText)) {
Log.d(TAG, "onQueryTextChange newText: " + newText);
ExampleAdapter.setSearchText(newText);
mAdapter.setSearchText(newText);
//Filter the items and notify the change!
mAdapter.updateDataSet();
}

if (ExampleAdapter.hasSearchText()) {
if (mAdapter.hasSearchText()) {
//mFab.setVisibility(View.GONE);
ViewCompat.animate(mFab)
.scaleX(0f)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,8 @@ public abstract class FlexibleAdapter<VH extends RecyclerView.ViewHolder, T> ext
protected List<T> mItems;
protected List<T> mDeletedItems;
protected List<Integer> mOriginalPosition;
//Searchable fields
protected static String mSearchText; //Static: It can exist only 1 searchText

protected String mSearchText;
protected Handler mHandler;

protected OnUpdateListener mUpdateListener;

public FlexibleAdapter() {
Expand Down Expand Up @@ -384,15 +381,15 @@ private void stopUndoTimer() {
}
}

public static boolean hasSearchText() {
public boolean hasSearchText() {
return mSearchText != null && mSearchText.length() > 0;
}

public static String getSearchText() {
public String getSearchText() {
return mSearchText;
}

public static void setSearchText(String searchText) {
public void setSearchText(String searchText) {
if (searchText != null)
mSearchText = searchText.trim().toLowerCase(Locale.getDefault());
else mSearchText = "";
Expand Down Expand Up @@ -497,9 +494,7 @@ protected void onPostExecute(Void result) {
}
}

/**
* This interface will contains only
*/

@Deprecated
public interface OnUpdateListener {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
public abstract class SelectableAdapter<VH extends RecyclerView.ViewHolder> extends RecyclerView.Adapter<VH> {

private static final String TAG = SelectableAdapter.class.getSimpleName();

/**
* Default mode for selection
*/
Expand All @@ -36,10 +37,11 @@ public SelectableAdapter() {
/**
* Set the mode of the selection, MODE_SINGLE is the default:
* <ul>
* <li>if {@link #MODE_SINGLE}, it will switch the selection position (previous selection is cleared automatically);
* <li>if {@link #MODE_MULTI}, it will add the position to the list of the items selected.
* <li>{@link #MODE_SINGLE} configures the adapter to react at the single tap over an item
* (previous selection is cleared automatically);
* <li>{@link #MODE_MULTI} configures the adapter to save the position to the list of the
* selected items.
* </ul>
* <b>NOTE:</b> #mModeMultiJustFinished is set true when #MODE_MULTI is finished.
*
* @param mode MODE_SINGLE or MODE_MULTI
*/
Expand All @@ -59,7 +61,7 @@ public int getMode() {
}

/**
* Indicates if the item at position position is selected.
* Indicates if the item, at the provided position, is selected.
*
* @param position Position of the item to check.
* @return true if the item is selected, false otherwise.
Expand All @@ -82,24 +84,26 @@ public void toggleSelection(int position) {
* Toggle the selection status of the item at a given position.<br/>
* The behaviour depends on the selection mode previously set with {@link #setMode}.
* <p/>
* <br/><br/>
* Optionally the item can be invalidated.<br/>
* However it is preferable to set <i>false</i> and to handle the Activated/Selected State of
* the ItemView in the Click events of the ViewHolder after the selection is registered and
* up to date: Very Useful if the item has views with own animation to perform!
* <p/>
* <br/><br/>
* <b>Usage:</b>
* <ul>
* <li>If you don't want any item to be selected/activated at all, just don't call this method.</li>
* <li>To have actually the item visually selected you need to add a custom <i>Selector Drawable</i> to your layout/view of the Item.
* It's preferable: <i>android:background="?attr/selectableItemBackground"</i> in your layout, pointing to a custom Drawable in the style.xml
* (note: prefix <i>?android:attr</i> seems to <u>not</u> work).</li>
* <li>In <i>onClick</i>, enable the Activated/Selected State of the ItemView of the ViewHolder <u>after</u> the listener consumed the event:
* <li>To have actually the item visually selected you need to add a custom <i>Selector Drawable</i>
* to your layout/view of the Item. It's preferable to set in your layout:
* <i>android:background="?attr/selectableItemBackground"</i>, pointing to a custom Drawable
* in the style.xml (note: prefix <i>?android:attr</i> <u>doesn't</u> work).</li>
* <li>In <i>onClick</i> event, enable the Activated/Selected State of the ItemView of the
* ViewHolder <u>after</u> the listener consumed the event:
* <i>itemView.setActivated(mAdapter.isSelected(getAdapterPosition()));</i></li>
* <li>In <i>onBindViewHolder</i>, adjust the selection status: <i>holder.itemView.setActivated(isSelected(position));</i></li>
* <li>If <i>invalidate</i> is set true, {@link #notifyItemChanged} is called and {@link #onBindViewHolder} will be automatically called
* afterwards overriding any animation in the ItemView!</li>
* <li>In <i>onBindViewHolder</i>, adjust the selection status:
* <i>holder.itemView.setActivated(isSelected(position));</i></li>
* <li>If <i>invalidate</i> is set true, {@link #notifyItemChanged} is called and
* {@link #onBindViewHolder} will be automatically called afterwards overriding any animation
* inside the ItemView!</li>
* </ul>
*
* @param position Position of the item to toggle the selection status for.
Expand All @@ -125,16 +129,16 @@ public void toggleSelection(int position, boolean invalidate) {
}

/**
* Convenience method when there is nothing to skip.
* Convenience method when there is no specific view to skip.
*/
public void selectAll() {
selectAll(-1);
}

/**
* Add the selection status for all items.
* Add the selection status for all items.<br/>
* The selector container is sequentially filled with All items positions.
* <br/><b>Note:</b> All items are invalidated and rebinded!
* <br/><b>Note:</b> All items are invalidated and rebound one by one!
*
* @param skipViewType ViewType for which we don't want selection
*/
Expand All @@ -150,9 +154,9 @@ public void selectAll(int skipViewType) {
}

/**
* Clear the selection status for all items one by one to not kill animations in the items.
* <br/><br/>
* <b>Note 1:</b> Items are invalidated and rebinded!<br/>
* Clear the selection status for all items one by one and it doesn't stop animations in the items.
* <p/>
* <b>Note 1:</b> Items are invalidated and rebound!<br/>
* <b>Note 2:</b> This method use java.util.Iterator to avoid java.util.ConcurrentModificationException.
*/
public void clearSelection() {
Expand Down

0 comments on commit 0ac3e92

Please sign in to comment.