From 62474a62fb54ae8e67a2c849f985f989f025bd20 Mon Sep 17 00:00:00 2001 From: Aidan Follestad Date: Sat, 15 Sep 2018 13:02:26 -0700 Subject: [PATCH] Upgrade to use AndroidX libraries, resolves #88 --- README.md | 15 +- dependencies.gradle | 9 +- gradle.properties | 3 + library/build.gradle | 16 +- library/proguard-rules.pro | 25 --- .../com/afollestad/aesthetic/Aesthetic.kt | 18 +- .../aesthetic/AestheticActionMenuItemView.kt | 2 +- .../afollestad/aesthetic/AestheticActivity.kt | 2 +- .../aesthetic/AestheticBorderlessButton.kt | 2 +- .../AestheticBottomNavigationView.kt | 28 ++- .../afollestad/aesthetic/AestheticButton.kt | 6 +- .../afollestad/aesthetic/AestheticCardView.kt | 6 +- .../afollestad/aesthetic/AestheticCheckBox.kt | 17 +- .../aesthetic/AestheticCoordinatorLayout.kt | 19 +- .../aesthetic/AestheticDialogButton.kt | 2 +- .../aesthetic/AestheticDrawerLayout.kt | 6 +- .../afollestad/aesthetic/AestheticEditText.kt | 22 +-- .../com/afollestad/aesthetic/AestheticFab.kt | 9 +- .../aesthetic/AestheticImageButton.kt | 12 +- .../aesthetic/AestheticImageView.kt | 12 +- .../aesthetic/AestheticNavigationView.kt | 13 +- .../aesthetic/AestheticNestedScrollView.kt | 2 +- .../aesthetic/AestheticRadioButton.kt | 16 +- .../aesthetic/AestheticRecyclerView.kt | 2 +- .../afollestad/aesthetic/AestheticSeekBar.kt | 6 +- .../aesthetic/AestheticSnackBarButton.kt | 2 +- .../aesthetic/AestheticSnackBarTextView.kt | 2 +- .../afollestad/aesthetic/AestheticSpinner.kt | 6 +- .../aesthetic/AestheticSwipeRefreshLayout.kt | 2 +- .../afollestad/aesthetic/AestheticSwitch.kt | 4 +- .../aesthetic/AestheticSwitchCompat.kt | 6 +- .../aesthetic/AestheticTabLayout.kt | 6 +- .../aesthetic/AestheticTextInputEditText.kt | 6 +- .../aesthetic/AestheticTextInputLayout.kt | 10 +- .../afollestad/aesthetic/AestheticTextView.kt | 6 +- .../afollestad/aesthetic/AestheticToolbar.kt | 2 +- .../aesthetic/AestheticViewPager.kt | 2 +- .../actions/ViewBackgroundSubscriber.kt | 2 +- .../internal/InflationInterceptor.kt | 67 +++---- .../afollestad/aesthetic/utils/Activity.kt | 5 +- .../afollestad/aesthetic/utils/Collection.kt | 2 +- .../com/afollestad/aesthetic/utils/Context.kt | 8 +- .../aesthetic/utils/EdgeGlowUtil.kt | 8 +- .../afollestad/aesthetic/utils/TintHelper.kt | 169 ++++++++---------- .../com/afollestad/aesthetic/utils/View.kt | 8 +- .../afollestad/aesthetic/utils/ViewUtil.kt | 42 ++--- sample/build.gradle | 14 +- sample/proguard-rules.pro | 25 --- sample/src/main/AndroidManifest.xml | 1 - .../com/afollestad/aestheticsample/App.kt | 22 --- .../aestheticsample/DrawerActivity.kt | 2 +- .../aestheticsample/MainActivity.kt | 2 +- .../afollestad/aestheticsample/MainAdapter.kt | 2 +- .../aestheticsample/MainFragment.kt | 12 +- .../aestheticsample/MainPagerAdapter.kt | 9 +- .../aestheticsample/RecyclerViewActivity.kt | 2 +- .../aestheticsample/SecondaryFragment.kt | 2 +- .../aestheticsample/SwipeRefreshActivity.kt | 8 +- .../main/res/layout/activity_bottom_nav.xml | 4 +- .../res/layout/activity_collapsing_appbar.xml | 18 +- .../src/main/res/layout/activity_drawer.xml | 8 +- sample/src/main/res/layout/activity_main.xml | 8 +- .../main/res/layout/activity_recyclerview.xml | 4 +- .../res/layout/activity_swipe_refresh.xml | 6 +- sample/src/main/res/layout/fragment_main.xml | 14 +- sample/src/main/res/menu/main.xml | 2 +- 66 files changed, 358 insertions(+), 442 deletions(-) delete mode 100644 library/proguard-rules.pro delete mode 100644 sample/proguard-rules.pro delete mode 100644 sample/src/main/java/com/afollestad/aestheticsample/App.kt diff --git a/README.md b/README.md index 3502fbd..7731374 100644 --- a/README.md +++ b/README.md @@ -390,7 +390,7 @@ when `isDark()` is false. By default, the action text color will match `colorAcc # Tab Layouts -Tab Layouts from the Design Support library are automatically themed. The main screen in the +Tab Layouts from the Google Material library are automatically themed. The main screen in the sample project is an example of this, you see the two tabs under the toolbar at the top. You can customize background theming behavior: @@ -456,7 +456,7 @@ In addition, unselected nav drawer items will be shades of white or black based # Bottom Navigation -Bottom Navigation Views from the Design Support library are automatically themed. +Bottom Navigation Views from the Google Material library are automatically themed. @@ -521,7 +521,7 @@ also notice that the icons and title color are updated to be most visible over t # Swipe Refresh Layouts -Swipe Refresh Layouts from the Design Support library are automatically themed. +Swipe Refresh Layouts from the Google Material library are automatically themed. @@ -589,12 +589,3 @@ adopt the same window theme properties as the main activity. If you do not use `AestheticActivity`, your custom Activity can implement the `AestheticKeyProvider` interface. - -# Proguard - -In case you are using views from the support library (e.g. TextInputLayout & TextInputEditText), you will -need to add the following to your proguard: - -``` --keep class android.support.design.widget.** { *; } -``` diff --git a/dependencies.gradle b/dependencies.gradle index 28c49c7..0a6409a 100644 --- a/dependencies.gradle +++ b/dependencies.gradle @@ -2,16 +2,17 @@ ext.versions = [ minSdk : 16, compileSdk : 28, buildTools : '28.0.2', - publishVersion : '0.6.1', - publishVersionCode: 25, + publishVersion : '0.7.0', + publishVersionCode: 26, gradlePlugin : '3.1.4', - kotlin : '1.2.61', + kotlin : '1.2.70', spotlessPlugin : '3.14.0', versionsPlugin : '0.20.0', bintrayRelease : '0.8.1', - supportLib : '28.0.0-rc02', + androidx : '1.0.0-rc02', + rxJava : '2.2.2', rxAndroid : '2.1.0', rxkPrefs : '1.0.1', diff --git a/gradle.properties b/gradle.properties index c49365c..72f6686 100644 --- a/gradle.properties +++ b/gradle.properties @@ -16,3 +16,6 @@ org.gradle.configureondemand=false # This option should only be used with decoupled projects. More details, visit # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects # org.gradle.parallel=true + +android.useAndroidX=true +android.enableJetifier=true diff --git a/library/build.gradle b/library/build.gradle index 8c23f65..2db6a65 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -31,17 +31,21 @@ android { packagingOptions { exclude 'META-INF/library_release.kotlin_module' + exclude 'META-INF/proguard/androidx-annotations.pro' } } +repositories { + google() + jcenter() +} + dependencies { - implementation 'com.android.support:appcompat-v7:' + versions.supportLib - implementation 'com.android.support:cardview-v7:' + versions.supportLib - implementation 'com.android.support:support-compat:' + versions.supportLib + implementation 'androidx.appcompat:appcompat:' + versions.androidx + implementation 'androidx.cardview:cardview:' + versions.androidx + implementation 'androidx.recyclerview:recyclerview:' + versions.androidx - implementation 'com.android.support:design:' + versions.supportLib - implementation 'com.android.support:recyclerview-v7:' + versions.supportLib - implementation 'com.android.support:support-v13:' + versions.supportLib + implementation 'com.google.android.material:material:' + versions.androidx implementation 'io.reactivex.rxjava2:rxjava:' + versions.rxJava implementation 'io.reactivex.rxjava2:rxandroid:' + versions.rxAndroid diff --git a/library/proguard-rules.pro b/library/proguard-rules.pro deleted file mode 100644 index 0515aa1..0000000 --- a/library/proguard-rules.pro +++ /dev/null @@ -1,25 +0,0 @@ -# Add project specific ProGuard rules here. -# By default, the flags in this file are appended to flags specified -# in /Users/z002jdw/Library/Android/sdk/tools/proguard/proguard-android.txt -# You can edit the include path and order by changing the proguardFiles -# directive in build.gradle. -# -# For more details, see -# http://developer.android.com/guide/developing/tools/proguard.html - -# Add any project specific keep options here: - -# If your project uses WebView with JS, uncomment the following -# and specify the fully qualified class name to the JavaScript interface -# class: -#-keepclassmembers class fqcn.of.javascript.interface.for.webview { -# public *; -#} - -# Uncomment this to preserve the line number information for -# debugging stack traces. -#-keepattributes SourceFile,LineNumberTable - -# If you keep the line number information, uncomment this to -# hide the original source file name. -#-renamesourcefileattribute SourceFile diff --git a/library/src/main/java/com/afollestad/aesthetic/Aesthetic.kt b/library/src/main/java/com/afollestad/aesthetic/Aesthetic.kt index 4c61e64..efdbf8c 100644 --- a/library/src/main/java/com/afollestad/aesthetic/Aesthetic.kt +++ b/library/src/main/java/com/afollestad/aesthetic/Aesthetic.kt @@ -17,11 +17,9 @@ import android.support.annotation.CheckResult import android.support.annotation.ColorInt import android.support.annotation.ColorRes import android.support.annotation.StyleRes -import android.support.v4.content.ContextCompat -import android.support.v4.util.Pair -import android.support.v4.widget.DrawerLayout -import android.support.v7.app.AppCompatActivity import android.view.View +import androidx.appcompat.app.AppCompatActivity +import androidx.drawerlayout.widget.DrawerLayout import com.afollestad.aesthetic.actions.ViewBackgroundSubscriber import com.afollestad.aesthetic.internal.PrefNames.KEY_ACCENT_COLOR import com.afollestad.aesthetic.internal.PrefNames.KEY_ACTIVITY_THEME @@ -516,8 +514,7 @@ class Aesthetic private constructor(private var ctxt: Context?) { rxkPrefs!! .integer( KEY_CARD_VIEW_BG_COLOR, - ContextCompat.getColor( - context, + context.color( if (it) R.color.ate_cardview_bg_dark else @@ -555,16 +552,15 @@ class Aesthetic private constructor(private var ctxt: Context?) { rxkPrefs!! .integer( KEY_ICON_TITLE_ACTIVE_COLOR, - ContextCompat.getColor( - context, if (isDark) R.color.ate_icon_dark else R.color.ate_icon_light + context.color( + if (isDark) R.color.ate_icon_dark else R.color.ate_icon_light ) ) .asObservable(), rxkPrefs!! .integer( KEY_ICON_TITLE_INACTIVE_COLOR, - ContextCompat.getColor( - context, + context.color( if (isDark) R.color.ate_icon_dark_inactive else @@ -810,7 +806,7 @@ class Aesthetic private constructor(private var ctxt: Context?) { ) subs += combineLatest>( colorStatusBar(), lightStatusBarMode(), - BiFunction> { a, b -> Pair.create(a, b) }) + BiFunction> { a, b -> Pair(a, b) }) .distinctToMainThread() .subscribe( Consumer { invalidateStatusBar() }, diff --git a/library/src/main/java/com/afollestad/aesthetic/AestheticActionMenuItemView.kt b/library/src/main/java/com/afollestad/aesthetic/AestheticActionMenuItemView.kt index 0aff64f..92766e5 100644 --- a/library/src/main/java/com/afollestad/aesthetic/AestheticActionMenuItemView.kt +++ b/library/src/main/java/com/afollestad/aesthetic/AestheticActionMenuItemView.kt @@ -9,8 +9,8 @@ import android.annotation.SuppressLint import android.content.Context import android.content.res.ColorStateList import android.graphics.drawable.Drawable -import android.support.v7.view.menu.ActionMenuItemView import android.util.AttributeSet +import androidx.appcompat.view.menu.ActionMenuItemView import com.afollestad.aesthetic.utils.TintHelper.createTintedDrawable import com.afollestad.aesthetic.utils.distinctToMainThread import com.afollestad.aesthetic.utils.onErrorLogAndRethrow diff --git a/library/src/main/java/com/afollestad/aesthetic/AestheticActivity.kt b/library/src/main/java/com/afollestad/aesthetic/AestheticActivity.kt index c8b13bb..16912f2 100644 --- a/library/src/main/java/com/afollestad/aesthetic/AestheticActivity.kt +++ b/library/src/main/java/com/afollestad/aesthetic/AestheticActivity.kt @@ -6,7 +6,7 @@ package com.afollestad.aesthetic import android.os.Bundle -import android.support.v7.app.AppCompatActivity +import androidx.appcompat.app.AppCompatActivity /** @author Aidan Follestad (afollestad) */ open class AestheticActivity : AppCompatActivity(), AestheticKeyProvider { diff --git a/library/src/main/java/com/afollestad/aesthetic/AestheticBorderlessButton.kt b/library/src/main/java/com/afollestad/aesthetic/AestheticBorderlessButton.kt index 69675b6..5d16502 100644 --- a/library/src/main/java/com/afollestad/aesthetic/AestheticBorderlessButton.kt +++ b/library/src/main/java/com/afollestad/aesthetic/AestheticBorderlessButton.kt @@ -7,8 +7,8 @@ package com.afollestad.aesthetic import android.content.Context import android.content.res.ColorStateList -import android.support.v7.widget.AppCompatButton import android.util.AttributeSet +import androidx.appcompat.widget.AppCompatButton import com.afollestad.aesthetic.utils.adjustAlpha import com.afollestad.aesthetic.utils.distinctToMainThread import com.afollestad.aesthetic.utils.onErrorLogAndRethrow diff --git a/library/src/main/java/com/afollestad/aesthetic/AestheticBottomNavigationView.kt b/library/src/main/java/com/afollestad/aesthetic/AestheticBottomNavigationView.kt index 4bb0a09..901230b 100644 --- a/library/src/main/java/com/afollestad/aesthetic/AestheticBottomNavigationView.kt +++ b/library/src/main/java/com/afollestad/aesthetic/AestheticBottomNavigationView.kt @@ -9,15 +9,15 @@ import android.content.Context import android.content.res.ColorStateList import android.graphics.Color import android.support.annotation.ColorInt -import android.support.design.widget.BottomNavigationView -import android.support.v4.content.ContextCompat.getColor import android.util.AttributeSet import com.afollestad.aesthetic.actions.ViewBackgroundAction import com.afollestad.aesthetic.utils.adjustAlpha +import com.afollestad.aesthetic.utils.color import com.afollestad.aesthetic.utils.distinctToMainThread import com.afollestad.aesthetic.utils.isColorLight import com.afollestad.aesthetic.utils.onErrorLogAndRethrow import com.afollestad.aesthetic.utils.plusAssign +import com.google.android.material.bottomnavigation.BottomNavigationView import io.reactivex.Observable.combineLatest import io.reactivex.disposables.CompositeDisposable import io.reactivex.disposables.Disposable @@ -32,15 +32,14 @@ class AestheticBottomNavigationView( ) : BottomNavigationView(context, attrs) { private var modesSubscription: Disposable? = null - private var colorSubscriptions: CompositeDisposable? = null + private var colorSubs: CompositeDisposable? = null private var lastTextIconColor: Int = 0 private fun invalidateIconTextColor( backgroundColor: Int, selectedColor: Int ) { - val baseColor = getColor( - context, + val baseColor = context.color( if (backgroundColor.isColorLight()) R.color.ate_icon_light else R.color.ate_icon_dark ) val unselectedIconTextColor = baseColor.adjustAlpha(.87f) @@ -69,12 +68,12 @@ class AestheticBottomNavigationView( } private fun onState(state: State) { - colorSubscriptions?.clear() - colorSubscriptions = CompositeDisposable() + colorSubs?.clear() + colorSubs = CompositeDisposable() when (state.iconTextMode) { BottomNavIconTextMode.SELECTED_PRIMARY -> - colorSubscriptions!! += + colorSubs += Aesthetic.get() .colorPrimary() .distinctToMainThread() @@ -84,7 +83,7 @@ class AestheticBottomNavigationView( ) BottomNavIconTextMode.SELECTED_ACCENT -> - colorSubscriptions!! += + colorSubs += Aesthetic.get() .colorAccent() .distinctToMainThread() @@ -99,7 +98,7 @@ class AestheticBottomNavigationView( when (state.bgMode) { BottomNavBgMode.PRIMARY -> - colorSubscriptions!! += + colorSubs += Aesthetic.get() .colorPrimary() .distinctToMainThread() @@ -107,7 +106,7 @@ class AestheticBottomNavigationView( ViewBackgroundAction(this), onErrorLogAndRethrow() ) - BottomNavBgMode.PRIMARY_DARK -> colorSubscriptions!! += + BottomNavBgMode.PRIMARY_DARK -> colorSubs += Aesthetic.get() .colorStatusBar() .distinctToMainThread() @@ -115,7 +114,7 @@ class AestheticBottomNavigationView( ViewBackgroundAction(this), onErrorLogAndRethrow() ) - BottomNavBgMode.ACCENT -> colorSubscriptions!! += + BottomNavBgMode.ACCENT -> colorSubs += Aesthetic.get() .colorAccent() .distinctToMainThread() @@ -125,8 +124,7 @@ class AestheticBottomNavigationView( ) BottomNavBgMode.BLACK_WHITE_AUTO -> setBackgroundColor( - getColor( - context, + context.color( if (state.isDark) R.color.ate_bottom_nav_default_dark_bg else @@ -154,7 +152,7 @@ class AestheticBottomNavigationView( override fun onDetachedFromWindow() { modesSubscription?.dispose() - colorSubscriptions?.clear() + colorSubs?.clear() super.onDetachedFromWindow() } diff --git a/library/src/main/java/com/afollestad/aesthetic/AestheticButton.kt b/library/src/main/java/com/afollestad/aesthetic/AestheticButton.kt index f4e3afa..ec1c057 100644 --- a/library/src/main/java/com/afollestad/aesthetic/AestheticButton.kt +++ b/library/src/main/java/com/afollestad/aesthetic/AestheticButton.kt @@ -8,14 +8,14 @@ package com.afollestad.aesthetic import android.content.Context import android.content.res.ColorStateList import android.graphics.Color -import android.support.v7.widget.AppCompatButton import android.util.AttributeSet +import androidx.appcompat.widget.AppCompatButton import com.afollestad.aesthetic.utils.TintHelper.setTintAuto -import com.afollestad.aesthetic.utils.ViewUtil.getObservableForResId import com.afollestad.aesthetic.utils.distinctToMainThread import com.afollestad.aesthetic.utils.isColorLight import com.afollestad.aesthetic.utils.onErrorLogAndRethrow import com.afollestad.aesthetic.utils.resId +import com.afollestad.aesthetic.utils.watchColor import io.reactivex.Observable.combineLatest import io.reactivex.disposables.Disposable import io.reactivex.functions.Consumer @@ -56,7 +56,7 @@ class AestheticButton( override fun onAttachedToWindow() { super.onAttachedToWindow() subscription = combineLatest( - getObservableForResId( + watchColor( context, backgroundResId, Aesthetic.get().colorAccent() )!!, Aesthetic.get().isDark, diff --git a/library/src/main/java/com/afollestad/aesthetic/AestheticCardView.kt b/library/src/main/java/com/afollestad/aesthetic/AestheticCardView.kt index 9caf232..737ee55 100644 --- a/library/src/main/java/com/afollestad/aesthetic/AestheticCardView.kt +++ b/library/src/main/java/com/afollestad/aesthetic/AestheticCardView.kt @@ -7,9 +7,9 @@ package com.afollestad.aesthetic import android.annotation.SuppressLint import android.content.Context -import android.support.v7.widget.CardView import android.util.AttributeSet -import com.afollestad.aesthetic.utils.ViewUtil.getObservableForResId +import androidx.cardview.widget.CardView +import com.afollestad.aesthetic.utils.watchColor import com.afollestad.aesthetic.utils.distinctToMainThread import com.afollestad.aesthetic.utils.onErrorLogAndRethrow import com.afollestad.aesthetic.utils.resId @@ -34,7 +34,7 @@ class AestheticCardView( override fun onAttachedToWindow() { super.onAttachedToWindow() - val obs = getObservableForResId( + val obs = watchColor( context, backgroundResId, Aesthetic.get().colorCardViewBackground() )!! bgSubscription = obs diff --git a/library/src/main/java/com/afollestad/aesthetic/AestheticCheckBox.kt b/library/src/main/java/com/afollestad/aesthetic/AestheticCheckBox.kt index 3a8f3c3..ad78000 100644 --- a/library/src/main/java/com/afollestad/aesthetic/AestheticCheckBox.kt +++ b/library/src/main/java/com/afollestad/aesthetic/AestheticCheckBox.kt @@ -6,11 +6,11 @@ package com.afollestad.aesthetic import android.content.Context -import android.support.v7.widget.AppCompatCheckBox import android.util.AttributeSet +import androidx.appcompat.widget.AppCompatCheckBox import com.afollestad.aesthetic.actions.ViewTextColorAction import com.afollestad.aesthetic.utils.TintHelper.setTint -import com.afollestad.aesthetic.utils.ViewUtil.getObservableForResId +import com.afollestad.aesthetic.utils.watchColor import com.afollestad.aesthetic.utils.distinctToMainThread import com.afollestad.aesthetic.utils.onErrorLogAndRethrow import com.afollestad.aesthetic.utils.plusAssign @@ -25,7 +25,7 @@ class AestheticCheckBox( attrs: AttributeSet? = null ) : AppCompatCheckBox(context, attrs) { - private var subscriptions: CompositeDisposable? = null + private var subs: CompositeDisposable? = null private var backgroundResId: Int = 0 init { @@ -39,11 +39,10 @@ class AestheticCheckBox( override fun onAttachedToWindow() { super.onAttachedToWindow() - subscriptions = CompositeDisposable() - - subscriptions!! += + subs = CompositeDisposable() + subs += combineLatest( - getObservableForResId( + watchColor( context, backgroundResId, Aesthetic.get().colorAccent() )!!, Aesthetic.get().isDark, @@ -54,7 +53,7 @@ class AestheticCheckBox( Consumer { this.invalidateColors(it) }, onErrorLogAndRethrow() ) - subscriptions!! += + subs += Aesthetic.get() .textColorPrimary() .distinctToMainThread() @@ -62,7 +61,7 @@ class AestheticCheckBox( } override fun onDetachedFromWindow() { - subscriptions?.clear() + subs?.clear() super.onDetachedFromWindow() } } diff --git a/library/src/main/java/com/afollestad/aesthetic/AestheticCoordinatorLayout.kt b/library/src/main/java/com/afollestad/aesthetic/AestheticCoordinatorLayout.kt index 2947f27..747ab3e 100644 --- a/library/src/main/java/com/afollestad/aesthetic/AestheticCoordinatorLayout.kt +++ b/library/src/main/java/com/afollestad/aesthetic/AestheticCoordinatorLayout.kt @@ -11,16 +11,13 @@ import android.graphics.PorterDuff import android.graphics.PorterDuffColorFilter import android.graphics.drawable.ColorDrawable import android.graphics.drawable.Drawable -import android.support.design.widget.AppBarLayout -import android.support.design.widget.CollapsingToolbarLayout -import android.support.design.widget.CoordinatorLayout -import android.support.v4.util.Pair -import android.support.v7.view.menu.ActionMenuItemView -import android.support.v7.widget.ActionMenuView -import android.support.v7.widget.Toolbar import android.util.AttributeSet import android.view.Menu import android.view.View +import androidx.appcompat.view.menu.ActionMenuItemView +import androidx.appcompat.widget.ActionMenuView +import androidx.appcompat.widget.Toolbar +import androidx.coordinatorlayout.widget.CoordinatorLayout import com.afollestad.aesthetic.utils.TintHelper.createTintedDrawable import com.afollestad.aesthetic.utils.adjustAlpha import com.afollestad.aesthetic.utils.blendWith @@ -29,6 +26,8 @@ import com.afollestad.aesthetic.utils.isColorLight import com.afollestad.aesthetic.utils.onErrorLogAndRethrow import com.afollestad.aesthetic.utils.setOverflowButtonColor import com.afollestad.aesthetic.utils.tintMenu +import com.google.android.material.appbar.AppBarLayout +import com.google.android.material.appbar.CollapsingToolbarLayout import io.reactivex.Observable.combineLatest import io.reactivex.disposables.Disposable import io.reactivex.functions.BiFunction @@ -129,13 +128,13 @@ class AestheticCoordinatorLayout( combineLatest>( toolbar!!.colorUpdated(), Aesthetic.get().colorIconTitle(toolbar!!.colorUpdated()), - ToolbarIconTitleFunc { a, b -> Pair.create(a, b) } + ToolbarIconTitleFunc { a, b -> Pair(a, b) } ) .distinctToMainThread() .subscribe( Consumer { - toolbarColor = it.first!! - iconTextColors = it.second!! + toolbarColor = it.first + iconTextColors = it.second invalidateColors() }, onErrorLogAndRethrow() diff --git a/library/src/main/java/com/afollestad/aesthetic/AestheticDialogButton.kt b/library/src/main/java/com/afollestad/aesthetic/AestheticDialogButton.kt index e2816eb..e418650 100644 --- a/library/src/main/java/com/afollestad/aesthetic/AestheticDialogButton.kt +++ b/library/src/main/java/com/afollestad/aesthetic/AestheticDialogButton.kt @@ -6,8 +6,8 @@ package com.afollestad.aesthetic import android.content.Context -import android.support.v7.widget.AppCompatButton import android.util.AttributeSet +import androidx.appcompat.widget.AppCompatButton import com.afollestad.aesthetic.actions.ViewTextColorAction import com.afollestad.aesthetic.utils.distinctToMainThread import io.reactivex.disposables.Disposable diff --git a/library/src/main/java/com/afollestad/aesthetic/AestheticDrawerLayout.kt b/library/src/main/java/com/afollestad/aesthetic/AestheticDrawerLayout.kt index 40c3fc2..3c7cea0 100644 --- a/library/src/main/java/com/afollestad/aesthetic/AestheticDrawerLayout.kt +++ b/library/src/main/java/com/afollestad/aesthetic/AestheticDrawerLayout.kt @@ -6,10 +6,10 @@ package com.afollestad.aesthetic import android.content.Context -import android.support.v4.widget.DrawerLayout -import android.support.v7.app.ActionBarDrawerToggle -import android.support.v7.graphics.drawable.DrawerArrowDrawable import android.util.AttributeSet +import androidx.appcompat.app.ActionBarDrawerToggle +import androidx.appcompat.graphics.drawable.DrawerArrowDrawable +import androidx.drawerlayout.widget.DrawerLayout import com.afollestad.aesthetic.utils.distinctToMainThread import com.afollestad.aesthetic.utils.onErrorLogAndRethrow import io.reactivex.disposables.Disposable diff --git a/library/src/main/java/com/afollestad/aesthetic/AestheticEditText.kt b/library/src/main/java/com/afollestad/aesthetic/AestheticEditText.kt index b2af85c..e744b60 100644 --- a/library/src/main/java/com/afollestad/aesthetic/AestheticEditText.kt +++ b/library/src/main/java/com/afollestad/aesthetic/AestheticEditText.kt @@ -8,13 +8,13 @@ package com.afollestad.aesthetic import android.annotation.SuppressLint import android.content.Context -import android.support.v7.widget.AppCompatEditText import android.util.AttributeSet +import androidx.appcompat.widget.AppCompatEditText import com.afollestad.aesthetic.actions.ViewHintTextColorAction import com.afollestad.aesthetic.actions.ViewTextColorAction import com.afollestad.aesthetic.utils.TintHelper.setCursorTint import com.afollestad.aesthetic.utils.TintHelper.setTintAuto -import com.afollestad.aesthetic.utils.ViewUtil.getObservableForResId +import com.afollestad.aesthetic.utils.watchColor import com.afollestad.aesthetic.utils.distinctToMainThread import com.afollestad.aesthetic.utils.onErrorLogAndRethrow import com.afollestad.aesthetic.utils.plusAssign @@ -29,7 +29,7 @@ class AestheticEditText( attrs: AttributeSet? = null ) : AppCompatEditText(context, attrs) { - private var subscriptions: CompositeDisposable? = null + private var subs: CompositeDisposable? = null private var backgroundResId: Int = 0 private var textColorResId: Int = 0 private var textColorHintResId: Int = 0 @@ -54,10 +54,10 @@ class AestheticEditText( override fun onAttachedToWindow() { super.onAttachedToWindow() - subscriptions = CompositeDisposable() - subscriptions!! += + subs = CompositeDisposable() + subs += combineLatest( - getObservableForResId( + watchColor( context, backgroundResId, Aesthetic.get().colorAccent() @@ -70,8 +70,8 @@ class AestheticEditText( Consumer { invalidateColors(it) }, onErrorLogAndRethrow() ) - subscriptions!! += - getObservableForResId( + subs += + watchColor( context, textColorResId, Aesthetic.get().textColorPrimary() @@ -81,8 +81,8 @@ class AestheticEditText( ViewTextColorAction(this), onErrorLogAndRethrow() ) - subscriptions!! += - getObservableForResId( + subs += + watchColor( context, textColorHintResId, Aesthetic.get().textColorSecondary() @@ -95,7 +95,7 @@ class AestheticEditText( } override fun onDetachedFromWindow() { - subscriptions?.clear() + subs?.clear() super.onDetachedFromWindow() } } diff --git a/library/src/main/java/com/afollestad/aesthetic/AestheticFab.kt b/library/src/main/java/com/afollestad/aesthetic/AestheticFab.kt index d6d3af4..1250ca7 100644 --- a/library/src/main/java/com/afollestad/aesthetic/AestheticFab.kt +++ b/library/src/main/java/com/afollestad/aesthetic/AestheticFab.kt @@ -8,21 +8,20 @@ package com.afollestad.aesthetic import android.content.Context import android.graphics.Color import android.graphics.drawable.Drawable -import android.support.design.widget.FloatingActionButton import android.util.AttributeSet import com.afollestad.aesthetic.utils.TintHelper.createTintedDrawable import com.afollestad.aesthetic.utils.TintHelper.setTintAuto -import com.afollestad.aesthetic.utils.ViewUtil.getObservableForResId +import com.afollestad.aesthetic.utils.watchColor import com.afollestad.aesthetic.utils.distinctToMainThread import com.afollestad.aesthetic.utils.isColorLight import com.afollestad.aesthetic.utils.onErrorLogAndRethrow import com.afollestad.aesthetic.utils.resId +import com.google.android.material.floatingactionbutton.FloatingActionButton import io.reactivex.Observable.combineLatest import io.reactivex.disposables.Disposable import io.reactivex.functions.Consumer -/** @author Aidan Follestad (afollestad) - */ +/** @author Aidan Follestad (afollestad) */ class AestheticFab( context: Context, attrs: AttributeSet? = null @@ -51,7 +50,7 @@ class AestheticFab( override fun onAttachedToWindow() { super.onAttachedToWindow() subscription = combineLatest( - getObservableForResId( + watchColor( context, backgroundResId, Aesthetic.get().colorAccent() diff --git a/library/src/main/java/com/afollestad/aesthetic/AestheticImageButton.kt b/library/src/main/java/com/afollestad/aesthetic/AestheticImageButton.kt index ff273fc..d39e938 100644 --- a/library/src/main/java/com/afollestad/aesthetic/AestheticImageButton.kt +++ b/library/src/main/java/com/afollestad/aesthetic/AestheticImageButton.kt @@ -6,11 +6,11 @@ package com.afollestad.aesthetic import android.content.Context -import android.support.v7.widget.AppCompatImageButton import android.util.AttributeSet +import androidx.appcompat.widget.AppCompatImageButton import com.afollestad.aesthetic.actions.ImageViewTintAction import com.afollestad.aesthetic.actions.ViewBackgroundAction -import com.afollestad.aesthetic.utils.ViewUtil.getObservableForResId +import com.afollestad.aesthetic.utils.watchColor import com.afollestad.aesthetic.utils.distinctToMainThread import com.afollestad.aesthetic.utils.onErrorLogAndRethrow import com.afollestad.aesthetic.utils.plusAssign @@ -41,9 +41,9 @@ class AestheticImageButton( super.onAttachedToWindow() subs = CompositeDisposable() - val backgroundObs = getObservableForResId(context, backgroundResId, null) + val backgroundObs = watchColor(context, backgroundResId, null) if (backgroundObs != null) { - subs!! += backgroundObs + subs += backgroundObs .distinctToMainThread() .subscribe( ViewBackgroundAction(this), @@ -51,9 +51,9 @@ class AestheticImageButton( ) } - val tintObs = getObservableForResId(context, tintResId, null) + val tintObs = watchColor(context, tintResId, null) if (tintObs != null) { - subs!! += tintObs + subs += tintObs .distinctToMainThread() .subscribe( ImageViewTintAction(this), diff --git a/library/src/main/java/com/afollestad/aesthetic/AestheticImageView.kt b/library/src/main/java/com/afollestad/aesthetic/AestheticImageView.kt index 95fad8d..332c840 100644 --- a/library/src/main/java/com/afollestad/aesthetic/AestheticImageView.kt +++ b/library/src/main/java/com/afollestad/aesthetic/AestheticImageView.kt @@ -6,11 +6,11 @@ package com.afollestad.aesthetic import android.content.Context -import android.support.v7.widget.AppCompatImageView import android.util.AttributeSet +import androidx.appcompat.widget.AppCompatImageView import com.afollestad.aesthetic.actions.ImageViewTintAction import com.afollestad.aesthetic.actions.ViewBackgroundAction -import com.afollestad.aesthetic.utils.ViewUtil.getObservableForResId +import com.afollestad.aesthetic.utils.watchColor import com.afollestad.aesthetic.utils.distinctToMainThread import com.afollestad.aesthetic.utils.onErrorLogAndRethrow import com.afollestad.aesthetic.utils.plusAssign @@ -41,9 +41,9 @@ class AestheticImageView( super.onAttachedToWindow() subs = CompositeDisposable() - val backgroundObs = getObservableForResId(context, backgroundResId, null) + val backgroundObs = watchColor(context, backgroundResId, null) if (backgroundObs != null) { - subs!! += backgroundObs + subs += backgroundObs .distinctToMainThread() .subscribe( ViewBackgroundAction(this), @@ -51,9 +51,9 @@ class AestheticImageView( ) } - val tintObs = getObservableForResId(context, tintResId, null) + val tintObs = watchColor(context, tintResId, null) if (tintObs != null) { - subs!! += tintObs + subs += tintObs .distinctToMainThread() .subscribe( ImageViewTintAction(this), diff --git a/library/src/main/java/com/afollestad/aesthetic/AestheticNavigationView.kt b/library/src/main/java/com/afollestad/aesthetic/AestheticNavigationView.kt index ecab285..3a490bc 100644 --- a/library/src/main/java/com/afollestad/aesthetic/AestheticNavigationView.kt +++ b/library/src/main/java/com/afollestad/aesthetic/AestheticNavigationView.kt @@ -11,15 +11,15 @@ import android.content.res.ColorStateList import android.graphics.Color import android.graphics.drawable.ColorDrawable import android.graphics.drawable.StateListDrawable -import android.support.design.widget.NavigationView -import android.support.v4.content.ContextCompat.getColor import android.util.AttributeSet import com.afollestad.aesthetic.ColorIsDarkState.Companion.creator import com.afollestad.aesthetic.NavigationViewMode.SELECTED_ACCENT import com.afollestad.aesthetic.NavigationViewMode.SELECTED_PRIMARY import com.afollestad.aesthetic.utils.adjustAlpha +import com.afollestad.aesthetic.utils.color import com.afollestad.aesthetic.utils.distinctToMainThread import com.afollestad.aesthetic.utils.onErrorLogAndRethrow +import com.google.android.material.navigation.NavigationView import io.reactivex.Observable.combineLatest import io.reactivex.disposables.Disposable import io.reactivex.functions.Consumer @@ -40,8 +40,7 @@ class AestheticNavigationView( val baseColor = if (isDark) Color.WHITE else Color.BLACK val unselectedIconColor = baseColor.adjustAlpha(.54f) val unselectedTextColor = baseColor.adjustAlpha(.87f) - val selectedItemBgColor = getColor( - context, + val selectedItemBgColor = context.color( if (isDark) R.color.ate_navigation_drawer_selected_dark else @@ -77,8 +76,8 @@ class AestheticNavigationView( .navigationViewMode() .distinctToMainThread() .subscribe( - Consumer { - when (it) { + Consumer { mode -> + when (mode) { SELECTED_PRIMARY -> colorSubscription = combineLatest( Aesthetic.get().colorPrimary(), @@ -101,7 +100,7 @@ class AestheticNavigationView( Consumer { colors -> invalidateColors(colors) }, onErrorLogAndRethrow() ) - else -> throw IllegalStateException("Unknown nav view mode: $it") + else -> throw IllegalStateException("Unknown nav view mode: $mode") } }, onErrorLogAndRethrow() diff --git a/library/src/main/java/com/afollestad/aesthetic/AestheticNestedScrollView.kt b/library/src/main/java/com/afollestad/aesthetic/AestheticNestedScrollView.kt index e67062c..434dcda 100644 --- a/library/src/main/java/com/afollestad/aesthetic/AestheticNestedScrollView.kt +++ b/library/src/main/java/com/afollestad/aesthetic/AestheticNestedScrollView.kt @@ -6,8 +6,8 @@ package com.afollestad.aesthetic import android.content.Context -import android.support.v4.widget.NestedScrollView import android.util.AttributeSet +import androidx.core.widget.NestedScrollView import com.afollestad.aesthetic.utils.EdgeGlowUtil.setEdgeGlowColor import com.afollestad.aesthetic.utils.distinctToMainThread import com.afollestad.aesthetic.utils.onErrorLogAndRethrow diff --git a/library/src/main/java/com/afollestad/aesthetic/AestheticRadioButton.kt b/library/src/main/java/com/afollestad/aesthetic/AestheticRadioButton.kt index 0a1d2c9..b59e67c 100644 --- a/library/src/main/java/com/afollestad/aesthetic/AestheticRadioButton.kt +++ b/library/src/main/java/com/afollestad/aesthetic/AestheticRadioButton.kt @@ -6,11 +6,11 @@ package com.afollestad.aesthetic import android.content.Context -import android.support.v7.widget.AppCompatRadioButton import android.util.AttributeSet +import androidx.appcompat.widget.AppCompatRadioButton import com.afollestad.aesthetic.actions.ViewTextColorAction import com.afollestad.aesthetic.utils.TintHelper.setTint -import com.afollestad.aesthetic.utils.ViewUtil.getObservableForResId +import com.afollestad.aesthetic.utils.watchColor import com.afollestad.aesthetic.utils.distinctToMainThread import com.afollestad.aesthetic.utils.onErrorLogAndRethrow import com.afollestad.aesthetic.utils.plusAssign @@ -25,7 +25,7 @@ class AestheticRadioButton( attrs: AttributeSet? = null ) : AppCompatRadioButton(context, attrs) { - private var subscriptions: CompositeDisposable? = null + private var subs: CompositeDisposable? = null private var backgroundResId: Int = 0 init { @@ -39,10 +39,10 @@ class AestheticRadioButton( override fun onAttachedToWindow() { super.onAttachedToWindow() - subscriptions = CompositeDisposable() - subscriptions!! += + subs = CompositeDisposable() + subs += combineLatest( - getObservableForResId( + watchColor( context, backgroundResId, Aesthetic.get().colorAccent() @@ -55,7 +55,7 @@ class AestheticRadioButton( Consumer { invalidateColors(it) }, onErrorLogAndRethrow() ) - subscriptions!! += + subs += Aesthetic.get() .textColorPrimary() .distinctToMainThread() @@ -63,7 +63,7 @@ class AestheticRadioButton( } override fun onDetachedFromWindow() { - subscriptions?.clear() + subs?.clear() super.onDetachedFromWindow() } } diff --git a/library/src/main/java/com/afollestad/aesthetic/AestheticRecyclerView.kt b/library/src/main/java/com/afollestad/aesthetic/AestheticRecyclerView.kt index 1673085..d230fa6 100644 --- a/library/src/main/java/com/afollestad/aesthetic/AestheticRecyclerView.kt +++ b/library/src/main/java/com/afollestad/aesthetic/AestheticRecyclerView.kt @@ -6,8 +6,8 @@ package com.afollestad.aesthetic import android.content.Context -import android.support.v7.widget.RecyclerView import android.util.AttributeSet +import androidx.recyclerview.widget.RecyclerView import com.afollestad.aesthetic.utils.EdgeGlowUtil.setEdgeGlowColor import com.afollestad.aesthetic.utils.distinctToMainThread import com.afollestad.aesthetic.utils.onErrorLogAndRethrow diff --git a/library/src/main/java/com/afollestad/aesthetic/AestheticSeekBar.kt b/library/src/main/java/com/afollestad/aesthetic/AestheticSeekBar.kt index 3280252..b53d667 100644 --- a/library/src/main/java/com/afollestad/aesthetic/AestheticSeekBar.kt +++ b/library/src/main/java/com/afollestad/aesthetic/AestheticSeekBar.kt @@ -6,10 +6,10 @@ package com.afollestad.aesthetic import android.content.Context -import android.support.v7.widget.AppCompatSeekBar import android.util.AttributeSet +import androidx.appcompat.widget.AppCompatSeekBar import com.afollestad.aesthetic.utils.TintHelper.setTint -import com.afollestad.aesthetic.utils.ViewUtil.getObservableForResId +import com.afollestad.aesthetic.utils.watchColor import com.afollestad.aesthetic.utils.distinctToMainThread import com.afollestad.aesthetic.utils.onErrorLogAndRethrow import com.afollestad.aesthetic.utils.resId @@ -39,7 +39,7 @@ class AestheticSeekBar( super.onAttachedToWindow() subscription = combineLatest( - getObservableForResId( + watchColor( context, backgroundResId, Aesthetic.get().colorAccent() ), Aesthetic.get().isDark, diff --git a/library/src/main/java/com/afollestad/aesthetic/AestheticSnackBarButton.kt b/library/src/main/java/com/afollestad/aesthetic/AestheticSnackBarButton.kt index 74f9146..b5ec71d 100644 --- a/library/src/main/java/com/afollestad/aesthetic/AestheticSnackBarButton.kt +++ b/library/src/main/java/com/afollestad/aesthetic/AestheticSnackBarButton.kt @@ -6,8 +6,8 @@ package com.afollestad.aesthetic import android.content.Context -import android.support.v7.widget.AppCompatButton import android.util.AttributeSet +import androidx.appcompat.widget.AppCompatButton import com.afollestad.aesthetic.actions.ViewTextColorAction import com.afollestad.aesthetic.utils.distinctToMainThread import io.reactivex.disposables.Disposable diff --git a/library/src/main/java/com/afollestad/aesthetic/AestheticSnackBarTextView.kt b/library/src/main/java/com/afollestad/aesthetic/AestheticSnackBarTextView.kt index 4722fec..e04e8c3 100644 --- a/library/src/main/java/com/afollestad/aesthetic/AestheticSnackBarTextView.kt +++ b/library/src/main/java/com/afollestad/aesthetic/AestheticSnackBarTextView.kt @@ -6,8 +6,8 @@ package com.afollestad.aesthetic import android.content.Context -import android.support.v7.widget.AppCompatTextView import android.util.AttributeSet +import androidx.appcompat.widget.AppCompatTextView import com.afollestad.aesthetic.actions.ViewTextColorAction import com.afollestad.aesthetic.utils.distinctToMainThread import com.afollestad.aesthetic.utils.onErrorLogAndRethrow diff --git a/library/src/main/java/com/afollestad/aesthetic/AestheticSpinner.kt b/library/src/main/java/com/afollestad/aesthetic/AestheticSpinner.kt index de4a0cd..6f75766 100644 --- a/library/src/main/java/com/afollestad/aesthetic/AestheticSpinner.kt +++ b/library/src/main/java/com/afollestad/aesthetic/AestheticSpinner.kt @@ -6,10 +6,10 @@ package com.afollestad.aesthetic import android.content.Context -import android.support.v7.widget.AppCompatSpinner import android.util.AttributeSet +import androidx.appcompat.widget.AppCompatSpinner import com.afollestad.aesthetic.utils.TintHelper.setTintAuto -import com.afollestad.aesthetic.utils.ViewUtil.getObservableForResId +import com.afollestad.aesthetic.utils.watchColor import com.afollestad.aesthetic.utils.distinctToMainThread import com.afollestad.aesthetic.utils.onErrorLogAndRethrow import com.afollestad.aesthetic.utils.resId @@ -40,7 +40,7 @@ class AestheticSpinner( super.onAttachedToWindow() subscription = Observable.combineLatest( - getObservableForResId( + watchColor( context, backgroundResId, Aesthetic.get().colorAccent() )!!, Aesthetic.get().isDark, diff --git a/library/src/main/java/com/afollestad/aesthetic/AestheticSwipeRefreshLayout.kt b/library/src/main/java/com/afollestad/aesthetic/AestheticSwipeRefreshLayout.kt index e975602..5362a8c 100644 --- a/library/src/main/java/com/afollestad/aesthetic/AestheticSwipeRefreshLayout.kt +++ b/library/src/main/java/com/afollestad/aesthetic/AestheticSwipeRefreshLayout.kt @@ -7,8 +7,8 @@ package com.afollestad.aesthetic import android.annotation.SuppressLint import android.content.Context -import android.support.v4.widget.SwipeRefreshLayout import android.util.AttributeSet +import androidx.swiperefreshlayout.widget.SwipeRefreshLayout import com.afollestad.aesthetic.utils.distinctToMainThread import com.afollestad.aesthetic.utils.onErrorLogAndRethrow import io.reactivex.disposables.Disposable diff --git a/library/src/main/java/com/afollestad/aesthetic/AestheticSwitch.kt b/library/src/main/java/com/afollestad/aesthetic/AestheticSwitch.kt index cc6cfb9..05d6280 100644 --- a/library/src/main/java/com/afollestad/aesthetic/AestheticSwitch.kt +++ b/library/src/main/java/com/afollestad/aesthetic/AestheticSwitch.kt @@ -9,7 +9,7 @@ import android.content.Context import android.util.AttributeSet import android.widget.Switch import com.afollestad.aesthetic.utils.TintHelper.setTint -import com.afollestad.aesthetic.utils.ViewUtil.getObservableForResId +import com.afollestad.aesthetic.utils.watchColor import com.afollestad.aesthetic.utils.distinctToMainThread import com.afollestad.aesthetic.utils.onErrorLogAndRethrow import com.afollestad.aesthetic.utils.resId @@ -39,7 +39,7 @@ class AestheticSwitch( super.onAttachedToWindow() subscription = combineLatest( - getObservableForResId( + watchColor( context, backgroundResId, Aesthetic.get().colorAccent() )!!, Aesthetic.get().isDark, diff --git a/library/src/main/java/com/afollestad/aesthetic/AestheticSwitchCompat.kt b/library/src/main/java/com/afollestad/aesthetic/AestheticSwitchCompat.kt index 4c403ec..d5fa161 100644 --- a/library/src/main/java/com/afollestad/aesthetic/AestheticSwitchCompat.kt +++ b/library/src/main/java/com/afollestad/aesthetic/AestheticSwitchCompat.kt @@ -6,10 +6,10 @@ package com.afollestad.aesthetic import android.content.Context -import android.support.v7.widget.SwitchCompat import android.util.AttributeSet +import androidx.appcompat.widget.SwitchCompat import com.afollestad.aesthetic.utils.TintHelper.setTint -import com.afollestad.aesthetic.utils.ViewUtil.getObservableForResId +import com.afollestad.aesthetic.utils.watchColor import com.afollestad.aesthetic.utils.distinctToMainThread import com.afollestad.aesthetic.utils.onErrorLogAndRethrow import com.afollestad.aesthetic.utils.resId @@ -39,7 +39,7 @@ class AestheticSwitchCompat( super.onAttachedToWindow() subscription = combineLatest( - getObservableForResId( + watchColor( context, backgroundResId, Aesthetic.get().colorAccent() diff --git a/library/src/main/java/com/afollestad/aesthetic/AestheticTabLayout.kt b/library/src/main/java/com/afollestad/aesthetic/AestheticTabLayout.kt index e5eb073..e9db467 100644 --- a/library/src/main/java/com/afollestad/aesthetic/AestheticTabLayout.kt +++ b/library/src/main/java/com/afollestad/aesthetic/AestheticTabLayout.kt @@ -9,7 +9,6 @@ import android.annotation.SuppressLint import android.content.Context import android.content.res.ColorStateList import android.support.annotation.ColorInt -import android.support.design.widget.TabLayout import android.util.AttributeSet import com.afollestad.aesthetic.TabLayoutBgMode.ACCENT import com.afollestad.aesthetic.TabLayoutBgMode.PRIMARY @@ -20,6 +19,7 @@ import com.afollestad.aesthetic.utils.distinctToMainThread import com.afollestad.aesthetic.utils.onErrorLogAndRethrow import com.afollestad.aesthetic.utils.one import com.afollestad.aesthetic.utils.plusAssign +import com.google.android.material.tabs.TabLayout import io.reactivex.Observable import io.reactivex.disposables.CompositeDisposable import io.reactivex.disposables.Disposable @@ -73,7 +73,7 @@ class AestheticTabLayout( super.onAttachedToWindow() topLevelSubs = CompositeDisposable() - topLevelSubs!! += Aesthetic.get() + topLevelSubs += Aesthetic.get() .tabLayoutBackgroundMode() .distinctToMainThread() .subscribe( @@ -106,7 +106,7 @@ class AestheticTabLayout( onErrorLogAndRethrow() ) - topLevelSubs!! += Aesthetic.get() + topLevelSubs += Aesthetic.get() .tabLayoutIndicatorMode() .distinctToMainThread() .subscribe( diff --git a/library/src/main/java/com/afollestad/aesthetic/AestheticTextInputEditText.kt b/library/src/main/java/com/afollestad/aesthetic/AestheticTextInputEditText.kt index a06a73a..476695e 100644 --- a/library/src/main/java/com/afollestad/aesthetic/AestheticTextInputEditText.kt +++ b/library/src/main/java/com/afollestad/aesthetic/AestheticTextInputEditText.kt @@ -6,17 +6,17 @@ package com.afollestad.aesthetic import android.content.Context -import android.support.design.widget.TextInputEditText import android.util.AttributeSet import com.afollestad.aesthetic.actions.ViewHintTextColorAction import com.afollestad.aesthetic.actions.ViewTextColorAction import com.afollestad.aesthetic.utils.TintHelper.setCursorTint import com.afollestad.aesthetic.utils.TintHelper.setTintAuto -import com.afollestad.aesthetic.utils.ViewUtil.getObservableForResId +import com.afollestad.aesthetic.utils.watchColor import com.afollestad.aesthetic.utils.distinctToMainThread import com.afollestad.aesthetic.utils.onErrorLogAndRethrow import com.afollestad.aesthetic.utils.plusAssign import com.afollestad.aesthetic.utils.resId +import com.google.android.material.textfield.TextInputEditText import io.reactivex.Observable.combineLatest import io.reactivex.disposables.CompositeDisposable import io.reactivex.functions.Consumer @@ -65,7 +65,7 @@ class AestheticTextInputEditText( ) subs!! += combineLatest( - getObservableForResId( + watchColor( context, backgroundResId, Aesthetic.get().colorAccent() diff --git a/library/src/main/java/com/afollestad/aesthetic/AestheticTextInputLayout.kt b/library/src/main/java/com/afollestad/aesthetic/AestheticTextInputLayout.kt index 4190c1d..9d63f66 100644 --- a/library/src/main/java/com/afollestad/aesthetic/AestheticTextInputLayout.kt +++ b/library/src/main/java/com/afollestad/aesthetic/AestheticTextInputLayout.kt @@ -6,9 +6,8 @@ package com.afollestad.aesthetic import android.content.Context -import android.support.design.widget.TextInputLayout import android.util.AttributeSet -import com.afollestad.aesthetic.utils.ViewUtil.getObservableForResId +import com.afollestad.aesthetic.utils.watchColor import com.afollestad.aesthetic.utils.adjustAlpha import com.afollestad.aesthetic.utils.distinctToMainThread import com.afollestad.aesthetic.utils.onErrorLogAndRethrow @@ -16,6 +15,7 @@ import com.afollestad.aesthetic.utils.plusAssign import com.afollestad.aesthetic.utils.resId import com.afollestad.aesthetic.utils.setAccentColor import com.afollestad.aesthetic.utils.setHintColor +import com.google.android.material.textfield.TextInputLayout import io.reactivex.disposables.CompositeDisposable import io.reactivex.functions.Consumer @@ -40,7 +40,7 @@ class AestheticTextInputLayout( super.onAttachedToWindow() subs = CompositeDisposable() - subs!! += + subs += Aesthetic.get() .textColorSecondary() .distinctToMainThread() @@ -48,8 +48,8 @@ class AestheticTextInputLayout( Consumer { setHintColor(it.adjustAlpha(0.7f)) }, onErrorLogAndRethrow() ) - subs!! += - getObservableForResId( + subs += + watchColor( context, backgroundResId, Aesthetic.get().colorAccent() diff --git a/library/src/main/java/com/afollestad/aesthetic/AestheticTextView.kt b/library/src/main/java/com/afollestad/aesthetic/AestheticTextView.kt index ab63e0e..bb602f5 100644 --- a/library/src/main/java/com/afollestad/aesthetic/AestheticTextView.kt +++ b/library/src/main/java/com/afollestad/aesthetic/AestheticTextView.kt @@ -6,10 +6,10 @@ package com.afollestad.aesthetic import android.content.Context -import android.support.v7.widget.AppCompatTextView import android.util.AttributeSet +import androidx.appcompat.widget.AppCompatTextView import com.afollestad.aesthetic.actions.ViewTextColorAction -import com.afollestad.aesthetic.utils.ViewUtil.getObservableForResId +import com.afollestad.aesthetic.utils.watchColor import com.afollestad.aesthetic.utils.distinctToMainThread import com.afollestad.aesthetic.utils.onErrorLogAndRethrow import com.afollestad.aesthetic.utils.resId @@ -32,7 +32,7 @@ class AestheticTextView( override fun onAttachedToWindow() { super.onAttachedToWindow() - val obs = getObservableForResId( + val obs = watchColor( context, textColorResId, if (id == android.R.id.title) diff --git a/library/src/main/java/com/afollestad/aesthetic/AestheticToolbar.kt b/library/src/main/java/com/afollestad/aesthetic/AestheticToolbar.kt index 8aecf45..10a8af4 100644 --- a/library/src/main/java/com/afollestad/aesthetic/AestheticToolbar.kt +++ b/library/src/main/java/com/afollestad/aesthetic/AestheticToolbar.kt @@ -8,8 +8,8 @@ package com.afollestad.aesthetic import android.content.Context import android.graphics.drawable.Drawable import android.support.annotation.ColorInt -import android.support.v7.widget.Toolbar import android.util.AttributeSet +import androidx.appcompat.widget.Toolbar import com.afollestad.aesthetic.BgIconColorState.Companion.creator import com.afollestad.aesthetic.utils.TintHelper.createTintedDrawable import com.afollestad.aesthetic.utils.distinctToMainThread diff --git a/library/src/main/java/com/afollestad/aesthetic/AestheticViewPager.kt b/library/src/main/java/com/afollestad/aesthetic/AestheticViewPager.kt index 5b842fc..ca78a1f 100644 --- a/library/src/main/java/com/afollestad/aesthetic/AestheticViewPager.kt +++ b/library/src/main/java/com/afollestad/aesthetic/AestheticViewPager.kt @@ -6,8 +6,8 @@ package com.afollestad.aesthetic import android.content.Context -import android.support.v4.view.ViewPager import android.util.AttributeSet +import androidx.viewpager.widget.ViewPager import com.afollestad.aesthetic.utils.EdgeGlowUtil.setEdgeGlowColor import com.afollestad.aesthetic.utils.distinctToMainThread import com.afollestad.aesthetic.utils.onErrorLogAndRethrow diff --git a/library/src/main/java/com/afollestad/aesthetic/actions/ViewBackgroundSubscriber.kt b/library/src/main/java/com/afollestad/aesthetic/actions/ViewBackgroundSubscriber.kt index d9519c2..b18a6e5 100644 --- a/library/src/main/java/com/afollestad/aesthetic/actions/ViewBackgroundSubscriber.kt +++ b/library/src/main/java/com/afollestad/aesthetic/actions/ViewBackgroundSubscriber.kt @@ -5,8 +5,8 @@ */ package com.afollestad.aesthetic.actions -import android.support.v7.widget.CardView import android.view.View +import androidx.cardview.widget.CardView import io.reactivex.exceptions.Exceptions import io.reactivex.observers.DisposableObserver diff --git a/library/src/main/java/com/afollestad/aesthetic/internal/InflationInterceptor.kt b/library/src/main/java/com/afollestad/aesthetic/internal/InflationInterceptor.kt index 0be01de..2419d77 100644 --- a/library/src/main/java/com/afollestad/aesthetic/internal/InflationInterceptor.kt +++ b/library/src/main/java/com/afollestad/aesthetic/internal/InflationInterceptor.kt @@ -7,13 +7,13 @@ package com.afollestad.aesthetic.internal import android.annotation.SuppressLint import android.content.Context -import android.support.v7.app.AppCompatActivity -import android.support.v7.app.AppCompatDelegate import android.util.AttributeSet import android.util.Log import android.view.LayoutInflater import android.view.View import android.widget.LinearLayout +import androidx.appcompat.app.AppCompatActivity +import androidx.appcompat.app.AppCompatDelegate import com.afollestad.aesthetic.Aesthetic import com.afollestad.aesthetic.AestheticActionMenuItemView import com.afollestad.aesthetic.AestheticBorderlessButton @@ -49,8 +49,8 @@ import com.afollestad.aesthetic.AestheticTextView import com.afollestad.aesthetic.AestheticToolbar import com.afollestad.aesthetic.AestheticViewPager import com.afollestad.aesthetic.R.id -import com.afollestad.aesthetic.utils.ViewUtil.getObservableForResId import com.afollestad.aesthetic.utils.resId +import com.afollestad.aesthetic.utils.watchColor /** @author Aidan Follestad (afollestad) */ internal class InflationInterceptor( @@ -62,6 +62,11 @@ internal class InflationInterceptor( private const val LOGGING_ENABLED = true + private const val ANDROIDX_WIDGET = "androidx.core.widget" + private const val APPCOMPAT_WIDGET = "androidx.appcompat.widget" + private const val APPCOMPAT_VIEW = "androidx.appcompat.view" + private const val GOOGLE_MATERIAL = "com.google.android.material" + @Suppress("ConstantConditionIf") private fun log(msg: String) { if (!LOGGING_ENABLED) return @@ -69,7 +74,7 @@ internal class InflationInterceptor( } private fun isBlackListedForApply(name: String): Boolean { - return ("android.support.design.internal.NavigationMenuItemView" == name || + return ("com.google.android.material.internal.NavigationMenuItemView" == name || "ViewStub" == name || "fragment" == name || "include" == name) @@ -122,17 +127,17 @@ internal class InflationInterceptor( val viewId = context.resId(attrs, android.R.attr.id) when (name) { - "ImageView", "android.support.v7.widget.AppCompatImageView" -> + "ImageView", "$APPCOMPAT_WIDGET.AppCompatImageView" -> view = AestheticImageView(context, attrs) - "ImageButton", "android.support.v7.widget.AppCompatImageButton" -> + "ImageButton", "$APPCOMPAT_WIDGET.AppCompatImageButton" -> view = AestheticImageButton(context, attrs) - "android.support.v4.widget.DrawerLayout" -> + "androidx.drawerlayout.widget.DrawerLayout" -> view = AestheticDrawerLayout(context, attrs) - "Toolbar", "android.support.v7.widget.Toolbar" -> + "Toolbar", "$APPCOMPAT_WIDGET.Toolbar" -> view = AestheticToolbar(context, attrs) - "android.support.v7.widget.AppCompatTextView", "TextView" -> + "$APPCOMPAT_WIDGET.AppCompatTextView", "TextView" -> if (viewId == id.snackbar_text) { view = AestheticSnackBarTextView(context, attrs) } else { @@ -142,7 +147,7 @@ internal class InflationInterceptor( view = null } } - "Button", "android.support.v7.widget.AppCompatButton" -> + "Button", "$APPCOMPAT_WIDGET.AppCompatButton" -> view = if (viewId == android.R.id.button1 || viewId == android.R.id.button2 || @@ -159,52 +164,52 @@ internal class InflationInterceptor( } else { AestheticButton(context, attrs) } - "android.support.v7.widget.AppCompatCheckBox", "CheckBox" -> + "$APPCOMPAT_WIDGET.AppCompatCheckBox", "CheckBox" -> view = AestheticCheckBox(context, attrs) - "android.support.v7.widget.AppCompatRadioButton", "RadioButton" -> + "$APPCOMPAT_WIDGET.AppCompatRadioButton", "RadioButton" -> view = AestheticRadioButton(context, attrs) - "android.support.v7.widget.AppCompatEditText", "EditText" -> + "$APPCOMPAT_WIDGET.AppCompatEditText", "EditText" -> view = AestheticEditText(context, attrs) "Switch" -> view = AestheticSwitch(context, attrs) - "android.support.v7.widget.SwitchCompat" -> view = + "$APPCOMPAT_WIDGET.SwitchCompat" -> view = AestheticSwitchCompat(context, attrs) - "android.support.v7.widget.AppCompatSeekBar", "SeekBar" -> + "$APPCOMPAT_WIDGET.AppCompatSeekBar", "SeekBar" -> view = AestheticSeekBar(context, attrs) - "ProgressBar", "me.zhanghai.android.materialprogressbar.MaterialProgressBar" -> + "ProgressBar" -> view = AestheticProgressBar(context, attrs) - "android.support.v7.view.menu.ActionMenuItemView" -> + "$APPCOMPAT_VIEW.ActionMenuItemView" -> view = AestheticActionMenuItemView(context, attrs) - "android.support.v7.widget.RecyclerView" -> + "$APPCOMPAT_WIDGET.RecyclerView" -> view = AestheticRecyclerView(context, attrs) - "android.support.v4.widget.NestedScrollView" -> + "$ANDROIDX_WIDGET.NestedScrollView" -> view = AestheticNestedScrollView(context, attrs) "ListView" -> view = AestheticListView(context, attrs) "ScrollView" -> view = AestheticScrollView(context, attrs) - "android.support.v4.view.ViewPager" -> view = + "androidx.viewpager.widget.ViewPager" -> view = AestheticViewPager(context, attrs) - "Spinner", "android.support.v7.widget.AppCompatSpinner" -> + "Spinner", "$APPCOMPAT_WIDGET.AppCompatSpinner" -> view = AestheticSpinner(context, attrs) - "android.support.design.widget.TextInputLayout" -> + "$GOOGLE_MATERIAL.textfield.TextInputLayout" -> view = AestheticTextInputLayout(context, attrs) - "android.support.design.widget.TextInputEditText" -> + "$GOOGLE_MATERIAL.textfield.TextInputEditText" -> view = AestheticTextInputEditText(context, attrs) - "android.support.v7.widget.CardView" -> view = + "$APPCOMPAT_WIDGET.CardView" -> view = AestheticCardView(context, attrs) - "android.support.design.widget.TabLayout" -> view = + "$GOOGLE_MATERIAL.tabs.TabLayout" -> view = AestheticTabLayout(context, attrs) - "android.support.design.widget.NavigationView" -> + "$GOOGLE_MATERIAL.navigation.NavigationView" -> view = AestheticNavigationView(context, attrs) - "android.support.design.widget.BottomNavigationView" -> + "$GOOGLE_MATERIAL.bottomnavigation.BottomNavigationView" -> view = AestheticBottomNavigationView(context, attrs) - "android.support.design.widget.FloatingActionButton" -> + "$GOOGLE_MATERIAL.floatingactionbutton.FloatingActionButton" -> view = AestheticFab(context, attrs) - "android.support.design.widget.CoordinatorLayout" -> + "androidx.coordinatorlayout.widget.CoordinatorLayout" -> view = AestheticCoordinatorLayout(context, attrs) - "android.support.v4.widget.SwipeRefreshLayout" -> + "androidx.swiperefreshlayout.widget.SwipeRefreshLayout" -> view = AestheticSwipeRefreshLayout(context, attrs) } @@ -275,7 +280,7 @@ internal class InflationInterceptor( } if (viewBackgroundRes != 0) { - val obs = getObservableForResId(context, viewBackgroundRes, null) + val obs = watchColor(context, viewBackgroundRes, null) if (obs != null) { Aesthetic.get() .addBackgroundSubscriber(view, obs) diff --git a/library/src/main/java/com/afollestad/aesthetic/utils/Activity.kt b/library/src/main/java/com/afollestad/aesthetic/utils/Activity.kt index 6598310..2e1b00a 100644 --- a/library/src/main/java/com/afollestad/aesthetic/utils/Activity.kt +++ b/library/src/main/java/com/afollestad/aesthetic/utils/Activity.kt @@ -12,11 +12,11 @@ import android.graphics.Bitmap import android.graphics.drawable.BitmapDrawable import android.os.Build import android.support.annotation.ColorInt -import android.support.v4.view.LayoutInflaterCompat -import android.support.v7.app.AppCompatActivity import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import androidx.appcompat.app.AppCompatActivity +import androidx.core.view.LayoutInflaterCompat import com.afollestad.aesthetic.internal.InflationInterceptor internal fun AppCompatActivity.setInflaterFactory(li: LayoutInflater) { @@ -73,6 +73,7 @@ internal fun Activity.setTaskDescriptionColor(@ColorInt requestedColor: Int) { } if (icon != null) { // Sets color of entry in the system recents page + @Suppress("DEPRECATION") val td = ActivityManager.TaskDescription(title as String, icon, color) setTaskDescription(td) } diff --git a/library/src/main/java/com/afollestad/aesthetic/utils/Collection.kt b/library/src/main/java/com/afollestad/aesthetic/utils/Collection.kt index a75ab92..552e752 100644 --- a/library/src/main/java/com/afollestad/aesthetic/utils/Collection.kt +++ b/library/src/main/java/com/afollestad/aesthetic/utils/Collection.kt @@ -5,7 +5,7 @@ */ package com.afollestad.aesthetic.utils -import android.support.v4.util.ArrayMap +import androidx.collection.ArrayMap internal fun String.splitToInts(delimiter: String = ","): IntArray { return split(delimiter).map { it.toInt() } diff --git a/library/src/main/java/com/afollestad/aesthetic/utils/Context.kt b/library/src/main/java/com/afollestad/aesthetic/utils/Context.kt index 2e752a8..95f237b 100644 --- a/library/src/main/java/com/afollestad/aesthetic/utils/Context.kt +++ b/library/src/main/java/com/afollestad/aesthetic/utils/Context.kt @@ -6,16 +6,22 @@ package com.afollestad.aesthetic.utils import android.content.Context +import android.graphics.drawable.Drawable import android.support.annotation.AttrRes import android.support.annotation.ColorInt import android.support.annotation.ColorRes -import android.support.v4.content.ContextCompat +import android.support.annotation.DrawableRes import android.util.AttributeSet +import androidx.core.content.ContextCompat @ColorInt internal fun Context.color(@ColorRes color: Int): Int { return ContextCompat.getColor(this, color) } +internal fun Context.drawable(@DrawableRes drawable: Int): Drawable? { + return ContextCompat.getDrawable(this, drawable) +} + @ColorInt internal fun Context.colorAttr(@AttrRes attr: Int, @ColorInt fallback: Int = 0): Int { val a = theme.obtainStyledAttributes(intArrayOf(attr)) return try { diff --git a/library/src/main/java/com/afollestad/aesthetic/utils/EdgeGlowUtil.kt b/library/src/main/java/com/afollestad/aesthetic/utils/EdgeGlowUtil.kt index 9a0f6ac..eb6ccd2 100644 --- a/library/src/main/java/com/afollestad/aesthetic/utils/EdgeGlowUtil.kt +++ b/library/src/main/java/com/afollestad/aesthetic/utils/EdgeGlowUtil.kt @@ -10,13 +10,13 @@ import android.graphics.PorterDuff import android.graphics.drawable.Drawable import android.os.Build import android.support.annotation.ColorInt -import android.support.v4.view.ViewPager -import android.support.v4.widget.EdgeEffectCompat -import android.support.v4.widget.NestedScrollView -import android.support.v7.widget.RecyclerView import android.widget.AbsListView import android.widget.EdgeEffect import android.widget.ScrollView +import androidx.core.widget.EdgeEffectCompat +import androidx.core.widget.NestedScrollView +import androidx.recyclerview.widget.RecyclerView +import androidx.viewpager.widget.ViewPager import com.afollestad.aesthetic.BuildConfig import java.lang.reflect.Field diff --git a/library/src/main/java/com/afollestad/aesthetic/utils/TintHelper.kt b/library/src/main/java/com/afollestad/aesthetic/utils/TintHelper.kt index a2b51a9..7edd0cb 100644 --- a/library/src/main/java/com/afollestad/aesthetic/utils/TintHelper.kt +++ b/library/src/main/java/com/afollestad/aesthetic/utils/TintHelper.kt @@ -14,13 +14,6 @@ import android.graphics.drawable.RippleDrawable import android.os.Build import android.support.annotation.CheckResult import android.support.annotation.ColorInt -import android.support.design.widget.FloatingActionButton -import android.support.design.widget.TextInputEditText -import android.support.v4.content.ContextCompat -import android.support.v4.graphics.drawable.DrawableCompat -import android.support.v4.view.TintableBackgroundView -import android.support.v4.view.ViewCompat -import android.support.v7.widget.SwitchCompat import android.view.View import android.widget.Button import android.widget.CheckBox @@ -31,9 +24,13 @@ import android.widget.RadioButton import android.widget.SeekBar import android.widget.Switch import android.widget.TextView +import androidx.appcompat.widget.SwitchCompat +import androidx.core.graphics.drawable.DrawableCompat +import androidx.core.view.TintableBackgroundView +import androidx.core.view.ViewCompat import com.afollestad.aesthetic.R -import com.afollestad.aesthetic.R.color -import com.afollestad.aesthetic.R.drawable +import com.google.android.material.floatingactionbutton.FloatingActionButton +import com.google.android.material.textfield.TextInputEditText /** @author Aidan Follestad (afollestad) */ internal object TintHelper { @@ -45,8 +42,8 @@ internal object TintHelper { useDarkRipple: Boolean ): Int { // Light ripple is actually translucent black, and vice versa - return ContextCompat.getColor( - context, if (useDarkRipple) color.ripple_material_light else color.ripple_material_dark + return context.color( + if (useDarkRipple) R.color.ripple_material_light else R.color.ripple_material_dark ) } @@ -69,58 +66,57 @@ internal object TintHelper { useDarkTheme: Boolean ) { val isColorLight = color.isColorLight() - val disabled = ContextCompat.getColor( - view.context, + val disabled = view.context.color( if (useDarkTheme) R.color.ate_button_disabled_dark else R.color.ate_button_disabled_light ) val pressed = color.shiftColor(if (darker) 0.9f else 1.1f) val activated = color.shiftColor(if (darker) 1.1f else 0.9f) val rippleColor = getDefaultRippleColor(view.context, isColorLight) - val textColor = ContextCompat.getColor( - view.context, + val textColor = view.context.color( if (isColorLight) R.color.ate_primary_text_light else R.color.ate_primary_text_dark ) val sl: ColorStateList - if (view is Button) { - sl = getDisabledColorStateList(color, disabled) - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && view.getBackground() is RippleDrawable) { - val rd = view.getBackground() as RippleDrawable - rd.setColor(ColorStateList.valueOf(rippleColor)) + when (view) { + is Button -> { + sl = getDisabledColorStateList(color, disabled) + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && view.getBackground() is RippleDrawable) { + val rd = view.getBackground() as RippleDrawable + rd.setColor(ColorStateList.valueOf(rippleColor)) + } + + // Disabled text color state for buttons, may get overridden later by ATE tags + view.setTextColor( + getDisabledColorStateList( + textColor, + view.getContext().color( + if (useDarkTheme) + R.color.ate_button_text_disabled_dark + else + R.color.ate_button_text_disabled_light + ) + ) + ) } + is FloatingActionButton -> { + // FloatingActionButton doesn't support disabled state? + sl = ColorStateList( + arrayOf( + intArrayOf(-android.R.attr.state_pressed), intArrayOf(android.R.attr.state_pressed) + ), + intArrayOf(color, pressed) + ) - // Disabled text color state for buttons, may get overridden later by ATE tags - view.setTextColor( - getDisabledColorStateList( - textColor, - ContextCompat.getColor( - view.getContext(), - if (useDarkTheme) - R.color.ate_button_text_disabled_dark - else - R.color.ate_button_text_disabled_light - ) + view.rippleColor = rippleColor + view.backgroundTintList = sl + if (view.drawable != null) + view.setImageDrawable( + createTintedDrawable(view.drawable, textColor) ) - ) - } else if (view is FloatingActionButton) { - // FloatingActionButton doesn't support disabled state? - sl = ColorStateList( - arrayOf( - intArrayOf(-android.R.attr.state_pressed), intArrayOf(android.R.attr.state_pressed) - ), - intArrayOf(color, pressed) - ) - - view.rippleColor = rippleColor - view.backgroundTintList = sl - if (view.drawable != null) - view.setImageDrawable( - createTintedDrawable(view.drawable, textColor) - ) - return - } else { - sl = ColorStateList( + return + } + else -> sl = ColorStateList( arrayOf( intArrayOf(-android.R.attr.state_enabled), intArrayOf(android.R.attr.state_enabled), intArrayOf(android.R.attr.state_enabled, android.R.attr.state_pressed), @@ -141,8 +137,7 @@ internal object TintHelper { view.setTextColor( getDisabledColorStateList( textColor, - ContextCompat.getColor( - view.getContext(), + view.getContext().color( if (isColorLight) R.color.ate_text_disabled_light else @@ -180,8 +175,7 @@ internal object TintHelper { ) { // Ripples for the above views (e.g. when you tap and hold a switch or checkbox) val rd = view.background as RippleDrawable - val unchecked = ContextCompat.getColor( - view.context, + val unchecked = view.context.color( if (isDark) R.color.ripple_material_dark else R.color.ripple_material_light ) val checked = color.adjustAlpha(0.4f) @@ -244,9 +238,7 @@ internal object TintHelper { } else { @SuppressLint("PrivateResource") val d = createTintedDrawable( - ContextCompat.getDrawable( - radioButton.context, drawable.abc_btn_radio_material - ), + radioButton.context.drawable(R.drawable.abc_btn_radio_material), sl ) radioButton.buttonDrawable = d @@ -260,8 +252,7 @@ internal object TintHelper { ) { val s1 = getDisabledColorStateList( color, - ContextCompat.getColor( - seekBar.context, + seekBar.context.color( if (useDarker) R.color.ate_control_disabled_dark else @@ -323,13 +314,13 @@ internal object TintHelper { ), intArrayOf() ), intArrayOf( - ContextCompat.getColor( - editText.context, + editText.context.color( if (useDarker) R.color.ate_text_disabled_dark else R.color.ate_text_disabled_light - ), ContextCompat.getColor( - editText.context, - if (useDarker) R.color.ate_control_normal_dark else R.color.ate_control_normal_light - ), color + ), + editText.context.color( + if (useDarker) R.color.ate_control_normal_dark else R.color.ate_control_normal_light + ), + color ) ) if (editText is TintableBackgroundView) { @@ -352,16 +343,16 @@ internal object TintHelper { intArrayOf(android.R.attr.state_enabled, android.R.attr.state_checked) ), intArrayOf( - ContextCompat.getColor( - box.context, + box.context.color( if (useDarker) R.color.ate_control_disabled_dark else R.color.ate_control_disabled_light - ), ContextCompat.getColor( - box.context, - if (useDarker) R.color.ate_control_normal_dark else R.color.ate_control_normal_light - ), color + ), + box.context.color( + if (useDarker) R.color.ate_control_normal_dark else R.color.ate_control_normal_light + ), + color ) ) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { @@ -369,9 +360,7 @@ internal object TintHelper { } else { @SuppressLint("PrivateResource") val drawable = createTintedDrawable( - ContextCompat.getDrawable( - box.context, drawable.abc_btn_check_material - ), sl + box.context.drawable(R.drawable.abc_btn_check_material), sl ) box.buttonDrawable = drawable } @@ -397,34 +386,30 @@ internal object TintHelper { val disabled: Int var normal: Int if (thumb) { - disabled = ContextCompat.getColor( - context, + disabled = context.color( if (useDarker) - color.ate_switch_thumb_disabled_dark + R.color.ate_switch_thumb_disabled_dark else - color.ate_switch_thumb_disabled_light + R.color.ate_switch_thumb_disabled_light ) - normal = ContextCompat.getColor( - context, + normal = context.color( if (useDarker) - color.ate_switch_thumb_normal_dark + R.color.ate_switch_thumb_normal_dark else - color.ate_switch_thumb_normal_light + R.color.ate_switch_thumb_normal_light ) } else { - disabled = ContextCompat.getColor( - context, + disabled = context.color( if (useDarker) - color.ate_switch_track_disabled_dark + R.color.ate_switch_track_disabled_dark else - color.ate_switch_track_disabled_light + R.color.ate_switch_track_disabled_light ) - normal = ContextCompat.getColor( - context, + normal = context.color( if (useDarker) - color.ate_switch_track_normal_dark + R.color.ate_switch_track_normal_dark else - color.ate_switch_track_normal_light + R.color.ate_switch_track_normal_light ) } @@ -536,10 +521,10 @@ internal object TintHelper { val fCursorDrawable = clazz.getDeclaredField("mCursorDrawable") fCursorDrawable.isAccessible = true val drawables = arrayOfNulls(2) - drawables[0] = ContextCompat.getDrawable(editText.context, mCursorDrawableRes) + drawables[0] = editText.context.drawable(mCursorDrawableRes) drawables[0] = createTintedDrawable(drawables[0], color) - drawables[1] = ContextCompat.getDrawable(editText.context, mCursorDrawableRes) + drawables[1] = editText.context.drawable(mCursorDrawableRes) drawables[1] = createTintedDrawable(drawables[1], color) fCursorDrawable.set(editor, drawables) diff --git a/library/src/main/java/com/afollestad/aesthetic/utils/View.kt b/library/src/main/java/com/afollestad/aesthetic/utils/View.kt index 546df93..849dbfb 100644 --- a/library/src/main/java/com/afollestad/aesthetic/utils/View.kt +++ b/library/src/main/java/com/afollestad/aesthetic/utils/View.kt @@ -9,16 +9,16 @@ import android.content.res.ColorStateList import android.graphics.drawable.Drawable import android.os.Build import android.support.annotation.ColorInt -import android.support.design.widget.TextInputLayout -import android.support.v4.view.ViewCompat -import android.support.v7.widget.SearchView -import android.support.v7.widget.Toolbar import android.view.Menu import android.view.View import android.widget.EditText import android.widget.ImageView +import androidx.appcompat.widget.SearchView +import androidx.appcompat.widget.Toolbar +import androidx.core.view.ViewCompat import com.afollestad.aesthetic.ActiveInactiveColors import com.afollestad.aesthetic.R +import com.google.android.material.textfield.TextInputLayout import io.reactivex.disposables.CompositeDisposable import io.reactivex.disposables.Disposable import java.lang.reflect.Field diff --git a/library/src/main/java/com/afollestad/aesthetic/utils/ViewUtil.kt b/library/src/main/java/com/afollestad/aesthetic/utils/ViewUtil.kt index 118c4f8..152c45d 100644 --- a/library/src/main/java/com/afollestad/aesthetic/utils/ViewUtil.kt +++ b/library/src/main/java/com/afollestad/aesthetic/utils/ViewUtil.kt @@ -11,28 +11,24 @@ import com.afollestad.aesthetic.Aesthetic import com.afollestad.aesthetic.R.attr import io.reactivex.Observable -/** @author Aidan Follestad (afollestad) */ -object ViewUtil { - - fun getObservableForResId( - context: Context, - @IdRes resId: Int, - fallback: Observable? - ): Observable? { - with(Aesthetic.get()) { - return when (resId) { - 0 -> fallback - context.resId(attr.colorPrimary) -> colorPrimary() - context.resId(attr.colorPrimaryDark) -> colorPrimaryDark() - context.resId(android.R.attr.statusBarColor) -> colorStatusBar() - context.resId(attr.colorAccent) -> colorAccent() - context.resId(android.R.attr.windowBackground) -> colorWindowBackground() - context.resId(android.R.attr.textColorPrimary) -> textColorPrimary() - context.resId(android.R.attr.textColorPrimaryInverse) -> textColorPrimaryInverse() - context.resId(android.R.attr.textColorSecondary) -> textColorSecondary() - context.resId(android.R.attr.textColorSecondaryInverse) -> textColorSecondaryInverse() - else -> fallback - } +fun watchColor( + context: Context, + @IdRes resId: Int, + fallback: Observable? +): Observable? { + with(Aesthetic.get()) { + return when (resId) { + 0 -> fallback + context.resId(attr.colorPrimary) -> colorPrimary() + context.resId(attr.colorPrimaryDark) -> colorPrimaryDark() + context.resId(android.R.attr.statusBarColor) -> colorStatusBar() + context.resId(attr.colorAccent) -> colorAccent() + context.resId(android.R.attr.windowBackground) -> colorWindowBackground() + context.resId(android.R.attr.textColorPrimary) -> textColorPrimary() + context.resId(android.R.attr.textColorPrimaryInverse) -> textColorPrimaryInverse() + context.resId(android.R.attr.textColorSecondary) -> textColorSecondary() + context.resId(android.R.attr.textColorSecondaryInverse) -> textColorSecondaryInverse() + else -> fallback } } -} +} \ No newline at end of file diff --git a/sample/build.gradle b/sample/build.gradle index ff4be03..8790efc 100644 --- a/sample/build.gradle +++ b/sample/build.gradle @@ -25,23 +25,25 @@ android { packagingOptions { exclude 'META-INF/library_release.kotlin_module' + exclude 'META-INF/proguard/androidx-annotations.pro' } } +repositories { + google() + jcenter() +} + dependencies { implementation project(':library') - implementation 'com.android.support:appcompat-v7:' + versions.supportLib - implementation 'com.android.support:design:' + versions.supportLib - implementation 'com.android.support:support-v13:' + versions.supportLib + implementation 'androidx.appcompat:appcompat:' + versions.androidx + implementation 'com.google.android.material:material:' + versions.androidx implementation 'io.reactivex.rxjava2:rxjava:' + versions.rxJava implementation 'io.reactivex.rxjava2:rxandroid:' + versions.rxAndroid implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk7:' + versions.kotlin - - debugImplementation 'com.squareup.leakcanary:leakcanary-android:' + versions.leakCanary - releaseImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:' + versions.leakCanary } apply from: '../spotless.gradle' \ No newline at end of file diff --git a/sample/proguard-rules.pro b/sample/proguard-rules.pro deleted file mode 100644 index 0515aa1..0000000 --- a/sample/proguard-rules.pro +++ /dev/null @@ -1,25 +0,0 @@ -# Add project specific ProGuard rules here. -# By default, the flags in this file are appended to flags specified -# in /Users/z002jdw/Library/Android/sdk/tools/proguard/proguard-android.txt -# You can edit the include path and order by changing the proguardFiles -# directive in build.gradle. -# -# For more details, see -# http://developer.android.com/guide/developing/tools/proguard.html - -# Add any project specific keep options here: - -# If your project uses WebView with JS, uncomment the following -# and specify the fully qualified class name to the JavaScript interface -# class: -#-keepclassmembers class fqcn.of.javascript.interface.for.webview { -# public *; -#} - -# Uncomment this to preserve the line number information for -# debugging stack traces. -#-keepattributes SourceFile,LineNumberTable - -# If you keep the line number information, uncomment this to -# hide the original source file name. -#-renamesourcefileattribute SourceFile diff --git a/sample/src/main/AndroidManifest.xml b/sample/src/main/AndroidManifest.xml index b5d911d..a1c3f35 100644 --- a/sample/src/main/AndroidManifest.xml +++ b/sample/src/main/AndroidManifest.xml @@ -5,7 +5,6 @@ package="com.afollestad.aestheticsample"> Aesthetic.config { colorPrimaryRes(R.color.md_red) @@ -130,6 +131,7 @@ class MainFragment : Fragment() { colorNavigationBarAuto() bottomNavigationBackgroundMode(BottomNavBgMode.PRIMARY_DARK) bottomNavigationIconTextMode(BottomNavIconTextMode.BLACK_WHITE_AUTO) + swipeRefreshLayoutColorsRes(R.color.md_red, R.color.md_amber) } R.id.btn_purple -> Aesthetic.config { colorPrimaryRes(R.color.md_purple) @@ -138,6 +140,7 @@ class MainFragment : Fragment() { colorNavigationBarAuto() bottomNavigationBackgroundMode(BottomNavBgMode.PRIMARY_DARK) bottomNavigationIconTextMode(BottomNavIconTextMode.BLACK_WHITE_AUTO) + swipeRefreshLayoutColorsRes(R.color.md_purple, R.color.md_lime) } R.id.btn_blue -> Aesthetic.config { colorPrimaryRes(R.color.md_blue) @@ -146,6 +149,7 @@ class MainFragment : Fragment() { colorNavigationBarAuto() bottomNavigationBackgroundMode(BottomNavBgMode.PRIMARY_DARK) bottomNavigationIconTextMode(BottomNavIconTextMode.BLACK_WHITE_AUTO) + swipeRefreshLayoutColorsRes(R.color.md_blue, R.color.md_pink) } R.id.btn_green -> Aesthetic.config { colorPrimaryRes(R.color.md_green) @@ -154,6 +158,7 @@ class MainFragment : Fragment() { colorNavigationBarAuto() bottomNavigationBackgroundMode(BottomNavBgMode.PRIMARY_DARK) bottomNavigationIconTextMode(BottomNavIconTextMode.BLACK_WHITE_AUTO) + swipeRefreshLayoutColorsRes(R.color.md_green, R.color.md_blue_grey) } R.id.btn_white -> Aesthetic.config { colorPrimaryRes(R.color.md_white) @@ -162,6 +167,7 @@ class MainFragment : Fragment() { colorNavigationBarAuto() bottomNavigationBackgroundMode(BottomNavBgMode.PRIMARY) bottomNavigationIconTextMode(BottomNavIconTextMode.SELECTED_ACCENT) + swipeRefreshLayoutColorsRes(R.color.md_blue) } } } diff --git a/sample/src/main/java/com/afollestad/aestheticsample/MainPagerAdapter.kt b/sample/src/main/java/com/afollestad/aestheticsample/MainPagerAdapter.kt index e8ffe48..d6c3f60 100644 --- a/sample/src/main/java/com/afollestad/aestheticsample/MainPagerAdapter.kt +++ b/sample/src/main/java/com/afollestad/aestheticsample/MainPagerAdapter.kt @@ -6,12 +6,11 @@ package com.afollestad.aestheticsample import android.content.Context -import android.support.v4.app.Fragment -import android.support.v4.app.FragmentManager -import android.support.v4.app.FragmentStatePagerAdapter +import androidx.fragment.app.Fragment +import androidx.fragment.app.FragmentManager +import androidx.fragment.app.FragmentStatePagerAdapter -/** @author Aidan Follestad (afollestad) - */ +/** @author Aidan Follestad (afollestad) */ internal class MainPagerAdapter( private val context: Context, fm: FragmentManager diff --git a/sample/src/main/java/com/afollestad/aestheticsample/RecyclerViewActivity.kt b/sample/src/main/java/com/afollestad/aestheticsample/RecyclerViewActivity.kt index 872c11f..ec2acf3 100644 --- a/sample/src/main/java/com/afollestad/aestheticsample/RecyclerViewActivity.kt +++ b/sample/src/main/java/com/afollestad/aestheticsample/RecyclerViewActivity.kt @@ -6,7 +6,7 @@ package com.afollestad.aestheticsample import android.os.Bundle -import android.support.v7.widget.LinearLayoutManager +import androidx.recyclerview.widget.LinearLayoutManager import com.afollestad.aesthetic.AestheticActivity import kotlinx.android.synthetic.main.activity_recyclerview.recycler_view import kotlinx.android.synthetic.main.activity_recyclerview.toolbar diff --git a/sample/src/main/java/com/afollestad/aestheticsample/SecondaryFragment.kt b/sample/src/main/java/com/afollestad/aestheticsample/SecondaryFragment.kt index be1b810..156783c 100644 --- a/sample/src/main/java/com/afollestad/aestheticsample/SecondaryFragment.kt +++ b/sample/src/main/java/com/afollestad/aestheticsample/SecondaryFragment.kt @@ -7,10 +7,10 @@ package com.afollestad.aestheticsample import android.content.Intent import android.os.Bundle -import android.support.v4.app.Fragment import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import androidx.fragment.app.Fragment import kotlinx.android.synthetic.main.fragment_secondary.view.bottom_tabs import kotlinx.android.synthetic.main.fragment_secondary.view.coordinator_layout import kotlinx.android.synthetic.main.fragment_secondary.view.drawer_layout diff --git a/sample/src/main/java/com/afollestad/aestheticsample/SwipeRefreshActivity.kt b/sample/src/main/java/com/afollestad/aestheticsample/SwipeRefreshActivity.kt index 83cbac8..1d58eac 100644 --- a/sample/src/main/java/com/afollestad/aestheticsample/SwipeRefreshActivity.kt +++ b/sample/src/main/java/com/afollestad/aestheticsample/SwipeRefreshActivity.kt @@ -7,11 +7,11 @@ package com.afollestad.aestheticsample import android.os.Bundle import com.afollestad.aesthetic.AestheticActivity -import io.reactivex.Observable +import io.reactivex.Observable.just import io.reactivex.disposables.Disposable import kotlinx.android.synthetic.main.activity_swipe_refresh.swipe_refresh_layout import kotlinx.android.synthetic.main.activity_swipe_refresh.toolbar -import java.util.concurrent.TimeUnit +import java.util.concurrent.TimeUnit.SECONDS /** @author Aidan Follestad (afollestad) */ class SwipeRefreshActivity : AestheticActivity() { @@ -24,8 +24,8 @@ class SwipeRefreshActivity : AestheticActivity() { toolbar.setNavigationOnClickListener { finish() } swipe_refresh_layout.setOnRefreshListener { - delayed = Observable.just(true) - .delay(2, TimeUnit.SECONDS) + delayed = just(true) + .delay(2, SECONDS) .subscribe { swipe_refresh_layout.isRefreshing = false } } } diff --git a/sample/src/main/res/layout/activity_bottom_nav.xml b/sample/src/main/res/layout/activity_bottom_nav.xml index 8b86940..c53807e 100644 --- a/sample/src/main/res/layout/activity_bottom_nav.xml +++ b/sample/src/main/res/layout/activity_bottom_nav.xml @@ -7,7 +7,7 @@ android:orientation="vertical" > - - - - - - + - + - - + - + diff --git a/sample/src/main/res/layout/activity_drawer.xml b/sample/src/main/res/layout/activity_drawer.xml index 925df47..fe5a8d5 100644 --- a/sample/src/main/res/layout/activity_drawer.xml +++ b/sample/src/main/res/layout/activity_drawer.xml @@ -1,5 +1,5 @@ - - - - + diff --git a/sample/src/main/res/layout/activity_main.xml b/sample/src/main/res/layout/activity_main.xml index 25267eb..2078a16 100644 --- a/sample/src/main/res/layout/activity_main.xml +++ b/sample/src/main/res/layout/activity_main.xml @@ -7,20 +7,20 @@ android:orientation="vertical" > - - - - + diff --git a/sample/src/main/res/layout/activity_recyclerview.xml b/sample/src/main/res/layout/activity_recyclerview.xml index 774b1f1..176346e 100644 --- a/sample/src/main/res/layout/activity_recyclerview.xml +++ b/sample/src/main/res/layout/activity_recyclerview.xml @@ -7,7 +7,7 @@ android:orientation="vertical" > - - - - - + diff --git a/sample/src/main/res/layout/fragment_main.xml b/sample/src/main/res/layout/fragment_main.xml index 38ebf10..08c4691 100644 --- a/sample/src/main/res/layout/fragment_main.xml +++ b/sample/src/main/res/layout/fragment_main.xml @@ -24,7 +24,7 @@ android:paddingTop="@dimen/content_inset_more" > - - - - + - - + -