This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 -> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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" /> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<resources> | |
<dimen name="item_fixed_width">70dp</dimen> | |
</resources> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 "" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var text: Editable = "".toEditable() | |
set(value) { | |
field = value | |
renderCode() // let's keep this for later | |
} | |
... | |
override fun onAttachedToWindow() { | |
super.onAttachedToWindow() | |
... |
NewerOlder