diff options
27 files changed, 346 insertions, 341 deletions
@@ -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 6e6eec1..79ee123 100644 --- a/.idea/codeStyles/codeStyleConfig.xml +++ b/.idea/codeStyles/codeStyleConfig.xml @@ -1,6 +1,5 @@ <component name="ProjectCodeStyleConfiguration"> <state> <option name="USE_PER_PROJECT_SETTINGS" value="true" /> - <option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" /> </state> </component>
\ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml deleted file mode 100644 index 61a9130..0000000 --- a/.idea/compiler.xml +++ /dev/null @@ -1,6 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project version="4"> - <component name="CompilerConfiguration"> - <bytecodeTargetLevel target="1.8" /> - </component> -</project>
\ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index 38dbd0c..0000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,48 +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="12"> - <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" /> - <item index="10" class="java.lang.String" itemvalue="com.android.annotations.Nullable" /> - <item index="11" class="java.lang.String" itemvalue="org.eclipse.jdt.annotation.Nullable" /> - </list> - </value> - </option> - <option name="myNotNulls"> - <value> - <list size="11"> - <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" /> - <item index="9" class="java.lang.String" itemvalue="com.android.annotations.NonNull" /> - <item index="10" class="java.lang.String" itemvalue="org.eclipse.jdt.annotation.NonNull" /> - </list> - </value> - </option> - </component> - <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" 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 index 7f68460..e497da9 100644 --- a/.idea/runConfigurations.xml +++ b/.idea/runConfigurations.xml @@ -3,6 +3,7 @@ <component name="RunConfigurationProducerService"> <option name="ignoredProducers"> <set> + <option value="com.android.tools.idea.compose.preview.runconfiguration.ComposePreviewRunConfigurationProducer" /> <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" /> 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 4fe97da..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,7 +35,6 @@ 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. @@ -51,7 +51,7 @@ 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 @@ -77,31 +77,38 @@ abstract class AboutActivityBase(val rClass: Class<*>?) : 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/android-lib.gradle b/android-lib.gradle index 429fd46..44ed40b 100644 --- a/android-lib.gradle +++ b/android-lib.gradle @@ -3,7 +3,7 @@ import kau.Versions apply plugin: 'com.android.library' apply plugin: 'kotlin-android' -apply plugin: 'kotlin-android-extensions' +apply plugin: 'kotlin-parcelize' apply plugin: 'com.github.dcendents.android-maven' //apply plugin: 'com.getkeepsafe.dexcount' group = "ca.allanwang" @@ -36,6 +36,10 @@ android { testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } + buildFeatures { + viewBinding = true + } + buildTypes { release { minifyEnabled false @@ -44,7 +48,7 @@ android { } lintOptions { - warningsAsErrors true + // warningsAsErrors true disable 'UnusedResources', 'ContentDescription', 'RtlSymmetry', @@ -62,6 +66,7 @@ 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 { diff --git a/buildSrc/src/main/kotlin/kau/Dependencies.kt b/buildSrc/src/main/kotlin/kau/Dependencies.kt index 18acccb..83f3d7b 100644 --- a/buildSrc/src/main/kotlin/kau/Dependencies.kt +++ b/buildSrc/src/main/kotlin/kau/Dependencies.kt @@ -71,6 +71,9 @@ object Dependencies { @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}" @@ -86,7 +89,7 @@ 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 = diff --git a/buildSrc/src/main/kotlin/kau/Versions.kt b/buildSrc/src/main/kotlin/kau/Versions.kt index c0118bc..56b6eaa 100644 --- a/buildSrc/src/main/kotlin/kau/Versions.kt +++ b/buildSrc/src/main/kotlin/kau/Versions.kt @@ -6,13 +6,13 @@ object Versions { const val targetSdk = 29 // https://mvnrepository.com/artifact/androidx.appcompat/appcompat?repo=google - const val appcompat = "1.2.0" + const val appcompat = "1.3.0-rc01" // https://mvnrepository.com/artifact/com.google.android.material/material - const val googleMaterial = "1.2.1" + 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.1.0" @@ -21,46 +21,50 @@ object Versions { const val cardView = "1.0.0" // https://mvnrepository.com/artifact/androidx.constraintlayout/constraintlayout - const val constraintLayout = "2.0.1" + const val constraintLayout = "2.1.0-beta01" // https://mvnrepository.com/artifact/androidx.core/core-ktx - const val coreKtx = "1.3.1" + const val coreKtx = "1.5.0-rc01" // https://kotlinlang.org/docs/reference/using-gradle.html - const val kotlin = "1.4.10" + const val kotlin = "1.4.32" // https://github.com/Kotlin/kotlinx.coroutines/releases - const val coroutines = "1.3.9" + const val coroutines = "1.4.3" // https://github.com/mikepenz/AboutLibraries/releases - const val aboutLibraries = "8.3.1" + const val aboutLibraries = "8.8.5" // https://github.com/wasabeef/Blurry/releases const val blurry = "3.0.0" // https://github.com/mikepenz/FastAdapter/releases - const val fastAdapter = "5.2.3" + const val fastAdapter = "5.4.1" // https://github.com/bumptech/glide/releases - const val glide = "4.11.0" + const val glide = "4.12.0" // https://github.com/mikepenz/Android-Iconics#1-provide-the-gradle-dependency - const val iconics = "5.0.3" - const val iconicsGoogle = "3.0.1.4" - const val iconicsMaterial = "2.2.0.6" - const val iconicsCommunity = "5.3.45.1" + const val iconics = "5.3.0-b01" + 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.3.0" // https://github.com/InsertKoinIO/koin/blob/master/CHANGELOG.md - const val koin = "2.2.0-beta-1" + const val koin = "3.0.1" + // https://github.com/google/dagger/releases // https://mvnrepository.com/artifact/com.google.dagger/hilt-android - const val hilt = "2.29.1-alpha" + const val hilt = "2.34.1-beta" + + // 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.4" + const val leakCanary = "2.7" // https://mvnrepository.com/artifact/androidx.test.espresso/espresso-core?repo=google const val espresso = "3.3.0" @@ -75,24 +79,26 @@ object Versions { const val testRules = "1.3.0" // https://github.com/diffplug/spotless/blob/master/plugin-gradle/CHANGES.md - const val spotless = "5.5.1" + const val spotless = "5.7.0" // https://github.com/bugsnag/bugsnag-android/releases - const val bugsnag = "5.2.0" + const val bugsnag = "5.9.0" // https://github.com/bugsnag/bugsnag-android-gradle-plugin/releases - const val bugsnagPlugin="5.2.0" + const val bugsnagPlugin="5.7.6" // https://mvnrepository.com/artifact/com.android.tools.build/gradle?repo=google - const val gradlePlugin = "4.1.0-rc03" + const val gradlePlugin = "4.2.0-rc01" + // https://github.com/dcendents/android-maven-gradle-plugin/releases const val mavenPlugin = "2.1" + // https://github.com/Triple-T/gradle-play-publisher/releases - const val playPublishPlugin = "3.0.0" + const val playPublishPlugin = "3.4.0-agp7.0" // https://github.com/KeepSafe/dexcount-gradle-plugin/releases - const val dexCountPlugin = "2.0.0-RC1" + const val dexCountPlugin = "2.0.0" // https://github.com/gladed/gradle-android-git-version/releases - const val gitVersionPlugin = "0.4.13" + 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/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/docs/Changelog.md b/docs/Changelog.md index fb05320..a4e3621 100644 --- a/docs/Changelog.md +++ b/docs/Changelog.md @@ -1,8 +1,14 @@ # Changelog +## v6.2.0 +* Add support for Android 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 and buganizer dependencies +* Breaking: Updated iconics, buganizer, and spotless dependencies (major version bump) ## v6.0.0 * Add support for Android 4.1.x diff --git a/fastadapter-viewbinding/build.gradle b/fastadapter-viewbinding/build.gradle index ad1a0a2..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 { - buildFeatures { - viewBinding = true - } -} - dependencies { implementation project(':core') diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 186b715..80cf08e 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.5-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-6.8-all.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists 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/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/BlurredImageView.kt b/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/BlurredImageView.kt index e430dff..8e78abf 100644 --- a/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/BlurredImageView.kt +++ b/mediapicker/src/main/kotlin/ca/allanwang/kau/mediapicker/BlurredImageView.kt @@ -18,12 +18,13 @@ 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 @@ -31,7 +32,6 @@ 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.* /** * Created by Allan Wang on 2017-07-14. @@ -51,12 +51,13 @@ 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) = @@ -88,10 +91,12 @@ class BlurredImageView @JvmOverloads constructor( factor.width = width factor.height = height BlurTask(imageBase, factor) { - image_blur.setImageDrawable(it) - scaleAnimate(ANIMATION_SCALE).start() - image_blur.alphaAnimate(1f).start() - image_foreground.alphaAnimate(1f).start() + with(binding) { + imageBlur.setImageDrawable(it) + scaleAnimate(ANIMATION_SCALE).start() + imageBlur.alphaAnimate(1f).start() + imageForeground.alphaAnimate(1f).start() + } }.execute() } @@ -107,10 +112,12 @@ class BlurredImageView @JvmOverloads constructor( factor.width = width factor.height = height BlurTask(imageBase, factor) { drawable -> - image_blur.setImageDrawable(drawable) - scaleXY = ANIMATION_SCALE - image_blur.alpha = 1f - image_foreground.alpha = 1f + with(binding) { + imageBlur.setImageDrawable(drawable) + scaleXY = ANIMATION_SCALE + imageBlur.alpha = 1f + imageForeground.alpha = 1f + } }.execute() } @@ -121,8 +128,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 +142,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 +174,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/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/sample/build.gradle b/sample/build.gradle index a39ee2d..9f2162f 100644 --- a/sample/build.gradle +++ b/sample/build.gradle @@ -3,7 +3,7 @@ import kau.Dependencies apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply plugin: 'kotlin-kapt' -apply plugin: 'kotlin-android-extensions' +apply plugin: 'kotlin-parcelize' //apply plugin: 'com.bugsnag.android.gradle' apply plugin: 'com.github.triplet.play' apply plugin: 'dagger.hilt.android.plugin' @@ -31,8 +31,8 @@ android { multiDexEnabled true testInstrumentationRunner "ca.allanwang.kau.sample.SampleTestRunner" } - buildFeatures { - viewBinding = true + viewBinding { + enabled true } def releaseSigning = file("../files/kau.properties") @@ -86,6 +86,7 @@ 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 { @@ -148,6 +149,6 @@ dependencies { androidTestImplementation Dependencies.espresso("contrib") androidTestImplementation Dependencies.testRules androidTestImplementation Dependencies.testRunner - testImplementation Dependencies.hiltTest - kaptTest Dependencies.hiltCompiler + 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 cc45b4e..fb360b9 100644 --- a/sample/src/androidTest/kotlin/ca/allanwang/kau/sample/KPrefViewTest.kt +++ b/sample/src/androidTest/kotlin/ca/allanwang/kau/sample/KPrefViewTest.kt @@ -28,7 +28,6 @@ import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.rule.ActivityTestRule import ca.allanwang.kau.sample.test.BaseTest import dagger.hilt.android.testing.HiltAndroidTest -import dagger.hilt.android.testing.UninstallModules import javax.inject.Inject import kotlin.test.assertFalse import kotlin.test.assertTrue @@ -50,7 +49,6 @@ import org.junit.runner.RunWith */ @RunWith(AndroidJUnit4::class) @HiltAndroidTest -@UninstallModules(PrefFactoryModule::class) class KPrefViewTest : BaseTest() { val activity: ActivityTestRule<MainActivity> = ActivityTestRule(MainActivity::class.java) diff --git a/sample/src/androidTest/kotlin/ca/allanwang/kau/sample/SampleTestApp.kt b/sample/src/androidTest/kotlin/ca/allanwang/kau/sample/SampleTestApp.kt index 89e74c7..f6ffdb1 100644 --- a/sample/src/androidTest/kotlin/ca/allanwang/kau/sample/SampleTestApp.kt +++ b/sample/src/androidTest/kotlin/ca/allanwang/kau/sample/SampleTestApp.kt @@ -22,8 +22,8 @@ import androidx.test.runner.AndroidJUnitRunner import dagger.hilt.EntryPoint import dagger.hilt.InstallIn import dagger.hilt.android.EntryPointAccessors -import dagger.hilt.android.components.ApplicationComponent 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 @@ -41,7 +41,7 @@ class SampleTestRunner : AndroidJUnitRunner() { class SampleTestRule : TestRule { @EntryPoint - @InstallIn(ApplicationComponent::class) + @InstallIn(SingletonComponent::class) interface SampleTestRuleEntryPoint { fun pref(): KPrefSample } 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 index 74da014..1615d2f 100644 --- a/sample/src/androidTest/kotlin/ca/allanwang/kau/sample/test/TestModules.kt +++ b/sample/src/androidTest/kotlin/ca/allanwang/kau/sample/test/TestModules.kt @@ -17,13 +17,16 @@ 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.InstallIn -import dagger.hilt.android.components.ApplicationComponent +import dagger.hilt.components.SingletonComponent +import dagger.hilt.testing.TestInstallIn @Module -@InstallIn(ApplicationComponent::class) +@TestInstallIn( + components = [SingletonComponent::class], + replaces = [PrefFactoryModule::class]) object PrefFactoryTestModule { @Provides fun factory(): KPrefFactory = KPrefFactoryInMemory 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 ee39184..970d3eb 100644 --- a/sample/src/main/kotlin/ca/allanwang/kau/sample/KPrefSample.kt +++ b/sample/src/main/kotlin/ca/allanwang/kau/sample/KPrefSample.kt @@ -23,8 +23,8 @@ import ca.allanwang.kau.kpref.KPrefFactoryAndroid import dagger.Module import dagger.Provides import dagger.hilt.InstallIn -import dagger.hilt.android.components.ApplicationComponent import dagger.hilt.android.qualifiers.ApplicationContext +import dagger.hilt.components.SingletonComponent /** * Created by Allan Wang on 2017-06-07. @@ -44,14 +44,14 @@ class KPrefSample(factory: KPrefFactory) : KPref("pref_sample", factory = factor } @Module -@InstallIn(ApplicationComponent::class) +@InstallIn(SingletonComponent::class) object PrefModule { @Provides fun pref(factory: KPrefFactory): KPrefSample = KPrefSample(factory) } @Module -@InstallIn(ApplicationComponent::class) +@InstallIn(SingletonComponent::class) object PrefFactoryModule { @Provides fun factory(@ApplicationContext context: Context): KPrefFactory = KPrefFactoryAndroid(context) diff --git a/sample/src/main/res/xml/kau_changelog.xml b/sample/src/main/res/xml/kau_changelog.xml index e88d697..c1648b0 100644 --- a/sample/src/main/res/xml/kau_changelog.xml +++ b/sample/src/main/res/xml/kau_changelog.xml @@ -6,6 +6,12 @@ <item text="" /> --> + <version title="v6.2.0" /> + <item text="Add support for Android 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)" /> 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 2947489..ea95c38 100644 --- a/spotless.gradle +++ b/spotless.gradle @@ -3,7 +3,7 @@ apply plugin: "com.diffplug.spotless" spotless { kotlin { target "**/*.kt" - ktlint() + ktlint().userData(["disabled_rules": "no-wildcard-imports"]) licenseHeaderFile '../spotless.license.kt' trimTrailingWhitespace() endWithNewline() |