This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.chrisjenx.gradle.deps | |
import org.gradle.jvm.tasks.Jar | |
plugins { | |
`maven-publish` | |
id("com.android.library") | |
kotlin("android") | |
} | |
android { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sealed interface CounterMessage | |
object IncrementCounter : CounterMessage | |
object DecrementCounter : CounterMessage | |
class GetCounterState(val deferred: CompletableDeferred<CounterState>) : CounterMessage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Repository { | |
suspend fun update(count: Int): Boolean { | |
TODO("Save to DB") | |
} | |
} | |
class CounterSideEffect( | |
private val repository: Repository, | |
private val counterStateStore: CounterStateStore, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun CoroutineScope.counterStateMachine( | |
initialState: CounterState, | |
mutableStateFlow: MutableStateFlow<CounterState>, | |
mutableMessages: MutableSharedFlow<CounterMessage>, | |
) = | |
actor<CounterMessage> { | |
var state: CounterState = initialState | |
channel.consumeEach { message -> | |
when (message) { | |
is IncrementCounter -> { |
NewerOlder