aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2017-08-12 10:09:01 -0700
committerGitHub <noreply@github.com>2017-08-12 10:09:01 -0700
commit10617f02a95b162695ea068c0be6acceda74cf35 (patch)
tree06943d13034cbcf0e7bdd01960162e62952bb51c
parent02e1dbc84425b0ac7f771c82f70444f742397452 (diff)
downloadkau-10617f02a95b162695ea068c0be6acceda74cf35.tar.gz
kau-10617f02a95b162695ea068c0be6acceda74cf35.tar.bz2
kau-10617f02a95b162695ea068c0be6acceda74cf35.zip
Release 3.3.1 (#36)3.3.1
* Add open message joiner function * Update text extraction * Fix background tint * Rename logger file * Test codecov * Remove coverage * Enhancement/swipe (#35) * Merge swipe onPostCreate with swipe onCreate * Update samples and docs * Add deprecated method to maintain compatibility * Replace exception with illegal argument * Check if parent exists before configurations in searchview
-rw-r--r--core/src/main/kotlin/ca/allanwang/kau/logging/KauLogger.kt (renamed from core/src/main/kotlin/ca/allanwang/kau/logging/TimberLogger.kt)14
-rw-r--r--core/src/main/kotlin/ca/allanwang/kau/swipe/SwipeBackHelper.kt44
-rw-r--r--core/src/main/kotlin/ca/allanwang/kau/swipe/SwipeBackLayout.kt2
-rw-r--r--core/src/main/kotlin/ca/allanwang/kau/utils/Utils.kt18
-rw-r--r--docs/Changelog.md5
-rw-r--r--sample/src/main/kotlin/ca/allanwang/kau/sample/AnimActivity.kt8
-rw-r--r--sample/src/main/kotlin/ca/allanwang/kau/sample/SwipeActivity.kt13
-rw-r--r--sample/src/main/res/xml/kau_changelog.xml11
-rw-r--r--searchview/src/main/kotlin/ca/allanwang/kau/searchview/SearchView.kt11
9 files changed, 80 insertions, 46 deletions
diff --git a/core/src/main/kotlin/ca/allanwang/kau/logging/TimberLogger.kt b/core/src/main/kotlin/ca/allanwang/kau/logging/KauLogger.kt
index 2fbecf5..14655f0 100644
--- a/core/src/main/kotlin/ca/allanwang/kau/logging/TimberLogger.kt
+++ b/core/src/main/kotlin/ca/allanwang/kau/logging/KauLogger.kt
@@ -16,6 +16,7 @@ open class KauLogger(val tag: String) {
open var enabled = true
open var showPrivateText = false
+ open var messageJoiner: (msg: String, privMsg: String) -> String = { msg, privMsg -> "$msg: $privMsg" }
/**
* Filter pass-through to decide what we wish to log
@@ -43,11 +44,14 @@ open class KauLogger(val tag: String) {
= enabled && filter(priority)
protected open fun logImpl(priority: Int, message: String?, privateMessage: String?, t: Throwable?) {
- var text = message ?: ""
- if (showPrivateText && privateMessage != null)
- text += "\n-\t$privateMessage"
- if (t != null) Log.e(tag, text, t)
- else if (text.isNotBlank()) Log.println(priority, tag, text)
+ val text = if (showPrivateText) {
+ if (message == null) privateMessage
+ else if (privateMessage == null) message
+ else messageJoiner(message, privateMessage)
+ } else message
+
+ if (t != null) Log.e(tag, text ?: "Error", t)
+ else if (!text.isNullOrBlank()) Log.println(priority, tag, text)
}
open fun v(text: String?, privateText: String? = null) = log(Log.VERBOSE, text, privateText)
diff --git a/core/src/main/kotlin/ca/allanwang/kau/swipe/SwipeBackHelper.kt b/core/src/main/kotlin/ca/allanwang/kau/swipe/SwipeBackHelper.kt
index 0859ac5..bc909be 100644
--- a/core/src/main/kotlin/ca/allanwang/kau/swipe/SwipeBackHelper.kt
+++ b/core/src/main/kotlin/ca/allanwang/kau/swipe/SwipeBackHelper.kt
@@ -7,8 +7,6 @@ import ca.allanwang.kau.logging.KL
import ca.allanwang.kau.swipe.SwipeBackHelper.onDestroy
import java.util.*
-internal class SwipeBackException(message: String = "You Should call kauSwipeOnCreate() first") : RuntimeException(message)
-
/**
* Singleton to hold our swipe stack
* All activity pages held with strong references, so it is crucial to call
@@ -30,14 +28,10 @@ internal object SwipeBackHelper {
else -> R.anim.kau_slide_in_top
}
activity.overridePendingTransition(startAnimation, 0)
+ page.onPostCreate()
KL.v("KauSwipe onCreate ${activity.localClassName}")
}
- fun onPostCreate(activity: Activity) {
- this[activity]?.onPostCreate() ?: throw SwipeBackException()
- KL.v("KauSwipe onPostCreate ${activity.localClassName}")
- }
-
fun onDestroy(activity: Activity) {
val page: SwipeBackPage? = this[activity]
pageStack.kauRemoveIf { it.activityRef.get() == null || it === page }
@@ -55,17 +49,43 @@ internal object SwipeBackHelper {
}
/**
- * The following are the activity bindings to add an activity to the stack
- * onCreate, onPostCreate, and onDestroy are mandatory
- * finish is there as a helper method to animate the transaction
+ * The creation binder, which adds the swipe functionality to an activity.
+ * Call this during [Activity.onCreate] after all views are added.
+ *
+ * Preferably, this should be the last line in the onCreate method.
+ * Note that this will also capture your statusbar color and nav bar color,
+ * so be sure to assign those beforehand if at all.
+ *
+ * Lastly, don't forget to call [kauSwipeOnDestroy] as well when the activity is destroyed.
*/
fun Activity.kauSwipeOnCreate(builder: SwipeBackContract.() -> Unit = {}) = SwipeBackHelper.onCreate(this, builder)
-fun Activity.kauSwipeOnPostCreate() = SwipeBackHelper.onPostCreate(this)
+/**
+ * Deprecated as onPostCreate seems unreliable.
+ * We will instead initialize everything during [kauSwipeOnCreate]
+ */
+@Deprecated(level = DeprecationLevel.WARNING, message = "All functionality has been moved to kauSwipeOnCreate")
+fun Activity.kauSwipeOnPostCreate() {
+}
+
+/**
+ * The unbinder, which removes our layouts, releases our weak references, and cleans our page stack
+ * Call this during [Activity.onDestroy]
+ *
+ * Given that our references are held weakly, we allow failures and missing pages to pass silently
+ * as they should be destroyed anyways.
+ *
+ * Don't forget to call [kauSwipeOnCreate] when the activity is created to enable swipe functionality.
+ */
fun Activity.kauSwipeOnDestroy() = SwipeBackHelper.onDestroy(this)
-fun Activity.kauSwipeFinish() = SwipeBackHelper.finish(this)
/**
+ * Helper function for activities to animate the finish transaction with a pseudo swipe
+ * The activity will automatically be finished afterwards
+ */
+fun Activity.kauSwipeFinish() = SwipeBackHelper.finish(this)
+
+/*
* Constants used for the swipe edge flags
*/
const val SWIPE_EDGE_LEFT = ViewDragHelper.EDGE_LEFT
diff --git a/core/src/main/kotlin/ca/allanwang/kau/swipe/SwipeBackLayout.kt b/core/src/main/kotlin/ca/allanwang/kau/swipe/SwipeBackLayout.kt
index 51cd17f..c0875d1 100644
--- a/core/src/main/kotlin/ca/allanwang/kau/swipe/SwipeBackLayout.kt
+++ b/core/src/main/kotlin/ca/allanwang/kau/swipe/SwipeBackLayout.kt
@@ -115,7 +115,7 @@ internal class SwipeBackLayout @JvmOverloads constructor(context: Context, attrs
*/
set(value) {
if (value !in arrayOf(SWIPE_EDGE_TOP, SWIPE_EDGE_BOTTOM, SWIPE_EDGE_LEFT, SWIPE_EDGE_RIGHT))
- throw SwipeBackException("Edge flag is not valid; use one of the SWIPE_EDGE_* values")
+ throw IllegalArgumentException("Edge flag is not valid; use one of the SWIPE_EDGE_* values")
field = value
horizontal = edgeFlag == SWIPE_EDGE_LEFT || edgeFlag == SWIPE_EDGE_RIGHT
dragHelper.setEdgeTrackingEnabled(value)
diff --git a/core/src/main/kotlin/ca/allanwang/kau/utils/Utils.kt b/core/src/main/kotlin/ca/allanwang/kau/utils/Utils.kt
index 2f3e9a5..9e0ad75 100644
--- a/core/src/main/kotlin/ca/allanwang/kau/utils/Utils.kt
+++ b/core/src/main/kotlin/ca/allanwang/kau/utils/Utils.kt
@@ -7,10 +7,8 @@ import android.graphics.Canvas
import android.graphics.drawable.BitmapDrawable
import android.graphics.drawable.Drawable
import android.os.Handler
-import android.os.Looper
import android.support.annotation.IntRange
import ca.allanwang.kau.R
-import ca.allanwang.kau.logging.KL
import java.math.RoundingMode
import java.text.DecimalFormat
@@ -30,13 +28,25 @@ annotation class KauUtils
get() = this * Resources.getSystem().displayMetrics.density
@KauUtils inline val Int.dpToPx: Int
- get() = (this * Resources.getSystem().displayMetrics.density).toInt()
+ get() = toFloat().dpToPx.toInt()
@KauUtils inline val Float.pxToDp: Float
get() = this / Resources.getSystem().displayMetrics.density
@KauUtils inline val Int.pxToDp: Int
- get() = (this / Resources.getSystem().displayMetrics.density).toInt()
+ get() = toFloat().pxToDp.toInt()
+
+@KauUtils inline val Float.dpToSp: Float
+ get() = this * Resources.getSystem().displayMetrics.scaledDensity
+
+@KauUtils inline val Int.dpToSp: Int
+ get() = toFloat().dpToSp.toInt()
+
+@KauUtils inline val Float.spToDp: Float
+ get() = this / Resources.getSystem().displayMetrics.scaledDensity
+
+@KauUtils inline val Int.spToDp: Int
+ get() = toFloat().spToDp.toInt()
/**
* Converts minute value to string
diff --git a/docs/Changelog.md b/docs/Changelog.md
index 0fe867a..a69171e 100644
--- a/docs/Changelog.md
+++ b/docs/Changelog.md
@@ -1,5 +1,10 @@
# Changelog
+## v3.3.1
+* :core: Open up all logger functions
+* :core: Deprecate kauSwipeOnPostCreate and move functionality to onCreate
+* :searchview: Fix background tint
+
## v3.3.0
* :core: Create debounce methods
* :core: Create zip methods
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 cd86d38..f052d97 100644
--- a/sample/src/main/kotlin/ca/allanwang/kau/sample/AnimActivity.kt
+++ b/sample/src/main/kotlin/ca/allanwang/kau/sample/AnimActivity.kt
@@ -10,7 +10,6 @@ import ca.allanwang.kau.permissions.kauRequestPermissions
import ca.allanwang.kau.swipe.SWIPE_EDGE_LEFT
import ca.allanwang.kau.swipe.kauSwipeOnCreate
import ca.allanwang.kau.swipe.kauSwipeOnDestroy
-import ca.allanwang.kau.swipe.kauSwipeOnPostCreate
import ca.allanwang.kau.utils.fullLinearRecycler
import ca.allanwang.kau.utils.startActivitySlideOut
import ca.allanwang.kau.utils.toast
@@ -49,14 +48,9 @@ class AnimActivity : KauBaseActivity() {
}
}
- override fun onPostCreate(savedInstanceState: Bundle?) {
- super.onPostCreate(savedInstanceState)
- kauSwipeOnPostCreate()
- }
-
override fun onDestroy() {
- super.onDestroy()
kauSwipeOnDestroy()
+ super.onDestroy()
}
override fun onBackPressed() {
diff --git a/sample/src/main/kotlin/ca/allanwang/kau/sample/SwipeActivity.kt b/sample/src/main/kotlin/ca/allanwang/kau/sample/SwipeActivity.kt
index cba9ccd..da088cf 100644
--- a/sample/src/main/kotlin/ca/allanwang/kau/sample/SwipeActivity.kt
+++ b/sample/src/main/kotlin/ca/allanwang/kau/sample/SwipeActivity.kt
@@ -40,9 +40,6 @@ class SwipeActivity : KauBaseActivity() {
it.setOnClickListener { startActivityWithEdge(swipeEdge) }
}
val flag = intent.getIntExtra(SWIPE_EDGE, -1)
- kauSwipeOnCreate {
- edgeFlag = flag
- }
toolbar.title = when (flag) {
SWIPE_EDGE_LEFT -> "Left Edge Swipe"
SWIPE_EDGE_RIGHT -> "Right Edge Swipe"
@@ -57,16 +54,14 @@ class SwipeActivity : KauBaseActivity() {
val bg = headerColor.darken(0.2f)
container.setBackgroundColor(bg)
navigationBarColor = bg
- }
-
- override fun onPostCreate(savedInstanceState: Bundle?) {
- super.onPostCreate(savedInstanceState)
- kauSwipeOnPostCreate()
+ kauSwipeOnCreate {
+ edgeFlag = flag
+ }
}
override fun onDestroy() {
- super.onDestroy()
kauSwipeOnDestroy()
+ super.onDestroy()
}
override fun onBackPressed() {
diff --git a/sample/src/main/res/xml/kau_changelog.xml b/sample/src/main/res/xml/kau_changelog.xml
index 6008ae1..fd3113c 100644
--- a/sample/src/main/res/xml/kau_changelog.xml
+++ b/sample/src/main/res/xml/kau_changelog.xml
@@ -6,6 +6,14 @@
<item text="" />
-->
+ <version title="v3.3.1"/>
+ <item text=":core: Open up all logger functions" />
+ <item text=":core: Deprecate kauSwipeOnPostCreate and move functionality to onCreate" />
+ <item text=":searchview: Fix background tint" />
+ <item text="" />
+ <item text="" />
+ <item text="" />
+
<version title="v3.3.0"/>
<item text=":core: Create debounce methods" />
<item text=":core: Create zip methods" />
@@ -14,9 +22,6 @@
<item text=":kpref-activity: [Breaking] Removed sliding toolbar and use normal toolbar title" />
<item text=":kpref-activity: Remove :core-ui: dependency" />
<item text=":searchview: [Breaking] remove reactive dependencies and stick with basic callbacks" />
- <item text="" />
- <item text="" />
- <item text="" />
<version title="v3.2.5"/>
<item text=":core: Fix FAQ background" />
diff --git a/searchview/src/main/kotlin/ca/allanwang/kau/searchview/SearchView.kt b/searchview/src/main/kotlin/ca/allanwang/kau/searchview/SearchView.kt
index cc56289..1376115 100644
--- a/searchview/src/main/kotlin/ca/allanwang/kau/searchview/SearchView.kt
+++ b/searchview/src/main/kotlin/ca/allanwang/kau/searchview/SearchView.kt
@@ -10,7 +10,6 @@ import android.support.transition.ChangeBounds
import android.support.transition.TransitionManager
import android.support.transition.TransitionSet
import android.support.v7.widget.AppCompatEditText
-import android.support.v7.widget.LinearLayoutManager
import android.support.v7.widget.RecyclerView
import android.text.Editable
import android.text.TextWatcher
@@ -153,7 +152,7 @@ class SearchView @JvmOverloads constructor(
}
if (SearchItem.backgroundColor != backgroundColor) {
SearchItem.backgroundColor = backgroundColor
- tintForeground(backgroundColor)
+ tintBackground(backgroundColor)
}
val icons = mutableListOf(navIcon to iconNav, clearIcon to iconClear)
val extra = extraIcon
@@ -291,11 +290,12 @@ class SearchView @JvmOverloads constructor(
*/
fun bind(menu: Menu, @IdRes id: Int, @ColorInt menuIconColor: Int = Color.WHITE, config: Configs.() -> Unit = {}): SearchView {
config(config)
- menuItem = menu.findItem(id) ?: throw IllegalArgumentException("Menu item with given id doesn't exist")
- if (menuItem!!.icon == null) menuItem!!.icon = GoogleMaterial.Icon.gmd_search.toDrawable(context, 18, menuIconColor)
+ val menuItem = menu.findItem(id) ?: throw IllegalArgumentException("Menu item with given id doesn't exist")
+ if (menuItem.icon == null) menuItem.icon = GoogleMaterial.Icon.gmd_search.toDrawable(context, 18, menuIconColor)
card.gone()
- menuItem!!.setOnMenuItemClickListener { configureCoords(it); revealOpen(); true }
+ menuItem.setOnMenuItemClickListener { configureCoords(it); revealOpen(); true }
shadow.setOnClickListener { revealClose() }
+ this.menuItem = menuItem
return this
}
@@ -310,6 +310,7 @@ class SearchView @JvmOverloads constructor(
}
private fun configureCoords(item: MenuItem) {
+ if (parent !is ViewGroup) return
val view = parentViewGroup.findViewById<View>(item.itemId) ?: return
val locations = IntArray(2)
view.getLocationOnScreen(locations)