Skip to content

Instantly share code, notes, and snippets.

@tfcporciuncula
tfcporciuncula / PdfAdapter.kt
Last active March 19, 2024 11:50
PDF rendering the easy way
class PdfAdapter(
// this would come from the ViewModel so we don't need to recreate it on config change
// and the VM can close it within onCleared()
private val renderer: PdfRenderer,
// this would come from the Activity/Fragment based on the display metrics
private val pageWidth: Int
) : RecyclerView.Adapter<PdfAdapter.ViewHolder>() {
class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
@manuelvicnt
manuelvicnt / AnAndroidApp.kt
Last active January 1, 2023 17:05
Hilt and AssistedInject working together in Hilt v2.28-alpha times - ViewModel version
// IMPORTANT! READ THIS FIRST
// Assisted Injection doesn't work with @HiltViewModel or @ViewModelInject
// Read more about the issue here: https://github.com/google/dagger/issues/2287
//
//
// AssistedInject and Hilt working together in v2.28-alpha times
// Example of a ViewModel using AssistedInject injected in a Fragment by Hilt
// As AssistedInject isn't part of Dagger yet, we cannot use in
// conjuction with @ViewModelInject
@filipkowicz
filipkowicz / HeaderItemDecoration.kt
Last active April 19, 2024 15:37
Item Decorator for sticky headers in Kotlin
package com.filipkowicz.headeritemdecorator
/*
solution based on - based on Sevastyan answer on StackOverflow
changes:
- take to account views offsets
- transformed to Kotlin
- now works on viewHolders
@parthdave93
parthdave93 / BindingAdapter.java
Created May 11, 2017 04:59
Date Picker Using Databinding
@BindingAdapter(value = {"bind:datePick", "bind:maxDate", "bind:minDate"}, requireAll = false)
public static void bindTextViewDateClicks(final TextView textView, final ObservableField<Date> date, final ObservableField<Date> maxDate, final ObservableField<Date> minDate) {
textView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
selectDate(textView.getContext(), date, maxDate, minDate);
}
});
}