From a380adea1052d39f23c9c4d432a9380ce347d6c4 Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Mon, 24 Dec 2018 00:27:25 -0500 Subject: Migrate to androidx (#178) * Initial refactor * Remove alpha version usages * Update test code * Add tests for checkbox * Fix invalid card import * Remove more old support content * Update kotlin version * Add back kotterknife with new imports * Update docs * Use bold notice * Add changelog * Remove deprecation for kotterknife * Remove unused dependencies * Update changelog --- core/build.gradle | 12 +- .../kotlin/ca/allanwang/kau/kpref/KPrefTest.kt | 9 +- .../ca/allanwang/kau/utils/KotterknifeTest.kt | 8 +- .../kotlin/ca/allanwang/kau/xml/FaqTest.kt | 15 ++- .../kotlin/ca/allanwang/kau/email/EmailBuilder.kt | 2 +- .../ca/allanwang/kau/internal/KauBaseActivity.kt | 2 +- .../kotlin/ca/allanwang/kau/kotlin/LazyContext.kt | 4 +- .../allanwang/kau/permissions/PermissionManager.kt | 2 +- .../ca/allanwang/kau/permissions/Permissions.kt | 2 +- .../ca/allanwang/kau/swipe/SwipeBackLayout.kt | 2 +- .../ca/allanwang/kau/swipe/ViewDragHelper.java | 4 +- .../ca/allanwang/kau/ui/SimpleRippleDrawable.kt | 4 +- .../kotlin/ca/allanwang/kau/utils/ActivityUtils.kt | 16 ++- .../kotlin/ca/allanwang/kau/utils/AnimHolder.kt | 2 +- .../kotlin/ca/allanwang/kau/utils/AnimUtils.kt | 2 +- .../kotlin/ca/allanwang/kau/utils/BundleUtils.kt | 2 +- .../kotlin/ca/allanwang/kau/utils/ColorUtils.kt | 12 +- .../main/kotlin/ca/allanwang/kau/utils/Const.kt | 3 +- .../kotlin/ca/allanwang/kau/utils/ContextUtils.kt | 4 +- .../kotlin/ca/allanwang/kau/utils/DrawableUtils.kt | 4 +- .../kotlin/ca/allanwang/kau/utils/FragmentUtils.kt | 2 +- .../kotlin/ca/allanwang/kau/utils/IIconUtils.kt | 2 +- .../kotlin/ca/allanwang/kau/utils/Kotterknife.kt | 135 ++++++--------------- .../ca/allanwang/kau/utils/NotificationUtils.kt | 2 +- .../kotlin/ca/allanwang/kau/utils/RecyclerUtils.kt | 2 +- .../ca/allanwang/kau/utils/TransitionUtils.kt | 14 +-- .../main/kotlin/ca/allanwang/kau/utils/Utils.kt | 2 +- .../kotlin/ca/allanwang/kau/utils/ViewUtils.kt | 20 +-- .../main/kotlin/ca/allanwang/kau/xml/Changelog.kt | 8 +- core/src/main/kotlin/ca/allanwang/kau/xml/FAQ.kt | 2 +- 30 files changed, 124 insertions(+), 176 deletions(-) (limited to 'core') diff --git a/core/build.gradle b/core/build.gradle index 046a734..a57ee6e 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -5,13 +5,11 @@ apply from: '../android-lib.gradle' dependencies { api kauDependency.kotlin - api "com.android.support:support-annotations:${kau.supportLibs}" - api "com.android.support:appcompat-v7:${kau.supportLibs}" - api "com.android.support:support-v13:${kau.supportLibs}" - api "com.android.support:design:${kau.supportLibs}" - api "com.android.support:recyclerview-v7:${kau.supportLibs}" - api "com.android.support:cardview-v7:${kau.supportLibs}" - api "com.android.support.constraint:constraint-layout:${kau.constraintLayout}" + api "androidx.appcompat:appcompat:${kau.appcompat}" + api "androidx.recyclerview:recyclerview:${kau.recyclerView}" + api "androidx.cardview:cardview:${kau.cardView}" + api "androidx.constraintlayout:constraintlayout:${kau.constraintLayout}" + api "com.google.android.material:material:${kau.googleMaterial}" api "com.mikepenz:iconics-core:${kau.iconics}@aar" api "com.mikepenz:google-material-typeface:${kau.iconicsGoogle}.original@aar" 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 2a9263a..52f344b 100644 --- a/core/src/androidTest/kotlin/ca/allanwang/kau/kpref/KPrefTest.kt +++ b/core/src/androidTest/kotlin/ca/allanwang/kau/kpref/KPrefTest.kt @@ -1,9 +1,10 @@ package ca.allanwang.kau.kpref import android.annotation.SuppressLint -import android.support.test.InstrumentationRegistry -import android.support.test.filters.MediumTest -import android.support.test.runner.AndroidJUnit4 +import android.content.Context +import androidx.test.core.app.ApplicationProvider +import androidx.test.ext.junit.runners.AndroidJUnit4 +import androidx.test.filters.MediumTest import org.junit.Before import org.junit.Test import org.junit.runner.RunWith @@ -23,7 +24,7 @@ class KPrefTest { class TestPref : KPref() { init { - initialize(InstrumentationRegistry.getTargetContext(), "kpref_test_${System.currentTimeMillis()}") + initialize(ApplicationProvider.getApplicationContext(), "kpref_test_${System.currentTimeMillis()}") } var one by kpref("one", 1) diff --git a/core/src/androidTest/kotlin/ca/allanwang/kau/utils/KotterknifeTest.kt b/core/src/androidTest/kotlin/ca/allanwang/kau/utils/KotterknifeTest.kt index 1dac92f..13a3c77 100644 --- a/core/src/androidTest/kotlin/ca/allanwang/kau/utils/KotterknifeTest.kt +++ b/core/src/androidTest/kotlin/ca/allanwang/kau/utils/KotterknifeTest.kt @@ -1,12 +1,12 @@ package ca.allanwang.kau.utils import android.content.Context -import android.support.test.InstrumentationRegistry -import android.support.test.filters.MediumTest -import android.support.test.runner.AndroidJUnit4 import android.view.View import android.widget.FrameLayout import android.widget.TextView +import androidx.test.ext.junit.runners.AndroidJUnit4 +import androidx.test.filters.MediumTest +import androidx.test.platform.app.InstrumentationRegistry import org.junit.Before import org.junit.Test import org.junit.runner.RunWith @@ -25,7 +25,7 @@ class KotterknifeTest { @Before fun init() { - context = InstrumentationRegistry.getContext() + context = InstrumentationRegistry.getInstrumentation().context } @Test diff --git a/core/src/androidTest/kotlin/ca/allanwang/kau/xml/FaqTest.kt b/core/src/androidTest/kotlin/ca/allanwang/kau/xml/FaqTest.kt index f9ce24b..7a6d2e0 100644 --- a/core/src/androidTest/kotlin/ca/allanwang/kau/xml/FaqTest.kt +++ b/core/src/androidTest/kotlin/ca/allanwang/kau/xml/FaqTest.kt @@ -1,8 +1,10 @@ package ca.allanwang.kau.xml -import android.support.test.InstrumentationRegistry -import android.support.test.filters.MediumTest -import android.support.test.runner.AndroidJUnit4 +import android.content.Context +import androidx.test.core.app.ApplicationProvider +import androidx.test.ext.junit.runners.AndroidJUnit4 +import androidx.test.filters.MediumTest +import ca.allanwang.kau.test.R import org.junit.Test import org.junit.runner.RunWith import kotlin.test.assertEquals @@ -14,9 +16,12 @@ import kotlin.test.assertEquals @MediumTest class FaqTest { + val context: Context + get() = ApplicationProvider.getApplicationContext() + @Test fun simpleTest() { - InstrumentationRegistry.getTargetContext().kauParseFaq(R.xml.test_faq) { data -> + context.kauParseFaq(R.xml.test_faq) { data -> assertEquals(2, data.size, "FAQ size is incorrect") assertEquals("1. This is a question", data.first().question.toString(), "First question does not match") assertEquals("This is an answer", data.first().answer.toString(), "First answer does not match") @@ -27,7 +32,7 @@ class FaqTest { @Test fun withoutNumbering() { - InstrumentationRegistry.getTargetContext().kauParseFaq(R.xml.test_faq, false) { data -> + context.kauParseFaq(R.xml.test_faq, false) { data -> assertEquals(2, data.size, "FAQ size is incorrect") assertEquals("This is a question", data.first().question.toString(), "First question does not match") assertEquals("This is an answer", data.first().answer.toString(), "First answer does not match") diff --git a/core/src/main/kotlin/ca/allanwang/kau/email/EmailBuilder.kt b/core/src/main/kotlin/ca/allanwang/kau/email/EmailBuilder.kt index dbdcf09..0184b9a 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/email/EmailBuilder.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/email/EmailBuilder.kt @@ -6,7 +6,7 @@ import android.content.Intent import android.content.pm.PackageManager import android.net.Uri import android.os.Build -import android.support.annotation.StringRes +import androidx.annotation.StringRes import android.util.DisplayMetrics import ca.allanwang.kau.R import ca.allanwang.kau.logging.KL diff --git a/core/src/main/kotlin/ca/allanwang/kau/internal/KauBaseActivity.kt b/core/src/main/kotlin/ca/allanwang/kau/internal/KauBaseActivity.kt index 87d94ce..c71761d 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/internal/KauBaseActivity.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/internal/KauBaseActivity.kt @@ -1,6 +1,6 @@ package ca.allanwang.kau.internal -import android.support.v7.app.AppCompatActivity +import androidx.appcompat.app.AppCompatActivity import ca.allanwang.kau.permissions.kauOnRequestPermissionsResult /** diff --git a/core/src/main/kotlin/ca/allanwang/kau/kotlin/LazyContext.kt b/core/src/main/kotlin/ca/allanwang/kau/kotlin/LazyContext.kt index 0a45b65..3d98633 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/kotlin/LazyContext.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/kotlin/LazyContext.kt @@ -1,8 +1,8 @@ package ca.allanwang.kau.kotlin import android.content.Context -import android.support.annotation.AnimRes -import android.support.annotation.InterpolatorRes +import androidx.annotation.AnimRes +import androidx.annotation.InterpolatorRes import android.view.animation.Animation import android.view.animation.AnimationUtils import android.view.animation.Interpolator diff --git a/core/src/main/kotlin/ca/allanwang/kau/permissions/PermissionManager.kt b/core/src/main/kotlin/ca/allanwang/kau/permissions/PermissionManager.kt index 36456ec..922dc09 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/permissions/PermissionManager.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/permissions/PermissionManager.kt @@ -3,7 +3,7 @@ package ca.allanwang.kau.permissions import android.app.Activity import android.content.Context import android.content.pm.PackageManager -import android.support.v4.app.ActivityCompat +import androidx.core.app.ActivityCompat import ca.allanwang.kau.kotlin.lazyContext import ca.allanwang.kau.logging.KL import ca.allanwang.kau.utils.KauException diff --git a/core/src/main/kotlin/ca/allanwang/kau/permissions/Permissions.kt b/core/src/main/kotlin/ca/allanwang/kau/permissions/Permissions.kt index 248e484..83cd2ed 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/permissions/Permissions.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/permissions/Permissions.kt @@ -4,7 +4,7 @@ import android.Manifest import android.app.Activity import android.content.Context import android.os.Build -import android.support.annotation.RequiresApi +import androidx.annotation.RequiresApi /** diff --git a/core/src/main/kotlin/ca/allanwang/kau/swipe/SwipeBackLayout.kt b/core/src/main/kotlin/ca/allanwang/kau/swipe/SwipeBackLayout.kt index a323e6c..4d7142c 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/swipe/SwipeBackLayout.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/swipe/SwipeBackLayout.kt @@ -4,7 +4,7 @@ import android.annotation.SuppressLint import android.app.Activity import android.content.Context import android.graphics.Canvas -import android.support.v4.view.ViewCompat +import androidx.core.view.ViewCompat import android.util.AttributeSet import android.view.MotionEvent import android.view.View diff --git a/core/src/main/kotlin/ca/allanwang/kau/swipe/ViewDragHelper.java b/core/src/main/kotlin/ca/allanwang/kau/swipe/ViewDragHelper.java index 566e9e5..ac7fb7e 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/swipe/ViewDragHelper.java +++ b/core/src/main/kotlin/ca/allanwang/kau/swipe/ViewDragHelper.java @@ -1,7 +1,7 @@ package ca.allanwang.kau.swipe; import android.content.Context; -import android.support.v4.view.ViewCompat; +import androidx.core.view.ViewCompat; import android.util.Log; import android.view.MotionEvent; import android.view.VelocityTracker; @@ -25,7 +25,7 @@ import static ca.allanwang.kau.swipe.SwipeBackHelperKt.SWIPE_EDGE_TOP; * of useful operations and state tracking for allowing a user to drag and reposition * views within their parent ViewGroup. *

- * This is an extension of {@link android.support.v4.widget.ViewDragHelper} + * This is an extension of {@link androidx.core.widget.ViewDragHelper} * Along with additional methods defined in {@link ViewDragHelperExtras} */ class ViewDragHelper implements ViewDragHelperExtras { diff --git a/core/src/main/kotlin/ca/allanwang/kau/ui/SimpleRippleDrawable.kt b/core/src/main/kotlin/ca/allanwang/kau/ui/SimpleRippleDrawable.kt index b92b222..4700162 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/ui/SimpleRippleDrawable.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/ui/SimpleRippleDrawable.kt @@ -4,8 +4,8 @@ import android.content.res.ColorStateList import android.graphics.drawable.ColorDrawable import android.graphics.drawable.RippleDrawable import android.os.Build -import android.support.annotation.ColorInt -import android.support.annotation.RequiresApi +import androidx.annotation.ColorInt +import androidx.annotation.RequiresApi import ca.allanwang.kau.utils.adjustAlpha /** diff --git a/core/src/main/kotlin/ca/allanwang/kau/utils/ActivityUtils.kt b/core/src/main/kotlin/ca/allanwang/kau/utils/ActivityUtils.kt index ab0e59f..eab9536 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/utils/ActivityUtils.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/utils/ActivityUtils.kt @@ -11,13 +11,13 @@ import android.content.Intent import android.graphics.Color import android.os.Build import android.os.Bundle -import android.support.annotation.ColorInt -import android.support.annotation.RequiresApi -import android.support.annotation.StringRes -import android.support.design.widget.Snackbar import android.view.Menu import android.view.View +import androidx.annotation.ColorInt +import androidx.annotation.RequiresApi +import androidx.annotation.StringRes import ca.allanwang.kau.R +import com.google.android.material.snackbar.Snackbar import com.mikepenz.iconics.typeface.IIcon import org.jetbrains.anko.contentView @@ -135,9 +135,13 @@ fun Context.setMenuIcons(menu: Menu, @ColorInt color: Int = Color.WHITE, vararg } } -inline fun Activity.hideKeyboard() = currentFocus.hideKeyboard() +inline fun Activity.hideKeyboard() { + currentFocus?.hideKeyboard() +} -inline fun Activity.showKeyboard() = currentFocus.showKeyboard() +inline fun Activity.showKeyboard() { + currentFocus?.showKeyboard() +} inline fun Activity.snackbar(text: String, duration: Int = Snackbar.LENGTH_LONG, noinline builder: Snackbar.() -> Unit = {}) = contentView!!.snackbar(text, duration, builder) diff --git a/core/src/main/kotlin/ca/allanwang/kau/utils/AnimHolder.kt b/core/src/main/kotlin/ca/allanwang/kau/utils/AnimHolder.kt index 2767f04..b988085 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/utils/AnimHolder.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/utils/AnimHolder.kt @@ -1,7 +1,7 @@ package ca.allanwang.kau.utils import android.os.Build -import android.support.annotation.RequiresApi +import androidx.annotation.RequiresApi import ca.allanwang.kau.kotlin.lazyInterpolator /** diff --git a/core/src/main/kotlin/ca/allanwang/kau/utils/AnimUtils.kt b/core/src/main/kotlin/ca/allanwang/kau/utils/AnimUtils.kt index a287cf2..d8e4681 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/utils/AnimUtils.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/utils/AnimUtils.kt @@ -3,7 +3,7 @@ package ca.allanwang.kau.utils import android.animation.Animator import android.animation.AnimatorListenerAdapter import android.annotation.SuppressLint -import android.support.annotation.StringRes +import androidx.annotation.StringRes import android.view.View import android.view.ViewAnimationUtils import android.view.ViewPropertyAnimator diff --git a/core/src/main/kotlin/ca/allanwang/kau/utils/BundleUtils.kt b/core/src/main/kotlin/ca/allanwang/kau/utils/BundleUtils.kt index 82cd577..d628214 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/utils/BundleUtils.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/utils/BundleUtils.kt @@ -5,7 +5,7 @@ import android.app.Activity import android.app.ActivityOptions import android.content.Context import android.os.Bundle -import android.support.annotation.AnimRes +import androidx.annotation.AnimRes import android.util.Pair import android.view.View import ca.allanwang.kau.R diff --git a/core/src/main/kotlin/ca/allanwang/kau/utils/ColorUtils.kt b/core/src/main/kotlin/ca/allanwang/kau/utils/ColorUtils.kt index 236f2ca..f010c6f 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/utils/ColorUtils.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/utils/ColorUtils.kt @@ -7,12 +7,12 @@ import android.graphics.Color import android.graphics.PorterDuff import android.graphics.drawable.Drawable import android.os.Build -import android.support.annotation.ColorInt -import android.support.annotation.FloatRange -import android.support.annotation.IntRange -import android.support.v4.graphics.drawable.DrawableCompat -import android.support.v7.widget.AppCompatEditText -import android.support.v7.widget.Toolbar +import androidx.annotation.ColorInt +import androidx.annotation.FloatRange +import androidx.annotation.IntRange +import androidx.core.graphics.drawable.DrawableCompat +import androidx.appcompat.widget.AppCompatEditText +import androidx.appcompat.widget.Toolbar import android.widget.* import com.afollestad.materialdialogs.R import java.util.* diff --git a/core/src/main/kotlin/ca/allanwang/kau/utils/Const.kt b/core/src/main/kotlin/ca/allanwang/kau/utils/Const.kt index 1eeac1a..eb09093 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/utils/Const.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/utils/Const.kt @@ -1,6 +1,7 @@ package ca.allanwang.kau.utils -import android.support.v4.widget.ViewDragHelper +import androidx.customview.widget.ViewDragHelper + /** * Created by Allan Wang on 2017-06-08. diff --git a/core/src/main/kotlin/ca/allanwang/kau/utils/ContextUtils.kt b/core/src/main/kotlin/ca/allanwang/kau/utils/ContextUtils.kt index 6568bf2..f6e9ac7 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/utils/ContextUtils.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/utils/ContextUtils.kt @@ -11,8 +11,8 @@ import android.content.pm.PackageManager import android.graphics.drawable.Drawable import android.net.Uri import android.os.Bundle -import android.support.annotation.* -import android.support.v4.content.ContextCompat +import androidx.annotation.* +import androidx.core.content.ContextCompat import android.util.TypedValue import android.view.View import android.view.animation.AnimationUtils diff --git a/core/src/main/kotlin/ca/allanwang/kau/utils/DrawableUtils.kt b/core/src/main/kotlin/ca/allanwang/kau/utils/DrawableUtils.kt index dae3bff..59e684a 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/utils/DrawableUtils.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/utils/DrawableUtils.kt @@ -2,8 +2,8 @@ package ca.allanwang.kau.utils import android.content.res.ColorStateList import android.graphics.drawable.Drawable -import android.support.annotation.ColorInt -import android.support.v4.graphics.drawable.DrawableCompat +import androidx.annotation.ColorInt +import androidx.core.graphics.drawable.DrawableCompat /** * Wrap the color into a state and tint the drawable diff --git a/core/src/main/kotlin/ca/allanwang/kau/utils/FragmentUtils.kt b/core/src/main/kotlin/ca/allanwang/kau/utils/FragmentUtils.kt index acc71f2..f99b342 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/utils/FragmentUtils.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/utils/FragmentUtils.kt @@ -1,6 +1,6 @@ package ca.allanwang.kau.utils -import android.support.v4.app.Fragment +import androidx.fragment.app.Fragment import org.jetbrains.anko.bundleOf /** diff --git a/core/src/main/kotlin/ca/allanwang/kau/utils/IIconUtils.kt b/core/src/main/kotlin/ca/allanwang/kau/utils/IIconUtils.kt index 51691af..66c56f8 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/utils/IIconUtils.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/utils/IIconUtils.kt @@ -4,7 +4,7 @@ import android.content.Context import android.content.res.ColorStateList import android.graphics.Color import android.graphics.drawable.Drawable -import android.support.annotation.ColorInt +import androidx.annotation.ColorInt import com.mikepenz.iconics.IconicsDrawable import com.mikepenz.iconics.typeface.IIcon diff --git a/core/src/main/kotlin/ca/allanwang/kau/utils/Kotterknife.kt b/core/src/main/kotlin/ca/allanwang/kau/utils/Kotterknife.kt index 8c7c039..3cbd93d 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/utils/Kotterknife.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/utils/Kotterknife.kt @@ -1,4 +1,4 @@ -@file:Suppress("UNCHECKED_CAST") +@file:Suppress("UNCHECKED_CAST", "DEPRECATION") package ca.allanwang.kau.utils @@ -8,146 +8,118 @@ package ca.allanwang.kau.utils * Courtesy of Jake Wharton * * https://github.com/JakeWharton/kotterknife/blob/master/src/main/kotlin/kotterknife/ButterKnife.kt + * + * Note that while this is useful for binding ids, there also exists other alternatives, such as + * `kotlin-android-extensions`. + * + * For fragments, make sure that the views are reset after the fragment lifecycle. */ import android.app.Activity import android.app.Dialog import android.app.DialogFragment import android.app.Fragment -import android.support.v7.widget.RecyclerView.ViewHolder import android.view.View +import androidx.recyclerview.widget.RecyclerView +import androidx.recyclerview.widget.RecyclerView.ViewHolder import java.util.* import kotlin.properties.ReadOnlyProperty import kotlin.reflect.KProperty -import android.support.v4.app.DialogFragment as SupportDialogFragment -import android.support.v4.app.Fragment as SupportFragment +import androidx.fragment.app.DialogFragment as SupportDialogFragment +import androidx.fragment.app.Fragment as SupportFragment -private const val DEPRECATION_MESSAGE = "Kotterknife will be removed in favour of the kotlin_android_extensions plugin" - -@Deprecated(DEPRECATION_MESSAGE) fun View.bindView(id: Int) : ReadOnlyProperty = required(id, viewFinder) -@Deprecated(DEPRECATION_MESSAGE) fun Activity.bindView(id: Int) : ReadOnlyProperty = required(id, viewFinder) -@Deprecated(DEPRECATION_MESSAGE) fun Dialog.bindView(id: Int) : ReadOnlyProperty = required(id, viewFinder) -@Deprecated(DEPRECATION_MESSAGE) fun DialogFragment.bindView(id: Int) : ReadOnlyProperty = required(id, viewFinder) -@Deprecated(DEPRECATION_MESSAGE) fun SupportDialogFragment.bindView(id: Int) - : ReadOnlyProperty = required(id, viewFinder) + : ReadOnlyProperty = required(id, viewFinder) -@Deprecated(DEPRECATION_MESSAGE) fun Fragment.bindView(id: Int) : ReadOnlyProperty = required(id, viewFinder) -@Deprecated(DEPRECATION_MESSAGE) fun SupportFragment.bindView(id: Int) - : ReadOnlyProperty = required(id, viewFinder) + : ReadOnlyProperty = required(id, viewFinder) -@Deprecated(DEPRECATION_MESSAGE) -fun ViewHolder.bindView(id: Int) - : ReadOnlyProperty = required(id, viewFinder) +fun RecyclerView.ViewHolder.bindView(id: Int) + : ReadOnlyProperty = required(id, viewFinder) -@Deprecated(DEPRECATION_MESSAGE) fun View.bindOptionalView(id: Int) : ReadOnlyProperty = optional(id, viewFinder) -@Deprecated(DEPRECATION_MESSAGE) fun Activity.bindOptionalView(id: Int) : ReadOnlyProperty = optional(id, viewFinder) -@Deprecated(DEPRECATION_MESSAGE) fun Dialog.bindOptionalView(id: Int) : ReadOnlyProperty = optional(id, viewFinder) -@Deprecated(DEPRECATION_MESSAGE) fun DialogFragment.bindOptionalView(id: Int) : ReadOnlyProperty = optional(id, viewFinder) -@Deprecated(DEPRECATION_MESSAGE) fun SupportDialogFragment.bindOptionalView(id: Int) - : ReadOnlyProperty = optional(id, viewFinder) + : ReadOnlyProperty = optional(id, viewFinder) -@Deprecated(DEPRECATION_MESSAGE) fun Fragment.bindOptionalView(id: Int) : ReadOnlyProperty = optional(id, viewFinder) -@Deprecated(DEPRECATION_MESSAGE) fun SupportFragment.bindOptionalView(id: Int) - : ReadOnlyProperty = optional(id, viewFinder) + : ReadOnlyProperty = optional(id, viewFinder) -@Deprecated(DEPRECATION_MESSAGE) -fun ViewHolder.bindOptionalView(id: Int) - : ReadOnlyProperty = optional(id, viewFinder) +fun RecyclerView.ViewHolder.bindOptionalView(id: Int) + : ReadOnlyProperty = optional(id, viewFinder) -@Deprecated(DEPRECATION_MESSAGE) fun View.bindViews(vararg ids: Int) : ReadOnlyProperty> = required(ids, viewFinder) -@Deprecated(DEPRECATION_MESSAGE) fun Activity.bindViews(vararg ids: Int) : ReadOnlyProperty> = required(ids, viewFinder) -@Deprecated(DEPRECATION_MESSAGE) fun Dialog.bindViews(vararg ids: Int) : ReadOnlyProperty> = required(ids, viewFinder) -@Deprecated(DEPRECATION_MESSAGE) fun DialogFragment.bindViews(vararg ids: Int) : ReadOnlyProperty> = required(ids, viewFinder) -@Deprecated(DEPRECATION_MESSAGE) fun SupportDialogFragment.bindViews(vararg ids: Int) - : ReadOnlyProperty> = required(ids, viewFinder) + : ReadOnlyProperty> = required(ids, viewFinder) -@Deprecated(DEPRECATION_MESSAGE) fun Fragment.bindViews(vararg ids: Int) : ReadOnlyProperty> = required(ids, viewFinder) -@Deprecated(DEPRECATION_MESSAGE) fun SupportFragment.bindViews(vararg ids: Int) - : ReadOnlyProperty> = required(ids, viewFinder) + : ReadOnlyProperty> = required(ids, viewFinder) -@Deprecated(DEPRECATION_MESSAGE) fun ViewHolder.bindViews(vararg ids: Int) : ReadOnlyProperty> = required(ids, viewFinder) -@Deprecated(DEPRECATION_MESSAGE) fun View.bindOptionalViews(vararg ids: Int) : ReadOnlyProperty> = optional(ids, viewFinder) -@Deprecated(DEPRECATION_MESSAGE) fun Activity.bindOptionalViews(vararg ids: Int) : ReadOnlyProperty> = optional(ids, viewFinder) -@Deprecated(DEPRECATION_MESSAGE) fun Dialog.bindOptionalViews(vararg ids: Int) : ReadOnlyProperty> = optional(ids, viewFinder) -@Deprecated(DEPRECATION_MESSAGE) fun DialogFragment.bindOptionalViews(vararg ids: Int) : ReadOnlyProperty> = optional(ids, viewFinder) -@Deprecated(DEPRECATION_MESSAGE) fun SupportDialogFragment.bindOptionalViews(vararg ids: Int) - : ReadOnlyProperty> = optional(ids, viewFinder) + : ReadOnlyProperty> = optional(ids, viewFinder) -@Deprecated(DEPRECATION_MESSAGE) fun Fragment.bindOptionalViews(vararg ids: Int) : ReadOnlyProperty> = optional(ids, viewFinder) -@Deprecated(DEPRECATION_MESSAGE) fun SupportFragment.bindOptionalViews(vararg ids: Int) - : ReadOnlyProperty> = optional(ids, viewFinder) + : ReadOnlyProperty> = optional(ids, viewFinder) -@Deprecated(DEPRECATION_MESSAGE) fun ViewHolder.bindOptionalViews(vararg ids: Int) : ReadOnlyProperty> = optional(ids, viewFinder) @@ -189,13 +161,13 @@ private fun optional(ids: IntArray, finder: T.(Int) -> View?) = La private open class Lazy(private val initializer: (T, KProperty<*>) -> V) : ReadOnlyProperty { protected object EMPTY - protected var value: Any? = EMPTY +protected var value: Any? = EMPTY - override fun getValue(thisRef: T, property: KProperty<*>): V { +override fun getValue(thisRef: T, property: KProperty<*>): V { if (value == EMPTY) value = initializer(thisRef, property) - return value as V +return value as V } } @@ -209,133 +181,101 @@ private open class Lazy(private val initializer: (T, KProperty<*>) * Credits to MichaelRocks */ -@Deprecated(DEPRECATION_MESSAGE) fun View.bindViewResettable(id: Int) : ReadOnlyProperty = requiredResettable(id, viewFinder) -@Deprecated(DEPRECATION_MESSAGE) fun Activity.bindViewResettable(id: Int) : ReadOnlyProperty = requiredResettable(id, viewFinder) -@Deprecated(DEPRECATION_MESSAGE) fun Dialog.bindViewResettable(id: Int) : ReadOnlyProperty = requiredResettable(id, viewFinder) -@Deprecated(DEPRECATION_MESSAGE) fun DialogFragment.bindViewResettable(id: Int) : ReadOnlyProperty = requiredResettable(id, viewFinder) -@Deprecated(DEPRECATION_MESSAGE) fun SupportDialogFragment.bindViewResettable(id: Int) - : ReadOnlyProperty = requiredResettable(id, viewFinder) + : ReadOnlyProperty = requiredResettable(id, viewFinder) -@Deprecated(DEPRECATION_MESSAGE) fun Fragment.bindViewResettable(id: Int) : ReadOnlyProperty = requiredResettable(id, viewFinder) -@Deprecated(DEPRECATION_MESSAGE) fun SupportFragment.bindViewResettable(id: Int) - : ReadOnlyProperty = requiredResettable(id, viewFinder) + : ReadOnlyProperty = requiredResettable(id, viewFinder) -@Deprecated(DEPRECATION_MESSAGE) fun ViewHolder.bindViewResettable(id: Int) : ReadOnlyProperty = requiredResettable(id, viewFinder) -@Deprecated(DEPRECATION_MESSAGE) fun View.bindOptionalViewResettable(id: Int) : ReadOnlyProperty = optionalResettable(id, viewFinder) -@Deprecated(DEPRECATION_MESSAGE) fun Activity.bindOptionalViewResettable(id: Int) : ReadOnlyProperty = optionalResettable(id, viewFinder) -@Deprecated(DEPRECATION_MESSAGE) fun Dialog.bindOptionalViewResettable(id: Int) : ReadOnlyProperty = optionalResettable(id, viewFinder) -@Deprecated(DEPRECATION_MESSAGE) fun DialogFragment.bindOptionalViewResettable(id: Int) : ReadOnlyProperty = optionalResettable(id, viewFinder) -@Deprecated(DEPRECATION_MESSAGE) fun SupportDialogFragment.bindOptionalViewResettable(id: Int) - : ReadOnlyProperty = optionalResettable(id, viewFinder) + : ReadOnlyProperty = optionalResettable(id, viewFinder) -@Deprecated(DEPRECATION_MESSAGE) fun Fragment.bindOptionalViewResettable(id: Int) : ReadOnlyProperty = optionalResettable(id, viewFinder) -@Deprecated(DEPRECATION_MESSAGE) fun SupportFragment.bindOptionalViewResettable(id: Int) - : ReadOnlyProperty = optionalResettable(id, viewFinder) + : ReadOnlyProperty = optionalResettable(id, viewFinder) -@Deprecated(DEPRECATION_MESSAGE) fun ViewHolder.bindOptionalViewResettable(id: Int) : ReadOnlyProperty = optionalResettable(id, viewFinder) -@Deprecated(DEPRECATION_MESSAGE) fun View.bindViewsResettable(vararg ids: Int) : ReadOnlyProperty> = requiredResettable(ids, viewFinder) -@Deprecated(DEPRECATION_MESSAGE) fun Activity.bindViewsResettable(vararg ids: Int) : ReadOnlyProperty> = requiredResettable(ids, viewFinder) -@Deprecated(DEPRECATION_MESSAGE) fun Dialog.bindViewsResettable(vararg ids: Int) : ReadOnlyProperty> = requiredResettable(ids, viewFinder) -@Deprecated(DEPRECATION_MESSAGE) fun DialogFragment.bindViewsResettable(vararg ids: Int) : ReadOnlyProperty> = requiredResettable(ids, viewFinder) -@Deprecated(DEPRECATION_MESSAGE) fun SupportDialogFragment.bindViewsResettable(vararg ids: Int) - : ReadOnlyProperty> = requiredResettable(ids, viewFinder) + : ReadOnlyProperty> = requiredResettable(ids, viewFinder) -@Deprecated(DEPRECATION_MESSAGE) fun Fragment.bindViewsResettable(vararg ids: Int) : ReadOnlyProperty> = requiredResettable(ids, viewFinder) -@Deprecated(DEPRECATION_MESSAGE) fun SupportFragment.bindViewsResettable(vararg ids: Int) - : ReadOnlyProperty> = requiredResettable(ids, viewFinder) + : ReadOnlyProperty> = requiredResettable(ids, viewFinder) -@Deprecated(DEPRECATION_MESSAGE) fun ViewHolder.bindViewsResettable(vararg ids: Int) : ReadOnlyProperty> = requiredResettable(ids, viewFinder) -@Deprecated(DEPRECATION_MESSAGE) fun View.bindOptionalViewsResettable(vararg ids: Int) : ReadOnlyProperty> = optionalResettable(ids, viewFinder) -@Deprecated(DEPRECATION_MESSAGE) fun Activity.bindOptionalViewsResettable(vararg ids: Int) : ReadOnlyProperty> = optionalResettable(ids, viewFinder) -@Deprecated(DEPRECATION_MESSAGE) fun Dialog.bindOptionalViewsResettable(vararg ids: Int) : ReadOnlyProperty> = optionalResettable(ids, viewFinder) -@Deprecated(DEPRECATION_MESSAGE) fun DialogFragment.bindOptionalViewsResettable(vararg ids: Int) : ReadOnlyProperty> = optionalResettable(ids, viewFinder) -@Deprecated(DEPRECATION_MESSAGE) fun SupportDialogFragment.bindOptionalViewsResettable(vararg ids: Int) - : ReadOnlyProperty> = optionalResettable(ids, viewFinder) + : ReadOnlyProperty> = optionalResettable(ids, viewFinder) -@Deprecated(DEPRECATION_MESSAGE) fun Fragment.bindOptionalViewsResettable(vararg ids: Int) : ReadOnlyProperty> = optionalResettable(ids, viewFinder) -@Deprecated(DEPRECATION_MESSAGE) fun SupportFragment.bindOptionalViewsResettable(vararg ids: Int) - : ReadOnlyProperty> = optionalResettable(ids, viewFinder) + : ReadOnlyProperty> = optionalResettable(ids, viewFinder) -@Deprecated(DEPRECATION_MESSAGE) fun ViewHolder.bindOptionalViewsResettable(vararg ids: Int) - : ReadOnlyProperty> = optionalResettable(ids, viewFinder) + : ReadOnlyProperty> = optionalResettable(ids, viewFinder) private fun requiredResettable(id: Int, finder: T.(Int) -> View?) = LazyResettable { t: T, desc -> (t.finder(id) as V?)?.apply { } ?: viewNotFound(id, desc) @@ -358,12 +298,11 @@ private class LazyResettable(initializer: (T, KProperty<*>) -> V) : return super.getValue(thisRef, property) } - fun reset() { +fun reset() { value = EMPTY } } -@Deprecated(DEPRECATION_MESSAGE) object Kotterknife { fun reset(target: Any) { KotterknifeRegistry.reset(target) @@ -373,7 +312,7 @@ object Kotterknife { private object KotterknifeRegistry { private val lazyMap = WeakHashMap>>() - fun register(target: Any, lazy: LazyResettable<*, *>) = lazyMap.getOrPut(target, { Collections.newSetFromMap(WeakHashMap()) }).add(lazy) +fun register(target: Any, lazy: LazyResettable<*, *>) = lazyMap.getOrPut(target, { Collections.newSetFromMap(WeakHashMap()) }).add(lazy) - fun reset(target: Any) = lazyMap[target]?.forEach(LazyResettable<*, *>::reset) +fun reset(target: Any) = lazyMap[target]?.forEach(LazyResettable<*, *>::reset) } \ No newline at end of file diff --git a/core/src/main/kotlin/ca/allanwang/kau/utils/NotificationUtils.kt b/core/src/main/kotlin/ca/allanwang/kau/utils/NotificationUtils.kt index 1eb0076..016f3d2 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/utils/NotificationUtils.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/utils/NotificationUtils.kt @@ -1,7 +1,7 @@ package ca.allanwang.kau.utils import android.content.Context -import android.support.v4.app.NotificationManagerCompat +import androidx.core.app.NotificationManagerCompat /** diff --git a/core/src/main/kotlin/ca/allanwang/kau/utils/RecyclerUtils.kt b/core/src/main/kotlin/ca/allanwang/kau/utils/RecyclerUtils.kt index 3a34db5..1c336f9 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/utils/RecyclerUtils.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/utils/RecyclerUtils.kt @@ -1,8 +1,8 @@ package ca.allanwang.kau.utils import android.graphics.Rect -import android.support.v7.widget.RecyclerView import android.view.View +import androidx.recyclerview.widget.RecyclerView /** * Created by Allan Wang on 2017-07-11. diff --git a/core/src/main/kotlin/ca/allanwang/kau/utils/TransitionUtils.kt b/core/src/main/kotlin/ca/allanwang/kau/utils/TransitionUtils.kt index ec206ee..1d12fd3 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/utils/TransitionUtils.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/utils/TransitionUtils.kt @@ -1,14 +1,14 @@ package ca.allanwang.kau.utils import android.os.Build -import android.support.annotation.RequiresApi -import android.support.annotation.TransitionRes -import android.support.transition.AutoTransition -import android.support.transition.TransitionInflater -import android.support.transition.TransitionManager +import androidx.annotation.RequiresApi +import androidx.annotation.TransitionRes +import androidx.transition.AutoTransition +import androidx.transition.TransitionInflater +import androidx.transition.TransitionManager import android.transition.Transition import android.view.ViewGroup -import android.support.transition.Transition as SupportTransition +import androidx.transition.Transition as SupportTransition /** * Created by Allan Wang on 2017-06-24. @@ -52,7 +52,7 @@ fun ViewGroup.transitionAuto(builder: AutoTransition.() -> Unit = {}) { } @KauUtils -fun ViewGroup.transitionDelayed(@TransitionRes id: Int, builder: android.support.transition.Transition.() -> Unit = {}) { +fun ViewGroup.transitionDelayed(@TransitionRes id: Int, builder: androidx.transition.Transition.() -> Unit = {}) { if (!buildIsLollipopAndUp) return val transition = TransitionInflater.from(context).inflateTransition(id) transition.builder() diff --git a/core/src/main/kotlin/ca/allanwang/kau/utils/Utils.kt b/core/src/main/kotlin/ca/allanwang/kau/utils/Utils.kt index 46e29b2..c8d5d2a 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/utils/Utils.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/utils/Utils.kt @@ -8,7 +8,7 @@ import android.graphics.drawable.BitmapDrawable import android.graphics.drawable.Drawable import android.os.Handler import android.os.Looper -import android.support.annotation.IntRange +import androidx.annotation.IntRange import ca.allanwang.kau.R import java.math.RoundingMode import java.text.DecimalFormat diff --git a/core/src/main/kotlin/ca/allanwang/kau/utils/ViewUtils.kt b/core/src/main/kotlin/ca/allanwang/kau/utils/ViewUtils.kt index 4e020bc..956df48 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/utils/ViewUtils.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/utils/ViewUtils.kt @@ -7,15 +7,10 @@ import android.annotation.SuppressLint import android.content.Context import android.graphics.Color import android.os.Build -import android.support.annotation.ColorInt -import android.support.annotation.ColorRes -import android.support.annotation.RequiresApi -import android.support.annotation.StringRes -import android.support.design.widget.FloatingActionButton -import android.support.design.widget.Snackbar -import android.support.design.widget.TextInputEditText -import android.support.v7.widget.LinearLayoutManager -import android.support.v7.widget.RecyclerView +import androidx.annotation.ColorInt +import androidx.annotation.ColorRes +import androidx.annotation.RequiresApi +import androidx.annotation.StringRes import android.view.LayoutInflater import android.view.MotionEvent import android.view.View @@ -23,7 +18,12 @@ import android.view.ViewGroup import android.view.inputmethod.InputMethodManager import android.widget.EditText import android.widget.ImageView +import androidx.recyclerview.widget.LinearLayoutManager +import androidx.recyclerview.widget.RecyclerView import ca.allanwang.kau.ui.createSimpleRippleDrawable +import com.google.android.material.floatingactionbutton.FloatingActionButton +import com.google.android.material.snackbar.Snackbar +import com.google.android.material.textfield.TextInputEditText import com.mikepenz.iconics.IconicsDrawable import com.mikepenz.iconics.typeface.IIcon @@ -291,7 +291,7 @@ fun FloatingActionButton.hideOnDownwardsScroll(recycler: RecyclerView) { recycler.addOnScrollListener(object : RecyclerView.OnScrollListener() { override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) { - if (newState == android.support.v7.widget.RecyclerView.SCROLL_STATE_IDLE && !isShown) show() + if (newState == RecyclerView.SCROLL_STATE_IDLE && !isShown) show() } override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) { diff --git a/core/src/main/kotlin/ca/allanwang/kau/xml/Changelog.kt b/core/src/main/kotlin/ca/allanwang/kau/xml/Changelog.kt index 28d51a4..3955a77 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/xml/Changelog.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/xml/Changelog.kt @@ -2,14 +2,14 @@ package ca.allanwang.kau.xml import android.content.Context import android.content.res.XmlResourceParser -import android.support.annotation.ColorInt -import android.support.annotation.LayoutRes -import android.support.annotation.XmlRes -import android.support.v7.widget.RecyclerView +import androidx.annotation.ColorInt +import androidx.annotation.LayoutRes +import androidx.annotation.XmlRes import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.widget.TextView +import androidx.recyclerview.widget.RecyclerView import ca.allanwang.kau.R import ca.allanwang.kau.utils.materialDialog import ca.allanwang.kau.utils.use diff --git a/core/src/main/kotlin/ca/allanwang/kau/xml/FAQ.kt b/core/src/main/kotlin/ca/allanwang/kau/xml/FAQ.kt index 7caf5d6..bbe9425 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/xml/FAQ.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/xml/FAQ.kt @@ -2,7 +2,7 @@ package ca.allanwang.kau.xml import android.content.Context import android.content.res.XmlResourceParser -import android.support.annotation.XmlRes +import androidx.annotation.XmlRes import android.text.Html import android.text.Spanned import ca.allanwang.kau.utils.use -- cgit v1.2.3