Skip to content

Instantly share code, notes, and snippets.


Abhi Muktheeswarar abhimuktheeswarar

View GitHub Profile
abhimuktheeswarar / ViewAnimationsExtensions.kt
Last active Mar 23, 2022
View reveal animation for view visibility
View ViewAnimationsExtensions.kt
import android.view.View
import android.view.ViewTreeObserver
import android.animation.Animator
import android.animation.AnimatorListenerAdapter
import android.animation.ValueAnimator
import android.view.Gravity
import android.view.ViewAnimationUtils
import android.view.ViewGroup
import androidx.core.view.isVisible
abhimuktheeswarar / AndroidManifest.xml
Last active Nov 22, 2021
Logic to support back navigation to parent activity properly when returning from PiP mode
View AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android=""
<dist:fusing dist:include="true" />
abhimuktheeswarar /
Created Nov 22, 2021 — forked from chuangx/
Bring your launcher task to front
public class TaskManager {
* Bring up launcher task to front
public void navToLauncherTask(@Nonnull Context appContext) {
ActivityManager activityManager = (ActivityManager) appContext.getSystemService(Context.ACTIVITY_SERVICE);
// iterate app tasks available and navigate to launcher task (browse task)
final List<ActivityManager.AppTask> appTasks = activityManager.getAppTasks();
for (ActivityManager.AppTask task : appTasks) {
abhimuktheeswarar / DownloadAndOpenPdf.kt
Last active Sep 15, 2021
Code snippet for downloading and opening a PDF file
View DownloadAndOpenPdf.kt
class DownloadAndOpenPdf(
private val applicationContext: Context,
private val okHttpClient: OkHttpClient,
private val scope: CoroutineScope
) {
private val tag = "DownloadAndOpenPdf"
private var inProgress: Boolean = false
private lateinit var file: File
abhimuktheeswarar / customCounterStateMachine.kt
Last active Aug 1, 2021
customCounterStateMachine for blog
View customCounterStateMachine.kt
fun CoroutineScope.customCounterStateMachine(channel : ReceiveChannel<CounterMessage>)
= launch {
var counter = 0 // actor state
channel.consumeEach { message ->
when (message) {
is IncrementCounter -> counter++
is GetCounter -> message.response.complete(counter)
View CounterMessage.kt
sealed interface CounterMessage
object IncrementCounter : CounterMessage
object DecrementCounter : CounterMessage
class GetCounterState(val deferred: CompletableDeferred<CounterState>) : CounterMessage
View CounterViewModel.kt
class CounterViewModel(private val counterStateStore: CounterStateStore) : ViewModel() {
val stateFlow: Flow<CounterState> = counterStateStore.stateFlow
fun dispatch(message: CounterMessage) {
override fun onCleared() {
abhimuktheeswarar / CounterSideEffect.kt
Last active Aug 6, 2021
CounterSideEffect for blog
View CounterSideEffect.kt
class Repository {
suspend fun update(count: Int): Boolean {
TODO("Save to DB")
class CounterSideEffect(
private val repository: Repository,
private val counterStateStore: CounterStateStore,
abhimuktheeswarar / counterStateMachine.kt
Last active Aug 6, 2021
counterStateMachine for blog
View counterStateMachine.kt
fun CoroutineScope.counterStateMachine(
initialState: CounterState,
mutableStateFlow: MutableStateFlow<CounterState>,
mutableMessages: MutableSharedFlow<CounterMessage>,
) =
actor<CounterMessage> {
var state: CounterState = initialState
channel.consumeEach { message ->
when (message) {
is IncrementCounter -> {
View CounterActivity.kt
class CounterActivity : AppCompatActivity() {
private val viewModel by viewModels<CounterViewModel>()
private lateinit var binding: ActivityCounterBinding
override fun onCreate(savedInstanceState: Bundle?) {
binding = ActivityCounterBinding.inflate(layoutInflater)