Skip to content

Instantly share code, notes, and snippets.

View lukelorusso's full-sized avatar
🤖
var droidMood = true

Luke Lorusso lukelorusso

🤖
var droidMood = true
View GitHub Profile
package com.lukelorusso.toomuchofscrolling
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.RecyclerView
import kotlinx.android.synthetic.main.activity_main.*
class MainActivity : AppCompatActivity(R.layout.activity_main) {
companion object {
@lukelorusso
lukelorusso / RecyclerViewExtension.kt
Last active June 14, 2021 16:54
Now it's complete
fun RecyclerView.bindScrollTo(vararg destinations: RecyclerView): RecyclerView.OnScrollListener {
object : RecyclerView.OnScrollListener() {
override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) {
// each time you drag a RecyclerView, you should STOP other destinations' scrolling
if (newState == RecyclerView.SCROLL_STATE_DRAGGING)
destinations.forEach { destinationRecyclerView ->
destinationRecyclerView.stopScroll()
}
// then you can scroll the RecyclerView, dragged or not
super.onScrollStateChanged(recyclerView, newState)
@lukelorusso
lukelorusso / RecyclerViewExtension.kt
Created July 26, 2020 09:17
Second try: somehow, this is not enough...
fun RecyclerView.bindScrollTo(vararg destinations: RecyclerView) {
object : RecyclerView.OnScrollListener() {
override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) {
super.onScrollStateChanged(recyclerView, newState)
}
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
// when you scroll a RecyclerView of some [dx, dy] you can do it
super.onScrolled(recyclerView, dx, dy)
@lukelorusso
lukelorusso / RecyclerViewExtension.kt
Created July 26, 2020 08:40
First try: it didn't work...
fun RecyclerView.bindScrollTo(vararg destinations: RecyclerView) {
object : RecyclerView.OnScrollListener() {
override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) {
super.onScrollStateChanged(recyclerView, newState)
}
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
super.onScrolled(recyclerView, dx, dy)
// First try: it didn't work...
destinations.forEach { destinationRecyclerView ->
class Base10Adapter : RecyclerView.Adapter<Base10Adapter.ViewHolder>() {
var data: List<String> = emptyList()
set(value) {
field = value
notifyDataSetChanged()
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder =
ViewHolder(
LayoutInflater.from(parent.context).inflate(
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/itemBase10TextView"
android:layout_width="@dimen/item_fixed_width"
android:layout_height="wrap_content"
android:background="#E0FCFF"
android:gravity="center"
android:padding="15dp"
tools:text="0" />
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="item_fixed_width">70dp</dimen>
</resources>
<?xml version="1.0" encoding="utf-8"?>
<androidx.core.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"><!-- vertical scrolling purpose -->
<LinearLayout
android:layout_width="match_parent"
@lukelorusso
lukelorusso / CodeEditText.kt
Created August 27, 2019 15:21
renderCode()
private fun renderCode() {
for (i in 0 until llCodeWrapper.childCount) {
val itemContainer = llCodeWrapper.getChildAt(i)
itemContainer.findViewById<TextView>(R.id.tvCode).text =
if (text.length > i)
(if (maskTheCode) codeMaskChar else text[i])
.toString()
else ""
@lukelorusso
lukelorusso / CodeEditText.kt
Last active August 27, 2019 11:14
onAttachedToWindow()
var text: Editable = "".toEditable()
set(value) {
field = value
renderCode() // let's keep this for later
}
...
override fun onAttachedToWindow() {
super.onAttachedToWindow()
...