use of com.mikepenz.fastadapter.adapters.ItemAdapter in project FastAdapter by mikepenz.
the class MultiselectSampleActivity 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_multi_select);
//style our ui
new MaterializeBuilder().withActivity(this).build();
//create our FastAdapter
mFastAdapter = new FastAdapter<>();
//
mUndoHelper = new UndoHelper(mFastAdapter, new UndoHelper.UndoListener<SimpleItem>() {
@Override
public void commitRemove(Set<Integer> positions, ArrayList<FastAdapter.RelativeInfo<SimpleItem>> removed) {
Log.e("UndoHelper", "Positions: " + positions.toString() + " Removed: " + removed.size());
}
});
//we init our ActionModeHelper
mActionModeHelper = new ActionModeHelper(mFastAdapter, R.menu.cab, new ActionBarCallBack());
//create our adapters
ItemAdapter<SimpleItem> itemAdapter = new ItemAdapter<>();
final HeaderAdapter<SimpleItem> headerAdapter = new HeaderAdapter<>();
//configure our mFastAdapter
//as we provide id's for the items we want the hasStableIds enabled to speed up things
mFastAdapter.setHasStableIds(true);
mFastAdapter.withSelectable(true);
mFastAdapter.withMultiSelect(true);
mFastAdapter.withSelectOnLongClick(true);
mFastAdapter.withOnPreClickListener(new FastAdapter.OnClickListener<SimpleItem>() {
@Override
public boolean onClick(View v, IAdapter<SimpleItem> adapter, SimpleItem item, int position) {
//we handle the default onClick behavior for the actionMode. This will return null if it didn't do anything and you can handle a normal onClick
Boolean res = mActionModeHelper.onClick(item);
return res != null ? res : false;
}
});
mFastAdapter.withOnClickListener(new FastAdapter.OnClickListener<SimpleItem>() {
@Override
public boolean onClick(View v, IAdapter<SimpleItem> adapter, SimpleItem item, int position) {
Toast.makeText(v.getContext(), "SelectedCount: " + mFastAdapter.getSelections().size() + " ItemsCount: " + mFastAdapter.getSelectedItems().size(), Toast.LENGTH_SHORT).show();
return false;
}
});
mFastAdapter.withOnPreLongClickListener(new FastAdapter.OnLongClickListener<SimpleItem>() {
@Override
public boolean onLongClick(View v, IAdapter<SimpleItem> adapter, SimpleItem item, int position) {
ActionMode actionMode = mActionModeHelper.onLongClick(MultiselectSampleActivity.this, position);
if (actionMode != null) {
//we want color our CAB
findViewById(R.id.action_mode_bar).setBackgroundColor(UIUtils.getThemeColorFromAttrOrRes(MultiselectSampleActivity.this, R.attr.colorPrimary, R.color.material_drawer_primary));
}
//if we have no actionMode we do not consume the event
return actionMode != null;
}
});
//get our recyclerView and do basic setup
RecyclerView rv = (RecyclerView) findViewById(R.id.rv);
rv.setLayoutManager(new LinearLayoutManager(this));
rv.setItemAnimator(new SlideDownAlphaAnimator());
rv.setAdapter(itemAdapter.wrap(headerAdapter.wrap(mFastAdapter)));
//fill with some sample data
SimpleItem SimpleItem = new SimpleItem();
SimpleItem.withName("Header").withIdentifier(1).withSelectable(false);
headerAdapter.add(SimpleItem);
List<SimpleItem> items = new ArrayList<>();
for (int i = 1; i <= 100; i++) {
SimpleItem item = new SimpleItem();
item.withName("Test " + i).withIdentifier(100 + i);
items.add(item);
}
itemAdapter.add(items);
//restore selections (this has to be done after the items were added
mFastAdapter.withSavedInstanceState(savedInstanceState);
//set the back arrow in the toolbar
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(false);
//inform that longClick is required
Toast.makeText(this, "LongClick to enable Multi-Selection", Toast.LENGTH_LONG).show();
}
use of com.mikepenz.fastadapter.adapters.ItemAdapter in project FastAdapter by mikepenz.
the class StickyHeaderSampleActivity 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_sticky_header);
//style our ui
new MaterializeBuilder().withActivity(this).build();
//create our FastAdapter
fastAdapter = new FastAdapter();
fastAdapter.withSelectable(true);
//create our adapters
final StickyHeaderAdapter stickyHeaderAdapter = new StickyHeaderAdapter();
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);
//get our recyclerView and do basic setup
RecyclerView rv = (RecyclerView) findViewById(R.id.rv);
rv.setLayoutManager(new LinearLayoutManager(this));
rv.setItemAnimator(new DefaultItemAnimator());
rv.setAdapter(stickyHeaderAdapter.wrap(itemAdapter.wrap(headerAdapter.wrap(fastAdapter))));
//this adds the Sticky Headers within our list
final StickyRecyclerHeadersDecoration decoration = new StickyRecyclerHeadersDecoration(stickyHeaderAdapter);
rv.addItemDecoration(decoration);
//fill with some sample data
headerAdapter.add(new SimpleItem().withName("Header").withIdentifier(1));
List<IItem> items = new ArrayList<>();
for (int i = 1; i <= 100; i++) {
items.add(new SimpleItem().withName("Test " + i).withHeader(headers[i / 5]).withIdentifier(100 + i));
}
itemAdapter.add(items);
//so the headers are aware of changes
stickyHeaderAdapter.registerAdapterDataObserver(new RecyclerView.AdapterDataObserver() {
@Override
public void onChanged() {
decoration.invalidateHeaders();
}
});
//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);
}
use of com.mikepenz.fastadapter.adapters.ItemAdapter 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 FastAdapter 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, checkCachedDetection, sort);
// prepare adapter
ItemAdapter itemAdapter = new ItemAdapter();
List<LibraryItem> libraryItems = new ArrayList<>();
for (Library library : libraries) {
libraryItems.add(new LibraryItem().withLibrary(library).withLibsBuilder(this));
}
FastAdapter fastAdapter = FastAdapter.with(itemAdapter);
// noinspection unchecked
itemAdapter.add(libraryItems);
return fastAdapter;
}
use of com.mikepenz.fastadapter.adapters.ItemAdapter 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) {
mItemAdapter = new ItemAdapter();
mAdapter = FastAdapter.with(mItemAdapter);
mRecyclerView.setAdapter(mAdapter);
if (builder.showLoadingProgress) {
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.adapters.ItemAdapter in project FastAdapter by mikepenz.
the class FastAdapterTest method testAddPreviouslyFilledAdapterPropagatesPossibleTypesToParentFastAdapter.
@Test
public void testAddPreviouslyFilledAdapterPropagatesPossibleTypesToParentFastAdapter() {
final TestItem testItem = new TestItem("example name");
ItemAdapter<TestItem> itemAdapter = new ItemAdapter<>();
itemAdapter.add(testItem);
FastAdapter<TestItem> adapter = new FastAdapter<>();
adapter.addAdapter(0, itemAdapter);
// registering the factory happens only during usage of the adapter now
adapter.registerItemFactory(testItem.getType(), testItem);
final ViewGroup dummyParent = new FrameLayout(RuntimeEnvironment.application);
adapter.onCreateViewHolder(dummyParent, testItem.getType());
}
Aggregations