Skip to content

Commit

Permalink
Add AndroidX collections dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisbanes committed Aug 23, 2019
1 parent 650051c commit a524b53
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 9 deletions.
1 change: 1 addition & 0 deletions base-android/build.gradle
Expand Up @@ -46,6 +46,7 @@ dependencies {


implementation Libs.AndroidX.Fragment.fragment implementation Libs.AndroidX.Fragment.fragment
implementation Libs.AndroidX.coreKtx implementation Libs.AndroidX.coreKtx
implementation Libs.AndroidX.collection


implementation Libs.timber implementation Libs.timber
implementation Libs.threeTenAbp implementation Libs.threeTenAbp
Expand Down
16 changes: 9 additions & 7 deletions base-android/src/main/java/app/tivi/SharedElementHelper.kt
Expand Up @@ -17,15 +17,17 @@
package app.tivi package app.tivi


import android.view.View import android.view.View
import androidx.collection.ArrayMap


data class SharedElementHelper( class SharedElementHelper {
private val sharedElementViews: MutableMap<View, String?> = mutableMapOf() private val _sharedElements = ArrayMap<View, String?>()
) {
val sharedElements: Map<View, String?> = sharedElementViews


fun addSharedElement(view: View, name: String? = null) { val sharedElements: Map<View, String?>
sharedElementViews[view] = name ?: view.transitionName get() = _sharedElements

fun addSharedElement(view: View, transitionName: String? = view.transitionName) {
_sharedElements[view] = transitionName ?: view.transitionName
} }


fun isEmpty(): Boolean = sharedElementViews.isEmpty() fun isEmpty(): Boolean = _sharedElements.isEmpty
} }
1 change: 1 addition & 0 deletions buildSrc/src/main/java/app/tivi/buildsrc/dependencies.kt
Expand Up @@ -73,6 +73,7 @@ object Libs {
object AndroidX { object AndroidX {
const val appcompat = "androidx.appcompat:appcompat:1.1.0-rc01" const val appcompat = "androidx.appcompat:appcompat:1.1.0-rc01"
const val browser = "androidx.browser:browser:1.0.0" const val browser = "androidx.browser:browser:1.0.0"
const val collection = "androidx.collection:collection-ktx:1.1.0"
const val palette = "androidx.palette:palette:1.0.0" const val palette = "androidx.palette:palette:1.0.0"
const val recyclerview = "androidx.recyclerview:recyclerview:1.1.0-beta03" const val recyclerview = "androidx.recyclerview:recyclerview:1.1.0-beta03"
const val emoji = "androidx.emoji:emoji:1.0.0" const val emoji = "androidx.emoji:emoji:1.0.0"
Expand Down
1 change: 1 addition & 0 deletions data/build.gradle
Expand Up @@ -32,6 +32,7 @@ dependencies {


api Libs.AndroidX.Room.common api Libs.AndroidX.Room.common
api Libs.AndroidX.Room.ktx api Libs.AndroidX.Room.ktx
implementation Libs.AndroidX.collection


api Libs.AndroidX.Paging.common api Libs.AndroidX.Paging.common


Expand Down
Expand Up @@ -16,14 +16,15 @@


package app.tivi.data.repositories.search package app.tivi.data.repositories.search


import androidx.collection.LruCache
import javax.inject.Inject import javax.inject.Inject


class SearchStore @Inject constructor() { class SearchStore @Inject constructor() {
private val cache = HashMap<String, LongArray>() private val cache = LruCache<String, LongArray>(32)


fun getResults(query: String) = cache[query] fun getResults(query: String) = cache[query]


fun setResults(query: String, results: LongArray) { fun setResults(query: String, results: LongArray) {
cache[query] = results cache.put(query, results)
} }
} }

0 comments on commit a524b53

Please sign in to comment.