Skip to content

Instantly share code, notes, and snippets.

View abhimuktheeswarar's full-sized avatar

Abhi Muktheeswarar abhimuktheeswarar

View GitHub Profile
/*
* Copyright (C) 2014 skyfish.jy@gmail.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@abhimuktheeswarar
abhimuktheeswarar / LockableViewPager.java
Last active September 29, 2016 10:05
Viewpager to use with bottom bar navigation
public class LockableViewPager extends ViewPager {
private boolean swipeLocked;
public LockableViewPager(Context context) {
super(context);
}
public LockableViewPager(Context context, AttributeSet attrs) {
super(context, attrs);
@abhimuktheeswarar
abhimuktheeswarar / UserLogin.java
Created September 29, 2016 10:05
Usecase for dynamic queries
/**
* Interactor to login the user using username and password
*/
public class UserLogin extends UseCase {
private final UserRepository userRepository;
private String password;
private String username;
public UserLogin(ThreadExecutor threadExecutor,
@abhimuktheeswarar
abhimuktheeswarar / SquareCardView
Created August 7, 2017 14:46
Create a perfect square cardview
public class SquareCardView extends CardView {
public SquareCardView(Context context) {
super(context);
}
public SquareCardView(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
@abhimuktheeswarar
abhimuktheeswarar / EqualSpacingGridItemDecorator.java
Created June 13, 2018 12:56
RecyclerView's ItemDecorator to achieve equal spacing around the items when using a GridLayoutManager
import android.graphics.Rect;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
public class EqualSpacingGridItemDecorator extends RecyclerView.ItemDecoration {
private final int padding;
public EqualSpacingGridItemDecorator(int padding) {
@abhimuktheeswarar
abhimuktheeswarar / CheckableConstraintLayout.kt
Created June 26, 2020 05:47
A ConstraintLayout that implements Checkable interface
package com.yourcompany.name
import android.content.Context
import android.util.AttributeSet
import android.view.View
import android.widget.Checkable
import androidx.constraintlayout.widget.ConstraintLayout
class CheckableConstraintLayout @JvmOverloads constructor(
context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
@abhimuktheeswarar
abhimuktheeswarar / EqualSpaceItemDecoration.kt
Created June 27, 2020 10:46
This decorator adds equal spacing for items in GridLayoutManager
package com.yourcompany.name
import android.graphics.Rect
import android.view.View
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
class EqualSpaceItemDecoration(private val padding: Int) :
RecyclerView.ItemDecoration() {
@abhimuktheeswarar
abhimuktheeswarar / ConcurrencyHelpers.kt
Created June 8, 2021 18:52 — forked from objcode/ConcurrencyHelpers.kt
Helpers to control concurrency for one shot requests using Kotlin coroutines.
import kotlinx.coroutines.CoroutineStart.LAZY
import kotlinx.coroutines.Deferred
import kotlinx.coroutines.async
import kotlinx.coroutines.cancelAndJoin
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.withLock
import kotlinx.coroutines.yield
import java.util.concurrent.atomic.AtomicReference
import kotlin.DeprecationLevel.ERROR
@abhimuktheeswarar
abhimuktheeswarar / stateMachine.kt
Last active July 17, 2021 13:32
Actor based simple StateMachine
fun <S : State> CoroutineScope.stateMachine(
initialState: S,
inputActionsChannel: ReceiveChannel<Action>,
outputChannel: SendChannel<S>,
publishActions: MutableSharedFlow<Action>,
outputStateFlow: MutableStateFlow<S>,
reduce: (Action, S) -> S,
) = launch {
var state = initialState