Skip to content

Instantly share code, notes, and snippets.

Svetlozar Kostadinov sevar83

Block or report user

Report or block sevar83

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@sevar83
sevar83 / PaddingTransition.kt
Created Nov 24, 2017
Non-stretching Glide placeholder
View PaddingTransition.kt
import android.graphics.drawable.Drawable
import com.bumptech.glide.request.transition.Transition
class PaddingTransition<T : Drawable>(private val realTransition: Transition<in T>) : Transition<T> {
override fun transition(current: T, adapter: Transition.ViewAdapter): Boolean {
val width = current.intrinsicWidth
val height = current.intrinsicHeight
return realTransition.transition(current, PaddingViewAdapter(adapter, width, height))
}
@sevar83
sevar83 / ControllerLifecycle.kt
Last active Aug 30, 2019
Conductor / Glide lifecycle integration
View ControllerLifecycle.kt
import com.bumptech.glide.manager.Lifecycle
import com.bumptech.glide.manager.LifecycleListener
import com.bumptech.glide.util.Util
import java.util.*
/**
* A [com.bumptech.glide.manager.Lifecycle] implementation for tracking and notifying
* listeners of [com.bluelinelabs.conductor.Controller] lifecycle events.
*/
class ControllerLifecycle : Lifecycle {
@sevar83
sevar83 / ParcelSortedMapAdapter.kt
Created Feb 21, 2017
PaperParcel SortedSet and SortedMap adapters
View ParcelSortedMapAdapter.kt
class ParcelSortedMapAdapter<K, V>(
private val keyAdapter: TypeAdapter<K>,
private val valueAdapter: TypeAdapter<V>
) : TypeAdapter<@JvmSuppressWildcards SortedMap<K, V>> {
override fun readFromParcel(source: Parcel): SortedMap<K, V> {
val size = source.readInt()
val map = TreeMap<K, V>()
for (ignored in 1..size) {
val key = keyAdapter.readFromParcel(source)
@sevar83
sevar83 / HorizontalPaddingItemDecoration.kt
Created Feb 20, 2017
Adds start/end padding to first/last item of a horizontal RecyclerView (like Play Store app)
View HorizontalPaddingItemDecoration.kt
class HorizontalPaddingItemDecoration(
private val paddingStart: Int = 0,
private val paddingEnd: Int = 0
) : RecyclerView.ItemDecoration() {
private var isRtl: Boolean? = null
fun isRTL(ctx: Context): Boolean {
val config = ctx.resources.configuration
return config.layoutDirection == View.LAYOUT_DIRECTION_RTL
@sevar83
sevar83 / LMBindingAdapter.java
Created Sep 3, 2016
Binding adapter for https://github.com/evant/binding-collection-adapter which assigns common parameters to a List/Grid RecyclerView. Automatically restores the state of the old LayoutManager into the new one.
View LMBindingAdapter.java
public class LMBindingAdapter {
// TODO the creation and modification of a layout manager must be done in one class. The creation is in a factory, but the modification is here.
@BindingAdapter(value = {"viewMode", "orientation", "reverseLayout", "spanCount", "spanSizeLookup"}, requireAll = false)
public static void setLayoutManager(RecyclerView recyclerView,
RecyclerViewMode viewMode,
@LayoutManagers.Orientation int orientation,
boolean reverseLayout,
int spanCount,
final SpanSizeLookup spanSizeLookup) {
if (viewMode == null) {
@sevar83
sevar83 / VarColumnGridLayoutManager
Last active Mar 2, 2016
GridLayoutManager with variable number of columns calculated based on the measured view width
View VarColumnGridLayoutManager
final VarColumnGridLayoutManager layoutManager
= new VarColumnGridLayoutManager(getContext(), OrientationHelper.VERTICAL, false);
VarColumnGridLayoutManager.ColumnCountProvider columnProvider
= new VarColumnGridLayoutManager.DefaultColumnCountProvider(getContext());
layoutManager.setColumnCountProvider(columnProvider);
mRecyclerView.setLayoutManager(layoutManager);
@sevar83
sevar83 / ListLayout.java
Created Jan 29, 2016
ListLayout - a LinearLayout getting its items from Adapter. Very simple alternative of RecyclerView when a nested list is needed. It wraps its content with just setting wrap_content as height easily in constrast of RecyclerView.
View ListLayout.java
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import android.content.Context;
import android.database.DataSetObserver;
import android.util.AttributeSet;
import android.view.View;
import android.widget.Adapter;
import android.widget.LinearLayout;
You can’t perform that action at this time.