aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--about/build.gradle4
-rw-r--r--about/src/main/kotlin/ca/allanwang/kau/about/AboutActivityBase.kt4
-rw-r--r--about/src/main/kotlin/ca/allanwang/kau/about/AboutPanelDelegate.kt14
-rw-r--r--about/src/main/kotlin/ca/allanwang/kau/about/CutoutIItem.kt6
-rw-r--r--about/src/main/kotlin/ca/allanwang/kau/about/FaqIItem.kt36
-rw-r--r--about/src/main/kotlin/ca/allanwang/kau/about/LibraryIItem.kt31
-rw-r--r--adapter/build.gradle4
-rw-r--r--android-lib.gradle24
-rw-r--r--build.gradle19
-rw-r--r--buildSrc/src/main/kotlin/kau/Dependencies.kt11
-rw-r--r--buildSrc/src/main/kotlin/kau/Versions.kt8
-rw-r--r--core-ui/src/main/kotlin/ca/allanwang/kau/ui/widgets/ElasticDragDismissFrameLayout.kt1
-rw-r--r--core/src/main/kotlin/ca/allanwang/kau/kpref/KPrefBuilder.kt17
-rw-r--r--core/src/main/kotlin/ca/allanwang/kau/kpref/KPrefSingleDelegate.kt2
-rw-r--r--core/src/main/kotlin/ca/allanwang/kau/permissions/Permissions.kt4
-rw-r--r--core/src/main/kotlin/ca/allanwang/kau/utils/IIconUtils.kt15
-rw-r--r--core/src/main/kotlin/ca/allanwang/kau/utils/Kotterknife.kt6
-rw-r--r--docs/Changelog.md3
-rw-r--r--fastadapter/build.gradle9
-rw-r--r--fastadapter/src/main/kotlin/ca/allanwang/kau/adapters/AdapterUtils.kt18
-rw-r--r--fastadapter/src/main/kotlin/ca/allanwang/kau/adapters/FastItemThemedAdapter.kt63
-rw-r--r--fastadapter/src/main/kotlin/ca/allanwang/kau/adapters/RepeatedClickListener.kt24
-rw-r--r--fastadapter/src/main/kotlin/ca/allanwang/kau/iitems/CardIItem.kt10
-rw-r--r--fastadapter/src/main/kotlin/ca/allanwang/kau/iitems/HeaderIItem.kt2
-rw-r--r--fastadapter/src/main/kotlin/ca/allanwang/kau/iitems/KauIItem.kt15
-rw-r--r--kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/KPrefActivity.kt15
-rw-r--r--kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefCheckbox.kt5
-rw-r--r--kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefColorPicker.kt10
-rw-r--r--kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefHeader.kt8
-rw-r--r--kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefItemBase.kt8
-rw-r--r--kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefItemCore.kt4
-rw-r--r--kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefPlainText.kt3
-rw-r--r--kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefSeekbar.kt11
-rw-r--r--kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefSubItems.kt6
-rw-r--r--kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefText.kt8
-rw-r--r--kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefTimePicker.kt17
-rw-r--r--mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/BlurredImageView.kt33
-rw-r--r--mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaActionItem.kt16
-rw-r--r--mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaItem.kt34
-rw-r--r--mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaItemBasic.kt21
-rw-r--r--mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaModel.kt2
-rw-r--r--mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaPickerActivityBase.kt30
-rw-r--r--mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaPickerActivityOverlayBase.kt2
-rw-r--r--mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaPickerCore.kt87
-rw-r--r--sample/build.gradle23
-rw-r--r--sample/proguard-rules.pro7
-rw-r--r--sample/src/main/kotlin/ca/allanwang/kau/sample/AboutActivity.kt4
-rw-r--r--sample/src/main/kotlin/ca/allanwang/kau/sample/AdapterActivity.kt6
-rw-r--r--sample/src/main/kotlin/ca/allanwang/kau/sample/AnimActivity.kt10
-rw-r--r--sample/src/main/kotlin/ca/allanwang/kau/sample/MainActivity.kt4
-rw-r--r--sample/src/main/kotlin/ca/allanwang/kau/sample/PermissionCheckbox.kt2
-rw-r--r--sample/src/main/res/xml/kau_changelog.xml5
-rw-r--r--searchview/build.gradle2
-rw-r--r--searchview/src/main/kotlin/ca/allanwang/kau/searchview/SearchItem.kt4
-rw-r--r--searchview/src/main/kotlin/ca/allanwang/kau/searchview/SearchView.kt58
55 files changed, 469 insertions, 326 deletions
diff --git a/about/build.gradle b/about/build.gradle
index b970530..274ef5c 100644
--- a/about/build.gradle
+++ b/about/build.gradle
@@ -1,3 +1,5 @@
+import kau.Dependencies
+
apply from: '../android-lib.gradle'
android {
@@ -10,7 +12,7 @@ dependencies {
implementation project(':core-ui')
implementation project(':fastadapter')
- api kau.Dependencies.aboutLibraries
+ api Dependencies.aboutLibraries
}
apply from: '../artifacts.gradle'
diff --git a/about/src/main/kotlin/ca/allanwang/kau/about/AboutActivityBase.kt b/about/src/main/kotlin/ca/allanwang/kau/about/AboutActivityBase.kt
index 79077c5..452d28c 100644
--- a/about/src/main/kotlin/ca/allanwang/kau/about/AboutActivityBase.kt
+++ b/about/src/main/kotlin/ca/allanwang/kau/about/AboutActivityBase.kt
@@ -33,7 +33,7 @@ import ca.allanwang.kau.utils.INVALID_ID
import ca.allanwang.kau.utils.dimenPixelSize
import com.mikepenz.aboutlibraries.Libs
import com.mikepenz.aboutlibraries.entity.Library
-import com.mikepenz.fastadapter.IItem
+import com.mikepenz.fastadapter.GenericItem
import kotlinx.android.synthetic.main.kau_activity_about.*
/**
@@ -128,7 +128,7 @@ abstract class AboutActivityBase(val rClass: Class<*>?, private val configBuilde
* Open hook called just before the main page view is returned
* Feel free to add your own items to the adapter in here
*/
- open fun postInflateMainPage(adapter: FastItemThemedAdapter<IItem<*, *>>) {
+ open fun postInflateMainPage(adapter: FastItemThemedAdapter<GenericItem>) {
}
/**
diff --git a/about/src/main/kotlin/ca/allanwang/kau/about/AboutPanelDelegate.kt b/about/src/main/kotlin/ca/allanwang/kau/about/AboutPanelDelegate.kt
index a5d9c17..ba7330c 100644
--- a/about/src/main/kotlin/ca/allanwang/kau/about/AboutPanelDelegate.kt
+++ b/about/src/main/kotlin/ca/allanwang/kau/about/AboutPanelDelegate.kt
@@ -34,7 +34,7 @@ import ca.allanwang.kau.utils.string
import ca.allanwang.kau.utils.withMarginDecoration
import ca.allanwang.kau.xml.kauParseFaq
import com.mikepenz.aboutlibraries.Libs
-import com.mikepenz.fastadapter.IItem
+import com.mikepenz.fastadapter.GenericItem
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
@@ -48,11 +48,11 @@ interface AboutPanelContract {
/**
* Model list to be added to [adapter]
*/
- var items: List<IItem<*, *>>?
+ var items: List<GenericItem>
/**
* The adapter, will be late initialized as it depends on configs
*/
- var adapter: FastItemThemedAdapter<IItem<*, *>>
+ var adapter: FastItemThemedAdapter<GenericItem>
/**
* Reference to the recyclerview, will be used to stop scrolling upon exit
*/
@@ -90,9 +90,9 @@ interface AboutPanelContract {
abstract class AboutPanelRecycler : AboutPanelContract {
- override var items: List<IItem<*, *>>? = null
+ override var items: List<GenericItem> = emptyList()
- override lateinit var adapter: FastItemThemedAdapter<IItem<*, *>>
+ override lateinit var adapter: FastItemThemedAdapter<GenericItem>
override var recycler: RecyclerView? = null
@@ -116,7 +116,9 @@ abstract class AboutPanelRecycler : AboutPanelContract {
}
override fun addItems(activity: AboutActivityBase, position: Int) {
- if (items == null) return
+ if (items.isEmpty()) {
+ return
+ }
activity.pageStatus[position] = 2
postDelayed(300) { addItemsImpl(activity, position) }
}
diff --git a/about/src/main/kotlin/ca/allanwang/kau/about/CutoutIItem.kt b/about/src/main/kotlin/ca/allanwang/kau/about/CutoutIItem.kt
index b51c9c8..d51db46 100644
--- a/about/src/main/kotlin/ca/allanwang/kau/about/CutoutIItem.kt
+++ b/about/src/main/kotlin/ca/allanwang/kau/about/CutoutIItem.kt
@@ -27,11 +27,13 @@ import ca.allanwang.kau.ui.views.CutoutView
*
* Just a cutout item with some defaults in [R.layout.kau_iitem_cutout]
*/
-class CutoutIItem(val config: CutoutView.() -> Unit = {}) : KauIItem<CutoutIItem, CutoutIItem.ViewHolder>(
+class CutoutIItem(val config: CutoutView.() -> Unit = {}) : KauIItem<CutoutIItem.ViewHolder>(
R.layout.kau_iitem_cutout, ::ViewHolder, R.id.kau_item_cutout
), ThemableIItem by ThemableIItemDelegate() {
- override fun isSelectable(): Boolean = false
+ override var isSelectable: Boolean
+ get() = false
+ set(_) {}
override fun bindView(holder: ViewHolder, payloads: MutableList<Any>) {
super.bindView(holder, payloads)
diff --git a/about/src/main/kotlin/ca/allanwang/kau/about/FaqIItem.kt b/about/src/main/kotlin/ca/allanwang/kau/about/FaqIItem.kt
index 755ac81..977b7ff 100644
--- a/about/src/main/kotlin/ca/allanwang/kau/about/FaqIItem.kt
+++ b/about/src/main/kotlin/ca/allanwang/kau/about/FaqIItem.kt
@@ -30,31 +30,37 @@ import ca.allanwang.kau.utils.parentViewGroup
import ca.allanwang.kau.utils.setPaddingLeft
import ca.allanwang.kau.xml.FaqItem
import com.mikepenz.fastadapter.FastAdapter
-import com.mikepenz.fastadapter.IItem
+import com.mikepenz.fastadapter.GenericItem
import com.mikepenz.fastadapter.listeners.ClickEventHook
+import com.mikepenz.fastadapter.select.getSelectExtension
/**
* Created by Allan Wang on 2017-08-02.
*/
-class FaqIItem(val content: FaqItem) : KauIItem<LibraryIItem, FaqIItem.ViewHolder>(
+class FaqIItem(val content: FaqItem) : KauIItem<FaqIItem.ViewHolder>(
R.layout.kau_iitem_faq, ::ViewHolder, R.id.kau_item_faq
), ThemableIItem by ThemableIItemDelegate() {
companion object {
- fun bindEvents(fastAdapter: FastAdapter<IItem<*, *>>) {
- fastAdapter.withSelectable(false)
- .withEventHook(object : ClickEventHook<IItem<*, *>>() {
+ fun bindEvents(fastAdapter: FastAdapter<GenericItem>) {
+ fastAdapter.getSelectExtension().isSelectable = true
+ fastAdapter.addEventHook(object : ClickEventHook<GenericItem>() {
- override fun onBind(viewHolder: RecyclerView.ViewHolder): View? =
- (viewHolder as? ViewHolder)?.questionContainer
+ override fun onBind(viewHolder: RecyclerView.ViewHolder): View? =
+ (viewHolder as? ViewHolder)?.questionContainer
- override fun onClick(v: View, position: Int, adapter: FastAdapter<IItem<*, *>>, item: IItem<*, *>) {
- if (item !is FaqIItem) return
- item.isExpanded = !item.isExpanded
- v.parentViewGroup.findViewById<CollapsibleTextView>(R.id.faq_item_answer)
- .setExpanded(item.isExpanded)
- }
- })
+ override fun onClick(
+ v: View,
+ position: Int,
+ fastAdapter: FastAdapter<GenericItem>,
+ item: GenericItem
+ ) {
+ if (item !is FaqIItem) return
+ item.isExpanded = !item.isExpanded
+ v.parentViewGroup.findViewById<CollapsibleTextView>(R.id.faq_item_answer)
+ .setExpanded(item.isExpanded)
+ }
+ })
}
}
@@ -69,7 +75,7 @@ class FaqIItem(val content: FaqItem) : KauIItem<LibraryIItem, FaqIItem.ViewHolde
answer.setExpanded(isExpanded, false)
if (accentColor != null) answer.setLinkTextColor(accentColor!!)
answer.text = content.answer
- answer.post { answer.setPaddingLeft(16.dpToPx + number.width) }
+ answer.post { answer.setPaddingLeft(16.dpToPx + number.width) } // TODO not performant at all; and doesn't align across all items
bindTextColor(number, question)
bindTextColorSecondary(answer)
val bg2 = backgroundColor?.colorToForeground(0.1f)
diff --git a/about/src/main/kotlin/ca/allanwang/kau/about/LibraryIItem.kt b/about/src/main/kotlin/ca/allanwang/kau/about/LibraryIItem.kt
index 33aac09..275945b 100644
--- a/about/src/main/kotlin/ca/allanwang/kau/about/LibraryIItem.kt
+++ b/about/src/main/kotlin/ca/allanwang/kau/about/LibraryIItem.kt
@@ -29,31 +29,34 @@ import ca.allanwang.kau.utils.startLink
import ca.allanwang.kau.utils.visible
import com.mikepenz.aboutlibraries.entity.Library
import com.mikepenz.fastadapter.FastAdapter
-import com.mikepenz.fastadapter.IItem
+import com.mikepenz.fastadapter.GenericItem
+import com.mikepenz.fastadapter.select.getSelectExtension
/**
* Created by Allan Wang on 2017-06-27.
*/
-class LibraryIItem(val lib: Library) : KauIItem<LibraryIItem, LibraryIItem.ViewHolder>(
+class LibraryIItem(val lib: Library) : KauIItem<LibraryIItem.ViewHolder>(
R.layout.kau_iitem_library, ::ViewHolder, R.id.kau_item_library
), ThemableIItem by ThemableIItemDelegate() {
companion object {
- fun bindEvents(fastAdapter: FastAdapter<IItem<*, *>>) {
- fastAdapter.withSelectable(false)
- .withOnClickListener { v, _, item, _ ->
- if (item !is LibraryIItem)
- false
- else
- with(item.lib) {
- v!!.context.startLink(libraryWebsite, repositoryLink, authorWebsite)
- true
- }
- }
+ fun bindEvents(fastAdapter: FastAdapter<GenericItem>) {
+ fastAdapter.getSelectExtension().isSelectable = true
+ fastAdapter.onClickListener = { v, _, item, _ ->
+ if (item !is LibraryIItem)
+ false
+ else
+ with(item.lib) {
+ v!!.context.startLink(libraryWebsite, repositoryLink, authorWebsite)
+ true
+ }
+ }
}
}
- override fun isSelectable(): Boolean = false
+ override var isSelectable: Boolean
+ get() = false
+ set(_) {}
override fun bindView(holder: ViewHolder, payloads: MutableList<Any>) {
super.bindView(holder, payloads)
diff --git a/adapter/build.gradle b/adapter/build.gradle
index 42c6eba..2874275 100644
--- a/adapter/build.gradle
+++ b/adapter/build.gradle
@@ -1,4 +1,6 @@
-ext.kauSubModuleMinSdk = kau.Versions.coreMinSdk
+import kau.Versions
+
+ext.kauSubModuleMinSdk = Versions.coreMinSdk
apply from: '../android-lib.gradle'
diff --git a/android-lib.gradle b/android-lib.gradle
index 90ec6bf..196cc1b 100644
--- a/android-lib.gradle
+++ b/android-lib.gradle
@@ -1,3 +1,6 @@
+import kau.Dependencies
+import kau.Versions
+
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
@@ -6,15 +9,15 @@ apply plugin: 'com.getkeepsafe.dexcount'
group = "ca.allanwang"
android {
- compileSdkVersion kau.Versions.targetSdk
- buildToolsVersion kau.Versions.buildTools
+ compileSdkVersion Versions.targetSdk
+ buildToolsVersion Versions.buildTools
androidGitVersion {
codeFormat = 'MMNNPPXX'
format = '%tag%%.count%%-commit%'
}
- def kauMinSdk = kau.Versions.minSdk
+ def kauMinSdk = Versions.minSdk
if (project.hasProperty('kauSubModuleMinSdk'))
kauMinSdk = kauSubModuleMinSdk
@@ -26,7 +29,7 @@ android {
defaultConfig {
minSdkVersion kauMinSdk
- targetSdkVersion kau.Versions.targetSdk
+ targetSdkVersion Versions.targetSdk
versionName androidGitVersion.name()
versionCode androidGitVersion.code()
consumerProguardFiles 'progress-proguard.txt'
@@ -59,6 +62,7 @@ android {
packagingOptions {
pickFirst 'META-INF/core_release.kotlin_module'
pickFirst 'META-INF/library_release.kotlin_module'
+ pickFirst 'META-INF/library-core_release.kotlin_module'
}
compileOptions {
@@ -87,11 +91,11 @@ android {
}
dependencies {
- testImplementation kau.Dependencies.kotlinTest
- testImplementation kau.Dependencies.junit
+ testImplementation Dependencies.kotlinTest
+ testImplementation Dependencies.junit
- androidTestImplementation kau.Dependencies.kotlinTest
- androidTestImplementation kau.Dependencies.espresso
- androidTestImplementation kau.Dependencies.testRules
- androidTestImplementation kau.Dependencies.testRunner
+ androidTestImplementation Dependencies.kotlinTest
+ androidTestImplementation Dependencies.espresso
+ androidTestImplementation Dependencies.testRules
+ androidTestImplementation Dependencies.testRunner
} \ No newline at end of file
diff --git a/build.gradle b/build.gradle
index 81655fb..bc5fadf 100644
--- a/build.gradle
+++ b/build.gradle
@@ -1,3 +1,6 @@
+import kau.ChangelogGenerator
+import kau.Plugins
+
buildscript {
repositories {
google()
@@ -7,13 +10,13 @@ buildscript {
}
dependencies {
- classpath kau.Plugins.android
- classpath kau.Plugins.kotlin
- classpath kau.Plugins.androidMaven
- classpath kau.Plugins.playPublisher
- classpath kau.Plugins.dexCount
- classpath kau.Plugins.gitVersion
- classpath kau.Plugins.spotless
+ classpath Plugins.android
+ classpath Plugins.kotlin
+ classpath Plugins.androidMaven
+ classpath Plugins.playPublisher
+ classpath Plugins.dexCount
+ classpath Plugins.gitVersion
+ classpath Plugins.spotless
}
wrapper.setDistributionType(Wrapper.DistributionType.ALL)
@@ -24,7 +27,7 @@ task clean(type: Delete) {
}
task generateChangelogMd {
- kau.ChangelogGenerator.generate("${project.rootDir}/sample/src/main/res/xml/kau_changelog.xml", "${project.rootDir}/docs/Changelog.md")
+ ChangelogGenerator.generate("${project.rootDir}/sample/src/main/res/xml/kau_changelog.xml", "${project.rootDir}/docs/Changelog.md")
}
subprojects {
diff --git a/buildSrc/src/main/kotlin/kau/Dependencies.kt b/buildSrc/src/main/kotlin/kau/Dependencies.kt
index f6d07ec..d1e2b89 100644
--- a/buildSrc/src/main/kotlin/kau/Dependencies.kt
+++ b/buildSrc/src/main/kotlin/kau/Dependencies.kt
@@ -30,9 +30,9 @@ object Dependencies {
const val googleMaterial = "com.google.android.material:material:${Versions.googleMaterial}"
const val iconics = "com.mikepenz:iconics-core:${Versions.iconics}"
- const val iconicsGoogle = "com.mikepenz:google-material-typeface:${Versions.iconicsGoogle}.original@aar"
- const val iconicsMaterial = "com.mikepenz:material-design-iconic-typeface:${Versions.iconicsMaterial}@aar"
- const val iconicsCommunity = "com.mikepenz:community-material-typeface:${Versions.iconicsCommunity}@aar"
+ const val iconicsGoogle = "com.mikepenz:google-material-typeface:${Versions.iconicsGoogle}.original-kotlin@aar"
+ const val iconicsMaterial = "com.mikepenz:material-design-iconic-typeface:${Versions.iconicsMaterial}-kotlin@aar"
+ const val iconicsCommunity = "com.mikepenz:community-material-typeface:${Versions.iconicsCommunity}-kotlin@aar"
const val aboutLibraries = "com.mikepenz:aboutlibraries:${Versions.aboutLibraries}"
@@ -49,10 +49,7 @@ object Dependencies {
const val fastAdapter = "com.mikepenz:fastadapter:${Versions.fastAdapter}"
@JvmStatic
- fun fastAdapter(type: String) = "com.mikepenz:fastadapter-$type:${Versions.fastAdapter}"
-
- @JvmField
- val fastAdapterCommons = fastAdapter("commons")
+ fun fastAdapter(type: String) = "com.mikepenz:fastadapter-extensions-$type:${Versions.fastAdapter}"
const val bugsnag = "com.bugsnag:bugsnag-android:${Versions.bugsnag}"
diff --git a/buildSrc/src/main/kotlin/kau/Versions.kt b/buildSrc/src/main/kotlin/kau/Versions.kt
index 4deb3b7..f3fbd09 100644
--- a/buildSrc/src/main/kotlin/kau/Versions.kt
+++ b/buildSrc/src/main/kotlin/kau/Versions.kt
@@ -36,15 +36,15 @@ object Versions {
const val blurry = "3.0.0"
// https://github.com/mikepenz/FastAdapter#using-maven
- const val fastAdapter = "3.3.1"
+ const val fastAdapter = "4.1.0-b01"
// https://github.com/bumptech/glide/releases
const val glide = "4.9.0"
// https://github.com/mikepenz/Android-Iconics#1-provide-the-gradle-dependency
- const val iconics = "3.2.5"
- const val iconicsGoogle = "3.0.1.3"
- const val iconicsMaterial = "2.2.0.5"
+ const val iconics = "4.0.1-b01"
+ const val iconicsGoogle = "3.0.1.4"
+ const val iconicsMaterial = "2.2.0.6"
const val iconicsCommunity = "3.5.95.1"
// https://github.com/afollestad/material-dialogs/releases
diff --git a/core-ui/src/main/kotlin/ca/allanwang/kau/ui/widgets/ElasticDragDismissFrameLayout.kt b/core-ui/src/main/kotlin/ca/allanwang/kau/ui/widgets/ElasticDragDismissFrameLayout.kt
index 2cf005a..52672fa 100644
--- a/core-ui/src/main/kotlin/ca/allanwang/kau/ui/widgets/ElasticDragDismissFrameLayout.kt
+++ b/core-ui/src/main/kotlin/ca/allanwang/kau/ui/widgets/ElasticDragDismissFrameLayout.kt
@@ -29,7 +29,6 @@ import ca.allanwang.kau.logging.KL
import ca.allanwang.kau.ui.R
import ca.allanwang.kau.utils.AnimHolder
import ca.allanwang.kau.utils.dimen
-import ca.allanwang.kau.utils.dpToPx
import ca.allanwang.kau.utils.isNavBarOnBottom
import ca.allanwang.kau.utils.navigationBarColor
import ca.allanwang.kau.utils.scaleXY
diff --git a/core/src/main/kotlin/ca/allanwang/kau/kpref/KPrefBuilder.kt b/core/src/main/kotlin/ca/allanwang/kau/kpref/KPrefBuilder.kt
index 4dd3012..8f6d0c5 100644
--- a/core/src/main/kotlin/ca/allanwang/kau/kpref/KPrefBuilder.kt
+++ b/core/src/main/kotlin/ca/allanwang/kau/kpref/KPrefBuilder.kt
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2019 Allan Wang
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package ca.allanwang.kau.kpref
interface KPrefBuilder {
@@ -72,4 +87,4 @@ object KPrefBuilderInMemory : KPrefBuilder {
KPrefDelegateInMemory(key, fallback, this, postSetter)
override fun KPref.kprefSingle(key: String) = KPrefSingleDelegateInMemory(key, this)
-} \ No newline at end of file
+}
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 ef59e78..ae1f855 100644
--- a/core/src/main/kotlin/ca/allanwang/kau/kpref/KPrefSingleDelegate.kt
+++ b/core/src/main/kotlin/ca/allanwang/kau/kpref/KPrefSingleDelegate.kt
@@ -110,4 +110,4 @@ class KPrefSingleDelegateInMemory internal constructor(
override fun isInitialized(): Boolean = _value != null
override fun toString(): String = if (isInitialized()) value.toString() else "Lazy kPref $key not initialized yet."
-} \ No newline at end of file
+}
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 3c90b05..ee4f5ef 100644
--- a/core/src/main/kotlin/ca/allanwang/kau/permissions/Permissions.kt
+++ b/core/src/main/kotlin/ca/allanwang/kau/permissions/Permissions.kt
@@ -1,5 +1,5 @@
/*
- * Copyright 2018 Allan Wang
+ * Copyright 2019 Allan Wang
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -76,6 +76,8 @@ const val PERMISSION_READ_CALL_LOG = Manifest.permission.READ_CALL_LOG
const val PERMISSION_WRITE_CALL_LOG = Manifest.permission.WRITE_CALL_LOG
const val PERMISSION_ADD_VOICEMAIL = Manifest.permission.ADD_VOICEMAIL
const val PERMISSION_USE_SIP = Manifest.permission.USE_SIP
+@Deprecated(level = DeprecationLevel.WARNING, message = "Permission is deprecated")
+@Suppress("DEPRECATION")
const val PERMISSION_PROCESS_OUTGOING_CALLS = Manifest.permission.PROCESS_OUTGOING_CALLS
@RequiresApi(Build.VERSION_CODES.KITKAT_WATCH)
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 8b40352..dc7b214 100644
--- a/core/src/main/kotlin/ca/allanwang/kau/utils/IIconUtils.kt
+++ b/core/src/main/kotlin/ca/allanwang/kau/utils/IIconUtils.kt
@@ -16,11 +16,11 @@
package ca.allanwang.kau.utils
import android.content.Context
-import android.content.res.ColorStateList
import android.graphics.Color
import android.graphics.drawable.Drawable
import androidx.annotation.ColorInt
import com.mikepenz.iconics.IconicsDrawable
+import com.mikepenz.iconics.dsl.iconicsDrawable
import com.mikepenz.iconics.typeface.IIcon
/**
@@ -32,10 +32,9 @@ fun IIcon.toDrawable(
sizeDp: Int = 24,
@ColorInt color: Int = Color.WHITE,
builder: IconicsDrawable.() -> Unit = {}
-): Drawable {
- val state = ColorStateList.valueOf(color)
- val icon = IconicsDrawable(c).icon(this).color(state)
- if (sizeDp > 0) icon.sizeDp(sizeDp)
- icon.builder()
- return icon
-}
+): Drawable = c.iconicsDrawable(this) {
+ this.color = colorInt(color)
+ if (sizeDp > 0) {
+ size = sizeDp(sizeDp)
+ }
+}.apply(builder)
diff --git a/core/src/main/kotlin/ca/allanwang/kau/utils/Kotterknife.kt b/core/src/main/kotlin/ca/allanwang/kau/utils/Kotterknife.kt
index 8765c69..aaef160 100644
--- a/core/src/main/kotlin/ca/allanwang/kau/utils/Kotterknife.kt
+++ b/core/src/main/kotlin/ca/allanwang/kau/utils/Kotterknife.kt
@@ -116,11 +116,11 @@ private inline val Dialog.viewFinder: Dialog.(Int) -> View?
private inline val DialogFragment.viewFinder: DialogFragment.(Int) -> View?
get() = { dialog.findViewById(it) }
private inline val SupportDialogFragment.viewFinder: SupportDialogFragment.(Int) -> View?
- get() = { dialog.findViewById(it) }
+ get() = { dialog?.findViewById(it) }
private inline val Fragment.viewFinder: Fragment.(Int) -> View?
- get() = { view!!.findViewById(it) }
+ get() = { view?.findViewById(it) }
private inline val SupportFragment.viewFinder: SupportFragment.(Int) -> View?
- get() = { view!!.findViewById(it) }
+ get() = { view?.findViewById(it) }
private inline val ViewHolder.viewFinder: ViewHolder.(Int) -> View?
get() = { itemView.findViewById(it) }
diff --git a/docs/Changelog.md b/docs/Changelog.md
index f8287ca..0078430 100644
--- a/docs/Changelog.md
+++ b/docs/Changelog.md
@@ -1,5 +1,8 @@
# Changelog
+## v5.2.0
+* :fastadapter: Migrate fastadapter to v4.x.x
+
## v5.1.0
* :adapter: Moved fastadapter elements to new module, :fastadapter:. To migrate, simply rename the dependency. If you don't use fast adapter, no changes are necessary
* :adapter: Make NoAnimatorChange an object; previously a class
diff --git a/fastadapter/build.gradle b/fastadapter/build.gradle
index 9fd848e..ff58fe8 100644
--- a/fastadapter/build.gradle
+++ b/fastadapter/build.gradle
@@ -1,4 +1,7 @@
-ext.kauSubModuleMinSdk = kau.Versions.coreMinSdk
+import kau.Dependencies
+import kau.Versions
+
+ext.kauSubModuleMinSdk = Versions.coreMinSdk
apply from: '../android-lib.gradle'
@@ -6,8 +9,8 @@ dependencies {
implementation project(':core')
api project(':adapter')
- api kau.Dependencies.fastAdapter
- api kau.Dependencies.fastAdapterCommons
+ api Dependencies.fastAdapter
+ api Dependencies.fastAdapter("utils")
}
apply from: '../artifacts.gradle'
diff --git a/fastadapter/src/main/kotlin/ca/allanwang/kau/adapters/AdapterUtils.kt b/fastadapter/src/main/kotlin/ca/allanwang/kau/adapters/AdapterUtils.kt
index 17fd09f..655b355 100644
--- a/fastadapter/src/main/kotlin/ca/allanwang/kau/adapters/AdapterUtils.kt
+++ b/fastadapter/src/main/kotlin/ca/allanwang/kau/adapters/AdapterUtils.kt
@@ -16,9 +16,8 @@
package ca.allanwang.kau.adapters
import com.mikepenz.fastadapter.FastAdapter
+import com.mikepenz.fastadapter.GenericItem
import com.mikepenz.fastadapter.IAdapter
-import com.mikepenz.fastadapter.IAdapterExtension
-import com.mikepenz.fastadapter.IItem
import com.mikepenz.fastadapter.select.SelectExtension
/**
@@ -28,17 +27,14 @@ import com.mikepenz.fastadapter.select.SelectExtension
/**
* Add kotlin's generic syntax to better support out types
*/
-fun <Item : IItem<*, *>> fastAdapter(vararg adapter: IAdapter<out Item>) =
- FastAdapter.with<Item, IAdapter<out Item>>(adapter.toList())!!
-
-inline fun <reified T : IAdapterExtension<Item>, Item : IItem<*, *>> FastAdapter<Item>.getExtension(): T? =
- getExtension(T::class.java)
+fun <Item : GenericItem> fastAdapter(vararg adapter: IAdapter<out Item>) =
+ FastAdapter.with<Item, IAdapter<out Item>>(adapter.toList())
/**
* Returns selection size, or -1 if selection is disabled
*/
-inline val <Item : IItem<*, *>> IAdapter<Item>.selectionSize: Int
- get() = fastAdapter.getExtension<SelectExtension<Item>, Item>()?.selections?.size ?: -1
+inline val <Item : GenericItem> IAdapter<Item>.selectionSize: Int
+ get() = fastAdapter?.getExtension<SelectExtension<Item>>()?.selections?.size ?: -1
-inline val <Item : IItem<*, *>> IAdapter<Item>.selectedItems: Set<Item>
- get() = fastAdapter.getExtension<SelectExtension<Item>, Item>()?.selectedItems ?: emptySet()
+inline val <Item : GenericItem> IAdapter<Item>.selectedItems: Set<Item>
+ get() = fastAdapter?.getExtension<SelectExtension<Item>>()?.selectedItems ?: emptySet()
diff --git a/fastadapter/src/main/kotlin/ca/allanwang/kau/adapters/FastItemThemedAdapter.kt b/fastadapter/src/main/kotlin/ca/allanwang/kau/adapters/FastItemThemedAdapter.kt
index 152982f..5531f59 100644
--- a/fastadapter/src/main/kotlin/ca/allanwang/kau/adapters/FastItemThemedAdapter.kt
+++ b/fastadapter/src/main/kotlin/ca/allanwang/kau/adapters/FastItemThemedAdapter.kt
@@ -23,8 +23,8 @@ import android.widget.TextView
import androidx.annotation.RequiresApi
import ca.allanwang.kau.ui.createSimpleRippleDrawable
import ca.allanwang.kau.utils.adjustAlpha
-import com.mikepenz.fastadapter.IItem
-import com.mikepenz.fastadapter.commons.adapters.FastItemAdapter
+import com.mikepenz.fastadapter.GenericItem
+import com.mikepenz.fastadapter.adapters.FastItemAdapter
/**
* Created by Allan Wang on 2017-06-29.
@@ -35,12 +35,23 @@ import com.mikepenz.fastadapter.commons.adapters.FastItemAdapter
* This adapter overrides every method where an item is added
* If that item extends [ThemableIItem], then the colors will be set
*/
-class FastItemThemedAdapter<Item : IItem<*, *>>(
+class FastItemThemedAdapter<Item : GenericItem>(
textColor: Int? = null,
backgroundColor: Int? = null,
accentColor: Int? = null
) : FastItemAdapter<Item>() {
- constructor(colors: ThemableIItemColors) : this(colors.textColor, colors.backgroundColor, colors.accentColor)
+ constructor(colors: ThemableIItemColors) : this(
+ colors.textColor,
+ colors.backgroundColor,
+ colors.accentColor
+ )
+
+ init {
+ itemAdapter.interceptor = {
+ injectTheme(it)
+ it
+ }
+ }
var textColor: Int? = textColor
set(value) {
@@ -73,51 +84,11 @@ class FastItemThemedAdapter<Item : IItem<*, *>>(
notifyAdapterDataSetChanged()
}
- override fun add(position: Int, items: List<Item>): FastItemAdapter<Item> {
- injectTheme(items)
- return super.add(position, items)
- }
-
- override fun add(position: Int, item: Item): FastItemAdapter<Item> {
- injectTheme(item)
- return super.add(position, item)
- }
-
- override fun add(item: Item): FastItemAdapter<Item> {
- injectTheme(item)
- return super.add(item)
- }
-
- override fun add(items: List<Item>?): FastItemAdapter<Item> {
- injectTheme(items)
- return super.add(items)
- }
-
- override fun set(items: List<Item>?): FastItemAdapter<Item> {
- injectTheme(items)
- return super.set(items)
- }
-
- override fun set(position: Int, item: Item): FastItemAdapter<Item> {
- injectTheme(item)
- return super.set(position, item)
- }
-
- override fun setNewList(items: List<Item>?, retainFilter: Boolean): FastItemAdapter<Item> {
- injectTheme(items)
- return super.setNewList(items, retainFilter)
- }
-
- override fun setNewList(items: List<Item>?): FastItemAdapter<Item> {
- injectTheme(items)
- return super.setNewList(items)
- }
-
- private fun injectTheme(items: Collection<IItem<*, *>?>?) {
+ private fun injectTheme(items: Collection<GenericItem?>?) {
items?.forEach { injectTheme(it) }
}
- protected fun injectTheme(item: IItem<*, *>?) {
+ protected fun injectTheme(item: GenericItem?) {
if (item is ThemableIItem && item.themeEnabled) {
item.textColor = textColor
item.backgroundColor = backgroundColor
diff --git a/fastadapter/src/main/kotlin/ca/allanwang/kau/adapters/RepeatedClickListener.kt b/fastadapter/src/main/kotlin/ca/allanwang/kau/adapters/RepeatedClickListener.kt
index 40b4774..1eba2e0 100644
--- a/fastadapter/src/main/kotlin/ca/allanwang/kau/adapters/RepeatedClickListener.kt
+++ b/fastadapter/src/main/kotlin/ca/allanwang/kau/adapters/RepeatedClickListener.kt
@@ -17,31 +17,33 @@ package ca.allanwang.kau.adapters
import android.view.View
import androidx.annotation.IntRange
+import com.mikepenz.fastadapter.ClickListener
import com.mikepenz.fastadapter.FastAdapter
+import com.mikepenz.fastadapter.GenericItem
import com.mikepenz.fastadapter.IAdapter
-import com.mikepenz.fastadapter.IItem
-import com.mikepenz.fastadapter.listeners.OnClickListener
/**
* Created by Allan Wang on 26/12/17.
*/
-fun <Item : IItem<*, *>> FastAdapter<Item>.withOnRepeatedClickListener(
+fun <Item : GenericItem> FastAdapter<Item>.withOnRepeatedClickListener(
count: Int,
duration: Long,
- event: OnClickListener<Item>
-) =
- withOnClickListener(RepeatedClickListener(count, duration, event))
+ event: ClickListener<Item>
+): FastAdapter<Item> {
+ onClickListener = RepeatedClickListener(count, duration, event)
+ return this
+}
/**
* Registers and skips each click until the designated [count] clicks are triggered,
* each within [duration] from each other.
* Only then will the [event] be fired, and everything will be reset.
*/
-private class RepeatedClickListener<Item : IItem<*, *>>(
+private class RepeatedClickListener<Item : GenericItem>(
@IntRange(from = 1) val count: Int,
@IntRange(from = 1) val duration: Long,
- val event: OnClickListener<Item>
-) : OnClickListener<Item> {
+ val event: ClickListener<Item>
+) : ClickListener<Item> {
init {
if (count <= 0)
@@ -53,7 +55,7 @@ private class RepeatedClickListener<Item : IItem<*, *>>(
private var chain = 0
private var time = -1L
- override fun onClick(v: View?, adapter: IAdapter<Item>, item: Item, position: Int): Boolean {
+ override fun invoke(v: View?, adapter: IAdapter<Item>, item: Item, position: Int): Boolean {
val now = System.currentTimeMillis()
if (time - now < duration)
chain++
@@ -62,7 +64,7 @@ private class RepeatedClickListener<Item : IItem<*, *>>(
time = now
if (chain == count) {
chain = 0
- event.onClick(v, adapter, item, position)
+ event(v, adapter, item, position)
return true
}
return false
diff --git a/fastadapter/src/main/kotlin/ca/allanwang/kau/iitems/CardIItem.kt b/fastadapter/src/main/kotlin/ca/allanwang/kau/iitems/CardIItem.kt
index 6e33833..1a2e6cb 100644
--- a/fastadapter/src/main/kotlin/ca/allanwang/kau/iitems/CardIItem.kt
+++ b/fastadapter/src/main/kotlin/ca/allanwang/kau/iitems/CardIItem.kt
@@ -34,7 +34,7 @@ import ca.allanwang.kau.utils.string
import ca.allanwang.kau.utils.toDrawable
import ca.allanwang.kau.utils.visible
import com.mikepenz.fastadapter.FastAdapter
-import com.mikepenz.fastadapter.IItem
+import com.mikepenz.fastadapter.GenericItem
import com.mikepenz.fastadapter.listeners.ClickEventHook
import com.mikepenz.iconics.typeface.IIcon
@@ -46,18 +46,18 @@ import com.mikepenz.iconics.typeface.IIcon
*/
class CardIItem(
val builder: Config.() -> Unit = {}
-) : KauIItem<CardIItem, CardIItem.ViewHolder>(
+) : KauIItem< CardIItem.ViewHolder>(
R.layout.kau_iitem_card, ::ViewHolder, R.id.kau_item_card
), ThemableIItem by ThemableIItemDelegate() {
companion object {
- fun bindClickEvents(fastAdapter: FastAdapter<IItem<*, *>>) {
- fastAdapter.withEventHook(object : ClickEventHook<IItem<*, *>>() {
+ fun bindClickEvents(fastAdapter: FastAdapter<GenericItem>) {
+ fastAdapter.addEventHook(object : ClickEventHook<GenericItem>() {
override fun onBindMany(viewHolder: RecyclerView.ViewHolder): List<View>? {
return if (viewHolder is ViewHolder) listOf(viewHolder.card, viewHolder.button) else null
}
- override fun onClick(v: View, position: Int, adapter: FastAdapter<IItem<*, *>>, item: IItem<*, *>) {
+ override fun onClick(v: View, position: Int, fastAdapter: FastAdapter<GenericItem>, item: GenericItem) {
if (item !is CardIItem) return
with(item.configs) {
when (v.id) {
diff --git a/fastadapter/src/main/kotlin/ca/allanwang/kau/iitems/HeaderIItem.kt b/fastadapter/src/main/kotlin/ca/allanwang/kau/iitems/HeaderIItem.kt
index 2c488b1..551cb59 100644
--- a/fastadapter/src/main/kotlin/ca/allanwang/kau/iitems/HeaderIItem.kt
+++ b/fastadapter/src/main/kotlin/ca/allanwang/kau/iitems/HeaderIItem.kt
@@ -34,7 +34,7 @@ import ca.allanwang.kau.utils.string
class HeaderIItem(
text: String? = null,
var textRes: Int = INVALID_ID
-) : KauIItem<HeaderIItem, HeaderIItem.ViewHolder>(
+) : KauIItem<HeaderIItem.ViewHolder>(
R.layout.kau_iitem_header, { ViewHolder(it) }, R.id.kau_item_header_big_margin_top
), ThemableIItem by ThemableIItemDelegate() {
diff --git a/fastadapter/src/main/kotlin/ca/allanwang/kau/iitems/KauIItem.kt b/fastadapter/src/main/kotlin/ca/allanwang/kau/iitems/KauIItem.kt
index c66dc01..34a2b7d 100644
--- a/fastadapter/src/main/kotlin/ca/allanwang/kau/iitems/KauIItem.kt
+++ b/fastadapter/src/main/kotlin/ca/allanwang/kau/iitems/KauIItem.kt
@@ -15,12 +15,9 @@
*/
package ca.allanwang.kau.iitems
-import android.annotation.SuppressLint
import android.view.View
import androidx.annotation.LayoutRes
import androidx.recyclerview.widget.RecyclerView
-import com.mikepenz.fastadapter.IClickable
-import com.mikepenz.fastadapter.IItem
import com.mikepenz.fastadapter.items.AbstractItem
/**
@@ -29,14 +26,10 @@ import com.mikepenz.fastadapter.items.AbstractItem
* Kotlin implementation of the [AbstractItem] to make things shorter
* If only one iitem type extends the given [layoutRes], you may use it as the type and not worry about another id
*/
-open class KauIItem<Item, VH : RecyclerView.ViewHolder>(
- @param:LayoutRes private val layoutRes: Int,
+open class KauIItem<VH : RecyclerView.ViewHolder>(
+ @param:LayoutRes override val layoutRes: Int,
private val viewHolder: (v: View) -> VH,
- private val type: Int = layoutRes
-) : AbstractItem<Item, VH>() where Item : IItem<*, *>, Item : IClickable<*> {
- @SuppressLint("ResourceType")
- final override fun getType(): Int = type
-
+ override val type: Int = layoutRes
+) : AbstractItem<VH>() {
final override fun getViewHolder(v: View): VH = viewHolder(v)
- final override fun getLayoutRes(): Int = layoutRes
}
diff --git a/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/KPrefActivity.kt b/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/KPrefActivity.kt
index edaf347..f11afde 100644
--- a/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/KPrefActivity.kt
+++ b/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/KPrefActivity.kt
@@ -31,7 +31,8 @@ import ca.allanwang.kau.utils.KAU_RIGHT
import ca.allanwang.kau.utils.resolveColor
import ca.allanwang.kau.utils.statusBarColor
import ca.allanwang.kau.utils.withLinearAdapter
-import com.mikepenz.fastadapter.commons.adapters.FastItemAdapter
+import com.mikepenz.fastadapter.adapters.FastItemAdapter
+import com.mikepenz.fastadapter.select.getSelectExtension
import kotlinx.android.synthetic.main.kau_pref_activity.*
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
@@ -82,7 +83,8 @@ abstract class KPrefActivity : KauBaseActivity(), KPrefActivityContract {
toolbar.setNavigationOnClickListener { onBackPressed() }
setDisplayShowTitleEnabled(false)
}
- window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_STABLE or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
+ window.decorView.systemUiVisibility =
+ View.SYSTEM_UI_FLAG_LAYOUT_STABLE or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
statusBarColor = 0x30000000
kau_toolbar_ripple.set(resolveColor(R.attr.colorPrimary))
kau_ripple.set(resolveColor(android.R.attr.colorBackground))
@@ -92,8 +94,13 @@ abstract class KPrefActivity : KauBaseActivity(), KPrefActivityContract {
core.builder()
globalOptions = GlobalOptions(core, this)
kau_recycler.withLinearAdapter(adapter)
- adapter.withSelectable(false)
- .withOnClickListener { v, _, item, _ -> item.onClick(v!!); true }
+ adapter.apply {
+ getSelectExtension().isSelectable = true
+ onClickListener = { v, _, item, _ ->
+ item.onClick(v!!)
+ true
+ }
+ }
showNextPrefs(R.string.kau_settings, onCreateKPrefs(savedInstanceState), true)
}
diff --git a/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefCheckbox.kt b/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefCheckbox.kt
index 0f025a6..f4f4a65 100644
--- a/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefCheckbox.kt
+++ b/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefCheckbox.kt
@@ -34,7 +34,7 @@ open class KPrefCheckbox(builder: BaseContract<Boolean>) : KPrefItemBase<Boolean
(innerView as AppCompatCheckBox).isChecked = pref
}
- override fun bindView(holder: ViewHolder, payloads: List<Any>) {
+ override fun bindView(holder: ViewHolder, payloads: MutableList<Any>) {
super.bindView(holder, payloads)
val checkbox = holder.bindInnerView<CheckBox>(R.layout.kau_pref_checkbox)
withAccentColor(checkbox::tint)
@@ -42,5 +42,6 @@ open class KPrefCheckbox(builder: BaseContract<Boolean>) : KPrefItemBase<Boolean
checkbox.jumpDrawablesToCurrentState() //Cancel the animation
}
- override fun getType(): Int = R.id.kau_item_pref_checkbox
+ override val type: Int
+ get() = R.id.kau_item_pref_checkbox
}
diff --git a/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefColorPicker.kt b/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefColorPicker.kt
index 8b051c5..76cfbab 100644
--- a/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefColorPicker.kt
+++ b/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefColorPicker.kt
@@ -33,7 +33,7 @@ import com.afollestad.materialdialogs.MaterialDialog
*/
open class KPrefColorPicker(open val builder: KPrefColorContract) : KPrefItemBase<Int>(builder) {
- override fun bindView(holder: ViewHolder, payloads: List<Any>) {
+ override fun bindView(holder: ViewHolder, payloads: MutableList<Any>) {
super.bindView(holder, payloads)
if (builder.showPreview) {
val preview = holder.bindInnerView<CircleView>(R.layout.kau_pref_color)
@@ -63,7 +63,7 @@ open class KPrefColorPicker(open val builder: KPrefColorContract) : KPrefItemBas
/**
* Extension of the base contract and [ColorContract] along with a showPreview option
*/
- interface KPrefColorContract : KPrefItemBase.BaseContract<Int>, ColorContract {
+ interface KPrefColorContract : BaseContract<Int>, ColorContract {
var showPreview: Boolean
var dialogBuilder: MaterialDialog.() -> Unit
}
@@ -76,11 +76,13 @@ open class KPrefColorPicker(open val builder: KPrefColorContract) : KPrefItemBas
titleId: Int,
getter: () -> Int,
setter: KPrefItemActions.(value: Int) -> Unit
- ) : KPrefColorContract, KPrefItemBase.BaseContract<Int> by BaseBuilder(globalOptions, titleId, getter, setter),
+ ) : KPrefColorContract,
+ BaseContract<Int> by BaseBuilder(globalOptions, titleId, getter, setter),
ColorContract by ColorBuilder() {
override var showPreview: Boolean = true
override var dialogBuilder: MaterialDialog.() -> Unit = {}
}
- override fun getType(): Int = R.id.kau_item_pref_color_picker
+ override val type: Int
+ get() = R.id.kau_item_pref_color_picker
}
diff --git a/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefHeader.kt b/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefHeader.kt
index 7d73322..ca70b61 100644
--- a/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefHeader.kt
+++ b/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefHeader.kt
@@ -25,12 +25,14 @@ import ca.allanwang.kau.kpref.activity.R
*/
open class KPrefHeader(builder: CoreContract) : KPrefItemCore(builder) {
- override fun getLayoutRes(): Int = R.layout.kau_pref_header
+ override val layoutRes: Int
+ get() = R.layout.kau_pref_header
- override fun bindView(holder: ViewHolder, payloads: List<Any>) {
+ override fun bindView(holder: ViewHolder, payloads: MutableList<Any>) {
super.bindView(holder, payloads)
withAccentColor(holder.title::setTextColor)
}
- override fun getType() = R.id.kau_item_pref_header
+ override val type: Int
+ get() = R.id.kau_item_pref_header
}
diff --git a/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefItemBase.kt b/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefItemBase.kt
index c597b63..9197057 100644
--- a/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefItemBase.kt
+++ b/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefItemBase.kt
@@ -46,7 +46,7 @@ abstract class KPrefItemBase<T>(protected val base: BaseContract<T>) : KPrefItem
}
@CallSuper
- override fun bindView(holder: ViewHolder, payloads: List<Any>) {
+ override fun bindView(holder: ViewHolder, payloads: MutableList<Any>) {
super.bindView(holder, payloads)
_enabled = base.enabler()
with(holder) {
@@ -77,12 +77,14 @@ abstract class KPrefItemBase<T>(protected val base: BaseContract<T>) : KPrefItem
super.unbindView(holder)
holder.container?.apply {
isEnabled = true
- background = holder.itemView.context.resolveDrawable(android.R.attr.selectableItemBackground)
+ background =
+ holder.itemView.context.resolveDrawable(android.R.attr.selectableItemBackground)
alpha = 1.0f
}
}
- final override fun getLayoutRes(): Int = R.layout.kau_pref_core
+ final override val layoutRes: Int
+ get() = R.layout.kau_pref_core
/**
* Extension of the core contract
diff --git a/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefItemCore.kt b/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefItemCore.kt
index 36bf670..79b7e82 100644
--- a/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefItemCore.kt
+++ b/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefItemCore.kt
@@ -48,7 +48,7 @@ import com.mikepenz.iconics.typeface.IIcon
* Core class containing nothing but the view items
*/
-abstract class KPrefItemCore(val core: CoreContract) : AbstractItem<KPrefItemCore, KPrefItemCore.ViewHolder>(), KPrefItemActions by core,
+abstract class KPrefItemCore(val core: CoreContract) : AbstractItem<KPrefItemCore.ViewHolder>(), KPrefItemActions by core,
ThemableIItem by ThemableIItemDelegate() {
final override fun getViewHolder(v: View) = ViewHolder(v)
@@ -70,7 +70,7 @@ abstract class KPrefItemCore(val core: CoreContract) : AbstractItem<KPrefItemCor
*/
@SuppressLint("NewApi")
@CallSuper
- override fun bindView(holder: ViewHolder, payloads: List<Any>) {
+ override fun bindView(holder: ViewHolder, payloads: MutableList<Any>) {
super.bindView(holder, payloads)
with(holder) {
updateTitle()
diff --git a/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefPlainText.kt b/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefPlainText.kt
index 6a0aaf5..7381a07 100644
--- a/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefPlainText.kt
+++ b/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefPlainText.kt
@@ -36,5 +36,6 @@ open class KPrefPlainText(open val builder: KPrefPlainTextBuilder) : KPrefItemBa
titleId: Int
) : BaseContract<Unit> by BaseBuilder(globalOptions, titleId, {}, {})
- override fun getType(): Int = R.id.kau_item_pref_plain_text
+ override val type: Int
+ get() = R.id.kau_item_pref_plain_text
}
diff --git a/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefSeekbar.kt b/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefSeekbar.kt
index a582ec4..5de1f83 100644
--- a/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefSeekbar.kt
+++ b/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefSeekbar.kt
@@ -37,7 +37,7 @@ open class KPrefSeekbar(val builder: KPrefSeekbarContract) : KPrefItemBase<Int>(
override fun KClick<Int>.defaultOnClick() = Unit
- override fun bindView(holder: ViewHolder, payloads: List<Any>) {
+ override fun bindView(holder: ViewHolder, payloads: MutableList<Any>) {
super.bindView(holder, payloads)
val text = holder.bindInnerView<TextView>(R.layout.kau_pref_seekbar_text)
withTextColor(text::setTextColor)
@@ -60,7 +60,8 @@ open class KPrefSeekbar(val builder: KPrefSeekbarContract) : KPrefItemBase<Int>(
})
}
withAccentColor(seekbar::tint)
- text.text = builder.toText(seekbar.progress.fromProgress) //set initial text in case no change occurs
+ text.text =
+ builder.toText(seekbar.progress.fromProgress) //set initial text in case no change occurs
seekbar.progress = pref.toProgress
seekbar.isEnabled = builder.enabler()
}
@@ -87,7 +88,8 @@ open class KPrefSeekbar(val builder: KPrefSeekbarContract) : KPrefItemBase<Int>(
titleId: Int,
getter: () -> Int,
setter: KPrefItemActions.(value: Int) -> Unit
- ) : KPrefSeekbarContract, BaseContract<Int> by BaseBuilder(globalOptions, titleId, getter, setter) {
+ ) : KPrefSeekbarContract,
+ BaseContract<Int> by BaseBuilder(globalOptions, titleId, getter, setter) {
override var min: Int = 0
@@ -118,5 +120,6 @@ open class KPrefSeekbar(val builder: KPrefSeekbarContract) : KPrefItemBase<Int>(
protected inline val Int.fromProgress: Int
get() = this * increment + min
- override fun getType(): Int = R.id.kau_item_pref_seekbar
+ override val type: Int
+ get() = R.id.kau_item_pref_seekbar
}
diff --git a/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefSubItems.kt b/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefSubItems.kt
index 1fa528b..8474627 100644
--- a/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefSubItems.kt
+++ b/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefSubItems.kt
@@ -33,7 +33,8 @@ open class KPrefSubItems(open val builder: KPrefSubItemsContract) : KPrefItemCor
builder.globalOptions.showNextPrefs(builder.titleFun(), builder.itemBuilder)
}
- override fun getLayoutRes(): Int = R.layout.kau_pref_core
+ override val layoutRes: Int
+ get() = R.layout.kau_pref_core
/**
* Extension of the base contract with an optional text getter
@@ -51,5 +52,6 @@ open class KPrefSubItems(open val builder: KPrefSubItemsContract) : KPrefItemCor
override val itemBuilder: KPrefAdapterBuilder.() -> Unit
) : KPrefSubItemsContract, CoreContract by CoreBuilder(globalOptions, titleId)
- override fun getType(): Int = R.id.kau_item_pref_sub_item
+ override val type: Int
+ get() = R.id.kau_item_pref_sub_item
}
diff --git a/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefText.kt b/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefText.kt
index 76c9e20..50f0c62 100644
--- a/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefText.kt
+++ b/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefText.kt
@@ -46,7 +46,7 @@ open class KPrefText<T>(open val builder: KPrefTextContract<T>) : KPrefItemBase<
context.toast("No click function set")
}
- override fun bindView(holder: ViewHolder, payloads: List<Any>) {
+ override fun bindView(holder: ViewHolder, payloads: MutableList<Any>) {
super.bindView(holder, payloads)
val textView = holder.bindInnerView<TextView>(R.layout.kau_pref_text)
withTextColor(textView::setTextColor)
@@ -68,9 +68,11 @@ open class KPrefText<T>(open val builder: KPrefTextContract<T>) : KPrefItemBase<
titleId: Int,
getter: () -> T,
setter: KPrefItemActions.(value: T) -> Unit
- ) : KPrefTextContract<T>, BaseContract<T> by BaseBuilder<T>(globalOptions, titleId, getter, setter) {
+ ) : KPrefTextContract<T>,
+ BaseContract<T> by BaseBuilder<T>(globalOptions, titleId, getter, setter) {
override var textGetter: (T) -> String? = { it?.toString() }
}
- override fun getType(): Int = R.id.kau_item_pref_text
+ override val type: Int
+ get() = R.id.kau_item_pref_text
}
diff --git a/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefTimePicker.kt b/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefTimePicker.kt
index f50397c..318b630 100644
--- a/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefTimePicker.kt
+++ b/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefTimePicker.kt
@@ -33,7 +33,8 @@ import java.util.Locale
*/
open class KPrefTimePicker(override val builder: KPrefTimeContract) : KPrefText<Int>(builder) {
- interface KPrefTimeContract : KPrefText.KPrefTextContract<Int>, TimePickerDialog.OnTimeSetListener {
+ interface KPrefTimeContract : KPrefText.KPrefTextContract<Int>,
+ TimePickerDialog.OnTimeSetListener {
var use24HourFormat: Boolean
}
@@ -50,7 +51,8 @@ open class KPrefTimePicker(override val builder: KPrefTimeContract) : KPrefText<
titleId: Int,
getter: () -> Int,
setter: KPrefItemActions.(value: Int) -> Unit
- ) : KPrefTimeContract, BaseContract<Int> by BaseBuilder(globalOptions, titleId, getter, setter) {
+ ) : KPrefTimeContract,
+ BaseContract<Int> by BaseBuilder(globalOptions, titleId, getter, setter) {
override var use24HourFormat: Boolean = false
@@ -64,11 +66,18 @@ open class KPrefTimePicker(override val builder: KPrefTimeContract) : KPrefText<
if (use24HourFormat)
String.format(Locale.CANADA, "%d:%02d", hour, min)
else
- String.format(Locale.CANADA, "%d:%02d %s", hour % 12, min, if (hour >= 12) "PM" else "AM")
+ String.format(
+ Locale.CANADA,
+ "%d:%02d %s",
+ hour % 12,
+ min,
+ if (hour >= 12) "PM" else "AM"
+ )
}
}
- override fun getType(): Int = R.id.kau_item_pref_time_picker
+ override val type: Int
+ get() = R.id.kau_item_pref_time_picker
}
private val Int.splitTime: Pair<Int, Int>
diff --git a/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/BlurredImageView.kt b/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/BlurredImageView.kt
index 739bf47..e430dff 100644
--- a/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/BlurredImageView.kt
+++ b/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/BlurredImageView.kt
@@ -28,7 +28,7 @@ import ca.allanwang.kau.utils.scaleXY
import ca.allanwang.kau.utils.setBackgroundColorRes
import ca.allanwang.kau.utils.setIcon
import ca.allanwang.kau.utils.visible
-import com.mikepenz.google_material_typeface_library.GoogleMaterial
+import com.mikepenz.iconics.typeface.library.googlematerial.GoogleMaterial
import jp.wasabeef.blurry.internal.BlurFactor
import jp.wasabeef.blurry.internal.BlurTask
import kotlinx.android.synthetic.main.kau_blurred_imageview.view.*
@@ -48,7 +48,9 @@ class BlurredImageView @JvmOverloads constructor(
defStyleAttr: Int = 0
) : FrameLayout(context, attrs, defStyleAttr), MeasureSpecContract by MeasureSpecDelegate() {
- private var blurred = false
+ var isBlurred = false
+ private set
+
val imageBase: ImageView get() = image_base
init {
@@ -69,20 +71,19 @@ class BlurredImageView @JvmOverloads constructor(
image_foreground.clearAnimation()
}
- private fun View.scaleAnimate(scale: Float) = animate().scaleXY(scale).setDuration(ANIMATION_DURATION)
- private fun View.alphaAnimate(alpha: Float) = animate().alpha(alpha).setDuration(ANIMATION_DURATION)
+ private fun View.scaleAnimate(scale: Float) =
+ animate().scaleXY(scale).setDuration(ANIMATION_DURATION)
- fun isBlurred(): Boolean {
- return blurred
- }
+ private fun View.alphaAnimate(alpha: Float) =
+ animate().alpha(alpha).setDuration(ANIMATION_DURATION)
/**
* Applies a blur and fills the blur image asynchronously
* When ready, scales the image down and shows the blur & foreground
*/
fun blur() {
- if (blurred) return
- blurred = true
+ if (isBlurred) return
+ isBlurred = true
val factor = BlurFactor()
factor.width = width
factor.height = height
@@ -100,7 +101,7 @@ class BlurredImageView @JvmOverloads constructor(
* is still asynchronous and takes time
*/
fun blurInstantly() {
- blurred = true
+ isBlurred = true
clearAnimation()
val factor = BlurFactor()
factor.width = width
@@ -117,8 +118,8 @@ class BlurredImageView @JvmOverloads constructor(
* Animate view back to original state and remove drawable when finished
*/
fun removeBlur() {
- if (!blurred) return
- blurred = false
+ if (!isBlurred) return
+ isBlurred = false
scaleAnimate(1.0f).start()
image_blur.alphaAnimate(0f).withEndAction { image_blur.setImageDrawable(null) }.start()
image_foreground.alphaAnimate(0f).start()
@@ -128,7 +129,7 @@ class BlurredImageView @JvmOverloads constructor(
* Clear all animations and unblur the image
*/
fun removeBlurInstantly() {
- blurred = false
+ isBlurred = false
clearAnimation()
scaleX = 1.0f
scaleX = 1.0f
@@ -143,9 +144,9 @@ class BlurredImageView @JvmOverloads constructor(
* @return true if new state is blurred; false otherwise
*/
fun toggleBlur(): Boolean {
- if (blurred) removeBlur()
+ if (isBlurred) removeBlur()
else blur()
- return blurred
+ return isBlurred
}
/**
@@ -162,7 +163,7 @@ class BlurredImageView @JvmOverloads constructor(
*/
fun fullReset() {
reset()
- fullAction({ it.visible().background = null })
+ fullAction { it.visible().background = null }
image_foreground.setBackgroundColorRes(R.color.kau_blurred_image_selection_overlay)
image_foreground.setIcon(GoogleMaterial.Icon.gmd_check, 30, Color.WHITE)
}
diff --git a/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaActionItem.kt b/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaActionItem.kt
index 1941ec0..552bf0f 100644
--- a/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaActionItem.kt
+++ b/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaActionItem.kt
@@ -26,8 +26,8 @@ import ca.allanwang.kau.permissions.PERMISSION_WRITE_EXTERNAL_STORAGE
import ca.allanwang.kau.permissions.kauRequestPermissions
import ca.allanwang.kau.utils.materialDialog
import ca.allanwang.kau.utils.string
-import com.mikepenz.google_material_typeface_library.GoogleMaterial
import com.mikepenz.iconics.typeface.IIcon
+import com.mikepenz.iconics.typeface.library.googlematerial.GoogleMaterial
import java.io.File
/**
@@ -36,18 +36,26 @@ import java.io.File
class MediaActionItem(
val action: MediaAction,
val mediaType: MediaType
-) : KauIItem<MediaActionItem, MediaItemBasic.ViewHolder>(
+) : KauIItem<MediaItemBasic.ViewHolder>(
R.layout.kau_iitem_image_basic,
{ MediaItemBasic.ViewHolder(it) },
R.id.kau_item_media_action
) {
- override fun isSelectable(): Boolean = false
+ override var isSelectable: Boolean
+ get() = false
+ set(_) {}
override fun bindView(holder: MediaItemBasic.ViewHolder, payloads: MutableList<Any>) {
super.bindView(holder, payloads)
holder.image.apply {
- setImageDrawable(MediaPickerCore.getIconDrawable(context, action.iicon(this@MediaActionItem), action.color))
+ setImageDrawable(
+ MediaPickerCore.getIconDrawable(
+ context,
+ action.iicon(this@MediaActionItem),
+ action.color
+ )
+ )
setOnClickListener { action(context, this@MediaActionItem) }
}
}
diff --git a/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaItem.kt b/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaItem.kt
index 5d3e7b9..88a304f 100644
--- a/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaItem.kt
+++ b/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaItem.kt
@@ -24,33 +24,37 @@ import com.bumptech.glide.load.engine.GlideException
import com.bumptech.glide.request.RequestListener
import com.bumptech.glide.request.target.Target
import com.mikepenz.fastadapter.FastAdapter
+import com.mikepenz.fastadapter.select.getSelectExtension
/**
* Created by Allan Wang on 2017-07-04.
*/
class MediaItem(val data: MediaModel) :
- KauIItem<MediaItem, MediaItem.ViewHolder>(R.layout.kau_iitem_image, { ViewHolder(it) }),
+ KauIItem<MediaItem.ViewHolder>(R.layout.kau_iitem_image, { ViewHolder(it) }),
GlideContract by GlideDelegate() {
private var failedToLoad = false
companion object {
fun bindEvents(fastAdapter: FastAdapter<MediaItem>) {
- fastAdapter.withMultiSelect(true)
- .withSelectable(true)
- //adapter selector occurs before the on click event
- .withOnClickListener { v, _, item, _ ->
- val image = v as BlurredImageView
- if (item.isSelected) image.blur()
- else image.removeBlur()
- true
- }
+ fastAdapter.getSelectExtension().apply {
+ isSelectable = true
+ multiSelect = true
+ }
+ fastAdapter.onClickListener = { v, _, item, _ ->
+ val image = v as BlurredImageView
+ if (item.isSelected) image.blur()
+ else image.removeBlur()
+ true
+ }
}
}
- override fun isSelectable(): Boolean = !failedToLoad
+ override var isSelectable: Boolean
+ get() = !failedToLoad
+ set(_) {}
- override fun bindView(holder: ViewHolder, payloads: List<Any>) {
+ override fun bindView(holder: ViewHolder, payloads: MutableList<Any>) {
super.bindView(holder, payloads)
glide(holder.itemView)
.load(data.data)
@@ -63,7 +67,11 @@ class MediaItem(val data: MediaModel) :
isFirstResource: Boolean
): Boolean {
failedToLoad = true
- holder.container.imageBase.setImageDrawable(MediaPickerCore.getErrorDrawable(holder.itemView.context))
+ holder.container.imageBase.setImageDrawable(
+ MediaPickerCore.getErrorDrawable(
+ holder.itemView.context
+ )
+ )
return true
}
diff --git a/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaItemBasic.kt b/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaItemBasic.kt
index 73647b8..873289f 100644
--- a/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaItemBasic.kt
+++ b/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaItemBasic.kt
@@ -27,29 +27,32 @@ import com.bumptech.glide.load.engine.GlideException
import com.bumptech.glide.request.RequestListener
import com.bumptech.glide.request.target.Target
import com.mikepenz.fastadapter.FastAdapter
+import com.mikepenz.fastadapter.select.getSelectExtension
/**
* Created by Allan Wang on 2017-07-04.
*/
class MediaItemBasic(val data: MediaModel) :
- KauIItem<MediaItem, MediaItemBasic.ViewHolder>(R.layout.kau_iitem_image_basic, { ViewHolder(it) }),
+ KauIItem<MediaItemBasic.ViewHolder>(R.layout.kau_iitem_image_basic, { ViewHolder(it) }),
GlideContract by GlideDelegate() {
companion object {
@SuppressLint("NewApi")
fun bindEvents(activity: Activity, fastAdapter: FastAdapter<MediaItemBasic>) {
- fastAdapter.withSelectable(false)
- //add image data and return right away
- .withOnClickListener { _, _, item, _ ->
- activity.finish(arrayListOf(item.data))
- true
- }
+ fastAdapter.getSelectExtension().isSelectable = true
+ //add image data and return right away
+ fastAdapter.onClickListener = { _, _, item, _ ->
+ activity.finish(arrayListOf(item.data))
+ true
+ }
}
}
- override fun isSelectable(): Boolean = false
+ override var isSelectable: Boolean
+ get() = false
+ set(_) {}
- override fun bindView(holder: ViewHolder, payloads: List<Any>) {
+ override fun bindView(holder: ViewHolder, payloads: MutableList<Any>) {
super.bindView(holder, payloads)
glide(holder.itemView)
.load(data.data)
diff --git a/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaModel.kt b/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaModel.kt
index edd6199..1ba8041 100644
--- a/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaModel.kt
+++ b/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaModel.kt
@@ -85,6 +85,8 @@ data class MediaModel(
}
companion object CREATOR : Parcelable.Creator<MediaModel> {
+ @Suppress("DEPRECATION")
+ // TODO verify data deprecation
val projection = arrayOf(
MediaStore.MediaColumns.DATA,
MediaStore.MediaColumns.MIME_TYPE,
diff --git a/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaPickerActivityBase.kt b/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaPickerActivityBase.kt
index 5e5d1ed..c7cff55 100644
--- a/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaPickerActivityBase.kt
+++ b/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaPickerActivityBase.kt
@@ -26,7 +26,9 @@ import ca.allanwang.kau.utils.setIcon
import ca.allanwang.kau.utils.toDrawable
import ca.allanwang.kau.utils.toast
import com.google.android.material.appbar.AppBarLayout
-import com.mikepenz.google_material_typeface_library.GoogleMaterial
+import com.mikepenz.fastadapter.ISelectionListener
+import com.mikepenz.fastadapter.select.selectExtension
+import com.mikepenz.iconics.typeface.library.googlematerial.GoogleMaterial
import kotlinx.android.synthetic.main.kau_activity_image_picker.*
/**
@@ -46,21 +48,37 @@ abstract class MediaPickerActivityBase(
setContentView(R.layout.kau_activity_image_picker)
- kau_selection_count.setCompoundDrawables(null, null, GoogleMaterial.Icon.gmd_image.toDrawable(this, 18), null)
+ kau_selection_count.setCompoundDrawables(
+ null,
+ null,
+ GoogleMaterial.Icon.gmd_image.toDrawable(this, 18),
+ null
+ )
setSupportActionBar(kau_toolbar)
supportActionBar?.apply {
setDisplayHomeAsUpEnabled(true)
setDisplayShowHomeEnabled(true)
- setHomeAsUpIndicator(GoogleMaterial.Icon.gmd_close.toDrawable(this@MediaPickerActivityBase, 18))
+ setHomeAsUpIndicator(
+ GoogleMaterial.Icon.gmd_close.toDrawable(
+ this@MediaPickerActivityBase,
+ 18
+ )
+ )
}
kau_toolbar.setNavigationOnClickListener { onBackPressed() }
initializeRecycler(kau_recyclerview)
- MediaItem.bindEvents(adapter.fastAdapter)
- adapter.fastAdapter.withSelectionListener { _, _ ->
- kau_selection_count.text = adapter.selectionSize.toString()
+ adapter.fastAdapter!!.let {
+ MediaItem.bindEvents(it)
+ it.selectExtension {
+ selectionListener = object : ISelectionListener<MediaItem> {
+ override fun onSelectionChanged(item: MediaItem?, selected: Boolean) {
+ kau_selection_count.text = adapter.selectionSize.toString()
+ }
+ }
+ }
}
kau_fab.apply {
diff --git a/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaPickerActivityOverlayBase.kt b/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaPickerActivityOverlayBase.kt
index a7ee63d..df47688 100644
--- a/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaPickerActivityOverlayBase.kt
+++ b/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaPickerActivityOverlayBase.kt
@@ -39,7 +39,7 @@ abstract class MediaPickerActivityOverlayBase(
super.onCreate(savedInstanceState)
setContentView(R.layout.kau_activity_image_picker_overlay)
initializeRecycler(kau_recyclerview)
- MediaItemBasic.bindEvents(this, adapter.fastAdapter)
+ MediaItemBasic.bindEvents(this, adapter.fastAdapter!!)
kau_draggable.addExitListener(this, R.transition.kau_image_exit_bottom, R.transition.kau_image_exit_top)
kau_draggable.setOnClickListener { finishAfterTransition() }
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 e6556ab..dceb1df 100644
--- a/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaPickerCore.kt
+++ b/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaPickerCore.kt
@@ -44,11 +44,11 @@ import ca.allanwang.kau.utils.dimenPixelSize
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.GenericItem
import com.mikepenz.fastadapter.adapters.ItemAdapter
-import com.mikepenz.google_material_typeface_library.GoogleMaterial
-import com.mikepenz.iconics.IconicsDrawable
+import com.mikepenz.iconics.dsl.iconicsDrawable
import com.mikepenz.iconics.typeface.IIcon
+import com.mikepenz.iconics.typeface.library.googlematerial.GoogleMaterial
import kotlinx.coroutines.CancellationException
import java.io.File
@@ -57,7 +57,7 @@ import java.io.File
*
* Container for the main logic behind the both pickers
*/
-abstract class MediaPickerCore<T : IItem<*, *>>(
+abstract class MediaPickerCore<T : GenericItem>(
val mediaType: MediaType,
val mediaActions: List<MediaAction>
) : KauBaseActivity(), LoaderManager.LoaderCallbacks<Cursor> {
@@ -87,15 +87,17 @@ abstract class MediaPickerCore<T : IItem<*, *>>(
/**
* Create error tile for a given item
*/
- fun getErrorDrawable(context: Context) = getIconDrawable(context, GoogleMaterial.Icon.gmd_error, accentColor)
+ fun getErrorDrawable(context: Context) =
+ getIconDrawable(context, GoogleMaterial.Icon.gmd_error, accentColor)
fun getIconDrawable(context: Context, iicon: IIcon, color: Int): Drawable {
- val sizePx = MediaPickerCore.computeViewSize(context)
- return IconicsDrawable(context, iicon)
- .sizePx(sizePx)
- .backgroundColor(color)
- .paddingPx(sizePx / 3)
- .color(Color.WHITE)
+ val sizePx = computeViewSize(context)
+ return context.iconicsDrawable(iicon) {
+ size = sizePx(sizePx)
+ backgroundColor = colorInt(color)
+ padding = sizePx(sizePx / 3)
+ this.color = colorInt(Color.WHITE)
+ }
}
var accentColor: Int = 0xff666666.toInt()
@@ -105,9 +107,12 @@ abstract class MediaPickerCore<T : IItem<*, *>>(
* This is used for both single and multiple photo picks
*/
fun onMediaPickerResult(resultCode: Int, data: Intent?): List<MediaModel> {
- if (resultCode != Activity.RESULT_OK || data == null || !data.hasExtra(MEDIA_PICKER_RESULT))
+ if (resultCode != Activity.RESULT_OK ||
+ data?.hasExtra(MEDIA_PICKER_RESULT) != true
+ ) {
return emptyList()
- return data.getParcelableArrayListExtra(MEDIA_PICKER_RESULT)
+ }
+ return data.getParcelableArrayListExtra(MEDIA_PICKER_RESULT) ?: emptyList()
}
/**
@@ -134,12 +139,14 @@ abstract class MediaPickerCore<T : IItem<*, *>>(
fun initializeRecycler(recycler: RecyclerView) {
val adapterHeader = ItemAdapter<MediaActionItem>()
- val fulladapter = fastAdapter<IItem<*, *>>(adapterHeader, adapter)
+ val fulladapter = fastAdapter<GenericItem>(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 {
- return if (mediaType != MediaType.VIDEO) extraSpace else super.getExtraLayoutSpace(state)
+ return if (mediaType != MediaType.VIDEO) extraSpace else super.getExtraLayoutSpace(
+ state
+ )
}
}
setItemViewCacheSize(CACHE_SIZE)
@@ -154,7 +161,14 @@ abstract class MediaPickerCore<T : IItem<*, *>>(
var sortQuery = MediaStore.MediaColumns.DATE_MODIFIED + " DESC"
override fun onCreateLoader(id: Int, args: Bundle?): Loader<Cursor> {
- return CursorLoader(this, mediaType.contentUri, MediaModel.projection, null, null, sortQuery)
+ return CursorLoader(
+ this,
+ mediaType.contentUri,
+ MediaModel.projection,
+ null,
+ null,
+ sortQuery
+ )
}
/**
@@ -238,7 +252,11 @@ abstract class MediaPickerCore<T : IItem<*, *>>(
* Method used to retrieve uri data for API 19+
* See <a href="http://hmkcode.com/android-display-selected-image-and-its-real-path/"></a>
*/
- private fun <R> ContentResolver.query(baseUri: Uri, uris: List<Uri>, block: (cursor: Cursor) -> R) {
+ private fun <R> ContentResolver.query(
+ baseUri: Uri,
+ uris: List<Uri>,
+ block: (cursor: Cursor) -> R
+ ) {
val ids = uris.filter {
val valid = DocumentsContract.isDocumentUri(this@MediaPickerCore, it)
if (!valid) KL.d { "Non document uri: ${it.encodedPath}" }
@@ -248,15 +266,17 @@ abstract class MediaPickerCore<T : IItem<*, *>>(
}.joinToString(prefix = "(", separator = ",", postfix = ")")
//? query replacements are done for one arg at a time
//since we potentially have a list of ids, we'll just format the WHERE clause ourself
- query(baseUri, MediaModel.projection, "${BaseColumns._ID} IN $ids", null, sortQuery)?.use(block)
+ query(baseUri, MediaModel.projection, "${BaseColumns._ID} IN $ids", null, sortQuery)?.use(
+ block
+ )
}
internal var tempPath: String? = null
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
if (resultCode != RESULT_OK) {
- if (tempPath != null) {
- val f = File(tempPath)
+ tempPath?.let {
+ val f = File(it)
if (f.exists()) f.delete()
tempPath = null
}
@@ -272,14 +292,18 @@ abstract class MediaPickerCore<T : IItem<*, *>>(
private fun onCameraResult(data: Intent?) {
val f: File
- if (tempPath != null) {
- f = File(tempPath)
- tempPath = null
- } else if (data?.data != null) {
- f = File(data.data!!.path)
- } else {
- KL.d { "Media camera no file found" }
- return
+ val tempPath = tempPath
+ val dataPath = data?.data?.path
+ when {
+ tempPath != null -> {
+ f = File(tempPath)
+ this.tempPath = null
+ }
+ dataPath != null -> f = File(dataPath)
+ else -> {
+ KL.d { "Media camera no file found" }
+ return
+ }
}
if (f.exists()) {
KL.v { "Media camera path found: ${f.absolutePath}" }
@@ -292,9 +316,10 @@ abstract class MediaPickerCore<T : IItem<*, *>>(
private fun onPickerResult(data: Intent?) {
val items = mutableListOf<Uri>()
- if (data?.data != null) {
- KL.v { "Media picker data uri: ${data.data!!.path}" }
- items.add(data.data!!)
+ val _data = data?.data
+ if (_data != null) {
+ KL.v { "Media picker data uri: ${_data.path}" }
+ items.add(_data)
} else if (data != null) {
val clip = data.clipData
if (clip != null) {
diff --git a/sample/build.gradle b/sample/build.gradle
index 4e34bf9..ab98695 100644
--- a/sample/build.gradle
+++ b/sample/build.gradle
@@ -1,3 +1,5 @@
+import kau.Dependencies
+
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
@@ -54,8 +56,6 @@ android {
buildTypes {
debug {
- minifyEnabled false
- shrinkResources false
applicationIdSuffix ".debug"
versionNameSuffix "-debug"
signingConfig signingConfigs.debug
@@ -78,6 +78,7 @@ android {
packagingOptions {
pickFirst 'META-INF/core_release.kotlin_module'
pickFirst 'META-INF/library_release.kotlin_module'
+ pickFirst 'META-INF/library-core_release.kotlin_module'
}
compileOptions {
@@ -127,15 +128,15 @@ dependencies {
implementation project(':searchview')
implementation project(':mediapicker')
- implementation kau.Dependencies.materialDialog("input")
+ implementation Dependencies.materialDialog("input")
- testImplementation kau.Dependencies.kotlinTest
- testImplementation kau.Dependencies.junit
+ testImplementation Dependencies.kotlinTest
+ testImplementation Dependencies.junit
- androidTestImplementation kau.Dependencies.kotlinTest
- androidTestImplementation kau.Dependencies.espresso
- androidTestImplementation kau.Dependencies.espresso("intents")
- androidTestImplementation kau.Dependencies.espresso("contrib")
- androidTestImplementation kau.Dependencies.testRules
- androidTestImplementation kau.Dependencies.testRunner
+ androidTestImplementation Dependencies.kotlinTest
+ androidTestImplementation Dependencies.espresso
+ androidTestImplementation Dependencies.espresso("intents")
+ androidTestImplementation Dependencies.espresso("contrib")
+ androidTestImplementation Dependencies.testRules
+ androidTestImplementation Dependencies.testRunner
}
diff --git a/sample/proguard-rules.pro b/sample/proguard-rules.pro
index f3a65f0..3189ebb 100644
--- a/sample/proguard-rules.pro
+++ b/sample/proguard-rules.pro
@@ -1,2 +1,7 @@
-ignorewarnings
--dontwarn kotlin.** \ No newline at end of file
+-dontwarn kotlin.**
+# Iconics
+-keep class .R
+-keep class **.R$* {
+ <fields>;
+} \ No newline at end of file
diff --git a/sample/src/main/kotlin/ca/allanwang/kau/sample/AboutActivity.kt b/sample/src/main/kotlin/ca/allanwang/kau/sample/AboutActivity.kt
index 928070e..ffe769a 100644
--- a/sample/src/main/kotlin/ca/allanwang/kau/sample/AboutActivity.kt
+++ b/sample/src/main/kotlin/ca/allanwang/kau/sample/AboutActivity.kt
@@ -18,7 +18,7 @@ package ca.allanwang.kau.sample
import ca.allanwang.kau.about.AboutActivityBase
import ca.allanwang.kau.adapters.FastItemThemedAdapter
import ca.allanwang.kau.iitems.CardIItem
-import com.mikepenz.fastadapter.IItem
+import com.mikepenz.fastadapter.GenericItem
/**
* Created by Allan Wang on 2017-06-27.
@@ -33,7 +33,7 @@ class AboutActivity : AboutActivityBase(R.string::class.java, {
faqParseNewLine = false
}) {
- override fun postInflateMainPage(adapter: FastItemThemedAdapter<IItem<*, *>>) {
+ override fun postInflateMainPage(adapter: FastItemThemedAdapter<GenericItem>) {
adapter.add(CardIItem {
title = "About KAU"
descRes = R.string.about_kau
diff --git a/sample/src/main/kotlin/ca/allanwang/kau/sample/AdapterActivity.kt b/sample/src/main/kotlin/ca/allanwang/kau/sample/AdapterActivity.kt
index a11a672..b166210 100644
--- a/sample/src/main/kotlin/ca/allanwang/kau/sample/AdapterActivity.kt
+++ b/sample/src/main/kotlin/ca/allanwang/kau/sample/AdapterActivity.kt
@@ -20,9 +20,9 @@ import ca.allanwang.kau.adapters.fastAdapter
import ca.allanwang.kau.iitems.CardIItem
import ca.allanwang.kau.ui.activities.ElasticRecyclerActivity
import ca.allanwang.kau.utils.toast
-import com.mikepenz.fastadapter.IItem
+import com.mikepenz.fastadapter.GenericItem
import com.mikepenz.fastadapter.adapters.ItemAdapter
-import com.mikepenz.google_material_typeface_library.GoogleMaterial
+import com.mikepenz.iconics.typeface.library.googlematerial.GoogleMaterial
/**
* Created by Allan Wang on 2017-07-17.
@@ -30,7 +30,7 @@ import com.mikepenz.google_material_typeface_library.GoogleMaterial
class AdapterActivity : ElasticRecyclerActivity() {
override fun onCreate(savedInstanceState: Bundle?, configs: Configs): Boolean {
- val adapter = ItemAdapter<IItem<*, *>>()
+ val adapter = ItemAdapter<GenericItem>()
recycler.adapter = fastAdapter(adapter)
adapter.add(
listOf(
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 349e3d1..a5ef8c3 100644
--- a/sample/src/main/kotlin/ca/allanwang/kau/sample/AnimActivity.kt
+++ b/sample/src/main/kotlin/ca/allanwang/kau/sample/AnimActivity.kt
@@ -30,7 +30,7 @@ import ca.allanwang.kau.utils.startActivity
import ca.allanwang.kau.utils.toast
import ca.allanwang.kau.utils.withAlpha
import ca.allanwang.kau.utils.withSlideOut
-import com.mikepenz.fastadapter.commons.adapters.FastItemAdapter
+import com.mikepenz.fastadapter.adapters.FastItemAdapter
/**
* Created by Allan Wang on 2017-06-12.
@@ -43,14 +43,18 @@ class AnimActivity : KauBaseActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val adapter = FastItemAdapter<PermissionCheckbox>()
- setContentView(fullLinearRecycler(adapter).apply { setBackgroundColor(KPrefSample.bgColor.withAlpha(255)) })
+ setContentView(fullLinearRecycler(adapter).apply {
+ setBackgroundColor(
+ KPrefSample.bgColor.withAlpha(255)
+ )
+ })
adapter.add(listOf(
PERMISSION_ACCESS_COARSE_LOCATION,
PERMISSION_ACCESS_FINE_LOCATION,
PERMISSION_CAMERA
).map { PermissionCheckbox(it) })
- adapter.withOnClickListener { _, _, item, _ ->
+ adapter.onClickListener = { _, _, item, _ ->
KL.d { "Perm Click" }
kauRequestPermissions(item.permission) { granted, _ ->
toast("${item.permission} enabled: $granted")
diff --git a/sample/src/main/kotlin/ca/allanwang/kau/sample/MainActivity.kt b/sample/src/main/kotlin/ca/allanwang/kau/sample/MainActivity.kt
index 9ce3f42..11d19e5 100644
--- a/sample/src/main/kotlin/ca/allanwang/kau/sample/MainActivity.kt
+++ b/sample/src/main/kotlin/ca/allanwang/kau/sample/MainActivity.kt
@@ -39,7 +39,7 @@ import ca.allanwang.kau.utils.toast
import ca.allanwang.kau.utils.withSceneTransitionAnimation
import ca.allanwang.kau.xml.showChangelog
import com.afollestad.materialdialogs.input.input
-import com.mikepenz.google_material_typeface_library.GoogleMaterial
+import com.mikepenz.iconics.typeface.library.googlematerial.GoogleMaterial
class MainActivity : KPrefActivity() {
@@ -106,7 +106,7 @@ class MainActivity : KPrefActivity() {
accentColor = KPrefSample::accentColor
}
- override fun onCreateKPrefs(savedInstanceState: android.os.Bundle?): KPrefAdapterBuilder.() -> Unit = {
+ override fun onCreateKPrefs(savedInstanceState: Bundle?): KPrefAdapterBuilder.() -> Unit = {
header(R.string.header)
diff --git a/sample/src/main/kotlin/ca/allanwang/kau/sample/PermissionCheckbox.kt b/sample/src/main/kotlin/ca/allanwang/kau/sample/PermissionCheckbox.kt
index 025179d..7cf6cc1 100644
--- a/sample/src/main/kotlin/ca/allanwang/kau/sample/PermissionCheckbox.kt
+++ b/sample/src/main/kotlin/ca/allanwang/kau/sample/PermissionCheckbox.kt
@@ -25,7 +25,7 @@ import ca.allanwang.kau.utils.hasPermission
/**
* Created by Allan Wang on 2017-07-03.
*/
-class PermissionCheckbox(val permission: String) : KauIItem<PermissionCheckbox, PermissionCheckbox.ViewHolder>(
+class PermissionCheckbox(val permission: String) : KauIItem<PermissionCheckbox.ViewHolder>(
R.layout.permission_checkbox, { ViewHolder(it) }) {
override fun bindView(holder: ViewHolder, payloads: MutableList<Any>) {
diff --git a/sample/src/main/res/xml/kau_changelog.xml b/sample/src/main/res/xml/kau_changelog.xml
index 62614ed..de73b41 100644
--- a/sample/src/main/res/xml/kau_changelog.xml
+++ b/sample/src/main/res/xml/kau_changelog.xml
@@ -6,6 +6,11 @@
<item text="" />
-->
+ <version title="v5.2.0" />
+ <item text=":fastadapter: Migrate fastadapter to v4.x.x" />
+ <item text="" />
+ <item text="" />
+
<version title="v5.1.0" />
<item text=":adapter: Moved fastadapter elements to new module, :fastadapter:. To migrate, simply rename the dependency. If you don't use fast adapter, no changes are necessary" />
<item text=":adapter: Make NoAnimatorChange an object; previously a class" />
diff --git a/searchview/build.gradle b/searchview/build.gradle
index f9e83fc..64a88b3 100644
--- a/searchview/build.gradle
+++ b/searchview/build.gradle
@@ -1,3 +1,5 @@
+import kau.Dependencies
+
ext.kauSubModuleResourcePrefix = "kau_search_"
apply from: '../android-lib.gradle'
diff --git a/searchview/src/main/kotlin/ca/allanwang/kau/searchview/SearchItem.kt b/searchview/src/main/kotlin/ca/allanwang/kau/searchview/SearchItem.kt
index 7747d81..7bf01b3 100644
--- a/searchview/src/main/kotlin/ca/allanwang/kau/searchview/SearchItem.kt
+++ b/searchview/src/main/kotlin/ca/allanwang/kau/searchview/SearchItem.kt
@@ -32,7 +32,7 @@ import ca.allanwang.kau.utils.setIcon
import ca.allanwang.kau.utils.setRippleBackground
import ca.allanwang.kau.utils.visible
import com.mikepenz.iconics.typeface.IIcon
-import com.mikepenz.google_material_typeface_library.GoogleMaterial
+import com.mikepenz.iconics.typeface.library.googlematerial.GoogleMaterial
/**
* Created by Allan Wang on 2017-06-23.
@@ -47,7 +47,7 @@ class SearchItem(
val description: String? = null,
val iicon: IIcon? = GoogleMaterial.Icon.gmd_search,
val image: Drawable? = null
-) : KauIItem<SearchItem, SearchItem.ViewHolder>(
+) : KauIItem<SearchItem.ViewHolder>(
R.layout.kau_search_iitem,
{ ViewHolder(it) },
R.id.kau_item_search
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 10f2de3..da06ec4 100644
--- a/searchview/src/main/kotlin/ca/allanwang/kau/searchview/SearchView.kt
+++ b/searchview/src/main/kotlin/ca/allanwang/kau/searchview/SearchView.kt
@@ -62,9 +62,10 @@ import ca.allanwang.kau.utils.tint
import ca.allanwang.kau.utils.toDrawable
import ca.allanwang.kau.utils.visible
import ca.allanwang.kau.utils.withLinearAdapter
-import com.mikepenz.fastadapter.commons.adapters.FastItemAdapter
+import com.mikepenz.fastadapter.adapters.FastItemAdapter
+import com.mikepenz.fastadapter.select.selectExtension
import com.mikepenz.iconics.typeface.IIcon
-import com.mikepenz.google_material_typeface_library.GoogleMaterial
+import com.mikepenz.iconics.typeface.library.googlematerial.GoogleMaterial
import kotlinx.android.synthetic.main.kau_search_view.view.*
/**
@@ -255,7 +256,11 @@ class SearchView @JvmOverloads constructor(
val list = if (value.isEmpty() && configs.noResultsFound != INVALID_ID)
listOf(SearchItem("", context.string(configs.noResultsFound), iicon = null))
else value
- if (configs.highlightQueryText && value.isNotEmpty()) list.forEach { it.withHighlights(kau_search_edit_text.text?.toString()) }
+ if (configs.highlightQueryText && value.isNotEmpty()) list.forEach {
+ it.withHighlights(
+ kau_search_edit_text.text?.toString()
+ )
+ }
cardTransition()
adapter.setNewList(list)
}
@@ -297,7 +302,8 @@ class SearchView @JvmOverloads constructor(
View.inflate(context, R.layout.kau_search_view, this)
z = 99f
kau_search_nav.setSearchIcon(configs.navIcon).setOnClickListener { revealClose() }
- kau_search_clear.setSearchIcon(configs.clearIcon).setOnClickListener { kau_search_edit_text.text?.clear() }
+ kau_search_clear.setSearchIcon(configs.clearIcon)
+ .setOnClickListener { kau_search_edit_text.text?.clear() }
tintForeground(configs.foregroundColor)
tintBackground(configs.backgroundColor)
with(kau_search_recycler) {
@@ -312,11 +318,18 @@ class SearchView @JvmOverloads constructor(
itemAnimator = null
}
with(adapter) {
- withSelectable(true)
- withOnClickListener { _, _, item, position ->
- if (item.key.isNotBlank()) configs.onItemClick(position, item.key, item.content, this@SearchView); true
+ selectExtension {
+ isSelectable = true
+ }
+ onClickListener = { _, _, item, position ->
+ if (item.key.isNotBlank()) configs.onItemClick(
+ position,
+ item.key,
+ item.content,
+ this@SearchView
+ ); true
}
- withOnLongClickListener { _, _, item, position ->
+ onLongClickListener = { _, _, item, position ->
if (item.key.isNotBlank()) configs.onItemLongClick(
position,
item.key,
@@ -390,7 +403,9 @@ class SearchView @JvmOverloads constructor(
config(config)
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)
+ if (menuItem.icon == null) {
+ menuItem.icon = GoogleMaterial.Icon.gmd_search.toDrawable(context, 18, menuIconColor)
+ }
kau_search_cardview.gone()
menuItem.setOnMenuItemClickListener { revealOpen(); true }
kau_search_shadow.setOnClickListener { revealClose() }
@@ -418,7 +433,8 @@ class SearchView @JvmOverloads constructor(
menuX = (locations[0] + view.width / 2)
menuHalfHeight = view.height / 2
menuY = (locations[1] + menuHalfHeight)
- kau_search_cardview.viewTreeObserver.addOnPreDrawListener(object : ViewTreeObserver.OnPreDrawListener {
+ kau_search_cardview.viewTreeObserver.addOnPreDrawListener(object :
+ ViewTreeObserver.OnPreDrawListener {
override fun onPreDraw(): Boolean {
view.viewTreeObserver.removeOnPreDrawListener(this)
kau_search_cardview.setMarginTop(menuY - kau_search_cardview.height / 2)
@@ -472,7 +488,11 @@ class SearchView @JvmOverloads constructor(
configs.openListener?.invoke(this@SearchView)
kau_search_shadow.fadeIn()
kau_search_edit_text.showKeyboard()
- kau_search_cardview.circularReveal(menuX, menuHalfHeight, duration = configs.revealDuration) {
+ kau_search_cardview.circularReveal(
+ menuX,
+ menuHalfHeight,
+ duration = configs.revealDuration
+ ) {
cardTransition()
kau_search_recycler.visible()
}
@@ -485,7 +505,9 @@ class SearchView @JvmOverloads constructor(
kau_search_shadow.fadeOut(duration = configs.transitionDuration)
cardTransition {
addEndListener {
- kau_search_cardview.circularHide(menuX, menuHalfHeight, duration = configs.revealDuration,
+ kau_search_cardview.circularHide(menuX,
+ menuHalfHeight,
+ duration = configs.revealDuration,
onFinish = {
configs.closeListener?.invoke(this@SearchView)
if (configs.shouldClearOnClose) kau_search_edit_text.text?.clear()
@@ -509,8 +531,9 @@ fun Activity.bindSearchView(
menu: Menu,
@IdRes id: Int,
@ColorInt menuIconColor: Int = Color.WHITE,
- config: SearchView.Configs.() -> Unit = {}
-): SearchView = findViewById<ViewGroup>(android.R.id.content).bindSearchView(menu, id, menuIconColor, config)
+ config: Configs.() -> Unit = {}
+): SearchView =
+ findViewById<ViewGroup>(android.R.id.content).bindSearchView(menu, id, menuIconColor, config)
/**
* Bind searchView to a menu item; call this in [Activity.onCreateOptionsMenu]
@@ -522,11 +545,14 @@ fun ViewGroup.bindSearchView(
menu: Menu,
@IdRes id: Int,
@ColorInt menuIconColor: Int = Color.WHITE,
- config: SearchView.Configs.() -> Unit = {}
+ config: Configs.() -> Unit = {}
): SearchView {
val searchView = SearchView(context)
searchView.layoutParams =
- FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT)
+ FrameLayout.LayoutParams(
+ FrameLayout.LayoutParams.MATCH_PARENT,
+ FrameLayout.LayoutParams.MATCH_PARENT
+ )
addView(searchView)
searchView.bind(menu, id, menuIconColor, config)
return searchView