Skip to content

Releases: janishar/PlaceHolderView

Fix Constructor Not Found and Proguard Rules Addition

03 Apr 17:52
Compare
Choose a tag to compare

Features

  1. This release fixes the constructor not found exception when minify is enabled.
  2. The proguard rules are added to keep the classes annotated with @Layout along with the generated classes required by the library

Note:

A new annotation @Keep is added for the purpose of keeping the class and its methods when minify is enabled. This was required by the library so to reference the generated classes for the item views.
This annotations as a by product can be utilised by the client code to prevent any class from being obfuscated.

@Recycle callback and RecyclableEditText

16 Feb 19:49
Compare
Choose a tag to compare

@Recycle Addition To PlaceHolderView

It will provide the callback to the ViewItem when the ViewHolder containing that ViewItem is recycled. It can then be used to clean up views and data.

Example:

@Layout(R.layout.row_user)
public class UserDetailView {

    @View(R.id.et_user_name) 
    private EditText etUserName;

    private User user;
    private TextWatcher textWatcher;

    public UserDetailView(User user){
         this.user = user;
         textWatcher = new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void onTextChanged(CharSequence charSequence, int pos, int i1, int i2) {
                if (charSequence.toString().length() > 0) {
                    user.setName(charSequence.toString())
                }
            }

            @Override
            public void afterTextChanged(Editable editable) {

            }
        };
   }

    @Resolve
    private void onResolved() {
        etUserName.setText(user.getName());
        etUserName.addTextChangedListener(textWatcher);
    }

    @Recycle
    private void onRecycle() {
        etUserName.removeTextChangedListener(textWatcher);
    }
}

RecyclableEditText Widget

The EditText in Android don't allow to remove TextChangedListener if TextWatcher instance is not known. Thus when ViewHolder is recycled then it leads to addition of multiple listeners and causes unpredictable behavior.

RecyclableEditText provides two methods setTextChangedListener and removeTextChangedListener.

    etUserName.setTextChangedListener(new RecyclableEditText.OnTextChangeListener() {
            @Override
            public void onTextChanged(CharSequence text, int start, int lengthBefore, int lengthAfter) {
                // Do something
            }
        });

PlaceHolderView sort, Swipe Stack Head Callback, Fix Expand ChildView Order

01 Dec 19:43
Compare
Choose a tag to compare

PlaceHolderView Sort

Now we can apply sort to the views added to the PlaceHolderView. This will refresh the views with new sort order.

Example: If the View Items added to the PlaceHolderView is of class ItemView, then we have to supply a Comparator that defines the comparison between the itemView objects. Here the itemView's title string is being compared for the sorting.

NOTE: Check item1 and item2 are of type ItemView for this example. This is required because any type of View Item class can be added into the PlaceHolderView

placeHolderView.sort(new Comparator<Object>() {
    @Override
    public int compare(Object item1, Object item2) {
        if (item1 instanceof ItemView && item2 instanceof ItemView) {
            ItemView view1 = (ItemView) item1;
            ItemView view2 = (ItemView) item2;
            return view1.getTitle().compareTo(view2.getTitle());
        }
        return 0;
    }
});

SwipeHead Callback

SwipePlaceHolderView will now provide SwipeHead annotation for callback when a card comes on top of the stack.

@SwipeHead
private void onSwipeHeadCard() {
    // do something when the card comes on the top
}

Example: In the below example link, the cards below the top card are blurred and when a card come on the top then it's blur removed.
Link: TinderCard

ExpandabePlaceHolderView Reverse Add Fix

The child views were getting added in reverse order and hence it is fixed now.

Fix Abrupt Swipe Animation

10 Sep 09:05
Compare
Choose a tag to compare

The Swipe Animation while changing the direction of swipe caused jumps. This is fixed in this release.

setSwipeMaxChangeAngle method has been added to the SwipeDecor that defines the maximum angle change allowed for subsequent card movement while swiping.

Example:

For allowing only up to 1 degree rotation increment (default is 2 degrees) keep it smaller for smoother animation.

swipeDecor().setSwipeMaxChangeAngle(1f)

Suggestion:

For smooth transition of card rotation keep setHeightSwipeDistFactor and setWidthSwipeDistFactor smaller and setSwipeMaxChangeAngle less than 2 degrees(default).

mSwipeView.getBuilder()
               .setHeightSwipeDistFactor(8)
               .setWidthSwipeDistFactor(4)

SwipeDirectionalView(Swipe Directions), Swipe Touch Callback, Animated Undo, Programmatically Expand/Collapse ExpandablePlaceHolderView

09 Aug 18:02
Compare
Choose a tag to compare

SwipeDirectionalView

0.7.0 version provides SwipeDirectionalView class, which is build on top of SwipePlaceHolderView. This View provides more refines directional callbacks for the swipes. All the properties of SwipePlaceHolderView is available to SwipeDirectionalView.

Usage:

    <com.mindorks.placeholderview.SwipeDirectionalView
        android:id="@+id/swipeView"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
