Skip to content

Commit

Permalink
Merge pull request #92 from janishar/0.7.3-alpha
Browse files Browse the repository at this point in the history
Add RecyclableEditText and Recycle Callback
  • Loading branch information
janishar authored Feb 16, 2018
2 parents c659237 + 2ee234f commit 4ba5474
Show file tree
Hide file tree
Showing 8 changed files with 169 additions and 92 deletions.
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name="com.mindorks.test.ActivityTinder">
<activity android:name="com.mindorks.test.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.mindorks.placeholderview.annotations.LongClick;
import com.mindorks.placeholderview.annotations.NonReusable;
import com.mindorks.placeholderview.annotations.Position;
import com.mindorks.placeholderview.annotations.Recycle;
import com.mindorks.placeholderview.annotations.Resolve;
import com.mindorks.placeholderview.annotations.View;
import com.mindorks.test.R;
Expand Down Expand Up @@ -45,7 +46,12 @@ public ImageTypeBig(Context context, PlaceHolderView placeHolderView, String ulr
@Resolve
private void onResolved() {
Glide.with(mContext).load(mUlr).into(imageView);
Log.d("DEBUG", "position " + position);
Log.d("DEBUG", "onResolved position " + position);
}

@Recycle
private void onRecycled() {
Log.d("DEBUG", "onRecycled position " + position);
}

@LongClick(R.id.imageView)
Expand Down
6 changes: 3 additions & 3 deletions placeholderview/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ ext {
siteUrl = 'https://github.com/janishar/PlaceHolderView'
gitUrl = 'https://github.com/janishar/PlaceHolderView.git'

libraryVersion = '0.7.2'
libraryVersion = '0.7.3-alpha'

developerId = '[email protected]'
developerName = 'Janishar Ali'
Expand All @@ -31,8 +31,8 @@ android {
defaultConfig {
minSdkVersion 16
targetSdkVersion 25
versionCode 9
versionName "0.7.2"
versionCode 10
versionName "0.7.3-alpha"
}
buildTypes {
release {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,12 @@
* Created by janisharali on 18/08/16.
*/

public class ViewAdapter<T> extends RecyclerView.Adapter<ViewHolder> {
public class ViewAdapter<T> extends RecyclerView.Adapter<ViewHolder<T, ViewBinder<T, View>>> {

private List<ViewBinder<T, View>> mViewBinderList;
private Context mContext;

/**
*
* @param context
*/
public ViewAdapter(Context context) {
Expand All @@ -33,31 +32,29 @@ public ViewAdapter(Context context) {
}

/**
*
* @param parent
* @param viewType
* @return
*/
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
public ViewHolder<T, ViewBinder<T, View>> onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(viewType, parent, false);
return new ViewHolder(view);
return new ViewHolder<>(view);
}

/**
*
* @param holder
* @param position
*/
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
mViewBinderList.get(position).bindView(holder.itemView, position);
public void onBindViewHolder(ViewHolder<T, ViewBinder<T, View>> holder, int position) {
holder.bind(mViewBinderList.get(position), position);
}

@Override
public void onViewAttachedToWindow(ViewHolder holder) {
public void onViewAttachedToWindow(ViewHolder<T, ViewBinder<T, View>> holder) {
super.onViewAttachedToWindow(holder);
if(holder.getLayoutPosition() > RecyclerView.NO_POSITION && holder.getLayoutPosition() < mViewBinderList.size()) {
if (holder.getLayoutPosition() > RecyclerView.NO_POSITION && holder.getLayoutPosition() < mViewBinderList.size()) {
mViewBinderList.get(holder.getLayoutPosition()).bindAnimation(
Utils.getDeviceWidth(mContext),
Utils.getDeviceHeight(mContext),
Expand All @@ -66,7 +63,6 @@ public void onViewAttachedToWindow(ViewHolder holder) {
}

/**
*
* @param position
* @return
*/
Expand All @@ -76,7 +72,6 @@ public int getItemViewType(int position) {
}

/**
*
* @return
*/
@Override
Expand All @@ -85,138 +80,128 @@ public int getItemCount() {
}

/**
*
* @param position
* @throws IndexOutOfBoundsException
*/
protected void removeView(int position)throws IndexOutOfBoundsException{
protected void removeView(int position) throws IndexOutOfBoundsException {
mViewBinderList.get(position).unbind();
mViewBinderList.remove(position);
notifyItemRemoved(position);
}

/**
*
* @param viewResolver
* @throws IndexOutOfBoundsException
*/
protected void addView(T viewResolver)throws IndexOutOfBoundsException{
protected void addView(T viewResolver) throws IndexOutOfBoundsException {
mViewBinderList.add(new ViewBinder<>(viewResolver));
notifyItemInserted(mViewBinderList.size() - 1);
}

/**
*
* @param viewResolver
* @throws IndexOutOfBoundsException
*/
protected void removeView(T viewResolver)throws IndexOutOfBoundsException{
protected void removeView(T viewResolver) throws IndexOutOfBoundsException {
int position = -1;
for(ViewBinder viewBinder : mViewBinderList){
if(viewBinder.getResolver() == viewResolver){
for (ViewBinder viewBinder : mViewBinderList) {
if (viewBinder.getResolver() == viewResolver) {
position = mViewBinderList.indexOf(viewBinder);
break;
}
}
if(position != -1){
if (position != -1) {
mViewBinderList.get(position).unbind();
mViewBinderList.remove(position);
notifyItemRemoved(position);
}
}

/**
*
* @param position
* @param viewResolver
* @throws IndexOutOfBoundsException
*/
protected void addView(int position, T viewResolver)throws IndexOutOfBoundsException{
protected void addView(int position, T viewResolver) throws IndexOutOfBoundsException {
mViewBinderList.add(position, new ViewBinder<>(viewResolver));
notifyItemInserted(position);
}

/**
*
* @param resolverOld
* @param resolverNew
* @param after
* @throws Resources.NotFoundException
*/
protected void addView(T resolverOld, T resolverNew, boolean after)throws Resources.NotFoundException{
protected void addView(T resolverOld, T resolverNew, boolean after) throws Resources.NotFoundException {
int position = -1;
for(ViewBinder viewBinder : mViewBinderList){
if(viewBinder.getResolver() == resolverOld){
for (ViewBinder viewBinder : mViewBinderList) {
if (viewBinder.getResolver() == resolverOld) {
position = mViewBinderList.indexOf(viewBinder);
break;
}
}
if(position != -1){
if(after)position++;
if (position != -1) {
if (after) position++;
mViewBinderList.add(position, new ViewBinder<>(resolverNew));
notifyItemInserted(position);
}else{
} else {
throw new Resources.NotFoundException("Old view don't Exists in the list");
}
}

/**
*
* @return
*/
protected List<ViewBinder<T, View>> getViewBinderList() {
return mViewBinderList;
}

/**
*
* @return
*/
protected Context getContext() {
return mContext;
}

/**
*
* @return
*/
protected int getViewBinderListSize(){
protected int getViewBinderListSize() {
return mViewBinderList.size();
}

/**
*
* @param position
* @return
* @throws IndexOutOfBoundsException
*/
protected T getViewResolverAtPosition(int position) throws IndexOutOfBoundsException{
protected T getViewResolverAtPosition(int position) throws IndexOutOfBoundsException {
return mViewBinderList.get(position).getResolver();
}

protected int getViewResolverPosition(T resolver){
for(int i = 0; i < mViewBinderList.size(); i++){
if(mViewBinderList.get(i).getResolver() == resolver){
protected int getViewResolverPosition(T resolver) {
for (int i = 0; i < mViewBinderList.size(); i++) {
if (mViewBinderList.get(i).getResolver() == resolver) {
return i;
}
}
return -1;
}

/**
*
* @return
*/
protected List<T> getAllViewResolvers() {
protected List<T> getAllViewResolvers() {
List<T> resolverList = new ArrayList<>();
for(ViewBinder<T, View> viewBinder : mViewBinderList){
for (ViewBinder<T, View> viewBinder : mViewBinderList) {
resolverList.add(viewBinder.getResolver());
}
return resolverList;
}

protected void removeAllViewBinders(){
for(ViewBinder<T, View> viewBinder : mViewBinderList){
protected void removeAllViewBinders() {
for (ViewBinder<T, View> viewBinder : mViewBinderList) {
viewBinder.unbind();
}
mViewBinderList.clear();
Expand All @@ -240,4 +225,10 @@ public int compare(ViewBinder<T, View> binder1, ViewBinder<T, View> binder2) {
});
notifyDataSetChanged();
}

@Override
public void onViewRecycled(ViewHolder<T, ViewBinder<T, View>> holder) {
super.onViewRecycled(holder);
holder.recycle();
}
}
Loading

0 comments on commit 4ba5474

Please sign in to comment.