Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
lutsenko-yuriy committed Mar 4, 2018
1 parent 14cda13 commit 2b86daa
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 26 deletions.
2 changes: 1 addition & 1 deletion app-kotlin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ android {


defaultConfig {
applicationId "com.yurich.app_kotlin"
applicationId "com.gun0912.app_kotlin"
minSdkVersion 14
targetSdkVersion 27
versionCode 1
Expand Down
3 changes: 2 additions & 1 deletion app-kotlin/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.yurich.app_kotlin">
package="com.gun0912.app_kotlin">

<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CAMERA" />

<application
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.yurich.app_kotlin
package com.gun0912.app_kotlin

import android.Manifest
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.widget.Toast
import com.yurich.tedpermission_kotlin_dsl.dsl.checkPermissions
import com.gun0912.tedpermission_kotlin_dsl.dsl.checkPermissions
import kotlinx.android.synthetic.main.activity_main.*

class MainActivity : AppCompatActivity() {
Expand All @@ -14,9 +14,11 @@ class MainActivity : AppCompatActivity() {
setContentView(R.layout.activity_main)

checkPermissions {

+Manifest.permission.CAMERA
+Manifest.permission.READ_CONTACTS
+listOf(Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION)
+Manifest.permission.ACCESS_COARSE_LOCATION

+listOf(Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.READ_CONTACTS, Manifest.permission.WRITE_EXTERNAL_STORAGE)

withPermissionListener {

Expand All @@ -40,7 +42,7 @@ class MainActivity : AppCompatActivity() {
message("If you reject permission,you can not use this service\n\nPlease turn on permissions at [Setting] > [Permission]")
}

inSettings {
onProceedingToSettings {
closeButtonText("Go to settings")
}

Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Mon Dec 28 10:00:20 PST 2015
#Mon Mar 05 01:18:53 MSK 2018
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
3 changes: 1 addition & 2 deletions tedpermission-kotlin-dsl/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.yurich.tedpermission_kotlin_dsl" />
<manifest package="com.gun0912.tedpermission_kotlin_dsl" />
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@file:JvmName("CheckPermissions")

package com.yurich.tedpermission_kotlin_dsl.dsl
package com.gun0912.tedpermission_kotlin_dsl.dsl

import android.content.Context

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.yurich.tedpermission_kotlin_dsl.dsl
package com.gun0912.tedpermission_kotlin_dsl.dsl

import android.content.Context
import android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
import android.support.annotation.StringRes
import com.gun0912.tedpermission.PermissionBuilder
import com.gun0912.tedpermission.TedPermission
import com.yurich.tedpermission_kotlin_dsl.listener.PermissionListenerBuilder
import com.gun0912.tedpermission_kotlin_dsl.listener.PermissionListenerBuilder

class Dsl(context: Context) {

Expand Down Expand Up @@ -39,7 +39,7 @@ class Dsl(context: Context) {
Rationale().apply(body)
}

fun inSettings(body: GoToSettings.() -> Unit) {
fun onProceedingToSettings(body: GoToSettings.() -> Unit) {
tedPermission.setGotoSettingButton(true)
GoToSettings().apply(body)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
@file:Suppress("PackageName")

package com.yurich.tedpermission_kotlin_dsl.listener
package com.gun0912.tedpermission_kotlin_dsl.listener

import com.gun0912.tedpermission.PermissionListener

class PermissionListenerBuilder {

private var onPermissionGrantedListener: () -> Unit = {}

private var onPermissionDeniedListener: (ArrayList<String>?) -> Unit = {}
private var onPermissionDeniedListener: (List<String>?) -> Unit = {}

fun onPermissionGranted(body: () -> Unit): PermissionListenerBuilder {
this.onPermissionGrantedListener = body
return this
}

fun onPermissionDenied(body: (ArrayList<String>?) -> Unit): PermissionListenerBuilder {
fun onPermissionDenied(body: (List<String>?) -> Unit): PermissionListenerBuilder {
this.onPermissionDeniedListener = body
return this
}
Expand All @@ -26,7 +26,7 @@ class PermissionListenerBuilder {
onPermissionGrantedListener()
}

override fun onPermissionDenied(deniedPermissions: ArrayList<String>?) {
override fun onPermissionDenied(deniedPermissions: ArrayList<String>) {
onPermissionDeniedListener(deniedPermissions)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,15 @@ public abstract class PermissionBuilder<T extends PermissionBuilder> {
private static final String PREFS_IS_FIRST_REQUEST = "PREFS_IS_FIRST_REQUEST";

private PermissionListener listener;

private final List<String> permissions = new ArrayList<>();

private CharSequence rationaleTitle;
private CharSequence rationaleMessage;

private CharSequence denyTitle;
private CharSequence denyMessage;

private CharSequence settingButtonText;

private boolean hasSettingBtn = true;
Expand Down Expand Up @@ -106,13 +109,6 @@ public T addPermissions(List<String> permissions) {
return (T) this;
}

public T addPermissions(String[] permissions) {
if (permissions != null) {
this.permissions.addAll(Arrays.asList(permissions));
}
return (T) this;
}

public T addSinglePermission(String permission) {
this.permissions.add(permission);
return (T) this;
Expand Down

0 comments on commit 2b86daa

Please sign in to comment.