aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore2
-rw-r--r--.idea/codeStyles/codeStyleConfig.xml2
-rw-r--r--.idea/jarRepositories.xml35
-rw-r--r--.idea/misc.xml44
-rw-r--r--.idea/runConfigurations.xml12
-rw-r--r--.jitpack.yml2
-rw-r--r--.travis.yml20
-rw-r--r--README.md7
-rw-r--r--about/src/main/kotlin/ca/allanwang/kau/about/AboutActivityBase.kt38
-rw-r--r--about/src/main/kotlin/ca/allanwang/kau/about/CutoutIItem.kt2
-rw-r--r--about/src/main/kotlin/ca/allanwang/kau/about/FaqIItem.kt2
-rw-r--r--about/src/main/kotlin/ca/allanwang/kau/about/LibraryIItem.kt2
-rw-r--r--android-lib.gradle34
-rw-r--r--artifacts.gradle38
-rw-r--r--build.gradle12
-rw-r--r--buildSrc/build.gradle.kts4
-rw-r--r--buildSrc/src/main/kotlin/kau/Dependencies.kt32
-rw-r--r--buildSrc/src/main/kotlin/kau/Plugins.kt3
-rw-r--r--buildSrc/src/main/kotlin/kau/Versions.kt83
-rw-r--r--core-ui/src/main/kotlin/ca/allanwang/kau/ui/activities/ElasticRecyclerActivity.kt26
-rw-r--r--core-ui/src/main/res-public/values/public.xml2
-rw-r--r--core/src/androidTest/kotlin/ca/allanwang/kau/Utils.kt22
-rw-r--r--core/src/androidTest/kotlin/ca/allanwang/kau/kpref/KPrefTest.kt36
-rw-r--r--core/src/main/kotlin/ca/allanwang/kau/kpref/KPref.kt47
-rw-r--r--core/src/main/kotlin/ca/allanwang/kau/kpref/KPrefBuilder.kt132
-rw-r--r--core/src/main/kotlin/ca/allanwang/kau/kpref/KPrefDelegate.kt29
-rw-r--r--core/src/main/kotlin/ca/allanwang/kau/kpref/KPrefFactory.kt37
-rw-r--r--core/src/main/kotlin/ca/allanwang/kau/kpref/KPrefSingleDelegate.kt14
-rw-r--r--core/src/main/kotlin/ca/allanwang/kau/logging/KauLogger.kt2
-rw-r--r--core/src/main/res-public/values/public.xml34
-rw-r--r--core/src/test/kotlin/ca/allanwang/kau/kotlin/DebounceTest.kt2
-rw-r--r--docs/Changelog.md23
-rw-r--r--docs/Migration.md21
-rw-r--r--fastadapter-viewbinding/build.gradle6
-rw-r--r--fastadapter-viewbinding/src/main/kotlin/ca/allanwang/fastadapter/viewbinding/BindingItem.kt4
-rw-r--r--fastadapter/src/main/kotlin/ca/allanwang/kau/adapters/AdapterUtils.kt4
-rw-r--r--fastadapter/src/main/kotlin/ca/allanwang/kau/iitems/CardIItem.kt2
-rw-r--r--fastadapter/src/main/kotlin/ca/allanwang/kau/iitems/HeaderIItem.kt2
-rwxr-xr-xfiles/translation_migration.sh2
-rw-r--r--gradle/wrapper/gradle-wrapper.jarbin55616 -> 58910 bytes
-rw-r--r--gradle/wrapper/gradle-wrapper.properties2
-rwxr-xr-xgradlew31
-rw-r--r--gradlew.bat4
-rw-r--r--kpref-activity/build.gradle2
-rw-r--r--kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/KPrefActivity.kt58
-rw-r--r--kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefCheckbox.kt2
-rw-r--r--kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefColorPicker.kt2
-rw-r--r--kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefHeader.kt2
-rw-r--r--kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefItemBase.kt2
-rw-r--r--kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefItemCore.kt2
-rw-r--r--kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefSeekbar.kt2
-rw-r--r--kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefText.kt2
-rw-r--r--mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/BlurredImageView.kt79
-rw-r--r--mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaActionItem.kt2
-rw-r--r--mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaItem.kt2
-rw-r--r--mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaItemBasic.kt2
-rw-r--r--mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaPickerActivityBase.kt55
-rw-r--r--mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaPickerActivityOverlayBase.kt21
-rw-r--r--mediapicker/src/main/res/layout/kau_iitem_image_basic.xml4
-rw-r--r--sample/build.gradle63
-rw-r--r--sample/src/androidTest/kotlin/ca/allanwang/kau/sample/KPrefViewTest.kt47
-rw-r--r--sample/src/androidTest/kotlin/ca/allanwang/kau/sample/SampleTestApp.kt63
-rw-r--r--sample/src/androidTest/kotlin/ca/allanwang/kau/sample/test/BaseTest.kt32
-rw-r--r--sample/src/androidTest/kotlin/ca/allanwang/kau/sample/test/TestModules.kt33
-rw-r--r--sample/src/main/AndroidManifest.xml3
-rw-r--r--sample/src/main/kotlin/ca/allanwang/kau/sample/AboutActivity.kt20
-rw-r--r--sample/src/main/kotlin/ca/allanwang/kau/sample/AnimActivity.kt8
-rw-r--r--sample/src/main/kotlin/ca/allanwang/kau/sample/KPrefSample.kt24
-rw-r--r--sample/src/main/kotlin/ca/allanwang/kau/sample/MainActivity.kt622
-rw-r--r--sample/src/main/kotlin/ca/allanwang/kau/sample/PermissionCheckbox.kt4
-rw-r--r--sample/src/main/kotlin/ca/allanwang/kau/sample/SampleApp.kt12
-rw-r--r--sample/src/main/res/xml/kau_changelog.xml26
-rw-r--r--searchview/src/main/kotlin/ca/allanwang/kau/searchview/SearchItem.kt2
-rw-r--r--searchview/src/main/kotlin/ca/allanwang/kau/searchview/SearchView.kt213
-rw-r--r--spotless.gradle4
75 files changed, 1615 insertions, 658 deletions
diff --git a/.gitignore b/.gitignore
index f08bd63..6540ec6 100644
--- a/.gitignore
+++ b/.gitignore
@@ -30,4 +30,6 @@
.idea/modules.xml
.idea/modules
.idea/vcs.xml
+.idea/compiler.xml
+.idea/misc.xml
.idea/codeStyles/Project.xml \ No newline at end of file
diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml
index a55e7a1..79ee123 100644
--- a/.idea/codeStyles/codeStyleConfig.xml
+++ b/.idea/codeStyles/codeStyleConfig.xml
@@ -1,5 +1,5 @@
<component name="ProjectCodeStyleConfiguration">
<state>
- <option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" />
+ <option name="USE_PER_PROJECT_SETTINGS" value="true" />
</state>
</component> \ No newline at end of file
diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml
new file mode 100644
index 0000000..1e2d92c
--- /dev/null
+++ b/.idea/jarRepositories.xml
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+ <component name="RemoteRepositoriesConfiguration">
+ <remote-repository>
+ <option name="id" value="central" />
+ <option name="name" value="Maven Central repository" />
+ <option name="url" value="https://repo1.maven.org/maven2" />
+ </remote-repository>
+ <remote-repository>
+ <option name="id" value="jboss.community" />
+ <option name="name" value="JBoss Community repository" />
+ <option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
+ </remote-repository>
+ <remote-repository>
+ <option name="id" value="BintrayJCenter" />
+ <option name="name" value="BintrayJCenter" />
+ <option name="url" value="https://jcenter.bintray.com/" />
+ </remote-repository>
+ <remote-repository>
+ <option name="id" value="maven" />
+ <option name="name" value="maven" />
+ <option name="url" value="https://jitpack.io" />
+ </remote-repository>
+ <remote-repository>
+ <option name="id" value="Google" />
+ <option name="name" value="Google" />
+ <option name="url" value="https://dl.google.com/dl/android/maven2/" />
+ </remote-repository>
+ <remote-repository>
+ <option name="id" value="MavenRepo" />
+ <option name="name" value="MavenRepo" />
+ <option name="url" value="https://repo.maven.apache.org/maven2/" />
+ </remote-repository>
+ </component>
+</project> \ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
deleted file mode 100644
index cc04cd3..0000000
--- a/.idea/misc.xml
+++ /dev/null
@@ -1,44 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<project version="4">
- <component name="NullableNotNullManager">
- <option name="myDefaultNullable" value="android.support.annotation.Nullable" />
- <option name="myDefaultNotNull" value="android.support.annotation.NonNull" />
- <option name="myNullables">
- <value>
- <list size="10">
- <item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.Nullable" />
- <item index="1" class="java.lang.String" itemvalue="javax.annotation.Nullable" />
- <item index="2" class="java.lang.String" itemvalue="javax.annotation.CheckForNull" />
- <item index="3" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.Nullable" />
- <item index="4" class="java.lang.String" itemvalue="android.support.annotation.Nullable" />
- <item index="5" class="java.lang.String" itemvalue="androidx.annotation.Nullable" />
- <item index="6" class="java.lang.String" itemvalue="androidx.annotation.RecentlyNullable" />
- <item index="7" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.qual.Nullable" />
- <item index="8" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.compatqual.NullableDecl" />
- <item index="9" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.compatqual.NullableType" />
- </list>
- </value>
- </option>
- <option name="myNotNulls">
- <value>
- <list size="9">
- <item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.NotNull" />
- <item index="1" class="java.lang.String" itemvalue="javax.annotation.Nonnull" />
- <item index="2" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.NonNull" />
- <item index="3" class="java.lang.String" itemvalue="android.support.annotation.NonNull" />
- <item index="4" class="java.lang.String" itemvalue="androidx.annotation.NonNull" />
- <item index="5" class="java.lang.String" itemvalue="androidx.annotation.RecentlyNonNull" />
- <item index="6" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.qual.NonNull" />
- <item index="7" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.compatqual.NonNullDecl" />
- <item index="8" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.compatqual.NonNullType" />
- </list>
- </value>
- </option>
- </component>
- <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK">
- <output url="file://$PROJECT_DIR$/build/classes" />
- </component>
- <component name="ProjectType">
- <option name="id" value="Android" />
- </component>
-</project> \ No newline at end of file
diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml
deleted file mode 100644
index 7f68460..0000000
--- a/.idea/runConfigurations.xml
+++ /dev/null
@@ -1,12 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<project version="4">
- <component name="RunConfigurationProducerService">
- <option name="ignoredProducers">
- <set>
- <option value="org.jetbrains.plugins.gradle.execution.test.runner.AllInPackageGradleConfigurationProducer" />
- <option value="org.jetbrains.plugins.gradle.execution.test.runner.TestClassGradleConfigurationProducer" />
- <option value="org.jetbrains.plugins.gradle.execution.test.runner.TestMethodGradleConfigurationProducer" />
- </set>
- </option>
- </component>
-</project> \ No newline at end of file
diff --git a/.jitpack.yml b/.jitpack.yml
new file mode 100644
index 0000000..adb3fe1
--- /dev/null
+++ b/.jitpack.yml
@@ -0,0 +1,2 @@
+jdk:
+ - openjdk11
diff --git a/.travis.yml b/.travis.yml
index 69dabb2..b42ec79 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,11 +1,13 @@
language: android
jdk:
-- oraclejdk8
+- openjdk11
env:
global:
- - ANDROID_API=29
+ - ANDROID_API=30
- EMULATOR_API=19
- - ANDROID_BUILD_TOOLS=29.0.0
+ - ANDROID_BUILD_TOOLS=30.0.2
+ - ANDROID_COMMAND_LINE_TOOLS=7583922
+ - ANDROID_HOME=~/android-sdk
git:
depth: 500
android:
@@ -22,8 +24,8 @@ android:
script:
- chmod +x gradlew
- "./gradlew --quiet androidGitVersion"
-- if [[ "$TRAVIS_BRANCH" == "master" ]]; then ./gradlew lintRelease publishRelease;
- else ./gradlew lintRelease testReleaseUnitTest; fi
+- if [[ "$TRAVIS_BRANCH" == "master" ]]; then ./gradlew spotlessCheck lintRelease publishRelease;
+ else ./gradlew spotlessCheck lintRelease testReleaseUnitTest; fi
branches:
except:
- gh-pages
@@ -42,7 +44,13 @@ cache:
- "$HOME/.gradle/wrapper/"
- "$HOME/.android/build-cache"
before_install:
-- yes | sdkmanager "platforms;android-$ANDROID_API"
+# Get Java 11 compatible tools: https://stackoverflow.com/a/68534598/4407321
+- touch $HOME/.android/repositories.cfg
+- wget "https://dl.google.com/android/repository/commandlinetools-linux-${ANDROID_COMMAND_LINE_TOOLS}_latest.zip" -O commandlinetools.zip
+- unzip commandlinetools.zip -d $ANDROID_HOME/
+- yes | $ANDROID_HOME/cmdline-tools/bin/sdkmanager "platforms;android-${ANDROID_API}" --sdk_root=$ANDROID_HOME
+- yes | $ANDROID_HOME/cmdline-tools/bin/sdkmanager "build-tools;${ANDROID_BUILD_TOOLS}" --sdk_root=$ANDROID_HOME
+# Get KAU content
- openssl aes-256-cbc -K $encrypted_12e8842891a3_key -iv $encrypted_12e8842891a3_iv
-in files/kau.tar.enc -out kau.tar -d
- tar xvf kau.tar
diff --git a/README.md b/README.md
index 481650b..73ba2e4 100644
--- a/README.md
+++ b/README.md
@@ -161,16 +161,20 @@ Special thanks to the following awesome people for translating significant porti
| Catalan | [Jaime Muñoz Martín](https://crowdin.com/profile/jmmartin_5) |
| Chinese (Simplified) | [Alcatelia](https://crowdin.com/profile/Alcatelia) |
| Chinese (Traditional) | [yipinghuang](https://crowdin.com/profile/yipinghuang) &bull; [Su, Jun-Ming](https://crowdin.com/profile/sujunmin) &bull; [Wei](https://crowdin.com/profile/wei4green) |
+| Czech | [Lukas Novotny](https://crowdin.com/profile/novas78) |
| Danish | [mhtorp](https://crowdin.com/profile/mhtorp) |
| Dutch | [ItGuillaume](https://crowdin.com/profile/ltGuillaume) &bull; [Tatum ter Kuile](https://crowdin.com/profile/Teitr) |
+| Finnish | [Rynach](https://crowdin.com/profile/Rynach) |
| French | [Vincent Kulak](https://github.com/VonOx) &bull; [Jean-Philippe Gravel](https://crowdin.com/profile/wokija) |
| Galician | [Xesús M. Mosquera](https://twitter.com/xesusmmc?lang=en) |
| German | [Bushido1992](https://forum.xda-developers.com/member.php?u=5179246) &bull; [Marcel Soehnchen](https://crowdin.com/profile/msoehnchen) &bull; [3LD0mi HA](https://forum.xda-developers.com/member.php?u=5860523) |
| Greek | [George Kitsopoulos](https://crowdin.com/profile/GeorgeKitsopoulos) |
| Hungarian | [János Erkli](https://crowdin.com/profile/erklijani0521) |
| Indonesian | [M. Angga Ariska](https://www.youtube.com/channel/UCkqMw81s2aw7bYO-U2YhD7w) |
-| Italian | [Bonnee](https://github.com/Bonnee) |
+| Italian | [Bonnee](https://github.com/Bonnee) &bull; [Keita Tanaka](https://crowdin.com/profile/Keita_Tanaka) |
+| Japanese | [maru2213](https://crowdin.com/profile/maru2213) |
| Korean | [잇스테이크](https://crowdin.com/profile/bexco2010) |
+| Malayalam | [Abhishek M](https://crowdin.com/profile/abhishekabhi789) |
| Norwegian | |
| Polish | [pantinPL](https://crowdin.com/profile/pantinPL) |
| Portuguese | [Sérgio Marques](https://crowdin.com/profile/smarquespt) &bull; [Miguel Dos Reis](https://crowdin.com/profile/siersod) |
@@ -180,6 +184,7 @@ Special thanks to the following awesome people for translating significant porti
| Spanish | [Jahir Fiquitiva](https://jahirfiquitiva.me/) &bull; [Nefi Salazar](https://plus.google.com/u/0/105547968033551087431)|
| Swedish | [Artswitcher](https://crowdin.com/profile/Artswitcher) |
| Tagalog | [Fray Damaso](https://crowdin.com/profile/Fray_Damaso) |
+| Tamil | [rooban23](https://crowdin.com/profile/rooban23) |
| Thai | [Thanawat Hanthong](https://crowdin.com/profile/peet6015) |
| Turkish | [zuma17](https://crowdin.com/profile/zuma17) |
| Ukrainian | [Вадим Жушман](https://crowdin.com/profile/android54544) |
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 6b57825..286d95e 100644
--- a/about/src/main/kotlin/ca/allanwang/kau/about/AboutActivityBase.kt
+++ b/about/src/main/kotlin/ca/allanwang/kau/about/AboutActivityBase.kt
@@ -23,6 +23,7 @@ import android.view.View
import android.view.ViewGroup
import androidx.viewpager.widget.PagerAdapter
import androidx.viewpager.widget.ViewPager
+import ca.allanwang.kau.about.databinding.KauActivityAboutBinding
import ca.allanwang.kau.adapters.FastItemThemedAdapter
import ca.allanwang.kau.adapters.ThemableIItemColors
import ca.allanwang.kau.adapters.ThemableIItemColorsDelegate
@@ -34,33 +35,31 @@ import ca.allanwang.kau.utils.dimenPixelSize
import com.mikepenz.aboutlibraries.Libs
import com.mikepenz.aboutlibraries.entity.Library
import com.mikepenz.fastadapter.GenericItem
-import kotlinx.android.synthetic.main.kau_activity_about.*
/**
* Created by Allan Wang on 2017-06-28.
*
* Floating About Activity Panel for your app
- * This contains all the necessary layouts, and can be extended and configured using the [configBuilder]
+ * This contains all the necessary layouts, and can be extended and configured using [buildConfigs]
* The [rClass] is necessary to generate the list of libraries used in your app, and should point to your app's
* R.string::class.java
* If you don't need auto detect, you can pass null instead
* 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<*>?) :
KauBaseActivity(), ViewPager.OnPageChangeListener {
val currentPage: Int
- get() = about_pager.currentItem
+ get() = binding.aboutPager.currentItem
/**
* Holds some common configurations that may be added directly from the constructor
* Applied lazily since it needs the context to fetch resources
*/
- val configs: Configs by lazy { Configs().apply { configBuilder() } }
+ val configs: Configs by lazy { Configs().apply { buildConfigs() } }
+
+ open fun Configs.buildConfigs() = Unit
/**
* Holds that status of each page
@@ -78,31 +77,38 @@ abstract class AboutActivityBase(
defaultPanels
}
+ private lateinit var binding: KauActivityAboutBinding
+
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
- setContentView(R.layout.kau_activity_about)
+ binding = KauActivityAboutBinding.inflate(layoutInflater)
+ setContentView(binding.root)
+ binding.init()
+ }
+
+ private fun KauActivityAboutBinding.init() {
pageStatus = IntArray(panels.size)
pageStatus[0] = 2 // the first page is instantly visible
if (configs.textColor != null) {
- about_indicator.setColour(configs.textColor!!)
+ aboutIndicator.setColour(configs.textColor!!)
}
- with(about_pager) {
+ with(aboutPager) {
adapter = AboutPagerAdapter()
pageMargin = dimenPixelSize(R.dimen.kau_spacing_normal)
offscreenPageLimit = panels.size - 1
addOnPageChangeListener(this@AboutActivityBase)
}
- about_indicator.setViewPager(about_pager)
- about_draggable_frame.addListener(object :
- ElasticDragDismissFrameLayout.SystemChromeFader(this) {
+ aboutIndicator.setViewPager(aboutPager)
+ aboutDraggableFrame.addListener(object :
+ ElasticDragDismissFrameLayout.SystemChromeFader(this@AboutActivityBase) {
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)
+ .inflateTransition(if (aboutDraggableFrame.translationY > 0) R.transition.kau_exit_slide_bottom else R.transition.kau_exit_slide_top)
panels[currentPage].recycler?.stopScroll()
finishAfterTransition()
}
})
- panels.forEachIndexed { index, contract -> contract.loadItems(this, index) }
+ panels.forEachIndexed { index, contract -> contract.loadItems(this@AboutActivityBase, index) }
}
class Configs : ThemableIItemColors by ThemableIItemColorsDelegate() {
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 d92f6a7..2a1588c 100644
--- a/about/src/main/kotlin/ca/allanwang/kau/about/CutoutIItem.kt
+++ b/about/src/main/kotlin/ca/allanwang/kau/about/CutoutIItem.kt
@@ -35,7 +35,7 @@ class CutoutIItem(val config: CutoutView.() -> Unit = {}) : KauIItem<CutoutIItem
get() = false
set(_) {}
- override fun bindView(holder: ViewHolder, payloads: MutableList<Any>) {
+ override fun bindView(holder: ViewHolder, payloads: List<Any>) {
super.bindView(holder, payloads)
with(holder) {
if (accentColor != null && themeEnabled) cutout.foregroundColor = accentColor!!
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 977b7ff..ddb9a18 100644
--- a/about/src/main/kotlin/ca/allanwang/kau/about/FaqIItem.kt
+++ b/about/src/main/kotlin/ca/allanwang/kau/about/FaqIItem.kt
@@ -67,7 +67,7 @@ class FaqIItem(val content: FaqItem) : KauIItem<FaqIItem.ViewHolder>(
private var isExpanded = false
@SuppressLint("SetTextI18n")
- override fun bindView(holder: ViewHolder, payloads: MutableList<Any>) {
+ override fun bindView(holder: ViewHolder, payloads: List<Any>) {
super.bindView(holder, payloads)
with(holder) {
number.text = "${content.number}."
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 cd53f55..c64fe4e 100644
--- a/about/src/main/kotlin/ca/allanwang/kau/about/LibraryIItem.kt
+++ b/about/src/main/kotlin/ca/allanwang/kau/about/LibraryIItem.kt
@@ -59,7 +59,7 @@ class LibraryIItem(val lib: Library) : KauIItem<LibraryIItem.ViewHolder>(
get() = false
set(_) {}
- override fun bindView(holder: ViewHolder, payloads: MutableList<Any>) {
+ override fun bindView(holder: ViewHolder, payloads: List<Any>) {
super.bindView(holder, payloads)
with(holder) {
name.text = lib.libraryName
diff --git a/android-lib.gradle b/android-lib.gradle
index 196cc1b..83813ca 100644
--- a/android-lib.gradle
+++ b/android-lib.gradle
@@ -3,14 +3,12 @@ import kau.Versions
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
-apply plugin: 'kotlin-android-extensions'
-apply plugin: 'com.github.dcendents.android-maven'
-apply plugin: 'com.getkeepsafe.dexcount'
+apply plugin: 'kotlin-parcelize'
+//apply plugin: 'com.getkeepsafe.dexcount'
group = "ca.allanwang"
android {
compileSdkVersion Versions.targetSdk
- buildToolsVersion Versions.buildTools
androidGitVersion {
codeFormat = 'MMNNPPXX'
@@ -37,6 +35,10 @@ android {
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
+ buildFeatures {
+ viewBinding = true
+ }
+
buildTypes {
release {
minifyEnabled false
@@ -45,15 +47,24 @@ android {
}
lintOptions {
- warningsAsErrors true
+ // warningsAsErrors true
disable 'UnusedResources',
'ContentDescription',
'RtlSymmetry',
'RtlHardcoded',
'RtlEnabled',
'Overdraw',
- 'MissingTranslation'
-
+ 'MissingTranslation',
+ 'MissingQuantity',
+ 'UnspecifiedImmutableFlag',
+ 'QueryPermissionsNeeded',
+ 'AnnotateVersionCheck',
+ 'Recycle',
+ 'MissingSuperCall',
+ 'UnsafeExperimentalUsageError',
+ 'UnsafeExperimentalUsageWarning'
+
+ abortOnError false
xmlReport false
textReport true
textOutput 'stdout'
@@ -63,11 +74,16 @@ android {
pickFirst 'META-INF/core_release.kotlin_module'
pickFirst 'META-INF/library_release.kotlin_module'
pickFirst 'META-INF/library-core_release.kotlin_module'
+ exclude "**/module-info.class"
}
compileOptions {
- sourceCompatibility JavaVersion.VERSION_1_8
- targetCompatibility JavaVersion.VERSION_1_8
+ sourceCompatibility Versions.java
+ targetCompatibility Versions.java
+ }
+
+ kotlinOptions {
+ jvmTarget = Versions.java.toString()
}
sourceSets {
diff --git a/artifacts.gradle b/artifacts.gradle
index 4471d37..8e01978 100644
--- a/artifacts.gradle
+++ b/artifacts.gradle
@@ -1,30 +1,6 @@
import groovy.xml.MarkupBuilder
-apply plugin: 'com.github.dcendents.android-maven'
-
-// build a jar with source files
-task sourcesJar(type: Jar) {
- from android.sourceSets.main.java.srcDirs
- classifier = 'sources'
-}
-
-task javadoc(type: Javadoc) {
- failOnError false
- source = android.sourceSets.main.java.sourceFiles
- classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
- classpath += configurations.compile
-}
-
-// build a jar with javadoc
-task javadocJar(type: Jar, dependsOn: javadoc) {
- classifier = 'javadoc'
- from javadoc.destinationDir
-}
-
-artifacts {
- archives sourcesJar
- archives javadocJar
-}
+apply plugin: 'maven-publish'
// Task to generate our public.xml file
// See https://developer.android.com/studio/projects/android-library.html#PrivateResources
@@ -107,4 +83,16 @@ task generatepublicxml {
}
}
+afterEvaluate {
+ publishing {
+ publications {
+ release(MavenPublication) {
+ from components.release
+ groupId = group
+ artifactId = project.name
+ }
+ }
+ }
+}
+
build.dependsOn generatepublicxml \ No newline at end of file
diff --git a/build.gradle b/build.gradle
index cf8998f..33d7cd0 100644
--- a/build.gradle
+++ b/build.gradle
@@ -5,7 +5,7 @@ buildscript {
repositories {
google()
- jcenter()
+ mavenCentral()
maven { url 'https://maven.fabric.io/public' }
maven { url "https://plugins.gradle.org/m2/" }
}
@@ -13,20 +13,18 @@ buildscript {
dependencies {
classpath Plugins.android
classpath Plugins.kotlin
- classpath Plugins.androidMaven
+ classpath Plugins.bugsnag
classpath Plugins.playPublisher
classpath Plugins.dexCount
classpath Plugins.gitVersion
classpath Plugins.spotless
+ classpath Plugins.aboutLibraries
+ classpath Plugins.hilt
}
wrapper.setDistributionType(Wrapper.DistributionType.ALL)
}
-task clean(type: Delete) {
- delete rootProject.buildDir
-}
-
task generateChangelogMd {
ChangelogGenerator.generate("${project.rootDir}/sample/src/main/res/xml/kau_changelog.xml", "${project.rootDir}/docs/Changelog.md")
}
@@ -42,7 +40,7 @@ subprojects {
repositories {
google()
- jcenter()
+ mavenCentral()
maven { url "https://jitpack.io" }
}
}
diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts
index 89cba29..0cc118e 100644
--- a/buildSrc/build.gradle.kts
+++ b/buildSrc/build.gradle.kts
@@ -1,10 +1,10 @@
plugins {
`kotlin-dsl`
- maven
+ id("maven-publish")
}
group = "ca.allanwang"
repositories {
- jcenter()
+ mavenCentral()
} \ No newline at end of file
diff --git a/buildSrc/src/main/kotlin/kau/Dependencies.kt b/buildSrc/src/main/kotlin/kau/Dependencies.kt
index caf2f6e..8048959 100644
--- a/buildSrc/src/main/kotlin/kau/Dependencies.kt
+++ b/buildSrc/src/main/kotlin/kau/Dependencies.kt
@@ -29,6 +29,9 @@ object Dependencies {
fun kauFastAdapter(version: String) = kau("fastadapter", version)
@JvmStatic
+ fun kauFastAdapterViewBinding(version: String) = kau("fastadapter-viewbinding", version)
+
+ @JvmStatic
fun kauKprefActivity(version: String) = kau("kpref-activity", version)
@JvmStatic
@@ -47,6 +50,30 @@ object Dependencies {
@JvmField
val kotlinReflect = kotlin("reflect")
+ @JvmField
+ val koin = koin("android")
+
+ @JvmField
+ val koinTest = koin("test")
+
+ @JvmStatic
+ fun koin(type: String) = "io.insert-koin:koin-$type:${Versions.koin}"
+
+ @JvmField
+ val hilt = "com.google.dagger:hilt-android:${Versions.hilt}"
+
+ @JvmField
+ val hiltCompiler = hilt("compiler")
+
+ @JvmField
+ val hiltTest = hilt("testing")
+
+ @JvmStatic
+ fun hilt(type: String) = "com.google.dagger:hilt-android-$type:${Versions.hilt}"
+
+ @JvmStatic
+ fun compose(type: String) = "androidx.ui:ui-$type:${Versions.compose}"
+
const val junit = "junit:junit:${Versions.junit}"
const val coroutines = "org.jetbrains.kotlinx:kotlinx-coroutines-android:${Versions.coroutines}"
@@ -62,12 +89,13 @@ object Dependencies {
const val iconics = "com.mikepenz:iconics-core:${Versions.iconics}"
const val iconicsGoogle =
- "com.mikepenz:google-material-typeface:${Versions.iconicsGoogle}.original-kotlin@aar"
+ "com.mikepenz:google-material-typeface:${Versions.iconicsGoogle}-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}"
const val aboutLibrariesCore = "com.mikepenz:aboutlibraries-core:${Versions.aboutLibraries}"
const val blurry = "jp.wasabeef:blurry:${Versions.blurry}"
@@ -89,6 +117,8 @@ object Dependencies {
const val bugsnag = "com.bugsnag:bugsnag-android:${Versions.bugsnag}"
+ const val leakCanary = "com.squareup.leakcanary:leakcanary-android:${Versions.leakCanary}"
+
@JvmStatic
fun espresso(type: String) = "androidx.test.espresso:espresso-$type:${Versions.espresso}"
diff --git a/buildSrc/src/main/kotlin/kau/Plugins.kt b/buildSrc/src/main/kotlin/kau/Plugins.kt
index 3978d7b..d255ad4 100644
--- a/buildSrc/src/main/kotlin/kau/Plugins.kt
+++ b/buildSrc/src/main/kotlin/kau/Plugins.kt
@@ -5,11 +5,12 @@ package kau
*/
object Plugins {
const val android = "com.android.tools.build:gradle:${Versions.gradlePlugin}"
+ const val aboutLibraries = "com.mikepenz.aboutlibraries.plugin:aboutlibraries-plugin:${Versions.aboutLibraries}"
const val bugsnag = "com.bugsnag:bugsnag-android-gradle-plugin:${Versions.bugsnagPlugin}"
const val kotlin = "org.jetbrains.kotlin:kotlin-gradle-plugin:${Versions.kotlin}"
- const val androidMaven = "com.github.dcendents:android-maven-gradle-plugin:${Versions.mavenPlugin}"
const val playPublisher = "com.github.triplet.gradle:play-publisher:${Versions.playPublishPlugin}"
const val dexCount = "com.getkeepsafe.dexcount:dexcount-gradle-plugin:${Versions.dexCountPlugin}"
const val gitVersion = "com.gladed.androidgitversion:gradle-android-git-version:${Versions.gitVersionPlugin}"
const val spotless = "com.diffplug.spotless:spotless-plugin-gradle:${Versions.spotless}"
+ const val hilt = "com.google.dagger:hilt-android-gradle-plugin:${Versions.hilt}"
} \ No newline at end of file
diff --git a/buildSrc/src/main/kotlin/kau/Versions.kt b/buildSrc/src/main/kotlin/kau/Versions.kt
index 6e1d70b..5d3627e 100644
--- a/buildSrc/src/main/kotlin/kau/Versions.kt
+++ b/buildSrc/src/main/kotlin/kau/Versions.kt
@@ -1,91 +1,106 @@
package kau
+import org.gradle.api.JavaVersion
+
object Versions {
const val coreMinSdk = 19
const val minSdk = 21
- const val targetSdk = 29
+ const val targetSdk = 30
- // https://developer.android.com/studio/releases/build-tools
- const val buildTools = "29.0.0"
+ val java = JavaVersion.VERSION_1_8
// https://mvnrepository.com/artifact/androidx.appcompat/appcompat?repo=google
- const val appcompat = "1.1.0"
+ const val appcompat = "1.3.0-rc01"
// https://mvnrepository.com/artifact/com.google.android.material/material
- const val googleMaterial = "1.1.0-beta02"
+ const val googleMaterial = "1.3.0"
// https://mvnrepository.com/artifact/androidx.recyclerview/recyclerview
- const val recyclerView = "1.1.0"
+ const val recyclerView = "1.2.0"
// https://mvnrepository.com/artifact/androidx.swiperefreshlayout/swiperefreshlayout
- const val swipeRefreshLayout = "1.0.0"
+ const val swipeRefreshLayout = "1.1.0"
// https://mvnrepository.com/artifact/androidx.cardview/cardview
const val cardView = "1.0.0"
// https://mvnrepository.com/artifact/androidx.constraintlayout/constraintlayout
- const val constraintLayout = "2.0.0-beta4"
+ const val constraintLayout = "2.1.0"
// https://mvnrepository.com/artifact/androidx.core/core-ktx
- const val coreKtx = "1.2.0-rc01"
+ const val coreKtx = "1.6.0"
// https://kotlinlang.org/docs/reference/using-gradle.html
- const val kotlin = "1.3.61"
+ const val kotlin = "1.5.30"
// https://github.com/Kotlin/kotlinx.coroutines/releases
- const val coroutines = "1.3.3"
+ const val coroutines = "1.5.0"
// https://github.com/mikepenz/AboutLibraries/releases
- const val aboutLibraries = "7.1.0"
+ const val aboutLibraries = "8.9.0"
+ // Keep old version
// https://github.com/wasabeef/Blurry/releases
- const val blurry = "3.0.0"
+ const val blurry = "4.0.0"
// https://github.com/mikepenz/FastAdapter/releases
- const val fastAdapter = "4.1.2"
+ const val fastAdapter = "5.4.1"
// https://github.com/bumptech/glide/releases
- const val glide = "4.10.0"
+ const val glide = "4.12.0"
// https://github.com/mikepenz/Android-Iconics#1-provide-the-gradle-dependency
- const val iconics = "4.0.2"
- const val iconicsGoogle = "3.0.1.4"
- const val iconicsMaterial = "2.2.0.6"
- const val iconicsCommunity = "3.5.95.1"
+ const val iconics = "5.3.0"
+ const val iconicsGoogle = "4.0.0.1"
+ const val iconicsMaterial = "2.2.0.8"
+ const val iconicsCommunity = "5.8.55.0"
// https://github.com/afollestad/material-dialogs/releases
- const val materialDialog = "3.1.1"
+ const val materialDialog = "3.3.0"
+
+ // https://github.com/InsertKoinIO/koin/blob/master/CHANGELOG.md
+ const val koin = "3.1.0"
+
+ // https://github.com/google/dagger/releases
+ // https://mvnrepository.com/artifact/com.google.dagger/hilt-android
+ const val hilt = "2.37"
+
+ // https://mvnrepository.com/artifact/androidx.ui/ui-core?repo=google
+ const val compose = "0.1.0-dev14"
+
+ // https://square.github.io/leakcanary/changelog/
+ const val leakCanary = "2.7"
// https://mvnrepository.com/artifact/androidx.test.espresso/espresso-core?repo=google
- const val espresso = "3.2.0"
+ const val espresso = "3.3.0"
// https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-api
- const val junit = "4.12"
+ const val junit = "4.13"
- const val testRunner = "1.1.0"
+ // https://mvnrepository.com/artifact/androidx.test.ext/junit
+ const val testRunner = "1.1.2"
// https://mvnrepository.com/artifact/androidx.test/rules?repo=google
- const val testRules = "1.2.0"
+ const val testRules = "1.3.0"
// https://github.com/diffplug/spotless/blob/master/plugin-gradle/CHANGES.md
- const val spotless = "3.26.1"
+ const val spotless = "5.7.0"
// https://github.com/bugsnag/bugsnag-android/releases
- const val bugsnag = "4.21.1"
+ const val bugsnag = "5.12.0"
// https://github.com/bugsnag/bugsnag-android-gradle-plugin/releases
- const val bugsnagPlugin="4.7.2"
+ const val bugsnagPlugin = "7.0.0"
// https://mvnrepository.com/artifact/com.android.tools.build/gradle?repo=google
- const val gradlePlugin = "3.6.0-rc01"
- // https://github.com/dcendents/android-maven-gradle-plugin/releases
- const val mavenPlugin = "2.1"
+ const val gradlePlugin = "7.1.0-alpha05"
+
// https://github.com/Triple-T/gradle-play-publisher/releases
- const val playPublishPlugin = "2.6.1"
+ const val playPublishPlugin = "3.4.0-agp7.0"
// https://github.com/KeepSafe/dexcount-gradle-plugin/releases
- const val dexCountPlugin = "1.0.2"
+ const val dexCountPlugin = "3.0.0"
// https://github.com/gladed/gradle-android-git-version/releases
- const val gitVersionPlugin = "0.4.11"
-} \ No newline at end of file
+ const val gitVersionPlugin = "0.4.14"
+}
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 3e7254f..e948f29 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
@@ -23,8 +23,8 @@ import androidx.appcompat.widget.Toolbar
import androidx.recyclerview.widget.RecyclerView
import ca.allanwang.kau.internal.KauBaseActivity
import ca.allanwang.kau.ui.R
+import ca.allanwang.kau.ui.databinding.KauElasticRecyclerActivityBinding
import ca.allanwang.kau.ui.widgets.ElasticDragDismissFrameLayout
-import kotlinx.android.synthetic.main.kau_elastic_recycler_activity.*
/**
* Created by Allan Wang on 2017-07-17.
@@ -41,8 +41,11 @@ import kotlinx.android.synthetic.main.kau_elastic_recycler_activity.*
abstract class ElasticRecyclerActivity : KauBaseActivity() {
private val configs = Configs()
- protected val toolbar: Toolbar get() = kau_toolbar
- protected val recycler: RecyclerView get() = kau_recycler
+
+ private lateinit var binding: KauElasticRecyclerActivityBinding
+
+ protected val toolbar: Toolbar get() = binding.kauToolbar
+ protected val recycler: RecyclerView get() = binding.kauRecycler
class Configs {
var exitTransitionBottom = R.transition.kau_exit_slide_bottom
@@ -51,17 +54,22 @@ abstract class ElasticRecyclerActivity : KauBaseActivity() {
final override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
- setContentView(R.layout.kau_elastic_recycler_activity)
- setSupportActionBar(kau_toolbar)
+ binding = KauElasticRecyclerActivityBinding.inflate(layoutInflater)
+ setContentView(binding.root)
+ setSupportActionBar(binding.kauToolbar)
if (!onCreate(savedInstanceState, configs)) {
return
}
- kau_draggable.addListener(object : ElasticDragDismissFrameLayout.SystemChromeFader(this) {
+ binding.init()
+ }
+
+ private fun KauElasticRecyclerActivityBinding.init() {
+ kauDraggable.addListener(object : ElasticDragDismissFrameLayout.SystemChromeFader(this@ElasticRecyclerActivity) {
override fun onDragDismissed() {
window.returnTransition = TransitionInflater.from(this@ElasticRecyclerActivity)
- .inflateTransition(if (kau_draggable.translationY > 0) configs.exitTransitionBottom else configs.exitTransitionTop)
- kau_recycler.stopScroll()
+ .inflateTransition(if (kauDraggable.translationY > 0) configs.exitTransitionBottom else configs.exitTransitionTop)
+ kauRecycler.stopScroll()
finishAfterTransition()
}
})
@@ -79,6 +87,6 @@ abstract class ElasticRecyclerActivity : KauBaseActivity() {
* Receive actions when the a click event is received outside of the coordinator
*/
fun setOutsideTapListener(listener: () -> Unit) {
- kau_draggable.setOnClickListener { listener() }
+ binding.kauDraggable.setOnClickListener { listener() }
}
}
diff --git a/core-ui/src/main/res-public/values/public.xml b/core-ui/src/main/res-public/values/public.xml
index c8c2e56..1e1a9df 100644
--- a/core-ui/src/main/res-public/values/public.xml
+++ b/core-ui/src/main/res-public/values/public.xml
@@ -1,7 +1,7 @@
<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' />
+ <public name='kau_recycler_detached_background' type='layout' />
<public name='kau_recycler_textslider' type='layout' />
<public name='Kau.Translucent' type='style' />
<public name='Kau.Translucent.NoAnimation' type='style' />
diff --git a/core/src/androidTest/kotlin/ca/allanwang/kau/Utils.kt b/core/src/androidTest/kotlin/ca/allanwang/kau/Utils.kt
new file mode 100644
index 0000000..c9d4e31
--- /dev/null
+++ b/core/src/androidTest/kotlin/ca/allanwang/kau/Utils.kt
@@ -0,0 +1,22 @@
+/*
+ * Copyright 2020 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
+
+import android.content.Context
+import androidx.test.platform.app.InstrumentationRegistry
+
+val context: Context
+ get() = InstrumentationRegistry.getInstrumentation().context
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 04c6444..70558df 100644
--- a/core/src/androidTest/kotlin/ca/allanwang/kau/kpref/KPrefTest.kt
+++ b/core/src/androidTest/kotlin/ca/allanwang/kau/kpref/KPrefTest.kt
@@ -16,10 +16,10 @@
package ca.allanwang.kau.kpref
import android.annotation.SuppressLint
-import android.content.Context
-import androidx.test.core.app.ApplicationProvider
+import android.content.SharedPreferences
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.MediumTest
+import ca.allanwang.kau.context
import kotlin.test.assertEquals
import org.junit.Before
import org.junit.Test
@@ -33,13 +33,11 @@ import org.junit.runner.RunWith
class KPrefTest {
lateinit var androidPref: TestPref
+ lateinit var androidSp: SharedPreferences
lateinit var memPref: TestPref
- class TestPref(builder: KPrefBuilder) : KPref(builder) {
-
- init {
- initialize(ApplicationProvider.getApplicationContext<Context>(), "kpref_test_${System.currentTimeMillis()}")
- }
+ class TestPref(factory: KPrefFactory) :
+ KPref("kpref_test_${System.currentTimeMillis()}", factory) {
var postSetterCount: Int = 0
@@ -60,9 +58,10 @@ class KPrefTest {
@Before
fun init() {
- androidPref = TestPref(KPrefBuilderAndroid)
- androidPref.sp.edit().clear().commit()
- memPref = TestPref(KPrefBuilderInMemory)
+ androidPref = TestPref(KPrefFactoryAndroid(context))
+ androidSp = (androidPref.builder as KPrefBuilderAndroid).sp
+ androidSp.edit().clear().commit()
+ memPref = TestPref(KPrefFactoryInMemory)
}
private fun pref(action: TestPref.() -> Unit) {
@@ -70,7 +69,11 @@ class KPrefTest {
memPref.action()
}
- private fun <T> assertPrefEquals(expected: T, actual: TestPref.() -> T, message: String? = null) {
+ private fun <T> assertPrefEquals(
+ expected: T,
+ actual: TestPref.() -> T,
+ message: String? = null
+ ) {
assertEquals(expected, androidPref.actual(), "Android KPrefs: $message")
assertEquals(expected, memPref.actual(), "In Mem KPrefs: $message")
}
@@ -83,7 +86,7 @@ class KPrefTest {
assertPrefEquals("hello", { hello })
assertPrefEquals(3, { set.size })
assertPrefEquals(setOf("po", "ta", "to"), { set })
- assertEquals(0, androidPref.sp.all.size, "Defaults should not be set automatically")
+ assertEquals(0, androidSp.all.size, "Defaults should not be set automatically")
}
@Test
@@ -93,8 +96,8 @@ class KPrefTest {
assertPrefEquals(2, { one })
pref { hello = "goodbye" }
assertPrefEquals("goodbye", { hello })
- assertEquals(androidPref.hello, androidPref.sp.getString("hello", "badfallback"))
- assertEquals(2, androidPref.sp.all.size)
+ assertEquals(androidPref.hello, androidSp.getString("hello", "badfallback"))
+ assertEquals(2, androidSp.all.size)
}
@SuppressLint("CommitPrefEdits")
@@ -104,9 +107,10 @@ class KPrefTest {
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
- assertPrefEquals(2, { one }, "Kpref did not properly fetch from shared prefs")
+ assertEquals(1, memPref.one, "Memory Kpref did not invalidate value")
+ assertEquals(2, androidPref.one, "Android Kpref did not properly fetch from shared prefs")
// Android pref only
- androidPref.sp.edit().putInt("one", -1).commit()
+ androidSp.edit().putInt("one", -1).commit()
assertEquals(2, androidPref.one, "Lazy kpref should still retain old value")
androidPref.reset()
assertEquals(-1, androidPref.one, "Kpref did not refetch from shared prefs upon reset")
diff --git a/core/src/main/kotlin/ca/allanwang/kau/kpref/KPref.kt b/core/src/main/kotlin/ca/allanwang/kau/kpref/KPref.kt
index fc7a76a..7f75370 100644
--- a/core/src/main/kotlin/ca/allanwang/kau/kpref/KPref.kt
+++ b/core/src/main/kotlin/ca/allanwang/kau/kpref/KPref.kt
@@ -15,10 +15,7 @@
*/
package ca.allanwang.kau.kpref
-import android.content.Context
-import android.content.SharedPreferences
import ca.allanwang.kau.kotlin.ILazyResettable
-import ca.allanwang.kau.logging.KL
/**
* Created by Allan Wang on 2017-06-07.
@@ -32,38 +29,36 @@ import ca.allanwang.kau.logging.KL
* Furthermore, all kprefs are held in the [prefMap],
* so if you wish to reset a preference, you must also invalidate the kpref
* from that map
- *
- * You may optionally override [deleteKeys]. This will be called on initialization
- * And delete all keys returned from that method
*/
-open class KPref(builder: KPrefBuilder = KPrefBuilderAndroid) : KPrefBuilder by builder {
-
- lateinit var PREFERENCE_NAME: String
- lateinit var sp: SharedPreferences
+open class KPref private constructor(
+ val preferenceName: String,
+ val builder: KPrefBuilder
+) : KPrefBuilder by builder {
- fun initialize(
- c: Context,
- preferenceName: String,
- sharedPrefs: SharedPreferences = c.applicationContext.getSharedPreferences(preferenceName, Context.MODE_PRIVATE)
- ) {
- PREFERENCE_NAME = preferenceName
- sp = sharedPrefs
- KL.d { "Shared Preference $preferenceName has been initialized" }
- val toDelete = deleteKeys()
- if (toDelete.isNotEmpty()) {
- val edit = sp.edit()
- toDelete.forEach { edit.remove(it) }
- edit.apply()
- }
- }
+ constructor(preferenceName: String, factory: KPrefFactory) : this(
+ preferenceName,
+ factory.createBuilder(preferenceName)
+ )
internal val prefMap: MutableMap<String, ILazyResettable<*>> = mutableMapOf()
+ fun add(entry: KPrefDelegate<*>) {
+ if (prefMap.containsKey(entry.key))
+ throw KPrefException("${entry.key} is already used elsewhere in preference $preferenceName")
+ prefMap[entry.key] = entry
+ }
+
fun reset() {
prefMap.values.forEach { it.invalidate() }
}
operator fun get(key: String): ILazyResettable<*>? = prefMap[key]
- open fun deleteKeys(): Array<String> = arrayOf()
+ /**
+ * Exposed key deletion function from builder.
+ * To avoid recursion, this type uses vararg
+ */
+ fun deleteKeys(vararg keys: String) {
+ deleteKeys(keys)
+ }
}
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 8f6d0c5..7a35ac2 100644
--- a/core/src/main/kotlin/ca/allanwang/kau/kpref/KPrefBuilder.kt
+++ b/core/src/main/kotlin/ca/allanwang/kau/kpref/KPrefBuilder.kt
@@ -15,22 +15,44 @@
*/
package ca.allanwang.kau.kpref
+import android.content.SharedPreferences
+
interface KPrefBuilder {
- fun KPref.kpref(key: String, fallback: Boolean, postSetter: (value: Boolean) -> Unit = {}): KPrefDelegate<Boolean>
+ fun KPref.kpref(
+ key: String,
+ fallback: Boolean,
+ postSetter: (value: Boolean) -> Unit = {}
+ ): KPrefDelegate<Boolean>
- fun KPref.kpref(key: String, fallback: Float, postSetter: (value: Float) -> Unit = {}): KPrefDelegate<Float>
+ fun KPref.kpref(
+ key: String,
+ fallback: Float,
+ postSetter: (value: Float) -> Unit = {}
+ ): KPrefDelegate<Float>
@Deprecated(
"Double is not supported in SharedPreferences; cast to float yourself",
ReplaceWith("kpref(key, fallback.toFloat(), postSetter)"),
DeprecationLevel.WARNING
)
- fun KPref.kpref(key: String, fallback: Double, postSetter: (value: Float) -> Unit = {}): KPrefDelegate<Float> =
+ fun KPref.kpref(
+ key: String,
+ fallback: Double,
+ postSetter: (value: Float) -> Unit = {}
+ ): KPrefDelegate<Float> =
kpref(key, fallback.toFloat(), postSetter)
- fun KPref.kpref(key: String, fallback: Int, postSetter: (value: Int) -> Unit = {}): KPrefDelegate<Int>
+ fun KPref.kpref(
+ key: String,
+ fallback: Int,
+ postSetter: (value: Int) -> Unit = {}
+ ): KPrefDelegate<Int>
- fun KPref.kpref(key: String, fallback: Long, postSetter: (value: Long) -> Unit = {}): KPrefDelegate<Long>
+ fun KPref.kpref(
+ key: String,
+ fallback: Long,
+ postSetter: (value: Long) -> Unit = {}
+ ): KPrefDelegate<Long>
fun KPref.kpref(
key: String,
@@ -38,32 +60,97 @@ interface KPrefBuilder {
postSetter: (value: Set<String>) -> Unit = {}
): KPrefDelegate<Set<String>>
- fun KPref.kpref(key: String, fallback: String, postSetter: (value: String) -> Unit = {}): KPrefDelegate<String>
+ fun KPref.kpref(
+ key: String,
+ fallback: String,
+ postSetter: (value: String) -> Unit = {}
+ ): KPrefDelegate<String>
fun KPref.kprefSingle(key: String): KPrefSingleDelegate
+
+ /**
+ * Remove keys from pref so they revert to the default
+ */
+ fun KPref.deleteKeys(keys: Array<out String>)
}
-object KPrefBuilderAndroid : KPrefBuilder {
+class KPrefBuilderAndroid(val sp: SharedPreferences) : KPrefBuilder {
override fun KPref.kpref(key: String, fallback: Boolean, postSetter: (value: Boolean) -> Unit) =
- KPrefDelegateAndroid(key, fallback, this, KPrefBooleanTransaction, postSetter)
+ KPrefDelegateAndroid(
+ key,
+ fallback,
+ this,
+ this@KPrefBuilderAndroid,
+ KPrefBooleanTransaction,
+ postSetter
+ )
override fun KPref.kpref(key: String, fallback: Float, postSetter: (value: Float) -> Unit) =
- KPrefDelegateAndroid(key, fallback, this, KPrefFloatTransaction, postSetter)
+ KPrefDelegateAndroid(
+ key,
+ fallback,
+ this,
+ this@KPrefBuilderAndroid,
+ KPrefFloatTransaction,
+ postSetter
+ )
override fun KPref.kpref(key: String, fallback: Int, postSetter: (value: Int) -> Unit) =
- KPrefDelegateAndroid(key, fallback, this, KPrefIntTransaction, postSetter)
+ KPrefDelegateAndroid(
+ key,
+ fallback,
+ this,
+ this@KPrefBuilderAndroid,
+ KPrefIntTransaction,
+ postSetter
+ )
override fun KPref.kpref(key: String, fallback: Long, postSetter: (value: Long) -> Unit) =
- KPrefDelegateAndroid(key, fallback, this, KPrefLongTransaction, postSetter)
-
- override fun KPref.kpref(key: String, fallback: Set<String>, postSetter: (value: Set<String>) -> Unit) =
- KPrefDelegateAndroid(key, fallback, this, KPrefSetTransaction, postSetter)
+ KPrefDelegateAndroid(
+ key,
+ fallback,
+ this,
+ this@KPrefBuilderAndroid,
+ KPrefLongTransaction,
+ postSetter
+ )
+
+ override fun KPref.kpref(
+ key: String,
+ fallback: Set<String>,
+ postSetter: (value: Set<String>) -> Unit
+ ) =
+ KPrefDelegateAndroid(
+ key,
+ fallback,
+ this,
+ this@KPrefBuilderAndroid,
+ KPrefSetTransaction,
+ postSetter
+ )
override fun KPref.kpref(key: String, fallback: String, postSetter: (value: String) -> Unit) =
- KPrefDelegateAndroid(key, fallback, this, KPrefStringTransaction, postSetter)
-
- override fun KPref.kprefSingle(key: String) = KPrefSingleDelegateAndroid(key, this)
+ KPrefDelegateAndroid(
+ key,
+ fallback,
+ this,
+ this@KPrefBuilderAndroid,
+ KPrefStringTransaction,
+ postSetter
+ )
+
+ override fun KPref.kprefSingle(key: String) =
+ KPrefSingleDelegateAndroid(key, this, this@KPrefBuilderAndroid)
+
+ override fun KPref.deleteKeys(keys: Array<out String>) {
+ // Remove pref listing
+ sp.edit().apply {
+ keys.forEach { remove(it) }
+ }.apply()
+ // Clear cached values
+ keys.forEach { prefMap[it]?.invalidate() }
+ }
}
object KPrefBuilderInMemory : KPrefBuilder {
@@ -80,11 +167,20 @@ object KPrefBuilderInMemory : KPrefBuilder {
override fun KPref.kpref(key: String, fallback: Long, postSetter: (value: Long) -> Unit) =
KPrefDelegateInMemory(key, fallback, this, postSetter)
- override fun KPref.kpref(key: String, fallback: Set<String>, postSetter: (value: Set<String>) -> Unit) =
+ override fun KPref.kpref(
+ key: String,
+ fallback: Set<String>,
+ postSetter: (value: Set<String>) -> Unit
+ ) =
KPrefDelegateInMemory(key, fallback, this, postSetter)
override fun KPref.kpref(key: String, fallback: String, postSetter: (value: String) -> Unit) =
KPrefDelegateInMemory(key, fallback, this, postSetter)
override fun KPref.kprefSingle(key: String) = KPrefSingleDelegateInMemory(key, this)
+
+ override fun KPref.deleteKeys(keys: Array<out String>) {
+ // Clear cached values
+ keys.forEach { prefMap[it]?.invalidate() }
+ }
}
diff --git a/core/src/main/kotlin/ca/allanwang/kau/kpref/KPrefDelegate.kt b/core/src/main/kotlin/ca/allanwang/kau/kpref/KPrefDelegate.kt
index 684b139..217bc6e 100644
--- a/core/src/main/kotlin/ca/allanwang/kau/kpref/KPrefDelegate.kt
+++ b/core/src/main/kotlin/ca/allanwang/kau/kpref/KPrefDelegate.kt
@@ -15,6 +15,7 @@
*/
package ca.allanwang.kau.kpref
+import android.content.SharedPreferences
import ca.allanwang.kau.kotlin.ILazyResettable
/**
@@ -26,29 +27,31 @@ import ca.allanwang.kau.kotlin.ILazyResettable
*/
interface KPrefDelegate<T> : ILazyResettable<T> {
+ val key: String
operator fun setValue(any: Any, property: kotlin.reflect.KProperty<*>, t: T)
}
class KPrefException(message: String) : IllegalAccessException(message)
class KPrefDelegateAndroid<T> internal constructor(
- private val key: String,
+ override val key: String,
private val fallback: T,
private val pref: KPref,
+ private val prefBuilder: KPrefBuilderAndroid,
private val transaction: KPrefTransaction<T>,
private var postSetter: (value: T) -> Unit = {}
) : KPrefDelegate<T> {
private object UNINITIALIZED
+ private val sp: SharedPreferences get() = prefBuilder.sp
+
@Volatile
private var _value: Any? = UNINITIALIZED
private val lock = this
init {
- if (pref.prefMap.containsKey(key))
- throw KPrefException("$key is already used elsewhere in preference ${pref.PREFERENCE_NAME}")
- pref.prefMap[key] = this@KPrefDelegateAndroid
+ pref.add(this)
}
override fun invalidate() {
@@ -67,7 +70,7 @@ class KPrefDelegateAndroid<T> internal constructor(
if (_v2 !== UNINITIALIZED) {
_v2 as T
} else {
- _value = transaction.get(pref.sp, key, fallback)
+ _value = transaction.get(sp, key, fallback)
_value as T
}
}
@@ -75,11 +78,12 @@ class KPrefDelegateAndroid<T> internal constructor(
override fun isInitialized(): Boolean = _value !== UNINITIALIZED
- override fun toString(): String = if (isInitialized()) value.toString() else "Lazy kPref $key not initialized yet."
+ override fun toString(): String =
+ if (isInitialized()) value.toString() else "Lazy kPref $key not initialized yet."
override operator fun setValue(any: Any, property: kotlin.reflect.KProperty<*>, t: T) {
_value = t
- val editor = pref.sp.edit()
+ val editor = sp.edit()
transaction.set(editor, key, t)
editor.apply()
postSetter(t)
@@ -87,7 +91,7 @@ class KPrefDelegateAndroid<T> internal constructor(
}
class KPrefDelegateInMemory<T> internal constructor(
- private val key: String,
+ override val key: String,
private val fallback: T,
private val pref: KPref,
private var postSetter: (value: T) -> Unit = {}
@@ -100,13 +104,11 @@ class KPrefDelegateInMemory<T> internal constructor(
private val lock = this
init {
- if (pref.prefMap.containsKey(key))
- throw KPrefException("$key is already used elsewhere in preference ${pref.PREFERENCE_NAME}")
- pref.prefMap[key] = this
+ pref.add(this)
}
override fun invalidate() {
- // No op
+ _value = UNINITIALIZED
}
@Suppress("UNCHECKED_CAST")
@@ -129,7 +131,8 @@ class KPrefDelegateInMemory<T> internal constructor(
override fun isInitialized(): Boolean = _value !== UNINITIALIZED
- override fun toString(): String = if (isInitialized()) value.toString() else "Lazy kPref $key not initialized yet."
+ override fun toString(): String =
+ if (isInitialized()) value.toString() else "Lazy kPref $key not initialized yet."
override operator fun setValue(any: Any, property: kotlin.reflect.KProperty<*>, t: T) {
_value = t
diff --git a/core/src/main/kotlin/ca/allanwang/kau/kpref/KPrefFactory.kt b/core/src/main/kotlin/ca/allanwang/kau/kpref/KPrefFactory.kt
new file mode 100644
index 0000000..dd6da29
--- /dev/null
+++ b/core/src/main/kotlin/ca/allanwang/kau/kpref/KPrefFactory.kt
@@ -0,0 +1,37 @@
+/*
+ * Copyright 2020 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
+
+import android.content.Context
+
+interface KPrefFactory {
+ fun createBuilder(preferenceName: String): KPrefBuilder
+}
+
+/**
+ * Default factory for Android preferences
+ */
+class KPrefFactoryAndroid(context: Context) : KPrefFactory {
+
+ val context: Context = context.applicationContext
+
+ override fun createBuilder(preferenceName: String): KPrefBuilder =
+ KPrefBuilderAndroid(context.getSharedPreferences(preferenceName, Context.MODE_PRIVATE))
+}
+
+object KPrefFactoryInMemory : KPrefFactory {
+ override fun createBuilder(preferenceName: String): KPrefBuilder = KPrefBuilderInMemory
+}
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 ae1f855..9d03a16 100644
--- a/core/src/main/kotlin/ca/allanwang/kau/kpref/KPrefSingleDelegate.kt
+++ b/core/src/main/kotlin/ca/allanwang/kau/kpref/KPrefSingleDelegate.kt
@@ -15,6 +15,7 @@
*/
package ca.allanwang.kau.kpref
+import android.content.SharedPreferences
import ca.allanwang.kau.kotlin.ILazyResettable
/**
@@ -29,16 +30,19 @@ interface KPrefSingleDelegate : ILazyResettable<Boolean>
class KPrefSingleDelegateAndroid internal constructor(
private val key: String,
- private val pref: KPref
+ private val pref: KPref,
+ private val prefBuilder: KPrefBuilderAndroid
) : KPrefSingleDelegate {
@Volatile
private var _value: Boolean? = null
private val lock = this
+ private val sp: SharedPreferences get() = prefBuilder.sp
+
init {
if (pref.prefMap.containsKey(key))
- throw KPrefException("$key is already used elsewhere in preference ${pref.PREFERENCE_NAME}")
+ throw KPrefException("$key is already used elsewhere in preference ${pref.preferenceName}")
pref.prefMap[key] = this
}
@@ -57,9 +61,9 @@ class KPrefSingleDelegateAndroid internal constructor(
if (_v2 != null) {
_v2
} else {
- _value = pref.sp.getBoolean(key, true)
+ _value = sp.getBoolean(key, true)
if (_value!!) {
- pref.sp.edit().putBoolean(key, false).apply()
+ sp.edit().putBoolean(key, false).apply()
_value = false
true
} else false
@@ -82,7 +86,7 @@ class KPrefSingleDelegateInMemory internal constructor(
init {
if (pref.prefMap.containsKey(key))
- throw KPrefException("$key is already used elsewhere in preference ${pref.PREFERENCE_NAME}")
+ throw KPrefException("$key is already used elsewhere in preference ${pref.preferenceName}")
pref.prefMap[key] = this
}
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 9410c4c..a9a97b7 100644
--- a/core/src/main/kotlin/ca/allanwang/kau/logging/KauLogger.kt
+++ b/core/src/main/kotlin/ca/allanwang/kau/logging/KauLogger.kt
@@ -47,7 +47,7 @@ open class KauLogger(
/**
* Toggle to dictate whether a message should be logged
*/
- var shouldLog: (priority: Int) -> Boolean = { true }
+ var shouldLog: (priority: Int) -> Boolean = { it >= Log.INFO }
) {
inline fun v(message: () -> Any?) = log(Log.VERBOSE, message)
diff --git a/core/src/main/res-public/values/public.xml b/core/src/main/res-public/values/public.xml
index 9f8780e..de08b64 100644
--- a/core/src/main/res-public/values/public.xml
+++ b/core/src/main/res-public/values/public.xml
@@ -1,19 +1,27 @@
<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' />
- <public name='kau_slide_out_right' type='anim' />
- <public name='kau_slide_out_right_top' type='anim' />
<public name='kau_fade_in' type='anim' />
- <public name='kau_slide_out_top' type='anim' />
- <public name='kau_slide_out_bottom' type='anim' />
<public name='kau_fade_out' type='anim' />
- <public name='kau_slide_out_left' type='anim' />
- <public name='kau_slide_out_left_top' type='anim' />
<public name='kau_slide_in_bottom' type='anim' />
+ <public name='kau_slide_in_left' type='anim' />
<public name='kau_slide_in_right' type='anim' />
- <public name='kau_transparent' type='drawable' />
+ <public name='kau_slide_in_top' type='anim' />
+ <public name='kau_slide_out_bottom' type='anim' />
+ <public name='kau_slide_out_left' type='anim' />
+ <public name='kau_slide_out_left_top' type='anim' />
+ <public name='kau_slide_out_right' type='anim' />
+ <public name='kau_slide_out_right_top' type='anim' />
+ <public name='kau_slide_out_top' type='anim' />
<public name='kau_selectable_white' type='drawable' />
+ <public name='kau_transparent' type='drawable' />
+ <public name='kau_enter_slide_bottom' type='transition' />
+ <public name='kau_enter_slide_left' type='transition' />
+ <public name='kau_enter_slide_right' type='transition' />
+ <public name='kau_enter_slide_top' type='transition' />
+ <public name='kau_exit_slide_bottom' type='transition' />
+ <public name='kau_exit_slide_left' type='transition' />
+ <public name='kau_exit_slide_right' type='transition' />
+ <public name='kau_exit_slide_top' type='transition' />
<public name='kau_shadow_overlay' type='color' />
<public name='kau_activity_horizontal_margin' type='dimen' />
<public name='kau_activity_vertical_margin' type='dimen' />
@@ -106,12 +114,4 @@
<public name='KauSlideInFadeOut' type='style' />
<public name='KauSlideInSlideOutRight' type='style' />
<public name='KauSlideInSlideOutBottom' type='style' />
- <public name='kau_enter_slide_bottom' type='transition' />
- <public name='kau_enter_slide_top' type='transition' />
- <public name='kau_exit_slide_bottom' type='transition' />
- <public name='kau_exit_slide_top' type='transition' />
- <public name='kau_enter_slide_right' type='transition' />
- <public name='kau_exit_slide_right' type='transition' />
- <public name='kau_exit_slide_left' type='transition' />
- <public name='kau_enter_slide_left' type='transition' />
</resources> \ No newline at end of file
diff --git a/core/src/test/kotlin/ca/allanwang/kau/kotlin/DebounceTest.kt b/core/src/test/kotlin/ca/allanwang/kau/kotlin/DebounceTest.kt
index a95c442..530f766 100644
--- a/core/src/test/kotlin/ca/allanwang/kau/kotlin/DebounceTest.kt
+++ b/core/src/test/kotlin/ca/allanwang/kau/kotlin/DebounceTest.kt
@@ -16,6 +16,7 @@
package ca.allanwang.kau.kotlin
import kotlin.test.assertEquals
+import org.junit.Ignore
import org.junit.Test
/**
@@ -47,6 +48,7 @@ class DebounceTest {
}
@Test
+ @Ignore("Pending fix")
fun multipleDebounces() {
var i = 0
val debounce = debounce<Int>(20) { i += it }
diff --git a/docs/Changelog.md b/docs/Changelog.md
index feb5e4a..8320c7e 100644
--- a/docs/Changelog.md
+++ b/docs/Changelog.md
@@ -1,7 +1,28 @@
# Changelog
-## v5.2.1
+## v6.3.0
+* Add support for Arctic Fox 2020.3.1
+* Move to new maven release system
+* Many version bumps
+
+## v6.2.0
+* Add support for Android Studio 4.2
+* Remove all usages of kotlin synthetics
+* Many version bumps
+* Added Hilt dep
+
+## v6.1.0
+* Add support for Android 4.1 RC03
+* Breaking: Updated iconics, buganizer, and spotless dependencies (major version bump)
+
+## v6.0.0
+* Add support for Android 4.1.x
+* Add major version library updates (FastAdapter, AboutLibrary, Iconics)
+
+## v5.3.0
+* :about: Moved config builder inside activity
* :color: Allow option to disable selected ring
+* :core: Breaking KPref changes; see migration
## v5.2.0
* :about: Migrate about libraries to v7.x.x
diff --git a/docs/Migration.md b/docs/Migration.md
index fb29f7b..7d50456 100644
--- a/docs/Migration.md
+++ b/docs/Migration.md
@@ -2,6 +2,27 @@
Below are some highlights on major refactoring/breaking changes
+# v5.2.0
+
+## KPref
+
+In an effort to improve testing options, KPref has some updates to allow for in memory preferences during unit tests.
+While you can still use KPref like before as an object (provide the `KPrefFactoryAndroid` factory),
+it is recommended that you use some sort of dependency injection/service locator to provide the factory.
+An example can be found in the sample app test class.
+
+Also note that to better support in memory preferences, `reset()` will clear the in memory content for both variants,
+meaning that in memory preferences will reset to default. Previously, in memory `reset()` did nothing.
+
+## AboutActivityBase
+
+`configBuilder` was previously required in the constructor, but is now an open function so that activity fields can be used in the builder.
+
+## Gradle
+
+* Due to Spotless updates, gradle should not include the `clean` task ([#521](https://github.com/diffplug/spotless/issues/521)).
+* `buildToolsVersion` is already included in Android Studio, so you no longer need to specify the link with KAU.
+
# v5.1.0
## KPref
diff --git a/fastadapter-viewbinding/build.gradle b/fastadapter-viewbinding/build.gradle
index a786edb..6649397 100644
--- a/fastadapter-viewbinding/build.gradle
+++ b/fastadapter-viewbinding/build.gradle
@@ -5,12 +5,6 @@ ext.kauSubModuleMinSdk = Versions.coreMinSdk
apply from: '../android-lib.gradle'
-android {
- viewBinding {
- enabled = true
- }
-}
-
dependencies {
implementation project(':core')
diff --git a/fastadapter-viewbinding/src/main/kotlin/ca/allanwang/fastadapter/viewbinding/BindingItem.kt b/fastadapter-viewbinding/src/main/kotlin/ca/allanwang/fastadapter/viewbinding/BindingItem.kt
index 96055e4..ff694f0 100644
--- a/fastadapter-viewbinding/src/main/kotlin/ca/allanwang/fastadapter/viewbinding/BindingItem.kt
+++ b/fastadapter-viewbinding/src/main/kotlin/ca/allanwang/fastadapter/viewbinding/BindingItem.kt
@@ -56,13 +56,13 @@ abstract class BindingItem<Binding : ViewBinding>(open val data: Any?) :
return binding.root
}
- final override fun bindView(holder: ViewHolder, payloads: MutableList<Any>) {
+ final override fun bindView(holder: ViewHolder, payloads: List<Any>) {
super.bindView(holder, payloads)
val binding = holder.getBinding<Binding>()
binding.bindView(holder, payloads)
}
- abstract fun Binding.bindView(holder: ViewHolder, payloads: MutableList<Any>)
+ abstract fun Binding.bindView(holder: ViewHolder, payloads: List<Any>)
protected fun unbind(vararg textViews: TextView) {
textViews.forEach { it.text = null }
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 655b355..a9e6bfa 100644
--- a/fastadapter/src/main/kotlin/ca/allanwang/kau/adapters/AdapterUtils.kt
+++ b/fastadapter/src/main/kotlin/ca/allanwang/kau/adapters/AdapterUtils.kt
@@ -27,8 +27,8 @@ import com.mikepenz.fastadapter.select.SelectExtension
/**
* Add kotlin's generic syntax to better support out types
*/
-fun <Item : GenericItem> fastAdapter(vararg adapter: IAdapter<out Item>) =
- FastAdapter.with<Item, IAdapter<out Item>>(adapter.toList())
+fun <Item : GenericItem> fastAdapter(vararg adapter: IAdapter<out Item>): FastAdapter<Item> =
+ FastAdapter.with(adapter.toList())
/**
* Returns selection size, or -1 if selection is disabled
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 1a2e6cb..41663c9 100644
--- a/fastadapter/src/main/kotlin/ca/allanwang/kau/iitems/CardIItem.kt
+++ b/fastadapter/src/main/kotlin/ca/allanwang/kau/iitems/CardIItem.kt
@@ -89,7 +89,7 @@ class CardIItem(
var imageRes: Int = INVALID_ID
}
- override fun bindView(holder: ViewHolder, payloads: MutableList<Any>) {
+ override fun bindView(holder: ViewHolder, payloads: List<Any>) {
super.bindView(holder, payloads)
with(holder.itemView.context) context@{
with(configs) {
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 551cb59..15ceb31 100644
--- a/fastadapter/src/main/kotlin/ca/allanwang/kau/iitems/HeaderIItem.kt
+++ b/fastadapter/src/main/kotlin/ca/allanwang/kau/iitems/HeaderIItem.kt
@@ -40,7 +40,7 @@ class HeaderIItem(
var text: String = text ?: "Header Placeholder"
- override fun bindView(holder: ViewHolder, payloads: MutableList<Any>) {
+ override fun bindView(holder: ViewHolder, payloads: List<Any>) {
super.bindView(holder, payloads)
holder.text.text = holder.itemView.context.string(textRes, text)
bindTextColor(holder.text)
diff --git a/files/translation_migration.sh b/files/translation_migration.sh
index d1372d1..aabd2f8 100755
--- a/files/translation_migration.sh
+++ b/files/translation_migration.sh
@@ -15,4 +15,4 @@ else
find . -type d -empty -delete
fi
-echo "Finished cleanieckng files" \ No newline at end of file
+echo "Finished cleaning files" \ No newline at end of file
diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar
index 5c2d1cf..62d4c05 100644
--- a/gradle/wrapper/gradle-wrapper.jar
+++ b/gradle/wrapper/gradle-wrapper.jar
Binary files differ
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
index 1ba7206..1acc777 100644
--- a/gradle/wrapper/gradle-wrapper.properties
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-6.0.1-all.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-7.1-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
diff --git a/gradlew b/gradlew
index 83f2acf..fbd7c51 100755
--- a/gradlew
+++ b/gradlew
@@ -82,6 +82,7 @@ esac
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
+
# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
@@ -129,6 +130,7 @@ fi
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
+
JAVACMD=`cygpath --unix "$JAVACMD"`
# We build the pattern for arguments to be converted via cygpath
@@ -154,19 +156,19 @@ if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
else
eval `echo args$i`="\"$arg\""
fi
- i=$((i+1))
+ i=`expr $i + 1`
done
case $i in
- (0) set -- ;;
- (1) set -- "$args0" ;;
- (2) set -- "$args0" "$args1" ;;
- (3) set -- "$args0" "$args1" "$args2" ;;
- (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
- (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
- (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
- (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
- (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
- (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
+ 0) set -- ;;
+ 1) set -- "$args0" ;;
+ 2) set -- "$args0" "$args1" ;;
+ 3) set -- "$args0" "$args1" "$args2" ;;
+ 4) set -- "$args0" "$args1" "$args2" "$args3" ;;
+ 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
+ 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
+ 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
+ 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
+ 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
esac
fi
@@ -175,14 +177,9 @@ save () {
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
echo " "
}
-APP_ARGS=$(save "$@")
+APP_ARGS=`save "$@"`
# Collect all arguments for the java command, following the shell quoting and substitution rules
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
-# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
-if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
- cd "$(dirname "$0")"
-fi
-
exec "$JAVACMD" "$@"
diff --git a/gradlew.bat b/gradlew.bat
index 9618d8d..5093609 100644
--- a/gradlew.bat
+++ b/gradlew.bat
@@ -29,6 +29,9 @@ if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
+@rem Resolve any "." and ".." in APP_HOME to make it shorter.
+for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
+
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
@@ -81,6 +84,7 @@ set CMD_LINE_ARGS=%*
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
+
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
diff --git a/kpref-activity/build.gradle b/kpref-activity/build.gradle
index 7df08d3..4dfaebf 100644
--- a/kpref-activity/build.gradle
+++ b/kpref-activity/build.gradle
@@ -10,6 +10,8 @@ dependencies {
implementation project(':core')
implementation project(':colorpicker')
implementation project(':fastadapter')
+
+ implementation kau.Dependencies.materialDialog("color")
}
apply from: '../artifacts.gradle'
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 818a770..70b40e7 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
@@ -25,18 +25,13 @@ import ca.allanwang.kau.animators.SlideAnimatorAdd
import ca.allanwang.kau.animators.SlideAnimatorRemove
import ca.allanwang.kau.internal.KauBaseActivity
import ca.allanwang.kau.kotlin.lazyUi
+import ca.allanwang.kau.kpref.activity.databinding.KauPrefActivityBinding
import ca.allanwang.kau.kpref.activity.items.KPrefItemCore
import ca.allanwang.kau.ui.views.RippleCanvas
-import ca.allanwang.kau.utils.KAU_LEFT
-import ca.allanwang.kau.utils.KAU_RIGHT
-import ca.allanwang.kau.utils.resolveColor
-import ca.allanwang.kau.utils.setMarginTop
-import ca.allanwang.kau.utils.statusBarColor
-import ca.allanwang.kau.utils.withLinearAdapter
+import ca.allanwang.kau.utils.*
import com.mikepenz.fastadapter.adapters.FastItemAdapter
import com.mikepenz.fastadapter.select.getSelectExtension
-import java.util.Stack
-import kotlinx.android.synthetic.main.kau_pref_activity.*
+import java.util.*
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
@@ -44,11 +39,12 @@ import kotlinx.coroutines.withContext
abstract class KPrefActivity : KauBaseActivity(), KPrefActivityContract {
private val adapter: FastItemAdapter<KPrefItemCore> = FastItemAdapter()
- val bgCanvas: RippleCanvas get() = kau_ripple
- val toolbarCanvas: RippleCanvas get() = kau_toolbar_ripple
- val toolbar: Toolbar get() = kau_toolbar
+ val bgCanvas: RippleCanvas get() = binding.kauRipple
+ val toolbarCanvas: RippleCanvas get() = binding.kauToolbarRipple
+ val toolbar: Toolbar get() = binding.kauToolbar
private lateinit var globalOptions: GlobalOptions
private val kprefStack = Stack<Pair<Int, List<KPrefItemCore>>>()
+
/**
* Toggle sliding animations for the kpref items
*/
@@ -56,14 +52,14 @@ abstract class KPrefActivity : KauBaseActivity(), KPrefActivityContract {
private val recyclerAnimatorNext: KauAnimator by lazyUi {
KauAnimator(
- SlideAnimatorAdd(KAU_RIGHT, itemDelayFactor = 0f),
- SlideAnimatorRemove(KAU_LEFT, itemDelayFactor = 0f)
+ SlideAnimatorAdd(KAU_RIGHT, itemDelayFactor = 0f),
+ SlideAnimatorRemove(KAU_LEFT, itemDelayFactor = 0f)
)
}
private val recyclerAnimatorPrev: KauAnimator by lazyUi {
KauAnimator(
- SlideAnimatorAdd(KAU_LEFT, itemDelayFactor = 0f),
- SlideAnimatorRemove(KAU_RIGHT, itemDelayFactor = 0f)
+ SlideAnimatorAdd(KAU_LEFT, itemDelayFactor = 0f),
+ SlideAnimatorRemove(KAU_RIGHT, itemDelayFactor = 0f)
)
}
@@ -73,11 +69,19 @@ abstract class KPrefActivity : KauBaseActivity(), KPrefActivityContract {
*/
abstract fun kPrefCoreAttributes(): CoreAttributeContract.() -> Unit
+ private lateinit var binding: KauPrefActivityBinding
+
@SuppressLint("NewApi")
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// setup layout
- setContentView(R.layout.kau_pref_activity)
+ binding = KauPrefActivityBinding.inflate(layoutInflater)
+ setContentView(binding.root)
+ binding.init(savedInstanceState)
+ }
+
+ @SuppressLint("NewApi")
+ private fun KauPrefActivityBinding.init(savedInstanceState: Bundle?) {
setSupportActionBar(toolbar)
supportActionBar?.apply {
setDisplayHomeAsUpEnabled(true)
@@ -86,20 +90,20 @@ abstract class KPrefActivity : KauBaseActivity(), KPrefActivityContract {
setDisplayShowTitleEnabled(false)
}
findViewById<View>(android.R.id.content).setOnApplyWindowInsetsListener { _, insets ->
- kau_toolbar.setMarginTop(insets.systemWindowInsetTop)
+ kauToolbar.setMarginTop(insets.systemWindowInsetTop)
insets
}
window.decorView.systemUiVisibility =
- View.SYSTEM_UI_FLAG_LAYOUT_STABLE or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
+ 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))
+ kauToolbarRipple.set(resolveColor(R.attr.colorPrimary))
+ kauRipple.set(resolveColor(android.R.attr.colorBackground))
// setup prefs
val core = CoreAttributeBuilder()
val builder = kPrefCoreAttributes()
core.builder()
- globalOptions = GlobalOptions(core, this)
- kau_recycler.withLinearAdapter(adapter)
+ globalOptions = GlobalOptions(core, this@KPrefActivity)
+ kauRecycler.withLinearAdapter(adapter)
adapter.apply {
getSelectExtension().isSelectable = true
onClickListener = { v, _, item, _ ->
@@ -111,9 +115,9 @@ abstract class KPrefActivity : KauBaseActivity(), KPrefActivityContract {
}
override fun showNextPrefs(@StringRes toolbarTitleRes: Int, builder: KPrefAdapterBuilder.() -> Unit) =
- showNextPrefs(toolbarTitleRes, builder, false)
+ binding.showNextPrefs(toolbarTitleRes, builder, false)
- private fun showNextPrefs(
+ private fun KauPrefActivityBinding.showNextPrefs(
@StringRes toolbarTitleRes: Int,
builder: KPrefAdapterBuilder.() -> Unit,
first: Boolean
@@ -125,7 +129,7 @@ abstract class KPrefActivity : KauBaseActivity(), KPrefActivityContract {
kprefStack.push(toolbarTitleRes to items.list)
items.list
}
- kau_recycler.itemAnimator = if (animate && !first) recyclerAnimatorNext else null
+ kauRecycler.itemAnimator = if (animate && !first) recyclerAnimatorNext else null
show(toolbarTitleRes, items)
}
}
@@ -143,7 +147,7 @@ abstract class KPrefActivity : KauBaseActivity(), KPrefActivityContract {
override fun showPrevPrefs() {
kprefStack.pop()
val (title, list) = kprefStack.peek()
- kau_recycler.itemAnimator = if (animate) recyclerAnimatorPrev else null
+ binding.kauRecycler.itemAnimator = if (animate) recyclerAnimatorPrev else null
show(title, list)
}
@@ -160,7 +164,7 @@ abstract class KPrefActivity : KauBaseActivity(), KPrefActivityContract {
fun reloadList() {
// If for some reason we are calling a reload before fetching our first kpref list, we will ignore it
if (kprefStack.size < 1) return
- kau_recycler.itemAnimator = null
+ binding.kauRecycler.itemAnimator = null
val list = kprefStack.peek().second
adapter.setNewList(list.filter { it.core.visible() })
}
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 a867d06..16900c4 100644
--- a/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefCheckbox.kt
+++ b/kpref-activity/src/main/kotlin/ca/allanwang/kau/kpref/activity/items/KPrefCheckbox.kt
@@ -34,7 +34,7 @@ open class KPrefCheckbox(builder: BaseContract<Boolean>) : KPrefItemBase<Boolean
(innerView as AppCompatCheckBox).isChecked = pref
}
- override fun bindView(holder: ViewHolder, payloads: MutableList<Any>) {
+ override fun bindView(holder: ViewHolder, payloads: List<Any>) {
super.bindView(holder, payloads)
val checkbox = holder.bindInnerView<CheckBox>(R.layout.kau_pref_checkbox)
withAccentColor(checkbox::tint)
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 76cfbab..d7023af 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: MutableList<Any>) {
+ override fun bindView(holder: ViewHolder, payloads: List<Any>) {
super.bindView(holder, payloads)
if (builder.showPreview) {
val preview = holder.bindInnerView<CircleView>(R.layout.kau_pref_color)
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 ca70b61..6828053 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
@@ -28,7 +28,7 @@ open class KPrefHeader(builder: CoreContract) : KPrefItemCore(builder) {
override val layoutRes: Int
get() = R.layout.kau_pref_header
- override fun bindView(holder: ViewHolder, payloads: MutableList<Any>) {
+ override fun bindView(holder: ViewHolder, payloads: List<Any>) {
super.bindView(holder, payloads)
withAccentColor(holder.title::setTextColor)
}
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 16363e2..22be523 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
@@ -47,7 +47,7 @@ abstract class KPrefItemBase<T>(protected val base: BaseContract<T>) : KPrefItem
}
@CallSuper
- override fun bindView(holder: ViewHolder, payloads: MutableList<Any>) {
+ override fun bindView(holder: ViewHolder, payloads: List<Any>) {
super.bindView(holder, payloads)
_enabled = base.enabler()
with(holder) {
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 79b7e82..0aaa2d3 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
@@ -70,7 +70,7 @@ abstract class KPrefItemCore(val core: CoreContract) : AbstractItem<KPrefItemCor
*/
@SuppressLint("NewApi")
@CallSuper
- override fun bindView(holder: ViewHolder, payloads: MutableList<Any>) {
+ override fun bindView(holder: ViewHolder, payloads: List<Any>) {
super.bindView(holder, payloads)
with(holder) {
updateTitle()
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 9abdf09..41efa42 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: MutableList<Any>) {
+ override fun bindView(holder: ViewHolder, payloads: List<Any>) {
super.bindView(holder, payloads)
val text = holder.bindInnerView<TextView>(R.layout.kau_pref_seekbar_text)
withTextColor(text::setTextColor)
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 50f0c62..b5a69dd 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: MutableList<Any>) {
+ override fun bindView(holder: ViewHolder, payloads: List<Any>) {
super.bindView(holder, payloads)
val textView = holder.bindInnerView<TextView>(R.layout.kau_pref_text)
withTextColor(textView::setTextColor)
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 e430dff..77ac04c 100644
--- a/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/BlurredImageView.kt
+++ b/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/BlurredImageView.kt
@@ -18,20 +18,19 @@ package ca.allanwang.kau.mediapicker
import android.content.Context
import android.graphics.Color
import android.util.AttributeSet
+import android.view.LayoutInflater
import android.view.View
import android.widget.FrameLayout
import android.widget.ImageView
+import ca.allanwang.kau.mediapicker.databinding.KauBlurredImageviewBinding
import ca.allanwang.kau.ui.views.MeasureSpecContract
import ca.allanwang.kau.ui.views.MeasureSpecDelegate
-import ca.allanwang.kau.utils.inflate
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.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.*
+import jp.wasabeef.blurry.Blurry
/**
* Created by Allan Wang on 2017-07-14.
@@ -51,12 +50,14 @@ class BlurredImageView @JvmOverloads constructor(
var isBlurred = false
private set
- val imageBase: ImageView get() = image_base
+ val imageBase: ImageView get() = binding.imageBase
+
+ private val binding: KauBlurredImageviewBinding =
+ KauBlurredImageviewBinding.inflate(LayoutInflater.from(context), this)
init {
- inflate(R.layout.kau_blurred_imageview, true)
initAttrs(context, attrs)
- image_foreground.setIcon(GoogleMaterial.Icon.gmd_check, 30)
+ binding.imageForeground.setIcon(GoogleMaterial.Icon.gmd_check, 30)
}
override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
@@ -66,9 +67,11 @@ class BlurredImageView @JvmOverloads constructor(
override fun clearAnimation() {
super.clearAnimation()
- imageBase.clearAnimation()
- image_blur.clearAnimation()
- image_foreground.clearAnimation()
+ with(binding) {
+ imageBase.clearAnimation()
+ imageBlur.clearAnimation()
+ imageForeground.clearAnimation()
+ }
}
private fun View.scaleAnimate(scale: Float) =
@@ -84,15 +87,12 @@ class BlurredImageView @JvmOverloads constructor(
fun blur() {
if (isBlurred) return
isBlurred = true
- val factor = BlurFactor()
- factor.width = width
- factor.height = height
- BlurTask(imageBase, factor) {
- image_blur.setImageDrawable(it)
+ with(binding) {
+ Blurry.with(imageBase.context).capture(imageBase).into(imageBlur)
scaleAnimate(ANIMATION_SCALE).start()
- image_blur.alphaAnimate(1f).start()
- image_foreground.alphaAnimate(1f).start()
- }.execute()
+ imageBlur.alphaAnimate(1f).start()
+ imageForeground.alphaAnimate(1f).start()
+ }
}
/**
@@ -103,15 +103,12 @@ class BlurredImageView @JvmOverloads constructor(
fun blurInstantly() {
isBlurred = true
clearAnimation()
- val factor = BlurFactor()
- factor.width = width
- factor.height = height
- BlurTask(imageBase, factor) { drawable ->
- image_blur.setImageDrawable(drawable)
+ with(binding) {
+ Blurry.with(imageBase.context).capture(imageBase).into(imageBlur)
scaleXY = ANIMATION_SCALE
- image_blur.alpha = 1f
- image_foreground.alpha = 1f
- }.execute()
+ imageBlur.alpha = 1f
+ imageForeground.alpha = 1f
+ }
}
/**
@@ -121,8 +118,10 @@ class BlurredImageView @JvmOverloads constructor(
if (!isBlurred) return
isBlurred = false
scaleAnimate(1.0f).start()
- image_blur.alphaAnimate(0f).withEndAction { image_blur.setImageDrawable(null) }.start()
- image_foreground.alphaAnimate(0f).start()
+ with(binding) {
+ imageBlur.alphaAnimate(0f).withEndAction { imageBlur.setImageDrawable(null) }.start()
+ imageForeground.alphaAnimate(0f).start()
+ }
}
/**
@@ -133,9 +132,11 @@ class BlurredImageView @JvmOverloads constructor(
clearAnimation()
scaleX = 1.0f
scaleX = 1.0f
- image_blur.alpha = 0f
- image_blur.setImageDrawable(null)
- image_foreground.alpha = 0f
+ with(binding) {
+ imageBlur.alpha = 0f
+ imageBlur.setImageDrawable(null)
+ imageForeground.alpha = 0f
+ }
}
/**
@@ -163,15 +164,17 @@ class BlurredImageView @JvmOverloads constructor(
*/
fun fullReset() {
reset()
- 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)
+ with(binding) {
+ fullAction { it.visible().background = null }
+ imageForeground.setBackgroundColorRes(R.color.kau_blurred_image_selection_overlay)
+ imageForeground.setIcon(GoogleMaterial.Icon.gmd_check, 30, Color.WHITE)
+ }
}
- private fun fullAction(action: (View) -> Unit) {
- action(this)
+ private fun KauBlurredImageviewBinding.fullAction(action: (View) -> Unit) {
+ action(this@BlurredImageView)
action(imageBase)
- action(image_blur)
- action(image_foreground)
+ action(imageBlur)
+ action(imageForeground)
}
}
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 552bf0f..636dcf0 100644
--- a/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaActionItem.kt
+++ b/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaActionItem.kt
@@ -46,7 +46,7 @@ class MediaActionItem(
get() = false
set(_) {}
- override fun bindView(holder: MediaItemBasic.ViewHolder, payloads: MutableList<Any>) {
+ override fun bindView(holder: MediaItemBasic.ViewHolder, payloads: List<Any>) {
super.bindView(holder, payloads)
holder.image.apply {
setImageDrawable(
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 88a304f..86cb367 100644
--- a/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaItem.kt
+++ b/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaItem.kt
@@ -54,7 +54,7 @@ class MediaItem(val data: MediaModel) :
get() = !failedToLoad
set(_) {}
- override fun bindView(holder: ViewHolder, payloads: MutableList<Any>) {
+ override fun bindView(holder: ViewHolder, payloads: List<Any>) {
super.bindView(holder, payloads)
glide(holder.itemView)
.load(data.data)
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 e801848..6f0d223 100644
--- a/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaItemBasic.kt
+++ b/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaItemBasic.kt
@@ -52,7 +52,7 @@ class MediaItemBasic(val data: MediaModel) :
get() = false
set(_) {}
- override fun bindView(holder: ViewHolder, payloads: MutableList<Any>) {
+ override fun bindView(holder: ViewHolder, payloads: List<Any>) {
super.bindView(holder, payloads)
glide(holder.itemView)
.load(data.data)
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 4c97b07..fe25d97 100644
--- a/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaPickerActivityBase.kt
+++ b/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaPickerActivityBase.kt
@@ -21,6 +21,7 @@ import androidx.loader.content.Loader
import androidx.recyclerview.widget.LinearLayoutManager
import ca.allanwang.kau.adapters.selectedItems
import ca.allanwang.kau.adapters.selectionSize
+import ca.allanwang.kau.mediapicker.databinding.KauActivityImagePickerBinding
import ca.allanwang.kau.utils.hideOnDownwardsScroll
import ca.allanwang.kau.utils.setIcon
import ca.allanwang.kau.utils.toDrawable
@@ -29,7 +30,6 @@ import com.google.android.material.appbar.AppBarLayout
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.*
/**
* Created by Allan Wang on 2017-07-04.
@@ -43,45 +43,50 @@ abstract class MediaPickerActivityBase(
mediaActions: List<MediaAction> = emptyList()
) : MediaPickerCore<MediaItem>(mediaType, mediaActions) {
+ private lateinit var binding: KauActivityImagePickerBinding
+
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
+ binding = KauActivityImagePickerBinding.inflate(layoutInflater)
+ setContentView(binding.root)
+ binding.init()
+ }
- setContentView(R.layout.kau_activity_image_picker)
-
- kau_selection_count.setCompoundDrawables(
- null,
- null,
- GoogleMaterial.Icon.gmd_image.toDrawable(this, 18),
- null
+ private fun KauActivityImagePickerBinding.init() {
+ kauSelectionCount.setCompoundDrawables(
+ null,
+ null,
+ GoogleMaterial.Icon.gmd_image.toDrawable(this@MediaPickerActivityBase, 18),
+ null
)
- setSupportActionBar(kau_toolbar)
+ setSupportActionBar(kauToolbar)
supportActionBar?.apply {
setDisplayHomeAsUpEnabled(true)
setDisplayShowHomeEnabled(true)
setHomeAsUpIndicator(
- GoogleMaterial.Icon.gmd_close.toDrawable(
- this@MediaPickerActivityBase,
- 18
- )
+ GoogleMaterial.Icon.gmd_close.toDrawable(
+ this@MediaPickerActivityBase,
+ 18
+ )
)
}
- kau_toolbar.setNavigationOnClickListener { onBackPressed() }
+ kauToolbar.setNavigationOnClickListener { onBackPressed() }
- initializeRecycler(kau_recyclerview)
+ initializeRecycler(kauRecyclerview)
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()
+ kauSelectionCount.text = adapter.selectionSize.toString()
}
}
}
}
- kau_fab.apply {
+ kauFab.apply {
show()
setIcon(GoogleMaterial.Icon.gmd_send)
setOnClickListener {
@@ -92,7 +97,7 @@ abstract class MediaPickerActivityBase(
finish(ArrayList(selection.map { it.data }))
}
}
- hideOnDownwardsScroll(kau_recyclerview)
+ hideOnDownwardsScroll(kauRecyclerview)
}
loadItems()
@@ -108,11 +113,11 @@ abstract class MediaPickerActivityBase(
* @param scrollable true if scroll flags are enabled, false otherwise
*/
- private fun setToolbarScrollable(scrollable: Boolean) {
- val params = kau_toolbar.layoutParams as AppBarLayout.LayoutParams
+ private fun KauActivityImagePickerBinding.setToolbarScrollable(scrollable: Boolean) {
+ val params = kauToolbar.layoutParams as AppBarLayout.LayoutParams
if (scrollable) {
params.scrollFlags = AppBarLayout.LayoutParams.SCROLL_FLAG_ENTER_ALWAYS or
- AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL
+ AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL
} else {
params.scrollFlags = 0
}
@@ -120,13 +125,13 @@ abstract class MediaPickerActivityBase(
override fun onLoadFinished(loader: Loader<Cursor>, data: Cursor?) {
super.onLoadFinished(loader, data)
- setToolbarScrollable(
- (kau_recyclerview.layoutManager as LinearLayoutManager)
- .findLastCompletelyVisibleItemPosition() < adapter.adapterItemCount - 1
+ binding.setToolbarScrollable(
+ (binding.kauRecyclerview.layoutManager as LinearLayoutManager)
+ .findLastCompletelyVisibleItemPosition() < adapter.adapterItemCount - 1
)
}
override fun onStatusChange(loaded: Boolean) {
- setToolbarScrollable(loaded)
+ binding.setToolbarScrollable(loaded)
}
}
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 df47688..0ecc298 100644
--- a/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaPickerActivityOverlayBase.kt
+++ b/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/MediaPickerActivityOverlayBase.kt
@@ -18,8 +18,8 @@ package ca.allanwang.kau.mediapicker
import android.os.Build
import android.os.Bundle
import androidx.annotation.RequiresApi
+import ca.allanwang.kau.mediapicker.databinding.KauActivityImagePickerOverlayBinding
import ca.allanwang.kau.utils.toast
-import kotlinx.android.synthetic.main.kau_activity_image_picker_overlay.*
/**
* Created by Allan Wang on 2017-07-23.
@@ -35,20 +35,27 @@ abstract class MediaPickerActivityOverlayBase(
mediaActions: List<MediaAction> = emptyList()
) : MediaPickerCore<MediaItemBasic>(mediaType, mediaActions) {
+ private lateinit var binding: KauActivityImagePickerOverlayBinding
+
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
- setContentView(R.layout.kau_activity_image_picker_overlay)
- initializeRecycler(kau_recyclerview)
- MediaItemBasic.bindEvents(this, adapter.fastAdapter!!)
+ binding = KauActivityImagePickerOverlayBinding.inflate(layoutInflater)
+ setContentView(binding.root)
+ binding.init()
+ }
+
+ private fun KauActivityImagePickerOverlayBinding.init() {
+ initializeRecycler(kauRecyclerview)
+ MediaItemBasic.bindEvents(this@MediaPickerActivityOverlayBase, adapter.fastAdapter!!)
- kau_draggable.addExitListener(this, R.transition.kau_image_exit_bottom, R.transition.kau_image_exit_top)
- kau_draggable.setOnClickListener { finishAfterTransition() }
+ kauDraggable.addExitListener(this@MediaPickerActivityOverlayBase, R.transition.kau_image_exit_bottom, R.transition.kau_image_exit_top)
+ kauDraggable.setOnClickListener { finishAfterTransition() }
loadItems()
}
override fun finishAfterTransition() {
- kau_recyclerview.stopScroll()
+ binding.kauRecyclerview.stopScroll()
super.finishAfterTransition()
}
diff --git a/mediapicker/src/main/res/layout/kau_iitem_image_basic.xml b/mediapicker/src/main/res/layout/kau_iitem_image_basic.xml
index b89e41d..939f139 100644
--- a/mediapicker/src/main/res/layout/kau_iitem_image_basic.xml
+++ b/mediapicker/src/main/res/layout/kau_iitem_image_basic.xml
@@ -1,10 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<ca.allanwang.kau.ui.views.MeasuredImageView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
+ xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/kau_image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="2dp"
android:foreground="@drawable/kau_selectable_white"
android:scaleType="centerCrop"
- app:relativeHeight="1" /> \ No newline at end of file
+ app:relativeHeight="1"
+ tools:ignore="UnusedAttribute" /> \ No newline at end of file
diff --git a/sample/build.gradle b/sample/build.gradle
index 47baed2..ff25f50 100644
--- a/sample/build.gradle
+++ b/sample/build.gradle
@@ -1,9 +1,14 @@
import kau.Dependencies
+import kau.Versions
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
-apply plugin: 'kotlin-android-extensions'
+apply plugin: 'kotlin-kapt'
+apply plugin: 'kotlin-parcelize'
+//apply plugin: 'com.bugsnag.android.gradle'
apply plugin: 'com.github.triplet.play'
+apply plugin: 'dagger.hilt.android.plugin'
+apply plugin: 'com.mikepenz.aboutlibraries.plugin'
play {
serviceAccountCredentials = file('../files/gplay-keys.json')
@@ -11,8 +16,7 @@ play {
}
android {
- compileSdkVersion kau.Versions.targetSdk
- buildToolsVersion kau.Versions.buildTools
+ compileSdkVersion Versions.targetSdk
androidGitVersion {
codeFormat = 'MMNNPPXX'
@@ -21,15 +25,15 @@ android {
defaultConfig {
applicationId "ca.allanwang.kau.sample"
- minSdkVersion kau.Versions.minSdk
- targetSdkVersion kau.Versions.targetSdk
+ minSdkVersion Versions.minSdk
+ targetSdkVersion Versions.targetSdk
versionName androidGitVersion.name()
versionCode androidGitVersion.code()
multiDexEnabled true
- testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
+ testInstrumentationRunner "ca.allanwang.kau.sample.SampleTestRunner"
}
viewBinding {
- enabled = true
+ enabled true
}
def releaseSigning = file("../files/kau.properties")
@@ -63,6 +67,7 @@ android {
versionNameSuffix "-debug"
signingConfig signingConfigs.debug
resValue "string", "app_name", "KAU Debug"
+ ext.enableBugsnag = false
}
release {
@@ -82,11 +87,16 @@ android {
pickFirst 'META-INF/core_release.kotlin_module'
pickFirst 'META-INF/library_release.kotlin_module'
pickFirst 'META-INF/library-core_release.kotlin_module'
+ exclude "**/module-info.class"
}
compileOptions {
- sourceCompatibility JavaVersion.VERSION_1_8
- targetCompatibility JavaVersion.VERSION_1_8
+ sourceCompatibility Versions.java
+ targetCompatibility Versions.java
+ }
+
+ kotlinOptions {
+ jvmTarget = Versions.java.toString()
}
sourceSets {
@@ -96,25 +106,15 @@ android {
main.res.srcDirs += 'src/main/res-public'
}
- testOptions.unitTests {
- // Don't throw runtime exceptions for android calls that are not mocked
- returnDefaultValues = true
-
- // Always show the result of every unit test, even if it passes.
- all {
- testLogging {
- events 'passed', 'skipped', 'failed', 'standardOut', 'standardError'
- }
- }
- }
+ testOptions {
+ unitTests {
+ // Don't throw runtime exceptions for android calls that are not mocked
+ returnDefaultValues = true
- // See https://github.com/facebook/flipper/issues/146
- configurations.all {
- resolutionStrategy.eachDependency { DependencyResolveDetails details ->
- def requested = details.requested
- if (requested.group == "com.android.support") {
- if (!requested.name.startsWith("multidex")) {
- details.useVersion "26.+"
+ // Always show the result of every unit test, even if it passes.
+ all {
+ testLogging {
+ events 'skipped', 'failed', 'standardOut', 'standardError'
}
}
}
@@ -132,10 +132,17 @@ dependencies {
implementation project(':searchview')
implementation project(':mediapicker')
+ implementation Dependencies.hilt
+ kapt Dependencies.hiltCompiler
+
+ implementation Dependencies.bugsnag
+
implementation Dependencies.materialDialog("input")
testImplementation Dependencies.kotlinTest
testImplementation Dependencies.junit
+ testImplementation Dependencies.hiltTest
+ kaptTest Dependencies.hiltCompiler
androidTestImplementation Dependencies.kotlinTest
androidTestImplementation Dependencies.espresso
@@ -143,4 +150,6 @@ dependencies {
androidTestImplementation Dependencies.espresso("contrib")
androidTestImplementation Dependencies.testRules
androidTestImplementation Dependencies.testRunner
+ androidTestImplementation Dependencies.hiltTest
+ kaptAndroidTest Dependencies.hiltCompiler
}
diff --git a/sample/src/androidTest/kotlin/ca/allanwang/kau/sample/KPrefViewTest.kt b/sample/src/androidTest/kotlin/ca/allanwang/kau/sample/KPrefViewTest.kt
index 72199cf..fb360b9 100644
--- a/sample/src/androidTest/kotlin/ca/allanwang/kau/sample/KPrefViewTest.kt
+++ b/sample/src/androidTest/kotlin/ca/allanwang/kau/sample/KPrefViewTest.kt
@@ -25,8 +25,12 @@ import androidx.test.espresso.matcher.BoundedMatcher
import androidx.test.espresso.matcher.ViewMatchers.withChild
import androidx.test.espresso.matcher.ViewMatchers.withText
import androidx.test.ext.junit.runners.AndroidJUnit4
-import androidx.test.filters.MediumTest
import androidx.test.rule.ActivityTestRule
+import ca.allanwang.kau.sample.test.BaseTest
+import dagger.hilt.android.testing.HiltAndroidTest
+import javax.inject.Inject
+import kotlin.test.assertFalse
+import kotlin.test.assertTrue
import org.hamcrest.BaseMatcher
import org.hamcrest.Description
import org.hamcrest.Matcher
@@ -34,6 +38,8 @@ import org.hamcrest.Matchers.allOf
import org.hamcrest.Matchers.instanceOf
import org.junit.Rule
import org.junit.Test
+import org.junit.rules.RuleChain
+import org.junit.rules.TestRule
import org.junit.runner.RunWith
/**
@@ -42,12 +48,16 @@ import org.junit.runner.RunWith
* Tests related to the :kpref-activity module
*/
@RunWith(AndroidJUnit4::class)
-@MediumTest
-class KPrefViewTest {
+@HiltAndroidTest
+class KPrefViewTest : BaseTest() {
- @get:Rule
val activity: ActivityTestRule<MainActivity> = ActivityTestRule(MainActivity::class.java)
+ @get:Rule
+ val rule: TestRule = RuleChain.outerRule(SampleTestRule()).around(activity)
+
+ @Inject lateinit var pref: KPrefSample
+
fun verifyCheck(checked: Boolean): Matcher<View> {
return object : BoundedMatcher<View, View>(View::class.java) {
@@ -93,11 +103,11 @@ class KPrefViewTest {
fun basicCheckboxToggle() {
val checkbox1 = onCheckboxView(withChild(withText(R.string.checkbox_1)))
- val initiallyChecked = KPrefSample.check1
+ assertTrue(pref.check1, "check1 not normalized")
- checkbox1.verifyCheck("checkbox1 init", initiallyChecked)
+ checkbox1.verifyCheck("checkbox1 init", true)
checkbox1.perform(click())
- checkbox1.verifyCheck("checkbox1 after click", !initiallyChecked)
+ checkbox1.verifyCheck("checkbox1 after click", false)
}
/**
@@ -107,23 +117,24 @@ class KPrefViewTest {
fun dependentCheckboxToggle() {
val checkbox2 = onCheckboxView(withChild(withText(R.string.checkbox_2)))
val checkbox3 =
- onCheckboxView(withChild(withText(R.string.checkbox_3)), withChild(withText(R.string.desc_dependent)))
+ onCheckboxView(
+ withChild(withText(R.string.checkbox_3)),
+ withChild(withText(R.string.desc_dependent))
+ )
- // normalize so that both are checked
- if (!KPrefSample.check2)
- checkbox2.perform(click())
- if (!KPrefSample.check3)
- checkbox3.perform(click())
+ assertFalse(pref.check2, "check2 not normalized")
+ assertFalse(pref.check3, "check3 not normalized")
- checkbox3.verifyCheck("checkbox3 init", true, true)
+ checkbox2.verifyCheck("checkbox2 init", checked = false, enabled = true)
+ checkbox3.verifyCheck("checkbox3 init", checked = false, enabled = false)
checkbox3.perform(click())
- checkbox3.verifyCheck("checkbox3 after click", false, true)
+ checkbox3.verifyCheck("checkbox3 after disabled click", checked = false, enabled = false)
checkbox2.perform(click())
- checkbox2.verifyCheck("checkbox2 after click", false, true)
- checkbox3.verifyCheck("checkbox3 after checkbox2 click", false, false)
+ checkbox2.verifyCheck("checkbox2 after click", checked = true, enabled = true)
+ checkbox3.verifyCheck("checkbox3 after checkbox2 click", checked = false, enabled = true)
checkbox3.perform(click())
- checkbox3.verifyCheck("checkbox3 after disabled click", false, false)
+ checkbox3.verifyCheck("checkbox3 after enabled click", checked = true, enabled = true)
}
}
diff --git a/sample/src/androidTest/kotlin/ca/allanwang/kau/sample/SampleTestApp.kt b/sample/src/androidTest/kotlin/ca/allanwang/kau/sample/SampleTestApp.kt
new file mode 100644
index 0000000..f6ffdb1
--- /dev/null
+++ b/sample/src/androidTest/kotlin/ca/allanwang/kau/sample/SampleTestApp.kt
@@ -0,0 +1,63 @@
+/*
+ * Copyright 2020 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.sample
+
+import android.app.Application
+import android.content.Context
+import androidx.test.core.app.ApplicationProvider
+import androidx.test.runner.AndroidJUnitRunner
+import dagger.hilt.EntryPoint
+import dagger.hilt.InstallIn
+import dagger.hilt.android.EntryPointAccessors
+import dagger.hilt.android.testing.HiltTestApplication
+import dagger.hilt.components.SingletonComponent
+import org.junit.rules.TestRule
+import org.junit.runner.Description
+import org.junit.runners.model.Statement
+
+class SampleTestRunner : AndroidJUnitRunner() {
+ override fun newApplication(
+ cl: ClassLoader?,
+ className: String?,
+ context: Context?
+ ): Application {
+ return super.newApplication(cl, HiltTestApplication::class.java.name, context)
+ }
+}
+
+class SampleTestRule : TestRule {
+
+ @EntryPoint
+ @InstallIn(SingletonComponent::class)
+ interface SampleTestRuleEntryPoint {
+ fun pref(): KPrefSample
+ }
+
+ override fun apply(base: Statement, description: Description): Statement =
+ object : Statement() {
+ override fun evaluate() {
+ val entryPoint = EntryPointAccessors.fromApplication(
+ ApplicationProvider.getApplicationContext(),
+ SampleTestRuleEntryPoint::class.java
+ )
+
+ // Reset prefs
+ entryPoint.pref().reset()
+
+ base.evaluate()
+ }
+ }
+}
diff --git a/sample/src/androidTest/kotlin/ca/allanwang/kau/sample/test/BaseTest.kt b/sample/src/androidTest/kotlin/ca/allanwang/kau/sample/test/BaseTest.kt
new file mode 100644
index 0000000..1cba88f
--- /dev/null
+++ b/sample/src/androidTest/kotlin/ca/allanwang/kau/sample/test/BaseTest.kt
@@ -0,0 +1,32 @@
+/*
+ * Copyright 2020 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.sample.test
+
+import dagger.hilt.android.testing.HiltAndroidRule
+import kotlin.test.BeforeTest
+import org.junit.Rule
+
+abstract class BaseTest {
+ @Suppress("LeakingThis")
+ @get:Rule
+ val hiltRule: HiltAndroidRule =
+ HiltAndroidRule(this)
+
+ @BeforeTest
+ fun before() {
+ hiltRule.inject()
+ }
+}
diff --git a/sample/src/androidTest/kotlin/ca/allanwang/kau/sample/test/TestModules.kt b/sample/src/androidTest/kotlin/ca/allanwang/kau/sample/test/TestModules.kt
new file mode 100644
index 0000000..1615d2f
--- /dev/null
+++ b/sample/src/androidTest/kotlin/ca/allanwang/kau/sample/test/TestModules.kt
@@ -0,0 +1,33 @@
+/*
+ * Copyright 2020 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.sample.test
+
+import ca.allanwang.kau.kpref.KPrefFactory
+import ca.allanwang.kau.kpref.KPrefFactoryInMemory
+import ca.allanwang.kau.sample.PrefFactoryModule
+import dagger.Module
+import dagger.Provides
+import dagger.hilt.components.SingletonComponent
+import dagger.hilt.testing.TestInstallIn
+
+@Module
+@TestInstallIn(
+ components = [SingletonComponent::class],
+ replaces = [PrefFactoryModule::class])
+object PrefFactoryTestModule {
+ @Provides
+ fun factory(): KPrefFactory = KPrefFactoryInMemory
+}
diff --git a/sample/src/main/AndroidManifest.xml b/sample/src/main/AndroidManifest.xml
index 5846c6b..b205c51 100644
--- a/sample/src/main/AndroidManifest.xml
+++ b/sample/src/main/AndroidManifest.xml
@@ -57,6 +57,9 @@
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/kau_file_paths" />
</provider>
+ <meta-data
+ android:name="com.bugsnag.android.API_KEY"
+ android:value="0a09e498a253b98237500fb5f948e5c6"/>
</application>
</manifest> \ 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 ffe769a..59f1c92 100644
--- a/sample/src/main/kotlin/ca/allanwang/kau/sample/AboutActivity.kt
+++ b/sample/src/main/kotlin/ca/allanwang/kau/sample/AboutActivity.kt
@@ -23,15 +23,17 @@ import com.mikepenz.fastadapter.GenericItem
/**
* Created by Allan Wang on 2017-06-27.
*/
-class AboutActivity : AboutActivityBase(R.string::class.java, {
- cutoutDrawableRes = R.drawable.kau
- textColor = 0xde000000.toInt()
- backgroundColor = 0xfffafafa.toInt()
- accentColor = 0xff00838F.toInt()
- cutoutForeground = 0xff18FFFF.toInt()
- faqXmlRes = R.xml.kau_faq
- faqParseNewLine = false
-}) {
+class AboutActivity : AboutActivityBase(R.string::class.java) {
+
+ override fun Configs.buildConfigs() {
+ cutoutDrawableRes = R.drawable.kau
+ textColor = 0xde000000.toInt()
+ backgroundColor = 0xfffafafa.toInt()
+ accentColor = 0xff00838F.toInt()
+ cutoutForeground = 0xff18FFFF.toInt()
+ faqXmlRes = R.xml.kau_faq
+ faqParseNewLine = false
+ }
override fun postInflateMainPage(adapter: FastItemThemedAdapter<GenericItem>) {
adapter.add(CardIItem {
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 a472f09..b3560c5 100644
--- a/sample/src/main/kotlin/ca/allanwang/kau/sample/AnimActivity.kt
+++ b/sample/src/main/kotlin/ca/allanwang/kau/sample/AnimActivity.kt
@@ -28,6 +28,8 @@ import ca.allanwang.kau.utils.fullLinearRecycler
import ca.allanwang.kau.utils.startActivity
import ca.allanwang.kau.utils.withAlpha
import ca.allanwang.kau.utils.withSlideOut
+import dagger.hilt.android.AndroidEntryPoint
+import javax.inject.Inject
/**
* Created by Allan Wang on 2017-06-12.
@@ -35,14 +37,18 @@ import ca.allanwang.kau.utils.withSlideOut
* Activity for animations
* Now also showcases permissions
*/
+@AndroidEntryPoint
class AnimActivity : KauBaseActivity() {
+ @Inject
+ lateinit var pref: KPrefSample
+
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val adapter = SingleFastAdapter()
setContentView(fullLinearRecycler(adapter).apply {
setBackgroundColor(
- KPrefSample.bgColor.withAlpha(255)
+ pref.bgColor.withAlpha(255)
)
})
diff --git a/sample/src/main/kotlin/ca/allanwang/kau/sample/KPrefSample.kt b/sample/src/main/kotlin/ca/allanwang/kau/sample/KPrefSample.kt
index 80a75bf..970d3eb 100644
--- a/sample/src/main/kotlin/ca/allanwang/kau/sample/KPrefSample.kt
+++ b/sample/src/main/kotlin/ca/allanwang/kau/sample/KPrefSample.kt
@@ -15,13 +15,21 @@
*/
package ca.allanwang.kau.sample
+import android.content.Context
import android.graphics.Color
import ca.allanwang.kau.kpref.KPref
+import ca.allanwang.kau.kpref.KPrefFactory
+import ca.allanwang.kau.kpref.KPrefFactoryAndroid
+import dagger.Module
+import dagger.Provides
+import dagger.hilt.InstallIn
+import dagger.hilt.android.qualifiers.ApplicationContext
+import dagger.hilt.components.SingletonComponent
/**
* Created by Allan Wang on 2017-06-07.
*/
-object KPrefSample : KPref() {
+class KPrefSample(factory: KPrefFactory) : KPref("pref_sample", factory = factory) {
var version: Int by kpref("version", -1)
var textColor: Int by kpref("TEXT_COLOR", Color.WHITE)
var accentColor: Int by kpref("ACCENT_COLOR", 0xffff8900.toInt())
@@ -34,3 +42,17 @@ object KPrefSample : KPref() {
var time12: Int by kpref("time_12", 315)
var time24: Int by kpref("time_24", 2220)
}
+
+@Module
+@InstallIn(SingletonComponent::class)
+object PrefModule {
+ @Provides
+ fun pref(factory: KPrefFactory): KPrefSample = KPrefSample(factory)
+}
+
+@Module
+@InstallIn(SingletonComponent::class)
+object PrefFactoryModule {
+ @Provides
+ fun factory(@ApplicationContext context: Context): KPrefFactory = KPrefFactoryAndroid(context)
+}
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 4fe941b..e6841c8 100644
--- a/sample/src/main/kotlin/ca/allanwang/kau/sample/MainActivity.kt
+++ b/sample/src/main/kotlin/ca/allanwang/kau/sample/MainActivity.kt
@@ -40,7 +40,10 @@ import ca.allanwang.kau.utils.withSceneTransitionAnimation
import ca.allanwang.kau.xml.showChangelog
import com.afollestad.materialdialogs.input.input
import com.mikepenz.iconics.typeface.library.googlematerial.GoogleMaterial
+import dagger.hilt.android.AndroidEntryPoint
+import javax.inject.Inject
+@AndroidEntryPoint
class MainActivity : KPrefActivity() {
var searchView: SearchView? = null
@@ -50,60 +53,518 @@ class MainActivity : KPrefActivity() {
// some of the most common english words for show
val wordBank: List<String> by lazy {
listOf(
- "the", "name", "of", "very", "to", "through",
- "and", "just", "a", "form", "in", "much", "is", "great", "it", "think", "you", "say",
- "that", "help", "he", "low", "was", "line", "for", "before", "on", "turn", "are", "cause",
- "with", "same", "as", "mean", "I", "differ", "his", "move", "they", "right", "be", "boy",
- "at", "old", "one", "too", "have", "does", "this", "tell", "from", "sentence", "or", "set",
- "had", "three", "by", "want", "hot", "air", "but", "well", "some", "also", "what", "play",
- "there", "small", "we", "end", "can", "put", "out", "home", "other", "read", "were", "hand",
- "all", "port", "your", "large", "when", "spell", "up", "add", "use", "even", "word", "land",
- "how", "here", "said", "must", "an", "big", "each", "high", "she", "such", "which", "follow",
- "do", "act", "their", "why", "time", "ask", "if", "men", "will", "change", "way", "went",
- "about", "light", "many", "kind", "then", "off", "them", "need", "would", "house", "write",
- "picture", "like", "try", "so", "us", "these", "again", "her", "animal", "long", "point",
- "make", "mother", "thing", "world", "see", "near", "him", "build", "two", "self", "has",
- "earth", "look", "father", "more", "head", "day", "stand", "could", "own", "go", "page",
- "come", "should", "did", "country", "my", "found", "sound", "answer", "no", "school", "most",
- "grow", "number", "study", "who", "still", "over", "learn", "know", "plant", "water", "cover",
- "than", "food", "call", "sun", "first", "four", "people", "thought", "may", "let", "down", "keep",
- "side", "eye", "been", "never", "now", "last", "find", "door", "any", "between", "new", "city",
- "work", "tree", "part", "cross", "take", "since", "get", "hard", "place", "start", "made",
- "might", "live", "story", "where", "saw", "after", "far", "back", "sea", "little", "draw",
- "only", "left", "round", "late", "man", "run", "year", "don't", "came", "while", "show",
- "press", "every", "close", "good", "night", "me", "real", "give", "life", "our", "few", "under",
- "stopRankWordRankWord", "open", "ten", "seem", "simple", "together", "several", "next",
- "vowel", "white", "toward", "children", "war", "begin", "lay", "got", "against", "walk", "pattern",
- "example", "slow", "ease", "center", "paper", "love", "often", "person", "always", "money",
- "music", "serve", "those", "appear", "both", "road", "mark", "map", "book", "science", "letter",
- "rule", "until", "govern", "mile", "pull", "river", "cold", "car", "notice", "feet", "voice",
- "care", "fall", "second", "power", "group", "town", "carry", "fine", "took", "certain", "rain",
- "fly", "eat", "unit", "room", "lead", "friend", "cry", "began", "dark", "idea", "machine",
- "fish", "note", "mountain", "wait", "north", "plan", "once", "figure", "base", "star", "hear",
- "box", "horse", "noun", "cut", "field", "sure", "rest", "watch", "correct", "color", "able",
- "face", "pound", "wood", "done", "main", "beauty", "enough", "drive", "plain", "stood", "girl",
- "contain", "usual", "front", "young", "teach", "ready", "week", "above", "final", "ever", "gave",
- "red", "green", "list", "oh", "though", "quick", "feel", "develop", "talk", "sleep", "bird",
- "warm", "soon", "free", "body", "minute", "dog", "strong", "family", "special", "direct", "mind",
- "pose", "behind", "leave", "clear", "song", "tail", "measure", "produce", "state", "fact", "product",
- "street", "black", "inch", "short", "lot", "numeral", "nothing", "class", "course", "wind", "stay",
- "question", "wheel", "happen", "full", "complete", "force", "ship", "blue", "area", "object", "half",
- "decide", "rock", "surface", "order", "deep", "fire", "moon", "south", "island", "problem", "foot",
- "piece", "yet", "told", "busy", "knew", "test", "pass", "record", "farm", "boat", "top", "common",
- "whole", "gold", "king", "possible", "size", "plane", "heard", "age", "best", "dry", "hour", "wonder",
- "better", "laugh", "true.", "thousand", "during", "ago", "hundred", "ran", "am", "check", "remember",
- "game", "step", "shape", "early", "yes", "hold", "hot", "west", "miss", "ground", "brought", "interest",
- "heat", "reach", "snow", "fast", "bed", "five", "bring", "sing", "sit", "listen", "perhaps", "six",
- "fill", "table", "east", "travel", "weight", "less", "language", "morning", "among"
+ "the",
+ "name",
+ "of",
+ "very",
+ "to",
+ "through",
+ "and",
+ "just",
+ "a",
+ "form",
+ "in",
+ "much",
+ "is",
+ "great",
+ "it",
+ "think",
+ "you",
+ "say",
+ "that",
+ "help",
+ "he",
+ "low",
+ "was",
+ "line",
+ "for",
+ "before",
+ "on",
+ "turn",
+ "are",
+ "cause",
+ "with",
+ "same",
+ "as",
+ "mean",
+ "I",
+ "differ",
+ "his",
+ "move",
+ "they",
+ "right",
+ "be",
+ "boy",
+ "at",
+ "old",
+ "one",
+ "too",
+ "have",
+ "does",
+ "this",
+ "tell",
+ "from",
+ "sentence",
+ "or",
+ "set",
+ "had",
+ "three",
+ "by",
+ "want",
+ "hot",
+ "air",
+ "but",
+ "well",
+ "some",
+ "also",
+ "what",
+ "play",
+ "there",
+ "small",
+ "we",
+ "end",
+ "can",
+ "put",
+ "out",
+ "home",
+ "other",
+ "read",
+ "were",
+ "hand",
+ "all",
+ "port",
+ "your",
+ "large",
+ "when",
+ "spell",
+ "up",
+ "add",
+ "use",
+ "even",
+ "word",
+ "land",
+ "how",
+ "here",
+ "said",
+ "must",
+ "an",
+ "big",
+ "each",
+ "high",
+ "she",
+ "such",
+ "which",
+ "follow",
+ "do",
+ "act",
+ "their",
+ "why",
+ "time",
+ "ask",
+ "if",
+ "men",
+ "will",
+ "change",
+ "way",
+ "went",
+ "about",
+ "light",
+ "many",
+ "kind",
+ "then",
+ "off",
+ "them",
+ "need",
+ "would",
+ "house",
+ "write",
+ "picture",
+ "like",
+ "try",
+ "so",
+ "us",
+ "these",
+ "again",
+ "her",
+ "animal",
+ "long",
+ "point",
+ "make",
+ "mother",
+ "thing",
+ "world",
+ "see",
+ "near",
+ "him",
+ "build",
+ "two",
+ "self",
+ "has",
+ "earth",
+ "look",
+ "father",
+ "more",
+ "head",
+ "day",
+ "stand",
+ "could",
+ "own",
+ "go",
+ "page",
+ "come",
+ "should",
+ "did",
+ "country",
+ "my",
+ "found",
+ "sound",
+ "answer",
+ "no",
+ "school",
+ "most",
+ "grow",
+ "number",
+ "study",
+ "who",
+ "still",
+ "over",
+ "learn",
+ "know",
+ "plant",
+ "water",
+ "cover",
+ "than",
+ "food",
+ "call",
+ "sun",
+ "first",
+ "four",
+ "people",
+ "thought",
+ "may",
+ "let",
+ "down",
+ "keep",
+ "side",
+ "eye",
+ "been",
+ "never",
+ "now",
+ "last",
+ "find",
+ "door",
+ "any",
+ "between",
+ "new",
+ "city",
+ "work",
+ "tree",
+ "part",
+ "cross",
+ "take",
+ "since",
+ "get",
+ "hard",
+ "place",
+ "start",
+ "made",
+ "might",
+ "live",
+ "story",
+ "where",
+ "saw",
+ "after",
+ "far",
+ "back",
+ "sea",
+ "little",
+ "draw",
+ "only",
+ "left",
+ "round",
+ "late",
+ "man",
+ "run",
+ "year",
+ "don't",
+ "came",
+ "while",
+ "show",
+ "press",
+ "every",
+ "close",
+ "good",
+ "night",
+ "me",
+ "real",
+ "give",
+ "life",
+ "our",
+ "few",
+ "under",
+ "stopRankWordRankWord",
+ "open",
+ "ten",
+ "seem",
+ "simple",
+ "together",
+ "several",
+ "next",
+ "vowel",
+ "white",
+ "toward",
+ "children",
+ "war",
+ "begin",
+ "lay",
+ "got",
+ "against",
+ "walk",
+ "pattern",
+ "example",
+ "slow",
+ "ease",
+ "center",
+ "paper",
+ "love",
+ "often",
+ "person",
+ "always",
+ "money",
+ "music",
+ "serve",
+ "those",
+ "appear",
+ "both",
+ "road",
+ "mark",
+ "map",
+ "book",
+ "science",
+ "letter",
+ "rule",
+ "until",
+ "govern",
+ "mile",
+ "pull",
+ "river",
+ "cold",
+ "car",
+ "notice",
+ "feet",
+ "voice",
+ "care",
+ "fall",
+ "second",
+ "power",
+ "group",
+ "town",
+ "carry",
+ "fine",
+ "took",
+ "certain",
+ "rain",
+ "fly",
+ "eat",
+ "unit",
+ "room",
+ "lead",
+ "friend",
+ "cry",
+ "began",
+ "dark",
+ "idea",
+ "machine",
+ "fish",
+ "note",
+ "mountain",
+ "wait",
+ "north",
+ "plan",
+ "once",
+ "figure",
+ "base",
+ "star",
+ "hear",
+ "box",
+ "horse",
+ "noun",
+ "cut",
+ "field",
+ "sure",
+ "rest",
+ "watch",
+ "correct",
+ "color",
+ "able",
+ "face",
+ "pound",
+ "wood",
+ "done",
+ "main",
+ "beauty",
+ "enough",
+ "drive",
+ "plain",
+ "stood",
+ "girl",
+ "contain",
+ "usual",
+ "front",
+ "young",
+ "teach",
+ "ready",
+ "week",
+ "above",
+ "final",
+ "ever",
+ "gave",
+ "red",
+ "green",
+ "list",
+ "oh",
+ "though",
+ "quick",
+ "feel",
+ "develop",
+ "talk",
+ "sleep",
+ "bird",
+ "warm",
+ "soon",
+ "free",
+ "body",
+ "minute",
+ "dog",
+ "strong",
+ "family",
+ "special",
+ "direct",
+ "mind",
+ "pose",
+ "behind",
+ "leave",
+ "clear",
+ "song",
+ "tail",
+ "measure",
+ "produce",
+ "state",
+ "fact",
+ "product",
+ "street",
+ "black",
+ "inch",
+ "short",
+ "lot",
+ "numeral",
+ "nothing",
+ "class",
+ "course",
+ "wind",
+ "stay",
+ "question",
+ "wheel",
+ "happen",
+ "full",
+ "complete",
+ "force",
+ "ship",
+ "blue",
+ "area",
+ "object",
+ "half",
+ "decide",
+ "rock",
+ "surface",
+ "order",
+ "deep",
+ "fire",
+ "moon",
+ "south",
+ "island",
+ "problem",
+ "foot",
+ "piece",
+ "yet",
+ "told",
+ "busy",
+ "knew",
+ "test",
+ "pass",
+ "record",
+ "farm",
+ "boat",
+ "top",
+ "common",
+ "whole",
+ "gold",
+ "king",
+ "possible",
+ "size",
+ "plane",
+ "heard",
+ "age",
+ "best",
+ "dry",
+ "hour",
+ "wonder",
+ "better",
+ "laugh",
+ "true.",
+ "thousand",
+ "during",
+ "ago",
+ "hundred",
+ "ran",
+ "am",
+ "check",
+ "remember",
+ "game",
+ "step",
+ "shape",
+ "early",
+ "yes",
+ "hold",
+ "hot",
+ "west",
+ "miss",
+ "ground",
+ "brought",
+ "interest",
+ "heat",
+ "reach",
+ "snow",
+ "fast",
+ "bed",
+ "five",
+ "bring",
+ "sing",
+ "sit",
+ "listen",
+ "perhaps",
+ "six",
+ "fill",
+ "table",
+ "east",
+ "travel",
+ "weight",
+ "less",
+ "language",
+ "morning",
+ "among"
)
}
const val REQUEST_MEDIA = 27
}
+ @Inject
+ lateinit var pref: KPrefSample
+
override fun kPrefCoreAttributes(): CoreAttributeContract.() -> Unit = {
- textColor = KPrefSample::textColor
- accentColor = KPrefSample::accentColor
+ textColor = pref::textColor
+ accentColor = pref::accentColor
}
override fun onCreateKPrefs(savedInstanceState: Bundle?): KPrefAdapterBuilder.() -> Unit = {
@@ -113,7 +574,7 @@ class MainActivity : KPrefActivity() {
/**
* This is how the setup looks like with all the proper tags
*/
- checkbox(title = R.string.checkbox_1, getter = KPrefSample::check1, setter = { KPrefSample.check1 = it },
+ checkbox(title = R.string.checkbox_1, getter = pref::check1, setter = { pref.check1 = it },
builder = {
descRes = R.string.desc
})
@@ -123,25 +584,25 @@ class MainActivity : KPrefActivity() {
*/
checkbox(
R.string.checkbox_2,
- KPrefSample::check2,
- { KPrefSample.check2 = it; reloadByTitle(R.string.checkbox_3) })
+ pref::check2,
+ { pref.check2 = it; reloadByTitle(R.string.checkbox_3) })
/**
* Since the builder is the last argument and is a lambda, we may write the setup cleanly like so:
*/
- checkbox(R.string.checkbox_3, KPrefSample::check3, { KPrefSample.check3 = it }) {
+ checkbox(R.string.checkbox_3, pref::check3, { pref.check3 = it }) {
descRes = R.string.desc_dependent
- enabler = { KPrefSample.check2 }
+ enabler = { pref.check2 }
onDisabledClick = { itemView.context.toast("I am still disabled") }
}
- colorPicker(R.string.text_color, KPrefSample::textColor, { KPrefSample.textColor = it; reload() }) {
+ colorPicker(R.string.text_color, pref::textColor, { pref.textColor = it; reload() }) {
descRes = R.string.color_custom
allowCustom = true
}
- colorPicker(R.string.accent_color, KPrefSample::accentColor, {
- KPrefSample.accentColor = it
+ colorPicker(R.string.accent_color, pref::accentColor, {
+ pref.accentColor = it
reload()
this@MainActivity.navigationBarColor = it
toolbarCanvas.ripple(it, RippleCanvas.MIDDLE, RippleCanvas.END, duration = 500L)
@@ -150,8 +611,8 @@ class MainActivity : KPrefActivity() {
allowCustom = false
}
- colorPicker(R.string.background_color, KPrefSample::bgColor, {
- KPrefSample.bgColor = it; bgCanvas.ripple(it, duration = 500L)
+ colorPicker(R.string.background_color, pref::bgColor, {
+ pref.bgColor = it; bgCanvas.ripple(it, duration = 500L)
}) {
iicon = GoogleMaterial.Icon.gmd_colorize
descRes = R.string.color_custom_alpha
@@ -159,19 +620,24 @@ class MainActivity : KPrefActivity() {
allowCustom = true
}
- text(R.string.text, KPrefSample::text, { KPrefSample.text = it }) {
+ text(R.string.text, pref::text, { pref.text = it }) {
descRes = R.string.text_desc
onClick = {
itemView.context.materialDialog {
title(text = "Type Text")
- input("Type here", prefill = item.pref, maxLength = 20, allowEmpty = true) { _, input ->
+ input(
+ "Type here",
+ prefill = item.pref,
+ maxLength = 20,
+ allowEmpty = true
+ ) { _, input ->
item.pref = input.toString()
}
}
}
}
- seekbar(R.string.seekbar, KPrefSample::seekbar, { KPrefSample.seekbar = it }) {
+ seekbar(R.string.seekbar, pref::seekbar, { pref.seekbar = it }) {
descRes = R.string.kau_lorem_ipsum
increments = 5
textViewConfigs = {
@@ -215,35 +681,40 @@ class MainActivity : KPrefActivity() {
*/
checkbox(
R.string.checkbox_2,
- KPrefSample::check2,
- { KPrefSample.check2 = it; reloadByTitle(R.string.checkbox_3) }) {
+ pref::check2,
+ { pref.check2 = it; reloadByTitle(R.string.checkbox_3) }) {
titleFun = { R.string.checkbox_3 }
descRes = R.string.kau_lorem_ipsum
}
- text(R.string.text, KPrefSample::text, { KPrefSample.text = it }) {
+ text(R.string.text, pref::text, { pref.text = it }) {
descRes = R.string.kau_lorem_ipsum
textGetter = { string(R.string.kau_lorem_ipsum) }
}
- timePicker(R.string.time, KPrefSample::time12, { KPrefSample.time12 = it }) {
+ timePicker(R.string.time, pref::time12, { pref.time12 = it }) {
descRes = R.string.time_desc_12
use24HourFormat = false
}
- timePicker(R.string.time, KPrefSample::time24, { KPrefSample.time24 = it }) {
+ timePicker(R.string.time, pref::time24, { pref.time24 = it }) {
descRes = R.string.time_desc_24
use24HourFormat = true
}
}
fun subPrefs(): KPrefAdapterBuilder.() -> Unit = {
- text(R.string.text, { KPrefSample.text }, { KPrefSample.text = it }) {
+ text(R.string.text, { pref.text }, { pref.text = it }) {
descRes = R.string.text_desc
onClick = {
itemView.context.materialDialog {
title(text = "Type Text")
- input("Type here", prefill = item.pref, maxLength = 20, allowEmpty = true) { _, input ->
+ input(
+ "Type here",
+ prefill = item.pref,
+ maxLength = 20,
+ allowEmpty = true
+ ) { _, input ->
item.pref = input.toString()
reloadSelf()
}
@@ -254,11 +725,11 @@ class MainActivity : KPrefActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
- bgCanvas.set(KPrefSample.bgColor)
- toolbarCanvas.set(KPrefSample.accentColor)
- this.navigationBarColor = KPrefSample.accentColor
- if (KPrefSample.version < BuildConfig.VERSION_CODE) {
- KPrefSample.version = BuildConfig.VERSION_CODE
+ bgCanvas.set(pref.bgColor)
+ toolbarCanvas.set(pref.accentColor)
+ this.navigationBarColor = pref.accentColor
+ if (pref.version < BuildConfig.VERSION_CODE) {
+ pref.version = BuildConfig.VERSION_CODE
if (!BuildConfig.DEBUG)
showChangelog(R.xml.kau_changelog)
}
@@ -308,7 +779,12 @@ class MainActivity : KPrefActivity() {
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
when (requestCode) {
- REQUEST_MEDIA -> toast("${kauOnMediaPickerResult(resultCode, data).size} items selected")
+ REQUEST_MEDIA -> toast(
+ "${kauOnMediaPickerResult(
+ resultCode,
+ data
+ ).size} items selected"
+ )
}
}
}
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 50cfe69..7bd2851 100644
--- a/sample/src/main/kotlin/ca/allanwang/kau/sample/PermissionCheckbox.kt
+++ b/sample/src/main/kotlin/ca/allanwang/kau/sample/PermissionCheckbox.kt
@@ -41,7 +41,7 @@ import com.mikepenz.fastadapter.listeners.EventHook
class PermissionCheckbox(val permission: String) : KauIItem<PermissionCheckbox.ViewHolder>(
R.layout.permission_checkbox, { ViewHolder(it) }) {
- override fun bindView(holder: ViewHolder, payloads: MutableList<Any>) {
+ override fun bindView(holder: ViewHolder, payloads: List<Any>) {
super.bindView(holder, payloads)
holder.text.text = permission
holder.checkbox.isChecked = holder.itemView.context.hasPermission(permission)
@@ -72,7 +72,7 @@ class PermissionCheckboxViewBinding(
override fun PermissionCheckboxBinding.bindView(
holder: ViewHolder,
- payloads: MutableList<Any>
+ payloads: List<Any>
) {
permText.text = data.permission
permCheckbox.apply {
diff --git a/sample/src/main/kotlin/ca/allanwang/kau/sample/SampleApp.kt b/sample/src/main/kotlin/ca/allanwang/kau/sample/SampleApp.kt
index 6e6d718..42fbe98 100644
--- a/sample/src/main/kotlin/ca/allanwang/kau/sample/SampleApp.kt
+++ b/sample/src/main/kotlin/ca/allanwang/kau/sample/SampleApp.kt
@@ -16,13 +16,23 @@
package ca.allanwang.kau.sample
import android.app.Application
+import com.bugsnag.android.Bugsnag
+import dagger.hilt.android.HiltAndroidApp
/**
* Created by Allan Wang on 2017-06-08.
*/
+@HiltAndroidApp
class SampleApp : Application() {
override fun onCreate() {
super.onCreate()
- KPrefSample.initialize(this, "pref_sample")
+ initBugsnag()
+ }
+
+ private fun initBugsnag() {
+ if (BuildConfig.DEBUG) {
+ return
+ }
+ Bugsnag.start(this)
}
}
diff --git a/sample/src/main/res/xml/kau_changelog.xml b/sample/src/main/res/xml/kau_changelog.xml
index d61fe63..2d47332 100644
--- a/sample/src/main/res/xml/kau_changelog.xml
+++ b/sample/src/main/res/xml/kau_changelog.xml
@@ -6,11 +6,29 @@
<item text="" />
-->
- <version title="v5.2.1" />
+ <version title="v6.3.0" />
+ <item text="Add support for Arctic Fox 2020.3.1" />
+ <item text="Move to new maven release system" />
+ <item text="Many version bumps" />
+
+ <version title="v6.2.0" />
+ <item text="Add support for Android Studio 4.2" />
+ <item text="Remove all usages of kotlin synthetics" />
+ <item text="Many version bumps" />
+ <item text="Added Hilt dep" />
+
+ <version title="v6.1.0" />
+ <item text="Add support for Android 4.1 RC03" />
+ <item text="Breaking: Updated iconics, buganizer, and spotless dependencies (major version bump)" />
+
+ <version title="v6.0.0" />
+ <item text="Add support for Android 4.1.x" />
+ <item text="Add major version library updates (FastAdapter, AboutLibrary, Iconics)" />
+
+ <version title="v5.3.0" />
+ <item text=":about: Moved config builder inside activity" />
<item text=":color: Allow option to disable selected ring" />
- <item text="" />
- <item text="" />
- <item text="" />
+ <item text=":core: Breaking KPref changes; see migration" />
<version title="v5.2.0" />
<item text=":about: Migrate about libraries to v7.x.x" />
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 78d8782..7be1c68 100644
--- a/searchview/src/main/kotlin/ca/allanwang/kau/searchview/SearchItem.kt
+++ b/searchview/src/main/kotlin/ca/allanwang/kau/searchview/SearchItem.kt
@@ -78,7 +78,7 @@ class SearchItem(
)
}
- override fun bindView(holder: ViewHolder, payloads: MutableList<Any>) {
+ override fun bindView(holder: ViewHolder, payloads: List<Any>) {
super.bindView(holder, payloads)
holder.title.setTextColor(foregroundColor)
holder.desc.setTextColor(foregroundColor.adjustAlpha(0.6f))
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 c2da5fa..12f835b 100644
--- a/searchview/src/main/kotlin/ca/allanwang/kau/searchview/SearchView.kt
+++ b/searchview/src/main/kotlin/ca/allanwang/kau/searchview/SearchView.kt
@@ -22,11 +22,7 @@ import android.graphics.Color
import android.text.Editable
import android.text.TextWatcher
import android.util.AttributeSet
-import android.view.Menu
-import android.view.MenuItem
-import android.view.View
-import android.view.ViewGroup
-import android.view.ViewTreeObserver
+import android.view.*
import android.view.inputmethod.EditorInfo
import android.widget.FrameLayout
import android.widget.ImageView
@@ -40,33 +36,12 @@ import ca.allanwang.kau.kotlin.Debouncer2
import ca.allanwang.kau.kotlin.debounce
import ca.allanwang.kau.logging.KL
import ca.allanwang.kau.searchview.SearchView.Configs
-import ca.allanwang.kau.utils.INVALID_ID
-import ca.allanwang.kau.utils.addEndListener
-import ca.allanwang.kau.utils.adjustAlpha
-import ca.allanwang.kau.utils.circularHide
-import ca.allanwang.kau.utils.circularReveal
-import ca.allanwang.kau.utils.fadeIn
-import ca.allanwang.kau.utils.fadeOut
-import ca.allanwang.kau.utils.gone
-import ca.allanwang.kau.utils.goneIf
-import ca.allanwang.kau.utils.hideKeyboard
-import ca.allanwang.kau.utils.invisibleIf
-import ca.allanwang.kau.utils.isVisible
-import ca.allanwang.kau.utils.parentViewGroup
-import ca.allanwang.kau.utils.runOnUiThread
-import ca.allanwang.kau.utils.setIcon
-import ca.allanwang.kau.utils.setMarginTop
-import ca.allanwang.kau.utils.showKeyboard
-import ca.allanwang.kau.utils.string
-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 ca.allanwang.kau.searchview.databinding.KauSearchViewBinding
+import ca.allanwang.kau.utils.*
import com.mikepenz.fastadapter.adapters.FastItemAdapter
import com.mikepenz.fastadapter.select.selectExtension
import com.mikepenz.iconics.typeface.IIcon
import com.mikepenz.iconics.typeface.library.googlematerial.GoogleMaterial
-import kotlinx.android.synthetic.main.kau_search_view.view.*
/**
* Created by Allan Wang on 2017-06-23.
@@ -204,14 +179,14 @@ class SearchView @JvmOverloads constructor(
* This event is only triggered when [key] is not blank (like in [noResultsFound]
*/
var onItemClick: (position: Int, key: String, content: String, searchView: SearchView) -> Unit =
- { _, _, _, _ -> }
+ { _, _, _, _ -> }
/**
* Long click event for suggestion items
* This event is only triggered when [key] is not blank (like in [noResultsFound]
*/
var onItemLongClick: (position: Int, key: String, content: String, searchView: SearchView) -> Unit =
- { _, _, _, _ -> }
+ { _, _, _, _ -> }
/**
* If a [SearchItem]'s title contains the submitted query, make that portion bold
@@ -232,20 +207,22 @@ class SearchView @JvmOverloads constructor(
SearchItem.backgroundColor = backgroundColor
tintBackground(backgroundColor)
}
- 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)
- }
- icons.forEach { (iicon, view) -> view.goneIf(iicon == null).setSearchIcon(iicon) }
+ with(binding) {
+ val icons = mutableListOf(navIcon to kauSearchNav, clearIcon to kauSearchClear)
+ val extra = extraIcon
+ if (extra != null) {
+ icons.add(extra.first to kauSearchExtra)
+ }
+ icons.forEach { (iicon, view) -> view.goneIf(iicon == null).setSearchIcon(iicon) }
- if (extra != null) {
- kau_search_extra.setOnClickListener(extra.second)
+ if (extra != null) {
+ kauSearchExtra.setOnClickListener(extra.second)
+ }
+ kauSearchDivider.invisibleIf(!withDivider)
+ kauSearchEditText.hint = context.string(hintTextRes, hintText)
+ textCallback.terminate()
+ textCallback = debounce(textDebounceInterval, this@Configs.textCallback)
}
- kau_search_divider.invisibleIf(!withDivider)
- kau_search_edit_text.hint = context.string(hintTextRes, hintText)
- textCallback.terminate()
- textCallback = debounce(textDebounceInterval, this@Configs.textCallback)
}
}
}
@@ -262,7 +239,7 @@ class SearchView @JvmOverloads constructor(
else value
if (configs.highlightQueryText && value.isNotEmpty()) list.forEach {
it.withHighlights(
- kau_search_edit_text.text?.toString()
+ binding.kauSearchEditText.text?.toString()
)
}
cardTransition()
@@ -279,19 +256,20 @@ class SearchView @JvmOverloads constructor(
}
private val configs = Configs()
+
// views
private var textCallback: Debouncer2<String, SearchView> =
- debounce(0) { query, _ -> KL.d { "Search query $query found; set your own textCallback" } }
+ debounce(0) { query, _ -> KL.d { "Search query $query found; set your own textCallback" } }
private val adapter = FastItemAdapter<SearchItem>()
private var menuItem: MenuItem? = null
val isOpen: Boolean
- get() = parent != null && kau_search_cardview.isVisible
+ get() = parent != null && binding.kauSearchCardview.isVisible
/**
* The current text located in our searchview
*/
val query: String
- get() = kau_search_edit_text.text?.toString()?.trim() ?: ""
+ get() = binding.kauSearchEditText.text?.toString()?.trim() ?: ""
/*
* Ripple start points and search view offset
@@ -302,15 +280,20 @@ class SearchView @JvmOverloads constructor(
var menuY: Int = -1 // reference for cardview's marginTop
var menuHalfHeight: Int = -1 // starting y for circular reveal (relative to the cardview)
+ private val binding: KauSearchViewBinding = KauSearchViewBinding.inflate(LayoutInflater.from(context), this)
+
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() }
+ binding.init()
+ }
+
+ private fun KauSearchViewBinding.init() {
+ kauSearchNav.setSearchIcon(configs.navIcon).setOnClickListener { revealClose() }
+ kauSearchClear.setSearchIcon(configs.clearIcon)
+ .setOnClickListener { kauSearchEditText.text?.clear() }
tintForeground(configs.foregroundColor)
tintBackground(configs.backgroundColor)
- with(kau_search_recycler) {
+ with(kauSearchRecycler) {
isNestedScrollingEnabled = false
withLinearAdapter(this@SearchView.adapter)
addOnScrollListener(object : RecyclerView.OnScrollListener() {
@@ -329,25 +312,25 @@ class SearchView @JvmOverloads constructor(
}
onClickListener = { _, _, item, position ->
if (item.key.isNotBlank()) configs.onItemClick(
- position,
- item.key,
- item.content,
- this@SearchView
+ position,
+ item.key,
+ item.content,
+ this@SearchView
); true
}
onLongClickListener = { _, _, item, position ->
if (item.key.isNotBlank()) {
configs.onItemLongClick(
- position,
- item.key,
- item.content,
- this@SearchView
+ position,
+ item.key,
+ item.content,
+ this@SearchView
)
}
true
}
}
- kau_search_edit_text.addTextChangedListener(object : TextWatcher {
+ kauSearchEditText.addTextChangedListener(object : TextWatcher {
override fun afterTextChanged(s: Editable?) {}
override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) {}
@@ -362,13 +345,13 @@ class SearchView @JvmOverloads constructor(
}
}
})
- kau_search_edit_text.setOnEditorActionListener { _, actionId, _ ->
+ kauSearchEditText.setOnEditorActionListener { _, actionId, _ ->
if (actionId == EditorInfo.IME_ACTION_SEARCH) {
- val query = kau_search_edit_text.text?.toString() ?: ""
- if (configs.searchCallback(query, this)) {
+ val query = kauSearchEditText.text?.toString() ?: ""
+ if (configs.searchCallback(query, this@SearchView)) {
revealClose()
} else {
- kau_search_edit_text.hideKeyboard()
+ kauSearchEditText.hideKeyboard()
}
return@setOnEditorActionListener true
}
@@ -382,13 +365,13 @@ 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
- TransitionSet().addTransition(ChangeBounds()).apply {
- duration = configs.transitionDuration
- builder()
- })
+ TransitionManager.beginDelayedTransition(binding.kauSearchCardview,
+ // 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()
+ })
}
/**
@@ -412,13 +395,13 @@ class SearchView @JvmOverloads constructor(
): SearchView {
config(config)
val menuItem = menu.findItem(id)
- ?: throw IllegalArgumentException("Menu item with given id doesn't exist")
+ ?: throw IllegalArgumentException("Menu item with given id doesn't exist")
if (menuItem.icon == null) {
menuItem.icon = GoogleMaterial.Icon.gmd_search.toDrawable(context, 18, menuIconColor)
}
- kau_search_cardview.gone()
+ binding.kauSearchCardview.gone()
menuItem.setOnMenuItemClickListener { revealOpen(); true }
- kau_search_shadow.setOnClickListener { revealClose() }
+ binding.kauSearchShadow.setOnClickListener { revealClose() }
this.menuItem = menuItem
return this
}
@@ -435,7 +418,7 @@ class SearchView @JvmOverloads constructor(
private val locations = IntArray(2)
- private fun configureCoords(item: MenuItem?) {
+ private fun KauSearchViewBinding.configureCoords(item: MenuItem?) {
item ?: return
if (parent !is ViewGroup) {
return
@@ -445,11 +428,11 @@ class SearchView @JvmOverloads constructor(
menuX = (locations[0] + view.width / 2)
menuHalfHeight = view.height / 2
menuY = (locations[1] + menuHalfHeight)
- kau_search_cardview.viewTreeObserver.addOnPreDrawListener(object :
- ViewTreeObserver.OnPreDrawListener {
+ kauSearchCardview.viewTreeObserver.addOnPreDrawListener(object :
+ ViewTreeObserver.OnPreDrawListener {
override fun onPreDraw(): Boolean {
view.viewTreeObserver.removeOnPreDrawListener(this)
- kau_search_cardview.setMarginTop(menuY - kau_search_cardview.height / 2)
+ kauSearchCardview.setMarginTop(menuY - kauSearchCardview.height / 2)
return true
}
})
@@ -472,12 +455,14 @@ class SearchView @JvmOverloads constructor(
* This can be done publicly through [configs], which will also save the color
*/
internal fun tintForeground(@ColorInt color: Int) {
- kau_search_nav.drawable.setTint(color)
- kau_search_clear.drawable.setTint(color)
- kau_search_divider.setBackgroundColor(color.adjustAlpha(0.1f))
- kau_search_edit_text.tint(color)
- kau_search_edit_text.setTextColor(ColorStateList.valueOf(color))
- kau_search_edit_text.setHintTextColor(color.adjustAlpha(0.7f))
+ with(binding) {
+ kauSearchNav.drawable.setTint(color)
+ kauSearchClear.drawable.setTint(color)
+ kauSearchDivider.setBackgroundColor(color.adjustAlpha(0.1f))
+ kauSearchEditText.tint(color)
+ kauSearchEditText.setTextColor(ColorStateList.valueOf(color))
+ kauSearchEditText.setHintTextColor(color.adjustAlpha(0.7f))
+ }
}
/**
@@ -485,14 +470,15 @@ class SearchView @JvmOverloads constructor(
* This can be done publicly through [configs], which will also save the color
*/
internal fun tintBackground(@ColorInt color: Int) {
- kau_search_cardview.setCardBackgroundColor(color)
+ binding.kauSearchCardview.setCardBackgroundColor(color)
}
fun revealOpen() {
if (parent == null || isOpen) {
return
}
- context.runOnUiThread {
+
+ fun KauSearchViewBinding.open() {
/**
* The y component is relative to the cardView, but it hasn't been drawn yet so its own height is 0
* We therefore use half the menuItem height, which is a close approximation to our intended value
@@ -500,41 +486,46 @@ class SearchView @JvmOverloads constructor(
*/
configureCoords(menuItem)
configs.openListener?.invoke(this@SearchView)
- kau_search_shadow.fadeIn()
- kau_search_edit_text.showKeyboard()
- kau_search_cardview.circularReveal(
- menuX,
- menuHalfHeight,
- duration = configs.revealDuration
+ kauSearchShadow.fadeIn()
+ kauSearchEditText.showKeyboard()
+ kauSearchCardview.circularReveal(
+ menuX,
+ menuHalfHeight,
+ duration = configs.revealDuration
) {
cardTransition()
- kau_search_recycler.visible()
+ kauSearchRecycler.visible()
}
}
+
+ context.runOnUiThread { binding.open() }
}
fun revealClose() {
if (parent == null || !isOpen) {
return
}
- context.runOnUiThread {
- kau_search_shadow.fadeOut(duration = configs.transitionDuration)
+
+ fun KauSearchViewBinding.close() {
+ kauSearchShadow.fadeOut(duration = configs.transitionDuration)
cardTransition {
addEndListener {
- kau_search_cardview.circularHide(menuX,
- menuHalfHeight,
- duration = configs.revealDuration,
- onFinish = {
- configs.closeListener?.invoke(this@SearchView)
- if (configs.shouldClearOnClose) {
- kau_search_edit_text.text?.clear()
- }
- })
+ kauSearchCardview.circularHide(menuX,
+ menuHalfHeight,
+ duration = configs.revealDuration,
+ onFinish = {
+ configs.closeListener?.invoke(this@SearchView)
+ if (configs.shouldClearOnClose) {
+ kauSearchEditText.text?.clear()
+ }
+ })
}
}
- kau_search_recycler.gone()
- kau_search_edit_text.hideKeyboard()
+ kauSearchRecycler.gone()
+ kauSearchEditText.hideKeyboard()
}
+
+ context.runOnUiThread { binding.close() }
}
}
@@ -551,7 +542,7 @@ fun Activity.bindSearchView(
@ColorInt menuIconColor: Int = Color.WHITE,
config: Configs.() -> Unit = {}
): SearchView =
- findViewById<ViewGroup>(android.R.id.content).bindSearchView(menu, id, menuIconColor, config)
+ findViewById<ViewGroup>(android.R.id.content).bindSearchView(menu, id, menuIconColor, config)
/**
* Bind searchView to a menu item; call this in [Activity.onCreateOptionsMenu]
@@ -567,10 +558,10 @@ fun ViewGroup.bindSearchView(
): 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/spotless.gradle b/spotless.gradle
index 22dba3a..ea95c38 100644
--- a/spotless.gradle
+++ b/spotless.gradle
@@ -1,9 +1,9 @@
-apply plugin: "com.diffplug.gradle.spotless"
+apply plugin: "com.diffplug.spotless"
spotless {
kotlin {
target "**/*.kt"
- ktlint()
+ ktlint().userData(["disabled_rules": "no-wildcard-imports"])
licenseHeaderFile '../spotless.license.kt'
trimTrailingWhitespace()
endWithNewline()