From 904f31f9e61baf16d17e9fa0ff6603842a038496 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andre=CC=81=20Sousa?= Date: Thu, 22 Oct 2020 09:01:36 +0100 Subject: [PATCH] [TASK] Update libraries --- .travis.yml | 51 +++++++++---- build.gradle | 20 +---- demo/build.gradle | 11 ++- demo/src/main/res/layout/list_item.xml | 4 +- gradle/wrapper/gradle-wrapper.properties | 3 +- lib/build.gradle | 24 ++++-- .../andrefrsousa/supertoolbar/KExtensions.kt | 36 --------- .../andrefrsousa/supertoolbar/SuperToolbar.kt | 76 +++++++++---------- .../com/andrefrsousa/supertoolbar/Utils.kt | 30 -------- .../main/res/layout/super_toolbar_title.xml | 4 +- 10 files changed, 101 insertions(+), 158 deletions(-) delete mode 100644 lib/src/main/java/com/andrefrsousa/supertoolbar/KExtensions.kt delete mode 100644 lib/src/main/java/com/andrefrsousa/supertoolbar/Utils.kt diff --git a/.travis.yml b/.travis.yml index b1f4b3a..928a5b2 100755 --- a/.travis.yml +++ b/.travis.yml @@ -1,31 +1,52 @@ language: android +jdk: oraclejdk8 + +env: + global: + - ANDROID_API_LEVEL=30 + - ANDROID_BUILD_TOOLS_VERSION=30.0.2 + +cache: + directories: + - $HOME/.gradle/caches/ + - $HOME/.gradle/wrapper/ branches: only: - master android: - components: - # Uncomment the lines below if you want to - # use the latest revision of Android SDK Tools - - platform-tools - - tools + licenses: + - android-sdk-preview-license-.+ + - android-sdk-license-.+ + - google-gdk-license-.+ + components: + - tools + - platform-tools # The BuildTools version used by your project - - build-tools-29.0.2 - + - build-tools-$ANDROID_BUILD_TOOLS_VERSION # The SDK version used to compile your project - - android-29 + - android-$ANDROID_API_LEVEL + # Additional components + - extra-google-google_play_services + - extra-google-m2repository + - extra-android-m2repository + - addon-google_apis-google-$ANDROID_API_LEVEL + # Android emulator + - android-22 + - sys-img-armeabi-v7a-android-22 before_install: - - yes | sdkmanager "platforms;android-29" + - yes | sdkmanager "platforms;android-30" + - yes | sdkmanager "build-tools;30.0.2" before_script: - - chmod +x gradlew - - mkdir "$ANDROID_HOME/licenses" || true - - echo -e "\n8933bad161af4178b1185d1a37fbf41ea5269c55" > "$ANDROID_HOME/licenses/android-sdk-license" - - echo -e "\n84831b9409646a918e30573bab4c9c91346d8abd" > "$ANDROID_HOME/licenses/android-sdk-preview-license" - - yes | sdkmanager --update - - yes | sdkmanager --licenses + # Launch emulator before the execution + - echo no | android create avd --force -n test -t android-22 --abi armeabi-v7a + - emulator -avd test -no-audio -no-window & + - android-wait-for-emulator + - adb shell input keyevent 82 & + - "curl -H 'Cache-Control: no-cache' https://raw.githubusercontent.com/fossas/fossa-cli/master/install.sh | sudo bash" script: ./gradlew build assembleDebug diff --git a/build.gradle b/build.gradle index 64cc754..83b0508 100644 --- a/build.gradle +++ b/build.gradle @@ -1,17 +1,12 @@ -// Top-level build file where you can add configuration options common to all sub-projects/modules. - buildscript { - ext.kotlin_version = '1.3.50' repositories { google() jcenter() } - dependencies { - classpath 'com.android.tools.build:gradle:3.5.1' - classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" - // NOTE: Do not place your application dependencies here; they belong - // in the individual module build.gradle files + dependencies { + classpath 'com.android.tools.build:gradle:4.1.0' + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.4.10" } } @@ -22,15 +17,6 @@ allprojects { } } -repositories { - flatDir { - dirs 'libs' - } - - maven { url "https://nexus.wit-software.com/repository/releases/" } - maven { url "https://nexus.wit-software.com/repository/snapshots/" } -} - task clean(type: Delete) { delete rootProject.buildDir } diff --git a/demo/build.gradle b/demo/build.gradle index b598c64..baf9113 100644 --- a/demo/build.gradle +++ b/demo/build.gradle @@ -3,12 +3,12 @@ apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' android { - compileSdkVersion 29 + compileSdkVersion 30 defaultConfig { applicationId "com.andrefrsousa.supertoolbar.demo" minSdkVersion 16 - targetSdkVersion 29 + targetSdkVersion 30 versionCode 1 versionName "1.0" } @@ -17,8 +17,7 @@ android { dependencies { implementation project(path: ':lib') - implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" - implementation 'androidx.appcompat:appcompat:1.1.0' - implementation 'androidx.recyclerview:recyclerview:1.0.0' - implementation 'androidx.constraintlayout:constraintlayout:1.1.3' + implementation 'androidx.appcompat:appcompat:1.2.0' + implementation 'androidx.recyclerview:recyclerview:1.1.0' + implementation 'androidx.constraintlayout:constraintlayout:2.0.2' } diff --git a/demo/src/main/res/layout/list_item.xml b/demo/src/main/res/layout/list_item.xml index a1f5cf0..58297f8 100644 --- a/demo/src/main/res/layout/list_item.xml +++ b/demo/src/main/res/layout/list_item.xml @@ -5,9 +5,9 @@ + android:padding="8dp" + android:text="Hello World!" /> \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index ca9d628..0127388 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,6 @@ +#Thu Oct 22 08:45:56 WEST 2020 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-all.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-6.5.1-all.zip diff --git a/lib/build.gradle b/lib/build.gradle index f585238..cbc183c 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -3,11 +3,11 @@ apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' android { - compileSdkVersion 29 + compileSdkVersion 30 defaultConfig { minSdkVersion 16 - targetSdkVersion 29 + targetSdkVersion 30 versionCode 1 versionName "1.0.0" } @@ -19,13 +19,21 @@ android { } } + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } + + kotlinOptions { + jvmTarget = JavaVersion.VERSION_1_8.toString() + } + + buildFeatures { + viewBinding true + } } dependencies { - // Kotlin - implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" - - // Support libraries - implementation 'androidx.appcompat:appcompat:1.1.0' - implementation 'com.google.android.material:material:1.0.0' + implementation 'androidx.appcompat:appcompat:1.2.0' + implementation 'com.google.android.material:material:1.2.1' } diff --git a/lib/src/main/java/com/andrefrsousa/supertoolbar/KExtensions.kt b/lib/src/main/java/com/andrefrsousa/supertoolbar/KExtensions.kt deleted file mode 100644 index 0de9ac6..0000000 --- a/lib/src/main/java/com/andrefrsousa/supertoolbar/KExtensions.kt +++ /dev/null @@ -1,36 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2018 André Sousa - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.andrefrsousa.supertoolbar - -import android.view.LayoutInflater -import android.view.View -import android.view.ViewGroup - -//region VIEW - -internal fun ViewGroup.inflate(layoutId: Int): View { - return LayoutInflater.from(context).inflate(layoutId, this, false) -} - -//endregion \ No newline at end of file diff --git a/lib/src/main/java/com/andrefrsousa/supertoolbar/SuperToolbar.kt b/lib/src/main/java/com/andrefrsousa/supertoolbar/SuperToolbar.kt index 1802022..b5d5710 100644 --- a/lib/src/main/java/com/andrefrsousa/supertoolbar/SuperToolbar.kt +++ b/lib/src/main/java/com/andrefrsousa/supertoolbar/SuperToolbar.kt @@ -28,16 +28,17 @@ import android.graphics.Typeface import android.os.Build import android.util.AttributeSet import android.view.Gravity +import android.view.LayoutInflater import android.view.animation.DecelerateInterpolator -import androidx.appcompat.widget.AppCompatTextView import androidx.appcompat.widget.Toolbar import androidx.core.view.ViewCompat +import com.andrefrsousa.supertoolbar.databinding.SuperToolbarTitleBinding private const val DURATION = 250 open class SuperToolbar : Toolbar { - private lateinit var titleView: AppCompatTextView + private lateinit var binding: SuperToolbarTitleBinding private var isElevationShown = false private var centerTitle = false @@ -45,6 +46,8 @@ open class SuperToolbar : Toolbar { private var animationDuration = 0L private var toolbarElevation = 0f + // region Constructor + constructor(context: Context) : super(context) { initView(context, null, 0) } @@ -62,15 +65,11 @@ open class SuperToolbar : Toolbar { } private fun initView(context: Context, attrs: AttributeSet?, defStyleAttr: Int) { - if (isInEditMode || attrs == null) { - return - } + if (attrs == null) return with(context.obtainStyledAttributes(attrs, R.styleable.SuperToolbar, defStyleAttr, 0)) { - animationDuration = - getInt(R.styleable.SuperToolbar_superToolbar_animationDuration, DURATION).toLong() - isElevationShown = - getBoolean(R.styleable.SuperToolbar_superToolbar_showElevationAtStart, false) + animationDuration = getInt(R.styleable.SuperToolbar_superToolbar_animationDuration, DURATION).toLong() + isElevationShown = getBoolean(R.styleable.SuperToolbar_superToolbar_showElevationAtStart, false) centerTitle = getBoolean(R.styleable.SuperToolbar_superToolbar_centerTitle, false) useLightFont = getBoolean(R.styleable.SuperToolbar_superToolbar_useLightFont, false) recycle() @@ -80,38 +79,35 @@ open class SuperToolbar : Toolbar { with(ViewCompat.getElevation(this)) { toolbarElevation = if (this == 0f) { resources.getDimension(R.dimen.super_toolbar_default_elevation) - } else { - this - } + + } else this } // By default we remove the elevation when creating the toolbar - if (!isElevationShown) { - ViewCompat.setElevation(this, 0f) - } + if (!isElevationShown) ViewCompat.setElevation(this, 0f) // Add a custom title view if (centerTitle || useLightFont) { - titleView = inflate(R.layout.super_toolbar_title) as AppCompatTextView + binding = SuperToolbarTitleBinding.inflate(LayoutInflater.from(context), this, false) - if (useLightFont) { - titleView.typeface = Typeface.SANS_SERIF - } + if (useLightFont) binding.toolbarTitle.typeface = Typeface.SANS_SERIF if (centerTitle) { - val layoutParams = titleView.layoutParams as Toolbar.LayoutParams + val layoutParams = binding.toolbarTitle.layoutParams as LayoutParams layoutParams.gravity = Gravity.CENTER - addView(titleView, layoutParams) + addView(binding.toolbarTitle, layoutParams) - } else { - addView(titleView) - } + } else addView(binding.toolbarTitle) } } + // endregion + + // region Methods from Toolbar + override fun setTitle(resId: Int) { - if (::titleView.isInitialized) { - titleView.setText(resId) + if (::binding.isInitialized) { + binding.toolbarTitle.setText(resId) return } @@ -119,23 +115,21 @@ open class SuperToolbar : Toolbar { } override fun setTitle(title: CharSequence?) { - if (::titleView.isInitialized) { - titleView.text = title + if (::binding.isInitialized) { + binding.toolbarTitle.text = title return } super.setTitle(title) } + @Suppress("DEPRECATION") override fun setTitleTextAppearance(context: Context?, resId: Int) { - if (::titleView.isInitialized) { - if (hasMinimumSdk(Build.VERSION_CODES.M)) { - titleView.setTextAppearance(resId) - - } else { - titleView.setTextAppearance(context, resId) - } + if (::binding.isInitialized) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + binding.toolbarTitle.setTextAppearance(resId) + } else binding.toolbarTitle.setTextAppearance(context, resId) return } @@ -143,15 +137,17 @@ open class SuperToolbar : Toolbar { } override fun setTitleTextColor(color: Int) { - if (::titleView.isInitialized) { - titleView.setTextColor(color) + if (::binding.isInitialized) { + binding.toolbarTitle.setTextColor(color) return } super.setTitleTextColor(color) } - //region PUBLIC METHODS + // endregion + + //region Public methods /** * Toggles the toolbar elevation visibility using an animation @@ -159,9 +155,7 @@ open class SuperToolbar : Toolbar { * @param show true if you want to show the elevation; false otherwise */ fun setElevationVisibility(show: Boolean) { - if (isElevationShown == show) { - return - } + if (isElevationShown == show) return isElevationShown = show diff --git a/lib/src/main/java/com/andrefrsousa/supertoolbar/Utils.kt b/lib/src/main/java/com/andrefrsousa/supertoolbar/Utils.kt deleted file mode 100644 index 4e2b9f7..0000000 --- a/lib/src/main/java/com/andrefrsousa/supertoolbar/Utils.kt +++ /dev/null @@ -1,30 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2018 André Sousa - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.andrefrsousa.supertoolbar - -import android.os.Build - -internal fun hasMinimumSdk(minimumSdk: Int): Boolean { - return Build.VERSION.SDK_INT >= minimumSdk -} \ No newline at end of file diff --git a/lib/src/main/res/layout/super_toolbar_title.xml b/lib/src/main/res/layout/super_toolbar_title.xml index 9719316..6319c45 100644 --- a/lib/src/main/res/layout/super_toolbar_title.xml +++ b/lib/src/main/res/layout/super_toolbar_title.xml @@ -1,6 +1,6 @@ \ No newline at end of file + android:layout_height="wrap_content" /> \ No newline at end of file