diff options
author | Allan Wang <me@allanwang.ca> | 2018-02-13 16:51:56 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-02-13 16:51:56 -0500 |
commit | cdb1bd6eec2c90abc9d3d982814552443c7fc3b2 (patch) | |
tree | 2d21dfcce61fec76384d862b410ee61579169bc2 /core/src/main | |
parent | f5d6ddb72a3dc369b95631a607471f9a6ea5e70f (diff) | |
download | kau-cdb1bd6eec2c90abc9d3d982814552443c7fc3b2.tar.gz kau-cdb1bd6eec2c90abc9d3d982814552443c7fc3b2.tar.bz2 kau-cdb1bd6eec2c90abc9d3d982814552443c7fc3b2.zip |
Update docs (#135)
* Update docs
* Update format
* Update dependencies
Diffstat (limited to 'core/src/main')
15 files changed, 91 insertions, 63 deletions
diff --git a/core/src/main/kotlin/ca/allanwang/kau/email/EmailBuilder.kt b/core/src/main/kotlin/ca/allanwang/kau/email/EmailBuilder.kt index 9dd5bea..804eacb 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/email/EmailBuilder.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/email/EmailBuilder.kt @@ -15,6 +15,8 @@ import ca.allanwang.kau.utils.* /** * Created by Allan Wang on 2017-06-20. + * + * Helper tool to call an email intent with device information */ class EmailBuilder(val email: String, val subject: String) { var message: String = "Write here." @@ -34,6 +36,9 @@ class EmailBuilder(val email: String, val subject: String) { attachment = uri } + /** + * Optional handler to update the created intent + */ var extras: Intent.() -> Unit = {} data class Package(val packageName: String, val appName: String) @@ -72,10 +77,12 @@ class EmailBuilder(val email: String, val subject: String) { } } - if (packages.isNotEmpty()) emailBuilder.append("\n") - packages.forEach { - if (context.isAppInstalled(it.packageName)) - emailBuilder.append(String.format("\n%s is installed", it.appName)) + if (packages.isNotEmpty()) { + emailBuilder.append("\n") + packages.forEach { + if (context.isAppInstalled(it.packageName)) + emailBuilder.append(String.format("\n%s is installed", it.appName)) + } } if (pairs.isNotEmpty()) { diff --git a/core/src/main/kotlin/ca/allanwang/kau/kpref/KPrefDelegate.kt b/core/src/main/kotlin/ca/allanwang/kau/kpref/KPrefDelegate.kt index ca3701b..33ba807 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/kpref/KPrefDelegate.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/kpref/KPrefDelegate.kt @@ -21,8 +21,8 @@ class StringSet(set: Collection<String>) : LinkedHashSet<String>(set) * Also contains an optional mutable postSetter that will be called every time a new value is given */ class KPrefDelegate<T : Any> internal constructor( - private val key: String, private val fallback: T, private val pref: KPref, var postSetter: (value: T) -> Unit = {}, lock: Any? = null -) : ILazyResettable<T>, java.io.Serializable { + private val key: String, private val fallback: T, private val pref: KPref, private var postSetter: (value: T) -> Unit = {}, lock: Any? = null +) : ILazyResettable<T> { private object UNINITIALIZED diff --git a/core/src/main/kotlin/ca/allanwang/kau/kpref/KPrefSingleDelegate.kt b/core/src/main/kotlin/ca/allanwang/kau/kpref/KPrefSingleDelegate.kt index ff08e3c..6525305 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/kpref/KPrefSingleDelegate.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/kpref/KPrefSingleDelegate.kt @@ -8,8 +8,8 @@ fun KPref.kprefSingle(key: String) = KPrefSingleDelegate(key, this) * Created by Allan Wang on 2017-06-07. * * Singular KPref Delegate for booleans - * When the shared pref is not initialized, it will return true then set the pref to false - * All subsequent retrievals will be false + * When the shared pref is not initialized, it will return [true] then set the pref to [false] + * All subsequent retrievals will be [false] * This is useful for one time toggles such as showcasing items */ class KPrefSingleDelegate internal constructor(private val key: String, private val pref: KPref, lock: Any? = null) : ILazyResettable<Boolean> { diff --git a/core/src/main/kotlin/ca/allanwang/kau/logging/KL.kt b/core/src/main/kotlin/ca/allanwang/kau/logging/KL.kt index f690571..9f48ab5 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/logging/KL.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/logging/KL.kt @@ -4,5 +4,7 @@ import ca.allanwang.kau.BuildConfig /** * Created by Allan Wang on 2017-06-19. + * + * Internal KAU logger */ object KL : KauLogger("KAU", { BuildConfig.DEBUG })
\ No newline at end of file diff --git a/core/src/main/kotlin/ca/allanwang/kau/logging/KauLogger.kt b/core/src/main/kotlin/ca/allanwang/kau/logging/KauLogger.kt index e639867..799d32f 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/logging/KauLogger.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/logging/KauLogger.kt @@ -21,6 +21,8 @@ import android.util.Log * inline fun _d(message: () -> Any?) { * if (BuildConfig.DEBUG) d(message) * } + * This use case allows for a constant boolean check, which should be caught and removed by proguard + * for production builds */ open class KauLogger( /** diff --git a/core/src/main/kotlin/ca/allanwang/kau/permissions/PermissionManager.kt b/core/src/main/kotlin/ca/allanwang/kau/permissions/PermissionManager.kt index 8b639ad..3b15e0b 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/permissions/PermissionManager.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/permissions/PermissionManager.kt @@ -15,6 +15,9 @@ import java.lang.ref.WeakReference /** * Created by Allan Wang on 2017-07-03. + * + * Permission manager that is decoupled from activities + * Keeps track of pending requests, and warns about invalid requests */ internal object PermissionManager { @@ -24,7 +27,7 @@ internal object PermissionManager { /** * Retrieve permissions requested in our manifest */ - val manifestPermission = lazyContext<Array<String>> { + private val manifestPermission = lazyContext<Array<String>> { try { it.packageManager.getPackageInfo(it.packageName, PackageManager.GET_PERMISSIONS)?.requestedPermissions ?: emptyArray() } catch (e: Exception) { @@ -44,7 +47,7 @@ internal object PermissionManager { } 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<out String>) { + @Synchronized private fun requestPermissions(context: Context, permissions: Array<out String>) { permissions.forEach { if (!manifestPermission(context).contains(it)) { KL.e { "Requested permission $it is not stated in the manifest" } @@ -57,6 +60,10 @@ internal object PermissionManager { ActivityCompat.requestPermissions(activity, permissions, 1) } + /** + * Handles permission result by allowing accepted permissions for all pending requests + * Also cleans up destroyed or completed pending requests + */ fun onRequestPermissionsResult(context: Context, permissions: Array<out String>, grantResults: IntArray) { KL.i { "On permission result: pending ${pendingResults.size}" } val count = Math.min(permissions.size, grantResults.size) diff --git a/core/src/main/kotlin/ca/allanwang/kau/permissions/PermissionResult.kt b/core/src/main/kotlin/ca/allanwang/kau/permissions/PermissionResult.kt index 14bfdff..ba3e6dd 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/permissions/PermissionResult.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/permissions/PermissionResult.kt @@ -4,6 +4,8 @@ import android.content.pm.PackageManager /** * Created by Allan Wang on 2017-07-03. + * + * Pending permission collector */ class PermissionResult(permissions: Array<out String>, val callback: (granted: Boolean, deniedPerm: String?) -> Unit) { val permissions = mutableSetOf(*permissions) diff --git a/core/src/main/kotlin/ca/allanwang/kau/permissions/Permissions.kt b/core/src/main/kotlin/ca/allanwang/kau/permissions/Permissions.kt index 36ad52f..4de6695 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/permissions/Permissions.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/permissions/Permissions.kt @@ -3,6 +3,8 @@ package ca.allanwang.kau.permissions import android.Manifest import android.app.Activity import android.content.Context +import android.os.Build +import android.support.annotation.RequiresApi /** @@ -60,6 +62,7 @@ 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 +@RequiresApi(Build.VERSION_CODES.KITKAT_WATCH) const val PERMISSION_BODY_SENSORS = Manifest.permission.BODY_SENSORS const val PERMISSION_SEND_SMS = Manifest.permission.SEND_SMS diff --git a/core/src/main/kotlin/ca/allanwang/kau/ui/views/RippleCanvas.kt b/core/src/main/kotlin/ca/allanwang/kau/ui/views/RippleCanvas.kt index 86aba6e..62a16d9 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/ui/views/RippleCanvas.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/ui/views/RippleCanvas.kt @@ -12,7 +12,6 @@ import android.view.View /** * Created by Allan Wang on 2016-11-17. * - * * Canvas drawn ripples that keep the previous color * Extends to view dimensions * Supports multiple ripples from varying locations diff --git a/core/src/main/kotlin/ca/allanwang/kau/utils/FontUtils.kt b/core/src/main/kotlin/ca/allanwang/kau/utils/FontUtils.kt index 3fc509d..05073c7 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/utils/FontUtils.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/utils/FontUtils.kt @@ -8,7 +8,7 @@ import android.graphics.Typeface */ object FontUtils { - val sTypefaceCache: MutableMap<String, Typeface> = mutableMapOf() + private val sTypefaceCache: MutableMap<String, Typeface> = mutableMapOf() fun get(context: Context, font: String): Typeface { synchronized(sTypefaceCache) { diff --git a/core/src/main/kotlin/ca/allanwang/kau/utils/IIconUtils.kt b/core/src/main/kotlin/ca/allanwang/kau/utils/IIconUtils.kt index a8c710e..51691af 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/utils/IIconUtils.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/utils/IIconUtils.kt @@ -14,7 +14,8 @@ import com.mikepenz.iconics.typeface.IIcon @KauUtils fun IIcon.toDrawable(c: Context, sizeDp: Int = 24, @ColorInt color: Int = Color.WHITE, builder: IconicsDrawable.() -> Unit = {}): Drawable { val state = ColorStateList.valueOf(color) - val icon = IconicsDrawable(c).icon(this).sizeDp(sizeDp).color(state) + val icon = IconicsDrawable(c).icon(this).color(state) + if (sizeDp > 0) icon.sizeDp(sizeDp) icon.builder() return icon }
\ No newline at end of file diff --git a/core/src/main/kotlin/ca/allanwang/kau/utils/NetworkUtils.kt b/core/src/main/kotlin/ca/allanwang/kau/utils/NetworkUtils.kt index 53016be..2271c16 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/utils/NetworkUtils.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/utils/NetworkUtils.kt @@ -1,5 +1,6 @@ package ca.allanwang.kau.utils +import android.annotation.SuppressLint import android.content.Context import android.net.ConnectivityManager @@ -7,6 +8,7 @@ import android.net.ConnectivityManager * Created by Allan Wang on 2017-07-07. */ inline val Context.isNetworkAvailable: Boolean + @SuppressLint("MissingPermission") get() { val connectivityManager = getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager val activeNetworkInfo = connectivityManager.activeNetworkInfo @@ -14,6 +16,7 @@ inline val Context.isNetworkAvailable: Boolean } inline val Context.isWifiConnected: Boolean + @SuppressLint("MissingPermission") get() { val connectivityManager = getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager val activeNetworkInfo = connectivityManager.activeNetworkInfo @@ -21,6 +24,7 @@ inline val Context.isWifiConnected: Boolean } inline val Context.isMobileDataConnected: Boolean + @SuppressLint("MissingPermission") get() { val connectivityManager = getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager val activeNetworkInfo = connectivityManager.activeNetworkInfo diff --git a/core/src/main/kotlin/ca/allanwang/kau/utils/RecyclerUtils.kt b/core/src/main/kotlin/ca/allanwang/kau/utils/RecyclerUtils.kt index f80c85e..3a34db5 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/utils/RecyclerUtils.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/utils/RecyclerUtils.kt @@ -13,7 +13,7 @@ fun RecyclerView.withMarginDecoration(sizeDp: Int, edgeFlags: Int) { class MarginItemDecoration(sizeDp: Int, val edgeFlags: Int) : RecyclerView.ItemDecoration() { - val sizePx = sizeDp.dpToPx + private val sizePx = sizeDp.dpToPx override fun getItemOffsets(outRect: Rect, view: View, parent: RecyclerView, state: RecyclerView.State) { super.getItemOffsets(outRect, view, parent, state) diff --git a/core/src/main/kotlin/ca/allanwang/kau/xml/Changelog.kt b/core/src/main/kotlin/ca/allanwang/kau/xml/Changelog.kt index cbebd55..83b182f 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/xml/Changelog.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/xml/Changelog.kt @@ -23,8 +23,9 @@ import org.xmlpull.v1.XmlPullParser /** * Created by Allan Wang on 2017-05-28. + * + * Easy changelog loader */ - fun Context.showChangelog(@XmlRes xmlRes: Int, @ColorInt textColor: Int? = null, customize: MaterialDialog.Builder.() -> Unit = {}) { doAsync { val items = parse(this@showChangelog, xmlRes) diff --git a/core/src/main/res-public/values/public.xml b/core/src/main/res-public/values/public.xml index f831c6d..2163b10 100644 --- a/core/src/main/res-public/values/public.xml +++ b/core/src/main/res-public/values/public.xml @@ -1,29 +1,56 @@ <resources xmlns:tools='http://schemas.android.com/tools' tools:ignore='ResourceName'> <!-- AUTO-GENERATED FILE. DO NOT MODIFY. public.xml is generated by the generatepublicxml gradle task --> - <public name='kau_exit_slide_bottom' type='transition' /> - <public name='kau_exit_slide_left' type='transition' /> - <public name='kau_enter_slide_right' type='transition' /> - <public name='kau_exit_slide_top' type='transition' /> - <public name='kau_exit_slide_right' type='transition' /> - <public name='kau_enter_slide_bottom' type='transition' /> - <public name='kau_enter_slide_top' type='transition' /> - <public name='kau_enter_slide_left' type='transition' /> - <public name='kau_selectable_white' type='drawable' /> - <public name='kau_transparent' type='drawable' /> - <public name='kau_fade_out' type='anim' /> - <public name='kau_slide_in_right' type='anim' /> <public name='kau_fade_in' type='anim' /> - <public name='kau_slide_out_right' type='anim' /> - <public name='kau_slide_out_left' type='anim' /> + <public name='kau_fade_out' type='anim' /> + <public name='kau_slide_in_bottom' type='anim' /> <public name='kau_slide_in_left' type='anim' /> + <public name='kau_slide_in_right' type='anim' /> + <public name='kau_slide_in_top' type='anim' /> <public name='kau_slide_out_bottom' type='anim' /> + <public name='kau_slide_out_left' type='anim' /> + <public name='kau_slide_out_left_top' type='anim' /> + <public name='kau_slide_out_right' type='anim' /> <public name='kau_slide_out_right_top' type='anim' /> - <public name='kau_slide_in_top' type='anim' /> <public name='kau_slide_out_top' type='anim' /> - <public name='kau_slide_in_bottom' type='anim' /> - <public name='kau_slide_out_left_top' type='anim' /> - <public name='Kau' type='style' /> - <public name='Kau.Translucent' type='style' /> + <public name='kau_selectable_white' type='drawable' /> + <public name='kau_transparent' type='drawable' /> + <public name='kau_enter_slide_bottom' type='transition' /> + <public name='kau_enter_slide_left' type='transition' /> + <public name='kau_enter_slide_right' type='transition' /> + <public name='kau_enter_slide_top' type='transition' /> + <public name='kau_exit_slide_bottom' type='transition' /> + <public name='kau_exit_slide_left' type='transition' /> + <public name='kau_exit_slide_right' type='transition' /> + <public name='kau_exit_slide_top' type='transition' /> + <public name='kau_shadow_overlay' type='color' /> + <public name='kau_activity_horizontal_margin' type='dimen' /> + <public name='kau_activity_vertical_margin' type='dimen' /> + <public name='kau_dialog_margin' type='dimen' /> + <public name='kau_dialog_margin_bottom' type='dimen' /> + <public name='kau_fab_margin' type='dimen' /> + <public name='kau_appbar_padding_top' type='dimen' /> + <public name='kau_splash_logo' type='dimen' /> + <public name='kau_progress_bar_height' type='dimen' /> + <public name='kau_account_image_size' type='dimen' /> + <public name='kau_status_bar_height' type='dimen' /> + <public name='kau_drag_dismiss_distance' type='dimen' /> + <public name='kau_drag_dismiss_distance_large' type='dimen' /> + <public name='kau_spacing_normal' type='dimen' /> + <public name='kau_spacing_micro' type='dimen' /> + <public name='kau_spacing_large' type='dimen' /> + <public name='kau_spacing_xlarge' type='dimen' /> + <public name='kau_spacing_huge' type='dimen' /> + <public name='kau_padding_small' type='dimen' /> + <public name='kau_padding_normal' type='dimen' /> + <public name='kau_padding_large' type='dimen' /> + <public name='kau_fab_size' type='dimen' /> + <public name='kau_fab_radius' type='dimen' /> + <public name='kau_display_4_text_size' type='dimen' /> + <public name='kau_avatar_size' type='dimen' /> + <public name='kau_avatar_bounds' type='dimen' /> + <public name='kau_avatar_padding' type='dimen' /> + <public name='kau_avatar_margin' type='dimen' /> + <public name='kau_avatar_ripple_radius' type='dimen' /> <public name='kau_about_app' type='string' /> <public name='kau_about_x' type='string' /> <public name='kau_add_account' type='string' /> @@ -79,7 +106,8 @@ <public name='kau_permission_denied' type='string' /> <public name='kau_0' type='string' /> <public name='kau_bullet_point' type='string' /> - <public name='kau_shadow_overlay' type='color' /> + <public name='Kau' type='style' /> + <public name='Kau.Translucent' type='style' /> <public name='KauFadeIn' type='style' /> <public name='KauFadeInFadeOut' type='style' /> <public name='KauSlideInRight' type='style' /> @@ -87,32 +115,4 @@ <public name='KauSlideInFadeOut' type='style' /> <public name='KauSlideInSlideOutRight' type='style' /> <public name='KauSlideInSlideOutBottom' type='style' /> - <public name='kau_activity_horizontal_margin' type='dimen' /> - <public name='kau_activity_vertical_margin' type='dimen' /> - <public name='kau_dialog_margin' type='dimen' /> - <public name='kau_dialog_margin_bottom' type='dimen' /> - <public name='kau_fab_margin' type='dimen' /> - <public name='kau_appbar_padding_top' type='dimen' /> - <public name='kau_splash_logo' type='dimen' /> - <public name='kau_progress_bar_height' type='dimen' /> - <public name='kau_account_image_size' type='dimen' /> - <public name='kau_status_bar_height' type='dimen' /> - <public name='kau_drag_dismiss_distance' type='dimen' /> - <public name='kau_drag_dismiss_distance_large' type='dimen' /> - <public name='kau_spacing_normal' type='dimen' /> - <public name='kau_spacing_micro' type='dimen' /> - <public name='kau_spacing_large' type='dimen' /> - <public name='kau_spacing_xlarge' type='dimen' /> - <public name='kau_spacing_huge' type='dimen' /> - <public name='kau_padding_small' type='dimen' /> - <public name='kau_padding_normal' type='dimen' /> - <public name='kau_padding_large' type='dimen' /> - <public name='kau_fab_size' type='dimen' /> - <public name='kau_fab_radius' type='dimen' /> - <public name='kau_display_4_text_size' type='dimen' /> - <public name='kau_avatar_size' type='dimen' /> - <public name='kau_avatar_bounds' type='dimen' /> - <public name='kau_avatar_padding' type='dimen' /> - <public name='kau_avatar_margin' type='dimen' /> - <public name='kau_avatar_ripple_radius' type='dimen' /> </resources>
\ No newline at end of file |