aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore4
-rw-r--r--.idea/vcs.xml6
-rw-r--r--about/build.gradle4
-rw-r--r--about/src/main/kotlin/ca/allanwang/kau/about/AboutActivityBase.kt40
-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.kt8
-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.kt30
-rw-r--r--adapter/build.gradle4
-rw-r--r--android-lib.gradle24
-rw-r--r--build.gradle20
-rw-r--r--buildSrc/src/main/kotlin/kau/Dependencies.kt49
-rw-r--r--buildSrc/src/main/kotlin/kau/Versions.kt34
-rw-r--r--core-ui/src/main/kotlin/ca/allanwang/kau/ui/activities/ElasticRecyclerActivity.kt4
-rw-r--r--core-ui/src/main/kotlin/ca/allanwang/kau/ui/widgets/ElasticDragDismissFrameLayout.kt5
-rw-r--r--core-ui/src/main/kotlin/ca/allanwang/kau/ui/widgets/TextSlider.kt2
-rw-r--r--core-ui/src/main/res-public/values/public.xml2
-rw-r--r--core/src/androidTest/kotlin/ca/allanwang/kau/kpref/KPrefTest.kt2
-rw-r--r--core/src/main/kotlin/ca/allanwang/kau/email/EmailBuilder.kt3
-rw-r--r--core/src/main/kotlin/ca/allanwang/kau/kotlin/Streams.kt11
-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/logging/KauLogger.kt15
-rw-r--r--core/src/main/kotlin/ca/allanwang/kau/permissions/PermissionManager.kt2
-rw-r--r--core/src/main/kotlin/ca/allanwang/kau/permissions/Permissions.kt4
-rw-r--r--core/src/main/kotlin/ca/allanwang/kau/swipe/RelativeSlider.kt2
-rw-r--r--core/src/main/kotlin/ca/allanwang/kau/swipe/SwipeBackHelper.kt2
-rw-r--r--core/src/main/kotlin/ca/allanwang/kau/swipe/SwipeBackLayout.kt26
-rw-r--r--core/src/main/kotlin/ca/allanwang/kau/ui/ProgressAnimator.kt8
-rw-r--r--core/src/main/kotlin/ca/allanwang/kau/ui/views/CollapsibleViewDelegate.kt38
-rw-r--r--core/src/main/kotlin/ca/allanwang/kau/ui/views/MeasureSpecDelegate.kt26
-rw-r--r--core/src/main/kotlin/ca/allanwang/kau/ui/views/RippleCanvas.kt3
-rw-r--r--core/src/main/kotlin/ca/allanwang/kau/utils/ActivityUtils.kt6
-rw-r--r--core/src/main/kotlin/ca/allanwang/kau/utils/ColorUtils.kt2
-rw-r--r--core/src/main/kotlin/ca/allanwang/kau/utils/ContextUtils.kt37
-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.kt8
-rw-r--r--core/src/main/kotlin/ca/allanwang/kau/utils/PackageUtils.kt4
-rw-r--r--core/src/main/kotlin/ca/allanwang/kau/utils/ViewUtils.kt22
-rw-r--r--core/src/main/kotlin/ca/allanwang/kau/xml/Changelog.kt10
-rw-r--r--core/src/main/kotlin/ca/allanwang/kau/xml/FAQ.kt2
-rw-r--r--core/src/main/res-public/values/public.xml2
-rw-r--r--core/src/test/kotlin/ca/allanwang/kau/kotlin/DebounceTest.kt8
-rw-r--r--core/src/test/kotlin/ca/allanwang/kau/kotlin/StreamsTest.kt4
-rw-r--r--docs/Changelog.md3
-rw-r--r--fastadapter-databinding/.gitignore1
-rw-r--r--fastadapter-databinding/build.gradle21
-rw-r--r--fastadapter-databinding/consumer-rules.pro0
-rw-r--r--fastadapter-databinding/proguard-rules.pro21
-rw-r--r--fastadapter-databinding/src/main/AndroidManifest.xml1
-rw-r--r--fastadapter-databinding/src/main/kotlin/ca/allanwang/fastadapter/databinding/BindingItem.kt123
-rw-r--r--fastadapter/build.gradle10
-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.kt69
-rw-r--r--fastadapter/src/main/kotlin/ca/allanwang/kau/adapters/RepeatedClickListener.kt24
-rw-r--r--fastadapter/src/main/kotlin/ca/allanwang/kau/adapters/SingleFastAdapter.kt57
-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--gradle/wrapper/gradle-wrapper.properties2
-rw-r--r--kpref-activity/build.gradle2
-rw-r--r--kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/KPrefActivity.kt19
-rw-r--r--kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefCheckbox.kt7
-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.kt35
-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.kt92
-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.kt6
-rw-r--r--sample/src/main/kotlin/ca/allanwang/kau/sample/PermissionCheckbox.kt4
-rw-r--r--sample/src/main/res/xml/kau_changelog.xml6
-rw-r--r--searchview/build.gradle2
-rw-r--r--searchview/src/main/kotlin/ca/allanwang/kau/searchview/SearchItem.kt19
-rw-r--r--searchview/src/main/kotlin/ca/allanwang/kau/searchview/SearchView.kt118
-rw-r--r--settings.gradle1
92 files changed, 1001 insertions, 487 deletions
diff --git a/.gitignore b/.gitignore
index ef20a58..f08bd63 100644
--- a/.gitignore
+++ b/.gitignore
@@ -28,4 +28,6 @@
.idea/**/assetWizardSettings.xml
.idea/**/caches
.idea/modules.xml
-.idea/modules \ No newline at end of file
+.idea/modules
+.idea/vcs.xml
+.idea/codeStyles/Project.xml \ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
deleted file mode 100644
index 35eb1dd..0000000
--- a/.idea/vcs.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<project version="4">
- <component name="VcsDirectoryMappings">
- <mapping directory="" vcs="Git" />
- </component>
-</project> \ No newline at end of file
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..7ba7811 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.*
/**
@@ -47,7 +47,10 @@ import kotlinx.android.synthetic.main.kau_activity_about.*
* Note that for the auto detection to work, the R fields must be excluded from Proguard
* Manual lib listings and other extra modifications can be done so by overriding the open functions
*/
-abstract class AboutActivityBase(val rClass: Class<*>?, private val configBuilder: Configs.() -> Unit = {}) :
+abstract class AboutActivityBase(
+ val rClass: Class<*>?,
+ private val configBuilder: Configs.() -> Unit = {}
+) :
KauBaseActivity(), ViewPager.OnPageChangeListener {
val currentPage: Int
@@ -69,7 +72,9 @@ abstract class AboutActivityBase(val rClass: Class<*>?, private val configBuilde
val panels: List<AboutPanelContract> by lazy {
val defaultPanels = mutableListOf(AboutPanelMain(), AboutPanelLibs())
- if (configs.faqXmlRes != INVALID_ID) defaultPanels.add(AboutPanelFaqs())
+ if (configs.faqXmlRes != INVALID_ID) {
+ defaultPanels.add(AboutPanelFaqs())
+ }
defaultPanels
}
@@ -77,8 +82,10 @@ abstract class AboutActivityBase(val rClass: Class<*>?, private val configBuilde
super.onCreate(savedInstanceState)
setContentView(R.layout.kau_activity_about)
pageStatus = IntArray(panels.size)
- pageStatus[0] = 2 //the first page is instantly visible
- if (configs.textColor != null) about_indicator.setColour(configs.textColor!!)
+ pageStatus[0] = 2 // the first page is instantly visible
+ if (configs.textColor != null) {
+ about_indicator.setColour(configs.textColor!!)
+ }
with(about_pager) {
adapter = AboutPagerAdapter()
pageMargin = dimenPixelSize(R.dimen.kau_spacing_normal)
@@ -86,7 +93,8 @@ abstract class AboutActivityBase(val rClass: Class<*>?, private val configBuilde
addOnPageChangeListener(this@AboutActivityBase)
}
about_indicator.setViewPager(about_pager)
- about_draggable_frame.addListener(object : ElasticDragDismissFrameLayout.SystemChromeFader(this) {
+ about_draggable_frame.addListener(object :
+ ElasticDragDismissFrameLayout.SystemChromeFader(this) {
override fun onDragDismissed() {
window.returnTransition = TransitionInflater.from(this@AboutActivityBase)
.inflateTransition(if (about_draggable_frame.translationY > 0) R.transition.kau_exit_slide_bottom else R.transition.kau_exit_slide_top)
@@ -107,14 +115,14 @@ abstract class AboutActivityBase(val rClass: Class<*>?, private val configBuilde
var libPageTitle: String? = null
set(value) {
field = value
- libPageTitleRes = INVALID_ID //reset res so we don't use our default
+ libPageTitleRes = INVALID_ID // reset res so we don't use our default
}
var faqXmlRes: Int = INVALID_ID
var faqPageTitleRes: Int = R.string.kau_about_faq_intro
var faqPageTitle: String? = null
set(value) {
field = value
- faqPageTitleRes = INVALID_ID //reset res so we don't use our default
+ faqPageTitleRes = INVALID_ID // reset res so we don't use our default
}
/**
* Whether new lines should be included
@@ -128,7 +136,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>) {
}
/**
@@ -138,7 +146,14 @@ abstract class AboutActivityBase(val rClass: Class<*>?, private val configBuilde
* This is fetched asynchronously and you may override it to customize the list
*/
open fun getLibraries(libs: Libs): List<Library> =
- libs.prepareLibraries(this, null, null, true, true, true)!!
+ libs.prepareLibraries(
+ this,
+ null,
+ null,
+ true,
+ true,
+ true
+ )
/*
* -------------------------------------------------------------------
@@ -178,7 +193,8 @@ abstract class AboutActivityBase(val rClass: Class<*>?, private val configBuilde
override fun onPageScrollStateChanged(state: Int) = Unit
- override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) = Unit
+ override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) =
+ Unit
override fun onPageSelected(position: Int) {
if (pageStatus[position] == 0) pageStatus[position] = 1 // mark as seen if previously null
@@ -186,7 +202,7 @@ abstract class AboutActivityBase(val rClass: Class<*>?, private val configBuilde
}
override fun onDestroy() {
- AnimHolder.decelerateInterpolator.invalidate() //clear the reference to the interpolators we've used
+ AnimHolder.decelerateInterpolator.invalidate() // clear the reference to the interpolators we've used
super.onDestroy()
}
}
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..d92f6a7 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)
@@ -45,7 +47,7 @@ class CutoutIItem(val config: CutoutView.() -> Unit = {}) : KauIItem<CutoutIItem
super.unbindView(holder)
with(holder) {
cutout.drawable = null
- cutout.text = "Text" //back to default
+ cutout.text = "Text" // back to default
}
}
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..cd53f55 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,35 @@ 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..cf8998f 100644
--- a/build.gradle
+++ b/build.gradle
@@ -1,4 +1,8 @@
+import kau.ChangelogGenerator
+import kau.Plugins
+
buildscript {
+
repositories {
google()
jcenter()
@@ -7,13 +11,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 +28,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..b2cdf48 100644
--- a/buildSrc/src/main/kotlin/kau/Dependencies.kt
+++ b/buildSrc/src/main/kotlin/kau/Dependencies.kt
@@ -7,8 +7,34 @@ object Dependencies {
@JvmStatic
fun kau(version: String) = "ca.allanwang:kau:$version"
+ private fun kau(type: String, version: String) = "ca.allanwang.kau:$type:$version"
+
+ @JvmStatic
+ fun kauAbout(version: String) = kau("about", version)
+
+ @JvmStatic
+ fun kauAdapter(version: String) = kau("adapter", version)
+
@JvmStatic
- fun kau(type: String, version: String) = "ca.allanwang.kau:$type:$version"
+ fun kauColorPicker(version: String) = kau("colorpicker", version)
+
+ @JvmStatic
+ fun kauCore(version: String) = kau("core", version)
+
+ @JvmStatic
+ fun kauCoreUi(version: String) = kau("core-ui", version)
+
+ @JvmStatic
+ fun kauFastAdapter(version: String) = kau("fastadapter", version)
+
+ @JvmStatic
+ fun kauKprefActivity(version: String) = kau("kpref-activity", version)
+
+ @JvmStatic
+ fun kauMediaPicker(version: String) = kau("mediapicker", version)
+
+ @JvmStatic
+ fun kauSearchView(version: String) = kau("searchview", version)
@JvmStatic
fun kotlin(type: String) = "org.jetbrains.kotlin:kotlin-$type:${Versions.kotlin}"
@@ -26,13 +52,17 @@ object Dependencies {
const val appcompat = "androidx.appcompat:appcompat:${Versions.appcompat}"
const val recyclerView = "androidx.recyclerview:recyclerview:${Versions.recyclerView}"
const val cardView = "androidx.cardview:cardview:${Versions.cardView}"
- const val constraintLayout = "androidx.constraintlayout:constraintlayout:${Versions.constraintLayout}"
+ const val constraintLayout =
+ "androidx.constraintlayout:constraintlayout:${Versions.constraintLayout}"
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}"
@@ -42,17 +72,16 @@ object Dependencies {
const val glideKapt = "com.github.bumptech.glide:compiler:${Versions.glide}"
@JvmStatic
- fun materialDialog(type: String) = "com.afollestad.material-dialogs:$type:${Versions.materialDialog}"
+ fun materialDialog(type: String) =
+ "com.afollestad.material-dialogs:$type:${Versions.materialDialog}"
@JvmField
val materialDialog = materialDialog("core")
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 515f702..3c54625 100644
--- a/buildSrc/src/main/kotlin/kau/Versions.kt
+++ b/buildSrc/src/main/kotlin/kau/Versions.kt
@@ -9,25 +9,25 @@ object Versions {
const val buildTools = "29.0.0"
// https://mvnrepository.com/artifact/androidx.appcompat/appcompat?repo=google
- const val appcompat = "1.0.2"
+ const val appcompat = "1.1.0-rc01"
// https://mvnrepository.com/artifact/com.google.android.material/material
const val googleMaterial = "1.0.0"
// https://mvnrepository.com/artifact/androidx.recyclerview/recyclerview
- const val recyclerView = "1.0.0"
+ const val recyclerView = "1.1.0-beta04"
// https://mvnrepository.com/artifact/androidx.cardview/cardview
const val cardView = "1.0.0"
// https://mvnrepository.com/artifact/androidx.constraintlayout/constraintlayout
- const val constraintLayout = "1.1.3"
+ const val constraintLayout = "2.0.0-beta2"
// https://kotlinlang.org/docs/reference/using-gradle.html
- const val kotlin = "1.3.31"
+ const val kotlin = "1.3.50"
// https://github.com/Kotlin/kotlinx.coroutines/releases
- const val coroutines = "1.3.0-M1"
+ const val coroutines = "1.3.1"
// https://github.com/mikepenz/AboutLibraries/releases
const val aboutLibraries = "6.2.3"
@@ -35,20 +35,20 @@ object Versions {
// https://github.com/wasabeef/Blurry/releases
const val blurry = "3.0.0"
- // https://github.com/mikepenz/FastAdapter#using-maven
- const val fastAdapter = "3.3.1"
+ // https://github.com/mikepenz/FastAdapter/releases
+ const val fastAdapter = "4.1.0-b02"
// 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-b02"
+ 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
- const val materialDialog = "3.0.0-rc2"
+ const val materialDialog = "3.1.1"
// https://mvnrepository.com/artifact/androidx.test.espresso/espresso-core?repo=google
const val espresso = "3.1.1"
@@ -62,24 +62,24 @@ object Versions {
const val testRules = "1.1.1"
// https://github.com/diffplug/spotless/blob/master/plugin-gradle/CHANGES.md
- const val spotless = "3.18.0"
+ const val spotless = "3.24.2"
// https://github.com/bugsnag/bugsnag-android/releases
- const val bugsnag = "4.12.0"
+ const val bugsnag = "4.19.1"
// https://github.com/bugsnag/bugsnag-android-gradle-plugin/releases
- const val bugsnagPlugin="4.1.1"
+ const val bugsnagPlugin="4.5.2"
// https://mvnrepository.com/artifact/com.android.tools.build/gradle?repo=google
- const val gradlePlugin = "3.4.1"
+ const val gradlePlugin = "3.5.0"
// https://github.com/dcendents/android-maven-gradle-plugin/releases
const val mavenPlugin = "2.1"
// https://github.com/Triple-T/gradle-play-publisher/releases
- const val playPublishPlugin = "2.2.1"
+ const val playPublishPlugin = "2.4.1"
// https://github.com/KeepSafe/dexcount-gradle-plugin/releases
const val dexCountPlugin = "0.8.6"
// https://github.com/gladed/gradle-android-git-version/releases
- const val gitVersionPlugin = "0.4.9"
+ const val gitVersionPlugin = "0.4.10"
} \ No newline at end of file
diff --git a/core-ui/src/main/kotlin/ca/allanwang/kau/ui/activities/ElasticRecyclerActivity.kt b/core-ui/src/main/kotlin/ca/allanwang/kau/ui/activities/ElasticRecyclerActivity.kt
index aff4d1c..3e7254f 100644
--- a/core-ui/src/main/kotlin/ca/allanwang/kau/ui/activities/ElasticRecyclerActivity.kt
+++ b/core-ui/src/main/kotlin/ca/allanwang/kau/ui/activities/ElasticRecyclerActivity.kt
@@ -53,7 +53,9 @@ abstract class ElasticRecyclerActivity : KauBaseActivity() {
super.onCreate(savedInstanceState)
setContentView(R.layout.kau_elastic_recycler_activity)
setSupportActionBar(kau_toolbar)
- if (!onCreate(savedInstanceState, configs)) return
+ if (!onCreate(savedInstanceState, configs)) {
+ return
+ }
kau_draggable.addListener(object : ElasticDragDismissFrameLayout.SystemChromeFader(this) {
override fun onDragDismissed() {
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..6095a32 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
@@ -205,7 +204,9 @@ class ElasticDragDismissFrameLayout @JvmOverloads constructor(
}
translationY = dragTo
- if (shouldScale) scaleXY = 1 - (1 - dragDismissScale) * dragFraction
+ if (shouldScale) {
+ scaleXY = 1 - (1 - dragDismissScale) * dragFraction
+ }
// if we've reversed direction and gone past the settle point then clear the flags to
// allow the list to get the scroll events & reset any transforms
diff --git a/core-ui/src/main/kotlin/ca/allanwang/kau/ui/widgets/TextSlider.kt b/core-ui/src/main/kotlin/ca/allanwang/kau/ui/widgets/TextSlider.kt
index 51f7ab9..726f5b6 100644
--- a/core-ui/src/main/kotlin/ca/allanwang/kau/ui/widgets/TextSlider.kt
+++ b/core-ui/src/main/kotlin/ca/allanwang/kau/ui/widgets/TextSlider.kt
@@ -138,7 +138,7 @@ class TextSlider @JvmOverloads constructor(
init {
setFactory {
TextView(context).apply {
- //replica of toolbar title
+ // replica of toolbar title
gravity = Gravity.START
setSingleLine()
ellipsize = TextUtils.TruncateAt.END
diff --git a/core-ui/src/main/res-public/values/public.xml b/core-ui/src/main/res-public/values/public.xml
index af7ce44..c8c2e56 100644
--- a/core-ui/src/main/res-public/values/public.xml
+++ b/core-ui/src/main/res-public/values/public.xml
@@ -1,4 +1,4 @@
-<resources xmlns:tools='http://schemas.android.com/tools' tools:ignore='ResourceName'>
+<resources xmlns:tools='http://schemas.android.com/tools' tools:ignore='ResourceName'>
<!-- AUTO-GENERATED FILE. DO NOT MODIFY. public.xml is generated by the generatepublicxml gradle task -->
<public name='kau_recycler_detached_background' type='layout' />
<public name='kau_elastic_recycler_activity' type='layout' />
diff --git a/core/src/androidTest/kotlin/ca/allanwang/kau/kpref/KPrefTest.kt b/core/src/androidTest/kotlin/ca/allanwang/kau/kpref/KPrefTest.kt
index 143b83f..64c4a37 100644
--- a/core/src/androidTest/kotlin/ca/allanwang/kau/kpref/KPrefTest.kt
+++ b/core/src/androidTest/kotlin/ca/allanwang/kau/kpref/KPrefTest.kt
@@ -103,7 +103,7 @@ class KPrefTest {
pref { one = 2 }
assertPrefEquals(2, { one })
assertPrefEquals(6, { prefMap.size }, "Prefmap does not have all elements")
- pref { reset() } //only invalidates our lazy delegate; doesn't change the actual pref
+ pref { reset() } // only invalidates our lazy delegate; doesn't change the actual pref
assertPrefEquals(2, { one }, "Kpref did not properly fetch from shared prefs")
// Android pref only
androidPref.sp.edit().putInt("one", -1).commit()
diff --git a/core/src/main/kotlin/ca/allanwang/kau/email/EmailBuilder.kt b/core/src/main/kotlin/ca/allanwang/kau/email/EmailBuilder.kt
index 78661b1..5ae8376 100644
--- a/core/src/main/kotlin/ca/allanwang/kau/email/EmailBuilder.kt
+++ b/core/src/main/kotlin/ca/allanwang/kau/email/EmailBuilder.kt
@@ -104,8 +104,9 @@ class EmailBuilder(val email: String, val subject: String) {
if (packages.isNotEmpty()) {
emailBuilder.append("\n")
packages.forEach {
- if (context.isAppInstalled(it.packageName))
+ if (context.isAppInstalled(it.packageName)) {
emailBuilder.append(String.format("\n%s is installed", it.appName))
+ }
}
}
diff --git a/core/src/main/kotlin/ca/allanwang/kau/kotlin/Streams.kt b/core/src/main/kotlin/ca/allanwang/kau/kotlin/Streams.kt
index 65d15a7..582b0cd 100644
--- a/core/src/main/kotlin/ca/allanwang/kau/kotlin/Streams.kt
+++ b/core/src/main/kotlin/ca/allanwang/kau/kotlin/Streams.kt
@@ -26,8 +26,11 @@ package ca.allanwang.kau.kotlin
*/
inline fun <T, C : MutableIterable<T>> C.kauRemoveIf(filter: (item: T) -> Boolean): C {
val iter = iterator()
- while (iter.hasNext())
- if (filter(iter.next())) iter.remove()
+ while (iter.hasNext()) {
+ if (filter(iter.next())) {
+ iter.remove()
+ }
+ }
return this
}
@@ -38,7 +41,9 @@ inline fun <T, C : MutableIterable<T>> C.kauRemoveIf(filter: (item: T) -> Boolea
inline fun <T : Any> Iterator<T>.firstOrNull(predicate: (T) -> Boolean): T? {
while (hasNext()) {
val data = next()
- if (predicate(data)) return data
+ if (predicate(data)) {
+ return data
+ }
}
return null
}
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/logging/KauLogger.kt b/core/src/main/kotlin/ca/allanwang/kau/logging/KauLogger.kt
index 4562b00..9410c4c 100644
--- a/core/src/main/kotlin/ca/allanwang/kau/logging/KauLogger.kt
+++ b/core/src/main/kotlin/ca/allanwang/kau/logging/KauLogger.kt
@@ -64,16 +64,18 @@ open class KauLogger(
}
inline fun log(priority: Int, message: () -> Any?, t: Throwable? = null) {
- if (shouldLog(priority))
+ if (shouldLog(priority)) {
logImpl(priority, message()?.toString(), t)
+ }
}
open fun logImpl(priority: Int, message: String?, t: Throwable?) {
val msg = message ?: "null"
- if (t != null)
+ if (t != null) {
Log.e(tag, msg, t)
- else
+ } else {
Log.println(priority, tag, msg)
+ }
}
/**
@@ -113,8 +115,11 @@ class KauLoggerExtension(val tag: String, val logger: KauLogger) {
inline fun log(priority: Int, message: () -> Any?, t: Throwable? = null) =
logger.log(priority, {
val msg = message()?.toString()
- if (msg == null) null
- else "$tag: $msg"
+ if (msg == null) {
+ null
+ } else {
+ "$tag: $msg"
+ }
}, t)
inline fun checkThread(id: Int) {
diff --git a/core/src/main/kotlin/ca/allanwang/kau/permissions/PermissionManager.kt b/core/src/main/kotlin/ca/allanwang/kau/permissions/PermissionManager.kt
index 96adfa3..b549523 100644
--- a/core/src/main/kotlin/ca/allanwang/kau/permissions/PermissionManager.kt
+++ b/core/src/main/kotlin/ca/allanwang/kau/permissions/PermissionManager.kt
@@ -82,7 +82,7 @@ internal object PermissionManager {
if (!manifestPermission(context).contains(it)) {
KL.e { "Requested permission $it is not stated in the manifest" }
context.toast("$it is not in the manifest")
- //we'll let the request pass through so it can be denied and so the callback can be triggered
+ // we'll let the request pass through so it can be denied and so the callback can be triggered
}
}
val activity = (context as? Activity)
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/swipe/RelativeSlider.kt b/core/src/main/kotlin/ca/allanwang/kau/swipe/RelativeSlider.kt
index 0b1dd88..9f23b63 100644
--- a/core/src/main/kotlin/ca/allanwang/kau/swipe/RelativeSlider.kt
+++ b/core/src/main/kotlin/ca/allanwang/kau/swipe/RelativeSlider.kt
@@ -37,7 +37,7 @@ internal class RelativeSlider(var curPage: SwipeBackPage) : SwipeListener {
* Set offset of previous page based on the edge flag and percentage scrolled
*/
override fun onScroll(percent: Float, px: Int, edgeFlag: Int) {
- if (offset == 0f) return //relative slider is not enabled
+ if (offset == 0f) return // relative slider is not enabled
val page = SwipeBackHelper.getPrePage(curPage) ?: return
if (percent == 0f) {
page.swipeBackLayout.x = 0f
diff --git a/core/src/main/kotlin/ca/allanwang/kau/swipe/SwipeBackHelper.kt b/core/src/main/kotlin/ca/allanwang/kau/swipe/SwipeBackHelper.kt
index 90e6e6d..a8c71a4 100644
--- a/core/src/main/kotlin/ca/allanwang/kau/swipe/SwipeBackHelper.kt
+++ b/core/src/main/kotlin/ca/allanwang/kau/swipe/SwipeBackHelper.kt
@@ -62,7 +62,7 @@ internal object SwipeBackHelper {
fun finish(activity: Activity) = this[activity]?.scrollToFinishActivity()
internal fun getPrePage(page: SwipeBackPage): SwipeBackPage? {
- //clean invalid pages
+ // clean invalid pages
pageStack.kauRemoveIf { it.activityRef.get() == null }
return pageStack.getOrNull(pageStack.indexOf(page) - 1)
}
diff --git a/core/src/main/kotlin/ca/allanwang/kau/swipe/SwipeBackLayout.kt b/core/src/main/kotlin/ca/allanwang/kau/swipe/SwipeBackLayout.kt
index c5b64e3..5f462b4 100644
--- a/core/src/main/kotlin/ca/allanwang/kau/swipe/SwipeBackLayout.kt
+++ b/core/src/main/kotlin/ca/allanwang/kau/swipe/SwipeBackLayout.kt
@@ -52,7 +52,9 @@ internal class SwipeBackLayout @JvmOverloads constructor(
*/
override var scrollThreshold = DEFAULT_SCROLL_THRESHOLD
set(value) {
- if (value >= 1.0f || value <= 0f) throw IllegalArgumentException("Threshold value should be between 0.0 and 1.0")
+ if (value >= 1.0f || value <= 0f) {
+ throw IllegalArgumentException("Threshold value should be between 0.0 and 1.0")
+ }
field = value
}
@@ -130,8 +132,9 @@ internal class SwipeBackLayout @JvmOverloads constructor(
* We will verify that only one axis is used at a time
*/
set(value) {
- if (value !in arrayOf(SWIPE_EDGE_TOP, SWIPE_EDGE_BOTTOM, SWIPE_EDGE_LEFT, SWIPE_EDGE_RIGHT))
+ if (value !in arrayOf(SWIPE_EDGE_TOP, SWIPE_EDGE_BOTTOM, SWIPE_EDGE_LEFT, SWIPE_EDGE_RIGHT)) {
throw IllegalArgumentException("Edge flag is not valid; use one of the SWIPE_EDGE_* values")
+ }
field = value
horizontal = edgeFlag == SWIPE_EDGE_LEFT || edgeFlag == SWIPE_EDGE_RIGHT
dragHelper.setEdgeTrackingEnabled(value)
@@ -162,7 +165,9 @@ internal class SwipeBackLayout @JvmOverloads constructor(
init {
dragHelper = ViewDragHelper.create(this, ViewDragCallback())
- //allow touch from anywhere on the screen
+ val density = resources.displayMetrics.density
+ val minVel = MIN_FLING_VELOCITY * density
+ // allow touch from anywhere on the screen
edgeSize = Math.max(resources.displayMetrics.widthPixels, resources.displayMetrics.heightPixels)
edgeFlag = edgeFlag
sensitivity = 0.3f
@@ -193,8 +198,9 @@ internal class SwipeBackLayout @JvmOverloads constructor(
val iter = listeners.iterator()
while (iter.hasNext()) {
val l = iter.next().get()
- if (l == null || l == listener)
+ if (l == null || l == listener) {
iter.remove()
+ }
}
}
@@ -206,10 +212,11 @@ internal class SwipeBackLayout @JvmOverloads constructor(
val iter = listeners.iterator()
while (iter.hasNext()) {
val l = iter.next().get()
- if (l == null)
+ if (l == null) {
iter.remove()
- else if (l == listener)
+ } else if (l == listener) {
return true
+ }
}
return false
}
@@ -240,6 +247,7 @@ internal class SwipeBackLayout @JvmOverloads constructor(
dragHelper.shouldInterceptTouchEvent(event)
} catch (e: Exception) {
false
+
}
}
@@ -360,7 +368,7 @@ internal class SwipeBackLayout @JvmOverloads constructor(
super.onViewPositionChanged(changedView, left, top, dx, dy)
val contentView = contentViewRef.get()
?: return KL.e { "KauSwipe cannot change view position as contentView is null; is onPostCreate called?" }
- //make sure that we are using the proper axis
+ // make sure that we are using the proper axis
scrollPercent = Math.abs(
if (horizontal) left.toFloat() / contentView.width
else (top.toFloat() / contentView.height)
@@ -388,7 +396,7 @@ internal class SwipeBackLayout @JvmOverloads constructor(
override fun onViewReleased(releasedChild: View, xvel: Float, yvel: Float) {
var result = Pair(0, 0)
if (scrollPercent <= scrollThreshold) {
- //threshold not met; check velocities
+ // threshold not met; check velocities
if ((edgeFlag == SWIPE_EDGE_LEFT && xvel > MIN_FLING_VELOCITY) ||
(edgeFlag == SWIPE_EDGE_RIGHT && xvel < -MIN_FLING_VELOCITY) ||
(edgeFlag == SWIPE_EDGE_TOP && yvel > MIN_FLING_VELOCITY) ||
@@ -396,7 +404,7 @@ internal class SwipeBackLayout @JvmOverloads constructor(
)
result = exitCaptureOffsets(edgeFlag, releasedChild)
} else {
- //threshold met; fling to designated side
+ // threshold met; fling to designated side
result = exitCaptureOffsets(edgeFlag, releasedChild)
}
dragHelper.settleCapturedViewAt(result.first, result.second)
diff --git a/core/src/main/kotlin/ca/allanwang/kau/ui/ProgressAnimator.kt b/core/src/main/kotlin/ca/allanwang/kau/ui/ProgressAnimator.kt
index a46e6c5..bb4cd88 100644
--- a/core/src/main/kotlin/ca/allanwang/kau/ui/ProgressAnimator.kt
+++ b/core/src/main/kotlin/ca/allanwang/kau/ui/ProgressAnimator.kt
@@ -94,7 +94,9 @@ class ProgressAnimator private constructor() : ValueAnimator() {
* @return [condition]
*/
private fun ProgressAction.runIf(condition: Boolean, progress: Float): Boolean {
- if (condition) this(progress)
+ if (condition) {
+ this(progress)
+ }
return condition
}
@@ -170,7 +172,9 @@ class ProgressAnimator private constructor() : ValueAnimator() {
fun withDisposableEndAction(action: ProgressDisposableRunnable) = endActions.add(action)
fun reset() {
- if (isRunning) cancel()
+ if (isRunning) {
+ cancel()
+ }
animators.clear()
startActions.clear()
cancelActions.clear()
diff --git a/core/src/main/kotlin/ca/allanwang/kau/ui/views/CollapsibleViewDelegate.kt b/core/src/main/kotlin/ca/allanwang/kau/ui/views/CollapsibleViewDelegate.kt
index b2a0d27..2a057cb 100644
--- a/core/src/main/kotlin/ca/allanwang/kau/ui/views/CollapsibleViewDelegate.kt
+++ b/core/src/main/kotlin/ca/allanwang/kau/ui/views/CollapsibleViewDelegate.kt
@@ -62,15 +62,22 @@ class CollapsibleViewDelegate : CollapsibleView {
override var expansion = 0f
set(value) {
- if (value == field) return
+ if (value == field) {
+ return
+ }
var v = value
- if (v > 1) v = 1f
- else if (v < 0) v = 0f
+ if (v > 1) {
+ v = 1f
+ } else if (v < 0) {
+ v = 0f
+ }
stateHolder =
- if (v == 0f) KAU_COLLAPSED
- else if (v == 1f) KAU_EXPANDED
- else if (v - field < 0) KAU_COLLAPSING
- else KAU_EXPANDING
+ when {
+ v == 0f -> KAU_COLLAPSED
+ v == 1f -> KAU_EXPANDED
+ v - field < 0 -> KAU_COLLAPSING
+ else -> KAU_EXPANDING
+ }
field = v
view?.goneIf(state == KAU_COLLAPSED)
view?.requestLayout()
@@ -89,8 +96,11 @@ class CollapsibleViewDelegate : CollapsibleView {
override fun resetCollapsibleAnimation() {
animator?.cancel()
animator = null
- if (stateHolder == KAU_COLLAPSING) stateHolder = KAU_COLLAPSED
- else if (stateHolder == KAU_EXPANDING) stateHolder = KAU_EXPANDED
+ if (stateHolder == KAU_COLLAPSING) {
+ stateHolder = KAU_COLLAPSED
+ } else if (stateHolder == KAU_EXPANDING) {
+ stateHolder = KAU_EXPANDED
+ }
}
override fun getCollapsibleDimension(): Pair<Int, Int> {
@@ -116,8 +126,14 @@ class CollapsibleViewDelegate : CollapsibleView {
override fun collapse(animate: Boolean) = setExpanded(false, animate)
override fun setExpanded(expand: Boolean) = setExpanded(expand, true)
override fun setExpanded(expand: Boolean, animate: Boolean) {
- if (expand == expanded) return //state already matches
+ if (expand == expanded) {
+ return // state already matches
+ }
val target = if (expand) 1f else 0f
- if (animate) animateSize(target) else expansion = target
+ if (animate) {
+ animateSize(target)
+ } else {
+ expansion = target
+ }
}
}
diff --git a/core/src/main/kotlin/ca/allanwang/kau/ui/views/MeasureSpecDelegate.kt b/core/src/main/kotlin/ca/allanwang/kau/ui/views/MeasureSpecDelegate.kt
index 6481306..728ba7b 100644
--- a/core/src/main/kotlin/ca/allanwang/kau/ui/views/MeasureSpecDelegate.kt
+++ b/core/src/main/kotlin/ca/allanwang/kau/ui/views/MeasureSpecDelegate.kt
@@ -95,7 +95,9 @@ class MeasureSpecDelegate : MeasureSpecContract {
private val parentFrame = Rect()
override fun initAttrs(context: Context, attrs: AttributeSet?) {
- if (attrs == null) return
+ if (attrs == null) {
+ return
+ }
val styledAttrs = context.obtainStyledAttributes(attrs, R.styleable.MeasureSpecDelegate)
relativeWidth = styledAttrs.getFloat(R.styleable.MeasureSpecDelegate_relativeWidth, relativeWidth)
relativeHeight = styledAttrs.getFloat(R.styleable.MeasureSpecDelegate_relativeHeight, relativeHeight)
@@ -113,21 +115,25 @@ class MeasureSpecDelegate : MeasureSpecContract {
view.parentViewGroup.getWindowVisibleDisplayFrame(parentFrame)
var width = View.MeasureSpec.getSize(widthMeasureSpec).toFloat()
var height = View.MeasureSpec.getSize(heightMeasureSpec).toFloat()
- //first cycle - relative to parent
- if (relativeHeightToParent > 0)
+ // first cycle - relative to parent
+ if (relativeHeightToParent > 0) {
height = relativeHeightToParent * parentFrame.height()
- if (relativeWidthToParent > 0)
+ }
+ if (relativeWidthToParent > 0) {
width = relativeWidthToParent * parentFrame.width()
- //second cycle - relative to each other
- if (relativeHeight > 0)
+ }
+ // second cycle - relative to each other
+ if (relativeHeight > 0) {
height = relativeHeight * width
- else if (relativeWidth > 0)
+ } else if (relativeWidth > 0) {
width = relativeWidth * height
- //third cycle - relative to each other
- if (postRelativeHeight > 0)
+ }
+ // third cycle - relative to each other
+ if (postRelativeHeight > 0) {
height = postRelativeHeight * width
- else if (postRelativeWidth > 0)
+ } else if (postRelativeWidth > 0) {
width = postRelativeWidth * height
+ }
return Pair(width.measureSpec, height.measureSpec)
}
diff --git a/core/src/main/kotlin/ca/allanwang/kau/ui/views/RippleCanvas.kt b/core/src/main/kotlin/ca/allanwang/kau/ui/views/RippleCanvas.kt
index 176b9ea..a972447 100644
--- a/core/src/main/kotlin/ca/allanwang/kau/ui/views/RippleCanvas.kt
+++ b/core/src/main/kotlin/ca/allanwang/kau/ui/views/RippleCanvas.kt
@@ -102,11 +102,12 @@ class RippleCanvas @JvmOverloads constructor(
ripple.radius = animation.animatedValue as Float
invalidate()
}
- if (callback != null)
+ if (callback != null) {
animator.addListener(object : AnimatorListenerAdapter() {
override fun onAnimationCancel(animation: Animator?) = callback()
override fun onAnimationEnd(animation: Animator?) = callback()
})
+ }
animator.start()
}
diff --git a/core/src/main/kotlin/ca/allanwang/kau/utils/ActivityUtils.kt b/core/src/main/kotlin/ca/allanwang/kau/utils/ActivityUtils.kt
index 21141f1..279bcd3 100644
--- a/core/src/main/kotlin/ca/allanwang/kau/utils/ActivityUtils.kt
+++ b/core/src/main/kotlin/ca/allanwang/kau/utils/ActivityUtils.kt
@@ -85,7 +85,7 @@ inline fun Activity.restart(intentBuilder: Intent.() -> Unit = {}) {
i.putExtras(oldExtras)
i.intentBuilder()
startActivity(i)
- overridePendingTransition(R.anim.kau_fade_in, R.anim.kau_fade_out) //No transitions
+ overridePendingTransition(R.anim.kau_fade_in, R.anim.kau_fade_out) // No transitions
finish()
overridePendingTransition(R.anim.kau_fade_in, R.anim.kau_fade_out)
}
@@ -125,7 +125,9 @@ inline var Activity.statusBarColor: Int
get() = if (buildIsLollipopAndUp) window.statusBarColor else Color.BLACK
@SuppressLint("NewApi")
set(value) {
- if (buildIsLollipopAndUp) window.statusBarColor = value
+ if (buildIsLollipopAndUp) {
+ window.statusBarColor = value
+ }
}
inline var Activity.statusBarLight: Boolean
diff --git a/core/src/main/kotlin/ca/allanwang/kau/utils/ColorUtils.kt b/core/src/main/kotlin/ca/allanwang/kau/utils/ColorUtils.kt
index 3de0297..ab7b341 100644
--- a/core/src/main/kotlin/ca/allanwang/kau/utils/ColorUtils.kt
+++ b/core/src/main/kotlin/ca/allanwang/kau/utils/ColorUtils.kt
@@ -157,7 +157,7 @@ fun String.toColor(): Int {
return Color.parseColor(toParse)
}
-//Get ColorStateList
+// Get ColorStateList
fun Context.colorStateList(@ColorInt color: Int): ColorStateList {
val disabledColor = color.adjustAlpha(0.3f)
return ColorStateList(
diff --git a/core/src/main/kotlin/ca/allanwang/kau/utils/ContextUtils.kt b/core/src/main/kotlin/ca/allanwang/kau/utils/ContextUtils.kt
index d002fb8..cf68066 100644
--- a/core/src/main/kotlin/ca/allanwang/kau/utils/ContextUtils.kt
+++ b/core/src/main/kotlin/ca/allanwang/kau/utils/ContextUtils.kt
@@ -80,22 +80,27 @@ inline fun <T : Activity> Context.startActivity(
intentBuilder: Intent.() -> Unit = {}
) {
val intent = Intent(this, clazz)
- if (clearStack) intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK)
+ if (clearStack) {
+ intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK)
+ }
intent.intentBuilder()
val bundle = Bundle()
bundle.bundleBuilder()
- startActivity(intent, if (bundle.isEmpty) null else bundle)
- if (clearStack && this is Activity) finish()
+ startActivity(intent, bundle.takeIf { !it.isEmpty })
+ if (clearStack && this is Activity) {
+ finish()
+ }
}
fun Context.startPlayStoreLink(@StringRes packageIdRes: Int) = startPlayStoreLink(string(packageIdRes))
fun Context.startPlayStoreLink(packageId: String) {
val intent = Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=$packageId"))
- if (intent.resolveActivity(packageManager) != null)
+ if (intent.resolveActivity(packageManager) != null) {
startActivity(intent)
- else
+ } else {
toast("Cannot resolve play store", log = true)
+ }
}
/**
@@ -105,15 +110,16 @@ fun Context.startPlayStoreLink(packageId: String) {
fun Context.startLink(vararg url: String?) {
val link = url.firstOrNull { !it.isNullOrBlank() } ?: return
val browserIntent = Intent(Intent.ACTION_VIEW, Uri.parse(link))
- if (browserIntent.resolveActivity(packageManager) != null)
+ if (browserIntent.resolveActivity(packageManager) != null) {
startActivity(browserIntent)
- else
+ } else {
toast("Cannot resolve browser", log = true)
+ }
}
fun Context.startLink(@StringRes url: Int) = startLink(string(url))
-//Toast helpers
+// Toast helpers
inline fun View.toast(@StringRes id: Int, duration: Int = Toast.LENGTH_LONG, log: Boolean = false) =
context.toast(id, duration, log)
@@ -130,7 +136,7 @@ inline fun Context.toast(text: String, duration: Int = Toast.LENGTH_LONG, log: B
const val INVALID_ID = 0
-//Resource retrievers
+// Resource retrievers
inline fun Context.string(@StringRes id: Int): String = getString(id)
inline fun Context.string(@StringRes id: Int, fallback: String?): String? =
@@ -161,7 +167,7 @@ inline fun Context.animation(@AnimRes id: Int) = AnimationUtils.loadAnimation(th
inline fun Context.plural(@PluralsRes id: Int, quantity: Number) =
resources.getQuantityString(id, quantity.toInt(), quantity.toInt())
-//Attr retrievers
+// Attr retrievers
fun Context.resolveColor(@AttrRes attr: Int, @ColorInt fallback: Int = 0): Int {
val a = theme.obtainStyledAttributes(intArrayOf(attr))
try {
@@ -240,19 +246,22 @@ fun Context.hasPermission(permissions: String) = !buildIsMarshmallowAndUp || Con
fun Context.copyToClipboard(text: String?, label: String = "Copied Text", showToast: Boolean = true) {
val clipboard = getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
clipboard.setPrimaryClip(ClipData.newPlainText(label, text ?: ""))
- if (showToast) toast(R.string.kau_text_copied)
+ if (showToast) {
+ toast(R.string.kau_text_copied)
+ }
}
fun Context.shareText(text: String?) {
- if (text == null) return toast("Share text is null")
+ text ?: return toast("Share text is null")
val intent = Intent(Intent.ACTION_SEND)
intent.type = "text/plain"
intent.putExtra(Intent.EXTRA_TEXT, text)
val chooserIntent = Intent.createChooser(intent, string(R.string.kau_share))
- if (chooserIntent.resolveActivity(packageManager) != null)
+ if (chooserIntent.resolveActivity(packageManager) != null) {
startActivity(chooserIntent)
- else
+ } else {
toast("Cannot resolve activity to share text", log = true)
+ }
}
/**
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..fac9421 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) }
@@ -246,7 +246,7 @@ private fun <T, V : View> requiredResettable(ids: IntArray, finder: T.(Int) -> V
private fun <T, V : View> optionalResettable(ids: IntArray, finder: T.(Int) -> View?) =
LazyResettable { t: T, _ -> ids.map { t.finder(it) as V? }.filterNotNull() }
-//Like Kotterknife's lazy delegate but is resettable
+// Like Kotterknife's lazy delegate but is resettable
private class LazyResettable<in T, out V>(initializer: (T, KProperty<*>) -> V) : Lazy<T, V>(initializer) {
override fun getValue(thisRef: T, property: KProperty<*>): V {
KotterknifeRegistry.register(thisRef!!, this)
diff --git a/core/src/main/kotlin/ca/allanwang/kau/utils/PackageUtils.kt b/core/src/main/kotlin/ca/allanwang/kau/utils/PackageUtils.kt
index 4055847..0bd534e 100644
--- a/core/src/main/kotlin/ca/allanwang/kau/utils/PackageUtils.kt
+++ b/core/src/main/kotlin/ca/allanwang/kau/utils/PackageUtils.kt
@@ -54,13 +54,13 @@ fun Context.isAppEnabled(packageName: String): Boolean {
@KauUtils
fun Context.showAppInfo(packageName: String) {
try {
- //Open the specific App Info page:
+ // Open the specific App Info page:
val intent = Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS)
intent.data = Uri.parse("package:$packageName")
startActivity(intent)
} catch (e: ActivityNotFoundException) {
e.printStackTrace()
- //Open the generic Apps page:
+ // Open the generic Apps page:
val intent = Intent(Settings.ACTION_MANAGE_APPLICATIONS_SETTINGS)
startActivity(intent)
}
diff --git a/core/src/main/kotlin/ca/allanwang/kau/utils/ViewUtils.kt b/core/src/main/kotlin/ca/allanwang/kau/utils/ViewUtils.kt
index 186d125..e4ec19c 100644
--- a/core/src/main/kotlin/ca/allanwang/kau/utils/ViewUtils.kt
+++ b/core/src/main/kotlin/ca/allanwang/kau/utils/ViewUtils.kt
@@ -105,7 +105,7 @@ fun ImageView.setIcon(
@ColorInt color: Int = Color.WHITE,
builder: IconicsDrawable.() -> Unit = {}
) {
- if (icon == null) return
+ icon ?: return
setImageDrawable(icon.toDrawable(context, sizeDp = sizeDp, color = color, builder = builder))
}
@@ -274,7 +274,9 @@ fun Context.fullLinearRecycler(rvAdapter: RecyclerView.Adapter<*>? = null, confi
layoutManager = LinearLayoutManager(this@fullLinearRecycler)
layoutParams =
RecyclerView.LayoutParams(RecyclerView.LayoutParams.MATCH_PARENT, RecyclerView.LayoutParams.MATCH_PARENT)
- if (rvAdapter != null) adapter = rvAdapter
+ if (rvAdapter != null) {
+ adapter = rvAdapter
+ }
configs()
}
@@ -296,8 +298,9 @@ inline fun <T : ImageView> T.fadeScaleTransition(
minScale: Float = 0.7f,
crossinline action: T.() -> Unit
) {
- if (!isVisible) action()
- else {
+ if (!isVisible) {
+ action()
+ } else {
var transitioned = false
ValueAnimator.ofFloat(1.0f, 0.0f, 1.0f).apply {
this.duration = duration
@@ -323,12 +326,17 @@ fun FloatingActionButton.hideOnDownwardsScroll(recycler: RecyclerView) {
recycler.addOnScrollListener(object : RecyclerView.OnScrollListener() {
override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) {
- if (newState == RecyclerView.SCROLL_STATE_IDLE && !isShown) show()
+ if (newState == RecyclerView.SCROLL_STATE_IDLE && !isShown) {
+ show()
+ }
}
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
- if (dy > 0 && isShown) hide()
- else if (dy < 0 && isHidden) show()
+ if (dy > 0 && isShown) {
+ hide()
+ } else if (dy < 0 && isHidden) {
+ show()
+ }
}
})
}
diff --git a/core/src/main/kotlin/ca/allanwang/kau/xml/Changelog.kt b/core/src/main/kotlin/ca/allanwang/kau/xml/Changelog.kt
index 9adcbf4..0872b68 100644
--- a/core/src/main/kotlin/ca/allanwang/kau/xml/Changelog.kt
+++ b/core/src/main/kotlin/ca/allanwang/kau/xml/Changelog.kt
@@ -84,8 +84,9 @@ internal fun parse(context: Context, @XmlRes xmlRes: Int): List<Pair<String, Cha
context.resources.getXml(xmlRes).use { parser: XmlResourceParser ->
var eventType = parser.eventType
while (eventType != XmlPullParser.END_DOCUMENT) {
- if (eventType == XmlPullParser.START_TAG)
+ if (eventType == XmlPullParser.START_TAG) {
ChangelogType.values.any { it.add(parser, items) }
+ }
eventType = parser.next()
}
}
@@ -104,9 +105,12 @@ internal enum class ChangelogType(val tag: String, val attr: String, @LayoutRes
* Returns true if tag matches; false otherwise
*/
fun add(parser: XmlResourceParser, list: MutableList<Pair<String, ChangelogType>>): Boolean {
- if (parser.name != tag) return false
- if (parser.getAttributeValue(null, attr).isNotBlank())
+ if (parser.name != tag) {
+ return false
+ }
+ if (parser.getAttributeValue(null, attr).isNotBlank()) {
list.add(Pair(parser.getAttributeValue(null, attr), this))
+ }
return true
}
}
diff --git a/core/src/main/kotlin/ca/allanwang/kau/xml/FAQ.kt b/core/src/main/kotlin/ca/allanwang/kau/xml/FAQ.kt
index 73d7d6c..afde735 100644
--- a/core/src/main/kotlin/ca/allanwang/kau/xml/FAQ.kt
+++ b/core/src/main/kotlin/ca/allanwang/kau/xml/FAQ.kt
@@ -43,7 +43,7 @@ fun Context.kauParseFaq(
resources.getXml(xmlRes).use { parser: XmlResourceParser ->
var eventType = parser.eventType
var question: Spanned? = null
- var flag = -1 //-1, 0, 1 -> invalid, question, answer
+ var flag = -1 // -1, 0, 1 -> invalid, question, answer
while (eventType != XmlPullParser.END_DOCUMENT) {
if (eventType == XmlPullParser.START_TAG) {
flag = when (parser.name) {
diff --git a/core/src/main/res-public/values/public.xml b/core/src/main/res-public/values/public.xml
index 9761199..211c539 100644
--- a/core/src/main/res-public/values/public.xml
+++ b/core/src/main/res-public/values/public.xml
@@ -1,4 +1,4 @@
-<resources xmlns:tools='http://schemas.android.com/tools' tools:ignore='ResourceName'>
+<resources xmlns:tools='http://schemas.android.com/tools' tools:ignore='ResourceName'>
<!-- AUTO-GENERATED FILE. DO NOT MODIFY. public.xml is generated by the generatepublicxml gradle task -->
<public name='kau_slide_in_top' type='anim' />
<public name='kau_slide_in_left' type='anim' />
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 c406901..d43901f 100644
--- a/core/src/test/kotlin/ca/allanwang/kau/kotlin/DebounceTest.kt
+++ b/core/src/test/kotlin/ca/allanwang/kau/kotlin/DebounceTest.kt
@@ -50,16 +50,16 @@ class DebounceTest {
fun multipleDebounces() {
var i = 0
val debounce = debounce<Int>(20) { i += it }
- debounce(1) //ignore -> i = 0
+ debounce(1) // ignore -> i = 0
Thread.sleep(10)
assertEquals(0, i)
- debounce(2) //accept -> i = 2
+ debounce(2) // accept -> i = 2
Thread.sleep(30)
assertEquals(2, i)
- debounce(4) //ignore -> i = 2
+ debounce(4) // ignore -> i = 2
Thread.sleep(10)
assertEquals(2, i)
- debounce(8) //accept -> i = 10
+ debounce(8) // accept -> i = 10
Thread.sleep(30)
assertEquals(10, i)
}
diff --git a/core/src/test/kotlin/ca/allanwang/kau/kotlin/StreamsTest.kt b/core/src/test/kotlin/ca/allanwang/kau/kotlin/StreamsTest.kt
index 4dc4a34..e3d4e5b 100644
--- a/core/src/test/kotlin/ca/allanwang/kau/kotlin/StreamsTest.kt
+++ b/core/src/test/kotlin/ca/allanwang/kau/kotlin/StreamsTest.kt
@@ -47,10 +47,10 @@ class StreamsTest {
items.add(3, thePotato)
assertEquals(result.size + 1, items.size, "Invalid list addition")
assertEquals(2, items.filter { it.id == 9 }.size, "Invalid number of potatoes with id 9")
- items.kauRemoveIf { it === thePotato } //removal by reference
+ items.kauRemoveIf { it === thePotato } // removal by reference
assertEquals(result.size, items.size, "Invalid list size after removal")
assertEquals(result, items)
- items.kauRemoveIf { it == thePotato } //removal by equality
+ items.kauRemoveIf { it == thePotato } // removal by equality
assertEquals(result.size - 1, items.size, "Invalid list removal based on equality")
}
}
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-databinding/.gitignore b/fastadapter-databinding/.gitignore
new file mode 100644
index 0000000..796b96d
--- /dev/null
+++ b/fastadapter-databinding/.gitignore
@@ -0,0 +1 @@
+/build
diff --git a/fastadapter-databinding/build.gradle b/fastadapter-databinding/build.gradle
new file mode 100644
index 0000000..aefb22e
--- /dev/null
+++ b/fastadapter-databinding/build.gradle
@@ -0,0 +1,21 @@
+import kau.Dependencies
+import kau.Versions
+
+ext.kauSubModuleMinSdk = Versions.coreMinSdk
+
+apply from: '../android-lib.gradle'
+
+android {
+ dataBinding {
+ enabled = true
+ }
+}
+
+dependencies {
+ implementation project(':core')
+
+ api Dependencies.fastAdapter
+ api Dependencies.fastAdapter("utils")
+}
+
+apply from: '../artifacts.gradle'
diff --git a/fastadapter-databinding/consumer-rules.pro b/fastadapter-databinding/consumer-rules.pro
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/fastadapter-databinding/consumer-rules.pro
diff --git a/fastadapter-databinding/proguard-rules.pro b/fastadapter-databinding/proguard-rules.pro
new file mode 100644
index 0000000..f1b4245
--- /dev/null
+++ b/fastadapter-databinding/proguard-rules.pro
@@ -0,0 +1,21 @@
+# Add project specific ProGuard rules here.
+# You can control the set of applied configuration files using the
+# proguardFiles setting in build.gradle.
+#
+# For more details, see
+# http://developer.android.com/guide/developing/tools/proguard.html
+
+# If your project uses WebView with JS, uncomment the following
+# and specify the fully qualified class name to the JavaScript interface
+# class:
+#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
+# public *;
+#}
+
+# Uncomment this to preserve the line number information for
+# debugging stack traces.
+#-keepattributes SourceFile,LineNumberTable
+
+# If you keep the line number information, uncomment this to
+# hide the original source file name.
+#-renamesourcefileattribute SourceFile
diff --git a/fastadapter-databinding/src/main/AndroidManifest.xml b/fastadapter-databinding/src/main/AndroidManifest.xml
new file mode 100644
index 0000000..acd1012
--- /dev/null
+++ b/fastadapter-databinding/src/main/AndroidManifest.xml
@@ -0,0 +1 @@
+<manifest package="ca.allanwang.kau.fastadapter.databinding" />
diff --git a/fastadapter-databinding/src/main/kotlin/ca/allanwang/fastadapter/databinding/BindingItem.kt b/fastadapter-databinding/src/main/kotlin/ca/allanwang/fastadapter/databinding/BindingItem.kt
new file mode 100644
index 0000000..b2b0f26
--- /dev/null
+++ b/fastadapter-databinding/src/main/kotlin/ca/allanwang/fastadapter/databinding/BindingItem.kt
@@ -0,0 +1,123 @@
+/*
+ * 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.fastadapter.databinding
+
+import android.content.Context
+import android.view.LayoutInflater
+import android.view.View
+import android.view.ViewGroup
+import androidx.databinding.DataBindingUtil
+import androidx.databinding.ViewDataBinding
+import androidx.recyclerview.widget.RecyclerView
+import ca.allanwang.kau.logging.KL
+import com.mikepenz.fastadapter.FastAdapter
+import com.mikepenz.fastadapter.GenericItem
+import com.mikepenz.fastadapter.items.AbstractItem
+import com.mikepenz.fastadapter.listeners.ClickEventHook
+
+interface VhModel {
+ fun vh(): GenericItem
+}
+
+abstract class BindingItem<Binding : ViewDataBinding>(open val data: Any?) :
+ AbstractItem<BindingItem.ViewHolder>(),
+ BindingLayout<Binding> {
+
+ override val type: Int
+ get() = layoutRes
+
+ override fun createView(ctx: Context, parent: ViewGroup?): View {
+ val binding: ViewDataBinding = DataBindingUtil.inflate(
+ LayoutInflater.from(ctx),
+ layoutRes, parent,
+ false
+ )
+ return binding.root
+ }
+
+ fun getBinding(holder: ViewHolder): Binding? =
+ DataBindingUtil.getBinding<Binding>(holder.itemView)
+
+ final override fun bindView(holder: ViewHolder, payloads: MutableList<Any>) {
+ super.bindView(holder, payloads)
+ val binding = getBinding(holder) ?: return
+ binding.bindView(holder, payloads)
+ binding.executePendingBindings()
+ }
+
+ abstract fun Binding.bindView(holder: ViewHolder, payloads: MutableList<Any>)
+
+ final override fun unbindView(holder: ViewHolder) {
+ super.unbindView(holder)
+ val binding = DataBindingUtil.getBinding<Binding>(holder.itemView) ?: return
+ binding.unbindView(holder)
+ binding.unbind()
+ }
+
+ open fun Binding.unbindView(holder: ViewHolder) {}
+
+ final override fun getViewHolder(v: View): ViewHolder = ViewHolder(v, layoutRes)
+
+ override fun failedToRecycle(holder: ViewHolder): Boolean {
+ KL.e { "Failed to recycle" }
+ return super.failedToRecycle(holder)
+ }
+
+ override fun equals(other: Any?): Boolean {
+ if (this === other) return true
+ if (other !is BindingItem<*>) return false
+ return identifier == other.identifier && data == other.data
+ }
+
+ override fun hashCode(): Int = data.hashCode()
+
+ class ViewHolder(itemView: View, internal val layoutRes: Int) :
+ RecyclerView.ViewHolder(itemView)
+}
+
+interface BindingLayout<Binding : ViewDataBinding> {
+ val layoutRes: Int
+}
+
+abstract class BindingClickEventHook<Binding : ViewDataBinding, Item : BindingItem<Binding>>(val identifier: BindingLayout<Binding>) :
+ ClickEventHook<Item>() {
+
+ private fun RecyclerView.ViewHolder.binding(): Binding? {
+ val holder = this as? BindingItem.ViewHolder ?: return null
+ if (holder.layoutRes != identifier.layoutRes) {
+ return null
+ }
+ return DataBindingUtil.getBinding(itemView)
+ }
+
+ final override fun onBind(viewHolder: RecyclerView.ViewHolder): View? =
+ viewHolder.binding()?.onBind(viewHolder) ?: super.onBind(viewHolder)
+
+ open fun Binding.onBind(viewHolder: RecyclerView.ViewHolder): View? = super.onBind(viewHolder)
+
+ final override fun onBindMany(viewHolder: RecyclerView.ViewHolder): List<View>? =
+ viewHolder.binding()?.onBindMany(viewHolder) ?: super.onBindMany(viewHolder)
+
+ open fun Binding.onBindMany(viewHolder: RecyclerView.ViewHolder): List<View>? =
+ super.onBindMany(viewHolder)
+
+ final override fun onClick(v: View, position: Int, fastAdapter: FastAdapter<Item>, item: Item) {
+ val binding: Binding = DataBindingUtil.findBinding(v) ?: return
+ binding.onClick(v, position, fastAdapter, item)
+ }
+
+ abstract fun Binding.onClick(v: View, position: Int, fastAdapter: FastAdapter<Item>, item: Item)
+}
diff --git a/fastadapter/build.gradle b/fastadapter/build.gradle
index 9fd848e..8abe566 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,9 @@ dependencies {
implementation project(':core')
api project(':adapter')
- api kau.Dependencies.fastAdapter
- api kau.Dependencies.fastAdapterCommons
+ api Dependencies.fastAdapter
+ api Dependencies.fastAdapter("utils")
+ implementation Dependencies.fastAdapter("diff")
}
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..32806f2 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) {
@@ -68,56 +79,18 @@ class FastItemThemedAdapter<Item : IItem<*, *>>(
}
fun themeChanged() {
- if (adapterItemCount == 0) return
+ if (adapterItemCount == 0) {
+ return
+ }
injectTheme(adapterItems)
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
@@ -188,7 +161,7 @@ class ThemableIItemDelegate : ThemableIItem, ThemableIItemColors by ThemableIIte
override fun bindBackgroundRipple(vararg views: View?) {
val background = backgroundColor ?: return
val foreground = accentColor ?: textColor ?: backgroundColor
- ?: return //default to normal background
+ ?: return // default to normal background
val ripple = createSimpleRippleDrawable(foreground, background)
views.forEach { it?.background = ripple }
}
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/adapters/SingleFastAdapter.kt b/fastadapter/src/main/kotlin/ca/allanwang/kau/adapters/SingleFastAdapter.kt
new file mode 100644
index 0000000..e183bde
--- /dev/null
+++ b/fastadapter/src/main/kotlin/ca/allanwang/kau/adapters/SingleFastAdapter.kt
@@ -0,0 +1,57 @@
+/*
+ * 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.adapters
+
+import com.mikepenz.fastadapter.FastAdapter
+import com.mikepenz.fastadapter.GenericItem
+import com.mikepenz.fastadapter.IAdapter
+import com.mikepenz.fastadapter.IItemAdapter
+import com.mikepenz.fastadapter.adapters.ItemAdapter
+import com.mikepenz.fastadapter.diff.FastAdapterDiffUtil
+
+/**
+ * Fast adapter with prewrapped item adapter
+ */
+class SingleFastAdapter private constructor(val adapter: ItemAdapter<GenericItem>) :
+ FastAdapter<GenericItem>(), IItemAdapter<GenericItem, GenericItem> by adapter {
+
+ constructor() : this(ItemAdapter())
+
+ var lastClearTime: Long = -1
+
+ init {
+ super.addAdapter(0, adapter)
+ }
+
+ override fun clear(): SingleFastAdapter {
+ if (itemCount != 0) {
+ adapter.clear()
+ lastClearTime = System.currentTimeMillis()
+ }
+ return this
+ }
+
+ override fun <A : IAdapter<GenericItem>> addAdapter(
+ index: Int,
+ adapter: A
+ ): FastAdapter<GenericItem> {
+ throw IllegalStateException("SingleFastAdapter only allows one adapter.")
+ }
+
+ fun setWithDiff(items: List<GenericItem>, detectMoves: Boolean = true) {
+ FastAdapterDiffUtil.set(adapter, items, detectMoves)
+ }
+}
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/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
index 9fccf04..ce43d4f 100644
--- a/gradle/wrapper/gradle-wrapper.properties
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.1-all.zip
diff --git a/kpref-activity/build.gradle b/kpref-activity/build.gradle
index 5cce460..7df08d3 100644
--- a/kpref-activity/build.gradle
+++ b/kpref-activity/build.gradle
@@ -1,3 +1,5 @@
+import kau.Dependencies
+
ext.kauSubModuleMinSdk = kau.Versions.coreMinSdk
ext.kauSubModuleResourcePrefix = "kau_pref_"
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..800a355 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
@@ -73,7 +74,7 @@ abstract class KPrefActivity : KauBaseActivity(), KPrefActivityContract {
@SuppressLint("NewApi")
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
- //setup layout
+ // setup layout
setContentView(R.layout.kau_pref_activity)
setSupportActionBar(toolbar)
supportActionBar?.apply {
@@ -82,18 +83,24 @@ 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))
- //setup prefs
+ // setup prefs
val core = CoreAttributeBuilder()
val builder = kPrefCoreAttributes()
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..a867d06 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,13 +34,14 @@ 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)
checkbox.isChecked = pref
- checkbox.jumpDrawablesToCurrentState() //Cancel the animation
+ 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..9abdf09 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..e801848 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..ad83d8a 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 {
@@ -92,11 +110,12 @@ abstract class MediaPickerActivityBase(
*/
private fun setToolbarScrollable(scrollable: Boolean) {
val params = kau_toolbar.layoutParams as AppBarLayout.LayoutParams
- if (scrollable)
+ if (scrollable) {
params.scrollFlags = AppBarLayout.LayoutParams.SCROLL_FLAG_ENTER_ALWAYS or
AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL
- else
+ } else {
params.scrollFlags = 0
+ }
}
override fun onLoadFinished(loader: Loader<Cursor>, data: Cursor?) {
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..68d1121 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,13 @@ 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)
@@ -150,11 +156,18 @@ abstract class MediaPickerCore<T : IItem<*, *>>(
}
}
- //Sort by descending date
+ // Sort by descending date
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 +251,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}" }
@@ -246,17 +263,19 @@ abstract class MediaPickerCore<T : IItem<*, *>>(
}.mapNotNull {
DocumentsContract.getDocumentId(it).split(":").getOrNull(1)
}.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 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
+ )
}
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 +291,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 +315,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..4fe941b 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() {
@@ -47,7 +47,7 @@ class MainActivity : KPrefActivity() {
companion object {
- //some of the most common english words for show
+ // some of the most common english words for show
val wordBank: List<String> by lazy {
listOf(
"the", "name", "of", "very", "to", "through",
@@ -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..68dde2a 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>) {
@@ -33,7 +33,7 @@ class PermissionCheckbox(val permission: String) : KauIItem<PermissionCheckbox,
holder.text.text = permission
holder.checkbox.isChecked = holder.itemView.context.hasPermission(permission)
holder.checkbox.isClickable = false
- holder.checkbox.jumpDrawablesToCurrentState() //Cancel the animation
+ holder.checkbox.jumpDrawablesToCurrentState() // Cancel the animation
}
class ViewHolder(v: View) : RecyclerView.ViewHolder(v) {
diff --git a/sample/src/main/res/xml/kau_changelog.xml b/sample/src/main/res/xml/kau_changelog.xml
index f91355b..7baecd8 100644
--- a/sample/src/main/res/xml/kau_changelog.xml
+++ b/sample/src/main/res/xml/kau_changelog.xml
@@ -6,6 +6,10 @@
<item text="" />
-->
+ <version title="v5.2.0" />
+ <item text=":fastadapter: Migrate fastadapter to v4.x.x" />
+ <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" />
@@ -23,13 +27,11 @@
<item text=":core: Remove cursor tinting in EditText as it used reflection" />
<item text=":colorpicker: Strip down to just the interface; unless you require the accent palette, it may be fine to just use MD's color extension" />
<item text=":gradle-plugin: Convert to kotlin, rework dependencies, and remove extension hooks" />
- <item text="" />
<version title="v4.1.0" />
<item text=":core: Deprecate NetworkUtils, as the underlying functions are deprecated" />
<item text=":core: Permission manager no longer synchronized, as all actions should occur in the main thread" />
<item text=":kpref-activity: Getter and setter now have action context, with the option to reload self" />
- <item text="" />
<version title="v4.0.0" />
<item text="Update translations" />
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..78d8782 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
@@ -66,7 +66,9 @@ class SearchItem(
internal fun withHighlights(subText: String?) {
subText ?: return
val index = content.indexOf(subText, ignoreCase = true)
- if (index == -1) return
+ if (index == -1) {
+ return
+ }
styledContent = SpannableStringBuilder(content)
styledContent!!.setSpan(
StyleSpan(Typeface.BOLD),
@@ -81,12 +83,17 @@ class SearchItem(
holder.title.setTextColor(foregroundColor)
holder.desc.setTextColor(foregroundColor.adjustAlpha(0.6f))
- if (image != null) holder.icon.setImageDrawable(image)
- else holder.icon.setIcon(iicon, sizeDp = 18, color = foregroundColor)
+ if (image != null) {
+ holder.icon.setImageDrawable(image)
+ } else {
+ holder.icon.setIcon(iicon, sizeDp = 18, color = foregroundColor)
+ }
holder.container.setRippleBackground(foregroundColor, backgroundColor)
holder.title.text = styledContent ?: content
- if (description?.isNotBlank() == true) holder.desc.visible().text = description
+ if (description?.isNotBlank() == true) {
+ holder.desc.visible().text = description
+ }
}
override fun unbindView(holder: ViewHolder) {
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..c2da5fa 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.*
/**
@@ -233,10 +234,14 @@ class SearchView @JvmOverloads constructor(
}
val icons = mutableListOf(navIcon to kau_search_nav, clearIcon to kau_search_clear)
val extra = extraIcon
- if (extra != null) icons.add(extra.first to kau_search_extra)
+ if (extra != null) {
+ icons.add(extra.first to kau_search_extra)
+ }
icons.forEach { (iicon, view) -> view.goneIf(iicon == null).setSearchIcon(iicon) }
- if (extra != null) kau_search_extra.setOnClickListener(extra.second)
+ if (extra != null) {
+ kau_search_extra.setOnClickListener(extra.second)
+ }
kau_search_divider.invisibleIf(!withDivider)
kau_search_edit_text.hint = context.string(hintTextRes, hintText)
textCallback.terminate()
@@ -255,7 +260,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)
}
@@ -289,15 +298,16 @@ class SearchView @JvmOverloads constructor(
* These are calculated every time the search view is opened,
* and can be overridden with the open listener if necessary
*/
- var menuX: Int = -1 //starting x for circular reveal
- var menuY: Int = -1 //reference for cardview's marginTop
- var menuHalfHeight: Int = -1 //starting y for circular reveal (relative to the cardview)
+ var menuX: Int = -1 // starting x for circular reveal
+ var menuY: Int = -1 // reference for cardview's marginTop
+ var menuHalfHeight: Int = -1 // starting y for circular reveal (relative to the cardview)
init {
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) {
@@ -306,24 +316,36 @@ class SearchView @JvmOverloads constructor(
addOnScrollListener(object : RecyclerView.OnScrollListener() {
override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) {
super.onScrollStateChanged(recyclerView, newState)
- if (newState == RecyclerView.SCROLL_STATE_DRAGGING) hideKeyboard()
+ if (newState == RecyclerView.SCROLL_STATE_DRAGGING) {
+ hideKeyboard()
+ }
}
})
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
}
- withOnLongClickListener { _, _, item, position ->
- if (item.key.isNotBlank()) configs.onItemLongClick(
+ onClickListener = { _, _, item, position ->
+ if (item.key.isNotBlank()) configs.onItemClick(
position,
item.key,
item.content,
this@SearchView
); true
}
+ onLongClickListener = { _, _, item, position ->
+ if (item.key.isNotBlank()) {
+ configs.onItemLongClick(
+ position,
+ item.key,
+ item.content,
+ this@SearchView
+ )
+ }
+ true
+ }
}
kau_search_edit_text.addTextChangedListener(object : TextWatcher {
override fun afterTextChanged(s: Editable?) {}
@@ -333,20 +355,21 @@ class SearchView @JvmOverloads constructor(
override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) {
val text = s.toString().trim()
textCallback.cancel()
- if (text.isNotEmpty())
+ if (text.isNotEmpty()) {
textCallback(text, this@SearchView)
- else if (!configs.textClearedCallback(this@SearchView))
+ } else if (!configs.textClearedCallback(this@SearchView)) {
clearResults()
+ }
}
})
kau_search_edit_text.setOnEditorActionListener { _, actionId, _ ->
if (actionId == EditorInfo.IME_ACTION_SEARCH) {
- if (configs.searchCallback(
- kau_search_edit_text.text?.toString()
- ?: "", this
- )
- ) revealClose()
- else kau_search_edit_text.hideKeyboard()
+ val query = kau_search_edit_text.text?.toString() ?: ""
+ if (configs.searchCallback(query, this)) {
+ revealClose()
+ } else {
+ kau_search_edit_text.hideKeyboard()
+ }
return@setOnEditorActionListener true
}
false
@@ -360,8 +383,8 @@ class SearchView @JvmOverloads constructor(
internal fun cardTransition(builder: TransitionSet.() -> Unit = {}) {
TransitionManager.beginDelayedTransition(kau_search_cardview,
- //we are only using change bounds, as the recyclerview items may be animated as well,
- //which causes a measure IllegalStateException
+ // we are only using change bounds, as the recyclerview items may be animated as well,
+ // which causes a measure IllegalStateException
TransitionSet().addTransition(ChangeBounds()).apply {
duration = configs.transitionDuration
builder()
@@ -390,7 +413,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() }
@@ -412,13 +437,16 @@ class SearchView @JvmOverloads constructor(
private fun configureCoords(item: MenuItem?) {
item ?: return
- if (parent !is ViewGroup) return
+ if (parent !is ViewGroup) {
+ return
+ }
val view = parentViewGroup.findViewById<View>(item.itemId) ?: return
view.getLocationInWindow(locations)
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)
@@ -461,7 +489,9 @@ class SearchView @JvmOverloads constructor(
}
fun revealOpen() {
- if (parent == null || isOpen) return
+ if (parent == null || isOpen) {
+ return
+ }
context.runOnUiThread {
/**
* The y component is relative to the cardView, but it hasn't been drawn yet so its own height is 0
@@ -472,7 +502,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()
}
@@ -480,15 +514,21 @@ class SearchView @JvmOverloads constructor(
}
fun revealClose() {
- if (parent == null || !isOpen) return
+ if (parent == null || !isOpen) {
+ return
+ }
context.runOnUiThread {
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()
+ if (configs.shouldClearOnClose) {
+ kau_search_edit_text.text?.clear()
+ }
})
}
}
@@ -509,8 +549,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 +563,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
diff --git a/settings.gradle b/settings.gradle
index 42d498e..0ec0606 100644
--- a/settings.gradle
+++ b/settings.gradle
@@ -4,6 +4,7 @@ include ':core',
':about',
':adapter',
':fastadapter',
+ ':fastadapter-databinding',
':colorpicker',
':mediapicker',
':kpref-activity',