• Stars
    star
    113
  • Rank 308,304 (Top 7 %)
  • Language
    Java
  • License
    Apache License 2.0
  • Created almost 9 years ago
  • Updated almost 9 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Sample app that shows how the new permissions model introduced in Android 6.0 works, and how we can implement it and educate our users on a nice way (following clean architecture, using architectural patterns, etc.)

PermissionsSample

Sample app that shows how the new permissions model introduced in Android 6.0 works, and how we can implement it and educate our users on a nice way (following clean architecture, using architectural patterns, etc.)

Requirements

To use properly this app we first we have to create some contacts in our device/emulator, adding a name, a phone number and an image would be perfect so we can try all the stuff the app does. If you are running this app in a device and you already have contacts, then you don't have to do anything else, just run it.

Do you want to see first what this app does?

Sure! here you have some screenshots that show how the app requests permissions for 1st and 2nd (or N time), and how it educates users showing the rationale info panel and a snackbar when the permission has been denied "forever".

Permission request 1st time Permission request 2nd time Showing rationale Showing snackbar-permission denied

And here you can watch a small video.

Architecture of the sample app

This app has been implemented based in the teachings of Clean Architecture by Uncle Bob. I would like to remark that is based, so is not strictly following it, since at the end, we are software developers who have to take these teachings and adjust them to our requirements, preferences, tastes, etc.

For an amazing and better example of Clean architecture on Android, or better said, the Clean approach followed by its author, check this amazing post of my friend Fernando Cejas.

The app is divided in three modules, to make easier the decoupling between the different parts of the app.

  • App (presentation): Is basically the UI, it has Android dependencies. Is built following the MVP pattern, so the views (Activity and Fragment) delegates (invokes) their presenters to deal with what the user tries to do.
  • Domain: is where the user cases are, the presenter will use the use cases that are here to get what it wants. Is a simple Java module without Android dependencies.
  • Action: Since this app sample is highly coupled to the Android framework, this module (an Android one) implements and declares actions that exposes outside. In this case with some of the actions that don't require a transformation model, that are just actions that even we couldn't return a result, the actions are used directly by the app.

How the new permissions model is implemented?

Since the main purpose of this app is just to play with the new Android permissions model and show how to educate users I will cover here how this is implemented.

First, in the App module (the presentation layer) we have the MainActivity that has a PermissionAction instance that is given by a Factory. This factory can implements and returns one of the two different PermissionAction implementations:

This implementation of the PermissionAction it will be injected to the PermissionPresenter that will take care of interacting with the implementation in a transparent way for the View.

Here we would use a dependency injector like Dagger or a Service Locator, but I decided not to use it since this app is to teach about other stuff (adding the separation of concerns just has added enough difficult to a simple implementation). On next iterations of this sample app, I would use a depenency injector like Dagger2.

In the PermissionPresenter we also have passed to its constructor a PermissionCallbacks that the MainActivity is implementing; this callback will be used by the PermissionPresenter to inform the View the process has been finished.

Testing

Testing the permissions functionality here is really easy. Since the PermissionPresenter's dependencies have been injected, we can mock both for being able to change their behaviour at glance, and checking the PermissionCallbacks methods wether they were called or not when some action was done.

You can check PermissionPresenterTest to see how is implemented.

UI

As we have seen here, the MainActivity actor is the one that is going to access and to interact with the permissions stuff, its fragments will just ask him to do some actions, but the fragments don't know anything about permissions, they are completely agnostic about that.

