Skip to content

Instantly share code, notes, and snippets.

View abhimuktheeswarar's full-sized avatar

Abhi Muktheeswarar abhimuktheeswarar

View GitHub Profile
@abhimuktheeswarar
abhimuktheeswarar / publish.kts
Created October 20, 2022 14:16
Gradle kts publish script to jFrog
import com.chrisjenx.gradle.deps
import org.gradle.jvm.tasks.Jar
plugins {
`maven-publish`
id("com.android.library")
kotlin("android")
}
android {
@abhimuktheeswarar
abhimuktheeswarar / ViewAnimationsExtensions.kt
Last active March 23, 2022 17:58
View reveal animation for view visibility
import android.graphics.Rect
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
abhimuktheeswarar / AndroidManifest.xml
Last active November 22, 2021 10:12
Logic to support back navigation to parent activity properly when returning from PiP mode
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:dist="http://schemas.android.com/apk/distribution"
xmlns:tools="http://schemas.android.com/tools"
package="com.app.yourapp">
<dist:module
dist:instant="false"
dist:title="@string/feature_title">
<dist:fusing dist:include="true" />
@abhimuktheeswarar
abhimuktheeswarar / TaskManager.java
Created November 22, 2021 09:04 — forked from chuangx/TaskManager.java
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
abhimuktheeswarar / DownloadAndOpenPdf.kt
Last active September 15, 2021 09:57
Code snippet for downloading and opening a PDF file
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
abhimuktheeswarar / customCounterStateMachine.kt
Last active August 1, 2021 11:22
customCounterStateMachine for blog
fun CoroutineScope.customCounterStateMachine(channel : ReceiveChannel<CounterMessage>)
= launch {
var counter = 0 // actor state
channel.consumeEach { message ->
ensureActive()
when (message) {
is IncrementCounter -> counter++
is GetCounter -> message.response.complete(counter)
}
}
@abhimuktheeswarar
abhimuktheeswarar / CounterMessage.kt
Created August 1, 2021 10:20
CounterMessage for blog
sealed interface CounterMessage
object IncrementCounter : CounterMessage
object DecrementCounter : CounterMessage
class GetCounterState(val deferred: CompletableDeferred<CounterState>) : CounterMessage
@abhimuktheeswarar
abhimuktheeswarar / CounterViewModel.kt
Created August 1, 2021 10:13
CounterViewModel for blog
class CounterViewModel(private val counterStateStore: CounterStateStore) : ViewModel() {
val stateFlow: Flow<CounterState> = counterStateStore.stateFlow
fun dispatch(message: CounterMessage) {
counterStateStore.dispatch(message)
}
override fun onCleared() {
super.onCleared()
@abhimuktheeswarar
abhimuktheeswarar / CounterSideEffect.kt
Last active August 6, 2021 06:17
CounterSideEffect for blog
class Repository {
suspend fun update(count: Int): Boolean {
TODO("Save to DB")
}
}
class CounterSideEffect(
private val repository: Repository,
private val counterStateStore: CounterStateStore,
@abhimuktheeswarar
abhimuktheeswarar / counterStateMachine.kt
Last active August 6, 2021 06:15
counterStateMachine for blog
fun CoroutineScope.counterStateMachine(
initialState: CounterState,
mutableStateFlow: MutableStateFlow<CounterState>,
mutableMessages: MutableSharedFlow<CounterMessage>,
) =
actor<CounterMessage> {
var state: CounterState = initialState
channel.consumeEach { message ->
when (message) {
is IncrementCounter -> {