Skip to content

Commit

Permalink
Merge branch 'release/v0.0.6-SNAPSHOT'
Browse files Browse the repository at this point in the history
  • Loading branch information
mikepenz committed Dec 30, 2015
2 parents 26c5eb3 + fb42249 commit eae1f12
Show file tree
Hide file tree
Showing 8 changed files with 143 additions and 58 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#Include in your project
##Using Maven
```javascript
compile('com.mikepenz:fastadapter:0.0.5-SNAPSHOT@aar') {
compile('com.mikepenz:fastadapter:0.0.6-SNAPSHOT@aar') {
transitive = true
}

Expand Down
7 changes: 5 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ android {
applicationId "com.mikepenz.crossfader.app"
minSdkVersion 11
targetSdkVersion 23
versionCode 5
versionName '0.0.5-SNAPSHOT'
versionCode 6
versionName '0.0.6-SNAPSHOT'

applicationVariants.all { variant ->
variant.outputs.each { output ->
Expand Down Expand Up @@ -52,14 +52,17 @@ dependencies {
compile project(':library')

//used to generate the drawer on the left
//https://github.com/mikepenz/MaterialDrawer
compile('com.mikepenz:materialdrawer:4.6.3@aar') {
transitive = true
}
//used to generate the Open Source section
//https://github.com/mikepenz/AboutLibraries
compile('com.mikepenz:aboutlibraries:5.3.4@aar') {
transitive = true
}
//used to display the icons in the drawer
//https://github.com/mikepenz/Android-Iconics
compile 'com.mikepenz:material-design-iconic-typeface:2.2.0.1@aar'

//Used for the StickyHeaderSample
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;

/**
* This sample showcases compatibility the awesome Sticky-Headers library by timehop
Expand All @@ -36,6 +37,10 @@ public class AdvancedSampleActivity extends AppCompatActivity {

//save our FastAdapter
private FastAdapter fastAdapter;
private ItemAdapter itemAdapter;

//the ActionMode
private ActionMode actionMode;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -55,26 +60,14 @@ protected void onCreate(Bundle savedInstanceState) {

//create our adapters
final StickyHeaderAdapter stickyHeaderAdapter = new StickyHeaderAdapter();
itemAdapter = new ItemAdapter();
final HeaderAdapter headerAdapter = new HeaderAdapter();
final ItemAdapter itemAdapter = new ItemAdapter();

//configure our fastAdapter
//as we provide id's for the items we want the hasStableIds enabled to speed up things
fastAdapter.setHasStableIds(true);
fastAdapter.withMultiSelect(true);
fastAdapter.withMultiSelectOnLongClick(true);
fastAdapter.withOnLongClickListener(new FastAdapter.OnLongClickListener() {
@Override
public boolean onLongClick(View v, int position, int relativePosition, IItem item) {
//may check if actionMode is already displayed
startSupportActionMode(new ActionBarCallBack());
findViewById(R.id.action_mode_bar).setBackgroundColor(UIUtils.getThemeColorFromAttrOrRes(AdvancedSampleActivity.this, R.attr.colorPrimary, R.color.material_drawer_primary));

//itemAdapter.removeItemRange(relativePosition, 5);
//itemAdapter.add(position, new PrimaryItem().withName("Awesome :D").withLevel(2).withIdentifier(fastAdapter.getItemCount() + 1000));
return false;
}
});
fastAdapter.withOnClickListener(new FastAdapter.OnClickListener() {
@Override
public boolean onClick(View v, int position, int relativePosition, IItem item) {
Expand All @@ -84,7 +77,27 @@ public boolean onClick(View v, int position, int relativePosition, IItem item) {
return true;
}
}
//Toast.makeText(v.getContext(), ((SectionItem) item).getName().getText(v.getContext()), Toast.LENGTH_SHORT).show();
//if we are current in CAB mode, and we remove the last selection, we want to finish the actionMode
if (actionMode != null && fastAdapter.getSelections().size() == 1 && item.isSelected()) {
actionMode.finish();
}
return false;
}
});
fastAdapter.withOnLongClickListener(new FastAdapter.OnLongClickListener() {
@Override
public boolean onLongClick(View v, int position, int relativePosition, IItem item) {
if (actionMode == null) {
//may check if actionMode is already displayed
actionMode = startSupportActionMode(new ActionBarCallBack());
findViewById(R.id.action_mode_bar).setBackgroundColor(UIUtils.getThemeColorFromAttrOrRes(AdvancedSampleActivity.this, R.attr.colorPrimary, R.color.material_drawer_primary));

//we have to select this on our own as we will consume the event
fastAdapter.select(position);
//we consume this event so the normal onClick isn't called anymore
return true;
}

return false;
}
});
Expand Down Expand Up @@ -162,9 +175,14 @@ class ActionBarCallBack implements ActionMode.Callback {

@Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
//at the moment just one item which removes selection
fastAdapter.deselect();
//after selection is removed we probably want finish the actionMode
//we have to refetch the selections array again and again as the position will change after one item is deleted
Set<Integer> selections = fastAdapter.getSelections();
while (selections.size() > 0) {
itemAdapter.remove(fastAdapter.getRelativePosition(selections.iterator().next()).relativePosition);
selections = fastAdapter.getSelections();
}

//finish the actionMode
mode.finish();
return true;
}
Expand All @@ -183,12 +201,17 @@ public boolean onCreateActionMode(ActionMode mode, Menu menu) {

@Override
public void onDestroyActionMode(ActionMode mode) {
actionMode = null;

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
getWindow().setStatusBarColor(Color.TRANSPARENT);
}

//after we are done with the actionMode we fallback to longClick for multiselect
fastAdapter.withMultiSelectOnLongClick(true);

//actionMode end. deselect everything
fastAdapter.deselect();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,15 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

public class MultiselectSampleActivity extends AppCompatActivity {
//save our FastAdapter
private FastAdapter fastAdapter;
private ItemAdapter itemAdapter;

//the ActionMode
private ActionMode actionMode;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -46,23 +51,38 @@ protected void onCreate(Bundle savedInstanceState) {
fastAdapter = new FastAdapter();

//create our adapters
itemAdapter = new ItemAdapter();
final HeaderAdapter headerAdapter = new HeaderAdapter();
final ItemAdapter itemAdapter = new ItemAdapter();

//configure our fastAdapter
//as we provide id's for the items we want the hasStableIds enabled to speed up things
fastAdapter.setHasStableIds(true);
fastAdapter.withMultiSelect(true);
fastAdapter.withMultiSelectOnLongClick(true);
fastAdapter.withOnClickListener(new FastAdapter.OnClickListener() {
@Override
public boolean onClick(View v, int position, int relativePosition, IItem item) {
//if we are current in CAB mode, and we remove the last selection, we want to finish the actionMode
if (actionMode != null && fastAdapter.getSelections().size() == 1 && item.isSelected()) {
actionMode.finish();
}
return false;
}
});
fastAdapter.withOnLongClickListener(new FastAdapter.OnLongClickListener() {
@Override
public boolean onLongClick(View v, int position, int relativePosition, IItem item) {
//may check if actionMode is already displayed
startSupportActionMode(new ActionBarCallBack());
findViewById(R.id.action_mode_bar).setBackgroundColor(UIUtils.getThemeColorFromAttrOrRes(MultiselectSampleActivity.this, R.attr.colorPrimary, R.color.material_drawer_primary));
if (actionMode == null) {
//may check if actionMode is already displayed
actionMode = startSupportActionMode(new ActionBarCallBack());
findViewById(R.id.action_mode_bar).setBackgroundColor(UIUtils.getThemeColorFromAttrOrRes(MultiselectSampleActivity.this, R.attr.colorPrimary, R.color.material_drawer_primary));

//we have to select this on our own as we will consume the event
fastAdapter.select(position);
//we consume this event so the normal onClick isn't called anymore
return true;
}

//itemAdapter.removeItemRange(relativePosition, 5);
//itemAdapter.add(position, new PrimaryItem().withName("Awesome :D").withLevel(2).withIdentifier(fastAdapter.getItemCount() + 1000));
return false;
}
});
Expand Down Expand Up @@ -119,9 +139,14 @@ class ActionBarCallBack implements ActionMode.Callback {

@Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
//at the moment just one item which removes selection
fastAdapter.deselect();
//after selection is removed we probably want finish the actionMode
//we have to refetch the selections array again and again as the position will change after one item is deleted
Set<Integer> selections = fastAdapter.getSelections();
while (selections.size() > 0) {
itemAdapter.remove(fastAdapter.getRelativePosition(selections.iterator().next()).relativePosition);
selections = fastAdapter.getSelections();
}

//finish the actionMode
mode.finish();
return true;
}
Expand All @@ -140,12 +165,17 @@ public boolean onCreateActionMode(ActionMode mode, Menu menu) {

@Override
public void onDestroyActionMode(ActionMode mode) {
actionMode = null;

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
getWindow().setStatusBarColor(Color.TRANSPARENT);
}

//after we are done with the actionMode we fallback to longClick for multiselect
fastAdapter.withMultiSelectOnLongClick(true);

//actionMode end. deselect everything
fastAdapter.deselect();
}

@Override
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ org.gradle.daemon=true
org.gradle.parallel=true

# Maven stuff
VERSION_NAME=0.0.5-SNAPSHOT
VERSION_CODE=5
VERSION_NAME=0.0.6-SNAPSHOT
VERSION_CODE=6
GROUP=com.mikepenz

POM_DESCRIPTION=FastAdapter Library
Expand Down
4 changes: 2 additions & 2 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ android {
defaultConfig {
minSdkVersion 10
targetSdkVersion 23
versionCode 5
versionName '0.0.5-SNAPSHOT'
versionCode 6
versionName '0.0.6-SNAPSHOT'
}
buildTypes {
release {
Expand Down
Loading

0 comments on commit eae1f12

Please sign in to comment.