Skip to content

Commit

Permalink
Merge dev
Browse files Browse the repository at this point in the history
  • Loading branch information
AllanWang committed Oct 14, 2017
2 parents 1edb6e1 + a0b3531 commit afc1a02
Show file tree
Hide file tree
Showing 26 changed files with 173 additions and 125 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
*.iml
/.idea
.gradle
/crowdin.properties
/local.properties
.DS_Store
/build
Expand Down
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ android:
# - android-21
- platform-tools
- tools
- build-tools-26.0.1
- build-tools-26.0.2
- android-26
- extra-android-support
- extra-android-m2repository
Expand Down
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ KAU is available on JitPack

[![](https://jitpack.io/v/ca.allanwang/kau.svg)](https://jitpack.io/#ca.allanwang/kau)
[![Build Status](https://travis-ci.org/AllanWang/KAU.svg?branch=master)](https://travis-ci.org/AllanWang/KAU)
[![Crowdin](https://d322cqt584bo4o.cloudfront.net/kotlin-android-utils/localized.svg)](https://crowdin.com/project/kotlin-android-utils)
[![Awesome Kotlin Badge](https://kotlin.link/awesome-kotlin.svg)](https://github.com/KotlinBy/awesome-kotlin)
[![Stories in Ready](https://badge.waffle.io/AllanWang/KAU.png?label=ready&title=Ready)](https://waffle.io/AllanWang/KAU?utm_source=badge)
[![ZenHub](https://img.shields.io/badge/Shipping%20faster%20with-ZenHub-45529A.svg)](https://app.zenhub.com/workspace/o/allanwang/kau/boards)
[![GitHub license](https://img.shields.io/badge/license-Apache%202-blue.svg)](https://raw.githubusercontent.com/AllanWang/KAU/master/LICENSE)

To apply, add the following to your root build.gradle:
Expand Down Expand Up @@ -140,4 +141,9 @@ To resolve that, add `multiDexEnabled true` under your `app.gradle > android > d

Likewise, it is highly recommended to use proguard to clean up your project upon release.
All KAU components support proguard out of the box.
Some may have extra requirements for certain features, which will be detailed in their respective README.
Some may have extra requirements for certain features, which will be detailed in their respective README.

## Translations

KAU depends on translations crowdsourced by the general public.
If you would like to contribute, please visit [here](https://crwd.in/kotlin-android-utils)
6 changes: 3 additions & 3 deletions about/src/main/kotlin/ca/allanwang/kau/about/FaqIItem.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package ca.allanwang.kau.about

import android.annotation.SuppressLint
import android.support.v7.widget.RecyclerView
import android.text.method.LinkMovementMethod
import android.view.View
Expand All @@ -22,9 +23,7 @@ class FaqIItem(val content: FaqItem) : KauIItem<LibraryIItem, FaqIItem.ViewHolde
), ThemableIItem by ThemableIItemDelegate() {

companion object {


@JvmStatic fun bindEvents(fastAdapter: FastAdapter<IItem<*, *>>) {
fun bindEvents(fastAdapter: FastAdapter<IItem<*, *>>) {
fastAdapter.withSelectable(false)
.withEventHook(object : ClickEventHook<IItem<*, *>>() {

Expand All @@ -43,6 +42,7 @@ class FaqIItem(val content: FaqItem) : KauIItem<LibraryIItem, FaqIItem.ViewHolde

private var isExpanded = false

@SuppressLint("SetTextI18n")
override fun bindView(holder: ViewHolder, payloads: MutableList<Any>?) {
super.bindView(holder, payloads)
with(holder) {
Expand Down
6 changes: 3 additions & 3 deletions about/src/main/kotlin/ca/allanwang/kau/about/LibraryIItem.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class LibraryIItem(val lib: Library) : KauIItem<LibraryIItem, LibraryIItem.ViewH
), ThemableIItem by ThemableIItemDelegate() {

companion object {
@JvmStatic fun bindEvents(fastAdapter: FastAdapter<IItem<*, *>>) {
fun bindEvents(fastAdapter: FastAdapter<IItem<*, *>>) {
fastAdapter.withSelectable(false)
.withOnClickListener { v, _, item, _ ->
if (item !is LibraryIItem) false
Expand Down Expand Up @@ -53,11 +53,11 @@ class LibraryIItem(val lib: Library) : KauIItem<LibraryIItem, LibraryIItem.ViewH
Html.fromHtml(lib.libraryDescription, Html.FROM_HTML_MODE_LEGACY)
else Html.fromHtml(lib.libraryDescription)
bottomDivider.gone()
if (lib.libraryVersion?.isNotBlank() ?: false) {
if (lib.libraryVersion?.isNotBlank() == true) {
bottomDivider.visible()
version.visible().text = lib.libraryVersion
}
if (lib.license?.licenseName?.isNotBlank() ?: false) {
if (lib.license?.licenseName?.isNotBlank() == true) {
bottomDivider.visible()
license.visible().text = lib.license?.licenseName
}
Expand Down
5 changes: 0 additions & 5 deletions about/src/main/res/values/strings.xml

This file was deleted.

23 changes: 4 additions & 19 deletions about/src/main/res/values/strings_about.xml
Original file line number Diff line number Diff line change
@@ -1,20 +1,5 @@
<resources xmlns:tools="http://schemas.android.com/tools" tools:ignore="ResourceName">
<string name="define_kau"/>
<string name="library_kau_author">Allan Wang</string>
<string name="library_kau_authorWebsite">https://www.allanwang.ca/dev/</string>
<string name="library_kau_libraryVersion">@string/kau_version_code</string>
<string name="library_kau_libraryName">KAU</string>
<string name="library_kau_libraryDescription">
<![CDATA[
An extensive collection of Kotlin Android Utilities.
<br/><br/>
KAU aims to make many common functions executable in one line. It adds numerous extensions to match Kotlin\'s DSL,
and supports completely customizable view groups that are usable in any app project.
]]>
</string>
<string name="library_kau_libraryWebsite">https://allanwang.github.io/KAU/</string>
<string name="library_kau_isOpenSource">true</string>
<string name="library_kau_repositoryLink">https://github.com/AllanWang/KAU</string>
<string name="library_kau_classPath">ca.allanwang.kau</string>
<string name="library_kau_licenseId">apache_2_0</string>
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="kau_about_libraries_intro">This app would not be possible without the following great libraries.</string>
<string name="kau_about_faq_intro">FAQ</string>
</resources>
20 changes: 20 additions & 0 deletions about/src/main/res/values/strings_about_kau.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<resources xmlns:tools="http://schemas.android.com/tools" tools:ignore="ResourceName">
<string name="define_kau"/>
<string name="library_kau_author">Allan Wang</string>
<string name="library_kau_authorWebsite">https://www.allanwang.ca/dev/</string>
<string name="library_kau_libraryVersion">@string/kau_version_code</string>
<string name="library_kau_libraryName">KAU</string>
<string name="library_kau_libraryDescription">
<![CDATA[
An extensive collection of Kotlin Android Utilities.
<br/><br/>
KAU aims to make many common functions executable in one line. It adds numerous extensions to match Kotlin\'s DSL,
and supports completely customizable view groups that are usable in any app project.
]]>
</string>
<string name="library_kau_libraryWebsite">https://allanwang.github.io/KAU/</string>
<string name="library_kau_isOpenSource">true</string>
<string name="library_kau_repositoryLink">https://github.com/AllanWang/KAU</string>
<string name="library_kau_classPath">ca.allanwang.kau</string>
<string name="library_kau_licenseId">apache_2_0</string>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class CardIItem(
), ThemableIItem by ThemableIItemDelegate() {

companion object {
@JvmStatic fun bindClickEvents(fastAdapter: FastAdapter<IItem<*, *>>) {
fun bindClickEvents(fastAdapter: FastAdapter<IItem<*, *>>) {
fastAdapter.withEventHook(object : ClickEventHook<IItem<*, *>>() {
override fun onBindMany(viewHolder: RecyclerView.ViewHolder): List<View>? {
return if (viewHolder is ViewHolder) listOf(viewHolder.card, viewHolder.button) else null
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ buildscript {
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0-beta6'
classpath 'com.android.tools.build:gradle:3.0.0-beta7'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${KOTLIN}"
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.0'
classpath 'com.github.triplet.gradle:play-publisher:1.2.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,6 @@ class CircleView @JvmOverloads constructor(context: Context, attrs: AttributeSet
companion object {

@ColorInt
@JvmStatic
private fun translucentColor(color: Int): Int {
val factor = 0.7f
val alpha = Math.round(Color.alpha(color) * factor)
Expand All @@ -205,7 +204,6 @@ class CircleView @JvmOverloads constructor(context: Context, attrs: AttributeSet
}

@ColorInt
@JvmStatic
fun shiftColor(@ColorInt color: Int,
@FloatRange(from = 0.0, to = 2.0) by: Float): Int {
if (by == 1f) return color
Expand All @@ -215,11 +213,9 @@ class CircleView @JvmOverloads constructor(context: Context, attrs: AttributeSet
}

@ColorInt
@JvmStatic
fun shiftColorDown(@ColorInt color: Int): Int = shiftColor(color, 0.9f)

@ColorInt
@JvmStatic
fun shiftColorUp(@ColorInt color: Int): Int = shiftColor(color, 1.1f)
}
}
File renamed without changes.
12 changes: 7 additions & 5 deletions core-ui/src/main/kotlin/ca/allanwang/kau/ui/views/CutoutView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -147,14 +147,16 @@ class CutoutView @JvmOverloads constructor(
paint.textSize = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_PX, mid, metrics)
val maxLineWidth = paint.measureText(text)

return if (high - low < precision) low
else if (maxLineWidth > targetWidth) getSingleLineTextSize(text, paint, targetWidth, low, mid, precision, metrics)
else if (maxLineWidth < targetWidth) getSingleLineTextSize(text, paint, targetWidth, mid, high, precision, metrics)
else mid
return when {
high - low < precision -> low
maxLineWidth > targetWidth -> getSingleLineTextSize(text, paint, targetWidth, low, mid, precision, metrics)
maxLineWidth < targetWidth -> getSingleLineTextSize(text, paint, targetWidth, mid, high, precision, metrics)
else -> mid
}
}

private fun createBitmap() {
if (!(cutout?.isRecycled ?: true))
if (cutout?.isRecycled == false)
cutout?.recycle()
if (width == 0 || height == 0) return
cutout = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888)
Expand Down
28 changes: 27 additions & 1 deletion core/src/main/kotlin/ca/allanwang/kau/logging/KauLogger.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,33 @@ import android.util.Log
*
* Base logger class with a predefined tag
* This may be extended by an object to effectively replace [Log]
* Almost everything is opened to make everything customizable
*/
open class KauLogger(val tag: String) {

/**
* Global toggle to enable the whole logger
*/
open var enabled = true

/**
* Global toggle to show private text
*/
open var showPrivateText = false

/**
* If both msg and priv msg are accepted, output the combined output
*/
open var messageJoiner: (msg: String, privMsg: String) -> String = { msg, privMsg -> "$msg: $privMsg" }

/**
* Open hook to change the output of the logger (for instance, output to stdout rather than Android log files
* Does not use reference notation to avoid constructor leaks
*/
open var logFun: (priority: Int, message: String?, privateMessage: String?, t: Throwable?) -> Unit = { p, m, pm, t ->
logImpl(p, m, pm, t)
}

/**
* Filter pass-through to decide what we wish to log
* By default, we will ignore verbose and debug logs
Expand All @@ -35,14 +55,20 @@ open class KauLogger(val tag: String) {
showPrivateText = enable
}

open fun log(priority: Int, message: String?, privateMessage: String?, t: Throwable? = null) {
private fun log(priority: Int, message: String?, privateMessage: String?, t: Throwable? = null) {
if (!shouldLog(priority, message, privateMessage, t)) return
logImpl(priority, message, privateMessage, t)
}

/**
* Condition to pass to allow the input to be logged
*/
protected open fun shouldLog(priority: Int, message: String?, privateMessage: String?, t: Throwable?): Boolean
= enabled && filter(priority)

/**
* Base implementation of the Android logger
*/
protected open fun logImpl(priority: Int, message: String?, privateMessage: String?, t: Throwable?) {
val text = if (showPrivateText) {
if (message == null) privateMessage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import java.lang.ref.WeakReference
*/
internal object PermissionManager {

var requestInProgress = false
val pendingResults: MutableList<WeakReference<PermissionResult>> by lazy { mutableListOf<WeakReference<PermissionResult>>() }
private var requestInProgress = false
private val pendingResults: MutableList<WeakReference<PermissionResult>> by lazy { mutableListOf<WeakReference<PermissionResult>>() }

/**
* Retrieve permissions requested in our manifest
Expand Down Expand Up @@ -63,7 +63,7 @@ internal object PermissionManager {
val iter = pendingResults.iterator()
while (iter.hasNext()) {
val action = iter.next().get()
if ((0 until count).any { action?.onResult(permissions[it], grantResults[it]) ?: true })
if ((0 until count).any { action?.onResult(permissions[it], grantResults[it]) != false })
iter.remove()
}
if (pendingResults.isEmpty())
Expand Down
18 changes: 11 additions & 7 deletions core/src/main/kotlin/ca/allanwang/kau/swipe/SwipeBackLayout.kt
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ internal class SwipeBackLayout @JvmOverloads constructor(context: Context, attrs
listeners.forEach { it.get()?.onScroll(scrollPercent, contentOffset, edgeFlag) }

if (scrollPercent >= 1) {
if (!(activity?.isFinishing ?: true)) {
if (activity?.isFinishing == false) {
if (scrollPercent >= scrollThreshold && isScrollOverValid) {
isScrollOverValid = false
listeners.forEach { it.get()?.onScrollToClose(edgeFlag) }
Expand Down Expand Up @@ -390,15 +390,19 @@ internal class SwipeBackLayout @JvmOverloads constructor(context: Context, attrs
}

override fun clampViewPositionHorizontal(child: View, left: Int, dx: Int): Int {
return if (edgeFlag == SWIPE_EDGE_RIGHT) Math.min(0, Math.max(left, -child.width))
else if (edgeFlag == SWIPE_EDGE_LEFT) Math.min(child.width, Math.max(left, 0))
else 0
return when (edgeFlag) {
SWIPE_EDGE_RIGHT -> Math.min(0, Math.max(left, -child.width))
SWIPE_EDGE_LEFT -> Math.min(child.width, Math.max(left, 0))
else -> 0
}
}

override fun clampViewPositionVertical(child: View, top: Int, dy: Int): Int {
return if (edgeFlag == SWIPE_EDGE_BOTTOM) Math.min(0, Math.max(top, -child.height))
else if (edgeFlag == SWIPE_EDGE_TOP) Math.min(child.height, Math.max(top, 0))
else 0
return when (edgeFlag) {
SWIPE_EDGE_BOTTOM -> Math.min(0, Math.max(top, -child.height))
SWIPE_EDGE_TOP -> Math.min(child.height, Math.max(top, 0))
else -> 0
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion core/src/main/kotlin/ca/allanwang/kau/xml/Changelog.kt
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ internal enum class ChangelogType(val tag: String, val attr: String, @LayoutRes
ITEM("item", "text", R.layout.kau_changelog_content);

companion object {
@JvmStatic val values = values()
val values = values()
}

/**
Expand Down
15 changes: 11 additions & 4 deletions docs/Changelog.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
# Changelog

## v3.4.1
* Validate context before showing dialogs
* Add intent resolver checks prior to all executions.
* Fix bundle NPE when starting activity
## v3.4.4
* Add translation support for crowdin
* Update dependencies
* :mediapicker: Validate document uri before parsing
* :searchview: Ignore casing for highlights

## v3.4.3
* :core: Validate context before showing dialogs
* :core: Add intent resolver checks prior to all executions.
* :core: Fix bundle NPE when starting activity
* :kpref-activity: Create timePicker

## v3.4.0
* Update to gradle 4.x; api and implementation rather than compile
Expand Down
10 changes: 5 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@ APP_GROUP=ca.allanwang
CORE_MIN_SDK=19
MIN_SDK=21
TARGET_SDK=26
BUILD_TOOLS=26.0.1
BUILD_TOOLS=26.0.2
ANDROID_SUPPORT_LIBS=26.1.0

VERSION_NAME=3.4.3
VERSION_NAME=3.4.4

KOTLIN=1.1.4-3
KOTLIN=1.1.51
ABOUT_LIBRARIES=5.9.7
ANKO=0.10.1
BLURRY=2.1.1
CONSTRAINT_LAYOUT=1.1.0-beta1
CONSTRAINT_LAYOUT=1.1.0-beta2
FAST_ADAPTER=2.6.3
FAST_ADAPTER_COMMONS=2.6.3
GLIDE=4.1.1
GLIDE=4.2.0
ICONICS=2.9.3
IICON_GOOGLE=3.0.1.1
MATERIAL_DIALOG=0.9.4.7
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ data class MediaModel(
@Throws(SQLException::class)
constructor(@NonNull cursor: Cursor) : this(
cursor.getString(0),
cursor.getString(1),
cursor.getString(1) ?: "",
cursor.getLong(2),
cursor.getLong(3),
cursor.getString(4)
Expand Down
Loading

0 comments on commit afc1a02

Please sign in to comment.