From b5d4ac6358f7d0f5b5d2a5f7764f46403dd94fab Mon Sep 17 00:00:00 2001 From: Mattias Isegran Bergander Date: Sun, 14 Feb 2016 22:35:57 +0100 Subject: [PATCH 01/19] Initial try at adding a simple swipe action to the sample app (cherry picked from commit b1de487) --- app/src/main/AndroidManifest.xml | 3 + .../fastadapter/app/SampleActivity.java | 3 + .../fastadapter/app/SwipeListActivity.java | 207 ++++++++++++++++++ .../app/swipe/SimpleSwipeCallback.java | 76 +++++++ .../app/swipe/SimpleSwipeDragCallback.java | 45 ++++ app/src/main/res/values/strings.xml | 2 + 6 files changed, 336 insertions(+) create mode 100644 app/src/main/java/com/mikepenz/fastadapter/app/SwipeListActivity.java create mode 100644 app/src/main/java/com/mikepenz/fastadapter/app/swipe/SimpleSwipeCallback.java create mode 100644 app/src/main/java/com/mikepenz/fastadapter/app/swipe/SimpleSwipeDragCallback.java diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 2b1f41d7b..f3a524066 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -20,6 +20,9 @@ + diff --git a/app/src/main/java/com/mikepenz/fastadapter/app/SampleActivity.java b/app/src/main/java/com/mikepenz/fastadapter/app/SampleActivity.java index d1799a093..8bbc7038f 100755 --- a/app/src/main/java/com/mikepenz/fastadapter/app/SampleActivity.java +++ b/app/src/main/java/com/mikepenz/fastadapter/app/SampleActivity.java @@ -75,6 +75,7 @@ protected void onCreate(Bundle savedInstanceState) { new PrimaryDrawerItem().withName(R.string.sample_multi_generic_item).withDescription(R.string.sample_multi_generic_item_descr).withSelectable(false).withIdentifier(9).withIcon(MaterialDesignIconic.Icon.gmi_format_list_numbered), new PrimaryDrawerItem().withName(R.string.sample_checkbox_item).withDescription(R.string.sample_checkbox_item_descr).withSelectable(false).withIdentifier(10).withIcon(CommunityMaterial.Icon.cmd_checkbox_marked), new PrimaryDrawerItem().withName(R.string.sample_radiobutton_item).withDescription(R.string.sample_radiobutton_item_descr).withSelectable(false).withIdentifier(11).withIcon(CommunityMaterial.Icon.cmd_radiobox_marked), + new PrimaryDrawerItem().withName(R.string.sample_swipe_list).withDescription(R.string.sample_swipe_list_descr).withSelectable(false).withIdentifier(12).withIcon(MaterialDesignIconic.Icon.gmi_format_align_left), new DividerDrawerItem(), new PrimaryDrawerItem().withName(R.string.open_source).withSelectable(false).withIdentifier(100).withIcon(MaterialDesignIconic.Icon.gmi_github) ) @@ -105,6 +106,8 @@ public boolean onItemClick(View view, int position, IDrawerItem drawerItem) { intent = new Intent(SampleActivity.this, CheckBoxSampleActivity.class); } else if (drawerItem.getIdentifier() == 11) { intent = new Intent(SampleActivity.this, RadioButtonSampleActivity.class); + } else if (drawerItem.getIdentifier() == 12) { + intent = new Intent(SampleActivity.this, SwipeListActivity.class); } else if (drawerItem.getIdentifier() == 100) { intent = new LibsBuilder() .withFields(R.string.class.getFields()) diff --git a/app/src/main/java/com/mikepenz/fastadapter/app/SwipeListActivity.java b/app/src/main/java/com/mikepenz/fastadapter/app/SwipeListActivity.java new file mode 100644 index 000000000..6756002c9 --- /dev/null +++ b/app/src/main/java/com/mikepenz/fastadapter/app/SwipeListActivity.java @@ -0,0 +1,207 @@ +package com.mikepenz.fastadapter.app; + +import android.graphics.Color; +import android.os.Build; +import android.os.Bundle; +import android.support.v4.content.ContextCompat; +import android.support.v7.app.AppCompatActivity; +import android.support.v7.widget.DefaultItemAnimator; +import android.support.v7.widget.LinearLayoutManager; +import android.support.v7.widget.RecyclerView; +import android.support.v7.widget.SearchView; +import android.support.v7.widget.Toolbar; +import android.support.v7.widget.helper.ItemTouchHelper; +import android.text.TextUtils; +import android.view.Menu; +import android.view.MenuInflater; +import android.view.MenuItem; +import android.view.View; +import android.widget.Toast; + +import com.mikepenz.fastadapter.FastAdapter; +import com.mikepenz.fastadapter.IAdapter; +import com.mikepenz.fastadapter.IItemAdapter; +import com.mikepenz.fastadapter.adapters.FastItemAdapter; +import com.mikepenz.fastadapter.app.adapter.FastScrollIndicatorAdapter; +import com.mikepenz.fastadapter.app.items.SampleItem; +import com.mikepenz.fastadapter.app.swipe.SimpleSwipeCallback; +import com.mikepenz.fastadapter.app.swipe.SimpleSwipeDragCallback; +import com.mikepenz.fastadapter.drag.ItemTouchCallback; +import com.mikepenz.fastadapter.drag.SimpleDragCallback; +import com.mikepenz.fastadapter.helpers.UndoHelper; +import com.mikepenz.materialize.MaterializeBuilder; +import com.turingtechnologies.materialscrollbar.AlphabetIndicator; +import com.turingtechnologies.materialscrollbar.DragScrollBar; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Random; + +public class SwipeListActivity extends AppCompatActivity implements ItemTouchCallback, SimpleSwipeCallback.ItemSwipeCallback { + private static final String[] ALPHABET = new String[]{"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"}; + + //save our FastAdapter + private FastItemAdapter fastItemAdapter; + + //drag & drop + private SimpleDragCallback touchCallback; + private ItemTouchHelper touchHelper; + + @Override + protected void onCreate(Bundle savedInstanceState) { + findViewById(android.R.id.content).setSystemUiVisibility(findViewById(android.R.id.content).getSystemUiVisibility() | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR); + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_sample); + + // Handle Toolbar + Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); + setSupportActionBar(toolbar); + + + //style our ui + new MaterializeBuilder().withActivity(this).build(); + + //create our FastAdapter which will manage everything + fastItemAdapter = new FastItemAdapter<>(); + + //configure our fastAdapter + fastItemAdapter.withOnClickListener(new FastAdapter.OnClickListener() { + @Override + public boolean onClick(View v, IAdapter adapter, SampleItem item, int position) { + Toast.makeText(v.getContext(), (item).name.getText(v.getContext()), Toast.LENGTH_LONG).show(); + return false; + } + }); + + //configure the itemAdapter + fastItemAdapter.withFilterPredicate(new IItemAdapter.Predicate() { + @Override + public boolean filter(SampleItem item, CharSequence constraint) { + //return true if we should filter it out + //return false to keep it + return !item.name.getText().toLowerCase().contains(constraint.toString().toLowerCase()); + } + }); + + //get our recyclerView and do basic setup + RecyclerView recyclerView = (RecyclerView) findViewById(R.id.rv); + recyclerView.setLayoutManager(new LinearLayoutManager(this)); + recyclerView.setItemAnimator(new DefaultItemAnimator()); + recyclerView.setAdapter(fastItemAdapter); + + //fill with some sample data + int x = 0; + List items = new ArrayList<>(); + for (String s : ALPHABET) { + int count = new Random().nextInt(20); + for (int i = 1; i <= count; i++) { + items.add(new SampleItem().withName(s + " Test " + x).withIdentifier(100 + x)); + x++; + } + } + fastItemAdapter.add(items); + + + //add drag and drop for item + //and add swipe as well + touchCallback = new SimpleSwipeDragCallback(this, this, ItemTouchHelper.LEFT, Color.GREEN); + touchHelper = new ItemTouchHelper(touchCallback); // Create ItemTouchHelper and pass with parameter the SimpleDragCallback + touchHelper.attachToRecyclerView(recyclerView); // Attach ItemTouchHelper to RecyclerView + + //restore selections (this has to be done after the items were added + fastItemAdapter.withSavedInstanceState(savedInstanceState); + + //set the back arrow in the toolbar + getSupportActionBar().setDisplayHomeAsUpEnabled(true); + getSupportActionBar().setHomeButtonEnabled(false); + } + + @Override + protected void onSaveInstanceState(Bundle outState) { + //add the values which need to be saved from the adapter to the bundle + outState = fastItemAdapter.saveInstanceState(outState); + super.onSaveInstanceState(outState); + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + //handle the click on the back arrow click + switch (item.getItemId()) { + case android.R.id.home: + onBackPressed(); + return true; + + default: + return super.onOptionsItemSelected(item); + } + } + + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + // Inflate the menu items for use in the action bar + MenuInflater inflater = getMenuInflater(); + inflater.inflate(R.menu.search, menu); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { + final SearchView searchView = (SearchView) menu.findItem(R.id.search).getActionView(); + searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { + @Override + public boolean onQueryTextSubmit(String s) { + touchCallback.setIsDragEnabled(false); + fastItemAdapter.filter(s); + return true; + } + + + @Override + public boolean onQueryTextChange(String s) { + fastItemAdapter.filter(s); + touchCallback.setIsDragEnabled(TextUtils.isEmpty(s)); + return true; + } + }); + } else { + menu.findItem(R.id.search).setVisible(false); + } + + return super.onCreateOptionsMenu(menu); + } + + @Override + public boolean itemTouchOnMove(int oldPosition, int newPosition) { + Collections.swap(fastItemAdapter.getAdapterItems(), oldPosition, newPosition); // change position + fastItemAdapter.notifyAdapterItemMoved(oldPosition, newPosition); + return true; + } + + @Override + public void itemSwiped(final int position, int direction) { + // -- Option 1: Direct action -- + //do something when swiped such as: remove, select, ... + //fastItemAdapter.select(position); + //fastItemAdapter.remove(position); + + // -- Option 2: Delayed action -- + //Currently just showing example of modifying current item, could swap it out, or + //set part of the layout as GONE and another as VISIBLE + //Possibly make a general case of this? + fastItemAdapter.getItem(position).withDescription("").withName("Swiped, removing..."); + fastItemAdapter.notifyItemChanged(position); + + Runnable removeRunnable = new Runnable() { + @Override + public void run() { + fastItemAdapter.remove(position); + } + }; + View rv = findViewById(R.id.rv); + rv.postDelayed(removeRunnable, 3000); + + //for undo, add an onClickListener to something (button, image, text) which removes this + //runnable from the message queue (reset the ui as well!) + //rv.removeCallbacks(removeRunnable); + //fastItemAdapter.notifyItemChanged(position); + } + +} diff --git a/app/src/main/java/com/mikepenz/fastadapter/app/swipe/SimpleSwipeCallback.java b/app/src/main/java/com/mikepenz/fastadapter/app/swipe/SimpleSwipeCallback.java new file mode 100644 index 000000000..3ad6983d0 --- /dev/null +++ b/app/src/main/java/com/mikepenz/fastadapter/app/swipe/SimpleSwipeCallback.java @@ -0,0 +1,76 @@ +package com.mikepenz.fastadapter.app.swipe; + +import android.graphics.Canvas; +import android.graphics.Color; +import android.graphics.Paint; +import android.support.annotation.ColorInt; +import android.support.v7.widget.RecyclerView; +import android.support.v7.widget.helper.ItemTouchHelper; +import android.view.View; + +/** + * Created by Mattias on 2016-02-13. + */ +public class SimpleSwipeCallback extends ItemTouchHelper.SimpleCallback { + + public interface ItemSwipeCallback { + + /** + * Called when an item has been swiped + * + * @param position position of item in the adapter + * @param direction direction the item was swiped + * @return true if moved otherwise false + */ + void itemSwiped(int position, int direction); + } + + private final ItemSwipeCallback itemSwipeCallback; + private final int bgColor; + private Paint bgPaint; + + public SimpleSwipeCallback(SimpleSwipeCallback.ItemSwipeCallback itemSwipeCallback) { + this(itemSwipeCallback, ItemTouchHelper.LEFT); + } + + public SimpleSwipeCallback(SimpleSwipeCallback.ItemSwipeCallback itemSwipeCallback, int swipeDirs) { + this(itemSwipeCallback, swipeDirs, Color.RED); + } + + public SimpleSwipeCallback(SimpleSwipeCallback.ItemSwipeCallback itemSwipeCallback, int swipeDirs, @ColorInt int bgColor) { + super(0, swipeDirs); + this.itemSwipeCallback = itemSwipeCallback; + this.bgColor = bgColor; + } + + + @Override + public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) { + int position = viewHolder.getAdapterPosition(); + if (position != RecyclerView.NO_POSITION) { + itemSwipeCallback.itemSwiped(position, direction); + } + } + + @Override + public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) { + // not enabled + return false; + } + + @Override + public void onChildDraw(Canvas c, RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState, boolean isCurrentlyActive) { + View itemView = viewHolder.itemView; + if (viewHolder.getAdapterPosition() == RecyclerView.NO_POSITION) { + return; + } + if (Math.abs(dX) > Math.abs(dY)) { + if (bgPaint == null) { + bgPaint = new Paint(); + bgPaint.setColor(bgColor); + } + c.drawRect(itemView.getRight() + (int) dX, itemView.getTop(), itemView.getRight(), itemView.getBottom(), bgPaint); + } + super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive); + } +} diff --git a/app/src/main/java/com/mikepenz/fastadapter/app/swipe/SimpleSwipeDragCallback.java b/app/src/main/java/com/mikepenz/fastadapter/app/swipe/SimpleSwipeDragCallback.java new file mode 100644 index 000000000..b2f6814c6 --- /dev/null +++ b/app/src/main/java/com/mikepenz/fastadapter/app/swipe/SimpleSwipeDragCallback.java @@ -0,0 +1,45 @@ +package com.mikepenz.fastadapter.app.swipe; + +import android.graphics.Canvas; +import android.graphics.Color; +import android.support.annotation.ColorInt; +import android.support.v7.widget.RecyclerView; +import android.support.v7.widget.helper.ItemTouchHelper; + +import com.mikepenz.fastadapter.drag.ItemTouchCallback; +import com.mikepenz.fastadapter.drag.SimpleDragCallback; + +/** + * Created by Mattias on 2016-02-13. + */ +public class SimpleSwipeDragCallback extends SimpleDragCallback { + + private final SimpleSwipeCallback simpleSwipeCallback; + + public SimpleSwipeDragCallback(ItemTouchCallback itemTouchCallback, SimpleSwipeCallback.ItemSwipeCallback itemSwipeCallback) { + this(itemTouchCallback, itemSwipeCallback, ItemTouchHelper.LEFT); + } + + public SimpleSwipeDragCallback(ItemTouchCallback itemTouchCallback, SimpleSwipeCallback.ItemSwipeCallback itemSwipeCallback, int swipeDirs) { + this(itemTouchCallback, itemSwipeCallback, swipeDirs, Color.RED); + } + + public SimpleSwipeDragCallback(ItemTouchCallback itemTouchCallback, SimpleSwipeCallback.ItemSwipeCallback itemSwipeCallback, int swipeDirs, @ColorInt int bgColor) { + super(itemTouchCallback); + setDefaultSwipeDirs(swipeDirs); + simpleSwipeCallback = new SimpleSwipeCallback(itemSwipeCallback, swipeDirs, bgColor); + } + + + @Override + public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) { + simpleSwipeCallback.onSwiped(viewHolder, direction); + } + + @Override + public void onChildDraw(Canvas c, RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState, boolean isCurrentlyActive) { + simpleSwipeCallback.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive); + //Happen to know that our direct parent class doesn't (currently) draw anything... + //super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive); + } +} diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 66a38112c..947bf9306 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -3,6 +3,8 @@ SimpleItemList Sample FastScroller, Filter, Drag&Drop + SwipeList Sample + Swipe, leave-behinds and actions IconGrid Sample Grid, Expandable ImageList Sample From d1be2660e0c68982d50467b293098a5381a9ed80 Mon Sep 17 00:00:00 2001 From: Mattias Isegran Bergander Date: Sun, 14 Feb 2016 22:39:12 +0100 Subject: [PATCH 02/19] fix multiple quick removals can cause wrong item(s) to be removed (cherry picked from commit ec1edbe) --- .../com/mikepenz/fastadapter/app/SwipeListActivity.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/mikepenz/fastadapter/app/SwipeListActivity.java b/app/src/main/java/com/mikepenz/fastadapter/app/SwipeListActivity.java index 6756002c9..9594baf76 100644 --- a/app/src/main/java/com/mikepenz/fastadapter/app/SwipeListActivity.java +++ b/app/src/main/java/com/mikepenz/fastadapter/app/SwipeListActivity.java @@ -176,7 +176,7 @@ public boolean itemTouchOnMove(int oldPosition, int newPosition) { } @Override - public void itemSwiped(final int position, int direction) { + public void itemSwiped(int position, int direction) { // -- Option 1: Direct action -- //do something when swiped such as: remove, select, ... //fastItemAdapter.select(position); @@ -186,12 +186,14 @@ public void itemSwiped(final int position, int direction) { //Currently just showing example of modifying current item, could swap it out, or //set part of the layout as GONE and another as VISIBLE //Possibly make a general case of this? - fastItemAdapter.getItem(position).withDescription("").withName("Swiped, removing..."); + final SampleItem item = fastItemAdapter.getItem(position); + item.withDescription("").withName("Swiped, removing..."); fastItemAdapter.notifyItemChanged(position); Runnable removeRunnable = new Runnable() { @Override public void run() { + int position = fastItemAdapter.getAdapterPosition(item); fastItemAdapter.remove(position); } }; From 67f4fd9a25ee044746f2fe1af435fa782e7085ec Mon Sep 17 00:00:00 2001 From: Mattias Isegran Bergander Date: Mon, 15 Feb 2016 00:10:34 +0100 Subject: [PATCH 03/19] Added leave-behind icon (cherry picked from commit 819b3a2) --- .../fastadapter/app/SwipeListActivity.java | 15 ++++--- .../app/swipe/SimpleSwipeCallback.java | 39 ++++++++++++++++--- .../app/swipe/SimpleSwipeDragCallback.java | 13 ++++--- 3 files changed, 49 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/com/mikepenz/fastadapter/app/SwipeListActivity.java b/app/src/main/java/com/mikepenz/fastadapter/app/SwipeListActivity.java index 9594baf76..09591e191 100644 --- a/app/src/main/java/com/mikepenz/fastadapter/app/SwipeListActivity.java +++ b/app/src/main/java/com/mikepenz/fastadapter/app/SwipeListActivity.java @@ -1,9 +1,9 @@ package com.mikepenz.fastadapter.app; import android.graphics.Color; +import android.graphics.drawable.Drawable; import android.os.Build; import android.os.Bundle; -import android.support.v4.content.ContextCompat; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.DefaultItemAnimator; import android.support.v7.widget.LinearLayoutManager; @@ -22,16 +22,14 @@ import com.mikepenz.fastadapter.IAdapter; import com.mikepenz.fastadapter.IItemAdapter; import com.mikepenz.fastadapter.adapters.FastItemAdapter; -import com.mikepenz.fastadapter.app.adapter.FastScrollIndicatorAdapter; import com.mikepenz.fastadapter.app.items.SampleItem; import com.mikepenz.fastadapter.app.swipe.SimpleSwipeCallback; import com.mikepenz.fastadapter.app.swipe.SimpleSwipeDragCallback; import com.mikepenz.fastadapter.drag.ItemTouchCallback; import com.mikepenz.fastadapter.drag.SimpleDragCallback; -import com.mikepenz.fastadapter.helpers.UndoHelper; +import com.mikepenz.iconics.IconicsDrawable; +import com.mikepenz.material_design_iconic_typeface_library.MaterialDesignIconic; import com.mikepenz.materialize.MaterializeBuilder; -import com.turingtechnologies.materialscrollbar.AlphabetIndicator; -import com.turingtechnologies.materialscrollbar.DragScrollBar; import java.util.ArrayList; import java.util.Collections; @@ -105,7 +103,12 @@ public boolean filter(SampleItem item, CharSequence constraint) { //add drag and drop for item //and add swipe as well - touchCallback = new SimpleSwipeDragCallback(this, this, ItemTouchHelper.LEFT, Color.GREEN); + Drawable leaveBehindDrawable = new IconicsDrawable(this) + .icon(MaterialDesignIconic.Icon.gmi_delete) + .color(Color.WHITE) + .sizeDp(24); + + touchCallback = new SimpleSwipeDragCallback(this, this, leaveBehindDrawable, ItemTouchHelper.LEFT, Color.RED); touchHelper = new ItemTouchHelper(touchCallback); // Create ItemTouchHelper and pass with parameter the SimpleDragCallback touchHelper.attachToRecyclerView(recyclerView); // Attach ItemTouchHelper to RecyclerView diff --git a/app/src/main/java/com/mikepenz/fastadapter/app/swipe/SimpleSwipeCallback.java b/app/src/main/java/com/mikepenz/fastadapter/app/swipe/SimpleSwipeCallback.java index 3ad6983d0..3922a102d 100644 --- a/app/src/main/java/com/mikepenz/fastadapter/app/swipe/SimpleSwipeCallback.java +++ b/app/src/main/java/com/mikepenz/fastadapter/app/swipe/SimpleSwipeCallback.java @@ -3,11 +3,13 @@ import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; +import android.graphics.drawable.Drawable; import android.support.annotation.ColorInt; import android.support.v7.widget.RecyclerView; import android.support.v7.widget.helper.ItemTouchHelper; import android.view.View; + /** * Created by Mattias on 2016-02-13. */ @@ -23,23 +25,29 @@ public interface ItemSwipeCallback { * @return true if moved otherwise false */ void itemSwiped(int position, int direction); + } private final ItemSwipeCallback itemSwipeCallback; + private final int bgColor; + + private Drawable leaveBehindDrawable; private Paint bgPaint; + private int horizMargin; - public SimpleSwipeCallback(SimpleSwipeCallback.ItemSwipeCallback itemSwipeCallback) { - this(itemSwipeCallback, ItemTouchHelper.LEFT); + public SimpleSwipeCallback(SimpleSwipeCallback.ItemSwipeCallback itemSwipeCallback, Drawable leaveBehindDrawable) { + this(itemSwipeCallback, leaveBehindDrawable, ItemTouchHelper.LEFT); } - public SimpleSwipeCallback(SimpleSwipeCallback.ItemSwipeCallback itemSwipeCallback, int swipeDirs) { - this(itemSwipeCallback, swipeDirs, Color.RED); + public SimpleSwipeCallback(SimpleSwipeCallback.ItemSwipeCallback itemSwipeCallback, Drawable leaveBehindDrawable, int swipeDirs) { + this(itemSwipeCallback, leaveBehindDrawable, swipeDirs, Color.RED); } - public SimpleSwipeCallback(SimpleSwipeCallback.ItemSwipeCallback itemSwipeCallback, int swipeDirs, @ColorInt int bgColor) { + public SimpleSwipeCallback(ItemSwipeCallback itemSwipeCallback, Drawable leaveBehindDrawable, int swipeDirs, @ColorInt int bgColor) { super(0, swipeDirs); this.itemSwipeCallback = itemSwipeCallback; + this.leaveBehindDrawable = leaveBehindDrawable; this.bgColor = bgColor; } @@ -58,6 +66,7 @@ public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHol return false; } + //Inspired/modified from: https://github.com/nemanja-kovacevic/recycler-view-swipe-to-delete/blob/master/app/src/main/java/net/nemanjakovacevic/recyclerviewswipetodelete/MainActivity.java @Override public void onChildDraw(Canvas c, RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState, boolean isCurrentlyActive) { View itemView = viewHolder.itemView; @@ -68,8 +77,26 @@ public void onChildDraw(Canvas c, RecyclerView recyclerView, RecyclerView.ViewHo if (bgPaint == null) { bgPaint = new Paint(); bgPaint.setColor(bgColor); + horizMargin = (int)(16 * recyclerView.getResources().getDisplayMetrics().density); + } + + if (bgColor != Color.TRANSPARENT) { + c.drawRect(itemView.getRight() + (int) dX, itemView.getTop(), itemView.getRight(), itemView.getBottom(), bgPaint); + } + + if (leaveBehindDrawable != null) { + int itemHeight = itemView.getBottom() - itemView.getTop(); + int intrinsicWidth = leaveBehindDrawable.getIntrinsicWidth(); + int intrinsicHeight = leaveBehindDrawable.getIntrinsicWidth(); + + int left = itemView.getRight() - horizMargin - intrinsicWidth; + int right = itemView.getRight() - horizMargin; + int top = itemView.getTop() + (itemHeight - intrinsicHeight)/2; + int bottom = top + intrinsicHeight; + leaveBehindDrawable.setBounds(left, top, right, bottom); + + leaveBehindDrawable.draw(c); } - c.drawRect(itemView.getRight() + (int) dX, itemView.getTop(), itemView.getRight(), itemView.getBottom(), bgPaint); } super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive); } diff --git a/app/src/main/java/com/mikepenz/fastadapter/app/swipe/SimpleSwipeDragCallback.java b/app/src/main/java/com/mikepenz/fastadapter/app/swipe/SimpleSwipeDragCallback.java index b2f6814c6..1098de81b 100644 --- a/app/src/main/java/com/mikepenz/fastadapter/app/swipe/SimpleSwipeDragCallback.java +++ b/app/src/main/java/com/mikepenz/fastadapter/app/swipe/SimpleSwipeDragCallback.java @@ -2,6 +2,7 @@ import android.graphics.Canvas; import android.graphics.Color; +import android.graphics.drawable.Drawable; import android.support.annotation.ColorInt; import android.support.v7.widget.RecyclerView; import android.support.v7.widget.helper.ItemTouchHelper; @@ -16,18 +17,18 @@ public class SimpleSwipeDragCallback extends SimpleDragCallback { private final SimpleSwipeCallback simpleSwipeCallback; - public SimpleSwipeDragCallback(ItemTouchCallback itemTouchCallback, SimpleSwipeCallback.ItemSwipeCallback itemSwipeCallback) { - this(itemTouchCallback, itemSwipeCallback, ItemTouchHelper.LEFT); + public SimpleSwipeDragCallback(ItemTouchCallback itemTouchCallback, SimpleSwipeCallback.ItemSwipeCallback itemSwipeCallback, Drawable leaveBehindDrawable) { + this(itemTouchCallback, itemSwipeCallback, leaveBehindDrawable, ItemTouchHelper.LEFT); } - public SimpleSwipeDragCallback(ItemTouchCallback itemTouchCallback, SimpleSwipeCallback.ItemSwipeCallback itemSwipeCallback, int swipeDirs) { - this(itemTouchCallback, itemSwipeCallback, swipeDirs, Color.RED); + public SimpleSwipeDragCallback(ItemTouchCallback itemTouchCallback, SimpleSwipeCallback.ItemSwipeCallback itemSwipeCallback, Drawable leaveBehindDrawable, int swipeDirs) { + this(itemTouchCallback, itemSwipeCallback, leaveBehindDrawable, swipeDirs, Color.RED); } - public SimpleSwipeDragCallback(ItemTouchCallback itemTouchCallback, SimpleSwipeCallback.ItemSwipeCallback itemSwipeCallback, int swipeDirs, @ColorInt int bgColor) { + public SimpleSwipeDragCallback(ItemTouchCallback itemTouchCallback, SimpleSwipeCallback.ItemSwipeCallback itemSwipeCallback, Drawable leaveBehindDrawable, int swipeDirs, @ColorInt int bgColor) { super(itemTouchCallback); setDefaultSwipeDirs(swipeDirs); - simpleSwipeCallback = new SimpleSwipeCallback(itemSwipeCallback, swipeDirs, bgColor); + simpleSwipeCallback = new SimpleSwipeCallback(itemSwipeCallback, leaveBehindDrawable, swipeDirs, bgColor); } From 7bbb36fd378982337be7d21a6be7fc2d9cc7ab94 Mon Sep 17 00:00:00 2001 From: Mattias Isegran Bergander Date: Tue, 16 Feb 2016 00:28:12 +0100 Subject: [PATCH 04/19] Implement a basic undo action that times out etc (cherry picked from commit 1da110d) --- .../fastadapter/app/SwipeListActivity.java | 52 +++--- .../fastadapter/app/items/SwipeableItem.java | 166 ++++++++++++++++++ .../app/swipe/SimpleSwipeCallback.java | 2 + app/src/main/res/layout/swipeable_item.xml | 86 +++++++++ app/src/main/res/values/ids.xml | 1 + app/src/main/res/values/strings.xml | 1 + 6 files changed, 286 insertions(+), 22 deletions(-) create mode 100644 app/src/main/java/com/mikepenz/fastadapter/app/items/SwipeableItem.java create mode 100644 app/src/main/res/layout/swipeable_item.xml diff --git a/app/src/main/java/com/mikepenz/fastadapter/app/SwipeListActivity.java b/app/src/main/java/com/mikepenz/fastadapter/app/SwipeListActivity.java index 09591e191..e8b5d8de8 100644 --- a/app/src/main/java/com/mikepenz/fastadapter/app/SwipeListActivity.java +++ b/app/src/main/java/com/mikepenz/fastadapter/app/SwipeListActivity.java @@ -4,6 +4,7 @@ import android.graphics.drawable.Drawable; import android.os.Build; import android.os.Bundle; +import android.support.v4.content.ContextCompat; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.DefaultItemAnimator; import android.support.v7.widget.LinearLayoutManager; @@ -23,6 +24,7 @@ import com.mikepenz.fastadapter.IItemAdapter; import com.mikepenz.fastadapter.adapters.FastItemAdapter; import com.mikepenz.fastadapter.app.items.SampleItem; +import com.mikepenz.fastadapter.app.items.SwipeableItem; import com.mikepenz.fastadapter.app.swipe.SimpleSwipeCallback; import com.mikepenz.fastadapter.app.swipe.SimpleSwipeDragCallback; import com.mikepenz.fastadapter.drag.ItemTouchCallback; @@ -40,7 +42,7 @@ public class SwipeListActivity extends AppCompatActivity implements ItemTouchCal private static final String[] ALPHABET = new String[]{"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"}; //save our FastAdapter - private FastItemAdapter fastItemAdapter; + private FastItemAdapter fastItemAdapter; //drag & drop private SimpleDragCallback touchCallback; @@ -64,18 +66,18 @@ protected void onCreate(Bundle savedInstanceState) { fastItemAdapter = new FastItemAdapter<>(); //configure our fastAdapter - fastItemAdapter.withOnClickListener(new FastAdapter.OnClickListener() { + fastItemAdapter.withOnClickListener(new FastAdapter.OnClickListener() { @Override - public boolean onClick(View v, IAdapter adapter, SampleItem item, int position) { + public boolean onClick(View v, IAdapter adapter, SwipeableItem item, int position) { Toast.makeText(v.getContext(), (item).name.getText(v.getContext()), Toast.LENGTH_LONG).show(); return false; } }); //configure the itemAdapter - fastItemAdapter.withFilterPredicate(new IItemAdapter.Predicate() { + fastItemAdapter.withFilterPredicate(new IItemAdapter.Predicate() { @Override - public boolean filter(SampleItem item, CharSequence constraint) { + public boolean filter(SwipeableItem item, CharSequence constraint) { //return true if we should filter it out //return false to keep it return !item.name.getText().toLowerCase().contains(constraint.toString().toLowerCase()); @@ -90,11 +92,11 @@ public boolean filter(SampleItem item, CharSequence constraint) { //fill with some sample data int x = 0; - List items = new ArrayList<>(); + List items = new ArrayList<>(); for (String s : ALPHABET) { int count = new Random().nextInt(20); for (int i = 1; i <= count; i++) { - items.add(new SampleItem().withName(s + " Test " + x).withIdentifier(100 + x)); + items.add(new SwipeableItem().withName(s + " Test " + x).withIdentifier(100 + x)); x++; } } @@ -108,7 +110,7 @@ public boolean filter(SampleItem item, CharSequence constraint) { .color(Color.WHITE) .sizeDp(24); - touchCallback = new SimpleSwipeDragCallback(this, this, leaveBehindDrawable, ItemTouchHelper.LEFT, Color.RED); + touchCallback = new SimpleSwipeDragCallback(this, this, leaveBehindDrawable, ItemTouchHelper.LEFT, ContextCompat.getColor(this, R.color.md_red_900)); touchHelper = new ItemTouchHelper(touchCallback); // Create ItemTouchHelper and pass with parameter the SimpleDragCallback touchHelper.attachToRecyclerView(recyclerView); // Attach ItemTouchHelper to RecyclerView @@ -181,32 +183,38 @@ public boolean itemTouchOnMove(int oldPosition, int newPosition) { @Override public void itemSwiped(int position, int direction) { // -- Option 1: Direct action -- - //do something when swiped such as: remove, select, ... - //fastItemAdapter.select(position); - //fastItemAdapter.remove(position); + //do something when swiped such as: select, remove, update, ...: + //A) fastItemAdapter.select(position); + //B) fastItemAdapter.remove(position); + //C) update item, set "read" if an email etc // -- Option 2: Delayed action -- - //Currently just showing example of modifying current item, could swap it out, or - //set part of the layout as GONE and another as VISIBLE //Possibly make a general case of this? - final SampleItem item = fastItemAdapter.getItem(position); - item.withDescription("").withName("Swiped, removing..."); - fastItemAdapter.notifyItemChanged(position); + final SwipeableItem item = fastItemAdapter.getItem(position); + item.setSwipedDirection(direction); - Runnable removeRunnable = new Runnable() { + final Runnable removeRunnable = new Runnable() { @Override public void run() { int position = fastItemAdapter.getAdapterPosition(item); + item.setSwipedAction(null); fastItemAdapter.remove(position); } }; - View rv = findViewById(R.id.rv); + final View rv = findViewById(R.id.rv); rv.postDelayed(removeRunnable, 3000); - //for undo, add an onClickListener to something (button, image, text) which removes this - //runnable from the message queue (reset the ui as well!) - //rv.removeCallbacks(removeRunnable); - //fastItemAdapter.notifyItemChanged(position); + item.setSwipedAction(new Runnable() { + @Override + public void run() { + rv.removeCallbacks(removeRunnable); + item.setSwipedDirection(0); + int position = fastItemAdapter.getAdapterPosition(item); + fastItemAdapter.notifyItemChanged(position); + } + }); + + fastItemAdapter.notifyItemChanged(position); } } diff --git a/app/src/main/java/com/mikepenz/fastadapter/app/items/SwipeableItem.java b/app/src/main/java/com/mikepenz/fastadapter/app/items/SwipeableItem.java new file mode 100644 index 000000000..e1d310ae9 --- /dev/null +++ b/app/src/main/java/com/mikepenz/fastadapter/app/items/SwipeableItem.java @@ -0,0 +1,166 @@ +package com.mikepenz.fastadapter.app.items; + +import android.support.annotation.StringRes; +import android.support.v7.widget.RecyclerView; +import android.view.View; +import android.widget.TextView; + +import com.mikepenz.fastadapter.app.R; +import com.mikepenz.fastadapter.items.AbstractItem; +import com.mikepenz.fastadapter.utils.ViewHolderFactory; +import com.mikepenz.materialdrawer.holder.StringHolder; + +import butterknife.Bind; +import butterknife.ButterKnife; + +/** + * Created by Mattias on 2016-02-15. + */ +public class SwipeableItem extends AbstractItem { + //the static ViewHolderFactory which will be used to generate the ViewHolder for this Item + private static final ViewHolderFactory FACTORY = new ItemFactory(); + + public StringHolder name; + public StringHolder description; + + public StringHolder undoTextSwipeFromRight; + public StringHolder undoTextSwipeFromLeft; + public StringHolder undoTextSwipeFromTop; + public StringHolder undoTextSwipeFromBottom; + + public int swipedDirection; + private Runnable swipedAction; + + public SwipeableItem withName(String Name) { + this.name = new StringHolder(Name); + return this; + } + + public SwipeableItem withName(@StringRes int NameRes) { + this.name = new StringHolder(NameRes); + return this; + } + + public SwipeableItem withDescription(String description) { + this.description = new StringHolder(description); + return this; + } + + public SwipeableItem withDescription(@StringRes int descriptionRes) { + this.description = new StringHolder(descriptionRes); + return this; + } + + public void setSwipedDirection(int swipedDirection) { + this.swipedDirection = swipedDirection; + } + + public void setSwipedAction(Runnable action) { + this.swipedAction = action; + } + + /** + * defines the type defining this item. must be unique. preferably an id + * + * @return the type + */ + @Override + public int getType() { + return R.id.fastadapter_swipable_item_id; + } + + /** + * defines the layout which will be used for this item in the list + * + * @return the layout for this item + */ + @Override + public int getLayoutRes() { + return R.layout.swipeable_item; + } + + /** + * binds the data of this item onto the viewHolder + * + * @param viewHolder the viewHolder of this item + */ + @Override + public void bindView(ViewHolder viewHolder) { + super.bindView(viewHolder); + + //set the text for the name + StringHolder.applyTo(name, viewHolder.name); + //set the text for the description or hide + StringHolder.applyToOrHide(description, viewHolder.description); + + viewHolder.swipeResultContent.setVisibility(swipedDirection != 0 ? View.VISIBLE : View.GONE); + viewHolder.itemContent.setVisibility(swipedDirection != 0 ? View.GONE : View.VISIBLE); + + CharSequence swipedAction = null; + CharSequence swipedText = null; + if (swipedDirection != 0) { + //FIXME left, right, top, bottom, ... + swipedAction = viewHolder.itemView.getContext().getString(R.string.action_undo); + swipedText = "Swiped"; + } + viewHolder.swipedAction.setText(swipedAction == null ? "" : swipedAction); + viewHolder.swipedText.setText(swipedText == null ? "" : swipedText); + viewHolder.swipedActionRunnable = this.swipedAction; + } + + + /** + * our ItemFactory implementation which creates the ViewHolder for our adapter. + * It is highly recommended to implement a ViewHolderFactory as it is 0-1ms faster for ViewHolder creation, + * and it is also many many times more efficient if you define custom listeners on views within your item. + */ + protected static class ItemFactory implements ViewHolderFactory { + public ViewHolder create(View v) { + return new ViewHolder(v); + } + } + + /** + * return our ViewHolderFactory implementation here + * + * @return + */ + @Override + public ViewHolderFactory getFactory() { + return FACTORY; + } + + + /** + * our ViewHolder + */ + protected static class ViewHolder extends RecyclerView.ViewHolder { + @Bind(R.id.material_drawer_name) + TextView name; + @Bind(R.id.material_drawer_description) + TextView description; + @Bind(R.id.swipe_result_content) + View swipeResultContent; + @Bind(R.id.item_content) + View itemContent; + @Bind(R.id.swiped_text) + TextView swipedText; + @Bind(R.id.swiped_action) + TextView swipedAction; + + public Runnable swipedActionRunnable; + + public ViewHolder(View view) { + super(view); + ButterKnife.bind(this, view); + swipedAction.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (swipedActionRunnable != null) { + swipedActionRunnable.run(); + } + } + }); + } + } +} diff --git a/app/src/main/java/com/mikepenz/fastadapter/app/swipe/SimpleSwipeCallback.java b/app/src/main/java/com/mikepenz/fastadapter/app/swipe/SimpleSwipeCallback.java index 3922a102d..e50ece349 100644 --- a/app/src/main/java/com/mikepenz/fastadapter/app/swipe/SimpleSwipeCallback.java +++ b/app/src/main/java/com/mikepenz/fastadapter/app/swipe/SimpleSwipeCallback.java @@ -54,6 +54,8 @@ public SimpleSwipeCallback(ItemSwipeCallback itemSwipeCallback, Drawable leaveBe @Override public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) { + viewHolder.itemView.setTranslationX(0); + viewHolder.itemView.setTranslationY(0); int position = viewHolder.getAdapterPosition(); if (position != RecyclerView.NO_POSITION) { itemSwipeCallback.itemSwiped(position, direction); diff --git a/app/src/main/res/layout/swipeable_item.xml b/app/src/main/res/layout/swipeable_item.xml new file mode 100644 index 000000000..b6935d3c8 --- /dev/null +++ b/app/src/main/res/layout/swipeable_item.xml @@ -0,0 +1,86 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/ids.xml b/app/src/main/res/values/ids.xml index 4206be355..cd6643caa 100644 --- a/app/src/main/res/values/ids.xml +++ b/app/src/main/res/values/ids.xml @@ -10,4 +10,5 @@ + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 947bf9306..3ca6da62c 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -27,4 +27,5 @@ Use FastAdapters internal state with a RadioButton Open Source Suche + UNDO From cc1b93a22a18aed893a47c66f677a69d52aba126 Mon Sep 17 00:00:00 2001 From: Mattias Isegran Bergander Date: Tue, 16 Feb 2016 02:15:14 +0100 Subject: [PATCH 05/19] swipe in both directions with different colors, icons and actions shown. Implement the actual undo/whatever action as well. (cherry picked from commit 3bf5a05) --- .../fastadapter/app/SwipeListActivity.java | 33 +++++-- .../fastadapter/app/items/SwipeableItem.java | 6 +- .../app/swipe/SimpleSwipeCallback.java | 96 ++++++++++++++----- .../app/swipe/SimpleSwipeDragCallback.java | 32 +++++++ 4 files changed, 136 insertions(+), 31 deletions(-) diff --git a/app/src/main/java/com/mikepenz/fastadapter/app/SwipeListActivity.java b/app/src/main/java/com/mikepenz/fastadapter/app/SwipeListActivity.java index e8b5d8de8..7a1f54ecd 100644 --- a/app/src/main/java/com/mikepenz/fastadapter/app/SwipeListActivity.java +++ b/app/src/main/java/com/mikepenz/fastadapter/app/SwipeListActivity.java @@ -23,7 +23,6 @@ import com.mikepenz.fastadapter.IAdapter; import com.mikepenz.fastadapter.IItemAdapter; import com.mikepenz.fastadapter.adapters.FastItemAdapter; -import com.mikepenz.fastadapter.app.items.SampleItem; import com.mikepenz.fastadapter.app.items.SwipeableItem; import com.mikepenz.fastadapter.app.swipe.SimpleSwipeCallback; import com.mikepenz.fastadapter.app.swipe.SimpleSwipeDragCallback; @@ -105,12 +104,25 @@ public boolean filter(SwipeableItem item, CharSequence constraint) { //add drag and drop for item //and add swipe as well - Drawable leaveBehindDrawable = new IconicsDrawable(this) + Drawable leaveBehindDrawableLeft = new IconicsDrawable(this) .icon(MaterialDesignIconic.Icon.gmi_delete) .color(Color.WHITE) .sizeDp(24); + Drawable leaveBehindDrawableRight = new IconicsDrawable(this) + .icon(MaterialDesignIconic.Icon.gmi_archive) + .color(Color.WHITE) + .sizeDp(24); + + touchCallback = new SimpleSwipeDragCallback( + this, + this, + leaveBehindDrawableLeft, + ItemTouchHelper.LEFT, + ContextCompat.getColor(this, R.color.md_red_900) + ) + .withBackgroundSwipeRight(ContextCompat.getColor(this, R.color.md_blue_900)) + .withLeaveBehindSwipeRight(leaveBehindDrawableRight); - touchCallback = new SimpleSwipeDragCallback(this, this, leaveBehindDrawable, ItemTouchHelper.LEFT, ContextCompat.getColor(this, R.color.md_red_900)); touchHelper = new ItemTouchHelper(touchCallback); // Create ItemTouchHelper and pass with parameter the SimpleDragCallback touchHelper.attachToRecyclerView(recyclerView); // Attach ItemTouchHelper to RecyclerView @@ -189,16 +201,19 @@ public void itemSwiped(int position, int direction) { //C) update item, set "read" if an email etc // -- Option 2: Delayed action -- - //Possibly make a general case of this? final SwipeableItem item = fastItemAdapter.getItem(position); item.setSwipedDirection(direction); + // This can vary depending on direction but remove & archive simulated here both results in + // removal from list final Runnable removeRunnable = new Runnable() { @Override public void run() { - int position = fastItemAdapter.getAdapterPosition(item); item.setSwipedAction(null); - fastItemAdapter.remove(position); + int position = fastItemAdapter.getAdapterPosition(item); + if (position != RecyclerView.NO_POSITION) { + fastItemAdapter.remove(position); + } } }; final View rv = findViewById(R.id.rv); @@ -210,11 +225,15 @@ public void run() { rv.removeCallbacks(removeRunnable); item.setSwipedDirection(0); int position = fastItemAdapter.getAdapterPosition(item); - fastItemAdapter.notifyItemChanged(position); + if (position != RecyclerView.NO_POSITION) { + fastItemAdapter.notifyItemChanged(position); + } } }); fastItemAdapter.notifyItemChanged(position); + + //TODO can this above be made more generic, along with the support in the item? } } diff --git a/app/src/main/java/com/mikepenz/fastadapter/app/items/SwipeableItem.java b/app/src/main/java/com/mikepenz/fastadapter/app/items/SwipeableItem.java index e1d310ae9..6dc376530 100644 --- a/app/src/main/java/com/mikepenz/fastadapter/app/items/SwipeableItem.java +++ b/app/src/main/java/com/mikepenz/fastadapter/app/items/SwipeableItem.java @@ -1,7 +1,9 @@ package com.mikepenz.fastadapter.app.items; import android.support.annotation.StringRes; +import android.support.v4.content.ContextCompat; import android.support.v7.widget.RecyclerView; +import android.support.v7.widget.helper.ItemTouchHelper; import android.view.View; import android.widget.TextView; @@ -99,9 +101,9 @@ public void bindView(ViewHolder viewHolder) { CharSequence swipedAction = null; CharSequence swipedText = null; if (swipedDirection != 0) { - //FIXME left, right, top, bottom, ... swipedAction = viewHolder.itemView.getContext().getString(R.string.action_undo); - swipedText = "Swiped"; + swipedText = swipedDirection == ItemTouchHelper.LEFT ? "Removed" : "Archived"; + viewHolder.swipeResultContent.setBackgroundColor(ContextCompat.getColor(viewHolder.itemView.getContext(), swipedDirection == ItemTouchHelper.LEFT ? R.color.md_red_900 : R.color.md_blue_900)); } viewHolder.swipedAction.setText(swipedAction == null ? "" : swipedAction); viewHolder.swipedText.setText(swipedText == null ? "" : swipedText); diff --git a/app/src/main/java/com/mikepenz/fastadapter/app/swipe/SimpleSwipeCallback.java b/app/src/main/java/com/mikepenz/fastadapter/app/swipe/SimpleSwipeCallback.java index e50ece349..df85d0018 100644 --- a/app/src/main/java/com/mikepenz/fastadapter/app/swipe/SimpleSwipeCallback.java +++ b/app/src/main/java/com/mikepenz/fastadapter/app/swipe/SimpleSwipeCallback.java @@ -1,5 +1,6 @@ package com.mikepenz.fastadapter.app.swipe; +import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; @@ -30,27 +31,65 @@ public interface ItemSwipeCallback { private final ItemSwipeCallback itemSwipeCallback; - private final int bgColor; + private int bgColorLeft; + private int bgColorRight; + private Drawable leaveBehindDrawableLeft; + private Drawable leaveBehindDrawableRight; - private Drawable leaveBehindDrawable; private Paint bgPaint; - private int horizMargin; + private int horizontalMargin = Integer.MAX_VALUE; - public SimpleSwipeCallback(SimpleSwipeCallback.ItemSwipeCallback itemSwipeCallback, Drawable leaveBehindDrawable) { - this(itemSwipeCallback, leaveBehindDrawable, ItemTouchHelper.LEFT); + public SimpleSwipeCallback(SimpleSwipeCallback.ItemSwipeCallback itemSwipeCallback, Drawable leaveBehindDrawableLeft) { + this(itemSwipeCallback, leaveBehindDrawableLeft, ItemTouchHelper.LEFT); } - public SimpleSwipeCallback(SimpleSwipeCallback.ItemSwipeCallback itemSwipeCallback, Drawable leaveBehindDrawable, int swipeDirs) { - this(itemSwipeCallback, leaveBehindDrawable, swipeDirs, Color.RED); + public SimpleSwipeCallback(SimpleSwipeCallback.ItemSwipeCallback itemSwipeCallback, Drawable leaveBehindDrawableLeft, int swipeDirs) { + this(itemSwipeCallback, leaveBehindDrawableLeft, swipeDirs, Color.RED); } - public SimpleSwipeCallback(ItemSwipeCallback itemSwipeCallback, Drawable leaveBehindDrawable, int swipeDirs, @ColorInt int bgColor) { + public SimpleSwipeCallback(ItemSwipeCallback itemSwipeCallback, Drawable leaveBehindDrawableLeft, int swipeDirs, @ColorInt int bgColor) { super(0, swipeDirs); this.itemSwipeCallback = itemSwipeCallback; - this.leaveBehindDrawable = leaveBehindDrawable; - this.bgColor = bgColor; + this.leaveBehindDrawableLeft = leaveBehindDrawableLeft; + this.bgColorLeft = bgColor; } + public SimpleSwipeCallback withLeaveBehindSwipeLeft(Drawable d) { + this.leaveBehindDrawableLeft = d; + setDefaultSwipeDirs(getSwipeDirs(null, null)|ItemTouchHelper.LEFT); + return this; + } + + public SimpleSwipeCallback withLeaveBehindSwipeRight(Drawable d) { + this.leaveBehindDrawableRight = d; + setDefaultSwipeDirs(getSwipeDirs(null, null)|ItemTouchHelper.RIGHT); + return this; + } + + public SimpleSwipeCallback withHorizontalMarginDp(Context ctx, int dp) { + return withHorizontalMarginPx((int) (ctx.getResources().getDisplayMetrics().density * dp)); + } + + public SimpleSwipeCallback withHorizontalMarginPx(int px) { + horizontalMargin = px; + return this; + } + + public SimpleSwipeCallback withBackgroundSwipeLeft(@ColorInt int bgColor) { + bgColorLeft = bgColor; + return this; + } + + public SimpleSwipeCallback withBackgroundSwipeRight(@ColorInt int bgColor) { + bgColorRight = bgColor; + return this; + } + + @Override + public int getSwipeDirs(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) { + //TODO should disallow this if in swiped state + return super.getSwipeDirs(recyclerView, viewHolder); + } @Override public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) { @@ -76,28 +115,41 @@ public void onChildDraw(Canvas c, RecyclerView recyclerView, RecyclerView.ViewHo return; } if (Math.abs(dX) > Math.abs(dY)) { + boolean isLeft = dX < 0; if (bgPaint == null) { bgPaint = new Paint(); - bgPaint.setColor(bgColor); - horizMargin = (int)(16 * recyclerView.getResources().getDisplayMetrics().density); + if (horizontalMargin == Integer.MAX_VALUE) { + withHorizontalMarginDp(recyclerView.getContext(), 16); + } } + bgPaint.setColor(isLeft ? bgColorLeft : bgColorRight); - if (bgColor != Color.TRANSPARENT) { - c.drawRect(itemView.getRight() + (int) dX, itemView.getTop(), itemView.getRight(), itemView.getBottom(), bgPaint); + if (bgPaint.getColor() != Color.TRANSPARENT) { + int left = isLeft ? itemView.getRight()+(int) dX : itemView.getLeft(); + int right = isLeft ? itemView.getRight() : (itemView.getLeft() + (int) dX); + c.drawRect(left, itemView.getTop(), right, itemView.getBottom(), bgPaint); } - if (leaveBehindDrawable != null) { + Drawable drawable = isLeft ? leaveBehindDrawableLeft : leaveBehindDrawableRight; + if (drawable != null) { int itemHeight = itemView.getBottom() - itemView.getTop(); - int intrinsicWidth = leaveBehindDrawable.getIntrinsicWidth(); - int intrinsicHeight = leaveBehindDrawable.getIntrinsicWidth(); - - int left = itemView.getRight() - horizMargin - intrinsicWidth; - int right = itemView.getRight() - horizMargin; + int intrinsicWidth = drawable.getIntrinsicWidth(); + int intrinsicHeight = drawable.getIntrinsicWidth(); + + int left; + int right; + if (isLeft) { + left = itemView.getRight() - horizontalMargin - intrinsicWidth; + right = itemView.getRight() - horizontalMargin; + } else { + left = itemView.getLeft() + horizontalMargin; + right = itemView.getLeft() + horizontalMargin + intrinsicWidth; + } int top = itemView.getTop() + (itemHeight - intrinsicHeight)/2; int bottom = top + intrinsicHeight; - leaveBehindDrawable.setBounds(left, top, right, bottom); + drawable.setBounds(left, top, right, bottom); - leaveBehindDrawable.draw(c); + drawable.draw(c); } } super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive); diff --git a/app/src/main/java/com/mikepenz/fastadapter/app/swipe/SimpleSwipeDragCallback.java b/app/src/main/java/com/mikepenz/fastadapter/app/swipe/SimpleSwipeDragCallback.java index 1098de81b..1b5890b0d 100644 --- a/app/src/main/java/com/mikepenz/fastadapter/app/swipe/SimpleSwipeDragCallback.java +++ b/app/src/main/java/com/mikepenz/fastadapter/app/swipe/SimpleSwipeDragCallback.java @@ -1,5 +1,6 @@ package com.mikepenz.fastadapter.app.swipe; +import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.drawable.Drawable; @@ -31,6 +32,37 @@ public SimpleSwipeDragCallback(ItemTouchCallback itemTouchCallback, SimpleSwipeC simpleSwipeCallback = new SimpleSwipeCallback(itemSwipeCallback, leaveBehindDrawable, swipeDirs, bgColor); } + public SimpleSwipeDragCallback withLeaveBehindSwipeLeft(Drawable d) { + setDefaultSwipeDirs(getSwipeDirs(null, null)|ItemTouchHelper.LEFT); + simpleSwipeCallback.withLeaveBehindSwipeLeft(d); + return this; + } + + public SimpleSwipeDragCallback withLeaveBehindSwipeRight(Drawable d) { + setDefaultSwipeDirs(getSwipeDirs(null, null) | ItemTouchHelper.RIGHT); + simpleSwipeCallback.withLeaveBehindSwipeRight(d); + return this; + } + + public SimpleSwipeDragCallback withHorizontalMarginDp(Context ctx, int dp) { + simpleSwipeCallback.withHorizontalMarginDp(ctx, dp); + return this; + } + + public SimpleSwipeDragCallback withHorizontalMarginPx(int px) { + simpleSwipeCallback.withHorizontalMarginPx(px); + return this; + } + + public SimpleSwipeDragCallback withBackgroundSwipeLeft(@ColorInt int bgColor) { + simpleSwipeCallback.withBackgroundSwipeLeft(bgColor); + return this; + } + + public SimpleSwipeDragCallback withBackgroundSwipeRight(@ColorInt int bgColor) { + simpleSwipeCallback.withBackgroundSwipeRight(bgColor); + return this; + } @Override public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) { From fee65ef6b6514c3c583c27e95766da8937217e92 Mon Sep 17 00:00:00 2001 From: Rainer-Lang Date: Wed, 17 Feb 2016 11:08:50 +0100 Subject: [PATCH 06/19] added samples --- README.md | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 07c7508a8..b751daec6 100644 --- a/README.md +++ b/README.md @@ -8,20 +8,36 @@ Beside being blazing fast, minimizing the code you need to write, it is also rea ##A quick overview: - Click / Long-Click listeners -- Selection / Multi-Selection +- Selection / Multi-Selection [MultiselectSample](https://github.com/mikepenz/FastAdapter/blob/develop/app/src/main/java/com/mikepenz/fastadapter/app/MultiselectSampleActivity.java) + - [CheckBoxSample](https://github.com/mikepenz/FastAdapter/blob/develop/app/src/main/java/com/mikepenz/fastadapter/app/CheckBoxSampleActivity.java) + - [RadioButtonSample](https://github.com/mikepenz/FastAdapter/blob/develop/app/src/main/java/com/mikepenz/fastadapter/app/RadioButtonSampleActivity.java) - Expandable items + - [ExpandableSample](https://github.com/mikepenz/FastAdapter/blob/develop/app/src/main/java/com/mikepenz/fastadapter/app/ExpandableSampleActivity.java) + - [IconGridSample](https://github.com/mikepenz/FastAdapter/blob/develop/app/src/main/java/com/mikepenz/fastadapter/app/IconGridActivity.java) + - [AdvancedSample](https://github.com/mikepenz/FastAdapter/blob/develop/app/src/main/java/com/mikepenz/fastadapter/app/AdvancedSampleActivity.java) - Write less code, get better results - Simple Drag & Drop -- Headers + - [SimpleItemListSample](https://github.com/mikepenz/FastAdapter/blob/develop/app/src/main/java/com/mikepenz/fastadapter/app/SimpleItemListActivity.java) +- Headers + - [StickyHeaderSample](https://github.com/mikepenz/FastAdapter/blob/develop/app/src/main/java/com/mikepenz/fastadapter/app/StickyHeaderSampleActivity.java) + - [AdvancedSample](https://github.com/mikepenz/FastAdapter/blob/develop/app/src/main/java/com/mikepenz/fastadapter/app/AdvancedSampleActivity.java) - Footers - FastScroller (external lib) + - [SimpleItemListSample](https://github.com/mikepenz/FastAdapter/blob/develop/app/src/main/java/com/mikepenz/fastadapter/app/SimpleItemListActivity.java) +- Filter + - [SimpleItemListSample](https://github.com/mikepenz/FastAdapter/blob/develop/app/src/main/java/com/mikepenz/fastadapter/app/SimpleItemListActivity.java) - Highly optimized code - Includes suggestions from the Android Team - Easily extensible +- Split item view and model + - [GenericItem](https://github.com/mikepenz/FastAdapter/blob/develop/app/src/main/java/com/mikepenz/fastadapter/app/GenericItemActivity.java) + - [MultiTypeGenericItem](https://github.com/mikepenz/FastAdapter/blob/develop/app/src/main/java/com/mikepenz/fastadapter/app/MultiTypeGenericItemActivity.java) - Chain other Adapters + - [SimpleItemListSample](https://github.com/mikepenz/FastAdapter/blob/develop/app/src/main/java/com/mikepenz/fastadapter/app/SimpleItemListActivity.java) + - [StickyHeaderSample](https://github.com/mikepenz/FastAdapter/blob/develop/app/src/main/java/com/mikepenz/fastadapter/app/StickyHeaderSampleActivity.java) - Comes with useful Helpers - - ActionModeHelper - - UndoHelper + - ActionModeHelper [MultiselectSample](https://github.com/mikepenz/FastAdapter/blob/develop/app/src/main/java/com/mikepenz/fastadapter/app/MultiselectSampleActivity.java) + - UndoHelper [MultiselectSample](https://github.com/mikepenz/FastAdapter/blob/develop/app/src/main/java/com/mikepenz/fastadapter/app/MultiselectSampleActivity.java) - More to come... #Preview From 581bc5e8c6fcfc2dc592dea28d8bc4e5fa714114 Mon Sep 17 00:00:00 2001 From: rainer-lang Date: Fri, 19 Feb 2016 12:23:34 +0100 Subject: [PATCH 07/19] callback after items filtered --- .../fastadapter/app/SimpleItemListActivity.java | 10 +++++++++- .../mikepenz/fastadapter/adapters/ItemAdapter.java | 12 ++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/mikepenz/fastadapter/app/SimpleItemListActivity.java b/app/src/main/java/com/mikepenz/fastadapter/app/SimpleItemListActivity.java index 90623c341..da57b1abd 100755 --- a/app/src/main/java/com/mikepenz/fastadapter/app/SimpleItemListActivity.java +++ b/app/src/main/java/com/mikepenz/fastadapter/app/SimpleItemListActivity.java @@ -21,6 +21,7 @@ import com.mikepenz.fastadapter.IAdapter; import com.mikepenz.fastadapter.IItemAdapter; import com.mikepenz.fastadapter.adapters.FastItemAdapter; +import com.mikepenz.fastadapter.adapters.ItemAdapter.ItemsFiltered; import com.mikepenz.fastadapter.app.adapter.FastScrollIndicatorAdapter; import com.mikepenz.fastadapter.app.items.SampleItem; import com.mikepenz.fastadapter.drag.ItemTouchCallback; @@ -34,7 +35,7 @@ import java.util.List; import java.util.Random; -public class SimpleItemListActivity extends AppCompatActivity implements ItemTouchCallback { +public class SimpleItemListActivity extends AppCompatActivity implements ItemTouchCallback, ItemsFiltered { private static final String[] ALPHABET = new String[]{"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"}; //save our FastAdapter @@ -82,6 +83,8 @@ public boolean filter(SampleItem item, CharSequence constraint) { } }); + fastItemAdapter.getItemAdapter().setItemsFilteredCallback(this); + //get our recyclerView and do basic setup RecyclerView recyclerView = (RecyclerView) findViewById(R.id.rv); recyclerView.setLayoutManager(new LinearLayoutManager(this)); @@ -175,4 +178,9 @@ public boolean itemTouchOnMove(int oldPosition, int newPosition) { fastItemAdapter.notifyAdapterItemMoved(oldPosition, newPosition); return true; } + + @Override + public void itemsFiltered() { + Toast.makeText(SimpleItemListActivity.this, "filtered items count: " + fastItemAdapter.getItemCount(), Toast.LENGTH_SHORT).show(); + } } diff --git a/library/src/main/java/com/mikepenz/fastadapter/adapters/ItemAdapter.java b/library/src/main/java/com/mikepenz/fastadapter/adapters/ItemAdapter.java index 65f97a00d..cf6431f1e 100644 --- a/library/src/main/java/com/mikepenz/fastadapter/adapters/ItemAdapter.java +++ b/library/src/main/java/com/mikepenz/fastadapter/adapters/ItemAdapter.java @@ -69,6 +69,14 @@ public void filter(CharSequence constraint) { mItemFilter.filter(constraint); } + public void setItemsFilteredCallback(ItemsFiltered callback) { + mItemsFilteredCallback = callback; + } + protected ItemsFiltered mItemsFilteredCallback; + public interface ItemsFiltered { + void itemsFiltered(); + } + /** * @return the order of the items within the FastAdapter */ @@ -354,6 +362,10 @@ protected FilterResults performFiltering(CharSequence constraint) { protected void publishResults(CharSequence constraint, FilterResults results) { // Now we have to inform the adapter about the new list filtered set((List) results.values); + + if (mItemsFilteredCallback != null) { + mItemsFilteredCallback.itemsFiltered(); + } } } } From 16eb2afe11a9ced15a7177025df8a9ceca12f605 Mon Sep 17 00:00:00 2001 From: rainer-lang Date: Fri, 19 Feb 2016 17:32:05 +0100 Subject: [PATCH 08/19] naming changes --- .../fastadapter/app/SimpleItemListActivity.java | 6 +++--- .../mikepenz/fastadapter/adapters/ItemAdapter.java | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/com/mikepenz/fastadapter/app/SimpleItemListActivity.java b/app/src/main/java/com/mikepenz/fastadapter/app/SimpleItemListActivity.java index da57b1abd..2f2ce1315 100755 --- a/app/src/main/java/com/mikepenz/fastadapter/app/SimpleItemListActivity.java +++ b/app/src/main/java/com/mikepenz/fastadapter/app/SimpleItemListActivity.java @@ -21,7 +21,7 @@ import com.mikepenz.fastadapter.IAdapter; import com.mikepenz.fastadapter.IItemAdapter; import com.mikepenz.fastadapter.adapters.FastItemAdapter; -import com.mikepenz.fastadapter.adapters.ItemAdapter.ItemsFiltered; +import com.mikepenz.fastadapter.adapters.ItemAdapter.ItemFilterListener; import com.mikepenz.fastadapter.app.adapter.FastScrollIndicatorAdapter; import com.mikepenz.fastadapter.app.items.SampleItem; import com.mikepenz.fastadapter.drag.ItemTouchCallback; @@ -35,7 +35,7 @@ import java.util.List; import java.util.Random; -public class SimpleItemListActivity extends AppCompatActivity implements ItemTouchCallback, ItemsFiltered { +public class SimpleItemListActivity extends AppCompatActivity implements ItemTouchCallback, ItemFilterListener { private static final String[] ALPHABET = new String[]{"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"}; //save our FastAdapter @@ -83,7 +83,7 @@ public boolean filter(SampleItem item, CharSequence constraint) { } }); - fastItemAdapter.getItemAdapter().setItemsFilteredCallback(this); + fastItemAdapter.getItemAdapter().setItemFilterListener(this); //get our recyclerView and do basic setup RecyclerView recyclerView = (RecyclerView) findViewById(R.id.rv); diff --git a/library/src/main/java/com/mikepenz/fastadapter/adapters/ItemAdapter.java b/library/src/main/java/com/mikepenz/fastadapter/adapters/ItemAdapter.java index cf6431f1e..582ed902f 100644 --- a/library/src/main/java/com/mikepenz/fastadapter/adapters/ItemAdapter.java +++ b/library/src/main/java/com/mikepenz/fastadapter/adapters/ItemAdapter.java @@ -69,11 +69,11 @@ public void filter(CharSequence constraint) { mItemFilter.filter(constraint); } - public void setItemsFilteredCallback(ItemsFiltered callback) { - mItemsFilteredCallback = callback; + public void setItemFilterListener(ItemFilterListener listener) { + mItemFilterListener = listener; } - protected ItemsFiltered mItemsFilteredCallback; - public interface ItemsFiltered { + protected ItemFilterListener mItemFilterListener; + public interface ItemFilterListener { void itemsFiltered(); } @@ -363,8 +363,8 @@ protected void publishResults(CharSequence constraint, FilterResults results) { // Now we have to inform the adapter about the new list filtered set((List) results.values); - if (mItemsFilteredCallback != null) { - mItemsFilteredCallback.itemsFiltered(); + if (mItemFilterListener != null) { + mItemFilterListener.itemsFiltered(); } } } From 9c7f8455ab5191372a1cd99d440748b045ecbd21 Mon Sep 17 00:00:00 2001 From: Mike Penz Date: Mon, 22 Feb 2016 20:07:58 +0100 Subject: [PATCH 09/19] * CIRTICAL bug-fix getItemCount method and rename it to getPreItemCount. * this issue caused mixed up position using when seting and updating the list. it is HIGHLY recommended to update to this version * FIX https://github.com/mikepenz/MaterialDrawer/issues/1019 * also add new getPreItemCountByOrder * some tiny speed improvements --- .../com/mikepenz/fastadapter/FastAdapter.java | 39 +++++++++++++++++-- .../adapters/GenericItemAdapter.java | 11 +++--- .../fastadapter/adapters/ItemAdapter.java | 19 ++++----- 3 files changed, 52 insertions(+), 17 deletions(-) diff --git a/library/src/main/java/com/mikepenz/fastadapter/FastAdapter.java b/library/src/main/java/com/mikepenz/fastadapter/FastAdapter.java index 144edc0cf..abd8f4075 100644 --- a/library/src/main/java/com/mikepenz/fastadapter/FastAdapter.java +++ b/library/src/main/java/com/mikepenz/fastadapter/FastAdapter.java @@ -503,7 +503,6 @@ public long getItemId(int position) { * * @return the global count */ - @Override public int getItemCount() { return mGlobalSize; } @@ -514,14 +513,42 @@ public int getItemCount() { * @param order the number up to which the items are counted * @return the total count of items up to the adapter order */ - public int getItemCount(int order) { + public int getPreItemCountByOrder(int order) { + //if we are empty just return 0 count + if (mGlobalSize == 0) { + return 0; + } + + int size = 0; + + //count the number of items before the adapter with the given order + for (IAdapter adapter : mAdapters.values()) { + if (adapter.getOrder() == order) { + return size; + } else { + size = size + adapter.getAdapterItemCount(); + } + } + + //get the count of items which are before this order + return size; + } + + + /** + * calculates the item count up to a given (excluding this) adapter (defined by the global position of the item) + * + * @param position the global position of an adapter item + * @return the total count of items up to the adapter which holds the given position + */ + public int getPreItemCount(int position) { //if we are empty just return 0 count if (mGlobalSize == 0) { return 0; } //get the count of items which are before this order - return mAdapterSizes.floorKey(order); + return mAdapterSizes.floorKey(position); } /** @@ -568,6 +595,12 @@ public Bundle saveInstanceState(Bundle savedInstanceState, String prefix) { private void cacheSizes() { mAdapterSizes.clear(); int size = 0; + + //we also have to add this for the first adapter otherwise the floorKey method will return the wrong value + if (mAdapters.size() > 0) { + mAdapterSizes.put(0, mAdapters.valueAt(0)); + } + for (IAdapter adapter : mAdapters.values()) { if (adapter.getAdapterItemCount() > 0) { mAdapterSizes.put(size, adapter); diff --git a/library/src/main/java/com/mikepenz/fastadapter/adapters/GenericItemAdapter.java b/library/src/main/java/com/mikepenz/fastadapter/adapters/GenericItemAdapter.java index b0c19ecb2..82428c805 100644 --- a/library/src/main/java/com/mikepenz/fastadapter/adapters/GenericItemAdapter.java +++ b/library/src/main/java/com/mikepenz/fastadapter/adapters/GenericItemAdapter.java @@ -92,7 +92,7 @@ public final void addModel(int position, Model... models) { */ public void addModel(int position, List models) { super.add(position, toItems(models)); - mItems.addAll(position - getFastAdapter().getItemCount(getOrder()), models); + mItems.addAll(position - getFastAdapter().getPreItemCount(position), models); } /** @@ -103,7 +103,7 @@ public void addModel(int position, List models) { */ public void setModel(int position, Model model) { super.set(position, toItem(model)); - mItems.set(position - getFastAdapter().getItemCount(getOrder()), model); + mItems.set(position - getFastAdapter().getPreItemCount(position), model); } /** @@ -125,11 +125,12 @@ public void removeModelRange(int position, int itemCount) { //global position to relative int length = mItems.size(); + int preItemCount = getFastAdapter().getPreItemCount(position); //make sure we do not delete to many items - int saveItemCount = Math.min(itemCount, length - position + getFastAdapter().getItemCount(getOrder())); + int saveItemCount = Math.min(itemCount, length - position + preItemCount); for (int i = 0; i < saveItemCount; i++) { - mItems.remove(position - getFastAdapter().getItemCount(getOrder())); + mItems.remove(position - preItemCount); } } @@ -140,7 +141,7 @@ public void removeModelRange(int position, int itemCount) { */ public void removeModel(int position) { super.remove(position); - mItems.remove(position - getFastAdapter().getItemCount(getOrder())); + mItems.remove(position - getFastAdapter().getPreItemCount(position)); } /** diff --git a/library/src/main/java/com/mikepenz/fastadapter/adapters/ItemAdapter.java b/library/src/main/java/com/mikepenz/fastadapter/adapters/ItemAdapter.java index 582ed902f..7508f021a 100644 --- a/library/src/main/java/com/mikepenz/fastadapter/adapters/ItemAdapter.java +++ b/library/src/main/java/com/mikepenz/fastadapter/adapters/ItemAdapter.java @@ -124,7 +124,7 @@ public int getAdapterPosition(Item item) { * @return the global position */ public int getGlobalPosition(int position) { - return position + getFastAdapter().getItemCount(getOrder()); + return position + getFastAdapter().getPreItemCount(position); } /** @@ -168,7 +168,7 @@ public void set(List items) { //get sizes int newItemsCount = items.size(); int previousItemsCount = mItems.size(); - int itemsBeforeThisAdapter = getFastAdapter().getItemCount(getOrder()); + int itemsBeforeThisAdapter = getFastAdapter().getPreItemCountByOrder(getOrder()); //make sure the new items list is not a reference of the already mItems list if (items != mItems) { @@ -235,7 +235,7 @@ public void add(List items) { } mItems.addAll(items); mapPossibleTypes(items); - getFastAdapter().notifyAdapterItemRangeInserted(getFastAdapter().getItemCount(getOrder()), items.size()); + getFastAdapter().notifyAdapterItemRangeInserted(getFastAdapter().getPreItemCountByOrder(getOrder()), items.size()); } /** @@ -260,7 +260,7 @@ public void add(int position, List items) { IdDistributor.checkIds(items); } if (items != null) { - mItems.addAll(position - getFastAdapter().getItemCount(getOrder()), items); + mItems.addAll(position - getFastAdapter().getPreItemCount(position), items); mapPossibleTypes(items); getFastAdapter().notifyAdapterItemRangeInserted(position, items.size()); } @@ -276,7 +276,7 @@ public void set(int position, Item item) { if (mUseIdDistributor) { IdDistributor.checkId(item); } - mItems.set(position - getFastAdapter().getItemCount(getOrder()), item); + mItems.set(position - getFastAdapter().getPreItemCount(position), item); mapPossibleType(item); getFastAdapter().notifyAdapterItemChanged(position); } @@ -287,7 +287,7 @@ public void set(int position, Item item) { * @param position the global position */ public void remove(int position) { - mItems.remove(position - getFastAdapter().getItemCount(getOrder())); + mItems.remove(position - getFastAdapter().getPreItemCount(position)); getFastAdapter().notifyAdapterItemRemoved(position); } @@ -300,11 +300,12 @@ public void remove(int position) { public void removeRange(int position, int itemCount) { //global position to relative int length = mItems.size(); + int preItemCount = getFastAdapter().getPreItemCount(position); //make sure we do not delete to many items - int saveItemCount = Math.min(itemCount, length - position + getFastAdapter().getItemCount(getOrder())); + int saveItemCount = Math.min(itemCount, length - position + preItemCount); for (int i = 0; i < saveItemCount; i++) { - mItems.remove(position - getFastAdapter().getItemCount(getOrder())); + mItems.remove(position - preItemCount); } getFastAdapter().notifyAdapterItemRangeRemoved(position, saveItemCount); @@ -316,7 +317,7 @@ public void removeRange(int position, int itemCount) { public void clear() { int count = mItems.size(); mItems.clear(); - getFastAdapter().notifyAdapterItemRangeRemoved(getFastAdapter().getItemCount(getOrder()), count); + getFastAdapter().notifyAdapterItemRangeRemoved(getFastAdapter().getPreItemCountByOrder(getOrder()), count); } /** From a20495aafe1d92afe260f4ddb1ab2a1b51bb4eb4 Mon Sep 17 00:00:00 2001 From: Mike Penz Date: Mon, 22 Feb 2016 20:20:26 +0100 Subject: [PATCH 10/19] * split up fastadapter into a new module called fastadapter-addon * this allows to remove the design dependency, and it also minifies the core to the lowest possible size --- app/build.gradle | 1 + .../app/SimpleItemListActivity.java | 4 +-- .../fastadapter/app/SwipeListActivity.java | 4 +-- .../app/swipe/SimpleSwipeDragCallback.java | 4 +-- ...-push.gradle => gradle-jcenter-push.gradle | 0 ...-mvn-push.gradle => gradle-mvn-push.gradle | 0 library-addon/.gitignore | 1 + library-addon/build.gradle | 33 +++++++++++++++++++ library-addon/gradle.properties | 3 ++ library-addon/proguard-rules.pro | 17 ++++++++++ library-addon/src/main/AndroidManifest.xml | 1 + .../fastadapter_addon}/ActionModeHelper.java | 2 +- .../fastadapter_addon}/UndoHelper.java | 2 +- .../drag/ItemTouchCallback.java | 2 +- .../drag/SimpleDragCallback.java | 2 +- library/build.gradle | 4 +-- library/gradle.properties | 19 ----------- settings.gradle | 2 +- 18 files changed, 69 insertions(+), 32 deletions(-) rename library/gradle-jcenter-push.gradle => gradle-jcenter-push.gradle (100%) rename library/gradle-mvn-push.gradle => gradle-mvn-push.gradle (100%) create mode 100644 library-addon/.gitignore create mode 100644 library-addon/build.gradle create mode 100755 library-addon/gradle.properties create mode 100644 library-addon/proguard-rules.pro create mode 100644 library-addon/src/main/AndroidManifest.xml rename {library/src/main/java/com/mikepenz/fastadapter/helpers => library-addon/src/main/java/com/mikepenz/fastadapter_addon}/ActionModeHelper.java (99%) rename {library/src/main/java/com/mikepenz/fastadapter/helpers => library-addon/src/main/java/com/mikepenz/fastadapter_addon}/UndoHelper.java (99%) rename {library/src/main/java/com/mikepenz/fastadapter => library-addon/src/main/java/com/mikepenz/fastadapter_addon}/drag/ItemTouchCallback.java (86%) rename {library/src/main/java/com/mikepenz/fastadapter => library-addon/src/main/java/com/mikepenz/fastadapter_addon}/drag/SimpleDragCallback.java (96%) diff --git a/app/build.gradle b/app/build.gradle index 5d8ce7977..3307cecbe 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -48,6 +48,7 @@ android { dependencies { compile project(':library') + compile project(':library-addon') //used to generate the drawer on the left //https://github.com/mikepenz/MaterialDrawer diff --git a/app/src/main/java/com/mikepenz/fastadapter/app/SimpleItemListActivity.java b/app/src/main/java/com/mikepenz/fastadapter/app/SimpleItemListActivity.java index 2f2ce1315..b57b16b4b 100755 --- a/app/src/main/java/com/mikepenz/fastadapter/app/SimpleItemListActivity.java +++ b/app/src/main/java/com/mikepenz/fastadapter/app/SimpleItemListActivity.java @@ -24,8 +24,8 @@ import com.mikepenz.fastadapter.adapters.ItemAdapter.ItemFilterListener; import com.mikepenz.fastadapter.app.adapter.FastScrollIndicatorAdapter; import com.mikepenz.fastadapter.app.items.SampleItem; -import com.mikepenz.fastadapter.drag.ItemTouchCallback; -import com.mikepenz.fastadapter.drag.SimpleDragCallback; +import com.mikepenz.fastadapter_addon.drag.ItemTouchCallback; +import com.mikepenz.fastadapter_addon.drag.SimpleDragCallback; import com.mikepenz.materialize.MaterializeBuilder; import com.turingtechnologies.materialscrollbar.AlphabetIndicator; import com.turingtechnologies.materialscrollbar.DragScrollBar; diff --git a/app/src/main/java/com/mikepenz/fastadapter/app/SwipeListActivity.java b/app/src/main/java/com/mikepenz/fastadapter/app/SwipeListActivity.java index 7a1f54ecd..37da063bd 100644 --- a/app/src/main/java/com/mikepenz/fastadapter/app/SwipeListActivity.java +++ b/app/src/main/java/com/mikepenz/fastadapter/app/SwipeListActivity.java @@ -26,8 +26,8 @@ import com.mikepenz.fastadapter.app.items.SwipeableItem; import com.mikepenz.fastadapter.app.swipe.SimpleSwipeCallback; import com.mikepenz.fastadapter.app.swipe.SimpleSwipeDragCallback; -import com.mikepenz.fastadapter.drag.ItemTouchCallback; -import com.mikepenz.fastadapter.drag.SimpleDragCallback; +import com.mikepenz.fastadapter_addon.drag.ItemTouchCallback; +import com.mikepenz.fastadapter_addon.drag.SimpleDragCallback; import com.mikepenz.iconics.IconicsDrawable; import com.mikepenz.material_design_iconic_typeface_library.MaterialDesignIconic; import com.mikepenz.materialize.MaterializeBuilder; diff --git a/app/src/main/java/com/mikepenz/fastadapter/app/swipe/SimpleSwipeDragCallback.java b/app/src/main/java/com/mikepenz/fastadapter/app/swipe/SimpleSwipeDragCallback.java index 1b5890b0d..5fe34b680 100644 --- a/app/src/main/java/com/mikepenz/fastadapter/app/swipe/SimpleSwipeDragCallback.java +++ b/app/src/main/java/com/mikepenz/fastadapter/app/swipe/SimpleSwipeDragCallback.java @@ -8,8 +8,8 @@ import android.support.v7.widget.RecyclerView; import android.support.v7.widget.helper.ItemTouchHelper; -import com.mikepenz.fastadapter.drag.ItemTouchCallback; -import com.mikepenz.fastadapter.drag.SimpleDragCallback; +import com.mikepenz.fastadapter_addon.drag.ItemTouchCallback; +import com.mikepenz.fastadapter_addon.drag.SimpleDragCallback; /** * Created by Mattias on 2016-02-13. diff --git a/library/gradle-jcenter-push.gradle b/gradle-jcenter-push.gradle similarity index 100% rename from library/gradle-jcenter-push.gradle rename to gradle-jcenter-push.gradle diff --git a/library/gradle-mvn-push.gradle b/gradle-mvn-push.gradle similarity index 100% rename from library/gradle-mvn-push.gradle rename to gradle-mvn-push.gradle diff --git a/library-addon/.gitignore b/library-addon/.gitignore new file mode 100644 index 000000000..796b96d1c --- /dev/null +++ b/library-addon/.gitignore @@ -0,0 +1 @@ +/build diff --git a/library-addon/build.gradle b/library-addon/build.gradle new file mode 100644 index 000000000..5a83dba68 --- /dev/null +++ b/library-addon/build.gradle @@ -0,0 +1,33 @@ +apply plugin: 'com.android.library' +apply plugin: 'com.novoda.bintray-release' + +android { + compileSdkVersion rootProject.ext.compileSdkVersion + buildToolsVersion rootProject.ext.buildToolsVersion + + defaultConfig { + minSdkVersion 10 + targetSdkVersion 23 + versionCode 110 + versionName '1.1.0' + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt' + } + } + productFlavors { + } + lintOptions { + abortOnError false + } +} + +apply from: '../gradle-mvn-push.gradle' +apply from: '../gradle-jcenter-push.gradle' + +dependencies { + compile project(':library') + compile "com.android.support:design:${rootProject.ext.supportLibVersion}" +} diff --git a/library-addon/gradle.properties b/library-addon/gradle.properties new file mode 100755 index 000000000..bae559f6e --- /dev/null +++ b/library-addon/gradle.properties @@ -0,0 +1,3 @@ +POM_NAME=FastAdapter Library-Addon +POM_ARTIFACT_ID=fastadapter-addon +POM_PACKAGING=aar diff --git a/library-addon/proguard-rules.pro b/library-addon/proguard-rules.pro new file mode 100644 index 000000000..da6f30276 --- /dev/null +++ b/library-addon/proguard-rules.pro @@ -0,0 +1,17 @@ +# Add project specific ProGuard rules here. +# By default, the flags in this file are appended to flags specified +# in /Development/android-sdk/tools/proguard/proguard-android.txt +# You can edit the include path and order by changing the proguardFiles +# directive in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# Add any project specific keep options here: + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} diff --git a/library-addon/src/main/AndroidManifest.xml b/library-addon/src/main/AndroidManifest.xml new file mode 100644 index 000000000..c97aaa149 --- /dev/null +++ b/library-addon/src/main/AndroidManifest.xml @@ -0,0 +1 @@ + diff --git a/library/src/main/java/com/mikepenz/fastadapter/helpers/ActionModeHelper.java b/library-addon/src/main/java/com/mikepenz/fastadapter_addon/ActionModeHelper.java similarity index 99% rename from library/src/main/java/com/mikepenz/fastadapter/helpers/ActionModeHelper.java rename to library-addon/src/main/java/com/mikepenz/fastadapter_addon/ActionModeHelper.java index 59cc35318..748dd84c2 100644 --- a/library/src/main/java/com/mikepenz/fastadapter/helpers/ActionModeHelper.java +++ b/library-addon/src/main/java/com/mikepenz/fastadapter_addon/ActionModeHelper.java @@ -1,4 +1,4 @@ -package com.mikepenz.fastadapter.helpers; +package com.mikepenz.fastadapter_addon; import android.support.annotation.MenuRes; diff --git a/library/src/main/java/com/mikepenz/fastadapter/helpers/UndoHelper.java b/library-addon/src/main/java/com/mikepenz/fastadapter_addon/UndoHelper.java similarity index 99% rename from library/src/main/java/com/mikepenz/fastadapter/helpers/UndoHelper.java rename to library-addon/src/main/java/com/mikepenz/fastadapter_addon/UndoHelper.java index 3f644a5a0..3b14ec346 100644 --- a/library/src/main/java/com/mikepenz/fastadapter/helpers/UndoHelper.java +++ b/library-addon/src/main/java/com/mikepenz/fastadapter_addon/UndoHelper.java @@ -1,4 +1,4 @@ -package com.mikepenz.fastadapter.helpers; +package com.mikepenz.fastadapter_addon; import android.support.design.widget.Snackbar; import android.view.View; diff --git a/library/src/main/java/com/mikepenz/fastadapter/drag/ItemTouchCallback.java b/library-addon/src/main/java/com/mikepenz/fastadapter_addon/drag/ItemTouchCallback.java similarity index 86% rename from library/src/main/java/com/mikepenz/fastadapter/drag/ItemTouchCallback.java rename to library-addon/src/main/java/com/mikepenz/fastadapter_addon/drag/ItemTouchCallback.java index 7578fcbaa..9a0589e86 100644 --- a/library/src/main/java/com/mikepenz/fastadapter/drag/ItemTouchCallback.java +++ b/library-addon/src/main/java/com/mikepenz/fastadapter_addon/drag/ItemTouchCallback.java @@ -1,4 +1,4 @@ -package com.mikepenz.fastadapter.drag; +package com.mikepenz.fastadapter_addon.drag; public interface ItemTouchCallback { diff --git a/library/src/main/java/com/mikepenz/fastadapter/drag/SimpleDragCallback.java b/library-addon/src/main/java/com/mikepenz/fastadapter_addon/drag/SimpleDragCallback.java similarity index 96% rename from library/src/main/java/com/mikepenz/fastadapter/drag/SimpleDragCallback.java rename to library-addon/src/main/java/com/mikepenz/fastadapter_addon/drag/SimpleDragCallback.java index 37eb9413a..6c0e61dfd 100644 --- a/library/src/main/java/com/mikepenz/fastadapter/drag/SimpleDragCallback.java +++ b/library-addon/src/main/java/com/mikepenz/fastadapter_addon/drag/SimpleDragCallback.java @@ -1,4 +1,4 @@ -package com.mikepenz.fastadapter.drag; +package com.mikepenz.fastadapter_addon.drag; import android.support.v7.widget.RecyclerView; import android.support.v7.widget.helper.ItemTouchHelper; diff --git a/library/build.gradle b/library/build.gradle index 9c75f2ef0..60014acc9 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -24,8 +24,8 @@ android { } } -apply from: 'gradle-mvn-push.gradle' -apply from: 'gradle-jcenter-push.gradle' +apply from: '../gradle-mvn-push.gradle' +apply from: '../gradle-jcenter-push.gradle' dependencies { compile "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}" diff --git a/library/gradle.properties b/library/gradle.properties index 14230b7a4..dc0066ddc 100755 --- a/library/gradle.properties +++ b/library/gradle.properties @@ -1,22 +1,3 @@ -# Project-wide Gradle settings. - -# IDE (e.g. Android Studio) users: -# Settings specified in this file will override any Gradle settings -# configured through the IDE. - -# For more details on how to configure your build environment visit -# http://www.gradle.org/docs/current/userguide/build_environment.html - -# Specifies the JVM arguments used for the daemon process. -# The setting is particularly useful for tweaking memory settings. -# Default value: -Xmx10248m -XX:MaxPermSize=256m -# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 - -# When configured, Gradle will run in incubating parallel mode. -# This option should only be used with decoupled projects. More details, visit -# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects -# org.gradle.parallel=true - POM_NAME=FastAdapter Library POM_ARTIFACT_ID=fastadapter POM_PACKAGING=aar diff --git a/settings.gradle b/settings.gradle index ef1bbc736..d0b6d70d7 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,2 +1,2 @@ -include ':app' +include ':app', ':library-addon' include ':library' \ No newline at end of file From 8bd348e013a499222aaa2278ca72a80d848a9141 Mon Sep 17 00:00:00 2001 From: Mike Penz Date: Mon, 22 Feb 2016 20:20:39 +0100 Subject: [PATCH 11/19] * type onClickListener in the ClickListenerHelper --- .../com/mikepenz/fastadapter/helpers/ClickListenerHelper.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/src/main/java/com/mikepenz/fastadapter/helpers/ClickListenerHelper.java b/library/src/main/java/com/mikepenz/fastadapter/helpers/ClickListenerHelper.java index 77339b3e8..c22ae09ce 100644 --- a/library/src/main/java/com/mikepenz/fastadapter/helpers/ClickListenerHelper.java +++ b/library/src/main/java/com/mikepenz/fastadapter/helpers/ClickListenerHelper.java @@ -28,7 +28,7 @@ public ClickListenerHelper(FastAdapter fastAdapter) { * @param view the view which listens for the click * @param onClickListener the listener which gets called */ - public void listen(final RecyclerView.ViewHolder viewHolder, View view, final OnClickListener onClickListener) { + public void listen(final RecyclerView.ViewHolder viewHolder, View view, final OnClickListener onClickListener) { view.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { @@ -49,7 +49,7 @@ public void onClick(View v) { * @param viewId the viewId which listens for the click * @param onClickListener the listener which gets called */ - public void listen(final RecyclerView.ViewHolder viewHolder, @IdRes int viewId, final OnClickListener onClickListener) { + public void listen(final RecyclerView.ViewHolder viewHolder, @IdRes int viewId, final OnClickListener onClickListener) { viewHolder.itemView.findViewById(viewId).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { From 478034e54e1ab0232bba748ad366bee89b30005f Mon Sep 17 00:00:00 2001 From: Mike Penz Date: Mon, 22 Feb 2016 20:20:53 +0100 Subject: [PATCH 12/19] * remove new not needed dependency --- library/build.gradle | 1 - 1 file changed, 1 deletion(-) diff --git a/library/build.gradle b/library/build.gradle index 60014acc9..939ac1a6f 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -31,5 +31,4 @@ dependencies { compile "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}" compile "com.android.support:recyclerview-v7:${rootProject.ext.supportLibVersion}" compile "com.android.support:support-annotations:${rootProject.ext.supportLibVersion}" - compile "com.android.support:design:${rootProject.ext.supportLibVersion}" } From c1a01371ad8578e56c97d4549680dbc9b6a52300 Mon Sep 17 00:00:00 2001 From: Mike Penz Date: Mon, 22 Feb 2016 20:22:33 +0100 Subject: [PATCH 13/19] * update package name to the new module --- .../com/mikepenz/fastadapter/app/AdvancedSampleActivity.java | 2 +- .../mikepenz/fastadapter/app/MultiselectSampleActivity.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/mikepenz/fastadapter/app/AdvancedSampleActivity.java b/app/src/main/java/com/mikepenz/fastadapter/app/AdvancedSampleActivity.java index 82d9155c3..13e7926c4 100755 --- a/app/src/main/java/com/mikepenz/fastadapter/app/AdvancedSampleActivity.java +++ b/app/src/main/java/com/mikepenz/fastadapter/app/AdvancedSampleActivity.java @@ -22,7 +22,7 @@ import com.mikepenz.fastadapter.app.adapter.StickyHeaderAdapter; import com.mikepenz.fastadapter.app.items.ExpandableItem; import com.mikepenz.fastadapter.app.items.SampleItem; -import com.mikepenz.fastadapter.helpers.ActionModeHelper; +import com.mikepenz.fastadapter_addon.ActionModeHelper; import com.mikepenz.iconics.context.IconicsLayoutInflater; import com.mikepenz.materialize.MaterializeBuilder; import com.mikepenz.materialize.util.UIUtils; diff --git a/app/src/main/java/com/mikepenz/fastadapter/app/MultiselectSampleActivity.java b/app/src/main/java/com/mikepenz/fastadapter/app/MultiselectSampleActivity.java index 23afa14fd..9b57b4438 100755 --- a/app/src/main/java/com/mikepenz/fastadapter/app/MultiselectSampleActivity.java +++ b/app/src/main/java/com/mikepenz/fastadapter/app/MultiselectSampleActivity.java @@ -18,8 +18,8 @@ import com.mikepenz.fastadapter.adapters.HeaderAdapter; import com.mikepenz.fastadapter.adapters.ItemAdapter; import com.mikepenz.fastadapter.app.items.SampleItem; -import com.mikepenz.fastadapter.helpers.ActionModeHelper; -import com.mikepenz.fastadapter.helpers.UndoHelper; +import com.mikepenz.fastadapter_addon.ActionModeHelper; +import com.mikepenz.fastadapter_addon.UndoHelper; import com.mikepenz.itemanimators.SlideDownAlphaAnimator; import com.mikepenz.materialize.MaterializeBuilder; import com.mikepenz.materialize.util.UIUtils; From ecb602c9a9e31cd319e6dd9a06b30c8a9e715ed6 Mon Sep 17 00:00:00 2001 From: Mike Penz Date: Mon, 22 Feb 2016 20:25:11 +0100 Subject: [PATCH 14/19] * rename new module from *addon to *extensions --- app/build.gradle | 2 +- .../com/mikepenz/fastadapter/app/AdvancedSampleActivity.java | 2 +- .../mikepenz/fastadapter/app/MultiselectSampleActivity.java | 4 ++-- .../com/mikepenz/fastadapter/app/SimpleItemListActivity.java | 4 ++-- .../java/com/mikepenz/fastadapter/app/SwipeListActivity.java | 4 ++-- .../fastadapter/app/swipe/SimpleSwipeDragCallback.java | 4 ++-- library-addon/gradle.properties | 3 --- library-addon/src/main/AndroidManifest.xml | 1 - {library-addon => library-extensions}/.gitignore | 0 {library-addon => library-extensions}/build.gradle | 0 library-extensions/gradle.properties | 3 +++ {library-addon => library-extensions}/proguard-rules.pro | 0 library-extensions/src/main/AndroidManifest.xml | 1 + .../mikepenz/fastadapter_extensions}/ActionModeHelper.java | 2 +- .../java/com/mikepenz/fastadapter_extensions}/UndoHelper.java | 2 +- .../fastadapter_extensions}/drag/ItemTouchCallback.java | 2 +- .../fastadapter_extensions}/drag/SimpleDragCallback.java | 2 +- settings.gradle | 2 +- 18 files changed, 19 insertions(+), 19 deletions(-) delete mode 100755 library-addon/gradle.properties delete mode 100644 library-addon/src/main/AndroidManifest.xml rename {library-addon => library-extensions}/.gitignore (100%) rename {library-addon => library-extensions}/build.gradle (100%) create mode 100755 library-extensions/gradle.properties rename {library-addon => library-extensions}/proguard-rules.pro (100%) create mode 100644 library-extensions/src/main/AndroidManifest.xml rename {library-addon/src/main/java/com/mikepenz/fastadapter_addon => library-extensions/src/main/java/com/mikepenz/fastadapter_extensions}/ActionModeHelper.java (99%) rename {library-addon/src/main/java/com/mikepenz/fastadapter_addon => library-extensions/src/main/java/com/mikepenz/fastadapter_extensions}/UndoHelper.java (99%) rename {library-addon/src/main/java/com/mikepenz/fastadapter_addon => library-extensions/src/main/java/com/mikepenz/fastadapter_extensions}/drag/ItemTouchCallback.java (85%) rename {library-addon/src/main/java/com/mikepenz/fastadapter_addon => library-extensions/src/main/java/com/mikepenz/fastadapter_extensions}/drag/SimpleDragCallback.java (96%) diff --git a/app/build.gradle b/app/build.gradle index 3307cecbe..9aec2b2c0 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -48,7 +48,7 @@ android { dependencies { compile project(':library') - compile project(':library-addon') + compile project(':library-extensions') //used to generate the drawer on the left //https://github.com/mikepenz/MaterialDrawer diff --git a/app/src/main/java/com/mikepenz/fastadapter/app/AdvancedSampleActivity.java b/app/src/main/java/com/mikepenz/fastadapter/app/AdvancedSampleActivity.java index 13e7926c4..68a552849 100755 --- a/app/src/main/java/com/mikepenz/fastadapter/app/AdvancedSampleActivity.java +++ b/app/src/main/java/com/mikepenz/fastadapter/app/AdvancedSampleActivity.java @@ -22,7 +22,7 @@ import com.mikepenz.fastadapter.app.adapter.StickyHeaderAdapter; import com.mikepenz.fastadapter.app.items.ExpandableItem; import com.mikepenz.fastadapter.app.items.SampleItem; -import com.mikepenz.fastadapter_addon.ActionModeHelper; +import com.mikepenz.fastadapter_extensions.ActionModeHelper; import com.mikepenz.iconics.context.IconicsLayoutInflater; import com.mikepenz.materialize.MaterializeBuilder; import com.mikepenz.materialize.util.UIUtils; diff --git a/app/src/main/java/com/mikepenz/fastadapter/app/MultiselectSampleActivity.java b/app/src/main/java/com/mikepenz/fastadapter/app/MultiselectSampleActivity.java index 9b57b4438..7714445c3 100755 --- a/app/src/main/java/com/mikepenz/fastadapter/app/MultiselectSampleActivity.java +++ b/app/src/main/java/com/mikepenz/fastadapter/app/MultiselectSampleActivity.java @@ -18,8 +18,8 @@ import com.mikepenz.fastadapter.adapters.HeaderAdapter; import com.mikepenz.fastadapter.adapters.ItemAdapter; import com.mikepenz.fastadapter.app.items.SampleItem; -import com.mikepenz.fastadapter_addon.ActionModeHelper; -import com.mikepenz.fastadapter_addon.UndoHelper; +import com.mikepenz.fastadapter_extensions.ActionModeHelper; +import com.mikepenz.fastadapter_extensions.UndoHelper; import com.mikepenz.itemanimators.SlideDownAlphaAnimator; import com.mikepenz.materialize.MaterializeBuilder; import com.mikepenz.materialize.util.UIUtils; diff --git a/app/src/main/java/com/mikepenz/fastadapter/app/SimpleItemListActivity.java b/app/src/main/java/com/mikepenz/fastadapter/app/SimpleItemListActivity.java index b57b16b4b..f94d3f04e 100755 --- a/app/src/main/java/com/mikepenz/fastadapter/app/SimpleItemListActivity.java +++ b/app/src/main/java/com/mikepenz/fastadapter/app/SimpleItemListActivity.java @@ -24,8 +24,8 @@ import com.mikepenz.fastadapter.adapters.ItemAdapter.ItemFilterListener; import com.mikepenz.fastadapter.app.adapter.FastScrollIndicatorAdapter; import com.mikepenz.fastadapter.app.items.SampleItem; -import com.mikepenz.fastadapter_addon.drag.ItemTouchCallback; -import com.mikepenz.fastadapter_addon.drag.SimpleDragCallback; +import com.mikepenz.fastadapter_extensions.drag.ItemTouchCallback; +import com.mikepenz.fastadapter_extensions.drag.SimpleDragCallback; import com.mikepenz.materialize.MaterializeBuilder; import com.turingtechnologies.materialscrollbar.AlphabetIndicator; import com.turingtechnologies.materialscrollbar.DragScrollBar; diff --git a/app/src/main/java/com/mikepenz/fastadapter/app/SwipeListActivity.java b/app/src/main/java/com/mikepenz/fastadapter/app/SwipeListActivity.java index 37da063bd..66dd1d945 100644 --- a/app/src/main/java/com/mikepenz/fastadapter/app/SwipeListActivity.java +++ b/app/src/main/java/com/mikepenz/fastadapter/app/SwipeListActivity.java @@ -26,8 +26,8 @@ import com.mikepenz.fastadapter.app.items.SwipeableItem; import com.mikepenz.fastadapter.app.swipe.SimpleSwipeCallback; import com.mikepenz.fastadapter.app.swipe.SimpleSwipeDragCallback; -import com.mikepenz.fastadapter_addon.drag.ItemTouchCallback; -import com.mikepenz.fastadapter_addon.drag.SimpleDragCallback; +import com.mikepenz.fastadapter_extensions.drag.ItemTouchCallback; +import com.mikepenz.fastadapter_extensions.drag.SimpleDragCallback; import com.mikepenz.iconics.IconicsDrawable; import com.mikepenz.material_design_iconic_typeface_library.MaterialDesignIconic; import com.mikepenz.materialize.MaterializeBuilder; diff --git a/app/src/main/java/com/mikepenz/fastadapter/app/swipe/SimpleSwipeDragCallback.java b/app/src/main/java/com/mikepenz/fastadapter/app/swipe/SimpleSwipeDragCallback.java index 5fe34b680..92d53461b 100644 --- a/app/src/main/java/com/mikepenz/fastadapter/app/swipe/SimpleSwipeDragCallback.java +++ b/app/src/main/java/com/mikepenz/fastadapter/app/swipe/SimpleSwipeDragCallback.java @@ -8,8 +8,8 @@ import android.support.v7.widget.RecyclerView; import android.support.v7.widget.helper.ItemTouchHelper; -import com.mikepenz.fastadapter_addon.drag.ItemTouchCallback; -import com.mikepenz.fastadapter_addon.drag.SimpleDragCallback; +import com.mikepenz.fastadapter_extensions.drag.ItemTouchCallback; +import com.mikepenz.fastadapter_extensions.drag.SimpleDragCallback; /** * Created by Mattias on 2016-02-13. diff --git a/library-addon/gradle.properties b/library-addon/gradle.properties deleted file mode 100755 index bae559f6e..000000000 --- a/library-addon/gradle.properties +++ /dev/null @@ -1,3 +0,0 @@ -POM_NAME=FastAdapter Library-Addon -POM_ARTIFACT_ID=fastadapter-addon -POM_PACKAGING=aar diff --git a/library-addon/src/main/AndroidManifest.xml b/library-addon/src/main/AndroidManifest.xml deleted file mode 100644 index c97aaa149..000000000 --- a/library-addon/src/main/AndroidManifest.xml +++ /dev/null @@ -1 +0,0 @@ - diff --git a/library-addon/.gitignore b/library-extensions/.gitignore similarity index 100% rename from library-addon/.gitignore rename to library-extensions/.gitignore diff --git a/library-addon/build.gradle b/library-extensions/build.gradle similarity index 100% rename from library-addon/build.gradle rename to library-extensions/build.gradle diff --git a/library-extensions/gradle.properties b/library-extensions/gradle.properties new file mode 100755 index 000000000..cdf45e2d7 --- /dev/null +++ b/library-extensions/gradle.properties @@ -0,0 +1,3 @@ +POM_NAME=FastAdapter Library-Extensions +POM_ARTIFACT_ID=fastadapter-extensions +POM_PACKAGING=aar diff --git a/library-addon/proguard-rules.pro b/library-extensions/proguard-rules.pro similarity index 100% rename from library-addon/proguard-rules.pro rename to library-extensions/proguard-rules.pro diff --git a/library-extensions/src/main/AndroidManifest.xml b/library-extensions/src/main/AndroidManifest.xml new file mode 100644 index 000000000..f982cae13 --- /dev/null +++ b/library-extensions/src/main/AndroidManifest.xml @@ -0,0 +1 @@ + diff --git a/library-addon/src/main/java/com/mikepenz/fastadapter_addon/ActionModeHelper.java b/library-extensions/src/main/java/com/mikepenz/fastadapter_extensions/ActionModeHelper.java similarity index 99% rename from library-addon/src/main/java/com/mikepenz/fastadapter_addon/ActionModeHelper.java rename to library-extensions/src/main/java/com/mikepenz/fastadapter_extensions/ActionModeHelper.java index 748dd84c2..fbd283fe2 100644 --- a/library-addon/src/main/java/com/mikepenz/fastadapter_addon/ActionModeHelper.java +++ b/library-extensions/src/main/java/com/mikepenz/fastadapter_extensions/ActionModeHelper.java @@ -1,4 +1,4 @@ -package com.mikepenz.fastadapter_addon; +package com.mikepenz.fastadapter_extensions; import android.support.annotation.MenuRes; diff --git a/library-addon/src/main/java/com/mikepenz/fastadapter_addon/UndoHelper.java b/library-extensions/src/main/java/com/mikepenz/fastadapter_extensions/UndoHelper.java similarity index 99% rename from library-addon/src/main/java/com/mikepenz/fastadapter_addon/UndoHelper.java rename to library-extensions/src/main/java/com/mikepenz/fastadapter_extensions/UndoHelper.java index 3b14ec346..b94807267 100644 --- a/library-addon/src/main/java/com/mikepenz/fastadapter_addon/UndoHelper.java +++ b/library-extensions/src/main/java/com/mikepenz/fastadapter_extensions/UndoHelper.java @@ -1,4 +1,4 @@ -package com.mikepenz.fastadapter_addon; +package com.mikepenz.fastadapter_extensions; import android.support.design.widget.Snackbar; import android.view.View; diff --git a/library-addon/src/main/java/com/mikepenz/fastadapter_addon/drag/ItemTouchCallback.java b/library-extensions/src/main/java/com/mikepenz/fastadapter_extensions/drag/ItemTouchCallback.java similarity index 85% rename from library-addon/src/main/java/com/mikepenz/fastadapter_addon/drag/ItemTouchCallback.java rename to library-extensions/src/main/java/com/mikepenz/fastadapter_extensions/drag/ItemTouchCallback.java index 9a0589e86..26fd1f9c7 100644 --- a/library-addon/src/main/java/com/mikepenz/fastadapter_addon/drag/ItemTouchCallback.java +++ b/library-extensions/src/main/java/com/mikepenz/fastadapter_extensions/drag/ItemTouchCallback.java @@ -1,4 +1,4 @@ -package com.mikepenz.fastadapter_addon.drag; +package com.mikepenz.fastadapter_extensions.drag; public interface ItemTouchCallback { diff --git a/library-addon/src/main/java/com/mikepenz/fastadapter_addon/drag/SimpleDragCallback.java b/library-extensions/src/main/java/com/mikepenz/fastadapter_extensions/drag/SimpleDragCallback.java similarity index 96% rename from library-addon/src/main/java/com/mikepenz/fastadapter_addon/drag/SimpleDragCallback.java rename to library-extensions/src/main/java/com/mikepenz/fastadapter_extensions/drag/SimpleDragCallback.java index 6c0e61dfd..1d4da6cbf 100644 --- a/library-addon/src/main/java/com/mikepenz/fastadapter_addon/drag/SimpleDragCallback.java +++ b/library-extensions/src/main/java/com/mikepenz/fastadapter_extensions/drag/SimpleDragCallback.java @@ -1,4 +1,4 @@ -package com.mikepenz.fastadapter_addon.drag; +package com.mikepenz.fastadapter_extensions.drag; import android.support.v7.widget.RecyclerView; import android.support.v7.widget.helper.ItemTouchHelper; diff --git a/settings.gradle b/settings.gradle index d0b6d70d7..d4fb34603 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,2 +1,2 @@ -include ':app', ':library-addon' +include ':app', ':library-extensions' include ':library' \ No newline at end of file From fc8b4743b97557dfe0a5e9c1552f601acb496211 Mon Sep 17 00:00:00 2001 From: Mike Penz Date: Mon, 22 Feb 2016 20:27:47 +0100 Subject: [PATCH 15/19] * move SimpleSwipeCallback and SimpleSwipeDragCallback to the new extensions module. (first step of making is part of the lib) --- .../java/com/mikepenz/fastadapter/app/SwipeListActivity.java | 4 ++-- .../fastadapter_extensions}/swipe/SimpleSwipeCallback.java | 2 +- .../swipe/SimpleSwipeDragCallback.java | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) rename {app/src/main/java/com/mikepenz/fastadapter/app => library-extensions/src/main/java/com/mikepenz/fastadapter_extensions}/swipe/SimpleSwipeCallback.java (99%) rename {app/src/main/java/com/mikepenz/fastadapter/app => library-extensions/src/main/java/com/mikepenz/fastadapter_extensions}/swipe/SimpleSwipeDragCallback.java (98%) diff --git a/app/src/main/java/com/mikepenz/fastadapter/app/SwipeListActivity.java b/app/src/main/java/com/mikepenz/fastadapter/app/SwipeListActivity.java index 66dd1d945..b000134fe 100644 --- a/app/src/main/java/com/mikepenz/fastadapter/app/SwipeListActivity.java +++ b/app/src/main/java/com/mikepenz/fastadapter/app/SwipeListActivity.java @@ -24,8 +24,8 @@ import com.mikepenz.fastadapter.IItemAdapter; import com.mikepenz.fastadapter.adapters.FastItemAdapter; import com.mikepenz.fastadapter.app.items.SwipeableItem; -import com.mikepenz.fastadapter.app.swipe.SimpleSwipeCallback; -import com.mikepenz.fastadapter.app.swipe.SimpleSwipeDragCallback; +import com.mikepenz.fastadapter_extensions.swipe.SimpleSwipeCallback; +import com.mikepenz.fastadapter_extensions.swipe.SimpleSwipeDragCallback; import com.mikepenz.fastadapter_extensions.drag.ItemTouchCallback; import com.mikepenz.fastadapter_extensions.drag.SimpleDragCallback; import com.mikepenz.iconics.IconicsDrawable; diff --git a/app/src/main/java/com/mikepenz/fastadapter/app/swipe/SimpleSwipeCallback.java b/library-extensions/src/main/java/com/mikepenz/fastadapter_extensions/swipe/SimpleSwipeCallback.java similarity index 99% rename from app/src/main/java/com/mikepenz/fastadapter/app/swipe/SimpleSwipeCallback.java rename to library-extensions/src/main/java/com/mikepenz/fastadapter_extensions/swipe/SimpleSwipeCallback.java index df85d0018..8d09bac9f 100644 --- a/app/src/main/java/com/mikepenz/fastadapter/app/swipe/SimpleSwipeCallback.java +++ b/library-extensions/src/main/java/com/mikepenz/fastadapter_extensions/swipe/SimpleSwipeCallback.java @@ -1,4 +1,4 @@ -package com.mikepenz.fastadapter.app.swipe; +package com.mikepenz.fastadapter_extensions.swipe; import android.content.Context; import android.graphics.Canvas; diff --git a/app/src/main/java/com/mikepenz/fastadapter/app/swipe/SimpleSwipeDragCallback.java b/library-extensions/src/main/java/com/mikepenz/fastadapter_extensions/swipe/SimpleSwipeDragCallback.java similarity index 98% rename from app/src/main/java/com/mikepenz/fastadapter/app/swipe/SimpleSwipeDragCallback.java rename to library-extensions/src/main/java/com/mikepenz/fastadapter_extensions/swipe/SimpleSwipeDragCallback.java index 92d53461b..e2d1eee16 100644 --- a/app/src/main/java/com/mikepenz/fastadapter/app/swipe/SimpleSwipeDragCallback.java +++ b/library-extensions/src/main/java/com/mikepenz/fastadapter_extensions/swipe/SimpleSwipeDragCallback.java @@ -1,4 +1,4 @@ -package com.mikepenz.fastadapter.app.swipe; +package com.mikepenz.fastadapter_extensions.swipe; import android.content.Context; import android.graphics.Canvas; From 73a7fad749adb8e85677ac5e8f16bb31bc0c725b Mon Sep 17 00:00:00 2001 From: Mike Penz Date: Mon, 22 Feb 2016 20:36:20 +0100 Subject: [PATCH 16/19] * update sample app dependencies * sample app needs the cardview --- app/build.gradle | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 9aec2b2c0..cffbd06ea 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -50,9 +50,11 @@ dependencies { compile project(':library') compile project(':library-extensions') + compile "com.android.support:cardview-v7:${rootProject.ext.supportLibVersion}" + //used to generate the drawer on the left //https://github.com/mikepenz/MaterialDrawer - compile('com.mikepenz:materialdrawer:5.0.0.b24-SNAPSHOT@aar') { + compile('com.mikepenz:materialdrawer:5.0.0@aar') { transitive = true exclude module: "fastadapter" } @@ -61,7 +63,7 @@ dependencies { compile 'com.mikepenz:itemanimators:0.2.1@aar' //used to generate the Open Source section //https://github.com/mikepenz/AboutLibraries - compile('com.mikepenz:aboutlibraries:5.5.0@aar') { + compile('com.mikepenz:aboutlibraries:5.5.2@aar') { transitive = true exclude module: "fastadapter" } @@ -69,7 +71,7 @@ dependencies { //https://github.com/mikepenz/Android-Iconics compile 'com.mikepenz:material-design-iconic-typeface:2.2.0.1@aar' compile 'com.mikepenz:community-material-typeface:1.3.41.1@aar' - compile 'com.mikepenz:google-material-typeface:2.1.0.1.original@aar' + compile 'com.mikepenz:google-material-typeface:2.2.0.1.original@aar' compile 'com.mikepenz:fontawesome-typeface:4.5.0.1@aar' //Used for the StickyHeaderSample @@ -80,7 +82,7 @@ dependencies { //Used to provide the FastScrollBar //https://github.com/krimin-killr21/MaterialScrollBar - compile 'com.turingtechnologies.materialscrollbar:lib:7.1.1' + compile 'com.turingtechnologies.materialscrollbar:lib:8.0.0' //https://github.com/JakeWharton/butterknife compile 'com.jakewharton:butterknife:7.0.1' From efa84ffc7594b816ccf04567c8e1bcf863da68e3 Mon Sep 17 00:00:00 2001 From: Mike Penz Date: Mon, 22 Feb 2016 20:48:19 +0100 Subject: [PATCH 17/19] * add info about new extension --- README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b751daec6..354b68968 100644 --- a/README.md +++ b/README.md @@ -49,8 +49,10 @@ You can try it out here [Google Play](https://play.google.com/store/apps/details #Include in your project ##Using Maven -```javascript -compile('com.mikepenz:fastadapter:1.0.6@aar') { + +The library is split up into core, and extensions. The core functions are included in the following dependency. +```gradle +compile('com.mikepenz:fastadapter:1.1.0@aar') { transitive = true } ``` From 8b1094e7464995fd8e486880dfc380a20b61c1d4 Mon Sep 17 00:00:00 2001 From: Mike Penz Date: Mon, 22 Feb 2016 20:48:31 +0100 Subject: [PATCH 18/19] * fix javadoc issue * formatting --- .../swipe/SimpleSwipeCallback.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/library-extensions/src/main/java/com/mikepenz/fastadapter_extensions/swipe/SimpleSwipeCallback.java b/library-extensions/src/main/java/com/mikepenz/fastadapter_extensions/swipe/SimpleSwipeCallback.java index 8d09bac9f..2f070f7b3 100644 --- a/library-extensions/src/main/java/com/mikepenz/fastadapter_extensions/swipe/SimpleSwipeCallback.java +++ b/library-extensions/src/main/java/com/mikepenz/fastadapter_extensions/swipe/SimpleSwipeCallback.java @@ -23,7 +23,6 @@ public interface ItemSwipeCallback { * * @param position position of item in the adapter * @param direction direction the item was swiped - * @return true if moved otherwise false */ void itemSwiped(int position, int direction); @@ -56,13 +55,13 @@ public SimpleSwipeCallback(ItemSwipeCallback itemSwipeCallback, Drawable leaveBe public SimpleSwipeCallback withLeaveBehindSwipeLeft(Drawable d) { this.leaveBehindDrawableLeft = d; - setDefaultSwipeDirs(getSwipeDirs(null, null)|ItemTouchHelper.LEFT); + setDefaultSwipeDirs(getSwipeDirs(null, null) | ItemTouchHelper.LEFT); return this; } public SimpleSwipeCallback withLeaveBehindSwipeRight(Drawable d) { this.leaveBehindDrawableRight = d; - setDefaultSwipeDirs(getSwipeDirs(null, null)|ItemTouchHelper.RIGHT); + setDefaultSwipeDirs(getSwipeDirs(null, null) | ItemTouchHelper.RIGHT); return this; } @@ -125,7 +124,7 @@ public void onChildDraw(Canvas c, RecyclerView recyclerView, RecyclerView.ViewHo bgPaint.setColor(isLeft ? bgColorLeft : bgColorRight); if (bgPaint.getColor() != Color.TRANSPARENT) { - int left = isLeft ? itemView.getRight()+(int) dX : itemView.getLeft(); + int left = isLeft ? itemView.getRight() + (int) dX : itemView.getLeft(); int right = isLeft ? itemView.getRight() : (itemView.getLeft() + (int) dX); c.drawRect(left, itemView.getTop(), right, itemView.getBottom(), bgPaint); } @@ -145,7 +144,7 @@ public void onChildDraw(Canvas c, RecyclerView recyclerView, RecyclerView.ViewHo left = itemView.getLeft() + horizontalMargin; right = itemView.getLeft() + horizontalMargin + intrinsicWidth; } - int top = itemView.getTop() + (itemHeight - intrinsicHeight)/2; + int top = itemView.getTop() + (itemHeight - intrinsicHeight) / 2; int bottom = top + intrinsicHeight; drawable.setBounds(left, top, right, bottom); From 63d42c10068deddae24a64aa918438744bdd97bd Mon Sep 17 00:00:00 2001 From: Mike Penz Date: Mon, 22 Feb 2016 20:48:41 +0100 Subject: [PATCH 19/19] * [release] v1.1.0 --- README.md | 6 ++++++ app/build.gradle | 4 ++-- gradle.properties | 2 -- library-extensions/build.gradle | 8 +++++--- library-extensions/gradle.properties | 3 +++ library/build.gradle | 12 +++++++----- library/gradle.properties | 3 +++ .../main/res/values/library_fastadapter_strings.xml | 2 +- 8 files changed, 27 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 354b68968..debae880b 100644 --- a/README.md +++ b/README.md @@ -57,6 +57,12 @@ compile('com.mikepenz:fastadapter:1.1.0@aar') { } ``` +All additions are included in the following dependency. +```gradle +compile 'com.mikepenz:fastadapter-extensions:1.1.0@aar' +``` + + ##How to use ###1. Implement your item (the easy way) Just create a class which extends the `AbstractItem` as shown below. Implement the methods, and your item is ready. diff --git a/app/build.gradle b/app/build.gradle index cffbd06ea..2ed34ebe8 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -12,8 +12,8 @@ android { defaultConfig { minSdkVersion 11 targetSdkVersion 23 - versionCode 106 - versionName '1.0.6' + versionCode 110 + versionName '1.1.0' applicationVariants.all { variant -> variant.outputs.each { output -> diff --git a/gradle.properties b/gradle.properties index 61f091f2d..84ffb79be 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,6 +1,4 @@ # Maven stuff -VERSION_NAME=1.0.6 -VERSION_CODE=106 GROUP=com.mikepenz POM_DESCRIPTION=FastAdapter Library diff --git a/library-extensions/build.gradle b/library-extensions/build.gradle index 5a83dba68..656f5ea11 100644 --- a/library-extensions/build.gradle +++ b/library-extensions/build.gradle @@ -1,5 +1,4 @@ apply plugin: 'com.android.library' -apply plugin: 'com.novoda.bintray-release' android { compileSdkVersion rootProject.ext.compileSdkVersion @@ -24,8 +23,11 @@ android { } } -apply from: '../gradle-mvn-push.gradle' -apply from: '../gradle-jcenter-push.gradle' +if (project.hasProperty('pushall') || project.hasProperty('libraryextensiononly')) { + apply from: '../gradle-mvn-push.gradle' + apply plugin: 'com.novoda.bintray-release' + apply from: '../gradle-jcenter-push.gradle' +} dependencies { compile project(':library') diff --git a/library-extensions/gradle.properties b/library-extensions/gradle.properties index cdf45e2d7..6a2530f3f 100755 --- a/library-extensions/gradle.properties +++ b/library-extensions/gradle.properties @@ -1,3 +1,6 @@ POM_NAME=FastAdapter Library-Extensions POM_ARTIFACT_ID=fastadapter-extensions POM_PACKAGING=aar + +VERSION_NAME=1.1.0 +VERSION_CODE=110 \ No newline at end of file diff --git a/library/build.gradle b/library/build.gradle index 939ac1a6f..4be3be31b 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -1,5 +1,4 @@ apply plugin: 'com.android.library' -apply plugin: 'com.novoda.bintray-release' android { compileSdkVersion rootProject.ext.compileSdkVersion @@ -8,8 +7,8 @@ android { defaultConfig { minSdkVersion 10 targetSdkVersion 23 - versionCode 106 - versionName '1.0.6' + versionCode 110 + versionName '1.1.0' } buildTypes { release { @@ -24,8 +23,11 @@ android { } } -apply from: '../gradle-mvn-push.gradle' -apply from: '../gradle-jcenter-push.gradle' +if (project.hasProperty('pushall') || project.hasProperty('librarycoreonly')) { + apply from: '../gradle-mvn-push.gradle' + apply plugin: 'com.novoda.bintray-release' + apply from: '../gradle-jcenter-push.gradle' +} dependencies { compile "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}" diff --git a/library/gradle.properties b/library/gradle.properties index dc0066ddc..48a600d6d 100755 --- a/library/gradle.properties +++ b/library/gradle.properties @@ -1,3 +1,6 @@ POM_NAME=FastAdapter Library POM_ARTIFACT_ID=fastadapter POM_PACKAGING=aar + +VERSION_NAME=1.1.0 +VERSION_CODE=110 \ No newline at end of file diff --git a/library/src/main/res/values/library_fastadapter_strings.xml b/library/src/main/res/values/library_fastadapter_strings.xml index d4ea00f3a..cf28a5763 100755 --- a/library/src/main/res/values/library_fastadapter_strings.xml +++ b/library/src/main/res/values/library_fastadapter_strings.xml @@ -10,7 +10,7 @@ FastAdapter, the bullet proof, fast and easy to use adapter library, which minimizes developing time to a fraction... ]]> - 1.0.6 + 1.1.0 https://github.com/mikepenz/FastAdapter apache_2_0 true