Skip to content

Commit

Permalink
Merge pull request #1023 from mikepenz/develop
Browse files Browse the repository at this point in the history
dev -> main
  • Loading branch information
mikepenz committed Nov 24, 2021
2 parents 8cc3f7e + 0514fed commit 1ebbcd6
Show file tree
Hide file tree
Showing 17 changed files with 342 additions and 221 deletions.
6 changes: 3 additions & 3 deletions README.md
Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions app/build.gradle
Expand Up @@ -14,7 +14,7 @@ android {
ndkVersion "21.3.6528147"

defaultConfig {
minSdkVersion setup.minSdk
minSdkVersion 21
targetSdkVersion setup.targetSdk
versionCode release.versionCode
versionName release.versionName
Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -191,6 +191,6 @@ buildscript {
}

dependencies {
classpath "io.realm:realm-gradle-plugin:10.8.0"
classpath "io.realm:realm-gradle-plugin:10.8.1"
}
}
Expand Up @@ -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
Expand All @@ -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
Expand Down
Expand Up @@ -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
Expand Down Expand Up @@ -79,7 +79,12 @@ class ExpandableMultiselectDeleteSampleActivity : AppCompatActivity() {
mRangeSelectorHelper.onLongClick(position)
if (actionMode != null) {
//we want color our CAB
this@ExpandableMultiselectDeleteSampleActivity.findViewById<View>(R.id.action_mode_bar).setBackgroundColor(this@ExpandableMultiselectDeleteSampleActivity.getThemeColor(R.attr.colorPrimary, ContextCompat.getColor(this, R.color.colorPrimary)))
this@ExpandableMultiselectDeleteSampleActivity.findViewById<View>(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)
Expand All @@ -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
Expand All @@ -123,19 +128,19 @@ 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
val subItems = LinkedList<ISubItem<*>>()
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
Expand All @@ -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)
}
}
Expand Down
Expand Up @@ -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
Expand Down Expand Up @@ -75,7 +74,11 @@ class MultiselectSampleActivity : AppCompatActivity() {

mFastAdapter.onClickListener = { v: View?, _: IAdapter<SimpleItem>, _: 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
}
Expand All @@ -84,7 +87,12 @@ class MultiselectSampleActivity : AppCompatActivity() {
val actionMode = mActionModeHelper.onLongClick(this@MultiselectSampleActivity, position)
if (actionMode != null) {
//we want color our CAB
findViewById<View>(R.id.action_mode_bar).setBackgroundColor(this@MultiselectSampleActivity.getThemeColor(R.attr.colorPrimary, ContextCompat.getColor(this, R.color.colorPrimary)))
findViewById<View>(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
Expand All @@ -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)
Expand Down Expand Up @@ -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<Snackbar>() {
override fun onDismissed(transientBottomBar: Snackbar?, event: Int) {
super.onDismissed(transientBottomBar, event)
if (event != Snackbar.Callback.DISMISS_EVENT_TIMEOUT) {
selectExtension.deselect()
}
.addCallback(object : BaseTransientBottomBar.BaseCallback<Snackbar>() {
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()
Expand Down
Expand Up @@ -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)
Expand Down
Expand Up @@ -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
Expand Down
Expand Up @@ -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
Expand Down
Expand Up @@ -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
Expand Down
Expand Up @@ -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
Expand Down
35 changes: 35 additions & 0 deletions 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
}
18 changes: 9 additions & 9 deletions build.gradle
Expand Up @@ -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
Expand All @@ -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"
]
}
Expand Down

0 comments on commit 1ebbcd6

Please sign in to comment.