diff options
Diffstat (limited to 'library')
-rw-r--r-- | library/src/main/kotlin/ca/allanwang/kau/about/AboutActivityBase.kt | 2 | ||||
-rw-r--r-- | library/src/main/kotlin/ca/allanwang/kau/iitems/KauIItem.kt (renamed from library/src/main/kotlin/ca/allanwang/kau/iitems/KotlinIItem.kt) | 2 | ||||
-rw-r--r-- | library/src/main/kotlin/ca/allanwang/kau/permissions/PermissionManager.kt | 7 | ||||
-rw-r--r-- | library/src/main/kotlin/ca/allanwang/kau/permissions/Permissions.kt | 72 | ||||
-rw-r--r-- | library/src/main/kotlin/ca/allanwang/kau/searchview/SearchItem.kt | 5 | ||||
-rw-r--r-- | library/src/main/kotlin/ca/allanwang/kau/utils/ViewUtils.kt | 5 |
6 files changed, 81 insertions, 12 deletions
diff --git a/library/src/main/kotlin/ca/allanwang/kau/about/AboutActivityBase.kt b/library/src/main/kotlin/ca/allanwang/kau/about/AboutActivityBase.kt index 9484299..32e8745 100644 --- a/library/src/main/kotlin/ca/allanwang/kau/about/AboutActivityBase.kt +++ b/library/src/main/kotlin/ca/allanwang/kau/about/AboutActivityBase.kt @@ -138,7 +138,7 @@ abstract class AboutActivityBase(val rClass: Class<*>, val configBuilder: Config */ open fun inflateMainPage(layoutInflater: LayoutInflater, parent: ViewGroup, position: Int): View { val fastAdapter = FastItemThemedAdapter<IItem<*, *>>(configs) - val recycler = fullLinearRecycler { adapter = fastAdapter } + val recycler = fullLinearRecycler(fastAdapter) fastAdapter.add(CutoutIItem { with(configs) { text = string(cutoutTextRes, cutoutText) diff --git a/library/src/main/kotlin/ca/allanwang/kau/iitems/KotlinIItem.kt b/library/src/main/kotlin/ca/allanwang/kau/iitems/KauIItem.kt index 7e4bda6..00b165c 100644 --- a/library/src/main/kotlin/ca/allanwang/kau/iitems/KotlinIItem.kt +++ b/library/src/main/kotlin/ca/allanwang/kau/iitems/KauIItem.kt @@ -12,7 +12,7 @@ import com.mikepenz.fastadapter.items.AbstractItem * * Kotlin implementation of the [AbstractItem] to make things shorter */ -open class KotlinIItem<Item, VH : RecyclerView.ViewHolder>( +open class KauIItem<Item, VH : RecyclerView.ViewHolder>( private val type: Int, @param:LayoutRes private val layoutRes: Int, private val viewHolder: (v: View) -> VH diff --git a/library/src/main/kotlin/ca/allanwang/kau/permissions/PermissionManager.kt b/library/src/main/kotlin/ca/allanwang/kau/permissions/PermissionManager.kt index 7181e2c..6f93c9f 100644 --- a/library/src/main/kotlin/ca/allanwang/kau/permissions/PermissionManager.kt +++ b/library/src/main/kotlin/ca/allanwang/kau/permissions/PermissionManager.kt @@ -18,6 +18,7 @@ internal object PermissionManager { val pendingResults: MutableList<WeakReference<PermissionResult>> by lazy { mutableListOf<WeakReference<PermissionResult>>() } operator fun invoke(context: Context, permissions: Array<out String>, callback: (granted: Boolean, deniedPerm: String?) -> Unit) { + KL.d("Requesting permissions: ${permissions.contentToString()}") if (!buildIsMarshmallowAndUp) return callback(true, null) val missingPermissions = permissions.filter { !context.hasPermission(it) } if (missingPermissions.isEmpty()) return callback(true, null) @@ -25,15 +26,15 @@ internal object PermissionManager { if (!requestInProgress) { requestInProgress = true requestPermissions(context, missingPermissions.toTypedArray()) - } else KL.d("Request is postponed since another one is still in progress") + } else KL.d("Request is postponed since another one is still in progress; did you remember to override onRequestPermissionsResult?") } - @Synchronized internal fun requestPermissions(context: Context, permissions: Array<String>) { + @Synchronized internal fun requestPermissions(context: Context, permissions: Array<out String>) { val activity = (context as? Activity) ?: throw KauException("Context is not an instance of an activity; cannot request permissions") ActivityCompat.requestPermissions(activity, permissions, 1) } - fun onRequestPermissionsResult(context: Context, permissions: Array<String>, grantResults: IntArray) { + fun onRequestPermissionsResult(context: Context, permissions: Array<out String>, grantResults: IntArray) { val count = Math.min(permissions.size, grantResults.size) val iter = pendingResults.iterator() while (iter.hasNext()) { diff --git a/library/src/main/kotlin/ca/allanwang/kau/permissions/Permissions.kt b/library/src/main/kotlin/ca/allanwang/kau/permissions/Permissions.kt index d466cb3..5d52ecb 100644 --- a/library/src/main/kotlin/ca/allanwang/kau/permissions/Permissions.kt +++ b/library/src/main/kotlin/ca/allanwang/kau/permissions/Permissions.kt @@ -1,7 +1,35 @@ package ca.allanwang.kau.permissions +import android.Manifest import android.app.Activity import android.content.Context +import android.Manifest.permission +import android.Manifest.permission.SYSTEM_ALERT_WINDOW +import android.Manifest.permission.WRITE_EXTERNAL_STORAGE +import android.Manifest.permission.READ_EXTERNAL_STORAGE +import android.Manifest.permission.RECEIVE_MMS +import android.Manifest.permission.RECEIVE_WAP_PUSH +import android.Manifest.permission.READ_SMS +import android.Manifest.permission.RECEIVE_SMS +import android.Manifest.permission.SEND_SMS +import android.Manifest.permission.BODY_SENSORS +import android.Manifest.permission.PROCESS_OUTGOING_CALLS +import android.Manifest.permission.USE_SIP +import android.Manifest.permission.ADD_VOICEMAIL +import android.Manifest.permission.WRITE_CALL_LOG +import android.Manifest.permission.READ_CALL_LOG +import android.Manifest.permission.CALL_PHONE +import android.Manifest.permission.READ_PHONE_STATE +import android.Manifest.permission.RECORD_AUDIO +import android.Manifest.permission.ACCESS_COARSE_LOCATION +import android.Manifest.permission.ACCESS_FINE_LOCATION +import android.Manifest.permission.GET_ACCOUNTS +import android.Manifest.permission.WRITE_CONTACTS +import android.Manifest.permission.READ_CONTACTS +import android.Manifest.permission.WRITE_CALENDAR +import android.Manifest.permission.READ_CALENDAR + + /** * Created by Allan Wang on 2017-07-02. @@ -12,7 +40,7 @@ import android.content.Context /** * Hook that should be added inside all [Activity.onRequestPermissionsResult] so that the Permission manager can handle the responses */ -fun Activity.kauOnRequestPermissionsResult(permissions: Array<String>, grantResults: IntArray) +fun Activity.kauOnRequestPermissionsResult(permissions: Array<out String>, grantResults: IntArray) = PermissionManager.onRequestPermissionsResult(this, permissions, grantResults) /** @@ -23,4 +51,44 @@ fun Activity.kauOnRequestPermissionsResult(permissions: Array<String>, grantResu * [deniedPerm] is the first denied permission, if granted is false */ fun Context.requestPermissions(vararg permissions: String, callback: (granted: Boolean, deniedPerm: String?) -> Unit) - = PermissionManager(this, permissions, callback)
\ No newline at end of file + = PermissionManager(this, permissions, callback) + +/** + * See http://developer.android.com/guide/topics/security/permissions.html#normal-dangerous for a + * list of 'dangerous' permissions that require a permission request on API 23. + */ +const val PERMISSION_READ_CALENDAR = Manifest.permission.READ_CALENDAR + +const val PERMISSION_WRITE_CALENDAR = Manifest.permission.WRITE_CALENDAR + +const val PERMISSION_CAMERA = Manifest.permission.CAMERA + +const val PERMISSION_READ_CONTACTS = Manifest.permission.READ_CONTACTS +const val PERMISSION_WRITE_CONTACTS = Manifest.permission.WRITE_CONTACTS +const val PERMISSION_GET_ACCOUNTS = Manifest.permission.GET_ACCOUNTS + +const val PERMISSION_ACCESS_FINE_LOCATION = Manifest.permission.ACCESS_FINE_LOCATION +const val PERMISSION_ACCESS_COARSE_LOCATION = Manifest.permission.ACCESS_COARSE_LOCATION + +const val PERMISSION_RECORD_AUDIO = Manifest.permission.RECORD_AUDIO + +const val PERMISSION_READ_PHONE_STATE = Manifest.permission.READ_PHONE_STATE +const val PERMISSION_CALL_PHONE = Manifest.permission.CALL_PHONE +const val PERMISSION_READ_CALL_LOG = Manifest.permission.READ_CALL_LOG +const val PERMISSION_WRITE_CALL_LOG = Manifest.permission.WRITE_CALL_LOG +const val PERMISSION_ADD_VOICEMAIL = Manifest.permission.ADD_VOICEMAIL +const val PERMISSION_USE_SIP = Manifest.permission.USE_SIP +const val PERMISSION_PROCESS_OUTGOING_CALLS = Manifest.permission.PROCESS_OUTGOING_CALLS + +const val PERMISSION_BODY_SENSORS = Manifest.permission.BODY_SENSORS + +const val PERMISSION_SEND_SMS = Manifest.permission.SEND_SMS +const val PERMISSION_RECEIVE_SMS = Manifest.permission.RECEIVE_SMS +const val PERMISSION_READ_SMS = Manifest.permission.READ_SMS +const val PERMISSION_RECEIVE_WAP_PUSH = Manifest.permission.RECEIVE_WAP_PUSH +const val PERMISSION_RECEIVE_MMS = Manifest.permission.RECEIVE_MMS + +const val PERMISSION_READ_EXTERNAL_STORAGE = Manifest.permission.READ_EXTERNAL_STORAGE +const val PERMISSION_WRITE_EXTERNAL_STORAGE = Manifest.permission.WRITE_EXTERNAL_STORAGE + +const val PERMISSION_SYSTEM_ALERT_WINDOW = Manifest.permission.SYSTEM_ALERT_WINDOW
\ No newline at end of file diff --git a/library/src/main/kotlin/ca/allanwang/kau/searchview/SearchItem.kt b/library/src/main/kotlin/ca/allanwang/kau/searchview/SearchItem.kt index 95a38da..ac8ec2e 100644 --- a/library/src/main/kotlin/ca/allanwang/kau/searchview/SearchItem.kt +++ b/library/src/main/kotlin/ca/allanwang/kau/searchview/SearchItem.kt @@ -11,9 +11,8 @@ import android.view.View import android.widget.ImageView import android.widget.TextView import ca.allanwang.kau.R -import ca.allanwang.kau.iitems.KotlinIItem +import ca.allanwang.kau.iitems.KauIItem import ca.allanwang.kau.utils.* -import com.mikepenz.fastadapter.items.AbstractItem import com.mikepenz.google_material_typeface_library.GoogleMaterial import com.mikepenz.iconics.typeface.IIcon @@ -29,7 +28,7 @@ class SearchItem(val key: String, val description: String? = null, val iicon: IIcon? = GoogleMaterial.Icon.gmd_search, val image: Drawable? = null -) : KotlinIItem<SearchItem, SearchItem.ViewHolder>( +) : KauIItem<SearchItem, SearchItem.ViewHolder>( R.id.kau_item_search, R.layout.kau_search_iitem, {ViewHolder(it)} diff --git a/library/src/main/kotlin/ca/allanwang/kau/utils/ViewUtils.kt b/library/src/main/kotlin/ca/allanwang/kau/utils/ViewUtils.kt index bd17b92..b4752a5 100644 --- a/library/src/main/kotlin/ca/allanwang/kau/utils/ViewUtils.kt +++ b/library/src/main/kotlin/ca/allanwang/kau/utils/ViewUtils.kt @@ -48,7 +48,7 @@ import com.mikepenz.iconics.typeface.IIcon @KauUtils fun View.isInvisible(): Boolean = visibility == View.INVISIBLE @KauUtils fun View.isGone(): Boolean = visibility == View.GONE -fun View.snackbar(text: String, duration: Int = Snackbar.LENGTH_LONG, builder: Snackbar.() -> Unit = {}):Snackbar { +fun View.snackbar(text: String, duration: Int = Snackbar.LENGTH_LONG, builder: Snackbar.() -> Unit = {}): Snackbar { val snackbar = Snackbar.make(this, text, duration) snackbar.builder() snackbar.show() @@ -116,10 +116,11 @@ val CIRCULAR_OUTLINE: ViewOutlineProvider = object : ViewOutlineProvider() { /** * Generates a recycler view with match parent and a linearlayoutmanager, since it's so commonly used */ -fun Context.fullLinearRecycler(configs: RecyclerView.() -> Unit = {}): RecyclerView { +fun Context.fullLinearRecycler(rvAdapter: RecyclerView.Adapter<*>? = null, configs: RecyclerView.() -> Unit = {}): RecyclerView { return RecyclerView(this).apply { layoutManager = LinearLayoutManager(this@fullLinearRecycler) layoutParams = RecyclerView.LayoutParams(RecyclerView.LayoutParams.MATCH_PARENT, RecyclerView.LayoutParams.MATCH_PARENT) + if (rvAdapter != null) adapter = rvAdapter configs() } }
\ No newline at end of file |