diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 000000000..13fadd222 --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1,3 @@ +# These are supported funding model platforms + +github: [mikepenz] diff --git a/.travis.yml b/.travis.yml index 8f6b451dc..fdfb61dd6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,12 +3,12 @@ android: components: - tools - platform-tools - - build-tools-29.0.0 + - build-tools-29.0.2 - android-29 - sys-img-armeabi-v7a-android-18 before_install: - yes | sdkmanager "platforms;android-29" - - yes | sdkmanager "build-tools;29.0.0" + - yes | sdkmanager "build-tools;29.0.2" jdk: - oraclejdk8 script: diff --git a/README.md b/README.md index d9927339b..2ac01ec8f 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,7 @@ You can try it out here [Google Play](https://play.google.com/store/apps/details # Include in your project ## Latest releases -- Kotlin | [v4.1.0](https://github.com/mikepenz/FastAdapter/tree/v4.1.0) +- Kotlin | [v4.1.1](https://github.com/mikepenz/FastAdapter/tree/v4.1.1) - Java && AndroidX | [v3.3.1](https://github.com/mikepenz/FastAdapter/tree/v3.3.1) - Java && AppCompat | [v3.2.9](https://github.com/mikepenz/FastAdapter/tree/v3.2.9) diff --git a/app/build.gradle b/app/build.gradle index 175b21ca0..b99df8071 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -177,6 +177,6 @@ buildscript { jcenter() } dependencies { - classpath "io.realm:realm-gradle-plugin:5.11.0" + classpath "io.realm:realm-gradle-plugin:6.0.0" } } \ No newline at end of file diff --git a/app/src/main/java/com/mikepenz/fastadapter/app/AdvancedSampleActivity.kt b/app/src/main/java/com/mikepenz/fastadapter/app/AdvancedSampleActivity.kt index 5d9dd60dc..ba0162e41 100644 --- a/app/src/main/java/com/mikepenz/fastadapter/app/AdvancedSampleActivity.kt +++ b/app/src/main/java/com/mikepenz/fastadapter/app/AdvancedSampleActivity.kt @@ -6,7 +6,6 @@ import android.view.MenuItem import android.view.View import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.view.ActionMode -import androidx.core.view.LayoutInflaterCompat import androidx.recyclerview.widget.DefaultItemAnimator import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView @@ -21,7 +20,6 @@ import com.mikepenz.fastadapter.app.items.expandable.SimpleSubItem import com.mikepenz.fastadapter.expandable.getExpandableExtension import com.mikepenz.fastadapter.helpers.ActionModeHelper import com.mikepenz.fastadapter.select.getSelectExtension -import com.mikepenz.iconics.context.IconicsLayoutInflater2 import com.mikepenz.materialize.MaterializeBuilder import com.mikepenz.materialize.util.UIUtils import com.timehop.stickyheadersrecyclerview.StickyRecyclerHeadersDecoration @@ -44,9 +42,6 @@ class AdvancedSampleActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { findViewById(android.R.id.content).systemUiVisibility = findViewById(android.R.id.content).systemUiVisibility or View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR - //as we use an icon from Android-Iconics via xml we add the IconicsLayoutInflater - //https://github.com/mikepenz/Android-Iconics - LayoutInflaterCompat.setFactory2(layoutInflater, IconicsLayoutInflater2(delegate)) super.onCreate(savedInstanceState) setContentView(R.layout.activity_sample) @@ -65,7 +60,7 @@ class AdvancedSampleActivity : AppCompatActivity() { //we also want the expandable feature //create our FastAdapter - val adapters: Collection> = Arrays.asList(mHeaderAdapter, mItemAdapter) + val adapters: Collection> = listOf(mHeaderAdapter, mItemAdapter) mFastAdapter = FastAdapter.with(adapters) mFastAdapter.getExpandableExtension() @@ -85,7 +80,7 @@ class AdvancedSampleActivity : AppCompatActivity() { mFastAdapter.onPreLongClickListener = { _: View, _: GenericAdapter, item: GenericItem, position: Int -> //we do not want expandable items to be selected - if (item is IExpandable<*> && item.subItems != null) { + if (item is IExpandable<*> && item.subItems.isNotEmpty()) { true } else { //handle the longclick actions diff --git a/app/src/main/java/com/mikepenz/fastadapter/app/EndlessScrollListActivity.kt b/app/src/main/java/com/mikepenz/fastadapter/app/EndlessScrollListActivity.kt index b2feb30e9..f4b559296 100644 --- a/app/src/main/java/com/mikepenz/fastadapter/app/EndlessScrollListActivity.kt +++ b/app/src/main/java/com/mikepenz/fastadapter/app/EndlessScrollListActivity.kt @@ -78,7 +78,7 @@ class EndlessScrollListActivity : AppCompatActivity(), ItemTouchCallback, ItemFi fastItemAdapter.itemFilter.filterPredicate = { item: GenericItem, constraint: CharSequence? -> if (item is SimpleItem) { //return true if we should filter it out - item.name?.text.toString().toLowerCase().contains(constraint.toString().toLowerCase()) + item.name?.text.toString().contains(constraint.toString(), ignoreCase = true) } else { //return false to keep it false diff --git a/app/src/main/java/com/mikepenz/fastadapter/app/ExpandableMultiselectDeleteSampleActivity.kt b/app/src/main/java/com/mikepenz/fastadapter/app/ExpandableMultiselectDeleteSampleActivity.kt index 4c7db3323..7aa698e05 100644 --- a/app/src/main/java/com/mikepenz/fastadapter/app/ExpandableMultiselectDeleteSampleActivity.kt +++ b/app/src/main/java/com/mikepenz/fastadapter/app/ExpandableMultiselectDeleteSampleActivity.kt @@ -7,7 +7,6 @@ import android.view.View import android.widget.Toast import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.view.ActionMode -import androidx.core.view.LayoutInflaterCompat import androidx.recyclerview.widget.LinearLayoutManager import com.michaelflisar.dragselectrecyclerview.DragSelectTouchListener import com.mikepenz.fastadapter.* @@ -22,7 +21,6 @@ import com.mikepenz.fastadapter.helpers.RangeSelectorHelper import com.mikepenz.fastadapter.select.SelectExtension import com.mikepenz.fastadapter.select.getSelectExtension import com.mikepenz.fastadapter.utils.SubItemUtil -import com.mikepenz.iconics.context.IconicsLayoutInflater import com.mikepenz.itemanimators.SlideDownAlphaAnimator import com.mikepenz.materialize.MaterializeBuilder import com.mikepenz.materialize.util.UIUtils @@ -40,9 +38,6 @@ class ExpandableMultiselectDeleteSampleActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { findViewById(android.R.id.content).systemUiVisibility = findViewById(android.R.id.content).systemUiVisibility or View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR - //as we use an icon from Android-Iconics via xml we add the IconicsLayoutInflater - //https://github.com/mikepenz/Android-Iconics - LayoutInflaterCompat.setFactory(layoutInflater, IconicsLayoutInflater(delegate)) super.onCreate(savedInstanceState) setContentView(R.layout.activity_sample) @@ -159,7 +154,7 @@ class ExpandableMultiselectDeleteSampleActivity : AppCompatActivity() { mExpandableExtension.expand() mSelectExtension.selectionListener = object : ISelectionListener> { - override fun onSelectionChanged(item: IItem<*>?, selected: Boolean) { + override fun onSelectionChanged(item: IItem<*>, selected: Boolean) { if (item is SimpleSubItem) { val headerItem = item.parent if (headerItem != null) { @@ -213,7 +208,7 @@ class ExpandableMultiselectDeleteSampleActivity : AppCompatActivity() { // delete the selected items with the SubItemUtil to correctly handle sub items // this will even delete empty headers if you want to - SubItemUtil.deleteSelected(fastItemAdapter, mSelectExtension, mExpandableExtension, true, true) + SubItemUtil.deleteSelected(fastItemAdapter, mSelectExtension, mExpandableExtension, notifyParent = true, deleteEmptyHeaders = true) //as we no longer have a selection so the actionMode can be finished mode.finish() //we consume the event diff --git a/app/src/main/java/com/mikepenz/fastadapter/app/ExpandableSampleActivity.kt b/app/src/main/java/com/mikepenz/fastadapter/app/ExpandableSampleActivity.kt index dab8d6ac9..579f6614d 100755 --- a/app/src/main/java/com/mikepenz/fastadapter/app/ExpandableSampleActivity.kt +++ b/app/src/main/java/com/mikepenz/fastadapter/app/ExpandableSampleActivity.kt @@ -4,7 +4,6 @@ import android.os.Bundle import android.view.MenuItem import android.view.View import androidx.appcompat.app.AppCompatActivity -import androidx.core.view.LayoutInflaterCompat import androidx.recyclerview.widget.LinearLayoutManager import com.mikepenz.fastadapter.GenericItem import com.mikepenz.fastadapter.adapters.FastItemAdapter @@ -13,7 +12,6 @@ import com.mikepenz.fastadapter.app.items.expandable.SimpleSubExpandableItem import com.mikepenz.fastadapter.app.items.expandable.SimpleSubItem import com.mikepenz.fastadapter.expandable.getExpandableExtension import com.mikepenz.fastadapter.select.getSelectExtension -import com.mikepenz.iconics.context.IconicsLayoutInflater2 import com.mikepenz.itemanimators.SlideDownAlphaAnimator import com.mikepenz.materialize.MaterializeBuilder import kotlinx.android.synthetic.main.activity_sample.* @@ -26,9 +24,6 @@ class ExpandableSampleActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { findViewById(android.R.id.content).systemUiVisibility = findViewById(android.R.id.content).systemUiVisibility or View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR - //as we use an icon from Android-Iconics via xml we add the IconicsLayoutInflater - //https://github.com/mikepenz/Android-Iconics - LayoutInflaterCompat.setFactory2(layoutInflater, IconicsLayoutInflater2(delegate)) super.onCreate(savedInstanceState) setContentView(R.layout.activity_sample) diff --git a/app/src/main/java/com/mikepenz/fastadapter/app/IconGridActivity.kt b/app/src/main/java/com/mikepenz/fastadapter/app/IconGridActivity.kt index c2eedc90c..2cc874c39 100644 --- a/app/src/main/java/com/mikepenz/fastadapter/app/IconGridActivity.kt +++ b/app/src/main/java/com/mikepenz/fastadapter/app/IconGridActivity.kt @@ -4,7 +4,6 @@ import android.os.Bundle import android.view.MenuItem import android.view.View import androidx.appcompat.app.AppCompatActivity -import androidx.core.view.LayoutInflaterCompat import androidx.recyclerview.widget.GridLayoutManager import com.mikepenz.fastadapter.adapters.FastItemAdapter import com.mikepenz.fastadapter.adapters.GenericFastItemAdapter @@ -12,7 +11,6 @@ import com.mikepenz.fastadapter.app.items.IconItem import com.mikepenz.fastadapter.app.items.expandable.SimpleSubExpandableItem import com.mikepenz.fastadapter.expandable.getExpandableExtension import com.mikepenz.iconics.Iconics -import com.mikepenz.iconics.context.IconicsLayoutInflater2 import com.mikepenz.itemanimators.SlideDownAlphaAnimator import com.mikepenz.materialize.MaterializeBuilder import kotlinx.android.synthetic.main.activity_sample.* @@ -25,9 +23,6 @@ class IconGridActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { findViewById(android.R.id.content).systemUiVisibility = findViewById(android.R.id.content).systemUiVisibility or View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR - //as we use an icon from Android-Iconics via xml we add the IconicsLayoutInflater - //https://github.com/mikepenz/Android-Iconics - LayoutInflaterCompat.setFactory2(layoutInflater, IconicsLayoutInflater2(delegate)) super.onCreate(savedInstanceState) setContentView(R.layout.activity_sample) diff --git a/app/src/main/java/com/mikepenz/fastadapter/app/ModelItemActivity.kt b/app/src/main/java/com/mikepenz/fastadapter/app/ModelItemActivity.kt index 38dc8452d..08db80329 100644 --- a/app/src/main/java/com/mikepenz/fastadapter/app/ModelItemActivity.kt +++ b/app/src/main/java/com/mikepenz/fastadapter/app/ModelItemActivity.kt @@ -17,9 +17,9 @@ import com.mikepenz.itemanimators.SlideDownAlphaAnimator import com.mikepenz.materialize.MaterializeBuilder import com.turingtechnologies.materialscrollbar.CustomIndicator import com.turingtechnologies.materialscrollbar.DragScrollBar -import kotlinx.android.synthetic.main.activity_sample.* +import kotlinx.android.synthetic.main.activity_sample.rv +import kotlinx.android.synthetic.main.activity_sample.toolbar import java.util.ArrayList -import java.util.Arrays import kotlin.Comparator class ModelItemActivity : AppCompatActivity() { @@ -45,7 +45,7 @@ class ModelItemActivity : AppCompatActivity() { } //create our FastAdapter which will manage everything - fastAdapter = FastAdapter.with(Arrays.asList(itemAdapter)) + fastAdapter = FastAdapter.with(listOf(itemAdapter)) val selectExtension = fastAdapter.getSelectExtension() selectExtension.isSelectable = true diff --git a/app/src/main/java/com/mikepenz/fastadapter/app/MultiTypeModelItemActivity.kt b/app/src/main/java/com/mikepenz/fastadapter/app/MultiTypeModelItemActivity.kt index 679f22175..5fae6bf86 100644 --- a/app/src/main/java/com/mikepenz/fastadapter/app/MultiTypeModelItemActivity.kt +++ b/app/src/main/java/com/mikepenz/fastadapter/app/MultiTypeModelItemActivity.kt @@ -45,7 +45,7 @@ class MultiTypeModelItemActivity : AppCompatActivity() { } //create our FastAdapter which will manage everything - fastAdapter = FastAdapter.with(Arrays.asList(itemAdapter)) + fastAdapter = FastAdapter.with(listOf(itemAdapter)) val selectExtension = fastAdapter.getSelectExtension() selectExtension.isSelectable = true diff --git a/app/src/main/java/com/mikepenz/fastadapter/app/MultiselectSampleActivity.kt b/app/src/main/java/com/mikepenz/fastadapter/app/MultiselectSampleActivity.kt index 0e0c61f35..89b72644b 100755 --- a/app/src/main/java/com/mikepenz/fastadapter/app/MultiselectSampleActivity.kt +++ b/app/src/main/java/com/mikepenz/fastadapter/app/MultiselectSampleActivity.kt @@ -62,7 +62,7 @@ class MultiselectSampleActivity : AppCompatActivity() { multiSelect = true selectOnLongClick = true selectionListener = object : ISelectionListener { - override fun onSelectionChanged(item: SimpleItem?, selected: Boolean) { + override fun onSelectionChanged(item: SimpleItem, selected: Boolean) { Log.i("FastAdapter", "SelectedCount: " + selectExtension.selections.size + " ItemsCount: " + selectExtension.selectedItems.size) } } diff --git a/app/src/main/java/com/mikepenz/fastadapter/app/RealmActivity.kt b/app/src/main/java/com/mikepenz/fastadapter/app/RealmActivity.kt index c259c69ab..a8a70d0d5 100755 --- a/app/src/main/java/com/mikepenz/fastadapter/app/RealmActivity.kt +++ b/app/src/main/java/com/mikepenz/fastadapter/app/RealmActivity.kt @@ -45,9 +45,7 @@ class RealmActivity : AppCompatActivity() { //configure our fastAdapter mFastItemAdapter.onClickListener = { v: View?, _: IAdapter, item: RealmSampleUserItem, _: Int -> - v?.let { v -> - Toast.makeText(v.context, item.name, Toast.LENGTH_SHORT).show() - } + v?.let { Toast.makeText(it.context, item.name, Toast.LENGTH_SHORT).show() } false } diff --git a/app/src/main/java/com/mikepenz/fastadapter/app/SortActivity.kt b/app/src/main/java/com/mikepenz/fastadapter/app/SortActivity.kt index 21cc0edc5..169470b56 100644 --- a/app/src/main/java/com/mikepenz/fastadapter/app/SortActivity.kt +++ b/app/src/main/java/com/mikepenz/fastadapter/app/SortActivity.kt @@ -24,10 +24,8 @@ import com.mikepenz.iconics.IconicsColor import com.mikepenz.iconics.IconicsDrawable import com.mikepenz.iconics.typeface.library.materialdesigniconic.MaterialDesignIconic import com.mikepenz.materialize.MaterializeBuilder -import kotlinx.android.synthetic.main.activity_sort.* +import kotlinx.android.synthetic.main.activity_sort.toolbar import java.io.Serializable -import java.lang.annotation.Retention -import java.lang.annotation.RetentionPolicy import java.util.* /** @@ -128,7 +126,6 @@ class SortActivity : AppCompatActivity() { super.onSaveInstanceState(outState) } - override fun onCreateOptionsMenu(menu: Menu): Boolean { val inflater = menuInflater inflater.inflate(R.menu.sort, menu) @@ -216,7 +213,7 @@ class SortActivity : AppCompatActivity() { return result.withDescription("$description letter in the alphabet") } - @Retention(RetentionPolicy.SOURCE) + @Retention(AnnotationRetention.SOURCE) @IntDef(SORT_NONE, SORT_ASCENDING, SORT_DESCENDING) annotation class SortingStrategy diff --git a/app/src/main/java/com/mikepenz/fastadapter/app/SwipeListActivity.kt b/app/src/main/java/com/mikepenz/fastadapter/app/SwipeListActivity.kt index 9d29408f9..08da31e11 100644 --- a/app/src/main/java/com/mikepenz/fastadapter/app/SwipeListActivity.kt +++ b/app/src/main/java/com/mikepenz/fastadapter/app/SwipeListActivity.kt @@ -76,7 +76,7 @@ class SwipeListActivity : AppCompatActivity(), ItemTouchCallback, SimpleSwipeCal //configure the itemAdapter fastItemAdapter.itemFilter.filterPredicate = { item: SwipeableItem, constraint: CharSequence? -> - item.name?.text.toString().toLowerCase().contains(constraint.toString().toLowerCase()) + item.name?.text.toString().contains(constraint.toString(), ignoreCase = true) } //get our recyclerView and do basic setup diff --git a/app/src/main/java/com/mikepenz/fastadapter/app/adapters/FastScrollIndicatorAdapter.kt b/app/src/main/java/com/mikepenz/fastadapter/app/adapters/FastScrollIndicatorAdapter.kt index 8a4dcabe3..20894411f 100644 --- a/app/src/main/java/com/mikepenz/fastadapter/app/adapters/FastScrollIndicatorAdapter.kt +++ b/app/src/main/java/com/mikepenz/fastadapter/app/adapters/FastScrollIndicatorAdapter.kt @@ -35,7 +35,7 @@ class FastScrollIndicatorAdapter : RecyclerView.Adapter { - return listOf(*imageItems) + return imageItems.toList() } private fun toList(vararg imageItems: SimpleImageItem): List { - return listOf(*imageItems) + return imageItems.toList() } } diff --git a/app/src/main/java/com/mikepenz/fastadapter/app/items/HeaderSelectionItem.kt b/app/src/main/java/com/mikepenz/fastadapter/app/items/HeaderSelectionItem.kt index 909c6681a..7ae5aae25 100644 --- a/app/src/main/java/com/mikepenz/fastadapter/app/items/HeaderSelectionItem.kt +++ b/app/src/main/java/com/mikepenz/fastadapter/app/items/HeaderSelectionItem.kt @@ -18,17 +18,17 @@ open class HeaderSelectionItem : SimpleSubExpandableItem() { this.mSubSelectionProvider = subSelectionProvider } - override fun bindView(viewHolder: ViewHolder, payloads: MutableList) { - super.bindView(viewHolder, payloads) + override fun bindView(holder: ViewHolder, payloads: MutableList) { + super.bindView(holder, payloads) //get the context - val ctx = viewHolder.itemView.context + val ctx = holder.itemView.context //set the background for the item - viewHolder.view.clearAnimation() - ViewCompat.setBackground(viewHolder.view, FastAdapterUIUtils.getSelectableBackground(ctx, Color.RED, true)) + holder.view.clearAnimation() + ViewCompat.setBackground(holder.view, FastAdapterUIUtils.getSelectableBackground(ctx, Color.RED, true)) //set the text for the name - StringHolder.applyTo(name, viewHolder.name) + StringHolder.applyTo(name, holder.name) //set the text for the description or hide var selectedSubItems = 0 @@ -37,8 +37,8 @@ open class HeaderSelectionItem : SimpleSubExpandableItem() { val descr = StringHolder(description?.text) if (selectedSubItems > 0) descr.setText("Selected children: " + selectedSubItems + "/" + subItems.size) - StringHolder.applyToOrHide(descr, viewHolder.description) + StringHolder.applyToOrHide(descr, holder.description) - viewHolder.description.setTextColor(if (selectedSubItems == 0) Color.BLACK else Color.RED) + holder.description.setTextColor(if (selectedSubItems == 0) Color.BLACK else Color.RED) } } diff --git a/app/src/main/java/com/mikepenz/fastadapter/app/items/IconItem.kt b/app/src/main/java/com/mikepenz/fastadapter/app/items/IconItem.kt index 36f8288bf..b81794503 100644 --- a/app/src/main/java/com/mikepenz/fastadapter/app/items/IconItem.kt +++ b/app/src/main/java/com/mikepenz/fastadapter/app/items/IconItem.kt @@ -23,7 +23,7 @@ class IconItem : AbstractItem(), IExpandable> get() = mutableListOf() - set(list) { + set(_) { } override val isAutoExpanding: Boolean @@ -83,7 +83,7 @@ class IconItem : AbstractItem(), IExpandable() { /** * binds the data of this item onto the viewHolder * - * @param viewHolder the viewHolder of this item + * @param holder the viewHolder of this item */ - override fun bindView(viewHolder: ViewHolder, payloads: MutableList) { - super.bindView(viewHolder, payloads) + override fun bindView(holder: ViewHolder, payloads: MutableList) { + super.bindView(holder, payloads) //get the context - val ctx = viewHolder.itemView.context + val ctx = holder.itemView.context //define our data for the view - viewHolder.imageName.text = mName - viewHolder.imageDescription.text = mDescription - viewHolder.imageView.setImageBitmap(null) + holder.imageName.text = mName + holder.imageDescription.text = mDescription + holder.imageView.setImageBitmap(null) //we pre-style our heart :D - style(viewHolder.imageLovedOn, if (mStarred) 1 else 0) - style(viewHolder.imageLovedOff, if (mStarred) 0 else 1) + style(holder.imageLovedOn, if (mStarred) 1 else 0) + style(holder.imageLovedOff, if (mStarred) 0 else 1) //load glide - Glide.with(ctx).load(mImageUrl).animate(R.anim.alpha_on).into(viewHolder.imageView) + Glide.with(ctx).load(mImageUrl).animate(R.anim.alpha_on).into(holder.imageView) } override fun unbindView(holder: ViewHolder) { @@ -129,7 +128,7 @@ class ImageItem : AbstractItem() { /** * our ViewHolder */ - class ViewHolder(protected var view: View) : RecyclerView.ViewHolder(view) { + class ViewHolder(var view: View) : RecyclerView.ViewHolder(view) { var imageView: ImageView = view.findViewById(R.id.item_image_img) var imageName: TextView = view.findViewById(R.id.item_image_name) var imageDescription: TextView = view.findViewById(R.id.item_image_description) diff --git a/app/src/main/java/com/mikepenz/fastadapter/app/items/RadioButtonSampleItem.kt b/app/src/main/java/com/mikepenz/fastadapter/app/items/RadioButtonSampleItem.kt index a529fdfd6..e9726ab75 100644 --- a/app/src/main/java/com/mikepenz/fastadapter/app/items/RadioButtonSampleItem.kt +++ b/app/src/main/java/com/mikepenz/fastadapter/app/items/RadioButtonSampleItem.kt @@ -91,7 +91,7 @@ class RadioButtonSampleItem : AbstractItem() { /** * our ViewHolder */ - class ViewHolder(protected var view: View) : RecyclerView.ViewHolder(view) { + class ViewHolder(var view: View) : RecyclerView.ViewHolder(view) { var radioButton: RadioButton = view.findViewById(R.id.radiobutton) internal var name: TextView = view.findViewById(R.id.material_drawer_name) internal var description: TextView = view.findViewById(R.id.material_drawer_description) diff --git a/app/src/main/java/com/mikepenz/fastadapter/app/items/RealmSampleUserItem.kt b/app/src/main/java/com/mikepenz/fastadapter/app/items/RealmSampleUserItem.kt index 4cbb3cc90..38842a7dd 100644 --- a/app/src/main/java/com/mikepenz/fastadapter/app/items/RealmSampleUserItem.kt +++ b/app/src/main/java/com/mikepenz/fastadapter/app/items/RealmSampleUserItem.kt @@ -223,9 +223,7 @@ open class RealmSampleUserItem : RealmObject(), IItem(R.id.text) as TextView diff --git a/app/src/main/java/com/mikepenz/fastadapter/app/items/expandable/SimpleSubExpandableItem.kt b/app/src/main/java/com/mikepenz/fastadapter/app/items/expandable/SimpleSubExpandableItem.kt index 8f6cefe28..6618a2bae 100644 --- a/app/src/main/java/com/mikepenz/fastadapter/app/items/expandable/SimpleSubExpandableItem.kt +++ b/app/src/main/java/com/mikepenz/fastadapter/app/items/expandable/SimpleSubExpandableItem.kt @@ -7,6 +7,7 @@ import android.widget.TextView import androidx.annotation.StringRes import androidx.core.view.ViewCompat import androidx.recyclerview.widget.RecyclerView +import com.mikepenz.fastadapter.ClickListener import com.mikepenz.fastadapter.IAdapter import com.mikepenz.fastadapter.IClickable import com.mikepenz.fastadapter.ISubItem @@ -24,7 +25,7 @@ open class SimpleSubExpandableItem : AbstractExpandableItem, item: SimpleSubExpandableItem, position: Int) -> Boolean)? = null + private var mOnClickListener: ClickListener? = null //we define a clickListener in here so we can directly animate /** @@ -33,8 +34,8 @@ open class SimpleSubExpandableItem : AbstractExpandableItem, item: SimpleSubExpandableItem, position: Int) -> Boolean)? = { v: View?, adapter: IAdapter, item: SimpleSubExpandableItem, position: Int -> - if (item.subItems != null) { + override var onItemClickListener: ClickListener? = { v: View?, adapter: IAdapter, item: SimpleSubExpandableItem, position: Int -> + if (item.subItems.isNotEmpty()) { v?.findViewById(R.id.material_drawer_icon)?.let { if (!item.isExpanded) { ViewCompat.animate(it).rotation(180f).start() @@ -49,14 +50,13 @@ open class SimpleSubExpandableItem : AbstractExpandableItem, item: SimpleSubExpandableItem, position: Int) -> Boolean)? + override var onPreItemClickListener: ClickListener? get() = null - set(onClickListener) { - } + set(_) {} - override//this might not be true for your application - var isSelectable: Boolean - get() = subItems == null + //this might not be true for your application + override var isSelectable: Boolean + get() = subItems.isEmpty() set(value) { super.isSelectable = value } @@ -121,7 +121,7 @@ open class SimpleSubExpandableItem : AbstractExpandableItem( private val demoEntityDAO: DemoEntityLocalDAO = LocalRepository.getDemoEntityDB(ctx).demoEntityDAO() //is called too load initial data - override fun loadInitial(params: PageKeyedDataSource.LoadInitialParams, - callback: PageKeyedDataSource.LoadInitialCallback) { + override fun loadInitial(params: LoadInitialParams, + callback: LoadInitialCallback) { var cpns = demoEntityDAO.getDemoEntitiesBySize(0, params.requestedLoadSize) @@ -34,11 +34,11 @@ class DemoEntityDataSource(ctx: Context) : PageKeyedDataSource( callback.onResult(cpns, null, cpns.size + 1) } - override fun loadBefore(params: PageKeyedDataSource.LoadParams, callback: PageKeyedDataSource.LoadCallback) { + override fun loadBefore(params: LoadParams, callback: LoadCallback) { } //is called to load pages of data using key passed in params - override fun loadAfter(params: PageKeyedDataSource.LoadParams, callback: PageKeyedDataSource.LoadCallback) { + override fun loadAfter(params: LoadParams, callback: LoadCallback) { val cpns = demoEntityDAO.getDemoEntitiesBySize(params.key, params.requestedLoadSize) Thread.sleep(500) diff --git a/app/src/main/res/layout/expandable_item.xml b/app/src/main/res/layout/expandable_item.xml index b5ee1cb6c..b8e5a1638 100755 --- a/app/src/main/res/layout/expandable_item.xml +++ b/app/src/main/res/layout/expandable_item.xml @@ -5,10 +5,10 @@ android:layout_width="match_parent" android:layout_height="@dimen/material_drawer_item_primary" android:orientation="horizontal" - android:paddingEnd="@dimen/material_drawer_vertical_padding" + android:paddingStart="@dimen/material_drawer_vertical_padding" android:paddingLeft="@dimen/material_drawer_vertical_padding" - android:paddingRight="@dimen/material_drawer_vertical_padding" - android:paddingStart="@dimen/material_drawer_vertical_padding"> + android:paddingEnd="@dimen/material_drawer_vertical_padding" + android:paddingRight="@dimen/material_drawer_vertical_padding"> - + app:iiv_color="@color/md_black_1000" + app:iiv_icon="gmd-keyboard-arrow-up" + app:iiv_size="16dp" /> diff --git a/build.gradle b/build.gradle index 39d929bb8..d38bc51ca 100644 --- a/build.gradle +++ b/build.gradle @@ -2,8 +2,8 @@ buildscript { ext { release = [ - versionName: "4.1.0", - versionCode: 4100 + versionName: "4.1.1", + versionCode: 4101 ] setup = [ @@ -15,17 +15,17 @@ buildscript { versions = [ androidX : '1.0.0', - recyclerView : '1.1.0-beta04', - material : '1.1.0-alpha10', + recyclerView : '1.1.0-beta05', + material : '1.1.0-beta02', appcompat : '1.1.0', drawerlayout : '1.1.0-alpha03', - constraintLayout: '2.0.0-beta2', + constraintLayout: '2.0.0-beta3', cardview : '1.0.0', kotlin : '1.3.50', materialize : '1.2.1', - iconics : '4.0.0', - materialdrawer : '7.0.0-rc07', - aboutlib : '7.0.1', + iconics : '4.0.1', + materialdrawer : '7.0.0-rc08', + aboutlib : '7.0.4', roboelectric : '4.3', detekt : '1.0.1', paging : "2.1.0", diff --git a/library-core/src/main/java/com/mikepenz/fastadapter/FastAdapter.kt b/library-core/src/main/java/com/mikepenz/fastadapter/FastAdapter.kt index d834022c2..44dc70af3 100644 --- a/library-core/src/main/java/com/mikepenz/fastadapter/FastAdapter.kt +++ b/library-core/src/main/java/com/mikepenz/fastadapter/FastAdapter.kt @@ -35,7 +35,7 @@ typealias GenericFastAdapter = FastAdapter * * See the sample application for more details * - * @param Defines the type of items this `FastAdapter` manages (in case of multiple different types, use `IItem`) + * @param Item Defines the type of items this `FastAdapter` manages (in case of multiple different types, use `IItem`) */ @FastAdapterDsl open class FastAdapter : RecyclerView.Adapter() { @@ -80,17 +80,21 @@ open class FastAdapter : RecyclerView.Adapter? = null var onClickListener: ClickListener? = null - var onPreLongClickListener: ((v: View, adapter: IAdapter, item: Item, position: Int) -> Boolean)? = null - var onLongClickListener: ((v: View, adapter: IAdapter, item: Item, position: Int) -> Boolean)? = null - var onTouchListener: ((v: View, event: MotionEvent, adapter: IAdapter, item: Item, position: Int) -> Boolean)? = null + var onPreLongClickListener: LongClickListener? = null + var onLongClickListener: LongClickListener? = null + var onTouchListener: TouchListener? = null //the listeners for onCreateViewHolder or onBindViewHolder var onCreateViewHolderListener: OnCreateViewHolderListener = OnCreateViewHolderListenerImpl() @@ -105,6 +109,7 @@ open class FastAdapter : RecyclerView.Adapter = object : ClickEventHook() { override fun onClick(v: View, position: Int, fastAdapter: FastAdapter, item: Item) { if (!item.isEnabled) return @@ -336,7 +341,7 @@ open class FastAdapter : RecyclerView.Adapter : RecyclerView.Adapter : RecyclerView.Adapter : RecyclerView.Adapter : RecyclerView.Adapter : RecyclerView.Adapter : RecyclerView.Adapter= globalSize) { return null } - if (verboseLoggingEnabled) Log.v(TAG, "getAdapter") + logger.log("getAdapter") //now get the adapter which is responsible for the given position return adapterSizes.valueAt(floorIndex(adapterSizes, position)) } @@ -843,8 +848,8 @@ open class FastAdapter : RecyclerView.Adapter - */ + * @param Item + */ abstract class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { /** diff --git a/library-core/src/main/java/com/mikepenz/fastadapter/IClickable.kt b/library-core/src/main/java/com/mikepenz/fastadapter/IClickable.kt index 8412eec81..4af18c499 100644 --- a/library-core/src/main/java/com/mikepenz/fastadapter/IClickable.kt +++ b/library-core/src/main/java/com/mikepenz/fastadapter/IClickable.kt @@ -7,6 +7,8 @@ import android.view.View */ typealias ClickListener = (v: View?, adapter: IAdapter, item: Item, position: Int) -> Boolean +typealias LongClickListener = (v: View, adapter: IAdapter, item: Item, position: Int) -> Boolean + interface IClickable { /** diff --git a/library-core/src/main/java/com/mikepenz/fastadapter/ISelectionListener.kt b/library-core/src/main/java/com/mikepenz/fastadapter/ISelectionListener.kt index 6312b8484..1f05532b4 100644 --- a/library-core/src/main/java/com/mikepenz/fastadapter/ISelectionListener.kt +++ b/library-core/src/main/java/com/mikepenz/fastadapter/ISelectionListener.kt @@ -11,5 +11,5 @@ interface ISelectionListener { * @param item the item who's selection state changed * param selected the new selection state of the item */ - fun onSelectionChanged(item: Item?, selected: Boolean) + fun onSelectionChanged(item: Item, selected: Boolean) } diff --git a/library-core/src/main/java/com/mikepenz/fastadapter/MutableSubItemList.kt b/library-core/src/main/java/com/mikepenz/fastadapter/MutableSubItemList.kt index 455ceeaa6..66cd57f9b 100644 --- a/library-core/src/main/java/com/mikepenz/fastadapter/MutableSubItemList.kt +++ b/library-core/src/main/java/com/mikepenz/fastadapter/MutableSubItemList.kt @@ -1,10 +1,24 @@ package com.mikepenz.fastadapter /** - * MutableList proxy which will properly set the parent for items added/set. + * MutableList proxy which will properly set and remove the parent for items added/set/removed. * This is important as otherwise collapsing will not work properly (does not resolve parent relationships) */ class MutableSubItemList>(val parent: IParentItem<*>, val list: MutableList = mutableListOf()) : MutableList by list { + + override fun remove(element: E): Boolean { + return list.remove(element).also { removed -> if (removed) element.parent = null } + } + + override fun removeAt(index: Int): E { + return list.removeAt(index).also { element -> element.parent = null } + } + + override fun removeAll(elements: Collection): Boolean { + elements.filter { list.contains(it) }.forEach { it.parent = null } + return list.removeAll(elements) + } + override fun add(element: E): Boolean { element.parent = parent return list.add(element) @@ -27,6 +41,6 @@ class MutableSubItemList>(val parent: IParentItem<*>, val list: override fun set(index: Int, element: E): E { element.parent = parent - return list.set(index, element) + return list.set(index, element).also { oldElement -> oldElement.parent = null } } } \ No newline at end of file diff --git a/library-core/src/main/java/com/mikepenz/fastadapter/VerboseLogger.kt b/library-core/src/main/java/com/mikepenz/fastadapter/VerboseLogger.kt new file mode 100644 index 000000000..b8728eed9 --- /dev/null +++ b/library-core/src/main/java/com/mikepenz/fastadapter/VerboseLogger.kt @@ -0,0 +1,17 @@ +package com.mikepenz.fastadapter + +import android.util.Log + +/** + * @author pa.gulko zTrap (16.10.2019) + */ +internal class VerboseLogger(private val tag: String) { + + var isEnabled = false + + fun log(message: String) { + if (isEnabled) { + Log.v(tag, message) + } + } +} \ No newline at end of file diff --git a/library-core/src/main/java/com/mikepenz/fastadapter/items/AbstractItem.kt b/library-core/src/main/java/com/mikepenz/fastadapter/items/AbstractItem.kt index eb77cb5b2..3477b1a14 100644 --- a/library-core/src/main/java/com/mikepenz/fastadapter/items/AbstractItem.kt +++ b/library-core/src/main/java/com/mikepenz/fastadapter/items/AbstractItem.kt @@ -156,9 +156,7 @@ abstract class AbstractItem : IItem { * @param id identifier * @return true if identifier equals id, false otherwise */ - override fun equals(id: Int): Boolean { - return id.toLong() == identifier - } + override fun equals(id: Int): Boolean = id.toLong() == identifier /** * If this item equals to the given object @@ -178,7 +176,5 @@ abstract class AbstractItem : IItem { * * @return */ - override fun hashCode(): Int { - return java.lang.Long.valueOf(identifier).hashCode() - } + override fun hashCode(): Int = identifier.hashCode() } diff --git a/library-core/src/main/java/com/mikepenz/fastadapter/listeners/TouchEventHook.kt b/library-core/src/main/java/com/mikepenz/fastadapter/listeners/TouchEventHook.kt index b41f19571..a0c14ef16 100644 --- a/library-core/src/main/java/com/mikepenz/fastadapter/listeners/TouchEventHook.kt +++ b/library-core/src/main/java/com/mikepenz/fastadapter/listeners/TouchEventHook.kt @@ -5,6 +5,9 @@ import android.view.View import androidx.recyclerview.widget.RecyclerView import com.mikepenz.fastadapter.FastAdapter import com.mikepenz.fastadapter.GenericItem +import com.mikepenz.fastadapter.IAdapter + +typealias TouchListener = (v: View, event: MotionEvent, adapter: IAdapter, item: Item, position: Int) -> Boolean abstract class TouchEventHook : EventHook { abstract fun onTouch(v: View, event: MotionEvent, position: Int, fastAdapter: FastAdapter, item: Item): Boolean diff --git a/library-extensions-expandable/src/main/java/com/mikepenz/fastadapter/expandable/ExpandableExtension.kt b/library-extensions-expandable/src/main/java/com/mikepenz/fastadapter/expandable/ExpandableExtension.kt index 919df356e..0d625ce85 100644 --- a/library-extensions-expandable/src/main/java/com/mikepenz/fastadapter/expandable/ExpandableExtension.kt +++ b/library-extensions-expandable/src/main/java/com/mikepenz/fastadapter/expandable/ExpandableExtension.kt @@ -76,7 +76,7 @@ class ExpandableExtension(private val fastAdapter: FastAdapt //this is the entrance parent if (allowedParents.size > 0) { // Go on until we hit an item with a parent which was not in our expandable hierarchy - val parent = (item as ISubItem<*>).parent + val parent = (item as? ISubItem<*>)?.parent if (parent == null || !allowedParents.contains(parent)) { return true } @@ -271,7 +271,7 @@ class ExpandableExtension(private val fastAdapter: FastAdapt * @return a set with the global positions of all expanded items on the same level as the current item */ fun getExpandedItemsSameLevel(position: Int): List { - fastAdapter.getItem(position).ifExpandableParent { child, parent -> + val result = fastAdapter.getItem(position).ifExpandableParent { child, parent -> //if it is a SubItem and has a parent, only return the expanded items on the same level parent.subItems.asSequence() .filter { it.isExpanded && it !== child } @@ -279,7 +279,7 @@ class ExpandableExtension(private val fastAdapter: FastAdapt .map { fastAdapter.getPosition(it) } .toList() } - return getExpandedItemsRootLevel(position) + return result ?: getExpandedItemsRootLevel(position) } /** @@ -310,13 +310,15 @@ class ExpandableExtension(private val fastAdapter: FastAdapt * toggles the expanded state of the given expandable item at the given position * * @param position the global position + * @param notifyItemChanged true if we need to call notifyItemChanged. DEFAULT: false */ - fun toggleExpandable(position: Int) { + @JvmOverloads + fun toggleExpandable(position: Int, notifyItemChanged: Boolean = true) { val item = fastAdapter.getItem(position) as? IExpandable<*> ?: return if (item.isExpanded) { - collapse(position) + collapse(position, notifyItemChanged) } else { - expand(position) + expand(position, notifyItemChanged) } } @@ -352,6 +354,24 @@ class ExpandableExtension(private val fastAdapter: FastAdapt } } + /** + * collapses (closes) the given collapsible item at the given position with parents who contains this item + * + * @param position the global position + * @param notifyItemChanged true if we need to call notifyItemChanged. DEFAULT: false + */ + @JvmOverloads + fun collapseIncludeParents(position: Int, notifyItemChanged: Boolean = false) { + val parents = getExpandableParents(position) + + parents.forEach { collapse(fastAdapter.getPosition(it.identifier)) } + + //we need to notify to get the correct drawable if there is one showing the current state + if (notifyItemChanged) { + fastAdapter.notifyItemChanged(position) + } + } + /** * expands all expandable items * @@ -398,7 +418,25 @@ class ExpandableExtension(private val fastAdapter: FastAdapt } /** - * calculates the count of expandable items before a given position + * opens the expandable item at the given position with parents who contains this item + * + * @param position the global position + * @param notifyItemChanged true if we need to call notifyItemChanged. DEFAULT: false + */ + @JvmOverloads + fun expandIncludeParents(position: Int, notifyItemChanged: Boolean = false) { + val parents = getExpandableParents(position) + + parents.forEach { expand(fastAdapter.getPosition(it.identifier)) } + + //we need to notify to get the correct drawable if there is one showing the current state + if (notifyItemChanged) { + fastAdapter.notifyItemChanged(position) + } + } + + /** + * calculates the count of expanded items before a given position * * @param from the global start position you should pass here the count of items of the previous adapters (or 0 if you want to start from the beginning) * @param position the global position @@ -413,6 +451,25 @@ class ExpandableExtension(private val fastAdapter: FastAdapt .sum() } + /** + * Walks through the parents tree while parents are non-null and parents are IExpandable + */ + private fun getExpandableParents(position: Int): List> { + val expandable = fastAdapter.getItem(position) as? IExpandable<*> ?: return emptyList() + + // walk through the parents tree + val parents = mutableListOf>() + + var element: IExpandable<*>? = expandable + while (element != null) { + parents.add(element) + element = element.parent as? IExpandable<*> + } + + // we need to reverse parents for going from root to provided item + return parents.reversed() + } + companion object { private const val BUNDLE_EXPANDED = "bundle_expanded" diff --git a/library-extensions-expandable/src/main/java/com/mikepenz/fastadapter/expandable/items/AbstractExpandableItem.kt b/library-extensions-expandable/src/main/java/com/mikepenz/fastadapter/expandable/items/AbstractExpandableItem.kt index e1b6292b0..8b6ba05f0 100644 --- a/library-extensions-expandable/src/main/java/com/mikepenz/fastadapter/expandable/items/AbstractExpandableItem.kt +++ b/library-extensions-expandable/src/main/java/com/mikepenz/fastadapter/expandable/items/AbstractExpandableItem.kt @@ -22,5 +22,5 @@ abstract class AbstractExpandableItem : override val isAutoExpanding: Boolean = true override var isSelectable: Boolean get() = subItems.isNullOrEmpty() - set(value) {} + set(_) {} } diff --git a/library-extensions-expandable/src/main/java/com/mikepenz/fastadapter/expandable/items/ModelAbstractExpandableItem.kt b/library-extensions-expandable/src/main/java/com/mikepenz/fastadapter/expandable/items/ModelAbstractExpandableItem.kt index ece5c0ac9..d0471b7bf 100644 --- a/library-extensions-expandable/src/main/java/com/mikepenz/fastadapter/expandable/items/ModelAbstractExpandableItem.kt +++ b/library-extensions-expandable/src/main/java/com/mikepenz/fastadapter/expandable/items/ModelAbstractExpandableItem.kt @@ -27,5 +27,5 @@ abstract class ModelAbstractExpandableItem) { // if necessary, init the drag handle, which will start the drag when touched if (item.touchHelper != null) { - item.getDragView(holder)?.setOnTouchListener { v, event -> - if (MotionEventCompat.getActionMasked(event) == MotionEvent.ACTION_DOWN) { + item.getDragView(holder)?.setOnTouchListener { _, event -> + if (event.actionMasked == MotionEvent.ACTION_DOWN) { if (item.isDraggable) item.touchHelper!!.startDrag(holder) } @@ -30,7 +29,7 @@ object DragDropUtil { } } - /* + /** * This functions handles the default drag and drop move event * It takes care to move all items one by one within the passed in positions *