From d024e8db464e8b0ba0133feed67896b854fd8b25 Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Mon, 3 Jul 2017 22:34:05 -0700 Subject: Push permission manager for release --- sample/src/main/AndroidManifest.xml | 4 ++- .../kotlin/ca/allanwang/kau/sample/AnimActivity.kt | 29 +++++++++++++++++++--- .../ca/allanwang/kau/sample/PermissionCheckbox.kt | 13 ++++++++-- sample/src/main/res/values/styles.xml | 7 ++++-- sample/src/main/res/xml/changelog.xml | 3 +++ 5 files changed, 47 insertions(+), 9 deletions(-) (limited to 'sample/src') 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 @@ + + + android:theme="@style/AppTheme.NoActionBar.Transparent"> 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 - val recycler = fullLinearRecycler { - + val adapter = FastItemAdapter() + 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, 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( +class PermissionCheckbox(val permission: String) : KauIItem( R.layout.permission_checkbox, R.layout.permission_checkbox, { ViewHolder(it) }) { + override fun bindView(holder: ViewHolder, payloads: MutableList?) { + 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 @@ @color/colorPrimaryDark @color/colorAccent #303030 - true - @android:color/transparent + + 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 @@ + + + -- cgit v1.2.3