aboutsummaryrefslogtreecommitdiff
path: root/sample
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2017-07-03 22:34:05 -0700
committerAllan Wang <me@allanwang.ca>2017-07-03 22:34:05 -0700
commitd024e8db464e8b0ba0133feed67896b854fd8b25 (patch)
treefcbe4828b91c566000a041989c3c28401b6b618f /sample
parent8df185cfdc94fa937d37d8ec6ece6a2374fba189 (diff)
downloadkau-d024e8db464e8b0ba0133feed67896b854fd8b25.tar.gz
kau-d024e8db464e8b0ba0133feed67896b854fd8b25.tar.bz2
kau-d024e8db464e8b0ba0133feed67896b854fd8b25.zip
Push permission manager for release
Diffstat (limited to 'sample')
-rw-r--r--sample/src/main/AndroidManifest.xml4
-rw-r--r--sample/src/main/kotlin/ca/allanwang/kau/sample/AnimActivity.kt29
-rw-r--r--sample/src/main/kotlin/ca/allanwang/kau/sample/PermissionCheckbox.kt13
-rw-r--r--sample/src/main/res/values/styles.xml7
-rw-r--r--sample/src/main/res/xml/changelog.xml3
5 files changed, 47 insertions, 9 deletions
diff --git a/sample/src/main/AndroidManifest.xml b/sample/src/main/AndroidManifest.xml
index 5e6eb4c..44d9416 100644
--- a/sample/src/main/AndroidManifest.xml
+++ b/sample/src/main/AndroidManifest.xml
@@ -2,6 +2,8 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="ca.allanwang.kau.sample">
+ <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
+
<application
android:name=".SampleApp"
android:allowBackup="true"
@@ -13,7 +15,7 @@
<activity
android:name=".MainActivity"
android:label="@string/title_activity_main"
- android:theme="@style/AppTheme.NoActionBar">
+ android:theme="@style/AppTheme.NoActionBar.Transparent">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
diff --git a/sample/src/main/kotlin/ca/allanwang/kau/sample/AnimActivity.kt b/sample/src/main/kotlin/ca/allanwang/kau/sample/AnimActivity.kt
index 2fd846c..8b8d784 100644
--- a/sample/src/main/kotlin/ca/allanwang/kau/sample/AnimActivity.kt
+++ b/sample/src/main/kotlin/ca/allanwang/kau/sample/AnimActivity.kt
@@ -2,8 +2,14 @@ package ca.allanwang.kau.sample
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
+import ca.allanwang.kau.logging.KL
+import ca.allanwang.kau.permissions.PERMISSION_ACCESS_COARSE_LOCATION
+import ca.allanwang.kau.permissions.PERMISSION_ACCESS_FINE_LOCATION
+import ca.allanwang.kau.permissions.kauOnRequestPermissionsResult
+import ca.allanwang.kau.permissions.requestPermissions
import ca.allanwang.kau.utils.fullLinearRecycler
import ca.allanwang.kau.utils.startActivitySlideOut
+import ca.allanwang.kau.utils.toast
import com.mikepenz.fastadapter.commons.adapters.FastItemAdapter
/**
@@ -16,14 +22,29 @@ class AnimActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
- val adapter = FastItemAdapter<KP>
- val recycler = fullLinearRecycler {
-
+ val adapter = FastItemAdapter<PermissionCheckbox>()
+ setContentView(fullLinearRecycler(adapter))
+ adapter.add(listOf(
+ PERMISSION_ACCESS_COARSE_LOCATION,
+ PERMISSION_ACCESS_FINE_LOCATION
+ ).map{ PermissionCheckbox(it) })
+ adapter.withOnClickListener { _, _, item, _ ->
+ KL.d("Perm Click")
+ requestPermissions(item.permission) {
+ granted, deniedPerm ->
+ toast("${item.permission} enabled: $granted")
+ adapter.notifyAdapterDataSetChanged()
+ }
+ true
}
- setContentView(R.layout.sample)
}
override fun onBackPressed() {
startActivitySlideOut(MainActivity::class.java)
}
+
+ override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>, grantResults: IntArray) {
+ super.onRequestPermissionsResult(requestCode, permissions, grantResults)
+ kauOnRequestPermissionsResult(permissions, grantResults)
+ }
} \ No newline at end of file
diff --git a/sample/src/main/kotlin/ca/allanwang/kau/sample/PermissionCheckbox.kt b/sample/src/main/kotlin/ca/allanwang/kau/sample/PermissionCheckbox.kt
index 012d523..c1b1865 100644
--- a/sample/src/main/kotlin/ca/allanwang/kau/sample/PermissionCheckbox.kt
+++ b/sample/src/main/kotlin/ca/allanwang/kau/sample/PermissionCheckbox.kt
@@ -4,15 +4,24 @@ import android.support.v7.widget.RecyclerView
import android.view.View
import android.widget.CheckBox
import android.widget.TextView
-import ca.allanwang.kau.iitems.KotlinIItem
+import ca.allanwang.kau.iitems.KauIItem
import ca.allanwang.kau.utils.bindView
+import ca.allanwang.kau.utils.hasPermission
/**
* Created by Allan Wang on 2017-07-03.
*/
-class PermissionCheckbox(val permission: String) : KotlinIItem<PermissionCheckbox, PermissionCheckbox.ViewHolder>(
+class PermissionCheckbox(val permission: String) : KauIItem<PermissionCheckbox, PermissionCheckbox.ViewHolder>(
R.layout.permission_checkbox, R.layout.permission_checkbox, { ViewHolder(it) }) {
+ override fun bindView(holder: ViewHolder, payloads: MutableList<Any>?) {
+ super.bindView(holder, payloads)
+ holder.text.text = permission
+ holder.checkbox.isChecked = holder.itemView.context.hasPermission(permission)
+ holder.checkbox.isClickable = false
+ holder.checkbox.jumpDrawablesToCurrentState() //Cancel the animation
+ }
+
class ViewHolder(v: View) : RecyclerView.ViewHolder(v) {
val text: TextView by bindView(R.id.perm_text)
val checkbox: CheckBox by bindView(R.id.perm_checkbox)
diff --git a/sample/src/main/res/values/styles.xml b/sample/src/main/res/values/styles.xml
index 781424d..b550607 100644
--- a/sample/src/main/res/values/styles.xml
+++ b/sample/src/main/res/values/styles.xml
@@ -7,8 +7,6 @@
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:colorBackground">#303030</item>
- <item name="android:windowShowWallpaper">true</item>
- <item name="android:windowBackground">@android:color/transparent</item>
</style>
<style name="AppTheme.NoActionBar">
@@ -16,6 +14,11 @@
<item name="windowNoTitle">true</item>
</style>
+ <style name="AppTheme.NoActionBar.Transparent">
+ <item name="android:windowShowWallpaper">true</item>
+ <item name="android:windowBackground">@android:color/transparent</item>
+ </style>
+
<style name="AppTheme.Slide" parent="AppTheme">
<item name="android:windowAnimationStyle">@style/KauSlideInSlideOut</item>
</style>
diff --git a/sample/src/main/res/xml/changelog.xml b/sample/src/main/res/xml/changelog.xml
index 148e511..1fe0a61 100644
--- a/sample/src/main/res/xml/changelog.xml
+++ b/sample/src/main/res/xml/changelog.xml
@@ -9,6 +9,9 @@
<version title="v1.5"/>
<item text="Change snackbar builder" />
<item text="Change addBundle to withArguments to match ANKO" />
+ <item text="Created KauIItem to replace AbstractItem" />
+ <item text="Created permission manager and permission constants" />
+ <item text="" />
<item text="" />
<item text="" />
<item text="" />