This file contains 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
abstract class NestedRecyclerViewStateRecoverAdapter<T, VH : RecyclerView.ViewHolder>( | |
diffUtil: DiffUtil.ItemCallback<T> | |
) : ListAdapter<T, VH>(diffUtil) { | |
private val layoutManagerStates = hashMapOf<String, Parcelable?>() | |
private val visibleScrollableViews = hashMapOf<Int, ViewHolderRef>() | |
@CallSuper | |
override fun onViewRecycled(holder: VH) { | |
if (holder is NestedRecyclerViewViewHolder) { | |
// Save the scroll position state (LayoutManager state) |
This file contains 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
abstract class NestedRecyclerViewStateRecoverAdapter<T, VH : RecyclerView.ViewHolder>( | |
diffUtil: DiffUtil.ItemCallback<T> | |
) : ListAdapter<T, VH>(diffUtil) { | |
private val layoutManagerStates = hashMapOf<String, Parcelable?>() | |
@CallSuper | |
override fun onViewRecycled(holder: VH) { | |
if (holder is NestedRecyclerViewViewHolder) { | |
// Save the scroll position state (LayoutManager state) | |
val state = holder.getLayoutManager()?.onSaveInstanceState() |
This file contains 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 MyViewModel : ViewModel() { | |
protected val actionSender = BroadcastChannel<Action>(Channel.BUFFERED) | |
val actionReceiver = actionSender.asFlow() | |
} |
This file contains 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 observeActionCommand() { | |
lifecycleScope.launchWhenStarted { | |
viewModel.actionReceiver.collect { | |
// TODO | |
} | |
} | |
} |
This file contains 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 MarginItemDecoration(private val spaceSize: Int) : RecyclerView.ItemDecoration() { | |
override fun getItemOffsets( | |
outRect: Rect, view: View, | |
parent: RecyclerView, | |
state: RecyclerView.State | |
) { | |
with(outRect) { | |
if (parent.getChildAdapterPosition(view) == 0) { | |
top = spaceSize | |
} |
This file contains 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 MarginItemDecoration( | |
private val spaceSize: Int, | |
private val spanCount: Int = 1, | |
private val orientation: Int = GridLayoutManager.VERTICAL | |
) : RecyclerView.ItemDecoration() { | |
override fun getItemOffsets( | |
outRect: Rect, view: View, | |
parent: RecyclerView, state: RecyclerView.State | |
) { | |
with(outRect) { |
This file contains 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
import Foundation | |
private class Localizer { | |
static let sharedInstance = Localizer() | |
lazy var localizableDictionary: NSDictionary! = { | |
if let path = Bundle.main.path(forResource: "Localizable", ofType: "plist") { | |
return NSDictionary(contentsOfFile: path) | |
} |