Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kotlin DSL #81

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app-kotlin/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
32 changes: 32 additions & 0 deletions app-kotlin/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion versions.compileSdkVersion
buildToolsVersion versions.buildToolsVersion


defaultConfig {
applicationId "com.gun0912.app_kotlin"
minSdkVersion versions.minSdkVersion
targetSdkVersion versions.targetSdkVersion
versionCode 1
versionName "1.0"

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}

}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(':tedpermission-kotlin-dsl')
}
21 changes: 21 additions & 0 deletions app-kotlin/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
35 changes: 35 additions & 0 deletions app-kotlin/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
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.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

<uses-permission android:name="android.permission.CAMERA" />

<!-- It is supposed to be a demo. It is not supposed to be indexed by Google Play -->
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme"
android:fullBackupContent="true"
tools:ignore="GoogleAppIndexingWarning">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>
127 changes: 127 additions & 0 deletions app-kotlin/src/main/java/com/gun0912/app_kotlin/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
package com.gun0912.app_kotlin

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

class MainActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)

requestPermissionsForCamera()

if (Build.VERSION.SDK_INT >= 16) {
requestPermissionsForStorage()
} else {
requestPermissionsForStorageOnPreJellyBean()
}

requestLocationPermission()

checkPermissions {

+Manifest.permission.READ_CONTACTS

withPermissionListener {

onPermissionGranted {
Toast.makeText(this@MainActivity, "Permissions are granted", Toast.LENGTH_SHORT).show()
}

onPermissionDenied {
denied_permissions.text = it?.joinToString(", ")
}

}

rationale {
title(R.string.rationale_title)
message(R.string.rationale_message)
}

onDeny {
title { "Permission denied" }
message {
"If you reject permission,you can not use this service\n\nPlease turn on permissions at [Setting] > [Permission]"
}
}

onProceedingToSettings {
closeButtonText(R.string.custom_close_text)
}

}
}

private fun requestLocationPermission() {
checkPermissions(Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.ACCESS_FINE_LOCATION) {
withPermissionListener {

onPermissionGranted {
Toast.makeText(this@MainActivity, "Permission for locations is granted", Toast.LENGTH_SHORT).show()
}

onPermissionDenied {
denied_permissions.text = it?.joinToString(", ")
}

}
}
}

@TargetApi(16)
private fun requestPermissionsForStorage() {
checkPermissions(Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE) {
withPermissionListener {

onPermissionGranted {
Toast.makeText(this@MainActivity, "Permission for storage is granted", Toast.LENGTH_SHORT).show()
}

onPermissionDenied {
denied_permissions.text = it?.joinToString(", ")
}

}
}
}

private fun requestPermissionsForStorageOnPreJellyBean() {
checkPermissions(Manifest.permission.WRITE_EXTERNAL_STORAGE) {
withPermissionListener {

onPermissionGranted {
Toast.makeText(this@MainActivity, "Permission for storage on Pre-JellyBean is granted", Toast.LENGTH_SHORT).show()
}

onPermissionDenied {
denied_permissions.text = it?.joinToString(", ")
}

}
}
}

private fun requestPermissionsForCamera() {
checkPermissions(Manifest.permission.CAMERA) {
withPermissionListener {

onPermissionGranted {
Toast.makeText(this@MainActivity, "Permission for camera is granted", Toast.LENGTH_SHORT).show()
}

onPermissionDenied {
denied_permissions.text = it?.joinToString(", ")
}

}
}
}
}
17 changes: 17 additions & 0 deletions app-kotlin/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<TextView
android:id="@+id/denied_permissions"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:padding="16dp"
android:textSize="16sp"
android:text="Hello World!" />

</FrameLayout>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions app-kotlin/src/main/res/values-ko/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>

<string name="app_name">TedPermission Kotlin DSL 데모</string>

<string name="custom_close_text">맞춤 닫기</string>

<string name="rationale_title">권한이 필요합니다</string>
<string name="rationale_message">
우리는 권한이 필요함을 읽을<b>연락처</b>을 찾아<b>위치</b>,<b>카메라</b><b>외부 저장 장치에 쓰기</b>
</string>


</resources>
6 changes: 6 additions & 0 deletions app-kotlin/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#FF4081</color>
</resources>
13 changes: 13 additions & 0 deletions app-kotlin/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<resources xmlns:tools="http://schemas.android.com/tools"
tools:ignore="UnusedResources">

<string name="app_name">TedPermission Kotlin DSL Demo</string>

<string name="custom_close_text">Custom Close</string>

<string name="rationale_title">Permission required</string>
<string name="rationale_message">
We need permission to read <b>contacts</b>, find your <b>location</b>, use your <b>camera</b> and <b>write to external storage</b>
</string>

</resources>
11 changes: 11 additions & 0 deletions app-kotlin/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>

</resources>
2 changes: 2 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

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

<application
android:allowBackup="true"
Expand Down
12 changes: 12 additions & 0 deletions app/src/main/res/values-ko/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">TedPermission 데모</string>

<string name="custom_close_text">맞춤 닫기</string>

<string name="rationale_title">권한이 필요합니다</string>
<string name="rationale_message">
<b> 연락처 </b>에 대한 권한이 필요하며 <b> 위치 </b>
</string>

</resources>
5 changes: 3 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
ext.kotlin_version = '1.2.30'
repositories {
jcenter()
mavenCentral()

}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}

apply from: 'dependencies.gradle'


}


Expand All @@ -33,4 +35,3 @@ allprojects {
task clean(type: Delete) {
delete rootProject.buildDir
}

2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
@@ -1 +1 @@
include ':app', ':tedpermission', ':tedpermission-rx1', ':tedpermission-rx2'
include ':app', ':tedpermission', ':tedpermission-rx1', ':tedpermission-rx2', ':tedpermission-kotlin-dsl', ':app-kotlin'
1 change: 1 addition & 0 deletions tedpermission-kotlin-dsl/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
29 changes: 29 additions & 0 deletions tedpermission-kotlin-dsl/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'

android {
compileSdkVersion versions.compileSdkVersion
buildToolsVersion versions.buildToolsVersion


defaultConfig {
minSdkVersion versions.minSdkVersion
targetSdkVersion versions.targetSdkVersion
versionCode 1
versionName "1.0"
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}

}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(':tedpermission')
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}
Loading