All Projects → hichamboushaba → SuspendActivityResult

hichamboushaba / SuspendActivityResult

Licence: MIT license
A lightweight library for requesting and consuming Activity Results using coroutines.

Programming Languages

kotlin
9241 projects

Projects that are alternatives of or similar to SuspendActivityResult

pihut-xmas-asyncio
Demonstration driving The Pi Hut Raspberry Pi 3D Xmas tree using Python Asyncio
Stars: ✭ 15 (-78.87%)
Mutual labels:  coroutines
tcl-modules
A collection of pure Tcl, production-ready micro packages
Stars: ✭ 25 (-64.79%)
Mutual labels:  coroutines
Dagger-Hilt-MVVM
Sample app that demonstrates the usage of Dagger Hilt with Kotlin & MVVM
Stars: ✭ 62 (-12.68%)
Mutual labels:  coroutines
AIO
Coroutine-based multithreading library for Delphi
Stars: ✭ 99 (+39.44%)
Mutual labels:  coroutines
Delish
Delish, a Food Recipes App in Jetpack Compose and Hilt based on modern Android tech-stacks and MVI clean architecture.
Stars: ✭ 356 (+401.41%)
Mutual labels:  coroutines
mvvm-coroutines
Android MVVM - Architecture Components with Kotlin Coroutines
Stars: ✭ 60 (-15.49%)
Mutual labels:  coroutines
raffler-kotlin
A raffling app developed as a playground to study many topics related to Android. Kotlin + Coroutines + MVVM
Stars: ✭ 44 (-38.03%)
Mutual labels:  coroutines
NewsPin
News app for android using Kotlin, coroutines, MVP architecture
Stars: ✭ 25 (-64.79%)
Mutual labels:  coroutines
SimpleKotlinMail
A simple, coroutine based Kotlin Email API for both client- and server-side projects
Stars: ✭ 56 (-21.13%)
Mutual labels:  coroutines
kotlin-monads
Monads for Kotlin
Stars: ✭ 114 (+60.56%)
Mutual labels:  coroutines
LuaCSP
Communicating Sequential Processes in Lua
Stars: ✭ 40 (-43.66%)
Mutual labels:  coroutines
kotlin-coroutines-jdbc
A library for interacting with blocking JDBC drivers using Kotlin Coroutines.
Stars: ✭ 40 (-43.66%)
Mutual labels:  coroutines
android
🌦 Vädret
Stars: ✭ 17 (-76.06%)
Mutual labels:  coroutines
pecan
Macro-based coroutines for Haxe
Stars: ✭ 37 (-47.89%)
Mutual labels:  coroutines
CoroutineLite
Simple implementation of kotlinx.coroutines to clarify the design of Kotlin Coroutines.
Stars: ✭ 142 (+100%)
Mutual labels:  coroutines
LinkHub
LinkHub is a simple and effective link management application that can help you to easily manage your app with no ads!
Stars: ✭ 90 (+26.76%)
Mutual labels:  coroutines
NetworkX
🅽🅴🆃🆆🅾🆁🅺🆇 An easy & handy library to monitor device internet connection status.
Stars: ✭ 92 (+29.58%)
Mutual labels:  coroutines
KotlinEverywhere
This application created for Kotlin Everywhere series as a codelab. It will show step by step Kotlin and Android Jetpack Components fundamentals. 🚀🚀
Stars: ✭ 52 (-26.76%)
Mutual labels:  coroutines
StatefulLiveData
StatefulLiveData is a lean, yet powerful tool that harnesses the capabilities of LiveData and enhances them, enabling the observer to distinguish between different states the data can be in, such as Success, Loading and Error.
Stars: ✭ 18 (-74.65%)
Mutual labels:  coroutines
mvvm android
A simple android app written in Kotlin with the MVVM architecture, room database, retrofit and coroutines.
Stars: ✭ 13 (-81.69%)
Mutual labels:  coroutines

Version

SuspendActivityResult

A lightweight library for requesting and consuming Activity Results using coroutines, it's usage is as simple as:

val uri = ActivityResultManager.getInstance().requestResult(
    contract = GetContent(),
    input = "image/*"
)

or using the built-in extensions:

val uri = ActivityResultManager.getInstance().getContent("image/*")

For more information, check the articles: Part 1 and Part 2

Runtime Permissions

The library offers a utility class for requesting runtime permissions with access to the shouldShowRequestPermissionRationale's value:

val result = PermissionManager.getInstance()
    .requestPermission(Manifest.permission.ACCESS_COARSE_LOCATION)
when (result) {
    PermissionGranted -> {
        // TODO
    }
    is PermissionDenied -> {
        if (result.shouldShowRationale) {
            // TODO
        } else {
            // TODO
        }
    }
}

This class uses internally ActivityResultManager.getInstance().requestPermission(), so everything below applies to it as well.

Download

implementation 'dev.hichamboushaba.suspendactivityresult:suspendactivityresult:0.1.5'

The default artifact uses App Startup for the initialization.

If you don't want this dependency added, you can use the other variant:

implementation 'dev.hichamboushaba.suspendactivityresult:suspendactivityresult-no-startup:0.1.5'

And initialize the library manually

class App : Application() {
    fun onCreate() {
        super.onCreate()
        ActivityResultManager.init(this)
    }
}

Testing

ActivityResultManager is an interface, so for better testability, it's recommended to inject ActivityResultManager.getInstance() into your components, for easier swapping to a fake or mocked implementation for tests.

Process-death

The implementation of requestResult takes into account process-death scenarios, and keeps track of the pending operation using the Activity's SavedStateRegistry , which means calling requestResult after a process-death, will not re-launch the activity result caller, and instead, it will only register the callback to allow receiving the result. And to make this work as expected, the application need to keep the screen's state across this process-death, to call requestResult afterwards, check the example app for how we can implement this using SavedStateHandle .

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].