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
val Fragment.injector | |
get() = (requireActivity().application as DaggerComponentProvider).component |
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
fun ImageView.load(resource: Int) { | |
Picasso.with(context) | |
.load(resource) | |
.into(this) | |
} |
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
@Module | |
object YourModule { | |
@Provides @JvmStatic | |
fun provideThatDependency() = ThatDependency() | |
} |
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
<?xml version="1.0" encoding="utf-8"?> | |
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
android:layout_width="100dp" | |
android:layout_height="100dp"> | |
<TextView | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:autoSizeMaxTextSize="100sp" | |
android:autoSizeMinTextSize="1sp" |
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
override fun onBindViewHolder(holder: DataBindingViewHolder<Listable>, position: Int) { | |
super.onBindViewHolder(holder, position) // make sure you keep this | |
holder.itemView.setOnClickListener { | |
// whatever you want! | |
// you could add a Presenter/ViewModel to the Adapter constructor and call a method, for instance: | |
// viewModel.onItemClicked() | |
} | |
} |
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 DataBindingViewHolder<T>(private val binding: ViewDataBinding) : | |
RecyclerView.ViewHolder(binding.root) { | |
fun bind(item: T) { | |
binding.setVariable(BR.item, item) | |
binding.executePendingBindings() | |
} | |
} |
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 DataBindingAdapter<T>(diffCallback: DiffUtil.ItemCallback<T>) : | |
ListAdapter<T, DataBindingViewHolder<T>>(diffCallback) { | |
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): DataBindingViewHolder<T> { | |
val layoutInflater = LayoutInflater.from(parent.context) | |
val binding = DataBindingUtil.inflate<ViewDataBinding>(layoutInflater, viewType, parent, false) | |
return DataBindingViewHolder(binding) | |
} | |
override fun onBindViewHolder(holder: DataBindingViewHolder<T>, position: Int) = holder.bind(getItem(position)) |
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 BooksAdapter : DataBindingAdapter<Book>(DiffCallback()) { | |
class DiffCallback : DiffUtil.ItemCallback<Book>() { | |
// your DiffCallback implementation | |
} | |
override fun getItemViewType(position: Int) = R.layout.item_book | |
} |
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
<?xml version="1.0" encoding="utf-8"?> | |
<layout xmlns:android="http://schemas.android.com/apk/res/android"> | |
<data> | |
<variable name="item" type="com.example.model.Book" /> | |
</data> | |
<LinearLayout | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" |
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 BooksAdapter : DataBindingAdapter<Listable>(DiffCallback()) { | |
class DiffCallback : DiffUtil.ItemCallback<Listable>() { | |
// your DiffCallback implementation | |
} | |
override fun getItemViewType(position: Int) = if (getItem(position) is Book) { | |
R.layout.item_book | |
} else { | |
R.layout.item_section |