aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2017-11-09 01:54:02 -0500
committerGitHub <noreply@github.com>2017-11-09 01:54:02 -0500
commit637851b6ddc4a22583797a45bdbb72eb9c6dac23 (patch)
tree68b5a496ea3c8783fa61748c74a88fb692df553b
parent98e8a962c419d49de6e6050bf834f4d490932aa9 (diff)
downloadkau-637851b6ddc4a22583797a45bdbb72eb9c6dac23.tar.gz
kau-637851b6ddc4a22583797a45bdbb72eb9c6dac23.tar.bz2
kau-637851b6ddc4a22583797a45bdbb72eb9c6dac23.zip
misc (#97)
* Update translators * Increase debounce test interval * Clean unnecessary adapter files * Update fastadapter * Add fastadapter helper method * Remove external method * Add better wrap * Add more helpers
-rw-r--r--README.md3
-rw-r--r--adapter/src/main/kotlin/ca/allanwang/kau/adapters/AdapterUtils.kt22
-rw-r--r--adapter/src/main/kotlin/ca/allanwang/kau/adapters/ChainedAdapters.kt85
-rw-r--r--adapter/src/main/kotlin/ca/allanwang/kau/adapters/FastItemThemedAdapter.kt11
-rw-r--r--adapter/src/main/kotlin/ca/allanwang/kau/adapters/SectionAdapter.kt13
-rw-r--r--core/src/test/kotlin/ca/allanwang/kau/kotlin/DebounceTest.kt10
-rw-r--r--docs/Changelog.md8
-rw-r--r--gradle.properties18
-rw-r--r--mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaPickerCore.kt13
-rw-r--r--sample/src/main/res/xml/kau_changelog.xml11
10 files changed, 64 insertions, 130 deletions
diff --git a/README.md b/README.md
index 9e44c03..1a76238 100644
--- a/README.md
+++ b/README.md
@@ -156,8 +156,9 @@ Special thanks to the following awesome people for translating significant porti
| Language | Contributors |
|----------|--------------|
| French | [Vincent Kulak](https://github.com/VonOx) &bull; [Jean-Philippe Gravel](https://crowdin.com/profile/wokija) |
-| German | [Bushido1992](https://forum.xda-developers.com/member.php?u=5179246) &bull; [msoehnchen](https://crowdin.com/profile/msoehnchen) &bull; [3LD0mi HA](https://forum.xda-developers.com/member.php?u=5860523) |
+| German | [Bushido1992](https://forum.xda-developers.com/member.php?u=5179246) &bull; [Marcel Soehnchen](https://crowdin.com/profile/msoehnchen) &bull; [3LD0mi HA](https://forum.xda-developers.com/member.php?u=5860523) |
| Korean | [잇스테이크](https://crowdin.com/profile/bexco2010) |
+| Italian | |
| Spanish | [Jahir Fiquitiva](https://jahirfiquitiva.me/) &bull; [Nefi Salazar](https://plus.google.com/u/0/105547968033551087431)|
| Vietnamese | [Alienz](https://crowdin.com/profile/alienyd) |
diff --git a/adapter/src/main/kotlin/ca/allanwang/kau/adapters/AdapterUtils.kt b/adapter/src/main/kotlin/ca/allanwang/kau/adapters/AdapterUtils.kt
new file mode 100644
index 0000000..206c66b
--- /dev/null
+++ b/adapter/src/main/kotlin/ca/allanwang/kau/adapters/AdapterUtils.kt
@@ -0,0 +1,22 @@
+package ca.allanwang.kau.adapters
+
+import com.mikepenz.fastadapter.FastAdapter
+import com.mikepenz.fastadapter.IAdapter
+import com.mikepenz.fastadapter.IItem
+import com.mikepenz.fastadapter.commons.adapters.FastItemAdapter
+
+/**
+ * Created by Allan Wang on 2017-11-08.
+ */
+
+/**
+ * Add kotlin's generic syntax to better support out types
+ */
+fun <T : IItem<*, *>> fastAdapter(vararg adapter: IAdapter<out T>) =
+ FastAdapter.with<T, IAdapter<out T>>(adapter.toList())!!
+
+/**
+ * Helper to get an [IAdapter] directly from a [FastItemAdapter]
+ */
+fun <T : IItem<*, *>> fastAdapter(adapter: IAdapter<out T>, fastAdapter: FastItemAdapter<out T>) =
+ fastAdapter(adapter, fastAdapter.itemAdapter) \ No newline at end of file
diff --git a/adapter/src/main/kotlin/ca/allanwang/kau/adapters/ChainedAdapters.kt b/adapter/src/main/kotlin/ca/allanwang/kau/adapters/ChainedAdapters.kt
deleted file mode 100644
index 2da0cac..0000000
--- a/adapter/src/main/kotlin/ca/allanwang/kau/adapters/ChainedAdapters.kt
+++ /dev/null
@@ -1,85 +0,0 @@
-package ca.allanwang.kau.adapters
-
-import android.support.v7.widget.LinearLayoutManager
-import android.support.v7.widget.RecyclerView
-import ca.allanwang.kau.utils.withLinearAdapter
-import com.mikepenz.fastadapter.IItem
-import com.mikepenz.fastadapter.adapters.HeaderAdapter
-import com.mikepenz.fastadapter.commons.adapters.FastItemAdapter
-import org.jetbrains.anko.collections.forEachReversedWithIndex
-import java.util.*
-
-/**
- * Created by Allan Wang on 2017-06-27.
- *
- * Once bounded to a [RecyclerView], this will
- * - Chain together a list of [HeaderAdapter]s, backed by a generic [FastItemAdapter]
- * - Add a [LinearLayoutManager] to the recycler
- * - Add a listener for when a new adapter segment is being used
- */
-class ChainedAdapters<T>(vararg items: Pair<T, SectionAdapter<*>>) {
- private val chain: MutableList<Pair<T, SectionAdapter<*>>> = mutableListOf(*items)
- val baseAdapter: FastItemAdapter<IItem<*, *>> = FastItemAdapter()
- private val indexStack = Stack<Int>()
- var recycler: RecyclerView? = null
- val firstVisibleItemPosition: Int
- get() = (recycler?.layoutManager as LinearLayoutManager?)?.findFirstVisibleItemPosition() ?: throw IllegalArgumentException("No recyclerview was bounded to the chain adapters")
-
- fun add(vararg items: Pair<T, SectionAdapter<*>>) = add(items.toList())
-
- fun add(items: Collection<Pair<T, SectionAdapter<*>>>): ChainedAdapters<T> {
- if (recycler != null) throw IllegalAccessException("Chain adapter is already bounded to a recycler; cannot add directly.")
- items.map { it.second }.forEachIndexed { index, sectionAdapter -> sectionAdapter.sectionOrder = chain.size + 1 + index }
- chain.addAll(items)
- return this
- }
-
- operator fun get(index: Int) = chain[index]
-
- /**
- * Attaches the chain to a recycler
- * After this stage, any modifications to the adapters must be done through external references
- * You may still get the generic header adapters through the get operator
- * Binding the recycler also involves supplying a callback, which returns
- * the item (T) associated with the adapter,
- * the index (Int) of the current adapter
- * and the dy (Int) as given by the scroll listener
- */
- fun bindRecyclerView(recyclerView: RecyclerView, onAdapterSectionChanged: (item: T, index: Int, dy: Int) -> Unit) {
- if (recycler != null) throw IllegalStateException("Chain adapter is already bounded")
- if (chain.isEmpty()) throw IllegalArgumentException("No adapters have been added to the adapters list")
- //wrap adapters
- chain.map { it.second }.forEachReversedWithIndex { i, headerAdapter ->
- if (i == chain.size - 1) headerAdapter.wrap(baseAdapter)
- else headerAdapter.wrap(chain[i + 1].second)
- }
- recycler = recyclerView
- indexStack.push(0)
- with(recyclerView) {
- withLinearAdapter(chain.first().second)
- addOnScrollListener(object : RecyclerView.OnScrollListener() {
- override fun onScrolled(rv: RecyclerView, dx: Int, dy: Int) {
- super.onScrolled(rv, dx, dy)
- val topPosition = firstVisibleItemPosition
- val currentAdapterIndex = indexStack.peek()
- if (dy > 0) {
- //look ahead from current adapter
- val nextAdapterIndex = (currentAdapterIndex until chain.size).asSequence()
- .firstOrNull {
- val adapter = chain[it].second
- adapter.adapterItemCount > 0 && adapter.getGlobalPosition(adapter.adapterItemCount - 1) >= topPosition
- } ?: currentAdapterIndex
- if (nextAdapterIndex == currentAdapterIndex) return
- indexStack.push(nextAdapterIndex)
- onAdapterSectionChanged(chain[indexStack.peek()].first, indexStack.peek(), dy)
- } else if (currentAdapterIndex == 0) {
- return //All adapters may be empty; in this case, if we are already at the beginning, don't bother checking
- } else if (chain[currentAdapterIndex].second.getGlobalPosition(0) > topPosition) {
- indexStack.pop()
- onAdapterSectionChanged(chain[indexStack.peek()].first, indexStack.peek(), dy)
- }
- }
- })
- }
- }
-} \ No newline at end of file
diff --git a/adapter/src/main/kotlin/ca/allanwang/kau/adapters/FastItemThemedAdapter.kt b/adapter/src/main/kotlin/ca/allanwang/kau/adapters/FastItemThemedAdapter.kt
index b1c281a..c3a1c61 100644
--- a/adapter/src/main/kotlin/ca/allanwang/kau/adapters/FastItemThemedAdapter.kt
+++ b/adapter/src/main/kotlin/ca/allanwang/kau/adapters/FastItemThemedAdapter.kt
@@ -8,9 +8,7 @@ import android.widget.ImageView
import android.widget.TextView
import ca.allanwang.kau.ui.createSimpleRippleDrawable
import ca.allanwang.kau.utils.adjustAlpha
-import com.mikepenz.fastadapter.IExpandable
import com.mikepenz.fastadapter.IItem
-import com.mikepenz.fastadapter.ISubItem
import com.mikepenz.fastadapter.commons.adapters.FastItemAdapter
/**
@@ -100,16 +98,11 @@ class FastItemThemedAdapter<Item : IItem<*, *>>(
return super.setNewList(items)
}
- override fun <T, S> setSubItems(collapsible: T, subItems: List<S>?): T where S : IItem<*, *>?, T : IItem<*, *>?, T : IExpandable<T, S>?, S : ISubItem<Item, T>? {
- injectTheme(subItems)
- return super.setSubItems(collapsible, subItems)
- }
-
- internal fun injectTheme(items: Collection<IItem<*, *>?>?) {
+ private fun injectTheme(items: Collection<IItem<*, *>?>?) {
items?.forEach { injectTheme(it) }
}
- internal fun injectTheme(item: IItem<*, *>?) {
+ protected fun injectTheme(item: IItem<*, *>?) {
if (item is ThemableIItem && item.themeEnabled) {
item.textColor = textColor
item.backgroundColor = backgroundColor
diff --git a/adapter/src/main/kotlin/ca/allanwang/kau/adapters/SectionAdapter.kt b/adapter/src/main/kotlin/ca/allanwang/kau/adapters/SectionAdapter.kt
deleted file mode 100644
index cf7205a..0000000
--- a/adapter/src/main/kotlin/ca/allanwang/kau/adapters/SectionAdapter.kt
+++ /dev/null
@@ -1,13 +0,0 @@
-package ca.allanwang.kau.adapters
-
-import com.mikepenz.fastadapter.IItem
-import com.mikepenz.fastadapter.adapters.HeaderAdapter
-
-/**
- * Created by Allan Wang on 2017-06-27.
- *
- * Extension of [HeaderAdapter] where we can define the order
- */
-class SectionAdapter<Item : IItem<*, *>>(var sectionOrder: Int = 100) : HeaderAdapter<Item>() {
- override fun getOrder(): Int = sectionOrder
-} \ No newline at end of file
diff --git a/core/src/test/kotlin/ca/allanwang/kau/kotlin/DebounceTest.kt b/core/src/test/kotlin/ca/allanwang/kau/kotlin/DebounceTest.kt
index 05345bd..8ccdab3 100644
--- a/core/src/test/kotlin/ca/allanwang/kau/kotlin/DebounceTest.kt
+++ b/core/src/test/kotlin/ca/allanwang/kau/kotlin/DebounceTest.kt
@@ -34,18 +34,18 @@ class DebounceTest {
@Test
fun multipleDebounces() {
var i = 0
- val debounce = debounce<Int>(10) { i += it }
+ val debounce = debounce<Int>(20) { i += it }
debounce(1) //ignore -> i = 0
- Thread.sleep(5)
+ Thread.sleep(10)
assertEquals(0, i)
debounce(2) //accept -> i = 2
- Thread.sleep(15)
+ Thread.sleep(30)
assertEquals(2, i)
debounce(4) //ignore -> i = 2
- Thread.sleep(5)
+ Thread.sleep(10)
assertEquals(2, i)
debounce(8) //accept -> i = 10
- Thread.sleep(15)
+ Thread.sleep(30)
assertEquals(10, i)
}
diff --git a/docs/Changelog.md b/docs/Changelog.md
index f13f21b..45b8e12 100644
--- a/docs/Changelog.md
+++ b/docs/Changelog.md
@@ -1,5 +1,13 @@
# Changelog
+## v3.5.0
+* Update dependencies, many of which with major version increments
+* Add Vietnamese translations
+* Add Italian translations
+* Clean up unnecessary build version support
+* Optimize and refactor old code
+* Add helper methods to enhance FastAdapter for Kotlin
+
## v3.4.5
* Add French translations
* Add Spanish translations
diff --git a/gradle.properties b/gradle.properties
index 3003784..4f368a8 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -23,19 +23,19 @@ TARGET_SDK=26
BUILD_TOOLS=26.0.2
ANDROID_SUPPORT_LIBS=27.0.0
-VERSION_NAME=3.4.4.1
+VERSION_NAME=3.5.0.0
KOTLIN=1.1.51
-ABOUT_LIBRARIES=5.9.7
-ANKO=0.10.1
+ABOUT_LIBRARIES=6.0.0
+ANKO=0.10.2
BLURRY=2.1.1
CONSTRAINT_LAYOUT=1.1.0-beta3
-FAST_ADAPTER=2.6.3
-FAST_ADAPTER_COMMONS=2.6.3
-GLIDE=4.2.0
-ICONICS=2.9.3
-IICON_GOOGLE=3.0.1.1
-MATERIAL_DIALOG=0.9.4.7
+FAST_ADAPTER=3.0.1
+FAST_ADAPTER_COMMONS=3.0.1
+GLIDE=4.3.1
+ICONICS=2.9.5
+IICON_GOOGLE=3.0.1.2
+MATERIAL_DIALOG=0.9.5.0
ESPRESSO=3.0.0
JUNIT=4.12
diff --git a/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaPickerCore.kt b/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaPickerCore.kt
index ec5d2f0..9bab4c4 100644
--- a/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaPickerCore.kt
+++ b/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaPickerCore.kt
@@ -18,6 +18,7 @@ import android.support.v4.content.CursorLoader
import android.support.v4.content.Loader
import android.support.v7.widget.GridLayoutManager
import android.support.v7.widget.RecyclerView
+import ca.allanwang.kau.adapters.fastAdapter
import ca.allanwang.kau.animators.FadeScaleAnimatorAdd
import ca.allanwang.kau.animators.KauAnimator
import ca.allanwang.kau.internal.KauBaseActivity
@@ -29,7 +30,7 @@ import ca.allanwang.kau.utils.toast
import com.bumptech.glide.Glide
import com.bumptech.glide.RequestManager
import com.mikepenz.fastadapter.IItem
-import com.mikepenz.fastadapter.adapters.HeaderAdapter
+import com.mikepenz.fastadapter.adapters.ItemAdapter
import com.mikepenz.fastadapter.commons.adapters.FastItemAdapter
import com.mikepenz.google_material_typeface_library.GoogleMaterial
import com.mikepenz.iconics.IconicsDrawable
@@ -108,7 +109,7 @@ abstract class MediaPickerCore<T : IItem<*, *>>(
private var hasPreloaded = false
private var prefetcher: Future<*>? = null
- val adapter: FastItemAdapter<T> = FastItemAdapter()
+ val adapter = FastItemAdapter<T>()
/**
* Further improve preloading by extending the layout space
@@ -121,9 +122,9 @@ abstract class MediaPickerCore<T : IItem<*, *>>(
}
fun initializeRecycler(recycler: RecyclerView) {
- val adapterWrapper = HeaderAdapter<MediaActionItem>()
- adapterWrapper.wrap(adapter)
- adapterWrapper.add(mediaActions.map { MediaActionItem(it, mediaType) })
+ val adapterHeader = ItemAdapter<MediaActionItem>()
+ val fulladapter = fastAdapter(adapterHeader, adapter)
+ adapterHeader.add(mediaActions.map { MediaActionItem(it, mediaType) })
recycler.apply {
val manager = object : GridLayoutManager(context, computeColumnCount(context)) {
override fun getExtraLayoutSpace(state: RecyclerView.State?): Int {
@@ -133,7 +134,7 @@ abstract class MediaPickerCore<T : IItem<*, *>>(
setItemViewCacheSize(CACHE_SIZE)
isDrawingCacheEnabled = true
layoutManager = manager
- adapter = adapterWrapper
+ adapter = fulladapter
setHasFixedSize(true)
itemAnimator = KauAnimator(FadeScaleAnimatorAdd(0.8f))
}
diff --git a/sample/src/main/res/xml/kau_changelog.xml b/sample/src/main/res/xml/kau_changelog.xml
index b964cb6..4718e09 100644
--- a/sample/src/main/res/xml/kau_changelog.xml
+++ b/sample/src/main/res/xml/kau_changelog.xml
@@ -6,13 +6,20 @@
<item text="" />
-->
+ <version title="v3.5.0" />
+ <item text="Update dependencies, many of which with major version increments" />
+ <item text="Add Vietnamese translations" />
+ <item text="Add Italian translations" />
+ <item text="Clean up unnecessary build version support" />
+ <item text="Optimize and refactor old code" />
+ <item text="Add helper methods to enhance FastAdapter for Kotlin" />
+ <item text="" />
+
<version title="v3.4.5" />
<item text="Add French translations" />
<item text="Add Spanish translations" />
<item text="Add German translations" />
<item text="Remove unnecessary strings" />
- <item text="" />
- <item text="" />
<version title="v3.4.4" />
<item text="Add translation support for crowdin" />