Support
Quality
Security
License
Reuse
kandi has reviewed FlexibleAdapter and discovered the below as its top functions. This is intended to give you an instant insight into FlexibleAdapter implemented functionality, and help decide if they suit your requirements.
Simple, Single & Multi selection mode.
Mapping multi-view types with Item interfaces.
Predefined ViewHolders with (child) click listeners and others callbacks.
Async Updates with optional DiffUtil for small lists.
Async Filter with spannable text (:eyeglasses:); Result list is animated; With optional original list; Works with sub items; Multi filter.
High performance filter and updates for medium and big lists.
Headers and Sections with sticky behaviour fully clickable and collapsible, elevation, transparency and automatic linkage on item move!
Scrollable Headers and Footers items that lay respectively at the top and at the bottom of the main items.
Expandable items with Selection Coherence and multi-level expansion.
Drag&Drop and Swipe-To-Dismiss with Leave-Behind pattern and with Selection Coherence.
Innovative bottom and top EndlessScroll (No OnScrollListener).
Customizable FastScroller with several features.
Customizable Scrolling Animations based on adapter position and beyond.
Customizable Animations when adding and removing items.
LayoutUtils for orientation, span count and visible items calculation.
Support for any thirds LayoutManagers.
Easy runtime position calculation for adding/moving items in sections.
Custom Tags for multiple adapter instances that ease our debug.
Comprehensive Wiki pages and JavaDoc documentation.
Setup
repositories {
jcenter()
}
License
Copyright 2015-2018 Davide Steduto, Davidea Solutions Sprl
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Recyclerview with sticky header and subheader
val newList = mutableListOf<SomeKindOfInterface>()
fun setData(list: List<YourJsonObject>) {
newList.clear()
var previousMonth = 0
var previousDay = 0
for (yourJsonObject in list) {
if (yourJsonObject.month != previousMonth) {
previousMonth = yourJsonObject.month
newList.add(MonthObject(yourJsonObject.month))
}
if (yourJsonObject.day != previousDay) {
previousDay = yourJsonObject.day
newList.add(DayObject(yourJsonObject.day))
}
newList.add(yourJsonObject)
}
}
class YourJsonObject(
val month: Int,
val day: Int
) : SomeKindOfInterface
class MonthObject(val month: Int) : SomeKindOfInterface
class DayObject(val day: Int) : SomeKindOfInterface
interface SomeKindOfInterface
override fun getItemViewType(position: Int): Int {
return when (newList.get(position)) {
is YourJsonObject -> 0
is MonthObject -> 1
is DayObject -> 2
}
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
return when (viewType) {
0 -> createYourJsonObjectViewHolder
1 -> createMonthObjectViewHolder
2 -> createDayObjectViewHolder
}
}
-----------------------
val newList = mutableListOf<SomeKindOfInterface>()
fun setData(list: List<YourJsonObject>) {
newList.clear()
var previousMonth = 0
var previousDay = 0
for (yourJsonObject in list) {
if (yourJsonObject.month != previousMonth) {
previousMonth = yourJsonObject.month
newList.add(MonthObject(yourJsonObject.month))
}
if (yourJsonObject.day != previousDay) {
previousDay = yourJsonObject.day
newList.add(DayObject(yourJsonObject.day))
}
newList.add(yourJsonObject)
}
}
class YourJsonObject(
val month: Int,
val day: Int
) : SomeKindOfInterface
class MonthObject(val month: Int) : SomeKindOfInterface
class DayObject(val day: Int) : SomeKindOfInterface
interface SomeKindOfInterface
override fun getItemViewType(position: Int): Int {
return when (newList.get(position)) {
is YourJsonObject -> 0
is MonthObject -> 1
is DayObject -> 2
}
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
return when (viewType) {
0 -> createYourJsonObjectViewHolder
1 -> createMonthObjectViewHolder
2 -> createDayObjectViewHolder
}
}
Trying to use FlexibleAdapter for Android
// Initialize the RecyclerView and attach the Adapter to it as usual
RecyclerView recyclerView = findViewById(R.id.recyclerView1);
recyclerView.setLayoutManager(new LinearLayoutManager(getApplicationContext()));
recyclerView.setAdapter(adapter);
QUESTION
Explanation required: Type mismatch Required: Nothing Found: MyItem
Asked 2019-Aug-22 at 05:57Currently I converting my android app to Kotlin. The app currently use a third party library called "FlexibleAdapter". I converted my adapter extension to Kotlin without any errors. But when I try to use this adapter I get an type mismatch error when calling the method addItem() which is not overriden by my adapter extension.
Due to the lack of Kotlin experience I don't understand whats going wrong here and how to fix it. Could someone explain what I need to change?
I strip down the code to the very basics to see whats going on! myfragment contains the code where the error appears
Kotlin implementation of the fragment
class myfragment : Fragment() {
private lateinit var myLayoutAdapter: MultiPurposeListAdapter<*>
private var myItems = mutableListOf<AbstractFlexibleItem<*>>()
override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)
myLayoutAdapter = MultiPurposeListAdapter(myItems, this, true)
// Prepare the RecyclerView and attach the Adapter to it
fragment_recycler_view.apply {
layoutManager = createNewLinearLayoutManager()
adapter = mIngredientsLayoutAdapter
setHasFixedSize(false) //Size of RecyclerView will change
}
}
/******
* A function to add items
******
fun addNewItem(itemToAdd: MyItem) {
//Note: itemToAdd is from MyItem that extends AbstractFlexibleItem
// If I try to invoke the addOtem method from the FlexibleAdapter
// I get a Type mismatch error
// addItem is not overriden by MultiplePurposeListAdapter!
myLayoutAdapter.addItem(itemToAdd) // <- Here I get a Type mismatch error
// Required: Nothing
// Found: MyItem
}
}
Kotlin implementation of my Flexible Adapter extension
open class MultiPurposeListAdapter<T: AbstractFlexibleItem<*>>
@JvmOverloads constructor(items: List<T>?, listeners: Any? = null, stableIds: Boolean = true)
: FlexibleAdapter<T>(items, listeners, stableIds) {
// Here we extend the FlexibleAdapter with custom filters
}
Java implementation of the adapter that comes from a third part library called FlexibleAdapter Note: I strip out only the things that seems necessarry to understand!
public class FlexibleAdapter<T extends IFlexible> extends AnimatorAdapter {
private List<T> mItems // The main container for ALL items
/**
* Simply append the provided item to the end of the list.
* <p>Convenience method of {@link #addItem(int, IFlexible)} with
* {@code position = getMainItemCount()}.</p>
*
* @param item the item to add
* @return true if the internal list was successfully modified, false otherwise
*/
public boolean addItem(@NonNull T item) {
return addItem(getItemCount(), item);
}
/**
* Returns the total number of items in the data set held by the adapter.
*
* @return the total number of items (headers and footers INCLUDED) held by the adapter
*/
@Override
public int getItemCount() {
return mItems.size();
}
/**
* Inserts the given item at the specified position or Adds the item to the end of the list
* (no matters if the new position is out of bounds!).
*
* @param position position inside the list, if negative, items will be added to the end
* @param item the item to add
* @return true if the internal list was successfully modified, false otherwise
*/
public boolean addItem(@IntRange(from = 0) int position, @NonNull T item) {
if (item == null) {
log.e("addItem No item to add!");
return false;
}
log.v("addItem delegates addition to addItems!");
return addItems(position, Collections.singletonList(item));
}
/**
* Inserts a set of items at specified position or Adds the items to the end of the list
* (no matters if the new position is out of bounds!).
*
* @param position position inside the list, if negative, items will be added to the end
* @param items the set of items to add
* @return true if the internal list was successfully modified, false otherwise
*/
public boolean addItems(@IntRange(from = 0) int position, @NonNull List<T> items) {
if (items == null || items.isEmpty()) {
log.e("addItems No items to add!");
return false;
}
int initialCount = getMainItemCount(); // Count only main items!
if (position < 0) {
log.w("addItems Position is negative! adding items to the end");
position = initialCount + mScrollableHeaders.size();
}
// Insert the items properly
performInsert(position, items, true);
// Show the headers of new items
showOrUpdateHeaders(items);
// Call listener to update EmptyView
if (!recursive && mUpdateListener != null && !multiRange && initialCount == 0 && getItemCount() > 0) {
mUpdateListener.onUpdateEmptyView(getMainItemCount());
}
return true;
}
}
The error message inside the Android Studio is: Type mismatch. Required: Nothing Found: MyItem
I expect that AbstractFlexibleItem is required. This happens only in the Kotlin converted code. Other fragment implementations (in java) doesn't show that error.
ANSWER
Answered 2019-Aug-22 at 05:57In this line: private lateinit var myLayoutAdapter: MultiPurposeListAdapter<*>
you just have to specify an Item type (java doesn´t require it) for example: MultiPurposeListAdapter<MyItem>
or MultiPurposeListAdapter<AbstractFlexibleItem<*>>
. For more information, see generic types overview
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
No vulnerabilities reported
Save this library and start creating your kit
Save this library and start creating your kit