All Projects → sagar-viradiya → Eazypermissions

sagar-viradiya / Eazypermissions

Licence: apache-2.0
Android library to handle runtime permission through Kotlin coroutines and Livedata.

Programming Languages

kotlin
9241 projects

Projects that are alternatives of or similar to Eazypermissions

Foodium
It simply loads Posts data from API and stores it in persistence storage (i.e. SQLite Database). Posts will be always loaded from local database. Remote data (from API) and Local data is always synchronized.
Stars: ✭ 1,940 (+910.42%)
Mutual labels:  hacktoberfest, coroutines, livedata
Nytimes App
🗽 A Simple Demonstration of the New York Times App 📱 using Jsoup web crawler with MVVM Architecture 🔥
Stars: ✭ 246 (+28.13%)
Mutual labels:  hacktoberfest, coroutines, livedata
Sample Code Movies
This repository contains sample code. Its purpose being, to quickly demonstrate Android and software development in general, clean code, best practices, testing and all those other must know goodies.
Stars: ✭ 81 (-57.81%)
Mutual labels:  coroutines, livedata
Refactored Umbrella
Example of Flow + LiveData w/ Room as single source of truth for data in an MVVM architecture
Stars: ✭ 100 (-47.92%)
Mutual labels:  coroutines, livedata
Covid19 Notifier In
A sample Android App which notifies about COVID19 cases in 🇮🇳India after every 1 hour.
Stars: ✭ 116 (-39.58%)
Mutual labels:  hacktoberfest, coroutines
Wanandroid
Jetpack MVVM For Wanandroid 最佳实践 !
Stars: ✭ 1,004 (+422.92%)
Mutual labels:  coroutines, livedata
Awesome Android Kotlin Apps
👓 A curated list of awesome android kotlin apps by open-source contributors.
Stars: ✭ 1,058 (+451.04%)
Mutual labels:  hacktoberfest, coroutines
Android Mvvm Coroutine
Kotlin android application example with MVVM pattern, android architecture, kotlin coroutine, unit test, and UI test
Stars: ✭ 111 (-42.19%)
Mutual labels:  coroutines, livedata
Jetpack Wanandroid
Kotlin+Jetpack+Coroutines+Retrofit+koin 完成的MVVM 组件化客户端 🔥🔥
Stars: ✭ 353 (+83.85%)
Mutual labels:  coroutines, livedata
Movieapp Clean Architecture
Learning Project (Movie App) For Applying Android Architecture Components And Clean Architecture Using MVVM With Kotlin
Stars: ✭ 123 (-35.94%)
Mutual labels:  coroutines, livedata
Ktarmor Mvvm
👻 Android快速开发框架, KtArmor 寓意着 为Android 赋予战斗装甲, 方便开发者快速进行Android 开发。
Stars: ✭ 148 (-22.92%)
Mutual labels:  coroutines, livedata
Ktx
LibKTX: Kotlin extensions for LibGDX games and applications
Stars: ✭ 913 (+375.52%)
Mutual labels:  hacktoberfest, coroutines
Sirix
SirixDB is a temporal, evolutionary database system, which uses an accumulate only approach. It keeps the full history of each resource. Every commit stores a space-efficient snapshot through structural sharing. It is log-structured and never overwrites data. SirixDB uses a novel page-level versioning approach called sliding snapshot.
Stars: ✭ 638 (+232.29%)
Mutual labels:  hacktoberfest, coroutines
Hal
🔴 A non-deterministic finite-state machine for Android & JVM that won't let you down
Stars: ✭ 63 (-67.19%)
Mutual labels:  coroutines, livedata
Orbit Mvi
An MVI framework for Kotlin and Android
Stars: ✭ 381 (+98.44%)
Mutual labels:  hacktoberfest, coroutines
Powerpermission
Android Permission lib PowerPermission makes handling runtime permissions extremely easy.
Stars: ✭ 103 (-46.35%)
Mutual labels:  coroutines, livedata
Android Clean Arch Coroutines Koin
Implemented by Clean Architecture, MVVM, Koin, Coroutines, Moshi, Mockk, LiveData & DataBinding
Stars: ✭ 173 (-9.9%)
Mutual labels:  coroutines, livedata
Architecturecomponentsdemo
Kotlin demo project that uses some Android Architecture Components (ViewModel and LiveData) with Dagger 2 and Coroutines
Stars: ✭ 269 (+40.1%)
Mutual labels:  coroutines, livedata
Moko Mvvm
Model-View-ViewModel architecture components for mobile (android & ios) Kotlin Multiplatform development
Stars: ✭ 329 (+71.35%)
Mutual labels:  coroutines, livedata
Harrypotter
🧙🏻 Sample HarryPotter application based on MVVM architecture (ViewModel, LiveData, Repository, Coroutines, Koin or Dagger-Hilt)
Stars: ✭ 116 (-39.58%)
Mutual labels:  coroutines, livedata

Eazy Runtime Permission

License Pull request API ktlint Android Arsenal

