Skip to content

Commit

Permalink
Merge branch 'release/v1.0.4'
Browse files Browse the repository at this point in the history
  • Loading branch information
mikepenz committed Feb 8, 2016
2 parents e5d2c91 + cdf2aa3 commit 1cd871b
Show file tree
Hide file tree
Showing 16 changed files with 698 additions and 10 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ 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.3@aar') {
compile('com.mikepenz:fastadapter:1.0.4@aar') {
transitive = true
}
```
Expand Down
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ android {
defaultConfig {
minSdkVersion 11
targetSdkVersion 23
versionCode 103
versionName '1.0.3'
versionCode 104
versionName '1.0.4'

applicationVariants.all { variant ->
variant.outputs.each { output ->
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,11 @@
<activity
android:name=".MultiTypeGenericItemActivity"
android:label="@string/sample_multi_generic_item" />
<activity
android:name=".CheckBoxSampleActivity"
android:label="@string/sample_checkbox_item" />
<activity
android:name=".RadioButtonSampleActivity"
android:label="@string/sample_radiobutton_item" />
</application>
</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
package com.mikepenz.fastadapter.app;

import android.os.Bundle;
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.Toolbar;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import com.mikepenz.fastadapter.FastAdapter;
import com.mikepenz.fastadapter.IAdapter;
import com.mikepenz.fastadapter.adapters.FastItemAdapter;
import com.mikepenz.fastadapter.app.items.CheckBoxSampleItem;
import com.mikepenz.fastadapter.helpers.ClickListenerHelper;
import com.mikepenz.materialize.MaterializeBuilder;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class CheckBoxSampleActivity extends AppCompatActivity {
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"};

//our recyclerView
private RecyclerView recyclerView;

//save our FastAdapter
private FastItemAdapter<CheckBoxSampleItem> fastItemAdapter;

private ClickListenerHelper<CheckBoxSampleItem> mClickListenerHelper;

@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<CheckBoxSampleItem>() {
@Override
public boolean onClick(View v, IAdapter<CheckBoxSampleItem> adapter, CheckBoxSampleItem item, int position) {
Toast.makeText(v.getContext(), (item).name.getText(v.getContext()), Toast.LENGTH_LONG).show();
return false;
}
});

//init the ClickListenerHelper which simplifies custom click listeners on views of the Adapter
mClickListenerHelper = new ClickListenerHelper<>(fastItemAdapter);

fastItemAdapter.withOnPreClickListener(new FastAdapter.OnClickListener<CheckBoxSampleItem>() {
@Override
public boolean onClick(View v, IAdapter<CheckBoxSampleItem> adapter, CheckBoxSampleItem item, int position) {
// consume otherwise radio/checkbox will be deselected
return true;
}
});

fastItemAdapter.withOnCreateViewHolderListener(new FastAdapter.OnCreateViewHolderListener() {
@Override
public RecyclerView.ViewHolder onPreCreateViewHolder(ViewGroup parent, int viewType) {
return fastItemAdapter.getTypeInstance(viewType).getViewHolder(parent);
}

@Override
public RecyclerView.ViewHolder onPostCreateViewHolder(final RecyclerView.ViewHolder viewHolder) {
mClickListenerHelper.listen(viewHolder, ((CheckBoxSampleItem.ViewHolder)viewHolder).checkBox, new ClickListenerHelper.OnClickListener<CheckBoxSampleItem>() {
@Override
public void onClick(View v, int position, CheckBoxSampleItem item) {
fastItemAdapter.toggleSelection(position);
}
});
return viewHolder;
}
});

//get our recyclerView and do basic setup
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<CheckBoxSampleItem> items = new ArrayList<>();
for (String s : ALPHABET) {
int count = new Random().nextInt(20);
for (int i = 1; i <= count; i++) {
items.add(new CheckBoxSampleItem().withName(s + " Test " + x).withIdentifier(100 + x));
x++;
}
}
fastItemAdapter.add(items);

//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 bundel
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:
Toast.makeText(getApplicationContext(), "selections = " + fastItemAdapter.getSelections(), Toast.LENGTH_LONG).show();
onBackPressed();
return true;

default:
return super.onOptionsItemSelected(item);
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
package com.mikepenz.fastadapter.app;

import android.os.Bundle;
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.Toolbar;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import com.mikepenz.fastadapter.FastAdapter;
import com.mikepenz.fastadapter.IAdapter;
import com.mikepenz.fastadapter.adapters.FastItemAdapter;
import com.mikepenz.fastadapter.app.items.RadioButtonSampleItem;
import com.mikepenz.fastadapter.helpers.ClickListenerHelper;
import com.mikepenz.materialize.MaterializeBuilder;

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

public class RadioButtonSampleActivity extends AppCompatActivity {
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"};

//our recyclerView
private RecyclerView recyclerView;

//save our FastAdapter
private FastItemAdapter<RadioButtonSampleItem> fastItemAdapter;

private ClickListenerHelper<RadioButtonSampleItem> mClickListenerHelper;

@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<RadioButtonSampleItem>() {
@Override
public boolean onClick(View v, IAdapter<RadioButtonSampleItem> adapter, RadioButtonSampleItem item, int position) {
Toast.makeText(v.getContext(), (item).name.getText(v.getContext()), Toast.LENGTH_LONG).show();
return false;
}
});

//init the ClickListenerHelper which simplifies custom click listeners on views of the Adapter
mClickListenerHelper = new ClickListenerHelper<>(fastItemAdapter);

fastItemAdapter.withOnPreClickListener(new FastAdapter.OnClickListener<RadioButtonSampleItem>() {
@Override
public boolean onClick(View v, IAdapter<RadioButtonSampleItem> adapter, RadioButtonSampleItem item, int position) {
// consume otherwise radio/checkbox will be deselected
return true;
}
});

fastItemAdapter.withOnCreateViewHolderListener(new FastAdapter.OnCreateViewHolderListener() {
@Override
public RecyclerView.ViewHolder onPreCreateViewHolder(ViewGroup parent, int viewType) {
return fastItemAdapter.getTypeInstance(viewType).getViewHolder(parent);
}

@Override
public RecyclerView.ViewHolder onPostCreateViewHolder(final RecyclerView.ViewHolder viewHolder) {
mClickListenerHelper.listen(viewHolder, ((RadioButtonSampleItem.ViewHolder)viewHolder).radioButton, new ClickListenerHelper.OnClickListener<RadioButtonSampleItem>() {
@Override
public void onClick(View v, int position, RadioButtonSampleItem item) {
if (!item.isSelected()) {
Set<Integer> selections = fastItemAdapter.getSelections();
if (!selections.isEmpty()) {
int selectedPosition = selections.iterator().next();
fastItemAdapter.deselect();
fastItemAdapter.notifyItemChanged(selectedPosition);
}
fastItemAdapter.select(position);
}
}
});
return viewHolder;
}
});

//get our recyclerView and do basic setup
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<RadioButtonSampleItem> items = new ArrayList<>();
for (String s : ALPHABET) {
int count = new Random().nextInt(20);
for (int i = 1; i <= count; i++) {
items.add(new RadioButtonSampleItem().withName(s + " Test " + x).withIdentifier(100 + x));
x++;
}
}
fastItemAdapter.add(items);

//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 bundel
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:
Toast.makeText(getApplicationContext(), "selections = " + fastItemAdapter.getSelections(), Toast.LENGTH_LONG).show();
onBackPressed();
return true;

default:
return super.onOptionsItemSelected(item);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import com.mikepenz.aboutlibraries.Libs;
import com.mikepenz.aboutlibraries.LibsBuilder;
import com.mikepenz.community_material_typeface_library.CommunityMaterial;
import com.mikepenz.fastadapter.FastAdapter;
import com.mikepenz.fastadapter.IItem;
import com.mikepenz.fastadapter.adapters.ItemAdapter;
Expand Down Expand Up @@ -72,6 +73,8 @@ protected void onCreate(Bundle savedInstanceState) {
new PrimaryDrawerItem().withName(R.string.sample_advanced).withDescription(R.string.sample_advanced_descr).withSelectable(false).withIdentifier(4).withIcon(MaterialDesignIconic.Icon.gmi_coffee),
new PrimaryDrawerItem().withName(R.string.sample_generic_item).withDescription(R.string.sample_generic_item_descr).withSelectable(false).withIdentifier(7).withIcon(MaterialDesignIconic.Icon.gmi_font),
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 DividerDrawerItem(),
new PrimaryDrawerItem().withName(R.string.open_source).withSelectable(false).withIdentifier(100).withIcon(MaterialDesignIconic.Icon.gmi_github)
)
Expand All @@ -98,6 +101,10 @@ public boolean onItemClick(View view, int position, IDrawerItem drawerItem) {
intent = new Intent(SampleActivity.this, IconGridActivity.class);
} else if (drawerItem.getIdentifier() == 9) {
intent = new Intent(SampleActivity.this, MultiTypeGenericItemActivity.class);
} else if (drawerItem.getIdentifier() == 10) {
intent = new Intent(SampleActivity.this, CheckBoxSampleActivity.class);
} else if (drawerItem.getIdentifier() == 11) {
intent = new Intent(SampleActivity.this, RadioButtonSampleActivity.class);
} else if (drawerItem.getIdentifier() == 100) {
intent = new LibsBuilder()
.withFields(R.string.class.getFields())
Expand Down
Loading

0 comments on commit 1cd871b

Please sign in to comment.