//PlaceHolderView to wrap around the recycler view in XML
<com.mindorks.placeholderview.PlaceHolderView
android:id="@+id/galleryView"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardCornerRadius="6dp"
app:cardElevation="6dp">
<ImageView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="250dp"
android:scaleType="centerCrop"
android:src="@android:color/holo_orange_dark"/>
</android.support.v7.widget.CardView>
</LinearLayout>
@Animate(Animation.ENTER_LEFT_DESC)
@NonReusable
@Layout(R.layout.gallery_item_big)
public class ImageTypeBig {
@View(R.id.imageView)
private ImageView imageView;
private String mUlr;
private Context mContext;
private PlaceHolderView mPlaceHolderView;
public ImageTypeBig(Context context, PlaceHolderView placeHolderView, String ulr) {
mContext = context;
mPlaceHolderView = placeHolderView;
mUlr = ulr;
}
@Resolve
private void onResolved() {
Glide.with(mContext).load(mUlr).into(imageView);
}
@LongClick(R.id.imageView)
private void onLongClick(){
mPlaceHolderView.removeView(this);
}
}
PlaceHolderView mGalleryView = (PlaceHolderView)findViewById(R.id.galleryView);
// (Optional): If customisation is Required then use Builder with the PlaceHolderView
// placeHolderView.getBuilder()
// .setHasFixedSize(false)
// .setItemViewCacheSize(10)
// .setLayoutManager(new GridLayoutManager(this, 3));
mGalleryView
.addView(new ImageTypeBig(this.getApplicationContext(), mGalleryView, url1));
.addView(new ImageTypeBig(this.getApplicationContext(), mGalleryView, url2));
.addView(new ImageTypeBig(this.getApplicationContext(), mGalleryView, url3));
.addView(new ImageTypeBig(this.getApplicationContext(), mGalleryView, url4));
getBuilder()
: Get builder for the PlaceHolderView to modify the default propertiessetLayoutManager(layoutManager)
: Add custom layout manageraddView()
: Add views to the PlaceHolderViewremoveView()
: Removes the existing viewSmoothLinearLayoutManager
: This class is bundled with the library, and should be used for those view which has dynamic heavy contents. It reduces the screen flickering on bind
@Layout
: Bind the XML layout with the class.@View
: Bind the variable with the view defined in the above layout.@Click
: Bind theOnClickListener
to a view.@LongClick
: Bind the long click listener to a view.@Resolve
: Any operation being performed on the view reference defined by@View
should be annotated with this.@Animate(Animation.ENTER_LEFT_DESC)
: Sets the defined animations in the Animation class on this item view.@NonReusable
: Releases the view reference along with all the attached references in the view object. This view object should not be used again in theaddView()
.@Position
: This annotation binds an int variable to the position of the item view after the item view is attached to the display.
PlaceHolderView
will recycle the viewItems and will try to use similar/same viewtype viewItem to populate the data of the current viewItem. So, the method annotated with@Resolve
will be called everytime the viewItem is attached to the window. Meaning if you don't explicitly manage to populate the viewItem in method annotated with@Resolve
then that viewItem may show history of the reused viewItem.- Try to instantiate any class in the constructor rather than method annotated with
@Resolve
. - If the itemView contains PlaceHolderView/ListViews and item are being adding through method annotated with
@Resolve
, then first make the list empty. This is required because duplicate viewitems may get added if the recycled view contains PlaceHolderView/ListViews of other itemView. For PlaceHolderView: call removeAllViews() before adding views in method annotated with@Resolve
.
This class is build upon the PlaceHolderView
and implements all the features of ExpandableListView
but with much power and lot easier
@Parent
: Defines the class to be used as the parent in the expandable list.@SingleTop
: Makes only one parent remain in expanded state.@Collapse
: Bind a method of the parent class to listen to the collapse event.@Expand
: Bind a method of the parent class to listen to the Expand event.@ParentPosition
: Bind an int variable to update with relative position among parents.@ChildPosition
: Bind an int variable to update with relative position among children of a parent.@Toggle
: Bind a view to be used as a trigger for expanding or collapsing a parent view. If not provided then the parent view becomes a toggle by default.
This class is bundled with view that can create beautiful card stacks like Tinder, LinkdIn and Card Games. This class provides methods to customize the behavior of the stack, gesture inputs and animations.
@SwipeIn
: It binds a method and calls it when a view is swiped in/accepted@SwipeOut
: It binds a method and calls it when a view is swiped out/rejected.@SwipeCancelState
: It binds a method and calls it when a card is put back in the stack/canceled.@SwipeInState
: It binds a method and pings it till a card is moving in the direction of swiping in/accepted@SwipeOutState
: It binds a method and pings it till a card is moving in the direction of swiping out/rejected@SwipeView
: It binds the android.view.View reference to the tinder view
This class provides a mechanism to load the data in bunches for infinite loading. If the scroll reaches the last item, it calls for LoadMore and show the defined loadmore indicator view. When new data it added the indication is removed. To get the callback for loadmore create a class like that used in PlaceHolderView and define a method with @LoadMore
annotation. This method should be used to do network calls and to add new fetched views.
setLoadMoreResolver(T loadMoreResolver)
: This method is used to add a class to be used as indicator for load more. The class can define a view with a progessbar to reflect loading. The class has to be defined in the same way as a class that is used in the PlaceHolderView. See above for PlaceHolderView example.loadingDone()
: After the view has beed added from the new fetch, call this method to remove the loading indicator view.noMoreToLoad()
: When all the data has been fetched, call this method to stop the infinite loading.
@LoadMore
: This annotation calls a method of the class provided insetLoadMoreResolver
with callback when load more is required, i.e. when last item has been seen.
The Full Documentation is in the process of writing. For any query post it in the discussion or janishar.ali@gmail.com
dependencies {
compile 'com.mindorks:placeholderview:0.5.2'
}
com.android.support:recyclerview-v7:24.+
-keepattributes *Annotation*
-keepclassmembers class ** {
@com.mindorks.placeholderview.annotations.** <methods>;
}
Android Beginner Image Gallery
Android Infinite List with Load More
Recent Library: JPost
JPost
is a pubsub library based on massages over a channel. It's very efficient and much powerful than other pubsub libraries. It prevents memory leak and increases code control. Also, provide a mechanism to run code asynchronously.
- In contrast to the existing pub-sub libraries, it hold the subscribers with weakreference. Thus it doesn't create memory leaks.
- Single message can be sent to selected subscribes. This avoids the problem of event getting received at undesirable places. Thus minimising the chances of abnormal application behaviour.
- The subscriber addition can be controlled by using private channels. It minimises the chances of adding subscribes by mistake to receive undesirable messages.
- It is a tiny library < 55kb . Thus not affecting the application overall size.
- It facilitates synchronous as well as asynchronous message delivery and processing.
- It provides a mechanism to run code asynchronously.
Copyright (C) 2016 Janishar Ali Anwar
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