aboutsummaryrefslogtreecommitdiff
path: root/sample/src/main/kotlin
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/src/main/kotlin
parent8df185cfdc94fa937d37d8ec6ece6a2374fba189 (diff)
downloadkau-d024e8db464e8b0ba0133feed67896b854fd8b25.tar.gz
kau-d024e8db464e8b0ba0133feed67896b854fd8b25.tar.bz2
kau-d024e8db464e8b0ba0133feed67896b854fd8b25.zip
Push permission manager for release
Diffstat (limited to 'sample/src/main/kotlin')
-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
2 files changed, 36 insertions, 6 deletions
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)