Skip to content

Commit

Permalink
Merge pull request #1011 from mikepenz/develop
Browse files Browse the repository at this point in the history
dev -> main
  • Loading branch information
mikepenz authored Sep 10, 2021
2 parents d3a7ab7 + 6882dfe commit 4713bbe
Show file tree
Hide file tree
Showing 23 changed files with 257 additions and 164 deletions.
9 changes: 5 additions & 4 deletions DEV/default-detekt-config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ complexity:
threshold: 60
LongParameterList:
active: true
threshold: 10
functionThreshold: 10
constructorThreshold: 10
ignoreDefaultParameters: false
MethodOverloading:
active: false
Expand Down Expand Up @@ -114,7 +115,7 @@ empty-blocks:
active: true
EmptyFunctionBlock:
active: false
ignoreOverriddenFunctions: false
ignoreOverridden: false
EmptyIfBlock:
active: true
EmptyInitBlock:
Expand Down Expand Up @@ -311,15 +312,15 @@ naming:
excludes: "**/test/**,**/androidTest/**,**/*.Test.kt,**/*.Spec.kt,**/*.Spek.kt"
parameterPattern: '[a-z][A-Za-z0-9]*'
excludeClassPattern: '$^'
ignoreOverriddenFunctions: true
ignoreOverridden: true
InvalidPackageDeclaration:
active: false
rootPackage: ''
MatchingDeclarationName:
active: true
MemberNameEqualsClassName:
active: false
ignoreOverriddenFunction: true
ignoreOverridden: true
ObjectPropertyNaming:
active: true
excludes: "**/test/**,**/androidTest/**,**/*.Test.kt,**/*.Spec.kt,**/*.Spek.kt"
Expand Down
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
GEM
remote: https://rubygems.org/
specs:
addressable (2.7.0)
addressable (2.8.0)
public_suffix (>= 2.0.2, < 5.0)
ansi (1.5.0)
ast (2.4.2)
Expand Down Expand Up @@ -58,7 +58,7 @@ GEM
open4 (1.3.4)
public_suffix (4.0.6)
rchardet (1.8.0)
rexml (3.2.4)
rexml (3.2.5)
ruby-ll (2.1.2)
ansi
ast
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ It's blazing fast, minimizing the code you need to write, and is easy to extend.

## Latest releases 🛠

- Kotlin | [v5.4.1](https://github.com/mikepenz/FastAdapter/tree/v5.4.1)
- Kotlin | [v5.5.0](https://github.com/mikepenz/FastAdapter/tree/v5.5.0)
- 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)

Expand Down
8 changes: 4 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ dependencies {
//https://github.com/mikepenz/Android-Iconics
implementation 'com.mikepenz:material-design-iconic-typeface:2.2.0.8-kotlin@aar'
implementation 'com.mikepenz:community-material-typeface:5.8.55.0-kotlin@aar'
implementation 'com.mikepenz:google-material-typeface:4.0.0.1-kotlin@aar'
implementation 'com.mikepenz:fontawesome-typeface:5.9.0.2-kotlin@aar'
implementation 'com.mikepenz:google-material-typeface:4.0.0.2-kotlin@aar'
implementation 'com.mikepenz:fontawesome-typeface:5.13.3.0-kotlin@aar'

//Used for the StickyHeaderSample
//https://github.com/timehop/sticky-headers-recyclerview
Expand All @@ -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.1.1'
implementation 'io.coil-kt:coil:1.3.2'

//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.4.0"
classpath "io.realm:realm-gradle-plugin:10.8.0"
}
}
68 changes: 56 additions & 12 deletions app/src/main/java/com/mikepenz/fastadapter/app/PagedActivity.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package com.mikepenz.fastadapter.app

