Skip to content

Commit

Permalink
Merge pull request #25 from mintrocket/release/1.1.0
Browse files Browse the repository at this point in the history
Release/1.1.0
  • Loading branch information
RadiationX authored Aug 9, 2022
2 parents dcd16ff + 21e199d commit f84cb76
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 2 deletions.
82 changes: 81 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ This library, using [Kotlin Coroutines](https://kotlinlang.org/docs/coroutines-g
- No additional activities
- Request queue - everything will be ok, even if you make several requests from different CoroutineScope at the same time

#### mintpermissions-flows
Library for processing permission states using dialogs in accordance with [Google recommendations](https://developer.android.com/training/permissions/requesting)
- Also, all the advantages of mintpermissions
- Easy to customize behavior and display with FlowConfig
- DialogsFlow for those cases when there is simply some kind of button on which an action must occur that requires permission
- PlainFlow for those cases when there is some kind of full screen content (for example, creating youtube shorts) and you need to display the permission status right inside the screen. Internally, DialogFlow is used with special settings

## Setup

```gradle
Expand All @@ -25,7 +32,10 @@ allprojects {
// Target module's build.gradle:
dependencies {
implementation "com.github.mintrocket:MintPermissions:1.0.0"
implementation 'com.github.mintrocket.MintPermissions:mintpermissions:1.1.0'
// if you need ready processing of permissions with dialogs
implementation 'com.github.mintrocket.MintPermissions:mintpermissions-flows:1.1.0'
}
```

Expand All @@ -48,6 +58,9 @@ class App : Application() {
override fun onCreate() {
super.onCreate()
initMintPermissions()

// if you used "mintpermissions-flows"
initMintPermissionsFlow()
}
}
```
Expand All @@ -59,13 +72,19 @@ class App : Application() {
override fun onCreate() {
super.onCreate()
initMintPermissions(MintPermissionsConfig(autoInitManagers = false))

// if you used "mintpermissions-flows"
initMintPermissions(MintPermissionsConfig(autoInitManagers = false))
}
}

class MainActivity : AppCompatActivity(R.layout.activity_main) {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
initMintPermissionsManager()

// if you used "mintpermissions-flows"
initMintPermissionsFlowManager()
}
}
```
Expand All @@ -81,6 +100,8 @@ val libraryModule = module {

### Request example

#### Request for self-processing

```kotlin
class SampleViewModel(
private val permissionsController: MintPermissionsController
Expand Down Expand Up @@ -110,6 +131,65 @@ class SampleViewModel(
}
```

#### MintPermissionsDialogFlow sample with dialogs

```kotlin
class SampleViewModel(
private val permissionsDialogFlow: MintPermissionsDialogFlow
) : ViewModel() {

companion object {
private val cameraPermissions = listOf(
Manifest.permission.CAMERA,
Manifest.permission.RECORD_AUDIO,
)
}

fun onActionClick() {
viewModelScope.launch {
val result = permissionsDialogFlow.request(cameraPermissions)
if (result.isSuccess()) {
// handle all permissions granted
} else {
// handle any permission not granted or dialog canceled
}
}
}
}
```

#### MintPermissionsPlainFlow sample with dialogs

Useful for cases where the status of permissions needs to be displayed on the screen itself

```kotlin
class SampleViewModel : ViewModel() {

companion object {
private val cameraPermissions = listOf(
Manifest.permission.CAMERA,
Manifest.permission.RECORD_AUDIO,
)
}

private val permissionsPlainFlow = MintPermissionsFlow.createPlainFlow(cameraPermissions)

// Use for update screen
val notGrantedFlow: Flow<List<MintPermissionStatus>> = permissionsPlainFlow.observeNotGranted()

fun onActionClick() {
viewModelScope.launch {
val result = permissionsPlainFlow.request()
if (result.isSuccess()) {
// handle all permissions granted
} else {
// handle any permission not granted or dialog canceled
}
}
}
}
```

## Additional info

### MintPermissionStatus
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ buildscript {
app_version_code = 1
app_version_name = "1.0"
library_min_sdk_version = 15
library_version_name = "1.0.1"
library_version_name = "1.1.0"

/* tools, plugins, etc. */
kotlin_version = '1.6.21'
Expand Down

0 comments on commit f84cb76

Please sign in to comment.