private SwipeDirectionalView mSwipeView;
...

mSwipeView.getBuilder()
                .setSwipeVerticalThreshold(Utils.dpToPx(50))
                .setSwipeHorizontalThreshold(Utils.dpToPx(50))
                ...

setSwipeVerticalThreshold: It defines the vertical area from the initial touch location.
setSwipeHorizontalThreshold: It defines the horizontal area from the initial touch location.

If the swipe take place within these areas then it will be considered for TOP, BOTTOM, LEFT or RIGHT direction swipe else the direction will be RIGHT_TOP, RIGHT_BOTTOM, LEFT_TOP or LEFT_BOTTOM

For receiving the directional callbacks for SwipeDirectionalView, new Annotations has been added:

  1. @SwipeOutDirectional: It is called when the card is either left swiped or top swiped.
    @SwipeOutDirectional
    private void onSwipeOutDirectional(SwipeDirection direction) {
        Log.d("DEBUG", "SwipeOutDirectional " + direction.name());
    }
  1. @SwipeInDirectional: It is called when the card is either right swiped or bottom swiped.
    @SwipeInDirectional
    private void onSwipeInDirectional(SwipeDirection direction) {
        Log.d("DEBUG", "SwipeInDirectional " + direction.name());
    }
  1. @SwipingDirection: It is called when the card is swiping in some direction.
    @SwipingDirection
    private void onSwipingDirection(SwipeDirection direction) {
        Log.d("DEBUG", "SwipingDirection " + direction.name());
    }

Refer to this demo example to understand it's usage: Link

SwipeTouch Callback

This callback is added to SwipePlaceHolderView. It provides the starting and current touch point's coordinates on the card while it is getting swiped.

    @SwipeTouch
    private void onSwipeTouch(float xStart, float yStart, float xCurrent, float yCurrent) {
        Log.d("DEBUG", "onSwipeTouch "
                + " xStart : " + xStart
                + " yStart : " + yStart
                + " xCurrent : " + xCurrent
                + " yCurrent : " + yCurrent
                + " distance : "
                + Math.sqrt(Math.pow(xCurrent - xStart, 2) + (Math.pow(yCurrent - yStart, 2)))
        );
    }

Programmatic undo for SwipePlaceHolderView with Animation.

The mSwipeView.undoLastSwipe(); will now put back the swiped card back into the stack by making a reverse animation.

Programmatic Expand/Collapse for ExpandablePlaceHolderView

// These will expand the desired parent
public <T> void expand(T resolver) throws Resources.NotFoundException
public void expand(int position) throws Resources.NotFoundException

// These will collapse the desired parent
public <T> void collapse(T resolver) throws Resources.NotFoundException
public void collapse(int position) throws Resources.NotFoundException

// This will collapse all the expanded parents
public void collapseAll()

//Example
    @OnClick(R.id.collapse)
    void onCollapse() {
        try {
            mExpandableView.collapse(parentItem);
           //mExpandableView.collapse(0);
        } catch (Resources.NotFoundException e) {
            e.printStackTrace();
        }
    }

Addition of getAllResolvers() into SwipePlaceHolderView

29 Mar 11:31
Compare
Choose a tag to compare

getAllResolvers() has been added to the SwipePlaceHolderView. This method will give the list of all the currently added and reserved views in the SwipePlaceHolderView.

Example:

for(Object view : mSwipeView.getAllResolvers()){
     // do with the added view objects
}

ItemRemovedListener added for SwipePlaceHolderView

17 Jan 21:01
Compare
Choose a tag to compare

SwipePlaceHolderView will now accept ItemRemovedListener. It will listen to the itemView remove events. onItemRemoved method will be called with the count of the current items in the view list after the view removal.

    mSwipePlaceHolderView.addItemRemoveListener(new ItemRemovedListener() {

        @Override
        public void onItemRemoved(int count) {
            //do something when the count changes to some specific value.
            //For Example: Call server to fetch more data when count is zero
        }
    });

RecyclerView version update and removeAllViews method addition for SwipePlaceHolderView

14 Dec 20:13
Compare
Choose a tag to compare

RecyclerView is updated to 25.+

com.android.support:recyclerview-v7:25.+

SwipePlaceHolderView can now remove all its child views to reset its empty state using:

mSwipePlaceHolderView.removeAllViews();

Swipe Option addition

21 Oct 09:34
Compare
Choose a tag to compare
  1. This release clubs all the non UI options into SwipeOption class. It will fix the Options of SwipePlaceHolderView to reset to default when new SwipeDecor class is passed to the Builder class.
  2. mSwipePlaceHolderView.deActivatePutBack() is renamed to mSwipePlaceHolderView.deactivatePutBack()

Disable Swipe on Touch

20 Oct 20:25
Compare
Choose a tag to compare

This version adds two method to enable/disable swiping on touch. The programmatic swipe will still be enabled.

mSwipePlaceHolderView.disableTouchSwipe();
mSwipePlaceHolderView.enableTouchSwipe();