A lightweight Android library which wraps boilerplate code of runtime permission and allows you to request permissions

  1. from coroutines. (No callbacks yay 🎉)
  2. request and observe permissions through LiveData.
  3. through clean and concise Kotlin DSL.

From release 2.0.0 onwards library is migrated to AndroidX. If you are still using support library and haven't migrated to AndroidX then check out non-androidX version of the library.

Including in your project

Eazy permissions is available in the Jcenter and divided into three modules so that based on your need you can include either coroutines or livedata or Kotlin DSL support in your project

//For coroutines
implementation 'com.sagar:coroutinespermission:[latest_version]'

//For LiveData
implementation 'com.sagar:livedatapermission:[latest_version]'

//For Kotlin DSL
implementation 'com.sagar:dslpermission:[latest_version]'
  • latest_version for coroutines - Download
  • latest_version for livedata - Download
  • latest_version for Kotlin DSL - Download

Coroutines support

This is how you would request permission within coroutines.

.
.
.
launch {
    //CoroutineScope

    val permissionResult = PermissionManager.requestPermissions(           //Suspends the coroutine
                            this@Fragment,                                  
                            REQUEST_ID,
                            Manifest.permission.ACCESS_FINE_LOCATION,
                            Manifest.permission.READ_CONTACTS,
                            Manifest.permission.CAMERA
                        )
                        
    //Resume coroutine once result is ready
    when(permissionResult) {
        is PermissionResult.PermissionGranted -> {
            //Add your logic here after user grants permission(s)
        }
        is PermissionResult.PermissionDenied -> {
            //Add your logic to handle permission denial
        }
        is PermissionResult.PermissionDeniedPermanently -> {
            //Add your logic here if user denied permission(s) permanently.
            //Ideally you should ask user to manually go to settings and enable permission(s)
        }
        is PermissionResult.ShowRational -> {
            //If user denied permission frequently then she/he is not clear about why you are asking this permission.
            //This is your chance to explain them why you need permission.
        }
    }

}

Read more about coroutines support here

Kotlin DSL support

This is how you would request permission through clean and concise Kotlin DSL.

requestPermissions(
    Manifest.permission.ACCESS_FINE_LOCATION,
    Manifest.permission.READ_CONTACTS,
    Manifest.permission.CAMERA
) {
    requestCode = 4
    resultCallback = {
        when(this) {
            is PermissionResult.PermissionGranted -> {
                //Add your logic here after user grants permission(s)
            }
            is PermissionResult.PermissionDenied -> {
                //Add your logic to handle permission denial
            }
            is PermissionResult.PermissionDeniedPermanently -> {
                //Add your logic here if user denied permission(s) permanently.
                //Ideally you should ask user to manually go to settings and enable permission(s)
            }
            is PermissionResult.ShowRational -> {
                //If user denied permission frequently then she/he is not clear about why you are asking this permission.
                //This is your chance to explain them why you need permission.
            }
        }
    }
}

Read more about Kotlin DSL support here

LiveData support

This is how you would request permission within Acivity/Fragment.

PermissionManager.requestPermissions(
                this,
                REQUEST_ID,
                Manifest.permission.ACCESS_FINE_LOCATION,
                Manifest.permission.READ_CONTACTS
            )

Observing permission result requires your Actvity/Fragment to implement PermissionObserver

/**
 * Interface definition for a callback to get [LiveData] of [PermissionResult]
 *
 * Implement this interface to get [LiveData] for observing permission request result.
 */
interface PermissionObserver {
    fun setupObserver(permissionResultLiveData: LiveData<PermissionResult>)
}

Just as you would observe other LiveData you can observe LiveData<PermissionResult> as follow.

override fun setupObserver(permissionResultLiveData: LiveData<PermissionResult>) {
    permissionResultLiveData.observe(this, Observer<PermissionResult> {
        when (it) {
            is PermissionResult.PermissionGranted -> {
                if (it.requestId == REQUEST_ID) {
                    //Add your logic here after user grants permission(s)
                }
            }
            is PermissionResult.PermissionDenied -> {
                if (it.requestId == REQUEST_ID) {
                    //Add your logic to handle permission denial
                }
            }
            is PermissionResult.PermissionDeniedPermanently -> {
                if (it.requestId == REQUEST_ID) {
                    //Add your logic here if user denied permission(s) permanently.
                    //Ideally you should ask user to manually go to settings and enable permission(s)
                }
            }
            is PermissionResult.ShowRational -> {
                if (it.requestId == REQUEST_ID) {
                    //If user denied permission frequently then she/he is not clear about why you are asking this permission.
                    //This is your chance to explain them why you need permission.
                }
            }
        }
    })
}

Read more about LiveData support here

Contributing

Have suggestions for improvements and want to contribute? or Found any issues?
Head over to Contribution guidelines to know more about contributing to this library.

Screenshots of sample

sc1 sc2
sc1 sc2

License

Copyright 2019 Sagar Viradiya

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
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
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].