use of com.mikepenz.fastadapter.FastAdapter in project AboutLibraries by mikepenz.
the class LibsBuilder method adapter.
/**
* builder to build an adapter out of the given information ;D
*
* @param context the current context
* @return a LibsRecyclerViewAdapter with the libraries
*/
public AbstractAdapter adapter(Context context) {
Libs libs;
if (fields == null) {
libs = new Libs(context);
} else {
libs = new Libs(context, fields);
}
//apply modifications
libs.modifyLibraries(libraryModification);
//fetch the libraries and sort if a comparator was set
ArrayList<Library> libraries = libs.prepareLibraries(context, internalLibraries, excludeLibraries, autoDetect, sort);
//prepare adapter
ItemAdapter itemAdapter = new ItemAdapter();
List<LibraryItem> libraryItems = new ArrayList<>();
for (Library library : libraries) {
libraryItems.add(new LibraryItem().withLibrary(library).withLibsBuilder(this));
}
//noinspection unchecked
itemAdapter.wrap(new FastAdapter());
itemAdapter.add(libraryItems);
return itemAdapter;
}
use of com.mikepenz.fastadapter.FastAdapter in project AboutLibraries by mikepenz.
the class LibsFragmentCompat method onCreateView.
public View onCreateView(Context context, LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState, Bundle arguments) {
if (arguments != null) {
builder = (LibsBuilder) arguments.getSerializable("data");
} else {
Log.e("AboutLibraries", "The AboutLibraries fragment can't be build without the bundle containing the LibsBuilder");
}
View view = inflater.inflate(R.layout.fragment_opensource, container, false);
//allows to modify the view before creating
if (LibsConfiguration.getInstance().getUiListener() != null) {
view = LibsConfiguration.getInstance().getUiListener().preOnCreateView(view);
}
// init CardView
RecyclerView mRecyclerView;
if (view.getId() == R.id.cardListView) {
mRecyclerView = (RecyclerView) view;
} else {
mRecyclerView = (RecyclerView) view.findViewById(R.id.cardListView);
}
mRecyclerView.setLayoutManager(new LinearLayoutManager(context));
if (LibsConfiguration.getInstance().getItemAnimator() != null) {
mRecyclerView.setItemAnimator(LibsConfiguration.getInstance().getItemAnimator());
} else {
mRecyclerView.setItemAnimator(new DefaultItemAnimator());
}
if (builder != null) {
mAdapter = new FastAdapter();
mItemAdapter = new ItemAdapter();
mRecyclerView.setAdapter(mItemAdapter.wrap(mAdapter));
mItemAdapter.add(new LoaderItem());
}
//allows to modify the view after creating
if (LibsConfiguration.getInstance().getUiListener() != null) {
view = LibsConfiguration.getInstance().getUiListener().postOnCreateView(view);
}
return view;
}
use of com.mikepenz.fastadapter.FastAdapter in project FastAdapter by mikepenz.
the class RadioButtonSampleActivity method onCreate.
@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<>();
fastItemAdapter.withSelectable(true);
//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.withItemEvent(new RadioButtonSampleItem.RadioButtonClickEvent());
//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<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);
}
use of com.mikepenz.fastadapter.FastAdapter in project FastAdapter by mikepenz.
the class SortActivity method onCreate.
@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_sort);
ButterKnife.bind(this);
// Handle Toolbar
setSupportActionBar(toolbar);
//style our ui
new MaterializeBuilder().withActivity(this).build();
//create our FastAdapter which will manage everything
fastItemAdapter = new FastItemAdapter<>();
fastItemAdapter.withSelectable(true);
//configure our fastAdapter
fastItemAdapter.withOnClickListener(new FastAdapter.OnClickListener<SimpleItem>() {
@Override
public boolean onClick(View v, IAdapter<SimpleItem> adapter, SimpleItem item, int position) {
Toast.makeText(v.getContext(), (item).name.getText(v.getContext()), Toast.LENGTH_LONG).show();
return false;
}
});
//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);
if (savedInstanceState != null) {
//Retrieve the previous sorting strategy from the instance state
sortingStrategy = toSortingStrategy(savedInstanceState.getInt("sorting_strategy"));
} else {
//Set the default so
sortingStrategy = SORT_NONE;
}
//we sort the list
fastItemAdapter.getItemAdapter().withComparator(getComparator());
//initial filling of the list
fastItemAdapter.setNewList(generateUnsortedList());
//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);
}
use of com.mikepenz.fastadapter.FastAdapter in project FastAdapter by mikepenz.
the class GenericItemActivity method onCreate.
@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);
getSupportActionBar().setTitle(R.string.sample_generic_item);
//style our ui
new MaterializeBuilder().withActivity(this).build();
//create our FastAdapter which will manage everything
fastAdapter = new FastAdapter();
fastAdapter.withSelectable(true);
//get our recyclerView and do basic setup
RecyclerView rv = (RecyclerView) findViewById(R.id.rv);
//init our gridLayoutManager and configure RV
GridLayoutManager gridLayoutManager = new GridLayoutManager(this, 3);
GenericItemAdapter<IconModel, GenericIconItem> itemAdapter = new GenericItemAdapter<>(GenericIconItem.class, IconModel.class);
final FastScrollIndicatorAdapter<GenericIconItem> fastScrollIndicatorAdapter = new FastScrollIndicatorAdapter<>();
rv.setAdapter(fastScrollIndicatorAdapter.wrap(itemAdapter.wrap(fastAdapter)));
DragScrollBar materialScrollBar = new DragScrollBar(this, rv, true);
materialScrollBar.setHandleColour(ContextCompat.getColor(this, R.color.colorAccent));
materialScrollBar.setHandleOffColour(ContextCompat.getColor(this, R.color.colorAccent));
materialScrollBar.addIndicator(new CustomIndicator(this), true);
rv.setLayoutManager(gridLayoutManager);
rv.setItemAnimator(new SlideDownAlphaAnimator());
//order fonts by their name
List<ITypeface> mFonts = new ArrayList<>(Iconics.getRegisteredFonts(this));
Collections.sort(mFonts, new Comparator<ITypeface>() {
@Override
public int compare(final ITypeface object1, final ITypeface object2) {
return object1.getFontName().compareTo(object2.getFontName());
}
});
//add all icons of all registered Fonts to the list
ArrayList<IconModel> models = new ArrayList<>();
for (ITypeface font : mFonts) {
for (String icon : font.getIcons()) {
models.add(new IconModel(font.getIcon(icon)));
}
}
//fill with some sample data
itemAdapter.addModel(models);
//restore selections (this has to be done after the items were added
fastAdapter.withSavedInstanceState(savedInstanceState);
//set the back arrow in the toolbar
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(false);
}
Aggregations