Then it makes perfectly sense that is the MainActivity the one that has the UI stuff of permissions. Its layout has a CoordinatorLayout, used to make possible the dismiss action of the snackbar, and a ViewStub, that it will be used to inflate in runtime the View we want to use, to educate our users when the permission is already asked (It's called rationale).

Slides

The slides of this sample app can be found in SpeackerDeck here.

Links and acknowledgements

I don't want to finish without linking to the awesome developers that have helped me a lot during the creation of this sample app. Their amazing posts and source code repos are a must that any developer should have a look.

New permissions model on Android:

Architecture:

And I would like to thank as well to Fine Cinnamon (OJTHandler) for all the knowledge and good people that can be found there (and funny times too).

Contributors

One last thing...

This is an open source sample app released under Apache License v2, so it means that you can grab the code an use it in your open source projects that use compatible licenses with Apache, but also in your privatives ones.

This license requires attribution, so if you are going to use the code, respect the attribution, respect the class headers that mention the license terms and author name, and if you are going to release your app (that uses this code) to the world (the binary, the apk) then create a section in your app where you mention all the libraries your app uses including author name, code license and code source link.

And that's all, hope this approach on managing the new android permissions model helps you! Thanks :-)

More Repositories

1

KUnidirectional

The goal of this sample app is to show how we can implement unidirectional data flow architecture based on Flux and Redux on Android... using Kotlin 😉
Kotlin
313
star
2

tldrlegal

TLDRLegal unofficial (community-made) app. Discover and learn what FLOSS licenses provide to you and to the community
Java
7
star
3

quitesleep

Automatically exported from code.google.com/p/quitesleep
Java
7
star
4

GeofencesDemo

Demo used in the 1st Berlin Android Meetup to show a demostration of geofencing in Android
Java
6
star
5

dcberlin21-workshop

Learn how to make an app designed for single-screen devices shine when running on foldable and dual-screen devices
Kotlin
4
star
6

GeofencesDemoBaseProject

This project must be used together the project GeofencesDemo, this is just the structure of the project, but it needs the main functions that are located in GeofencesDemo
Java
4
star
7

SlidingPaneLayoutSample

Sample using SlidingPaneLayout component
Kotlin
3
star
8

checkyouritems

CheckYourItems is a project of Comunes Collective to allow the user to know about the orogin of the products which can buy in any shop, or wathever product you want to know about it.
Java
3
star
9

dual-screen-training-surface-duo-frame-layout-sample

This is a small sample app that shows how to use the SurfaceDuoFrameLayout easily in your app. SurfaceDuoFrameLayout provides an easy way to move the children views of this layout to the start and end screen, and using the whole width of both screens when an app is spanned.
Kotlin
3
star
10

preferences-foldable

This is a sample to showcase how the latest updates on androidx.preference, that target foldable, dual-screen and large-screen devices, work.
Kotlin
2
star
11

qualifiers-bazel-sample

This is a sample app that shows the usage of resource qualifiers + using Bazel to build and deploy
Starlark
2
star
12

SonySmartWatch2Hackathon

Project created to be used as main project during the Sony SmartWatch2 Hackathon in Berlin (Spetember'13)
Java
2
star
13

list-detail-variant

This repo contains a variant of the list-detail dual screen pattern implementation where the detail view is still shown when we are back from spanned mode and we also show a back (up) action on the toolbar.
Kotlin
2
star
14

cesarvaliente.github.io

CSS
1
star
15

foldables-codelab

Different samples used to show how we can take advantage of what foldable devices bring
Kotlin
1
star
16

try_git

1
star
17

navigation-foldable

This is a sample that shows how the latest updates on androidx.navigation, that target foldables, dual-screen and large-screen devices, work.
Kotlin
1
star
18

AndroidWearWorkshopExamples

Code with diverse examples about Android Wear used in the Workshop given at Romobos conference (Cluj Napoca, Romania, November 2014)
Java
1
star
19

YourLifeAlbum

Repository created to participate in the Photo Hack Day 2013 in Berlin
Java
1
star
20

dual-screen-training-list-detail-app

Simple app that follows and implements the list-detail dual-screen pattern.
Kotlin
1
star
21

dual-screen-training-bottom-navigation-sample

This is a small sample app that shows how to use the SurfaceDuoBottomNavigationView easily in your app. SurfaceDuoBottomNavigationView provides an easy way to move your bottom navigation menu to start and/or end screens and using the whole width of both screens when an app is spanned.
Kotlin
1
star
22

NavigationRail-WM-Sample

This is a sample that shows the power of using NavigationRail, BottomNavigation, latest Navigation component and WindowManager altogether, so depending on the device form factor used (single screen or foldable/dual-screen), a specific UI navigation will be shown to the user, taking advantage of the extra-room that these new devices provide.
Kotlin
1
star
23

dual-screen-training-tab-layout-sample

This is a small sample app that shows how to use the SrufaceDuoTabLayout easily in your app. SurfaceDuoTabLayout provides an easy way to move your tabs to start, end and using the whole width of both screens when an app is spanned.
Kotlin
1
star
24

dual-screen-training-window-manager-sample

This is a small sample app that uses WindowManager and that shows the information that provides so we can see how it changes according with the device posture, when the app is spanned/unspaned, when the orientation changes, etc.
Kotlin
1
star