diff --git a/README.md b/README.md index 977900227..c5ea8f3b6 100644 --- a/README.md +++ b/README.md @@ -48,9 +48,9 @@ It's blazing fast, minimizing the code you need to write, and is easy to extend. ## Latest releases 🛠 -- Kotlin | [v5.5.1](https://github.com/mikepenz/FastAdapter/tree/v5.5.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) +- Kotlin | [v5.6.0](https://github.com/mikepenz/FastAdapter/tree/v5.6.0) +- [Deprecated] Java && AndroidX | [v3.3.1](https://github.com/mikepenz/FastAdapter/tree/v3.3.1) +- [Deprecated] Java && AppCompat | [v3.2.9](https://github.com/mikepenz/FastAdapter/tree/v3.2.9) ## Provide the gradle dependency diff --git a/app/build.gradle b/app/build.gradle index 1f1b1b219..e5985a22b 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -14,7 +14,7 @@ android { ndkVersion "21.3.6528147" defaultConfig { - minSdkVersion setup.minSdk + minSdkVersion 21 targetSdkVersion setup.targetSdk versionCode release.versionCode versionName release.versionName @@ -148,7 +148,7 @@ dependencies { //used to load the images in the ImageListSample //https://github.com/coil-kt/coil - implementation 'io.coil-kt:coil:1.3.2' + implementation 'io.coil-kt:coil:1.4.0' //Used to provide the drag selection like google photos implementation 'com.github.MFlisar:DragSelectRecyclerView:0.3' @@ -191,6 +191,6 @@ buildscript { } dependencies { - classpath "io.realm:realm-gradle-plugin:10.8.0" + classpath "io.realm:realm-gradle-plugin:10.8.1" } } \ 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 d3eaa6f78..818c7829c 100644 --- a/app/src/main/java/com/mikepenz/fastadapter/app/AdvancedSampleActivity.kt +++ b/app/src/main/java/com/mikepenz/fastadapter/app/AdvancedSampleActivity.kt @@ -10,7 +10,6 @@ import androidx.core.content.ContextCompat import androidx.recyclerview.widget.DefaultItemAnimator import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView -import com.mikepenz.aboutlibraries.util.getThemeColor import com.mikepenz.fastadapter.* import com.mikepenz.fastadapter.adapters.GenericItemAdapter import com.mikepenz.fastadapter.adapters.ItemAdapter @@ -20,6 +19,7 @@ import com.mikepenz.fastadapter.app.databinding.ActivitySampleBinding import com.mikepenz.fastadapter.app.items.SimpleItem import com.mikepenz.fastadapter.app.items.expandable.SimpleSubExpandableItem import com.mikepenz.fastadapter.app.items.expandable.SimpleSubItem +import com.mikepenz.fastadapter.app.utils.getThemeColor import com.mikepenz.fastadapter.expandable.getExpandableExtension import com.mikepenz.fastadapter.helpers.ActionModeHelper import com.mikepenz.fastadapter.select.getSelectExtension 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 fc6449ec4..e1a83cf8d 100644 --- a/app/src/main/java/com/mikepenz/fastadapter/app/ExpandableMultiselectDeleteSampleActivity.kt +++ b/app/src/main/java/com/mikepenz/fastadapter/app/ExpandableMultiselectDeleteSampleActivity.kt @@ -10,13 +10,13 @@ import androidx.appcompat.view.ActionMode import androidx.core.content.ContextCompat import androidx.recyclerview.widget.LinearLayoutManager import com.michaelflisar.dragselectrecyclerview.DragSelectTouchListener -import com.mikepenz.aboutlibraries.util.getThemeColor import com.mikepenz.fastadapter.* import com.mikepenz.fastadapter.adapters.FastItemAdapter import com.mikepenz.fastadapter.adapters.GenericFastItemAdapter import com.mikepenz.fastadapter.app.databinding.ActivitySampleBinding import com.mikepenz.fastadapter.app.items.HeaderSelectionItem import com.mikepenz.fastadapter.app.items.expandable.SimpleSubItem +import com.mikepenz.fastadapter.app.utils.getThemeColor import com.mikepenz.fastadapter.expandable.ExpandableExtension import com.mikepenz.fastadapter.expandable.getExpandableExtension import com.mikepenz.fastadapter.helpers.ActionModeHelper @@ -79,7 +79,12 @@ class ExpandableMultiselectDeleteSampleActivity : AppCompatActivity() { mRangeSelectorHelper.onLongClick(position) if (actionMode != null) { //we want color our CAB - this@ExpandableMultiselectDeleteSampleActivity.findViewById(R.id.action_mode_bar).setBackgroundColor(this@ExpandableMultiselectDeleteSampleActivity.getThemeColor(R.attr.colorPrimary, ContextCompat.getColor(this, R.color.colorPrimary))) + this@ExpandableMultiselectDeleteSampleActivity.findViewById(R.id.action_mode_bar).setBackgroundColor( + this@ExpandableMultiselectDeleteSampleActivity.getThemeColor( + R.attr.colorPrimary, + ContextCompat.getColor(this, R.color.colorPrimary) + ) + ) // start the drag selection mDragSelectTouchListener.startDragSelection(position) @@ -91,24 +96,24 @@ class ExpandableMultiselectDeleteSampleActivity : AppCompatActivity() { // provide a custom title provider that even shows the count of sub items mActionModeHelper = ActionModeHelper(fastItemAdapter, R.menu.cab, ActionBarCallBack()) - .withTitleProvider(object : ActionModeHelper.ActionModeTitleProvider { - override fun getTitle(selected: Int): String { - return selected.toString() + "/" + SubItemUtil.countItems(fastItemAdapter.itemAdapter, false) - } - }) + .withTitleProvider(object : ActionModeHelper.ActionModeTitleProvider { + override fun getTitle(selected: Int): String { + return selected.toString() + "/" + SubItemUtil.countItems(fastItemAdapter.itemAdapter, false) + } + }) // this will take care of selecting range of items via long press on the first and afterwards on the last item mRangeSelectorHelper = RangeSelectorHelper(fastItemAdapter) - .withSavedInstanceState(savedInstanceState) - .withActionModeHelper(mActionModeHelper) + .withSavedInstanceState(savedInstanceState) + .withActionModeHelper(mActionModeHelper) // setup the drag select listener and add it to the RecyclerView mDragSelectTouchListener = DragSelectTouchListener() - .withSelectListener { start, end, isSelected -> - mRangeSelectorHelper.selectRange(start, end, isSelected, true) - // we handled the long press, so we reset the range selector - mRangeSelectorHelper.reset() - } + .withSelectListener { start, end, isSelected -> + mRangeSelectorHelper.selectRange(start, end, isSelected, true) + // we handled the long press, so we reset the range selector + mRangeSelectorHelper.reset() + } binding.rv.addOnItemTouchListener(mDragSelectTouchListener) // do basic RecyclerView setup @@ -123,9 +128,9 @@ class ExpandableMultiselectDeleteSampleActivity : AppCompatActivity() { val expandableItem = HeaderSelectionItem() expandableItem.withSubSelectionProvider { SubItemUtil.countSelectedSubItems(fastItemAdapter, expandableItem) } expandableItem - .withName("Test " + (i + 1)) - .withDescription("ID: " + (i + 1)) - .identifier = (i + 1).toLong() + .withName("Test " + (i + 1)) + .withDescription("ID: " + (i + 1)) + .identifier = (i + 1).toLong() //.withIsExpanded(true) don't use this in such a setup, use adapter.expand() to expand all items instead //add subItems so we can showcase the collapsible functionality @@ -133,9 +138,9 @@ class ExpandableMultiselectDeleteSampleActivity : AppCompatActivity() { for (ii in 1..5) { val sampleItem = SimpleSubItem() sampleItem - .withName("-- Test " + (i + 1) + "." + ii) - .withDescription("ID: " + ((i + 1) * 100 + ii)) - .identifier = ((i + 1) * 100 + ii).toLong() + .withName("-- Test " + (i + 1) + "." + ii) + .withDescription("ID: " + ((i + 1) * 100 + ii)) + .identifier = ((i + 1) * 100 + ii).toLong() subItems.add(sampleItem) } expandableItem.subItems = subItems @@ -144,9 +149,9 @@ class ExpandableMultiselectDeleteSampleActivity : AppCompatActivity() { } else { val sampleItem = SimpleSubItem() sampleItem - .withName("Test " + (i + 1)) - .withDescription("ID: " + (i + 1)) - .identifier = (i + 1).toLong() + .withName("Test " + (i + 1)) + .withDescription("ID: " + (i + 1)) + .identifier = (i + 1).toLong() items.add(sampleItem) } } 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 ed5e950b5..06dfdef57 100755 --- a/app/src/main/java/com/mikepenz/fastadapter/app/MultiselectSampleActivity.kt +++ b/app/src/main/java/com/mikepenz/fastadapter/app/MultiselectSampleActivity.kt @@ -12,19 +12,18 @@ import androidx.core.content.ContextCompat import androidx.recyclerview.widget.LinearLayoutManager import com.google.android.material.snackbar.BaseTransientBottomBar import com.google.android.material.snackbar.Snackbar -import com.mikepenz.aboutlibraries.util.getThemeColor import com.mikepenz.fastadapter.FastAdapter import com.mikepenz.fastadapter.IAdapter import com.mikepenz.fastadapter.ISelectionListener import com.mikepenz.fastadapter.adapters.ItemAdapter import com.mikepenz.fastadapter.app.databinding.ActivitySampleBinding import com.mikepenz.fastadapter.app.items.SimpleItem +import com.mikepenz.fastadapter.app.utils.getThemeColor import com.mikepenz.fastadapter.helpers.ActionModeHelper import com.mikepenz.fastadapter.helpers.UndoHelper import com.mikepenz.fastadapter.select.SelectExtension import com.mikepenz.fastadapter.select.getSelectExtension import com.mikepenz.itemanimators.SlideDownAlphaAnimator -import java.util.* class MultiselectSampleActivity : AppCompatActivity() { private lateinit var binding: ActivitySampleBinding @@ -75,7 +74,11 @@ class MultiselectSampleActivity : AppCompatActivity() { mFastAdapter.onClickListener = { v: View?, _: IAdapter, _: SimpleItem, _: Int -> if (v != null) { - Toast.makeText(v.context, "SelectedCount: " + selectExtension.selections.size + " ItemsCount: " + selectExtension.selectedItems.size, Toast.LENGTH_SHORT).show() + Toast.makeText( + v.context, + "SelectedCount: " + selectExtension.selections.size + " ItemsCount: " + selectExtension.selectedItems.size, + Toast.LENGTH_SHORT + ).show() } false } @@ -84,7 +87,12 @@ class MultiselectSampleActivity : AppCompatActivity() { val actionMode = mActionModeHelper.onLongClick(this@MultiselectSampleActivity, position) if (actionMode != null) { //we want color our CAB - findViewById(R.id.action_mode_bar).setBackgroundColor(this@MultiselectSampleActivity.getThemeColor(R.attr.colorPrimary, ContextCompat.getColor(this, R.color.colorPrimary))) + findViewById(R.id.action_mode_bar).setBackgroundColor( + this@MultiselectSampleActivity.getThemeColor( + R.attr.colorPrimary, + ContextCompat.getColor(this, R.color.colorPrimary) + ) + ) } //if we have no actionMode we do not consume the event actionMode != null @@ -107,8 +115,7 @@ class MultiselectSampleActivity : AppCompatActivity() { //fill with some sample data val simpleItem = SimpleItem() - simpleItem - .withName("Header") + simpleItem.withName("Header") simpleItem.identifier = 2 simpleItem.isSelectable = false headerAdapter.add(simpleItem) @@ -157,14 +164,14 @@ class MultiselectSampleActivity : AppCompatActivity() { override fun onActionItemClicked(mode: ActionMode, item: MenuItem): Boolean { mUndoHelper.remove(findViewById(android.R.id.content), "Item removed", "Undo", Snackbar.LENGTH_LONG, selectExtension.selections) - .addCallback(object : BaseTransientBottomBar.BaseCallback() { - override fun onDismissed(transientBottomBar: Snackbar?, event: Int) { - super.onDismissed(transientBottomBar, event) - if (event != Snackbar.Callback.DISMISS_EVENT_TIMEOUT) { - selectExtension.deselect() - } + .addCallback(object : BaseTransientBottomBar.BaseCallback() { + override fun onDismissed(transientBottomBar: Snackbar?, event: Int) { + super.onDismissed(transientBottomBar, event) + if (event != Snackbar.Callback.DISMISS_EVENT_TIMEOUT) { + selectExtension.deselect() } - }) + } + }) //as we no longer have a selection so the actionMode can be finished mode.finish() diff --git a/app/src/main/java/com/mikepenz/fastadapter/app/SampleActivity.kt b/app/src/main/java/com/mikepenz/fastadapter/app/SampleActivity.kt index 1a91e1e41..539a751b5 100755 --- a/app/src/main/java/com/mikepenz/fastadapter/app/SampleActivity.kt +++ b/app/src/main/java/com/mikepenz/fastadapter/app/SampleActivity.kt @@ -117,7 +117,6 @@ class SampleActivity : AppCompatActivity() { 21L -> Intent(this@SampleActivity, PagedActivity::class.java) 22L -> Intent(this@SampleActivity, DragAndDropActivity::class.java) 100L -> LibsBuilder() - .withFields(R.string::class.java.fields) .withActivityTitle(getString(R.string.open_source)) .withAboutIconShown(true) .withVersionShown(true) diff --git a/app/src/main/java/com/mikepenz/fastadapter/app/binding/BindingIconItem.kt b/app/src/main/java/com/mikepenz/fastadapter/app/binding/BindingIconItem.kt index a6d9bb5ca..6c33d4b40 100644 --- a/app/src/main/java/com/mikepenz/fastadapter/app/binding/BindingIconItem.kt +++ b/app/src/main/java/com/mikepenz/fastadapter/app/binding/BindingIconItem.kt @@ -2,12 +2,12 @@ package com.mikepenz.fastadapter.app.binding import android.view.LayoutInflater import android.view.ViewGroup -import com.mikepenz.aboutlibraries.util.getThemeColor import com.mikepenz.fastadapter.IExpandable import com.mikepenz.fastadapter.IParentItem import com.mikepenz.fastadapter.ISubItem import com.mikepenz.fastadapter.app.R import com.mikepenz.fastadapter.app.databinding.IconItemBinding +import com.mikepenz.fastadapter.app.utils.getThemeColor import com.mikepenz.fastadapter.binding.AbstractBindingItem import com.mikepenz.fastadapter.binding.BindingViewHolder import com.mikepenz.iconics.IconicsDrawable 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 414ad0969..b84529666 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 @@ -3,11 +3,11 @@ package com.mikepenz.fastadapter.app.items import android.view.View import android.widget.TextView import androidx.recyclerview.widget.RecyclerView -import com.mikepenz.aboutlibraries.util.getThemeColor import com.mikepenz.fastadapter.IExpandable import com.mikepenz.fastadapter.IParentItem import com.mikepenz.fastadapter.ISubItem import com.mikepenz.fastadapter.app.R +import com.mikepenz.fastadapter.app.utils.getThemeColor import com.mikepenz.fastadapter.items.AbstractItem import com.mikepenz.iconics.IconicsDrawable import com.mikepenz.iconics.typeface.IIcon diff --git a/app/src/main/java/com/mikepenz/fastadapter/app/items/SimpleImageItem.kt b/app/src/main/java/com/mikepenz/fastadapter/app/items/SimpleImageItem.kt index e3d786e5d..7bed45654 100644 --- a/app/src/main/java/com/mikepenz/fastadapter/app/items/SimpleImageItem.kt +++ b/app/src/main/java/com/mikepenz/fastadapter/app/items/SimpleImageItem.kt @@ -8,9 +8,9 @@ import androidx.core.content.ContextCompat import androidx.recyclerview.widget.RecyclerView import coil.clear import coil.load -import com.mikepenz.aboutlibraries.util.getThemeColor import com.mikepenz.fastadapter.IItemVHFactory import com.mikepenz.fastadapter.app.R +import com.mikepenz.fastadapter.app.utils.getThemeColor import com.mikepenz.fastadapter.items.BaseItem import com.mikepenz.fastadapter.items.BaseItemFactory import com.mikepenz.fastadapter.ui.utils.FastAdapterUIUtils diff --git a/app/src/main/java/com/mikepenz/fastadapter/app/model/ModelIconItem.kt b/app/src/main/java/com/mikepenz/fastadapter/app/model/ModelIconItem.kt index 982e61475..e83b6e49d 100644 --- a/app/src/main/java/com/mikepenz/fastadapter/app/model/ModelIconItem.kt +++ b/app/src/main/java/com/mikepenz/fastadapter/app/model/ModelIconItem.kt @@ -3,8 +3,8 @@ package com.mikepenz.fastadapter.app.model import android.view.View import android.widget.TextView import androidx.recyclerview.widget.RecyclerView -import com.mikepenz.aboutlibraries.util.getThemeColor import com.mikepenz.fastadapter.app.R +import com.mikepenz.fastadapter.app.utils.getThemeColor import com.mikepenz.fastadapter.items.ModelAbstractItem import com.mikepenz.iconics.IconicsDrawable import com.mikepenz.iconics.utils.colorInt diff --git a/app/src/main/java/com/mikepenz/fastadapter/app/utils/Utils.kt b/app/src/main/java/com/mikepenz/fastadapter/app/utils/Utils.kt new file mode 100644 index 000000000..5f56d3aa5 --- /dev/null +++ b/app/src/main/java/com/mikepenz/fastadapter/app/utils/Utils.kt @@ -0,0 +1,35 @@ +package com.mikepenz.fastadapter.app.utils + +import android.content.Context +import android.util.TypedValue +import androidx.annotation.AttrRes +import androidx.annotation.ColorInt +import androidx.annotation.RestrictTo +import androidx.core.content.ContextCompat +import androidx.core.content.res.ResourcesCompat + +internal fun Context.getThemeColor(attr: Int): Int { + val tv = TypedValue() + return if (this.theme.resolveAttribute(attr, tv, true)) { + if (tv.resourceId != 0) { + ContextCompat.getColor(this, tv.resourceId) + } else { + tv.data + } + } else { + 0 + } +} + + +/** + * a helper method to get the color from an attribute + * @hide + */ +@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) +fun Context.getThemeColor(@AttrRes attr: Int, @ColorInt def: Int = 0): Int { + val tv = TypedValue() + return if (theme.resolveAttribute(attr, tv, true)) { + if (tv.resourceId != 0) ResourcesCompat.getColor(resources, tv.resourceId, theme) else tv.data + } else def +} \ No newline at end of file diff --git a/build.gradle b/build.gradle index 6e2e43176..d07a597fd 100644 --- a/build.gradle +++ b/build.gradle @@ -4,13 +4,13 @@ buildscript { ext { release = [ - versionName: "5.5.1", - versionCode: 5051 + versionName: "5.6.0", + versionCode: 5060 ] setup = [ - gradleTools: '7.0.2', - compileSdk : 30, + gradleTools: '7.0.3', + compileSdk : 31, buildTools : "31.0.0", minSdk : 16, targetSdk : 30 @@ -19,18 +19,18 @@ buildscript { versions = [ recyclerView : '1.2.1', material : '1.4.0', - appcompat : '1.3.1', + appcompat : '1.4.0', drawerlayout : '1.1.0', constraintLayout: '2.1.0', cardview : '1.0.0', - kotlin : '1.5.30', + kotlin : '1.5.31', iconics : '5.2.8', - materialdrawer : '8.4.3', - aboutlib : '8.9.1', + materialdrawer : '8.4.5', + aboutlib : '10.0.0-b01', roboelectric : '4.6.1', detekt : '1.18.1', paging : "2.1.2", - room : "2.4.0-alpha04", + room : "2.4.0-beta02", lifecycle : "2.3.1" ] } diff --git a/fastadapter-extensions-expandable/src/main/java/com/mikepenz/fastadapter/expandable/ExpandableExtension.kt b/fastadapter-extensions-expandable/src/main/java/com/mikepenz/fastadapter/expandable/ExpandableExtension.kt index 9d97b9ee3..b42eaed96 100644 --- a/fastadapter-extensions-expandable/src/main/java/com/mikepenz/fastadapter/expandable/ExpandableExtension.kt +++ b/fastadapter-extensions-expandable/src/main/java/com/mikepenz/fastadapter/expandable/ExpandableExtension.kt @@ -49,7 +49,7 @@ internal fun IItem?.ifExpandableParent(block: ( */ @FastAdapterDsl class ExpandableExtension(private val fastAdapter: FastAdapter) : - IAdapterExtension { + IAdapterExtension { private val collapseAdapterPredicate = object : AdapterPredicate { private var allowedParents = ArraySet>() @@ -57,10 +57,10 @@ class ExpandableExtension(private val fastAdapter: FastAdapt private var expandedItemsCount = 0 override fun apply( - lastParentAdapter: IAdapter, - lastParentPosition: Int, - item: Item, - position: Int + lastParentAdapter: IAdapter, + lastParentPosition: Int, + item: Item, + position: Int ): Boolean { //we do not care about non visible items if (position == RecyclerView.NO_POSITION) { @@ -153,10 +153,10 @@ class ExpandableExtension(private val fastAdapter: FastAdapt return } val expandedItems = (0 until fastAdapter.itemCount).asSequence() - .mapNotNull { fastAdapter.getItem(it) } - .filter { it.isExpanded } - .map { it.identifier } - .toList() + .mapNotNull { fastAdapter.getItem(it) } + .filter { it.isExpanded } + .map { it.identifier } + .toList() //remember the collapsed states savedInstanceState.putLongArray(BUNDLE_EXPANDED + prefix, expandedItems.toLongArray()) } @@ -183,20 +183,20 @@ class ExpandableExtension(private val fastAdapter: FastAdapt } override fun onLongClick( - v: View, - pos: Int, - fastAdapter: FastAdapter, - item: Item + v: View, + pos: Int, + fastAdapter: FastAdapter, + item: Item ): Boolean { return false } override fun onTouch( - v: View, - event: MotionEvent, - position: Int, - fastAdapter: FastAdapter, - item: Item + v: View, + event: MotionEvent, + position: Int, + fastAdapter: FastAdapter, + item: Item ): Boolean { return false } @@ -245,8 +245,8 @@ class ExpandableExtension(private val fastAdapter: FastAdapt (adapter as? IItemAdapter<*, *>)?.removeRange(position + 1, previousCount) expandable.subItems.let { subItems -> (adapter as? IItemAdapter?)?.add( - position + 1, - subItems + position + 1, + subItems ) } } @@ -262,10 +262,10 @@ class ExpandableExtension(private val fastAdapter: FastAdapt 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 } - .mapNotNull { it as? Item? } - .map { fastAdapter.getPosition(it) } - .toList() + .filter { it.isExpanded && it !== child } + .mapNotNull { it as? Item? } + .map { fastAdapter.getPosition(it) } + .toList() } return result ?: getExpandedItemsRootLevel(position) } @@ -333,12 +333,12 @@ class ExpandableExtension(private val fastAdapter: FastAdapt fun collapse(position: Int, notifyItemChanged: Boolean = false) { val adapter = fastAdapter.getAdapter(position) (adapter as? IItemAdapter<*, *>?)?.removeRange( - position + 1, - collapseAdapterPredicate.collapse(position, fastAdapter) + position + 1, + collapseAdapterPredicate.collapse(position, fastAdapter) ) //we need to notify to get the correct drawable if there is one showing the current state if (notifyItemChanged) { - fastAdapter.notifyItemChanged(position) + fastAdapter.notifyItemChanged(position, PAYLOAD_COLLAPSE) } } @@ -356,7 +356,7 @@ class ExpandableExtension(private val fastAdapter: FastAdapt //we need to notify to get the correct drawable if there is one showing the current state if (notifyItemChanged) { - fastAdapter.notifyItemChanged(position) + fastAdapter.notifyItemChanged(position, PAYLOAD_COLLAPSE) } } @@ -389,8 +389,8 @@ class ExpandableExtension(private val fastAdapter: FastAdapt if (adapter != null && adapter is IItemAdapter<*, *>) { (expandable.subItems as? List?)?.let { subItems -> (adapter as IItemAdapter<*, Item>).addInternal( - position + 1, - subItems + position + 1, + subItems ) } } @@ -400,7 +400,7 @@ class ExpandableExtension(private val fastAdapter: FastAdapt //we need to notify to get the correct drawable if there is one showing the current state if (notifyItemChanged) { - fastAdapter.notifyItemChanged(position) + fastAdapter.notifyItemChanged(position, PAYLOAD_EXPAND) } } } @@ -420,7 +420,7 @@ class ExpandableExtension(private val fastAdapter: FastAdapt //we need to notify to get the correct drawable if there is one showing the current state if (notifyItemChanged) { val position = fastAdapter.getPosition(item.identifier) - fastAdapter.notifyItemChanged(position) + fastAdapter.notifyItemChanged(position, PAYLOAD_EXPAND) } } @@ -438,7 +438,7 @@ class ExpandableExtension(private val fastAdapter: FastAdapt //we need to notify to get the correct drawable if there is one showing the current state if (notifyItemChanged) { - fastAdapter.notifyItemChanged(position) + fastAdapter.notifyItemChanged(position, PAYLOAD_EXPAND) } } @@ -451,11 +451,11 @@ class ExpandableExtension(private val fastAdapter: FastAdapt */ fun getExpandedItemsCount(from: Int, position: Int): Int { return (from until position) - .asSequence() - .mapNotNull { fastAdapter.getItem(it) as? IExpandable<*> } - .filter { it.isExpanded } - .map { it.subItems.size } - .sum() + .asSequence() + .mapNotNull { fastAdapter.getItem(it) as? IExpandable<*> } + .filter { it.isExpanded } + .map { it.subItems.size } + .sum() } /** Walks through the parents tree while parents are non-null and parents are IExpandable */ @@ -484,6 +484,16 @@ class ExpandableExtension(private val fastAdapter: FastAdapt companion object { private const val BUNDLE_EXPANDED = "bundle_expanded" + /** + * Payload indicating the item was clicked to expand + */ + const val PAYLOAD_EXPAND = "fa_PAYLOAD_EXPAND" + + /** + * Payload indicating the item was clicked to collapse + */ + const val PAYLOAD_COLLAPSE = "fa_PAYLOAD_COLLAPSE" + init { ExtensionsFactories.register(ExpandableExtensionFactory()) } diff --git a/fastadapter-extensions-utils/src/main/java/com/mikepenz/fastadapter/helpers/UndoHelper.kt b/fastadapter-extensions-utils/src/main/java/com/mikepenz/fastadapter/helpers/UndoHelper.kt index b6dc97543..ba414bea9 100644 --- a/fastadapter-extensions-utils/src/main/java/com/mikepenz/fastadapter/helpers/UndoHelper.kt +++ b/fastadapter-extensions-utils/src/main/java/com/mikepenz/fastadapter/helpers/UndoHelper.kt @@ -1,7 +1,6 @@ package com.mikepenz.fastadapter.helpers import android.view.View -import android.widget.TextView import com.google.android.material.snackbar.BaseTransientBottomBar import com.google.android.material.snackbar.Snackbar import com.mikepenz.fastadapter.FastAdapter @@ -20,8 +19,8 @@ import java.util.Arrays.asList * @param undoListener the listener which gets called when an item was really removed */ class UndoHelper( - private val adapter: FastAdapter, - private val undoListener: UndoListener + private val adapter: FastAdapter, + private val undoListener: UndoListener ) { private var history: History? = null private var snackBarActionText = "" @@ -49,37 +48,37 @@ class UndoHelper( var snackBar: Snackbar? = null private set + /** Constructs the snackbar to be used for the undoHelper */ + private var snackbarBuilder: (() -> Snackbar)? = null + /** * An optional method to add a [Snackbar] of your own with custom styling. * note that using this method will override your custom action * - * @param snackBar your own Snackbar * @param actionText the text to show for the Undo Action + * @param snackbarBuilder constructs the snackbar with custom styling */ - fun withSnackBar(snackBar: Snackbar, actionText: String) { - this.snackBar = snackBar - snackBarActionText = actionText - snackBar.addCallback(snackBarCallback).setAction(actionText) { undoChange() } + fun withSnackBar(actionText: String, snackbarBuilder: () -> Snackbar) { + this.snackBarActionText = actionText + this.snackbarBuilder = snackbarBuilder } /** * Convenience method to be used if you have previously set a [Snackbar] with [withSnackBar] + * NOTE: No action will be executed if [withSnackBar] was not previously called. * * @param positions the positions where the items were removed * @return the snackbar or null if [withSnackBar] was not previously called */ fun remove(positions: Set): Snackbar? { - val snackBar = this.snackBar ?: return null - val snackBarView = snackBar.view - val snackBarText = snackBarView.findViewById(com.google.android.material.R.id.snackbar_text) as TextView - return remove(snackBarView, snackBarText.text.toString(), snackBarActionText, snackBar.duration, positions) + val builder = this.snackbarBuilder ?: return null + return remove(positions, snackBarActionText, builder) } /** * Removes items from the ItemAdapter. - * note that the values of "view", "text", "actionText", and "duration" - * will be ignored if [withSnackBar] was used. - * if it was not used, a default snackbar will be generated + * + * Creates a default [Snackbar] with the given information. * * @param view the view which will host the SnackBar * @param text the text to show on the SnackBar @@ -88,6 +87,21 @@ class UndoHelper( * @return the generated Snackbar */ fun remove(view: View, text: String, actionText: String, @BaseTransientBottomBar.Duration duration: Int, positions: Set): Snackbar { + return remove(positions, actionText) { + Snackbar.make(view, text, duration) + } + } + + /** + * Removes items from the ItemAdapter. + * Displays the created [Snackbar] via the [snackbarBuilder], and configures the action with the given [actionText] + * + * @param positions the positions where the items were removed + * @param actionText the text to show for the Undo Action + * @param snackbarBuilder constructs the snackbar with custom styling + * @return the generated Snackbar + */ + fun remove(positions: Set, actionText: String, snackbarBuilder: () -> Snackbar): Snackbar { if (history != null) { // Set a flag, if remove was called before the Snackbar // executed the commit -> Snackbar does not commit the new @@ -101,16 +115,18 @@ class UndoHelper( for (position in positions) { history.items.add(adapter.getRelativeInfo(position)) } - history.items.sortWith(Comparator { lhs, rhs -> Integer.valueOf(lhs.position).compareTo(rhs.position) }) + history.items.sortWith { lhs, rhs -> Integer.valueOf(lhs.position).compareTo(rhs.position) } this.history = history doChange() // Do not execute when Snackbar shows up, instead change immediately - val snackBar = Snackbar.make(view, text, duration).addCallback(snackBarCallback) - snackBar.setAction(actionText) { undoChange() } - snackBar.show() - this.snackBar = snackBar - return snackBar + return snackbarBuilder.invoke() + .addCallback(snackBarCallback) + .setAction(actionText) { undoChange() } + .also { + it.show() + this.snackBar = it + } } private fun notifyCommit() { diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index e708b1c02..7454180f2 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index a0f7639f7..fbce071a3 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.3-all.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew index 4f906e0c8..3da45c161 100755 --- a/gradlew +++ b/gradlew @@ -1,7 +1,7 @@ -#!/usr/bin/env sh +#!/bin/sh # -# Copyright 2015 the original author or authors. +# Copyright ? 2015-2021 the original authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -17,67 +17,101 @@ # ############################################################################## -## -## Gradle start up script for UN*X -## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions ?$var?, ?${var}?, ?${var:-default}?, ?${var+SET}?, +# ?${var#prefix}?, ?${var%suffix}?, and ?$( cmd )?; +# * compound commands having a testable exit status, especially ?case?; +# * various built-in commands including ?command?, ?set?, and ?ulimit?. +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# ############################################################################## # Attempt to set APP_HOME + # Resolve links: $0 may be a link -PRG="$0" -# Need this for relative symlinks. -while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG=`dirname "$PRG"`"/$link" - fi +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac done -SAVED="`pwd`" -cd "`dirname \"$PRG\"`/" >/dev/null -APP_HOME="`pwd -P`" -cd "$SAVED" >/dev/null + +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit APP_NAME="Gradle" -APP_BASE_NAME=`basename "$0"` +APP_BASE_NAME=${0##*/} # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' # Use the maximum available, or set MAX_FD != -1 to use that value. -MAX_FD="maximum" +MAX_FD=maximum warn () { echo "$*" -} +} >&2 die () { echo echo "$*" echo exit 1 -} +} >&2 # OS specific support (must be 'true' or 'false'). cygwin=false msys=false darwin=false nonstop=false -case "`uname`" in - CYGWIN* ) - cygwin=true - ;; - Darwin* ) - darwin=true - ;; - MINGW* ) - msys=true - ;; - NONSTOP* ) - nonstop=true - ;; +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; esac CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar @@ -87,9 +121,9 @@ CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar if [ -n "$JAVA_HOME" ] ; then if [ -x "$JAVA_HOME/jre/sh/java" ] ; then # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" + JAVACMD=$JAVA_HOME/jre/sh/java else - JAVACMD="$JAVA_HOME/bin/java" + JAVACMD=$JAVA_HOME/bin/java fi if [ ! -x "$JAVACMD" ] ; then die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME @@ -98,7 +132,7 @@ Please set the JAVA_HOME variable in your environment to match the location of your Java installation." fi else - JAVACMD="java" + JAVACMD=java which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the @@ -106,80 +140,95 @@ location of your Java installation." fi # Increase the maximum file descriptors if we can. -if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then - MAX_FD_LIMIT=`ulimit -H -n` - if [ $? -eq 0 ] ; then - if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then - MAX_FD="$MAX_FD_LIMIT" - fi - ulimit -n $MAX_FD - if [ $? -ne 0 ] ; then - warn "Could not set maximum file descriptor limit: $MAX_FD" - fi - else - warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" - fi +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac fi -# For Darwin, add options to specify how the application appears in the dock -if $darwin; then - GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" -fi +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. # For Cygwin or MSYS, switch paths to Windows format before running java -if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then - APP_HOME=`cygpath --path --mixed "$APP_HOME"` - CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` - - JAVACMD=`cygpath --unix "$JAVACMD"` - - # We build the pattern for arguments to be converted via cygpath - ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` - SEP="" - for dir in $ROOTDIRSRAW ; do - ROOTDIRS="$ROOTDIRS$SEP$dir" - SEP="|" - done - OURCYGPATTERN="(^($ROOTDIRS))" - # Add a user-defined pattern to the cygpath arguments - if [ "$GRADLE_CYGPATTERN" != "" ] ; then - OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" - fi +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + # Now convert the arguments - kludge to limit ourselves to /bin/sh - i=0 - for arg in "$@" ; do - CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` - CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option - - if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition - eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` - else - eval `echo args$i`="\"$arg\"" + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) fi - i=`expr $i + 1` + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg done - case $i in - 0) set -- ;; - 1) set -- "$args0" ;; - 2) set -- "$args0" "$args1" ;; - 3) set -- "$args0" "$args1" "$args2" ;; - 4) set -- "$args0" "$args1" "$args2" "$args3" ;; - 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; - 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; - 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; - 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; - 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; - esac fi -# Escape application args -save () { - for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done - echo " " -} -APP_ARGS=`save "$@"` +# Collect all arguments for the java command; +# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of +# shell script including quotes and variable substitutions, so put them in +# double quotes to make sure that they get re-expanded; and +# * put everything else in single quotes, so that it's not re-expanded. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# -# Collect all arguments for the java command, following the shell quoting and substitution rules -eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' exec "$JAVACMD" "$@"