import android.graphics.Color
import android.os.Bundle
import android.os.Handler
import android.view.Menu
import android.view.MenuItem
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.ViewModelProvider
import androidx.recyclerview.widget.AsyncDifferConfig
Expand All @@ -14,6 +18,10 @@ import com.mikepenz.fastadapter.app.paged.DemoEntity
import com.mikepenz.fastadapter.app.paged.DemoEntityViewModel
import com.mikepenz.fastadapter.paged.PagedModelAdapter
import com.mikepenz.fastadapter.select.getSelectExtension
import com.mikepenz.iconics.IconicsDrawable
import com.mikepenz.iconics.typeface.library.materialdesigniconic.MaterialDesignIconic
import com.mikepenz.iconics.utils.actionBar
import com.mikepenz.iconics.utils.colorInt


class PagedActivity : AppCompatActivity() {
Expand All @@ -25,6 +33,8 @@ class PagedActivity : AppCompatActivity() {
//save our FastAdapter
private lateinit var mItemAdapter: PagedModelAdapter<DemoEntity, SimpleImageItem>

private lateinit var viewModel: DemoEntityViewModel

override fun onCreate(savedInstanceState: Bundle?) {
//create the activity
super.onCreate(savedInstanceState)
Expand All @@ -36,22 +46,27 @@ class PagedActivity : AppCompatActivity() {
setSupportActionBar(binding.toolbar)
supportActionBar?.setTitle(R.string.sample_paged_list)

val asyncDifferConfig = AsyncDifferConfig.Builder<DemoEntity>(object : DiffUtil.ItemCallback<DemoEntity>() {
override fun areItemsTheSame(oldItem: DemoEntity, newItem: DemoEntity): Boolean {
return oldItem.identifier == newItem.identifier
}
val asyncDifferConfig =
AsyncDifferConfig.Builder(object : DiffUtil.ItemCallback<DemoEntity>() {
override fun areItemsTheSame(oldItem: DemoEntity, newItem: DemoEntity): Boolean {
return oldItem.identifier == newItem.identifier
}

override fun areContentsTheSame(oldItem: DemoEntity, newItem: DemoEntity): Boolean {
return oldItem == newItem
}
}).build()
override fun areContentsTheSame(oldItem: DemoEntity, newItem: DemoEntity): Boolean {
return oldItem.data1 == newItem.data1
}
}).build()

//create our ItemAdapter which will host our items
mItemAdapter = PagedModelAdapter<DemoEntity, SimpleImageItem>(asyncDifferConfig, { arg: Int -> SimpleImageItem().setPlaceholder() }) {
SimpleImageItem().withName(it.data1 ?: "").withDescription(it.data2 ?: "").apply {
mItemAdapter = PagedModelAdapter<DemoEntity, SimpleImageItem>(
asyncDifferConfig,
{ SimpleImageItem().setPlaceholder() }) {
SimpleImageItem().apply {
identifier = it.identifier.toLong()
isSelectable = true
withImage("https://raw.githubusercontent.com/mikepenz/earthview-wallpapers/develop/thumb/yang_zhuo_yong_cuo,_tibet-china-63.jpg")
withName(it.data1 ?: "")
withDescription(it.data2 ?: "")
}
}

Expand All @@ -67,14 +82,17 @@ class PagedActivity : AppCompatActivity() {
binding.rv.layoutManager = LinearLayoutManager(this)
binding.rv.adapter = mFastAdapter

val viewModel = ViewModelProvider(this, DemoEntityViewModel.DemoEntityViewModelFactory(this.application))
viewModel = ViewModelProvider(
this,
DemoEntityViewModel.DemoEntityViewModelFactory(this.application)
)
.get(DemoEntityViewModel::class.java)

//listen to data changes and pass it to adapter for displaying in recycler view
viewModel.demoEntitiesList.observe(this, { t -> mItemAdapter.submitList(t!!) })

//if we do this. the first added items will be animated :D
Handler().postDelayed({
Handler(mainLooper).postDelayed({
//restore selections (this has to be done after the items were added
mFastAdapter.withSavedInstanceState(savedInstanceState)
}, 50)
Expand All @@ -92,6 +110,32 @@ class PagedActivity : AppCompatActivity() {
super.onSaveInstanceState(outState)
}

override fun onCreateOptionsMenu(menu: Menu): Boolean {
val inflater = menuInflater
inflater.inflate(R.menu.refresh, menu)
menu.findItem(R.id.item_refresh).icon =
IconicsDrawable(this, MaterialDesignIconic.Icon.gmi_refresh).apply {
colorInt = Color.BLACK; actionBar()
}
return true
}

override fun onOptionsItemSelected(item: MenuItem): Boolean {
//handle the click on the back arrow click
return when (item.itemId) {
android.R.id.home -> {
onBackPressed()
true
}
R.id.item_refresh -> {
viewModel.updateEntities()
Toast.makeText(this, "Refresh DB", Toast.LENGTH_SHORT).show()
true
}
else -> super.onOptionsItemSelected(item)
}
}

override fun onSupportNavigateUp(): Boolean {
onBackPressed()
return true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ import android.os.Bundle
import android.text.TextUtils
import android.view.Menu
import android.view.MenuItem
import android.view.View
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.SearchView
import androidx.recyclerview.widget.DefaultItemAnimator
import androidx.recyclerview.widget.ItemTouchHelper
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.mikepenz.fastadapter.IAdapter
import com.mikepenz.fastadapter.adapters.FastItemAdapter
import com.mikepenz.fastadapter.app.adapters.IDraggableViewHolder
import com.mikepenz.fastadapter.app.databinding.ActivitySampleBinding
Expand All @@ -28,7 +30,8 @@ import com.mikepenz.iconics.utils.colorInt
import io.reactivex.functions.Consumer
import java.util.*

class SwipeDrawerListActivity : AppCompatActivity(), ItemTouchCallback, SimpleSwipeDrawerCallback.ItemSwipeCallback {
class SwipeDrawerListActivity : AppCompatActivity(), ItemTouchCallback,
SimpleSwipeDrawerCallback.ItemSwipeCallback {
private lateinit var binding: ActivitySampleBinding

//save our FastAdapter
Expand Down Expand Up @@ -78,9 +81,20 @@ class SwipeDrawerListActivity : AppCompatActivity(), ItemTouchCallback, SimpleSw
//create our FastAdapter which will manage everything
fastItemDrawerAdapter = FastItemAdapter()
//configure the itemAdapter
fastItemDrawerAdapter.itemFilter.filterPredicate = { item: SwipeableDrawerItem, constraint: CharSequence? ->
item.name?.textString.toString().contains(constraint.toString(), ignoreCase = true)
}
fastItemDrawerAdapter.itemFilter.filterPredicate =
{ item: SwipeableDrawerItem, constraint: CharSequence? ->
item.name?.textString.toString().contains(constraint.toString(), ignoreCase = true)
}


// Item click listener
fastItemDrawerAdapter.onClickListener =
{ _: View?, _: IAdapter<SwipeableDrawerItem>, _: SwipeableDrawerItem, pos: Int ->
run {
println("click! $pos")
true
}
}

//get our recyclerView and do basic setup
binding.rv.layoutManager = LinearLayoutManager(this)
Expand Down Expand Up @@ -110,16 +124,18 @@ class SwipeDrawerListActivity : AppCompatActivity(), ItemTouchCallback, SimpleSw
//add drag and drop for item
//and add swipe as well
touchCallback = SimpleSwipeDrawerDragCallback(
this,
ItemTouchHelper.LEFT,
this)
.withNotifyAllDrops(true)
.withSwipeLeft(80) // Width of delete button
.withSwipeRight(160) // Width of archive and share buttons
.withSensitivity(10f)
.withSurfaceThreshold(0.3f)

touchHelper = ItemTouchHelper(touchCallback) // Create ItemTouchHelper and pass with parameter the SimpleDragCallback
this,
ItemTouchHelper.LEFT,
this
)
.withNotifyAllDrops(true)
.withSwipeLeft(80) // Width of delete button
.withSwipeRight(160) // Width of archive and share buttons
.withSensitivity(10f)
.withSurfaceThreshold(0.3f)

touchHelper =
ItemTouchHelper(touchCallback) // Create ItemTouchHelper and pass with parameter the SimpleDragCallback
touchHelper.attachToRecyclerView(binding.rv) // Attach ItemTouchHelper to RecyclerView

//restore selections (this has to be done after the items were added)
Expand Down Expand Up @@ -155,7 +171,10 @@ class SwipeDrawerListActivity : AppCompatActivity(), ItemTouchCallback, SimpleSw
inflater.inflate(R.menu.search, menu)

//search icon
menu.findItem(R.id.search).icon = IconicsDrawable(this, MaterialDesignIconic.Icon.gmi_search).apply { colorInt = Color.BLACK; actionBar() }
menu.findItem(R.id.search).icon =
IconicsDrawable(this, MaterialDesignIconic.Icon.gmi_search).apply {
colorInt = Color.BLACK; actionBar()
}

val searchView = menu.findItem(R.id.search).actionView as SearchView
searchView.setOnQueryTextListener(object : SearchView.OnQueryTextListener {
Expand All @@ -177,7 +196,11 @@ class SwipeDrawerListActivity : AppCompatActivity(), ItemTouchCallback, SimpleSw
}

override fun itemTouchOnMove(oldPosition: Int, newPosition: Int): Boolean {
DragDropUtil.onMove(fastItemDrawerAdapter.itemAdapter, oldPosition, newPosition) // change position
DragDropUtil.onMove(
fastItemDrawerAdapter.itemAdapter,
oldPosition,
newPosition
) // change position
return true
}

Expand All @@ -196,7 +219,34 @@ class SwipeDrawerListActivity : AppCompatActivity(), ItemTouchCallback, SimpleSw
}

companion object {
private val ALPHABET = arrayOf("A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z")
private val ALPHABET = arrayOf(
"A",
"B",
"C",
"D",
"E",
"F",
"G",
"H",
"I",
"J",
"K",
"L",
"M",
"N",
"O",
"P",
"Q",
"R",
"S",
"T",
"U",
"V",
"W",
"X",
"Y",
"Z"
)
}

override fun itemSwiped(position: Int, direction: Int) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ class SimpleImageItem : BaseItem<SimpleImageItem.ViewHolder>() {
private var mImageUrl: String? = null
private var mName: String? = null
private var mDescription: String? = null
private var isPlaceholder: Boolean = false // True when used as placeholderInterceptor by PagedModelAdapter
private var isPlaceholder: Boolean =
false // True when used as placeholderInterceptor by PagedModelAdapter

/**
* defines the type defining this item. must be unique. preferably an id
Expand Down Expand Up @@ -85,10 +86,18 @@ class SimpleImageItem : BaseItem<SimpleImageItem.ViewHolder>() {
holder.imageView.setImageBitmap(null)

//set the background for the item
val color = ctx.getThemeColor(R.attr.colorPrimary, ContextCompat.getColor(ctx, R.color.colorPrimary))
val color = ctx.getThemeColor(
R.attr.colorPrimary,
ContextCompat.getColor(ctx, R.color.colorPrimary)
)

holder.view.clearAnimation()
holder.view.foreground = FastAdapterUIUtils.getSelectablePressedBackground(ctx, FastAdapterUIUtils.adjustAlpha(color, 100), 50, true)
holder.view.foreground = FastAdapterUIUtils.getSelectablePressedBackground(
ctx,
FastAdapterUIUtils.adjustAlpha(color, 100),
50,
true
)

//load glide
holder.imageView.load(mImageUrl) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ class SwipeableDrawerItem : AbstractItem<SwipeableDrawerItem.ViewHolder>(), ISwi
shareBtn.setOnClickListener {
shareActionRunnable?.run()
}
// Important : trigger the ViewHolder's global onClick event
itemContent.setOnClickListener {
(it.parent as View).performClick()
}
}

override fun onDropped() {
Expand Down
Loading

0 comments on commit 4713bbe

Please sign in to comment.