diff --git a/flexible-adapter-app/src/main/java/eu/davidea/samples/flexibleadapter/MainActivity.java b/flexible-adapter-app/src/main/java/eu/davidea/samples/flexibleadapter/MainActivity.java
index 13be3acf..53a6961d 100644
--- a/flexible-adapter-app/src/main/java/eu/davidea/samples/flexibleadapter/MainActivity.java
+++ b/flexible-adapter-app/src/main/java/eu/davidea/samples/flexibleadapter/MainActivity.java
@@ -30,7 +30,6 @@
import android.support.v7.widget.helper.ItemTouchHelper;
import android.text.InputType;
import android.transition.Fade;
-import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
@@ -50,6 +49,8 @@
import eu.davidea.flexibleadapter.helpers.UndoHelper;
import eu.davidea.flexibleadapter.items.AbstractFlexibleItem;
import eu.davidea.flexibleadapter.items.IFlexible;
+import eu.davidea.flexibleadapter.utils.Log;
+import eu.davidea.flexibleadapter.utils.Log.Level;
import eu.davidea.samples.flexibleadapter.dialogs.EditItemDialog;
import eu.davidea.samples.flexibleadapter.dialogs.MessageDialog;
import eu.davidea.samples.flexibleadapter.fragments.AbstractFragment;
@@ -112,8 +113,6 @@ public class MainActivity extends AppCompatActivity implements
NavigationView.OnNavigationItemSelectedListener,
OnFragmentInteractionListener {
- public static final String TAG = MainActivity.class.getSimpleName();
-
/**
* Bundle key representing the Active Fragment
*/
@@ -170,8 +169,8 @@ protected void onCreate(Bundle savedInstanceState) {
}
setContentView(R.layout.activity_main);
- Log.d(TAG, "onCreate");
- FlexibleAdapter.enableLogs(true);
+ FlexibleAdapter.enableLogs(Level.DEBUG);
+ Log.v("onCreate");
// Initialize Toolbar, Drawer & FAB
initializeToolbar();
@@ -187,7 +186,7 @@ protected void onCreate(Bundle savedInstanceState) {
@Override
public void onSaveInstanceState(Bundle outState) {
- Log.v(TAG, "onSaveInstanceState!");
+ Log.v("onSaveInstanceState!");
mAdapter.onSaveInstanceState(outState);
getSupportFragmentManager().putFragment(outState, STATE_ACTIVE_FRAGMENT, mFragment);
super.onSaveInstanceState(outState);
@@ -264,7 +263,7 @@ public void onRefresh() {
}
private void initializeToolbar() {
- Log.d(TAG, "initializeToolbar as actionBar");
+ Log.d("initializeToolbar as actionBar");
mToolbar = (Toolbar) findViewById(R.id.toolbar);
mHeaderView = (HeaderView) findViewById(R.id.toolbar_header_view);
mHeaderView.bindTo(getString(R.string.app_name), getString(R.string.overall));
@@ -446,7 +445,7 @@ private void showFab() {
@Override
public void initSearchView(final Menu menu) {
// Associate searchable configuration with the SearchView
- Log.d(TAG, "onCreateOptionsMenu setup SearchView!");
+ Log.d("onCreateOptionsMenu setup SearchView!");
SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
MenuItem searchItem = menu.findItem(R.id.action_search);
if (searchItem != null) {
@@ -482,7 +481,7 @@ public boolean onMenuItemActionCollapse(MenuItem item) {
@Override
public boolean onQueryTextChange(String newText) {
if (mAdapter.hasNewSearchText(newText)) {
- Log.d(TAG, "onQueryTextChange newText: " + newText);
+ Log.d("onQueryTextChange newText: " + newText);
mAdapter.setSearchText(newText);
// Fill and Filter mItems with your custom list and automatically animate the changes
@@ -499,7 +498,7 @@ public boolean onQueryTextChange(String newText) {
@Override
public boolean onQueryTextSubmit(String query) {
- Log.v(TAG, "onQueryTextSubmit called!");
+ Log.v("onQueryTextSubmit called!");
return onQueryTextChange(query);
}
@@ -509,12 +508,12 @@ public boolean onQueryTextSubmit(String query) {
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
- Log.v(TAG, "onPrepareOptionsMenu called!");
+ Log.v("onPrepareOptionsMenu called!");
if (mSearchView != null) {
//Has searchText?
if (!mAdapter.hasSearchText()) {
- Log.d(TAG, "onPrepareOptionsMenu Clearing SearchView!");
+ Log.d("onPrepareOptionsMenu Clearing SearchView!");
mSearchView.setIconified(true);// This also clears the text in SearchView widget
} else {
//Necessary after the restoreInstanceState
@@ -701,7 +700,7 @@ public boolean onItemClick(int position) {
// Action on elements are allowed if Mode is IDLE, otherwise selection has priority
if (mAdapter.getMode() != SelectableAdapter.MODE_IDLE && mActionModeHelper != null) {
boolean activate = mActionModeHelper.onClick(position);
- Log.d(TAG, "Last activated position " + mActionModeHelper.getActivatedPosition());
+ Log.d("Last activated position %s", mActionModeHelper.getActivatedPosition());
return activate;
} else {
// Notify the active callbacks or implement a custom action onClick
@@ -749,8 +748,7 @@ public void onItemMove(int fromPosition, int toPosition) {
@Override
public void onItemSwipe(final int position, int direction) {
- Log.i(TAG, "onItemSwipe position=" + position +
- " direction=" + (direction == ItemTouchHelper.LEFT ? "LEFT" : "RIGHT"));
+ Log.i("onItemSwipe position=%s direction=%s", position, (direction == ItemTouchHelper.LEFT ? "LEFT" : "RIGHT"));
// Option 1 FULL_SWIPE: Direct action no Undo Action
// Do something based on direction when item has been swiped:
@@ -829,7 +827,7 @@ public void onPostAction() {
*/
@Override
public void onUpdateEmptyView(int size) {
- Log.d(TAG, "onUpdateEmptyView size=" + size);
+ Log.d("onUpdateEmptyView size=%s", size);
FastScroller fastScroller = (FastScroller) findViewById(R.id.fast_scroller);
View emptyView = findViewById(R.id.empty_view);
TextView emptyText = (TextView) findViewById(R.id.empty_text);
@@ -891,12 +889,12 @@ public void onDeleteConfirmed(int action) {
case R.layout.recycler_sub_item:
SubItem subItem = (SubItem) adapterItem;
DatabaseService.getInstance().removeSubItem(mAdapter.getExpandableOfDeletedChild(subItem), subItem);
- Log.d(TAG, "Confirm removed " + subItem);
+ Log.d("Confirm removed %s", subItem);
break;
case R.layout.recycler_simple_item:
case R.layout.recycler_expandable_item:
DatabaseService.getInstance().removeItem(adapterItem);
- Log.d(TAG, "Confirm removed " + adapterItem);
+ Log.d("Confirm removed %s", adapterItem);
break;
}
}
diff --git a/flexible-adapter/src/main/java/eu/davidea/fastscroller/FastScroller.java b/flexible-adapter/src/main/java/eu/davidea/fastscroller/FastScroller.java
index 441680fb..743556b0 100644
--- a/flexible-adapter/src/main/java/eu/davidea/fastscroller/FastScroller.java
+++ b/flexible-adapter/src/main/java/eu/davidea/fastscroller/FastScroller.java
@@ -32,7 +32,6 @@
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.StaggeredGridLayoutManager;
import android.util.AttributeSet;
-import android.util.Log;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
@@ -47,6 +46,7 @@
import java.util.List;
import eu.davidea.flexibleadapter.R;
+import eu.davidea.flexibleadapter.utils.Log;
import static java.lang.annotation.RetentionPolicy.SOURCE;
@@ -56,9 +56,9 @@
* @see
* github.com/AndroidDeveloperLB/LollipopContactsRecyclerViewFastScroller
* @since Up to the date 23/01/2016
- *
23/01/2016 Added onFastScrollerStateChange in the listener
- *
10/03/2017 Added autoHide, bubblePosition, bubbleEnabled, ignoreTouchesOutsideHandle (thanks to @arpinca)
- *
22/04/2017 Added minimum scroll threshold
+ *
23/01/2016 Added onFastScrollerStateChange in the listener
+ *
10/03/2017 Added autoHide, bubblePosition, bubbleEnabled, ignoreTouchesOutsideHandle (thanks to @arpinca)
+ *
22/04/2017 Added minimum scroll threshold
*/
public class FastScroller extends FrameLayout {
@@ -205,7 +205,7 @@ protected void notifyScrollStateChange(boolean scrolling) {
}
/**
- * Layout customization.
+ * Layout customization.
* Color for Selected State is the bubbleAndHandleColor defined inside the Drawables.
*
* @param layoutResId Main layout of Fast Scroller
@@ -232,7 +232,7 @@ public void setViewsToUse(@LayoutRes int layoutResId, @IdRes int bubbleResId, @I
}
/**
- * Layout customization
+ * Layout customization
* Color for Selected State is also customized by the user.
*
* @param layoutResId Main layout of Fast Scroller
@@ -288,7 +288,7 @@ public void setBubbleAndHandleColor(@ColorInt int color) {
handle.setImageDrawable(stateListDrawable);
} catch (Exception e) {
// This should never happen in theory (Java Reflection Exception)
- Log.e(FastScroller.class.getSimpleName(), "Exception while setting Bubble and Handle Color", e);
+ Log.wtf(e, "Exception while setting Bubble and Handle Color");
}
}
}
diff --git a/flexible-adapter/src/main/java/eu/davidea/flexibleadapter/AnimatorAdapter.java b/flexible-adapter/src/main/java/eu/davidea/flexibleadapter/AnimatorAdapter.java
index 4e0e4dbf..e665bd7d 100644
--- a/flexible-adapter/src/main/java/eu/davidea/flexibleadapter/AnimatorAdapter.java
+++ b/flexible-adapter/src/main/java/eu/davidea/flexibleadapter/AnimatorAdapter.java
@@ -26,7 +26,6 @@
import android.support.annotation.NonNull;
import android.support.v4.view.ViewCompat;
import android.support.v7.widget.RecyclerView;
-import android.util.Log;
import android.util.SparseArray;
import android.view.View;
import android.view.animation.Interpolator;
@@ -37,6 +36,7 @@
import java.util.List;
import eu.davidea.flexibleadapter.helpers.AnimatorHelper;
+import eu.davidea.flexibleadapter.utils.Log;
import eu.davidea.viewholders.FlexibleViewHolder;
import static eu.davidea.flexibleadapter.utils.FlexibleUtils.getClassName;
@@ -52,14 +52,12 @@
* @see FlexibleAdapter
* @see SelectableAdapter
* @since 10/01/2016 Created
- *
30/01/2016 Class now extends {@link SelectableAdapter}
- *
13/09/2016 {@link #animateView(RecyclerView.ViewHolder, int)} is now automatically called
+ *
30/01/2016 Class now extends {@link SelectableAdapter}
+ *
13/09/2016 {@link #animateView(RecyclerView.ViewHolder, int)} is now automatically called
*/
@SuppressWarnings({"unused", "WeakerAccess"})
public abstract class AnimatorAdapter extends SelectableAdapter {
- private static final String TAG = AnimatorAdapter.class.getSimpleName();
-
private Interpolator mInterpolator = new LinearInterpolator();
private AnimatorAdapterDataObserver mAnimatorNotifierObserver;
private boolean mEntryStep = true;
@@ -108,7 +106,7 @@ private enum AnimatorEnum {
AnimatorAdapter(boolean stableIds) {
super();
setHasStableIds(stableIds);
- if (DEBUG) Log.i("FlexibleAdapter", "Initialized with StableIds=" + stableIds);
+ Log.iTag("FlexibleAdapter", "Initialized with StableIds=" + stableIds);
//Get notified when an item is changed (should skip animation)
mAnimatorNotifierObserver = new AnimatorAdapterDataObserver();
@@ -137,7 +135,7 @@ void setScrollAnimate(boolean animate) {
* @since 5.0.0-b1
*/
public AnimatorAdapter setAnimationInitialDelay(long initialDelay) {
- if (DEBUG) Log.i(TAG, "Set animationInitialDelay=" + initialDelay);
+ Log.i("Set animationInitialDelay=%s", initialDelay);
mInitialDelay = initialDelay;
return this;
}
@@ -152,7 +150,7 @@ public AnimatorAdapter setAnimationInitialDelay(long initialDelay) {
* @since 5.0.0-b1
*/
public AnimatorAdapter setAnimationDelay(@IntRange(from = 0) long delay) {
- if (DEBUG) Log.i(TAG, "Set animationDelay=" + delay);
+ Log.i("Set animationDelay=%s", delay);
mStepDelay = delay;
return this;
}
@@ -168,7 +166,7 @@ public AnimatorAdapter setAnimationDelay(@IntRange(from = 0) long delay) {
* since 5.0.0-b8
*/
public AnimatorAdapter setAnimationEntryStep(boolean entryStep) {
- if (DEBUG) Log.i(TAG, "Set animationEntryStep=" + entryStep);
+ Log.i("Set animationEntryStep=%s", entryStep);
this.mEntryStep = entryStep;
return this;
}
@@ -182,7 +180,7 @@ public AnimatorAdapter setAnimationEntryStep(boolean entryStep) {
* @since 5.0.0-b1
*/
public AnimatorAdapter setAnimationDuration(@IntRange(from = 1) long duration) {
- if (DEBUG) Log.i(TAG, "Set animationDuration=" + duration);
+ Log.i("Set animationDuration=%s", duration);
mDuration = duration;
return this;
}
@@ -195,7 +193,7 @@ public AnimatorAdapter setAnimationDuration(@IntRange(from = 1) long duration) {
* @return this AnimatorAdapter, so the call can be chained
*/
public AnimatorAdapter setAnimationInterpolator(@NonNull Interpolator interpolator) {
- if (DEBUG) Log.i(TAG, "Set animationInterpolator=" + getClassName(interpolator));
+ Log.i("Set animationInterpolator=%s", getClassName(interpolator));
mInterpolator = interpolator;
return this;
}
@@ -210,14 +208,14 @@ public AnimatorAdapter setAnimationInterpolator(@NonNull Interpolator interpolat
*/
@Deprecated
public AnimatorAdapter setAnimationStartPosition(@IntRange(from = 0) int start) {
- if (DEBUG) Log.i(TAG, "Set animationStartPosition=" + start);
+ Log.i("Set animationStartPosition=%s", start);
mLastAnimatedPosition = start;
return this;
}
/**
* Enables/Disables item animation while scrolling and on loading.
- *
Enabling scrolling will disable onlyEntryAnimation.
+ *
Enabling scrolling will disable onlyEntryAnimation.
* Disabling scrolling will disable also reverse scrolling.
* Default value is {@code false}.
* Note: Loading animation can only be performed if the Adapter is initialized
@@ -230,7 +228,7 @@ public AnimatorAdapter setAnimationStartPosition(@IntRange(from = 0) int start)
* @since 5.0.0-b1
*/
public AnimatorAdapter setAnimationOnScrolling(boolean enabled) {
- if (DEBUG) Log.i(TAG, "Set animationOnScrolling=" + enabled);
+ Log.i("Set animationOnScrolling=%s", enabled);
if (enabled) this.onlyEntryAnimation = false;
shouldAnimate = enabled;
return this;
@@ -251,7 +249,7 @@ public boolean isAnimationOnScrollingEnabled() {
* @since 5.0.0-b1
*/
public AnimatorAdapter setAnimationOnReverseScrolling(boolean enabled) {
- if (DEBUG) Log.i(TAG, "Set animationOnReverseScrolling=" + enabled);
+ Log.i("Set animationOnReverseScrolling=%s", enabled);
isReverseEnabled = enabled;
return this;
}
@@ -287,7 +285,7 @@ public boolean isAnimationOnReverseScrollingEnabled() {
* @since 5.0.0-b8
*/
public AnimatorAdapter setOnlyEntryAnimation(boolean enabled) {
- if (DEBUG) Log.i(TAG, "Set onlyEntryAnimation=" + enabled);
+ Log.i("Set onlyEntryAnimation=%s", enabled);
if (enabled) this.shouldAnimate = true;
this.onlyEntryAnimation = enabled;
return this;
@@ -307,12 +305,12 @@ public boolean isOnlyEntryAnimation() {
/*--------------*/
/**
- * Build your custom list of {@link Animator} to apply on the ItemView.
+ * Build your custom list of {@link Animator} to apply on the ItemView.
* Write the logic based on the position and/or viewType and/or the item selection.
*
Suggestions:
- *
- You can also use {@link #getItemViewType(int)} to apply different Animation for
+ *
- You can also use {@link #getItemViewType(int)} to apply different Animation for
* each view type.
- *
- If you want to apply same animation for all items, create new list at class level
+ *
- If you want to apply same animation for all items, create new list at class level
* and initialize it in the constructor, not inside this method!
*
* @param itemView the bounded ItemView
@@ -356,7 +354,6 @@ private void cancelExistingAnimation(final int hashCode) {
* @param position the current item position
* @since 5.0.0-b1
*/
- @SuppressWarnings("ConstantConditions")
protected final void animateView(final RecyclerView.ViewHolder holder, final int position) {
if (mRecyclerView == null) return;
@@ -369,16 +366,10 @@ protected final void animateView(final RecyclerView.ViewHolder holder, final int
shouldAnimate = false;
}
int lastVisiblePosition = getFlexibleLayoutManager().findLastVisibleItemPosition();
-// if (DEBUG) {
-// Log.v(TAG, "shouldAnimate=" + shouldAnimate
-// + " isFastScroll=" + isFastScroll
-// + " isNotified=" + mAnimatorNotifierObserver.isPositionNotified()
-// + " isReverseEnabled=" + isReverseEnabled
-// + " mLastAnimatedPosition=" + mLastAnimatedPosition
-// + (!isReverseEnabled ? " Pos>LasVisPos=" + (position > lastVisiblePosition) : "")
-// + " mMaxChildViews=" + mMaxChildViews
-// );
-// }
+// Log.v("shouldAnimate=%s isFastScroll=%s isNotified=%s isReverseEnabled=%s mLastAnimatedPosition=%s %s mMaxChildViews=%s",
+// shouldAnimate, isFastScroll, mAnimatorNotifierObserver.isPositionNotified(), isReverseEnabled, mLastAnimatedPosition,
+// (!isReverseEnabled ? " Pos>LasVisPos=" + (position > lastVisiblePosition) : ""), mMaxChildViews
+// );
if (holder instanceof FlexibleViewHolder && shouldAnimate && !isFastScroll &&
!mAnimatorNotifierObserver.isPositionNotified() &&
(position > lastVisiblePosition || isReverseEnabled || isScrollableHeaderOrFooter(position) || (position == 0 && mMaxChildViews == 0))) {
@@ -403,7 +394,7 @@ protected final void animateView(final RecyclerView.ViewHolder holder, final int
duration = animator.getDuration();
}
}
- //Log.v(TAG, "duration=" + duration);
+ //Log.v("duration=%s", duration);
set.setDuration(duration);
set.addListener(new HelperAnimatorListener(hashCode));
if (mEntryStep) {
@@ -412,7 +403,7 @@ protected final void animateView(final RecyclerView.ViewHolder holder, final int
}
set.start();
mAnimators.put(hashCode, set);
- if (DEBUG) Log.v(TAG, "animateView Scroll animation on position " + position);
+ //Log.v("animateView Scroll animation on position %s", position);
}
mAnimatorNotifierObserver.clearNotified();
// Update last animated position
@@ -449,7 +440,7 @@ public final void animateView(final View itemView, int position) {
//Add Alpha animator
ViewCompat.setAlpha(itemView, 0);
animators.add(ObjectAnimator.ofFloat(itemView, "alpha", 0f, 1f));
- Log.w(TAG, "Started Deprecated Animation on position " + position);
+ Log.w("Started Deprecated Animation on position %s", position);
//Execute the animations
AnimatorSet set = new AnimatorSet();
@@ -516,13 +507,9 @@ private long calculateAnimationDelay(int position) {
delay = mInitialDelay + (position * mStepDelay);
}
-// if (DEBUG) Log.v(TAG, "Delay[" + position + "]=" + delay +
-// " FirstVisible=" + firstVisiblePosition +
-// " LastVisible=" + lastVisiblePosition +
-// " LastAnimated=" + numberOfAnimatedItems +
-// " VisibleItems=" + visibleItems +
-// " ChildCount=" + mRecyclerView.getChildCount() +
-// " MaxChildCount=" + mMaxChildViews);
+// Log.v("Delay[%s]=%s FirstVisible=%s LastVisible=%s LastAnimated=%s VisibleItems=%s ChildCount=%s MaxChildCount=%s",
+// position, delay, firstVisiblePosition, lastVisiblePosition, numberOfAnimatedItems,
+// visibleItems, mRecyclerView.getChildCount(), mMaxChildViews);
return delay;
}
@@ -532,9 +519,9 @@ private long calculateAnimationDelay(int position) {
/*-----------*/
/**
- * This is the default animator.
+ * This is the default animator.
* Alpha animator will be always automatically added.
- * Note: Only 1 animator of the same compatible type can be added.
+ *
Note: Only 1 animator of the same compatible type can be added.
* Incompatible with ALPHA animator.
*
* @param animators user defined list
@@ -552,10 +539,10 @@ private void addAlphaAnimator(
}
/**
- * Item will slide from Left to Right.
+ * Item will slide from Left to Right.
* Ignored if LEFT, RIGHT, TOP or BOTTOM animators were already added.
- * Note: Only 1 animator of the same compatible type can be added per time.
- * Incompatible with LEFT, TOP, BOTTOM animators.
+ *
Note: Only 1 animator of the same compatible type can be added per time.
+ * Incompatible with LEFT, TOP, BOTTOM animators.
*
* @param animators user defined list
* @param view itemView to animate
@@ -575,10 +562,10 @@ public void addSlideInFromLeftAnimator(
}
/**
- * Item will slide from Right to Left.
+ * Item will slide from Right to Left.
* Ignored if LEFT, RIGHT, TOP or BOTTOM animators were already added.
- *
Note: Only 1 animator of the same compatible type can be added per time.
- * Incompatible with RIGHT, TOP, BOTTOM animators.
+ *
Note: Only 1 animator of the same compatible type can be added per time.
+ * Incompatible with RIGHT, TOP, BOTTOM animators.
*
* @param animators user defined list
* @param view ItemView to animate
@@ -598,9 +585,9 @@ public void addSlideInFromRightAnimator(
}
/**
- * Item will slide from Top of the screen to its natural position.
+ * Item will slide from Top of the screen to its natural position.
* Ignored if LEFT, RIGHT, TOP or BOTTOM animators were already added.
- *
Note: Only 1 animator of the same compatible type can be added per time.
+ *
Note: Only 1 animator of the same compatible type can be added per time.
* Incompatible with LEFT, RIGHT, TOP, BOTTOM animators.
*
* @param animators user defined list
@@ -620,9 +607,9 @@ public void addSlideInFromTopAnimator(
}
/**
- * Item will slide from Bottom of the screen to its natural position.
+ * Item will slide from Bottom of the screen to its natural position.
* Ignored if LEFT, RIGHT, TOP or BOTTOM animators were already added.
- * Note: Only 1 animator of the same compatible type can be added per time.
+ *
Note: Only 1 animator of the same compatible type can be added per time.
* Incompatible with LEFT, RIGHT, TOP, BOTTOM animators.
*
* @param animators user defined list
@@ -642,10 +629,10 @@ public void addSlideInFromBottomAnimator(
}
/**
- * Item will scale.
+ * Item will scale.
* Ignored if SCALE animator was already added.
- * Note: Only 1 animator of the same compatible type can be added per time.
- * Incompatible with LEFT, RIGHT, BOTTOM animators.
+ *
Note: Only 1 animator of the same compatible type can be added per time.
+ * Incompatible with LEFT, RIGHT, BOTTOM animators.
*
* @param animators user defined list
* @param view itemView to animate
@@ -675,7 +662,7 @@ private class AnimatorAdapterDataObserver extends RecyclerView.AdapterDataObserv
private boolean notified;
private Handler mAnimatorHandler = new Handler(Looper.getMainLooper(), new Handler.Callback() {
public boolean handleMessage(Message message) {
- if (DEBUG) Log.v(TAG, "Clear notified for scrolling Animations");
+ //Log.v("Clear notified for scrolling Animations");
notified = false;
return true;
}
diff --git a/flexible-adapter/src/main/java/eu/davidea/flexibleadapter/FlexibleAdapter.java b/flexible-adapter/src/main/java/eu/davidea/flexibleadapter/FlexibleAdapter.java
index 3259a3f4..7a75e9e2 100644
--- a/flexible-adapter/src/main/java/eu/davidea/flexibleadapter/FlexibleAdapter.java
+++ b/flexible-adapter/src/main/java/eu/davidea/flexibleadapter/FlexibleAdapter.java
@@ -29,7 +29,6 @@
import android.support.v7.util.DiffUtil;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.helper.ItemTouchHelper;
-import android.util.Log;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
@@ -56,6 +55,7 @@
import eu.davidea.flexibleadapter.items.IHeader;
import eu.davidea.flexibleadapter.items.ISectionable;
import eu.davidea.flexibleadapter.utils.FlexibleUtils;
+import eu.davidea.flexibleadapter.utils.Log;
import eu.davidea.viewholders.ExpandableViewHolder;
import eu.davidea.viewholders.FlexibleViewHolder;
@@ -97,7 +97,7 @@
*
15/04/2017 Starting or resetting the Filter will empty the bin of the deletedItems
*
23/04/2017 Wrapper class for any third type of LayoutManagers
*/
-//@SuppressWarnings({"Range", "unused", "unchecked", "ConstantConditions", "SuspiciousMethodCalls", "WeakerAccess"})
+@SuppressWarnings({"Range", "unused", "unchecked", "ConstantConditions", "SuspiciousMethodCalls", "WeakerAccess"})
public class FlexibleAdapter
extends AnimatorAdapter
implements ItemTouchHelperCallback.AdapterCallback {
@@ -283,35 +283,35 @@ public FlexibleAdapter initializeListeners(@Nullable Object listener) {
*/
@CallSuper
public FlexibleAdapter addListener(@Nullable Object listener) {
- if (DEBUG && listener != null) {
- Log.i(TAG, "Setting listener class " + getClassName(listener) + " as:");
+ if (listener != null) {
+ Log.i("Setting listener class %s as:", getClassName(listener));
}
if (listener instanceof OnItemClickListener) {
- if (DEBUG) Log.i(TAG, "- OnItemClickListener");
+ if (DEBUG) Log.i("- OnItemClickListener");
mItemClickListener = (OnItemClickListener) listener;
}
if (listener instanceof OnItemLongClickListener) {
- if (DEBUG) Log.i(TAG, "- OnItemLongClickListener");
+ if (DEBUG) Log.i("- OnItemLongClickListener");
mItemLongClickListener = (OnItemLongClickListener) listener;
}
if (listener instanceof OnItemMoveListener) {
- if (DEBUG) Log.i(TAG, "- OnItemMoveListener");
+ if (DEBUG) Log.i("- OnItemMoveListener");
mItemMoveListener = (OnItemMoveListener) listener;
}
if (listener instanceof OnItemSwipeListener) {
- if (DEBUG) Log.i(TAG, "- OnItemSwipeListener");
+ if (DEBUG) Log.i("- OnItemSwipeListener");
mItemSwipeListener = (OnItemSwipeListener) listener;
}
if (listener instanceof OnDeleteCompleteListener) {
- if (DEBUG) Log.i(TAG, "- OnDeleteCompleteListener");
+ if (DEBUG) Log.i("- OnDeleteCompleteListener");
mDeleteCompleteListener = (OnDeleteCompleteListener) listener;
}
if (listener instanceof OnStickyHeaderChangeListener) {
- if (DEBUG) Log.i(TAG, "- OnStickyHeaderChangeListener");
+ if (DEBUG) Log.i("- OnStickyHeaderChangeListener");
mStickyHeaderChangeListener = (OnStickyHeaderChangeListener) listener;
}
if (listener instanceof OnUpdateListener) {
- if (DEBUG) Log.i(TAG, "- OnUpdateListener");
+ if (DEBUG) Log.i("- OnUpdateListener");
mUpdateListener = (OnUpdateListener) listener;
mUpdateListener.onUpdateEmptyView(getMainItemCount());
}
@@ -548,7 +548,7 @@ public void updateDataSet(@Nullable List items, boolean animate) {
prepareItemsForUpdate(newItems);
mItems = newItems;
// Execute instant reset on init
- if (DEBUG) Log.w(TAG, "updateDataSet with notifyDataSetChanged!");
+ Log.w("updateDataSet with notifyDataSetChanged!");
notifyDataSetChanged();
onPostUpdate();
}
@@ -756,11 +756,8 @@ public int calculatePositionFor(@NonNull Object item, @Nullable Comparator(mItems);
if (!sortedList.contains(item)) sortedList.add(item);
Collections.sort(sortedList, comparator);
- if (DEBUG)
- Log.v(TAG, "Calculated position " + Math.max(0, sortedList.indexOf(item)) + " for item=" + item);
+ Log.v("Calculated position %s for item=%s", Math.max(0, sortedList.indexOf(item)), item);
return Math.max(0, sortedList.indexOf(item));
}
@@ -838,7 +834,7 @@ public final boolean isScrollableHeaderOrFooter(T item) {
* @since 5.0.0-rc1
*/
public final boolean addScrollableHeader(@NonNull T headerItem) {
- if (DEBUG) Log.d(TAG, "Add scrollable header " + getClassName(headerItem));
+ Log.d("Add scrollable header %s", getClassName(headerItem));
if (!mScrollableHeaders.contains(headerItem)) {
headerItem.setSelectable(false);
headerItem.setDraggable(false);
@@ -849,7 +845,7 @@ public final boolean addScrollableHeader(@NonNull T headerItem) {
setScrollAnimate(false);
return true;
} else {
- Log.w(TAG, "Scrollable header " + getClassName(headerItem) + " already exists");
+ Log.w("Scrollable header %s already exists", getClassName(headerItem));
return false;
}
}
@@ -879,7 +875,7 @@ public final boolean addScrollableHeader(@NonNull T headerItem) {
*/
public final boolean addScrollableFooter(@NonNull T footerItem) {
if (!mScrollableFooters.contains(footerItem)) {
- if (DEBUG) Log.d(TAG, "Add scrollable footer " + getClassName(footerItem));
+ Log.d("Add scrollable footer %s", getClassName(footerItem));
footerItem.setSelectable(false);
footerItem.setDraggable(false);
int progressFix = (footerItem == mProgressItem) ? mScrollableFooters.size() : 0;
@@ -892,7 +888,7 @@ public final boolean addScrollableFooter(@NonNull T footerItem) {
performInsert(getItemCount() - progressFix, Collections.singletonList(footerItem), true);
return true;
} else {
- Log.w(TAG, "Scrollable footer " + getClassName(footerItem) + " already exists");
+ Log.w("Scrollable footer %s already exists", getClassName(footerItem));
return false;
}
}
@@ -907,7 +903,7 @@ public final boolean addScrollableFooter(@NonNull T footerItem) {
*/
public final void removeScrollableHeader(@NonNull T headerItem) {
if (mScrollableHeaders.remove(headerItem)) {
- if (DEBUG) Log.d(TAG, "Remove scrollable header " + getClassName(headerItem));
+ Log.d("Remove scrollable header %s", getClassName(headerItem));
performRemove(headerItem, true);
}
}
@@ -922,7 +918,7 @@ public final void removeScrollableHeader(@NonNull T headerItem) {
*/
public final void removeScrollableFooter(@NonNull T footerItem) {
if (mScrollableFooters.remove(footerItem)) {
- if (DEBUG) Log.d(TAG, "Remove scrollable footer " + getClassName(footerItem));
+ Log.d("Remove scrollable footer %s", getClassName(footerItem));
performRemove(footerItem, true);
}
}
@@ -936,7 +932,7 @@ public final void removeScrollableFooter(@NonNull T footerItem) {
*/
public final void removeAllScrollableHeaders() {
if (mScrollableHeaders.size() > 0) {
- if (DEBUG) Log.d(TAG, "Remove all scrollable headers");
+ Log.d("Remove all scrollable headers");
mItems.removeAll(mScrollableHeaders);
notifyItemRangeRemoved(0, mScrollableHeaders.size());
mScrollableHeaders.clear();
@@ -952,7 +948,7 @@ public final void removeAllScrollableHeaders() {
*/
public final void removeAllScrollableFooters() {
if (mScrollableFooters.size() > 0) {
- if (DEBUG) Log.d(TAG, "Remove all scrollable footers");
+ Log.d("Remove all scrollable footers");
mItems.removeAll(mScrollableFooters);
notifyItemRangeRemoved(getItemCount() - mScrollableFooters.size(), mScrollableFooters.size());
mScrollableFooters.clear();
@@ -971,8 +967,7 @@ public final void removeAllScrollableFooters() {
*/
public final void addScrollableHeaderWithDelay(@NonNull final T headerItem, @IntRange(from = 0) long delay,
final boolean scrollToPosition) {
- if (DEBUG)
- Log.d(TAG, "Enqueued adding scrollable header (" + delay + "ms) " + getClassName(headerItem));
+ Log.d("Enqueued adding scrollable header (%sms) %s", delay, getClassName(headerItem));
mHandler.postDelayed(new Runnable() {
@Override
public void run() {
@@ -994,8 +989,7 @@ public void run() {
*/
public final void addScrollableFooterWithDelay(@NonNull final T footerItem, @IntRange(from = 0) long delay,
final boolean scrollToPosition) {
- if (DEBUG)
- Log.d(TAG, "Enqueued adding scrollable footer (" + delay + "ms) " + getClassName(footerItem));
+ Log.d("Enqueued adding scrollable footer (%sms) %s", delay, getClassName(footerItem));
mHandler.postDelayed(new Runnable() {
@Override
public void run() {
@@ -1015,8 +1009,7 @@ public void run() {
* @since 5.0.0-rc1
*/
public final void removeScrollableHeaderWithDelay(@NonNull final T headerItem, @IntRange(from = 0) long delay) {
- if (DEBUG)
- Log.d(TAG, "Enqueued removing scrollable header (" + delay + "ms) " + getClassName(headerItem));
+ Log.d("Enqueued removing scrollable header (%sms) %s", delay, getClassName(headerItem));
mHandler.postDelayed(new Runnable() {
@Override
public void run() {
@@ -1035,8 +1028,7 @@ public void run() {
* @since 5.0.0-rc1
*/
public final void removeScrollableFooterWithDelay(@NonNull final T footerItem, @IntRange(from = 0) long delay) {
- if (DEBUG)
- Log.d(TAG, "Enqueued removing scrollable footer (" + delay + "ms) " + getClassName(footerItem));
+ Log.d("Enqueued removing scrollable footer (%sms) %s", delay, getClassName(footerItem));
mHandler.postDelayed(new Runnable() {
@Override
public void run() {
@@ -1086,7 +1078,7 @@ public boolean isRemoveOrphanHeaders() {
*/
@Deprecated
public FlexibleAdapter setRemoveOrphanHeaders(boolean removeOrphanHeaders) {
- if (DEBUG) Log.i(TAG, "Set removeOrphanHeaders=" + removeOrphanHeaders);
+ Log.i("Set removeOrphanHeaders=%s", removeOrphanHeaders);
this.removeOrphanHeaders = removeOrphanHeaders;
return this;
}
@@ -1101,7 +1093,7 @@ public FlexibleAdapter setRemoveOrphanHeaders(boolean removeOrphanHeaders) {
* @since 5.0.0-b6
*/
public FlexibleAdapter setUnlinkAllItemsOnRemoveHeaders(boolean unlinkOnRemoveHeader) {
- if (DEBUG) Log.i(TAG, "Set unlinkOnRemoveHeader=" + unlinkOnRemoveHeader);
+ Log.i("Set unlinkOnRemoveHeader=%s", unlinkOnRemoveHeader);
this.unlinkOnRemoveHeader = unlinkOnRemoveHeader;
return this;
}
@@ -1447,8 +1439,7 @@ public FlexibleAdapter setStickyHeaders(boolean sticky) {
* @since 5.0.0-rc1
*/
public FlexibleAdapter setStickyHeaders(final boolean sticky, @Nullable ViewGroup stickyContainer) {
- if (DEBUG) Log.i(TAG, "Set stickyHeaders=" + sticky + " (in Post!)" +
- (stickyContainer != null ? " with user defined Sticky Container" : ""));
+ Log.i("Set stickyHeaders=%s (in Post!)%s", sticky, (stickyContainer != null ? " with user defined Sticky Container" : ""));
// With user defined container
mStickyContainer = stickyContainer;
@@ -1463,12 +1454,12 @@ public void run() {
mStickyHeaderHelper = new StickyHeaderHelper(FlexibleAdapter.this,
mStickyHeaderChangeListener, mStickyContainer);
mStickyHeaderHelper.attachToRecyclerView(mRecyclerView);
- if (DEBUG) Log.i(TAG, "Sticky headers enabled");
+ Log.i("Sticky headers enabled");
}
} else if (areHeadersSticky()) {
mStickyHeaderHelper.detachFromRecyclerView();
mStickyHeaderHelper = null;
- if (DEBUG) Log.i(TAG, "Sticky headers disabled");
+ Log.i("Sticky headers disabled");
}
}
});
@@ -1554,10 +1545,10 @@ public ViewGroup getStickyHeaderContainer() {
@Deprecated
public FlexibleAdapter setStickyHeaderContainer(@Nullable ViewGroup stickyContainer) {
if (areHeadersSticky()) {
- Log.w(TAG, "StickyHeader has been already initialized! Call this method before enabling StickyHeaders");
+ Log.w("StickyHeader has been already initialized! Call this method before enabling StickyHeaders");
}
- if (DEBUG && stickyContainer != null)
- Log.i(TAG, "Set stickyHeaderContainer=" + getClassName(stickyContainer));
+ if (stickyContainer != null)
+ Log.i("Set stickyHeaderContainer=%s", getClassName(stickyContainer));
this.mStickyContainer = stickyContainer;
return this;
}
@@ -1605,18 +1596,18 @@ public FlexibleAdapter showAllHeaders() {
*/
private void showAllHeaders(boolean init) {
if (init) {
- if (DEBUG) Log.i(TAG, "showAllHeaders at startup");
+ Log.i("showAllHeaders at startup");
// No notifyItemInserted!
showAllHeadersWithReset(true);
} else {
- if (DEBUG) Log.i(TAG, "showAllHeaders with insert notification (in Post!)");
+ Log.i("showAllHeaders with insert notification (in Post!)");
// In post, let's notifyItemInserted!
mHandler.post(new Runnable() {
@Override
public void run() {
// #144 - Check if headers are already shown, discard the call to not duplicate headers
if (headersShown) {
- Log.w(TAG, "Double call detected! Headers already shown OR the method showAllHeaders() was already called!");
+ Log.w("Double call detected! Headers already shown OR the method showAllHeaders() was already called!");
return;
}
showAllHeadersWithReset(false);
@@ -1670,7 +1661,7 @@ private boolean showHeaderOf(int position, T item, boolean init) {
// Check header existence
if (header == null || getPendingRemovedItem(item) != null) return false;
if (header.isHidden()) {
- if (DEBUG) Log.v(TAG, "Showing header at position " + position + " header=" + header);
+ Log.v("Showing header position=%s header=%s", position, header);
header.setHidden(false);
// Insert header, but skip notifyItemInserted when init=true!
performInsert(position, Collections.singletonList((T) header), !init);
@@ -1726,7 +1717,7 @@ private boolean hideHeaderOf(T item) {
private boolean hideHeader(int position, IHeader header) {
if (position >= 0) {
- if (DEBUG) Log.v(TAG, "Hiding header at position " + position + " header=" + header);
+ Log.v("Hiding header position=%s header=$s", position, header);
header.setHidden(true);
// Remove and notify removals
mItems.remove(position);
@@ -1758,7 +1749,7 @@ private boolean linkHeaderTo(T item, IHeader header, @Nullable Object payload) {
unlinkHeaderFrom((T) sectionable, Payload.UNLINK);
}
if (sectionable.getHeader() == null && header != null) {
- if (DEBUG) Log.v(TAG, "Link header " + header + " to " + sectionable);
+ Log.v("Link header %s to %s", header, sectionable);
//TODO: try-catch for when sectionable item has a different header class signature, if so, they just can't accept that header!
sectionable.setHeader(header);
linked = true;
@@ -1790,7 +1781,7 @@ private IHeader unlinkHeaderFrom(T item, @Nullable Object payload) {
if (hasHeader(item)) {
ISectionable sectionable = (ISectionable) item;
IHeader header = sectionable.getHeader();
- if (DEBUG) Log.v(TAG, "Unlink header " + header + " from " + sectionable);
+ Log.v("Unlink header %s from %s", header, sectionable);
sectionable.setHeader(null);
addToOrphanListIfNeeded(header, getGlobalPositionOf(item), 1);
// Notify items
@@ -1808,15 +1799,14 @@ private void addToOrphanListIfNeeded(IHeader header, int positionStart, int item
// Check if the header is not already added (happens after un-linkage with un-success linkage)
if (!mOrphanHeaders.contains(header) && !isHeaderShared(header, positionStart, itemCount)) {
mOrphanHeaders.add(header);
- if (DEBUG)
- Log.v(TAG, "Added to orphan list [" + mOrphanHeaders.size() + "] Header " + header);
+ Log.v("Added to orphan list [%s] Header %s", mOrphanHeaders.size(), header);
}
}
@Deprecated
private void removeFromOrphanList(IHeader header) {
if (mOrphanHeaders.remove(header) && DEBUG)
- Log.v(TAG, "Removed from orphan list [" + mOrphanHeaders.size() + "] Header " + header);
+ Log.v("Removed from orphan list [%s] Header %s", mOrphanHeaders.size(), header);
}
@Deprecated
@@ -1879,8 +1869,8 @@ public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType
T item = getViewTypeInstance(viewType);
if (item == null || !autoMap) {
// If everything has been set properly, this should never happen ;-)
- throw new IllegalStateException("ViewType instance not found for viewType " + viewType +
- ". You should implement the AutoMap properly.");
+ throw new IllegalStateException(
+ String.format("ViewType instance not found for viewType %s. You should implement the AutoMap properly.", viewType));
}
if (mInflater == null) {
mInflater = LayoutInflater.from(parent.getContext());
@@ -1914,14 +1904,10 @@ public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
*/
@Override
public void onBindViewHolder(final RecyclerView.ViewHolder holder, int position, List payloads) {
- if (DEBUG) {
- Log.v(TAG, "onViewBound Holder=" + getClassName(holder) + " position=" + position +
- " itemId=" + holder.getItemId() + " layoutPosition=" + holder.getLayoutPosition());
- }
+ Log.v("onViewBound Holder=%s position=%s itemId=%s", getClassName(holder), position, holder.getItemId());
if (!autoMap) {
// If everything has been set properly, this should never happen ;-)
- throw new IllegalStateException("AutoMap is not active, this method cannot be called." +
- " Override this method or implement the AutoMap properly.");
+ throw new IllegalStateException("AutoMap is not active, this method cannot be called. You should implement the AutoMap properly.");
}
// Bind view activation with current selection
super.onBindViewHolder(holder, position, payloads);
@@ -2031,7 +2017,7 @@ public int getEndlessPageSize() {
* @since 5.0.0-rc1
*/
public FlexibleAdapter setEndlessPageSize(@IntRange(from = 0) int endlessPageSize) {
- if (DEBUG) Log.i(TAG, "Set endlessPageSize=" + endlessPageSize);
+ Log.i("Set endlessPageSize=%s", endlessPageSize);
mEndlessPageSize = endlessPageSize;
return this;
}
@@ -2062,7 +2048,7 @@ public int getEndlessTargetCount() {
* @since 5.0.0-rc1
*/
public FlexibleAdapter setEndlessTargetCount(@IntRange(from = 0) int endlessTargetCount) {
- if (DEBUG) Log.i(TAG, "Set endlessTargetCount=" + endlessTargetCount);
+ Log.i("Set endlessTargetCount=%s", endlessTargetCount);
mEndlessTargetCount = endlessTargetCount;
return this;
}
@@ -2076,7 +2062,7 @@ public FlexibleAdapter setEndlessTargetCount(@IntRange(from = 0) int endlessT
* @return this Adapter, so the call can be chained
*/
public FlexibleAdapter setLoadingMoreAtStartUp(boolean enable) {
- if (DEBUG) Log.i(TAG, "Set loadingAtStartup=" + enable);
+ Log.i("Set loadingAtStartup=%s", enable);
if (enable) {
mHandler.post(new Runnable() {
@Override
@@ -2106,12 +2092,10 @@ public FlexibleAdapter setEndlessProgressItem(@Nullable T progressItem) {
if (progressItem != null) {
setEndlessScrollThreshold(mEndlessScrollThreshold);
mProgressItem = progressItem;
- if (DEBUG) {
- Log.i(TAG, "Set progressItem=" + getClassName(progressItem));
- Log.i(TAG, "Enabled EndlessScrolling");
- }
- } else if (DEBUG) {
- Log.i(TAG, "Disabled EndlessScrolling");
+ Log.i("Set progressItem=%s", getClassName(progressItem));
+ Log.i("Enabled EndlessScrolling");
+ } else {
+ Log.i("Disabled EndlessScrolling");
}
return this;
}
@@ -2130,7 +2114,7 @@ public FlexibleAdapter setEndlessProgressItem(@Nullable T progressItem) {
*/
public FlexibleAdapter setEndlessScrollListener(@Nullable EndlessScrollListener endlessScrollListener,
@NonNull T progressItem) {
- if (DEBUG) Log.i(TAG, "Set endlessScrollListener=" + getClassName(endlessScrollListener));
+ Log.i("Set endlessScrollListener=%s", getClassName(endlessScrollListener));
mEndlessScrollListener = endlessScrollListener;
return setEndlessProgressItem(progressItem);
}
@@ -2150,7 +2134,7 @@ public FlexibleAdapter setEndlessScrollThreshold(@IntRange(from = 1) int thre
thresholdItems = thresholdItems * spanCount;
}
mEndlessScrollThreshold = thresholdItems;
- if (DEBUG) Log.i(TAG, "Set endlessScrollThreshold=" + mEndlessScrollThreshold);
+ Log.i("Set endlessScrollThreshold=%s", mEndlessScrollThreshold);
return this;
}
@@ -2173,10 +2157,9 @@ protected void onLoadMore(int position) {
if ((!mTopEndless && (position == getGlobalPositionOf(mProgressItem) || position < threshold)) ||
(mTopEndless && position > 0 && position > threshold)) {
return;
- } else if (DEBUG) {
- Log.v(TAG, "onLoadMore topEndless=" + mTopEndless + ", loading=" + endlessLoading
- + ", position=" + position + ", itemCount=" + getItemCount()
- + ", threshold=" + mEndlessScrollThreshold + ", currentThreshold=" + threshold);
+ } else {
+ Log.v("onLoadMore topEndless=%s, loading=%s, position=%s, itemCount=%s threshold=%s, currentThreshold=%s",
+ mTopEndless, endlessLoading, position, getItemCount(), mEndlessScrollThreshold, threshold);
}
// Load more if not loading and inside the threshold
endlessLoading = true;
@@ -2191,7 +2174,7 @@ public void run() {
boolean added = mTopEndless ? addScrollableHeader(mProgressItem) : addScrollableFooter(mProgressItem);
// When the listener is not set, loading more is called upon a user request
if (added && mEndlessScrollListener != null) {
- if (DEBUG) Log.d(TAG, "onLoadMore invoked!");
+ Log.d("onLoadMore invoked!");
mEndlessScrollListener.onLoadMore(getMainItemCount(), getEndlessCurrentPage());
} else if (!added) {
endlessLoading = false;
@@ -2237,8 +2220,7 @@ public void onLoadMoreComplete(@Nullable List newItems, @IntRange(from = -1)
int totalItemCount = newItemsSize + getMainItemCount();
// Add any new items
if (newItemsSize > 0) {
- if (DEBUG)
- Log.v(TAG, "onLoadMore performing adding " + newItemsSize + " new items on Page=" + getEndlessCurrentPage());
+ Log.v("onLoadMore performing adding %s new items on page=%s", newItemsSize, getEndlessCurrentPage());
int position = mTopEndless ? mScrollableHeaders.size() : getGlobalPositionOf(mProgressItem);
addItems(position, newItems);
}
@@ -2250,8 +2232,7 @@ public void onLoadMoreComplete(@Nullable List newItems, @IntRange(from = -1)
}
// Remove the progressItem if needed
if (delay > 0 && (newItemsSize == 0 || !isEndlessScrollEnabled())) {
- if (DEBUG)
- Log.v(TAG, "onLoadMore enqueued removing progressItem (" + delay + "ms)");
+ Log.v("onLoadMore enqueued removing progressItem (%sms)", delay);
mHandler.sendEmptyMessageDelayed(LOAD_MORE_COMPLETE, delay);
} else {
hideProgressItem();
@@ -2270,7 +2251,7 @@ public void onLoadMoreComplete(@Nullable List newItems, @IntRange(from = -1)
private void hideProgressItem() {
int positionToNotify = getGlobalPositionOf(mProgressItem);
if (positionToNotify >= 0) {
- if (DEBUG) Log.v(TAG, "onLoadMore remove progressItem");
+ Log.v("onLoadMore remove progressItem");
if (mTopEndless) {
removeScrollableHeader(mProgressItem);
} else {
@@ -2283,7 +2264,7 @@ private void hideProgressItem() {
* Called when no more items are loaded.
*/
private void noMoreLoad(int newItemsSize) {
- if (DEBUG) Log.i(TAG, "noMoreLoad!");
+ Log.i("noMoreLoad!");
int positionToNotify = getGlobalPositionOf(mProgressItem);
if (positionToNotify >= 0)
notifyItemChanged(positionToNotify, Payload.NO_MORE_LOAD);
@@ -2313,7 +2294,7 @@ public boolean isAutoCollapseOnExpand() {
* @since 5.0.0-b1
*/
public FlexibleAdapter setAutoCollapseOnExpand(boolean collapseOnExpand) {
- if (DEBUG) Log.i(TAG, "Set autoCollapseOnExpand=" + collapseOnExpand);
+ Log.i("Set autoCollapseOnExpand=%s", collapseOnExpand);
this.collapseOnExpand = collapseOnExpand;
return this;
}
@@ -2337,7 +2318,7 @@ public boolean isAutoScrollOnExpand() {
* @since 5.0.0-b1
*/
public FlexibleAdapter setAutoScrollOnExpand(boolean scrollOnExpand) {
- if (DEBUG) Log.i(TAG, "Set setAutoScrollOnExpand=" + scrollOnExpand);
+ Log.i("Set setAutoScrollOnExpand=%s", scrollOnExpand);
this.scrollOnExpand = scrollOnExpand;
return this;
}
@@ -2388,7 +2369,7 @@ public int getMinCollapsibleLevel() {
* @since 5.0.0-b6
*/
public FlexibleAdapter setMinCollapsibleLevel(int minCollapsibleLevel) {
- if (DEBUG) Log.i(TAG, "Set minCollapsibleLevel=" + minCollapsibleLevel);
+ Log.i("Set minCollapsibleLevel=%s", minCollapsibleLevel);
this.mMinCollapsibleLevel = minCollapsibleLevel;
return this;
}
@@ -2638,15 +2619,12 @@ private int expand(int position, boolean expandAll, boolean init, boolean notify
IExpandable expandable = (IExpandable) item;
if (!hasSubItems(expandable)) {
expandable.setExpanded(false);//clear the expanded flag
- if (DEBUG)
- Log.w(TAG, "No subItems to Expand on position " + position +
- " expanded " + expandable.isExpanded());
+ Log.w("No subItems to Expand on position %s expanded %s", position, expandable.isExpanded());
return 0;
}
- if (DEBUG && !init && !expandAll) {
- Log.v(TAG, "Request to Expand on position=" + position +
- " expanded=" + expandable.isExpanded() +
- " anyParentSelected=" + parentSelected);
+ if (!init && !expandAll) {
+ Log.v("Request to Expand on position=%s expanded=%s anyParentSelected=%s",
+ position, expandable.isExpanded(), parentSelected);
}
int subItemsCount = 0;
if (init || !expandable.isExpanded() &&
@@ -2688,10 +2666,7 @@ private int expand(int position, boolean expandAll, boolean init, boolean notify
if (!expandSHF(mScrollableHeaders, expandable))
expandSHF(mScrollableFooters, expandable);
- if (DEBUG) {
- Log.v(TAG, (init ? "Initially expanded " : "Expanded ") +
- subItemsCount + " subItems on position=" + position);
- }
+ Log.v("%s %s subItems on position=%s", (init ? "Initially expanded" : "Expanded"), subItemsCount, position);
}
return subItemsCount;
}
@@ -2782,11 +2757,8 @@ public int collapse(@IntRange(from = 0) int position, boolean notifyParent) {
List subItems = getExpandableList(expandable);
int subItemsCount = subItems.size(), recursiveCount = 0;
- if (DEBUG) {
- Log.v(TAG, "Request to Collapse on position=" + position +
- " expanded=" + expandable.isExpanded() +
- " hasSubItemsSelected=" + hasSubItemsSelected(position, subItems));
- }
+ Log.v("Request to Collapse on position=%s expanded=%s hasSubItemsSelected=%s",
+ position, expandable.isExpanded(), hasSubItemsSelected(position, subItems));
if (expandable.isExpanded() && subItemsCount > 0 &&
(!hasSubItemsSelected(position, subItems) || getPendingRemovedItem(item) != null)) {
@@ -2813,8 +2785,7 @@ public int collapse(@IntRange(from = 0) int position, boolean notifyParent) {
if (!collapseSHF(mScrollableHeaders, expandable))
collapseSHF(mScrollableFooters, expandable);
- if (DEBUG)
- Log.v(TAG, "Collapsed " + subItemsCount + " subItems on position " + position);
+ Log.v("Collapsed %s subItems on position %s", subItemsCount, position);
}
return subItemsCount + recursiveCount;
}
@@ -2913,16 +2884,16 @@ public void updateItem(@NonNull T item, @Nullable Object payload) {
*/
public void updateItem(@IntRange(from = 0) int position, @NonNull T item, @Nullable Object payload) {
if (item == null) {
- Log.e(TAG, "updateItem No Item to update!");
+ Log.e("updateItem No Item to update!");
return;
}
int itemCount = getItemCount();
if (position < 0 || position >= itemCount) {
- Log.e(TAG, "Cannot updateItem on position out of OutOfBounds!");
+ Log.e("Cannot updateItem on position out of OutOfBounds!");
return;
}
mItems.set(position, item);
- if (DEBUG) Log.d(TAG, "updateItem notifyItemChanged on position " + position);
+ Log.d("updateItem notifyItemChanged on position " + position);
notifyItemChanged(position, payload);
}
@@ -2985,10 +2956,10 @@ public boolean addItem(@NonNull T item) {
*/
public boolean addItem(@IntRange(from = 0) int position, @NonNull T item) {
if (item == null) {
- Log.e(TAG, "addItem No item to add!");
+ Log.e("addItem No item to add!");
return false;
}
- if (DEBUG) Log.v(TAG, "addItem delegates addition to addItems!");
+ Log.v("addItem delegates addition to addItems!");
return addItems(position, Collections.singletonList(item));
}
@@ -3010,12 +2981,12 @@ public boolean addItem(@IntRange(from = 0) int position, @NonNull T item) {
*/
public boolean addItems(@IntRange(from = 0) int position, @NonNull List items) {
if (items == null || items.isEmpty()) {
- Log.e(TAG, "addItems No items to add!");
+ Log.e("addItems No items to add!");
return false;
}
int initialCount = getMainItemCount();//Count only main items!
if (position < 0) {
- Log.w(TAG, "addItems Position is negative! adding items to the end");
+ Log.w("addItems Position is negative! adding items to the end");
position = initialCount;
}
// Insert the item properly
@@ -3044,8 +3015,7 @@ private void performInsert(int position, List items, boolean notify) {
}
// Notify range addition
if (notify) {
- if (DEBUG)
- Log.d(TAG, "addItems on position=" + position + " itemCount=" + items.size());
+ Log.d("addItems on position=%s itemCount=%s", position, items.size());
notifyItemRangeInserted(position, items.size());
}
}
@@ -3084,7 +3054,7 @@ public boolean addSubItem(@IntRange(from = 0) int parentPosition,
@IntRange(from = 0) int subPosition,
@NonNull T item, boolean expandParent, @Nullable Object payload) {
if (item == null) {
- Log.e(TAG, "No items to add!");
+ Log.e("No items to add!");
return false;
}
// Build a new list with 1 item to chain the methods of addSubItems
@@ -3146,7 +3116,7 @@ public boolean addSubItems(@IntRange(from = 0) int parentPosition,
IExpandable expandable = (IExpandable) parent;
return addSubItems(parentPosition, subPosition, expandable, items, expandParent, payload);
}
- Log.e(TAG, "Provided parentPosition doesn't belong to an Expandable item!");
+ Log.e("Provided parentPosition doesn't belong to an Expandable item!");
return false;
}
@@ -3285,7 +3255,7 @@ public int addItemToSection(@NonNull ISectionable sectionable, @Nullable IHeader
*/
public int addItemToSection(@NonNull ISectionable sectionable, @Nullable IHeader header,
@IntRange(from = 0) int index) {
- if (DEBUG) Log.d(TAG, "addItemToSection relativePosition=" + index);
+ Log.d("addItemToSection relativePosition=%s", index);
int headerPosition = getGlobalPositionOf(header);
if (index >= 0) {
sectionable.setHeader(header);
@@ -3311,7 +3281,7 @@ public int addItemToSection(@NonNull ISectionable sectionable, @Nullable IHeader
* @since 5.0.0-rc1
*/
public void clear() {
- if (DEBUG) Log.d(TAG, "clearAll views");
+ Log.d("clearAll views");
removeAllScrollableHeaders();
removeAllScrollableFooters();
removeRange(0, getItemCount(), null);
@@ -3330,7 +3300,7 @@ public void clear() {
*/
public void clearAllBut(Integer... viewTypes) {
List viewTypeList = Arrays.asList(viewTypes);
- if (DEBUG) Log.d(TAG, "clearAll retaining views " + viewTypeList);
+ Log.d("clearAll retaining views %s", viewTypeList);
List positionsToRemove = new ArrayList<>();
int startPosition = Math.max(0, mScrollableHeaders.size());
int endPosition = getItemCount() - mScrollableFooters.size();
@@ -3349,7 +3319,7 @@ public void clearAllBut(Integer... viewTypes) {
@Deprecated
public void removeItemWithDelay(@NonNull final T item, @IntRange(from = 0) long delay,
final boolean permanent, boolean resetLayoutAnimation) {
- Log.w(TAG, "Method removeItemWithDelay() with 'resetLayoutAnimation' has been deprecated, param 'resetLayoutAnimation'. Method will be removed with final release!");
+ Log.w("Method removeItemWithDelay() with 'resetLayoutAnimation' has been deprecated, param 'resetLayoutAnimation'. Method will be removed with final release!");
removeItemWithDelay(item, delay, permanent);
}
@@ -3421,7 +3391,7 @@ public void removeItem(@IntRange(from = 0) int position) {
public void removeItem(@IntRange(from = 0) int position, @Nullable Object payload) {
// Request to collapse after the notification of remove range
collapse(position);
- if (DEBUG) Log.v(TAG, "removeItem delegates removal to removeRange");
+ Log.v("removeItem delegates removal to removeRange");
removeRange(position, 1, payload);
}
@@ -3458,8 +3428,7 @@ public void removeItems(@NonNull List selectedPositions) {
* @since 5.0.0-b1
*/
public void removeItems(@Nullable List selectedPositions, @Nullable Object payload) {
- if (DEBUG)
- Log.v(TAG, "removeItems selectedPositions=" + selectedPositions + " payload=" + payload);
+ Log.v("removeItems selectedPositions=%s payload=%s", selectedPositions, payload);
// Check if list is empty
if (selectedPositions == null || selectedPositions.isEmpty()) return;
// Reverse-sort the list, start from last position for efficiency
@@ -3469,8 +3438,7 @@ public int compare(Integer lhs, Integer rhs) {
return rhs - lhs;
}
});
- if (DEBUG)
- Log.v(TAG, "removeItems after reverse sort selectedPositions=" + selectedPositions);
+ Log.v("removeItems after reverse sort selectedPositions=%s", selectedPositions);
// Split the list in ranges
int positionStart = 0, itemCount = 0;
int lastPosition = selectedPositions.get(0);
@@ -3574,13 +3542,12 @@ public void removeRange(@IntRange(from = 0) int positionStart,
public void removeRange(@IntRange(from = 0) int positionStart,
@IntRange(from = 0) int itemCount, @Nullable Object payload) {
int initialCount = getItemCount();
- if (DEBUG)
- Log.d(TAG, "removeRange positionStart=" + positionStart + " itemCount=" + itemCount);
+ Log.d("removeRange positionStart=%s itemCount=%s", positionStart, itemCount);
if (positionStart < 0 || (positionStart + itemCount) > initialCount) {
- Log.e(TAG, "Cannot removeRange with positionStart out of OutOfBounds!");
+ Log.e("Cannot removeRange with positionStart OutOfBounds!");
return;
} else if (itemCount == 0 || initialCount == 0) {
- Log.w(TAG, "Nothing to delete!");
+ Log.w("Nothing to delete!");
return;
}
@@ -3640,7 +3607,7 @@ public void removeRange(@IntRange(from = 0) int positionStart,
for (IHeader orphanHeader : mOrphanHeaders) {
headerPosition = getGlobalPositionOf(orphanHeader);
if (headerPosition >= 0) {
- if (DEBUG) Log.v(TAG, "Removing orphan header " + orphanHeader);
+ Log.v("Removing orphan header %s", orphanHeader);
if (!permanentDelete)
createRestoreItemInfo(headerPosition, (T) orphanHeader);
mItems.remove(headerPosition);
@@ -3718,7 +3685,7 @@ public boolean isPermanentDelete() {
* @since 5.0.0-b6
*/
public FlexibleAdapter setPermanentDelete(boolean permanentDelete) {
- if (DEBUG) Log.i(TAG, "Set permanentDelete=" + permanentDelete);
+ Log.i("Set permanentDelete=%s", permanentDelete);
this.permanentDelete = permanentDelete;
return this;
}
@@ -3746,7 +3713,7 @@ public boolean isRestoreWithSelection() {
* @since 5.0.0-b1
*/
public FlexibleAdapter setRestoreSelectionOnUndo(boolean restoreSelection) {
- if (DEBUG) Log.i(TAG, "Set restoreSelectionOnUndo=" + restoreSelection);
+ Log.i("Set restoreSelectionOnUndo=%s", restoreSelection);
this.restoreSelection = restoreSelection;
return this;
}
@@ -3772,12 +3739,12 @@ public void restoreDeletedItems() {
if (restoreInfo.relativePosition >= 0) {
// Restore child
- if (DEBUG) Log.d(TAG, "Restore SubItem " + restoreInfo);
+ Log.d("Restore SubItem %s", restoreInfo);
addSubItem(restoreInfo.getRestorePosition(true), restoreInfo.relativePosition,
restoreInfo.item, false, Payload.UNDO);
} else {
// Restore parent or simple item
- if (DEBUG) Log.d(TAG, "Restore Item " + restoreInfo);
+ Log.d("Restore Item %s", restoreInfo);
addItem(restoreInfo.getRestorePosition(false), restoreInfo.item);
}
// Item is again visible
@@ -3808,7 +3775,7 @@ public void restoreDeletedItems() {
addSelection(getGlobalPositionOf(restoreInfo.item));
}
}
- if (DEBUG) Log.d(TAG, "Selected positions after restore " + getSelectedPositions());
+ Log.d("Selected positions after restore %s", getSelectedPositions());
}
// Call listener to update EmptyView
multiRange = false;
@@ -3826,7 +3793,7 @@ public void restoreDeletedItems() {
* @since 3.0.0
*/
public synchronized void emptyBin() {
- if (DEBUG) Log.d(TAG, "emptyBin!");
+ Log.d("emptyBin!");
mRestoreList.clear();
}
@@ -4002,7 +3969,7 @@ public void setSearchText(String searchText) {
* @since 5.0.0-b1
*/
public final FlexibleAdapter setNotifyChangeOfUnfilteredItems(boolean notifyChange) {
- if (DEBUG) Log.i(TAG, "Set notifyChangeOfUnfilteredItems=" + notifyChange);
+ Log.i("Set notifyChangeOfUnfilteredItems=%s", notifyChange);
this.notifyChangeOfUnfilteredItems = notifyChange;
return this;
}
@@ -4022,7 +3989,7 @@ public final FlexibleAdapter setNotifyChangeOfUnfilteredItems(boolean notifyChan
* @since 5.0.0-b8
*/
public final FlexibleAdapter setNotifyMoveOfFilteredItems(boolean notifyMove) {
- if (DEBUG) Log.i(TAG, "Set notifyMoveOfFilteredItems=" + notifyMove);
+ Log.i("Set notifyMoveOfFilteredItems=%s", notifyMove);
this.notifyMoveOfFilteredItems = notifyMove;
return this;
}
@@ -4095,7 +4062,7 @@ public void filterItems(@NonNull List unfilteredItems, @IntRange(from = 0) lo
* the current filter.
* Filter is skipped while endless feature is active (loading).
* Items are animated thanks to {@link #animateTo(List, Payload)} BUT a limit of
- * {@value ANIMATE_TO_LIMIT} (default) items is set. Note: Above this limit,
+ * {@value #ANIMATE_TO_LIMIT} (default) items is set. Note: Above this limit,
* {@link #notifyDataSetChanged()} will be called to improve performance. you can change
* this limit by calling {@link #setAnimateToLimit(int)}.
*
@@ -4118,7 +4085,7 @@ public void filterItems(@NonNull List unfilteredItems) {
}
private synchronized void filterItemsAsync(@NonNull List unfilteredItems) {
- if (DEBUG) Log.i(TAG, "filterItems with searchText=\"" + mSearchText + "\"");
+ Log.d("filterItems with searchText=\"%s\"", mSearchText);
List filteredItems = new ArrayList<>();
filtering = true; //Enable flag
@@ -4300,14 +4267,14 @@ private void resetFilterFlags(List items) {
* Tunes the limit after the which the synchronization animations, occurred during
* updateDataSet and filter operations, are skipped and {@link #notifyDataSetChanged()}
* will be called instead.
- * Default value is {@value ANIMATE_TO_LIMIT} items, number new items.
+ * Default value is {@value #ANIMATE_TO_LIMIT} items, number new items.
*
* @param limit the number of new items that, when reached, will skip synchronization animations
* @return this Adapter, so the call can be chained
* @since 5.0.0-b8
*/
public FlexibleAdapter setAnimateToLimit(int limit) {
- if (DEBUG) Log.i(TAG, "Set animateToLimit=" + limit);
+ Log.i("Set animateToLimit=%s", limit);
mAnimateToLimit = limit;
return this;
}
@@ -4366,7 +4333,7 @@ public FlexibleAdapter setDiffUtilCallback(DiffUtilCallback diffUtilCallback)
@Deprecated //TODO: Call animateTo instead.
private synchronized void animateDiff(@Nullable List newItems, Payload payloadChange) {
if (useDiffUtil) {
- Log.v(TAG, "Animate changes with DiffUtils! oldSize=" + getItemCount() + " newSize=" + newItems.size());
+ Log.d("Animate changes with DiffUtils! oldSize=%s newSize=%s", getItemCount(), newItems.size());
if (diffUtilCallback == null) {
diffUtilCallback = new DiffUtilCallback();
}
@@ -4395,16 +4362,14 @@ private synchronized void animateDiff(@Nullable List newItems, Payload payloa
private synchronized void animateTo(@Nullable List newItems, Payload payloadChange) {
mNotifications = new ArrayList<>();
if (newItems != null && newItems.size() <= mAnimateToLimit) {
- if (DEBUG)
- Log.v(TAG, "Animate changes! oldSize=" + getItemCount() + " newSize=" + newItems.size() + " limit=" + mAnimateToLimit);
+ Log.d("Animate changes! oldSize=%s newSize=%s limit=%s", getItemCount(), newItems.size(), mAnimateToLimit);
mTempItems = new ArrayList<>(mItems);
applyAndAnimateRemovals(mTempItems, newItems);
applyAndAnimateAdditions(mTempItems, newItems);
if (notifyMoveOfFilteredItems)
applyAndAnimateMovedItems(mTempItems, newItems);
} else {
- if (DEBUG)
- Log.v(TAG, "NotifyDataSetChanged! oldSize=" + getItemCount() + " newSize=" + (newItems != null ? newItems.size() : "0") + " limit=" + mAnimateToLimit);
+ Log.d("NotifyDataSetChanged! oldSize=%s newSize=%s limit=%s", getItemCount(), (newItems != null ? newItems.size() : "0"), mAnimateToLimit);
mTempItems = newItems;
mNotifications.add(new Notification(-1, 0));
}
@@ -4451,8 +4416,7 @@ private void applyAndAnimateRemovals(List from, List newItems) {
if (mFilterAsyncTask != null && mFilterAsyncTask.isCancelled()) return;
final T item = from.get(i);
if (!mHashItems.contains(item)) {
- if (DEBUG)
- Log.v(TAG, "calculateRemovals remove position=" + i + " item=" + item + " searchText=" + mSearchText);
+ Log.v("calculateRemovals remove position=%s item=%s searchText=%s", i, item, mSearchText);
from.remove(i);
mNotifications.add(new Notification(i, Notification.REMOVE));
out++;
@@ -4469,10 +4433,8 @@ private void applyAndAnimateRemovals(List from, List newItems) {
}
}
mHashItems = null;
- if (DEBUG) {
- Log.v(TAG, "calculateModifications total mod=" + mod);
- Log.v(TAG, "calculateRemovals total out=" + out);
- }
+ Log.d("calculateModifications total mod=%s", mod);
+ Log.d("calculateRemovals total out=%s", out);
}
/**
@@ -4488,8 +4450,7 @@ private void applyAndAnimateAdditions(List from, List newItems) {
if (mFilterAsyncTask != null && mFilterAsyncTask.isCancelled()) return;
final T item = newItems.get(position);
if (!mHashItems.contains(item)) {
- if (DEBUG)
- Log.v(TAG, "calculateAdditions add position=" + position + " item=" + item + " searchText=" + mSearchText);
+ Log.v("calculateAdditions add position=%s item=%s searchText=%s", position, item, mSearchText);
if (notifyMoveOfFilteredItems) {
// We add always at the end to animate moved items at the missing position
from.add(item);
@@ -4504,7 +4465,7 @@ private void applyAndAnimateAdditions(List from, List newItems) {
}
}
mHashItems = null;
- if (DEBUG) Log.v(TAG, "calculateAdditions total new=" + in);
+ Log.d("calculateAdditions total new=%s", in);
}
/**
@@ -4520,8 +4481,7 @@ private void applyAndAnimateMovedItems(List from, List newItems) {
final T item = newItems.get(toPosition);
final int fromPosition = from.indexOf(item);
if (fromPosition >= 0 && fromPosition != toPosition) {
- if (DEBUG)
- Log.v(TAG, "calculateMovedItems fromPosition=" + fromPosition + " toPosition=" + toPosition + " searchText=" + mSearchText);
+ Log.v("calculateMovedItems fromPosition=%s toPosition=%s searchText=%s", fromPosition, toPosition, mSearchText);
T movedItem = from.remove(fromPosition);
if (toPosition < from.size()) from.add(toPosition, movedItem);
else from.add(movedItem);
@@ -4529,17 +4489,17 @@ private void applyAndAnimateMovedItems(List from, List newItems) {
move++;
}
}
- if (DEBUG) Log.v(TAG, "calculateMovedItems total move=" + move);
+ Log.v("calculateMovedItems total move=%s", move);
}
private synchronized void executeNotifications(Payload payloadChange) {
if (diffResult != null) {
- if (DEBUG) Log.i(TAG, "Dispatching notifications");
+ Log.i("Dispatching notifications");
mItems = diffUtilCallback.getNewItems(); //Update mItems in the UI Thread
diffResult.dispatchUpdatesTo(this);
diffResult = null;
} else {
- if (DEBUG) Log.i(TAG, "Performing " + mNotifications.size() + " notifications");
+ Log.i("Performing %s notifications", mNotifications.size());
mItems = mTempItems; //Update mItems in the UI Thread
setScrollAnimate(false); //Disable scroll animation
for (Notification notification : mNotifications) {
@@ -4557,7 +4517,7 @@ private synchronized void executeNotifications(Payload payloadChange) {
notifyItemMoved(notification.fromPosition, notification.position);
break;
default:
- if (DEBUG) Log.w(TAG, "notifyDataSetChanged!");
+ Log.w("notifyDataSetChanged!");
notifyDataSetChanged();
break;
}
@@ -4567,7 +4527,7 @@ private synchronized void executeNotifications(Payload payloadChange) {
}
time = System.currentTimeMillis();
time = time - start;
- if (DEBUG) Log.i(TAG, "Animate changes DONE in " + time + "ms");
+ Log.i("Animate changes DONE in %sms", time);
}
/**
@@ -4588,7 +4548,7 @@ private void initializeItemTouchHelper() {
}
if (mItemTouchHelperCallback == null) {
mItemTouchHelperCallback = new ItemTouchHelperCallback(this);
- if (DEBUG) Log.i(TAG, "Initialized default ItemTouchHelperCallback");
+ Log.i("Initialized default ItemTouchHelperCallback");
}
mItemTouchHelper = new ItemTouchHelper(mItemTouchHelperCallback);
mItemTouchHelper.attachToRecyclerView(mRecyclerView);
@@ -4633,7 +4593,7 @@ public final FlexibleAdapter setItemTouchHelperCallback(ItemTouchHelperCallback
mItemTouchHelperCallback = itemTouchHelperCallback;
mItemTouchHelper = null;
initializeItemTouchHelper();
- if (DEBUG) Log.i(TAG, "Initialized custom ItemTouchHelperCallback");
+ Log.i("Initialized custom ItemTouchHelperCallback");
return this;
}
@@ -4664,7 +4624,7 @@ public final boolean isLongPressDragEnabled() {
*/
public final FlexibleAdapter setLongPressDragEnabled(boolean longPressDragEnabled) {
initializeItemTouchHelper();
- if (DEBUG) Log.i(TAG, "Set longPressDragEnabled=" + longPressDragEnabled);
+ Log.i("Set longPressDragEnabled=%s", longPressDragEnabled);
mItemTouchHelperCallback.setLongPressDragEnabled(longPressDragEnabled);
return this;
}
@@ -4694,7 +4654,7 @@ public final boolean isHandleDragEnabled() {
*/
public final FlexibleAdapter setHandleDragEnabled(boolean handleDragEnabled) {
initializeItemTouchHelper();
- if (DEBUG) Log.i(TAG, "Set handleDragEnabled=" + handleDragEnabled);
+ Log.i("Set handleDragEnabled=%s", handleDragEnabled);
this.mItemTouchHelperCallback.setHandleDragEnabled(handleDragEnabled);
return this;
}
@@ -4722,7 +4682,7 @@ public final boolean isSwipeEnabled() {
* @since 5.0.0-b1
*/
public final FlexibleAdapter setSwipeEnabled(boolean swipeEnabled) {
- if (DEBUG) Log.i(TAG, "Set swipeEnabled=" + swipeEnabled);
+ Log.i("Set swipeEnabled=%s", swipeEnabled);
initializeItemTouchHelper();
mItemTouchHelperCallback.setSwipeEnabled(swipeEnabled);
return this;
@@ -4755,8 +4715,7 @@ public void moveItem(int fromPosition, int toPosition) {
* @since 5.0.0-b7
*/
public void moveItem(int fromPosition, int toPosition, @Nullable Object payload) {
- if (DEBUG)
- Log.v(TAG, "moveItem fromPosition=" + fromPosition + " toPosition=" + toPosition);
+ Log.v("moveItem fromPosition=%s toPosition=%s", fromPosition, toPosition);
// Preserve selection
if ((isSelected(fromPosition))) {
removeSelection(fromPosition);
@@ -4792,11 +4751,8 @@ public void swapItems(List list, int fromPosition, int toPosition) {
toPosition < 0 || toPosition >= getItemCount()) {
return;
}
- if (DEBUG) {
- Log.v(TAG, "swapItems from=" +
- fromPosition + " [selected? " + isSelected(fromPosition) + "] to=" +
- toPosition + " [selected? " + isSelected(toPosition) + "]");
- }
+ Log.v("swapItems from=%s [selected? %s] to=%s [selected? %s]",
+ fromPosition, isSelected(fromPosition), toPosition, isSelected(toPosition));
// Collapse expandable before swapping (otherwise items are mixed badly)
if (fromPosition < toPosition && isExpandable(getItem(fromPosition)) && isExpanded(toPosition)) {
@@ -4806,13 +4762,13 @@ public void swapItems(List list, int fromPosition, int toPosition) {
// Perform item swap (for all LayoutManagers)
if (fromPosition < toPosition) {
for (int i = fromPosition; i < toPosition; i++) {
- if (DEBUG) Log.v(TAG, "swapItems from=" + i + " to=" + (i + 1));
+ Log.v("swapItems from=%s to=%s", i, (i + 1));
Collections.swap(mItems, i, i + 1);
swapSelection(i, i + 1);
}
} else {
for (int i = fromPosition; i > toPosition; i--) {
- if (DEBUG) Log.v(TAG, "swapItems from=" + i + " to=" + (i - 1));
+ Log.v("swapItems from=%s to=%s", i, (i - 1));
Collections.swap(mItems, i, i - 1);
swapSelection(i, i - 1);
}
@@ -4947,8 +4903,7 @@ public void onItemSwiped(int position, int direction) {
private void mapViewTypeFrom(T item) {
if (item != null && !mTypeInstances.containsKey(item.getLayoutRes())) {
mTypeInstances.put(item.getLayoutRes(), item);
- if (DEBUG)
- Log.i(TAG, "Mapped viewType " + item.getLayoutRes() + " from " + getClassName(item));
+ Log.i("Mapped viewType %s from %s", item.getLayoutRes(), getClassName(item));
}
}
@@ -4984,10 +4939,8 @@ private void createRestoreSubItemInfo(IExpandable expandable, T item) {
List siblings = getExpandableList(expandable);
int childPosition = siblings.indexOf(item);
mRestoreList.add(new RestoreInfo((T) expandable, item, childPosition));
- if (DEBUG) {
- Log.v(TAG, "Recycled SubItem " + mRestoreList.get(mRestoreList.size() - 1)
- + " with Parent position=" + getGlobalPositionOf(expandable));
- }
+ Log.v("Recycled SubItem %s with Parent position=%s",
+ mRestoreList.get(mRestoreList.size() - 1), getGlobalPositionOf(expandable));
}
/**
@@ -5007,8 +4960,7 @@ private void createRestoreItemInfo(int position, T item) {
if (expandable != null) refItem = (T) expandable;
}
mRestoreList.add(new RestoreInfo(refItem, item));
- if (DEBUG)
- Log.v(TAG, "Recycled Item " + mRestoreList.get(mRestoreList.size() - 1) + " on position=" + position);
+ Log.v("Recycled Item %s on position=%s", mRestoreList.get(mRestoreList.size() - 1), position);
}
/**
@@ -5059,8 +5011,7 @@ public boolean handleMessage(Message message) {
int firstVisibleItem = getFlexibleLayoutManager().findFirstCompletelyVisibleItemPosition();
int lastVisibleItem = getFlexibleLayoutManager().findLastCompletelyVisibleItemPosition();
int itemsToShow = position + subItemsCount - lastVisibleItem;
-// if (DEBUG)
-// Log.v(TAG, "autoScroll itemsToShow=" + itemsToShow + " firstVisibleItem=" + firstVisibleItem + " lastVisibleItem=" + lastVisibleItem + " RvChildCount=" + mRecyclerView.getChildCount());
+// Log.v("autoScroll itemsToShow=%s firstVisibleItem=%s lastVisibleItem=%s RvChildCount=%s", itemsToShow, firstVisibleItem, lastVisibleItem, mRecyclerView.getChildCount());
if (itemsToShow > 0) {
int scrollMax = position - firstVisibleItem;
int scrollMin = Math.max(0, position + subItemsCount - lastVisibleItem);
@@ -5070,8 +5021,7 @@ public boolean handleMessage(Message message) {
scrollBy = scrollBy % spanCount + spanCount;
}
int scrollTo = firstVisibleItem + scrollBy;
-// if (DEBUG)
-// Log.v(TAG, "autoScroll scrollMin=" + scrollMin + " scrollMax=" + scrollMax + " scrollBy=" + scrollBy + " scrollTo=" + scrollTo);
+// Log.v("autoScroll scrollMin=%s scrollMax=%s scrollBy=%s scrollTo=%s", scrollMin, scrollMax, scrollBy, scrollTo);
performScroll(scrollTo);
} else if (position < firstVisibleItem) {
performScroll(position);
@@ -5098,15 +5048,14 @@ public int compare(Integer lhs, Integer rhs) {
}
for (Integer position : selectedPositions) {
if (position >= startPosition) {
-// if (DEBUG)
-// Log.v(TAG, "Adjust Selected position " + position + " to " + Math.max(position + itemCount, startPosition));
+// Log.v("Adjust Selected position %s to %s", position, Math.max(position + itemCount, startPosition));
removeSelection(position);
addAdjustedSelection(Math.max(position + itemCount, startPosition));
adjusted = true;
}
}
- if (DEBUG && adjusted)
- Log.v(TAG, "AdjustedSelected(" + diff + itemCount + ")=" + getSelectedPositions());
+ if (adjusted)
+ Log.v("AdjustedSelected(%s)=%s", (diff + itemCount), getSelectedPositions());
}
/*----------------*/
@@ -5487,7 +5436,6 @@ public String toString() {
private class FilterAsyncTask extends AsyncTask {
- private final String TAG = FilterAsyncTask.class.getSimpleName();
private final List newItems;
private final int what;
@@ -5500,13 +5448,13 @@ private class FilterAsyncTask extends AsyncTask {
@Override
protected void onPreExecute() {
if (endlessLoading) {
- Log.w(TAG, "Cannot filter while endlessLoading");
+ Log.w("Cannot filter while endlessLoading");
this.cancel(true);
}
// Note: In case some items are in pending deletion (Undo started),
// we commit the deletion before starting or resetting the filter.
if (isRestoreInTime() && mDeleteCompleteListener != null) {
- if (DEBUG) Log.d(TAG, "Hiding all deleted items before filtering/updating");
+ Log.d("Hiding all deleted items before filtering/updating");
newItems.removeAll(getDeletedItems());
if (mOriginalList != null) mOriginalList.removeAll(getDeletedItems());
mDeleteCompleteListener.onDeleteConfirmed();
@@ -5515,7 +5463,7 @@ protected void onPreExecute() {
@Override
protected void onCancelled() {
- if (DEBUG) Log.i(TAG, "FilterAsyncTask cancelled!");
+ Log.i("FilterAsyncTask cancelled!");
}
@Override
@@ -5523,16 +5471,16 @@ protected Void doInBackground(Void... params) {
start = System.currentTimeMillis();
switch (what) {
case UPDATE:
- if (DEBUG) Log.d(TAG, "doInBackground - started UPDATE");
+ Log.d("doInBackground - started UPDATE");
prepareItemsForUpdate(newItems);
animateDiff(newItems, Payload.CHANGE);
//animateTo(newItems, Payload.CHANGE);
- if (DEBUG) Log.d(TAG, "doInBackground - ended UPDATE");
+ Log.d("doInBackground - ended UPDATE");
break;
case FILTER:
- if (DEBUG) Log.d(TAG, "doInBackground - started FILTER");
+ Log.d("doInBackground - started FILTER");
filterItemsAsync(newItems);
- if (DEBUG) Log.d(TAG, "doInBackground - ended FILTER");
+ Log.d("doInBackground - ended FILTER");
break;
}
return null;
@@ -5714,9 +5662,8 @@ public boolean areItemsTheSame(int oldItemPosition, int newItemPosition) {
*
* DiffUtil uses this method to check equality instead of {@link Object#equals(Object)}
* so that you can change its behavior depending on your UI.
- * For example, if you are using DiffUtil with a
- * {@link RecyclerView.Adapter RecyclerView.Adapter}, you should
- * return whether the items' visual representations are the same.
+ * For example, if you are using DiffUtil with a {@link RecyclerView.Adapter}, you
+ * should return whether the items' visual representations are the same.
*
* This method is called only if {@link #areItemsTheSame(int, int)} returns
* {@code true} for these items.
diff --git a/flexible-adapter/src/main/java/eu/davidea/flexibleadapter/SelectableAdapter.java b/flexible-adapter/src/main/java/eu/davidea/flexibleadapter/SelectableAdapter.java
index d15a5935..e7159544 100644
--- a/flexible-adapter/src/main/java/eu/davidea/flexibleadapter/SelectableAdapter.java
+++ b/flexible-adapter/src/main/java/eu/davidea/flexibleadapter/SelectableAdapter.java
@@ -20,7 +20,6 @@
import android.support.annotation.NonNull;
import android.support.v4.view.ViewCompat;
import android.support.v7.widget.RecyclerView;
-import android.util.Log;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@@ -37,6 +36,8 @@
import eu.davidea.flexibleadapter.common.FlexibleLayoutManager;
import eu.davidea.flexibleadapter.common.IFlexibleLayoutManager;
import eu.davidea.flexibleadapter.utils.FlexibleUtils;
+import eu.davidea.flexibleadapter.utils.Log;
+import eu.davidea.flexibleadapter.utils.Log.Level;
import eu.davidea.viewholders.FlexibleViewHolder;
/**
@@ -51,12 +52,14 @@
*
27/01/2016 Improved Selection, SelectAll, FastScroller
*
29/05/2016 Use of TreeSet instead of ArrayList
*
04/04/2017 Use of FastScrollerDelegate
+ *
05/06/2017 Improved Log system
*/
@SuppressWarnings({"unused", "unchecked", "ConstantConditions", "WeakerAccess"})
public abstract class SelectableAdapter extends RecyclerView.Adapter
implements FastScroller.BubbleTextCreator, FastScroller.OnScrollStateChangeListener, FastScroller.AdapterInterface {
private static final String TAG = SelectableAdapter.class.getSimpleName();
+ @Deprecated
public static boolean DEBUG = false;
/**
@@ -108,8 +111,8 @@ public abstract class SelectableAdapter extends RecyclerView.Adapter
* @since 1.0.0
*/
public SelectableAdapter() {
- Log.i("FlexibleAdapter", "Running version " + BuildConfig.VERSION_NAME);
- mSelectedPositions = new TreeSet<>();
+ Log.iTag("FlexibleAdapter", "Running version %s", BuildConfig.VERSION_NAME);
+ mSelectedPositions = Collections.synchronizedSet(new TreeSet());
mBoundViewHolders = new HashSet<>();
mMode = MODE_IDLE;
@@ -121,14 +124,29 @@ public SelectableAdapter() {
/*----------------*/
/**
- * Call this once, to enable or disable DEBUG logs.
+ * Call this once, to enable or disable logs.
* DEBUG logs are disabled by default.
*
* @param enable true to show DEBUG logs in verbose mode, false to hide them.
* @since 5.0.0-b1
+ * @deprecated Use the new {@link #enableLogs(int)}
*/
+ @Deprecated
public static void enableLogs(boolean enable) {
DEBUG = enable;
+ if (enable) enableLogs(Level.DEBUG);
+ else enableLogs(Level.SUPPRESS);
+ }
+
+ /**
+ * Call this once, to enable or disable internal logs with custom level.
+ * Logs are disabled by default.
+ *
+ * @param level One of {@link Level} value
+ * @since 5.0.0-b1
+ */
+ public static void enableLogs(@Level int level) {
+ Log.setLevel(level);
}
/*--------------*/
@@ -175,8 +193,9 @@ public RecyclerView getRecyclerView() {
/**
* Current instance of the wrapper class for LayoutManager suitable for FlexibleAdapter.
* LayoutManager must be already initialized in the RecyclerView.
+ *
+ * return wrapper class for any non-conventional LayoutManagers or {@code null} if not initialized.
*
- * @return wrapper class for any non-conventional LayoutManagers or {@code null} if not initialized
* @since 5.0.0-rc2
*/
public IFlexibleLayoutManager getFlexibleLayoutManager() {
@@ -215,7 +234,7 @@ public void setFlexibleLayoutManager(IFlexibleLayoutManager flexibleLayoutManage
* @since 2.0.0
*/
public void setMode(@Mode int mode) {
- if (DEBUG) Log.i(TAG, FlexibleUtils.getModeName(mode) + " enabled");
+ Log.i("%s enabled", FlexibleUtils.getModeName(mode));
if (mMode == MODE_SINGLE && mode == MODE_IDLE)
clearSelection();
this.mMode = mode;
@@ -323,8 +342,8 @@ public void toggleSelection(int position) {
} else {
addSelection(position);
}
- if (DEBUG) Log.v(TAG, "toggleSelection " + (contains ? "removed" : "added") +
- " on position " + position + ", current " + mSelectedPositions);
+ Log.v("toggleSelection %s on position %s, current %s",
+ (contains ? "removed" : "added"), position, mSelectedPositions);
}
/**
@@ -388,7 +407,7 @@ protected void swapSelection(int fromPosition, int toPosition) {
public void selectAll(Integer... viewTypes) {
mSelectAll = true;
List viewTypesToSelect = Arrays.asList(viewTypes);
- if (DEBUG) Log.v(TAG, "selectAll ViewTypes to include " + viewTypesToSelect);
+ Log.v("selectAll ViewTypes to include %s", viewTypesToSelect);
int positionStart = 0, itemCount = 0;
for (int i = 0; i < getItemCount(); i++) {
if (isSelectable(i) &&
@@ -404,8 +423,7 @@ public void selectAll(Integer... viewTypes) {
}
}
}
- if (DEBUG)
- Log.d(TAG, "selectAll notifyItemRangeChanged from positionStart=" + positionStart + " itemCount=" + getItemCount());
+ Log.d("selectAll notifyItemRangeChanged from positionStart=%s itemCount=%s", positionStart, getItemCount());
notifySelectionChanged(positionStart, getItemCount());
}
@@ -419,7 +437,7 @@ public void selectAll(Integer... viewTypes) {
* @since 1.0.0
*/
public void clearSelection() {
- if (DEBUG) Log.d(TAG, "clearSelection " + mSelectedPositions);
+ Log.d("clearSelection %s", mSelectedPositions);
// #373 - ConcurrentModificationException with Undo after multiple rapid swipe removals
synchronized (mSelectedPositions) {
Iterator iterator = mSelectedPositions.iterator();
@@ -532,8 +550,8 @@ public Set getSelectedPositionsAsSet() {
*/
public void onSaveInstanceState(Bundle outState) {
outState.putIntegerArrayList(TAG, new ArrayList<>(mSelectedPositions));
- if (DEBUG && getSelectedItemCount() > 0)
- Log.d(TAG, "Saving selection " + mSelectedPositions);
+ if (Log.isDebugEnabled() && getSelectedItemCount() > 0)
+ Log.d("Saving selection %s", mSelectedPositions);
}
/**
@@ -544,8 +562,8 @@ public void onSaveInstanceState(Bundle outState) {
*/
public void onRestoreInstanceState(Bundle savedInstanceState) {
mSelectedPositions.addAll(savedInstanceState.getIntegerArrayList(TAG));
- if (DEBUG && getSelectedItemCount() > 0)
- Log.d(TAG, "Restore selection " + mSelectedPositions);
+ if (Log.isDebugEnabled() && getSelectedItemCount() > 0)
+ Log.d("Restore selection %s", mSelectedPositions);
}
/*---------------*/
diff --git a/flexible-adapter/src/main/java/eu/davidea/flexibleadapter/common/FlexibleItemAnimator.java b/flexible-adapter/src/main/java/eu/davidea/flexibleadapter/common/FlexibleItemAnimator.java
index aad73c32..cc915df7 100644
--- a/flexible-adapter/src/main/java/eu/davidea/flexibleadapter/common/FlexibleItemAnimator.java
+++ b/flexible-adapter/src/main/java/eu/davidea/flexibleadapter/common/FlexibleItemAnimator.java
@@ -26,7 +26,6 @@
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.RecyclerView.ViewHolder;
import android.support.v7.widget.SimpleItemAnimator;
-import android.util.Log;
import android.view.View;
import android.view.animation.Interpolator;
import android.view.animation.LinearInterpolator;
@@ -36,7 +35,7 @@
import java.util.Comparator;
import java.util.List;
-import eu.davidea.flexibleadapter.FlexibleAdapter;
+import eu.davidea.flexibleadapter.utils.Log;
import eu.davidea.viewholders.AnimatedViewHolder;
/**
@@ -48,8 +47,6 @@
*/
public class FlexibleItemAnimator extends SimpleItemAnimator {
- private final String TAG = this.getClass().getSimpleName();
-
private ArrayList mPendingRemovals = new ArrayList<>();
private ArrayList mPendingAdditions = new ArrayList<>();
private ArrayList mPendingMoves = new ArrayList<>();
@@ -61,15 +58,15 @@ public class FlexibleItemAnimator extends SimpleItemAnimator {
private ArrayList mMoveAnimations = new ArrayList<>();
private ArrayList mChangeAnimations = new ArrayList<>();
- protected ArrayList mRemoveAnimations = new ArrayList<>();
- protected ArrayList mAddAnimations = new ArrayList<>();
+ private ArrayList mRemoveAnimations = new ArrayList<>();
+ private ArrayList mAddAnimations = new ArrayList<>();
protected Interpolator mInterpolator = new LinearInterpolator();
private static class MoveInfo {
public ViewHolder holder;
- public int fromX, fromY, toX, toY;
+ int fromX, fromY, toX, toY;
private MoveInfo(ViewHolder holder, int fromX, int fromY, int toX, int toY) {
this.holder = holder;
@@ -82,8 +79,8 @@ private MoveInfo(ViewHolder holder, int fromX, int fromY, int toX, int toY) {
private static class ChangeInfo {
- public ViewHolder oldHolder, newHolder;
- public int fromX, fromY, toX, toY;
+ ViewHolder oldHolder, newHolder;
+ int fromX, fromY, toX, toY;
private ChangeInfo(ViewHolder oldHolder, ViewHolder newHolder) {
this.oldHolder = oldHolder;
@@ -263,13 +260,14 @@ public void run() {
* Prepares the View for Remove Animation.
* - If {@link AnimatedViewHolder#preAnimateRemoveImpl()} is implemented and returns
* {@code true}, then ViewHolder has precedence and the implementation of this method is ignored;
- *
- If not, the implementation of this method is therefore performed.
+ *
- If not, the implementation of this method is therefore performed.
* Default value is {@code true}.
*
* @param holder the ViewHolder
* @return {@code true} if a later call to {@link #runPendingAnimations()} is requested,
* false otherwise.
*/
+ @SuppressWarnings("UnusedParameters")
protected boolean preAnimateRemoveImpl(final ViewHolder holder) {
return true;
}
@@ -279,7 +277,7 @@ protected boolean preAnimateRemoveImpl(final ViewHolder holder) {
* - If {@link AnimatedViewHolder#animateRemoveImpl(ViewPropertyAnimatorListener, long, int)} is
* implemented and returns true, then ViewHolder has precedence and the implementation of this
* method is ignored;
- *
- If not, the implementation of this method is therefore performed.
+ *
- If not, the implementation of this method is therefore performed.
*
* @param holder the ViewHolder
* @param index the progressive order of execution
@@ -298,8 +296,7 @@ private boolean preAnimateRemove(final ViewHolder holder) {
}
private void doAnimateRemove(final ViewHolder holder, final int index) {
- if (FlexibleAdapter.DEBUG)
- Log.v(TAG, "AnimateRemove on itemId " + holder.getItemId());
+ Log.v("AnimateRemove on itemId %s", holder.getItemId());
boolean consumed = false;
if (holder instanceof AnimatedViewHolder) {
consumed = ((AnimatedViewHolder) holder).animateRemoveImpl(new DefaultRemoveVpaListener(holder), getRemoveDuration(), index);
@@ -324,7 +321,7 @@ public final boolean animateRemove(final ViewHolder holder) {
* Prepares the View for Add Animation.
* - If {@link AnimatedViewHolder#preAnimateAddImpl()} is implemented and returns
* {@code true}, then ViewHolder has precedence and the implementation of this method is ignored;
- *
- If not, the implementation of this method is therefore performed.
+ *
- If not, the implementation of this method is therefore performed.
* Default value is {@code true}.
*
* @param holder the ViewHolder
@@ -340,7 +337,7 @@ protected boolean preAnimateAddImpl(final ViewHolder holder) {
* - If {@link AnimatedViewHolder#animateAddImpl(ViewPropertyAnimatorListener, long, int)} is
* implemented and returns {@code true}, then ViewHolder has precedence and the implementation
* of this method is ignored;
- *
- If not, the implementation of this method is therefore performed.
+ *
- If not, the implementation of this method is therefore performed.
*
* @param holder the ViewHolder
* @param index the progressive order of execution
@@ -359,8 +356,7 @@ private boolean preAnimateAdd(final ViewHolder holder) {
}
private void doAnimateAdd(final ViewHolder holder, final int index) {
- if (FlexibleAdapter.DEBUG)
- Log.v(TAG, "AnimateAdd on itemId=" + holder.getItemId() + " position=" + holder.getLayoutPosition());
+ Log.v("AnimateAdd on itemId=%s position=%s", holder.getItemId(), holder.getLayoutPosition());
boolean consumed = false;
if (holder instanceof AnimatedViewHolder) {
consumed = ((AnimatedViewHolder) holder).animateAddImpl(new DefaultAddVpaListener(holder), getAddDuration(), index);
@@ -765,7 +761,7 @@ public void endAnimations() {
dispatchAnimationsFinished();
}
- void cancelAll(List viewHolders) {
+ private void cancelAll(List viewHolders) {
for (int i = viewHolders.size() - 1; i >= 0; i--) {
ViewCompat.animate(viewHolders.get(i).itemView).cancel();
}
diff --git a/flexible-adapter/src/main/java/eu/davidea/flexibleadapter/common/TopSnappedSmoothScroller.java b/flexible-adapter/src/main/java/eu/davidea/flexibleadapter/common/TopSnappedSmoothScroller.java
index dbbe3952..91518a3b 100644
--- a/flexible-adapter/src/main/java/eu/davidea/flexibleadapter/common/TopSnappedSmoothScroller.java
+++ b/flexible-adapter/src/main/java/eu/davidea/flexibleadapter/common/TopSnappedSmoothScroller.java
@@ -26,7 +26,7 @@
* Common class for all Smooth Scroller Layout Managers.
*
* @since 5.0.0-b6 Creation
- *
5.0.0-b8 Class is now public to allow customization of the MILLISECONDS_PER_INCH
+ *
5.0.0-b8 Class is now public to allow customization of the MILLISECONDS_PER_INCH
*/
public class TopSnappedSmoothScroller extends LinearSmoothScroller {
@@ -41,6 +41,7 @@ public class TopSnappedSmoothScroller extends LinearSmoothScroller {
private PointF vectorPosition = new PointF(0, 0);
private IFlexibleLayoutManager layoutManager;
+ @SuppressWarnings("WeakerAccess")
public TopSnappedSmoothScroller(Context context, RecyclerView.LayoutManager layoutManager) {
super(context);
this.layoutManager = new FlexibleLayoutManager(layoutManager);
diff --git a/flexible-adapter/src/main/java/eu/davidea/flexibleadapter/helpers/ActionModeHelper.java b/flexible-adapter/src/main/java/eu/davidea/flexibleadapter/helpers/ActionModeHelper.java
index 83a75fa0..510288a2 100644
--- a/flexible-adapter/src/main/java/eu/davidea/flexibleadapter/helpers/ActionModeHelper.java
+++ b/flexible-adapter/src/main/java/eu/davidea/flexibleadapter/helpers/ActionModeHelper.java
@@ -18,10 +18,10 @@
import android.support.annotation.CallSuper;
import android.support.annotation.MenuRes;
import android.support.annotation.NonNull;
+import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.view.ActionMode;
import android.support.v7.widget.RecyclerView;
-import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
@@ -30,6 +30,7 @@
import eu.davidea.flexibleadapter.FlexibleAdapter;
import eu.davidea.flexibleadapter.SelectableAdapter;
import eu.davidea.flexibleadapter.SelectableAdapter.Mode;
+import eu.davidea.flexibleadapter.utils.Log;
/**
* Helper to coordinates the MULTI selection with FlexibleAdapter.
@@ -39,8 +40,6 @@
*/
public class ActionModeHelper implements ActionMode.Callback {
- public static final String TAG = ActionModeHelper.class.getSimpleName();
-
@Mode
private int defaultMode = SelectableAdapter.MODE_IDLE;
@MenuRes
@@ -72,7 +71,7 @@ public ActionModeHelper(@NonNull FlexibleAdapter adapter, @MenuRes int cabMenu)
* @since 5.0.0-b6
*/
public ActionModeHelper(@NonNull FlexibleAdapter adapter, @MenuRes int cabMenu,
- @NonNull ActionMode.Callback callback) {
+ @Nullable ActionMode.Callback callback) {
this(adapter, cabMenu);
this.mCallback = callback;
}
@@ -211,7 +210,7 @@ public void restoreSelection(AppCompatActivity activity) {
public boolean onCreateActionMode(ActionMode actionMode, Menu menu) {
// Inflate the Context Menu
actionMode.getMenuInflater().inflate(mCabMenu, menu);
- if (SelectableAdapter.DEBUG) Log.i(TAG, "ActionMode is active!");
+ Log.d("ActionMode is active!");
// Activate the ActionMode Multi
mAdapter.setMode(SelectableAdapter.MODE_MULTI);
// Notify the provided callback
@@ -246,8 +245,7 @@ public boolean onActionItemClicked(ActionMode actionMode, MenuItem item) {
@CallSuper
@Override
public void onDestroyActionMode(ActionMode actionMode) {
- if (SelectableAdapter.DEBUG)
- Log.i(TAG, "ActionMode is about to be destroyed! New mode will be " + defaultMode);
+ Log.d("ActionMode is about to be destroyed! New mode will be %s", defaultMode);
// Change mode and deselect everything
mAdapter.setMode(defaultMode);
mAdapter.clearSelection();
diff --git a/flexible-adapter/src/main/java/eu/davidea/flexibleadapter/helpers/AnimatorHelper.java b/flexible-adapter/src/main/java/eu/davidea/flexibleadapter/helpers/AnimatorHelper.java
index 98ca955c..0f47c898 100644
--- a/flexible-adapter/src/main/java/eu/davidea/flexibleadapter/helpers/AnimatorHelper.java
+++ b/flexible-adapter/src/main/java/eu/davidea/flexibleadapter/helpers/AnimatorHelper.java
@@ -22,12 +22,11 @@
import android.support.annotation.NonNull;
import android.support.v4.view.ViewCompat;
import android.support.v7.widget.RecyclerView;
-import android.util.Log;
import android.view.View;
import java.util.List;
-import eu.davidea.flexibleadapter.FlexibleAdapter;
+import eu.davidea.flexibleadapter.utils.Log;
/**
* @author Davide Steduto
@@ -35,8 +34,6 @@
*/
public class AnimatorHelper {
- protected static final String TAG = AnimatorHelper.class.getSimpleName();
-
/*-----------*/
/* ANIMATORS */
/*-----------*/
@@ -68,7 +65,7 @@ public static void slideInFromLeftAnimator(
RecyclerView recyclerView, @FloatRange(from = 0.0, to= 1.0) float percent) {
alphaAnimator(animators, view, 0f);
animators.add(ObjectAnimator.ofFloat(view, "translationX", -recyclerView.getLayoutManager().getWidth() * percent, 0));
- if (FlexibleAdapter.DEBUG) Log.v(TAG, " Added LEFT Animator");
+ Log.v("Added LEFT Animator");
}
/**
@@ -84,7 +81,7 @@ public static void slideInFromRightAnimator(
RecyclerView recyclerView, @FloatRange(from = 0.0, to = 1.0) float percent) {
alphaAnimator(animators, view, 0f);
animators.add(ObjectAnimator.ofFloat(view, "translationX", recyclerView.getLayoutManager().getWidth() * percent, 0));
- if (FlexibleAdapter.DEBUG) Log.v(TAG, " Added RIGHT Animator");
+ Log.v("Added RIGHT Animator");
}
/**
@@ -99,7 +96,7 @@ public static void slideInFromTopAnimator(
RecyclerView recyclerView) {
alphaAnimator(animators, view, 0f);
animators.add(ObjectAnimator.ofFloat(view, "translationY", -recyclerView.getMeasuredHeight() >> 1, 0));
- if (FlexibleAdapter.DEBUG) Log.v(TAG, " Added TOP Animator");
+ Log.v("Added TOP Animator");
}
/**
@@ -114,7 +111,7 @@ public static void slideInFromBottomAnimator(
RecyclerView recyclerView) {
alphaAnimator(animators, view, 0f);
animators.add(ObjectAnimator.ofFloat(view, "translationY", recyclerView.getMeasuredHeight() >> 1, 0));
- if (FlexibleAdapter.DEBUG) Log.v(TAG, " Added BOTTOM Animator");
+ Log.v("Added BOTTOM Animator");
}
/**
@@ -130,7 +127,7 @@ public static void scaleAnimator(
alphaAnimator(animators, view, 0f);
animators.add(ObjectAnimator.ofFloat(view, "scaleX", scaleFrom, 1f));
animators.add(ObjectAnimator.ofFloat(view, "scaleY", scaleFrom, 1f));
- if (FlexibleAdapter.DEBUG) Log.v(TAG, " Added SCALE Animator");
+ Log.v("Added SCALE Animator");
}
/**
@@ -143,7 +140,7 @@ public static void scaleAnimator(
public static void flipAnimator(@NonNull List animators, @NonNull View view) {
alphaAnimator(animators, view, 0f);
animators.add(ObjectAnimator.ofFloat(view, "scaleY", 0f, 1f));
- if (FlexibleAdapter.DEBUG) Log.v(TAG, " Added FLIP Animator");
+ Log.v("Added FLIP Animator");
}
/**
diff --git a/flexible-adapter/src/main/java/eu/davidea/flexibleadapter/helpers/ItemTouchHelperCallback.java b/flexible-adapter/src/main/java/eu/davidea/flexibleadapter/helpers/ItemTouchHelperCallback.java
index fc593eb2..0c51dac3 100644
--- a/flexible-adapter/src/main/java/eu/davidea/flexibleadapter/helpers/ItemTouchHelperCallback.java
+++ b/flexible-adapter/src/main/java/eu/davidea/flexibleadapter/helpers/ItemTouchHelperCallback.java
@@ -41,7 +41,6 @@
@SuppressWarnings({"WeakerAccess", "unused"})
public class ItemTouchHelperCallback extends Callback {
- private static final String TAG = ItemTouchHelperCallback.class.getSimpleName();
protected static final float ALPHA_FULL = 1.0f;
protected AdapterCallback mAdapterCallback;
diff --git a/flexible-adapter/src/main/java/eu/davidea/flexibleadapter/helpers/StickyHeaderHelper.java b/flexible-adapter/src/main/java/eu/davidea/flexibleadapter/helpers/StickyHeaderHelper.java
index 927a68a0..e0fe9f17 100644
--- a/flexible-adapter/src/main/java/eu/davidea/flexibleadapter/helpers/StickyHeaderHelper.java
+++ b/flexible-adapter/src/main/java/eu/davidea/flexibleadapter/helpers/StickyHeaderHelper.java
@@ -20,7 +20,6 @@
import android.support.v7.widget.OrientationHelper;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.RecyclerView.OnScrollListener;
-import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@@ -31,6 +30,7 @@
import eu.davidea.flexibleadapter.FlexibleAdapter.OnStickyHeaderChangeListener;
import eu.davidea.flexibleadapter.R;
import eu.davidea.flexibleadapter.items.IHeader;
+import eu.davidea.flexibleadapter.utils.Log;
import eu.davidea.viewholders.FlexibleViewHolder;
/**
@@ -41,8 +41,6 @@
*/
public final class StickyHeaderHelper extends OnScrollListener {
- private static final String TAG = StickyHeaderHelper.class.getSimpleName();
-
private FlexibleAdapter mAdapter;
private RecyclerView mRecyclerView;
private ViewGroup mStickyHolderLayout;
@@ -83,7 +81,7 @@ public void detachFromRecyclerView() {
mRecyclerView.removeOnScrollListener(this);
mRecyclerView = null;
clearHeaderWithAnimation();
- if (FlexibleAdapter.DEBUG) Log.i(TAG, "StickyHolderLayout detached");
+ Log.d("StickyHolderLayout detached");
}
private FrameLayout createContainer(int width, int height) {
@@ -106,9 +104,9 @@ private void initStickyHeadersHolder() {
oldParentLayout.addView(stickyContainer);
// Initialize Holder Layout
mStickyHolderLayout = (ViewGroup) LayoutInflater.from(mRecyclerView.getContext()).inflate(R.layout.sticky_header_layout, stickyContainer);
- if (FlexibleAdapter.DEBUG) Log.i(TAG, "Default StickyHolderLayout initialized");
- } else if (FlexibleAdapter.DEBUG) {
- Log.i(TAG, "User defined StickyHolderLayout initialized");
+ Log.i("Default StickyHolderLayout initialized");
+ } else {
+ Log.i("User defined StickyHolderLayout initialized");
}
// Show sticky header if exists already
updateOrClearHeader(false);
@@ -158,8 +156,7 @@ private void updateHeader(int headerPosition, boolean updateHeaderContent) {
}
mHeaderPosition = headerPosition;
FlexibleViewHolder holder = getHeaderViewHolder(headerPosition);
- if (FlexibleAdapter.DEBUG)
- Log.d(TAG, "swapHeader newHeaderPosition=" + mHeaderPosition);
+ Log.d("swapHeader newHeaderPosition=%s", mHeaderPosition);
swapHeader(holder);
} else if (updateHeaderContent) {
// #299 - ClassCastException after click on expanded sticky header when AutoCollapse is enabled
@@ -291,7 +288,7 @@ private void resetHeader(FlexibleViewHolder header) {
private void clearHeader() {
if (mStickyHeaderViewHolder != null) {
- if (FlexibleAdapter.DEBUG) Log.d(TAG, "clearHeader");
+ Log.d("clearHeader");
resetHeader(mStickyHeaderViewHolder);
mStickyHolderLayout.setAlpha(0);
mStickyHolderLayout.animate().cancel();
diff --git a/flexible-adapter/src/main/java/eu/davidea/flexibleadapter/helpers/UndoHelper.java b/flexible-adapter/src/main/java/eu/davidea/flexibleadapter/helpers/UndoHelper.java
index 9f262644..f6fc9794 100644
--- a/flexible-adapter/src/main/java/eu/davidea/flexibleadapter/helpers/UndoHelper.java
+++ b/flexible-adapter/src/main/java/eu/davidea/flexibleadapter/helpers/UndoHelper.java
@@ -273,7 +273,7 @@ public interface OnUndoListener {
/**
* Called when Undo timeout is over and action must be committed in the user Database.
* Due to Java Generic, it's too complicated and not well manageable if we pass the
- * List<T> object.
+ * {@code List} object.
* So, to get deleted items, use {@link FlexibleAdapter#getDeletedItems()} from the
* implementation of this method.
*
diff --git a/flexible-adapter/src/main/java/eu/davidea/flexibleadapter/items/IFilterable.java b/flexible-adapter/src/main/java/eu/davidea/flexibleadapter/items/IFilterable.java
index fcaa11e3..e71e3165 100644
--- a/flexible-adapter/src/main/java/eu/davidea/flexibleadapter/items/IFilterable.java
+++ b/flexible-adapter/src/main/java/eu/davidea/flexibleadapter/items/IFilterable.java
@@ -33,7 +33,7 @@ public interface IFilterable {
* Checks and performs the filter on this item, you can apply the logic and the filter on
* every fields your use case foresees.
* Note: Filter method makes use of {@code HashSet}, in case you implemented
- * {@link #equals(Object)} you should implement {@link #hashCode()} too!
+ * {@link Object#equals(Object)} you should implement {@link Object#hashCode()} too!
*
* @param constraint the search text typed by the user always provided in lowercase
* @return true if this item should be collected by the Adapter for the filtered list, false otherwise
diff --git a/flexible-adapter/src/main/java/eu/davidea/flexibleadapter/utils/Log.java b/flexible-adapter/src/main/java/eu/davidea/flexibleadapter/utils/Log.java
new file mode 100644
index 00000000..3ca6d464
--- /dev/null
+++ b/flexible-adapter/src/main/java/eu/davidea/flexibleadapter/utils/Log.java
@@ -0,0 +1,266 @@
+/*
+ * Copyright 2017 Davide Steduto
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package eu.davidea.flexibleadapter.utils;
+
+import android.support.annotation.IntDef;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+import static eu.davidea.flexibleadapter.utils.Log.Level.DEBUG;
+import static eu.davidea.flexibleadapter.utils.Log.Level.ERROR;
+import static eu.davidea.flexibleadapter.utils.Log.Level.INFO;
+import static eu.davidea.flexibleadapter.utils.Log.Level.SUPPRESS;
+import static eu.davidea.flexibleadapter.utils.Log.Level.VERBOSE;
+import static eu.davidea.flexibleadapter.utils.Log.Level.WARN;
+
+/**
+ * Utility class that simplifies the use of {@link android.util.Log} by improving the call
+ * to all log methods by supplying arguments as parameters instead of creating a string. This
+ * avoids useless memory allocations when not requested: the StringBuilder itself, the buffer
+ * and the String object. The new methods check in advance if the level is enabled and only
+ * after creates the string message with arguments.
+ * Others features are:
+ *
+ * - Automatic TAG corresponding to the caller class name.
+ * - Runtime log level without the need of props file (useful for libraries).
+ * - Method name with line number.
+ *
+ * Use {@link Level#SUPPRESS} to disable all logs. For instance:
+ *
+ * if (BuildConfig.DEBUG) {
+ * Log.setLevel(Level.INFO);
+ * } else {
+ * Log.setLevel(Level.SUPPRESS);
+ * }
+ *
+ *
+ * @author Davide Steduto
+ * @since 02/06/2017
+ */
+public class Log {
+
+ private static int LEVEL;
+ private static boolean withMethodName;
+ private static boolean withLineNumber;
+
+ private Log() {
+ }
+
+ /**
+ * Annotation interface for log level:
+ * {@link #VERBOSE}, {@link #DEBUG}, {@link #INFO},
+ * {@link #WARN}, {@link #ERROR}, {@link #SUPPRESS}
+ */
+ @IntDef({VERBOSE, DEBUG, INFO, WARN, ERROR, SUPPRESS})
+ @Retention(RetentionPolicy.SOURCE)
+ public @interface Level {
+ int VERBOSE = android.util.Log.VERBOSE;
+ int DEBUG = android.util.Log.DEBUG;
+ int INFO = android.util.Log.INFO;
+ int WARN = android.util.Log.WARN;
+ int ERROR = android.util.Log.ERROR;
+ int SUPPRESS = 10;
+ }
+
+ public static void setLevel(@Level int level) {
+ LEVEL = level;
+ }
+
+ /**
+ * Allows to log method name and line number from where the log is called.
+ * - With method name: {@code [method] msg}.
+ *
- With line number: {@code [method:line] msg}.
+ * Note: Line number needs method name enabled.
+ *
+ * @param method true to print method name at the beginning of the message, false otherwise
+ * @param line true to print line number after the method name, false otherwise
+ */
+ public static void logMethodName(boolean method, boolean line) {
+ withMethodName = method;
+ withLineNumber = line;
+ }
+
+ public static boolean isVerboseEnabled() {
+ return LEVEL <= VERBOSE;
+ }
+
+ public static boolean isDebugEnabled() {
+ return LEVEL <= DEBUG;
+ }
+
+ public static boolean isInfoEnabled() {
+ return LEVEL <= INFO;
+ }
+
+ public static boolean isWarnEnabled() {
+ return LEVEL <= WARN;
+ }
+
+ public static boolean isErrorEnabled() {
+ return LEVEL <= ERROR;
+ }
+
+ /**
+ * Sends a {@link Level#VERBOSE} log message.
+ *
+ * @param msg the message you would like logged
+ * @param args the extra arguments for the message
+ */
+ public static void v(String msg, Object... args) {
+ if (isVerboseEnabled()) {
+ android.util.Log.v(getTag(), formatMessage(msg, args));
+ }
+ }
+
+ /**
+ * Sends a {@link Level#DEBUG} log message.
+ *
+ * @param msg the message you would like logged
+ * @param args the extra arguments for the message
+ */
+ public static void d(String msg, Object... args) {
+ if (isDebugEnabled()) {
+ android.util.Log.d(getTag(), formatMessage(msg, args));
+ }
+ }
+
+ /**
+ * Sends an {@link Level#INFO} log message.
+ *
+ * @param msg the message you would like logged
+ * @param args the extra arguments for the message
+ */
+ public static void i(String msg, Object... args) {
+ if (isInfoEnabled()) {
+ android.util.Log.i(getTag(), formatMessage(msg, args));
+ }
+ }
+
+ /**
+ * As {@link #i(String, Object...)} but with custom tag for one call only.
+ *
+ * @param tag custom tag, used to identify the source of a log message
+ * @param msg the message you would like logged
+ * @param args the extra arguments for the message
+ */
+ public static void iTag(String tag, String msg, Object... args) {
+ if (isInfoEnabled()) {
+ android.util.Log.i(tag, formatMessage(msg, args));
+ }
+ }
+
+ /**
+ * Sends a {@link Level#WARN} log message.
+ *
+ * @param msg the message you would like logged
+ * @param args the extra arguments for the message
+ */
+ public static void w(String msg, Object... args) {
+ if (isWarnEnabled()) {
+ android.util.Log.w(getTag(), formatMessage(msg, args));
+ }
+ }
+
+ /**
+ * Sends a {@link Level#WARN} log message with the Exception at the end of the message.
+ *
+ * @param t The exception to log
+ * @param msg the message you would like logged
+ * @param args the extra arguments for the message
+ */
+ public static void w(Throwable t, String msg, Object... args) {
+ if (isWarnEnabled()) {
+ android.util.Log.w(getTag(), formatMessage(msg, args), t);
+ }
+ }
+
+ /**
+ * Sends an {@link Level#ERROR} log message.
+ *
+ * @param msg the message you would like logged
+ * @param args the extra arguments for the message
+ */
+ public static void e(String msg, Object... args) {
+ if (isErrorEnabled()) {
+ android.util.Log.e(getTag(), formatMessage(msg, args));
+ }
+ }
+
+ /**
+ * Sends an {@link Level#ERROR} log message with the Exception at the end of the message.
+ *
+ * @param t The exception to log
+ * @param msg the message you would like logged
+ * @param args the extra arguments for the message
+ */
+ public static void e(Throwable t, String msg, Object... args) {
+ if (isErrorEnabled()) {
+ android.util.Log.e(getTag(), formatMessage(msg, args), t);
+ }
+ }
+
+ /**
+ * What a Terrible Failure: Report a condition that should never happen.
+ *
+ * @param msg the message you would like logged
+ * @param args the extra arguments for the message
+ */
+ public static void wtf(String msg, Object... args) {
+ if (isErrorEnabled()) {
+ android.util.Log.wtf(getTag(), formatMessage(msg, args));
+ }
+ }
+
+ /**
+ * What a Terrible Failure: Report a condition that should never happen with the Exception
+ * at the end of the message.
+ *
+ * @param t The exception to log
+ * @param msg the message you would like logged
+ * @param args the extra arguments for the message
+ */
+ public static void wtf(Throwable t, String msg, Object... args) {
+ if (isErrorEnabled()) {
+ android.util.Log.wtf(getTag(), formatMessage(msg, args), t);
+ }
+ }
+
+ private static String getTag() {
+ StackTraceElement traceElement = new Throwable().getStackTrace()[2];
+ return traceElement.getFileName().split("[.]")[0];
+ }
+
+ private static String formatMessage(String msg, Object... args) {
+ // In order to have the "null" values logged we need to pass args when null to the formatter
+ // (This can still break depending on conversion of the formatter, see String.format)
+ // else if there is no args, we return the message as-is, otherwise we pass args to formatting normally.
+ return createLog(args != null && args.length == 0 ? msg : String.format(msg, args));
+ }
+
+ private static String createLog(String log) {
+ if (withMethodName) {
+ StackTraceElement traceElement = new Throwable().getStackTrace()[3];
+ if (withLineNumber) {
+ return String.format("[%s:%s] %s", traceElement.getMethodName(), traceElement.getLineNumber(), log);
+ } else {
+ return String.format("[%s] %s", traceElement.getMethodName(), log);
+ }
+ }
+ return log;
+ }
+
+}
\ No newline at end of file