From 02464adde6f4505920a1afda3459840bf15c2229 Mon Sep 17 00:00:00 2001 From: Joe Timmins Date: Thu, 24 Sep 2020 18:29:15 +0100 Subject: [PATCH 01/16] Update kotlin version, android gradle plugin, and others --- app/build.gradle | 47 +++++++++---------- .../teresaholfeld/stories/app/MainActivity.kt | 14 +++--- app/src/main/res/layout/activity_main.xml | 16 +++---- build.gradle | 38 +++++++-------- gradle.properties | 2 + gradle/wrapper/gradle-wrapper.properties | 4 +- library/build.gradle | 43 +++++++++-------- .../stories/PausableProgressBar.kt | 20 ++++---- .../stories/StoriesProgressView.kt | 12 +++-- 9 files changed, 99 insertions(+), 97 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 4b1b752..d68a27d 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -2,34 +2,33 @@ apply plugin: 'com.android.application' apply plugin: 'kotlin-android' android { - compileSdkVersion 28 - buildToolsVersion '28.0.3' - defaultConfig { - applicationId "com.teresaholfeld.stories.app" - minSdkVersion 15 - targetSdkVersion 28 - versionCode 1 - versionName "1.0" - testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" - } - buildTypes { - release { - minifyEnabled false - proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + compileSdkVersion 30 + defaultConfig { + applicationId "com.teresaholfeld.stories.app" + minSdkVersion 15 + targetSdkVersion 30 + versionCode 1 + versionName "1.0" + testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner' + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } } - } } dependencies { - implementation 'com.github.teresaholfeld:Stories:1.1.2' - implementation 'com.android.support:appcompat-v7:28.0.0' - implementation 'com.android.support.constraint:constraint-layout:1.1.3' - testImplementation 'junit:junit:4.12' - androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', { - exclude group: 'com.android.support', module: 'support-annotations' - }) - implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" + implementation 'androidx.appcompat:appcompat:1.2.0' + implementation 'androidx.constraintlayout:constraintlayout:2.0.1' + testImplementation 'junit:junit:4.13' + androidTestImplementation('androidx.test.espresso:espresso-core:3.3.0', { + exclude group: 'com.android.support', module: 'support-annotations' + }) + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" + implementation project(':library') } repositories { - mavenCentral() + mavenCentral() } diff --git a/app/src/main/java/com/teresaholfeld/stories/app/MainActivity.kt b/app/src/main/java/com/teresaholfeld/stories/app/MainActivity.kt index 7172626..fc5291c 100644 --- a/app/src/main/java/com/teresaholfeld/stories/app/MainActivity.kt +++ b/app/src/main/java/com/teresaholfeld/stories/app/MainActivity.kt @@ -1,11 +1,11 @@ package com.teresaholfeld.stories.app import android.os.Bundle -import android.support.v7.app.AppCompatActivity import android.view.MotionEvent import android.view.View import android.view.WindowManager import android.widget.ImageView +import androidx.appcompat.app.AppCompatActivity import com.teresaholfeld.stories.StoriesProgressView class MainActivity : AppCompatActivity(), StoriesProgressView.StoriesListener { @@ -15,12 +15,12 @@ class MainActivity : AppCompatActivity(), StoriesProgressView.StoriesListener { private var counter = 0 private val resources = intArrayOf( - R.drawable.sample1, - R.drawable.sample2, - R.drawable.sample3, - R.drawable.sample4, - R.drawable.sample5, - R.drawable.sample6 + R.drawable.sample1, + R.drawable.sample2, + R.drawable.sample3, + R.drawable.sample4, + R.drawable.sample5, + R.drawable.sample6 ) private val durations = longArrayOf(500L, 1000L, 1500L, 4000L, 5000L, 1000) diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index abc7fa3..5cd040b 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -1,9 +1,9 @@ + xmlns:app="http://schemas.android.com/apk/res-auto" + xmlns:tools="http://schemas.android.com/tools" + android:layout_width="match_parent" + android:layout_height="match_parent"> + tools:src="@drawable/sample1" /> + android:layout_weight="1" /> + android:layout_weight="1" /> + app:progressColor="@color/colorAccent" /> \ No newline at end of file diff --git a/build.gradle b/build.gradle index 330b58c..6909257 100644 --- a/build.gradle +++ b/build.gradle @@ -1,29 +1,29 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { - ext.kotlin_version = '1.3.21' - repositories { - google() - jcenter() - mavenCentral() - } - dependencies { - classpath 'com.android.tools.build:gradle:3.3.1' - classpath 'com.github.dcendents:android-maven-gradle-plugin:2.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 - } + ext.kotlin_version = '1.4.10' + repositories { + google() + jcenter() + mavenCentral() + } + dependencies { + classpath 'com.android.tools.build:gradle:4.0.1' + classpath 'com.github.dcendents:android-maven-gradle-plugin:2.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 + } } allprojects { - repositories { - google() - jcenter() - maven { url "https://jitpack.io" } - } + repositories { + google() + jcenter() + maven { url "https://jitpack.io" } + } } task clean(type: Delete) { - delete rootProject.buildDir + delete rootProject.buildDir } diff --git a/gradle.properties b/gradle.properties index aac7c9b..9e6fce1 100644 --- a/gradle.properties +++ b/gradle.properties @@ -9,6 +9,8 @@ # Specifies the JVM arguments used for the daemon process. # The setting is particularly useful for tweaking memory settings. +android.enableJetifier=true +android.useAndroidX=true org.gradle.jvmargs=-Xmx1536m # When configured, Gradle will run in incubating parallel mode. diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 096f39d..d576996 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Mon Sep 10 10:57:05 WEST 2018 +#Thu Sep 24 18:15:02 BST 2020 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-6.6-all.zip diff --git a/library/build.gradle b/library/build.gradle index 98a57f5..1dc0656 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -3,35 +3,34 @@ apply plugin: 'kotlin-android' apply plugin: 'com.github.dcendents.android-maven' android { - compileSdkVersion 28 - buildToolsVersion '28.0.3' - group = "com.teresaholfeld.stories" + compileSdkVersion 30 + group = "com.teresaholfeld.stories" - defaultConfig { - minSdkVersion 15 - targetSdkVersion 28 - versionCode 1 - versionName "1.1.4" + defaultConfig { + minSdkVersion 15 + targetSdkVersion 30 + versionCode 2 + versionName "1.1.5" - testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner' - } - buildTypes { - release { - minifyEnabled false - proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } - } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } } dependencies { - implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version" - implementation 'com.android.support:appcompat-v7:28.0.0' - testImplementation 'junit:junit:4.12' - androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', { - exclude group: 'com.android.support', module: 'support-annotations' - }) + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version" + implementation 'androidx.appcompat:appcompat:1.2.0' + testImplementation 'junit:junit:4.13' + androidTestImplementation('androidx.test.espresso:espresso-core:3.3.0', { + exclude group: 'com.android.support', module: 'support-annotations' + }) } repositories { - mavenCentral() + mavenCentral() } diff --git a/library/src/main/java/com/teresaholfeld/stories/PausableProgressBar.kt b/library/src/main/java/com/teresaholfeld/stories/PausableProgressBar.kt index 7921f3a..2b40955 100644 --- a/library/src/main/java/com/teresaholfeld/stories/PausableProgressBar.kt +++ b/library/src/main/java/com/teresaholfeld/stories/PausableProgressBar.kt @@ -115,14 +115,14 @@ internal class PausableProgressBar constructor(context: Context, animation = null } - private inner class PausableScaleAnimation internal constructor(fromX: Float, - toX: Float, - fromY: Float, - toY: Float, - pivotXType: Int, - pivotXValue: Float, - pivotYType: Int, - pivotYValue: Float) + private inner class PausableScaleAnimation(fromX: Float, + toX: Float, + fromY: Float, + toY: Float, + pivotXType: Int, + pivotXValue: Float, + pivotYType: Int, + pivotYValue: Float) : ScaleAnimation(fromX, toX, fromY, toY, pivotXType, pivotXValue, pivotYType, pivotYValue) { private var mElapsedAtPause: Long = 0 @@ -141,7 +141,7 @@ internal class PausableProgressBar constructor(context: Context, /*** * pause animation */ - internal fun pause() { + fun pause() { if (mPaused) return mElapsedAtPause = 0 mPaused = true @@ -150,7 +150,7 @@ internal class PausableProgressBar constructor(context: Context, /*** * resume animation */ - internal fun resume() { + fun resume() { mPaused = false } } diff --git a/library/src/main/java/com/teresaholfeld/stories/StoriesProgressView.kt b/library/src/main/java/com/teresaholfeld/stories/StoriesProgressView.kt index 36d3f5f..97a495f 100644 --- a/library/src/main/java/com/teresaholfeld/stories/StoriesProgressView.kt +++ b/library/src/main/java/com/teresaholfeld/stories/StoriesProgressView.kt @@ -5,16 +5,16 @@ package com.teresaholfeld.stories import android.annotation.TargetApi import android.content.Context import android.os.Build -import android.support.v4.content.ContextCompat import android.util.AttributeSet import android.view.View import android.widget.LinearLayout +import androidx.core.content.ContextCompat import java.util.ArrayList class StoriesProgressView : LinearLayout { - private val progressBarLayoutParam = LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT, 1f) - private val spaceLayoutParam = LinearLayout.LayoutParams(5, LinearLayout.LayoutParams.WRAP_CONTENT) + private val progressBarLayoutParam = LayoutParams(0, LayoutParams.WRAP_CONTENT, 1f) + private val spaceLayoutParam = LayoutParams(5, LayoutParams.WRAP_CONTENT) private val defaultColor = ContextCompat.getColor(context, R.color.progress_primary) private val defaultBackgroundColor = ContextCompat.getColor(context, R.color.progress_secondary) @@ -24,6 +24,7 @@ class StoriesProgressView : LinearLayout { private val progressBars = ArrayList() private var storiesCount = -1 + /** * pointer of running animation */ @@ -42,7 +43,8 @@ class StoriesProgressView : LinearLayout { fun onComplete() } - @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : super(context, attrs) { + @JvmOverloads + constructor(context: Context, attrs: AttributeSet? = null) : super(context, attrs) { init(context, attrs) } @@ -57,7 +59,7 @@ class StoriesProgressView : LinearLayout { } private fun init(context: Context, attrs: AttributeSet?) { - orientation = LinearLayout.HORIZONTAL + orientation = HORIZONTAL val typedArray = context.obtainStyledAttributes(attrs, R.styleable.StoriesProgressView) storiesCount = typedArray.getInt(R.styleable.StoriesProgressView_progressCount, 0) progressColor = typedArray.getColor(R.styleable.StoriesProgressView_progressColor, defaultColor) From 56a0c17adceb0116dfbd60dde5374aa1c36ebc01 Mon Sep 17 00:00:00 2001 From: Joe Timmins Date: Thu, 24 Sep 2020 18:40:20 +0100 Subject: [PATCH 02/16] Call findViewById to fix sample app --- .../teresaholfeld/stories/app/MainActivity.kt | 41 +++++-------------- 1 file changed, 10 insertions(+), 31 deletions(-) diff --git a/app/src/main/java/com/teresaholfeld/stories/app/MainActivity.kt b/app/src/main/java/com/teresaholfeld/stories/app/MainActivity.kt index fc5291c..4a78550 100644 --- a/app/src/main/java/com/teresaholfeld/stories/app/MainActivity.kt +++ b/app/src/main/java/com/teresaholfeld/stories/app/MainActivity.kt @@ -1,7 +1,6 @@ package com.teresaholfeld.stories.app import android.os.Bundle -import android.view.MotionEvent import android.view.View import android.view.WindowManager import android.widget.ImageView @@ -10,7 +9,7 @@ import com.teresaholfeld.stories.StoriesProgressView class MainActivity : AppCompatActivity(), StoriesProgressView.StoriesListener { - private var storiesProgressView: StoriesProgressView? = null + private lateinit var storiesProgressView: StoriesProgressView private var image: ImageView? = null private var counter = 0 @@ -23,54 +22,34 @@ class MainActivity : AppCompatActivity(), StoriesProgressView.StoriesListener { R.drawable.sample6 ) - private val durations = longArrayOf(500L, 1000L, 1500L, 4000L, 5000L, 1000) - - private var pressTime = 0L - private var limit = 500L - - private val onTouchListener = View.OnTouchListener { v, event -> - when (event.action) { - MotionEvent.ACTION_DOWN -> { - pressTime = System.currentTimeMillis() - storiesProgressView?.pause() - return@OnTouchListener false - } - MotionEvent.ACTION_UP -> { - val now = System.currentTimeMillis() - storiesProgressView?.resume() - return@OnTouchListener limit < now - pressTime - } - } - false - } +// private val durations = longArrayOf(500L, 1000L, 1500L, 4000L, 5000L, 1000) override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) window.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN) setContentView(R.layout.activity_main) - storiesProgressView?.setStoriesCount(PROGRESS_COUNT) - storiesProgressView?.setStoryDuration(3000L) + storiesProgressView = findViewById(R.id.stories) + storiesProgressView.setStoriesCount(PROGRESS_COUNT) + storiesProgressView.setStoryDuration(3000L) // or // storiesProgressView.setStoriesCountWithDurations(durations); - storiesProgressView?.setStoriesListener(this) + storiesProgressView.setStoriesListener(this) counter = 2 - storiesProgressView?.startStories(counter) + storiesProgressView.startStories(counter) image = findViewById(R.id.image) as ImageView image?.setImageResource(resources[counter]) // bind reverse view val reverse = findViewById(R.id.reverse) - reverse.setOnClickListener { storiesProgressView?.reverse() } - reverse.setOnTouchListener(onTouchListener) + reverse.setOnClickListener { storiesProgressView.reverse() } // bind skip view val skip = findViewById(R.id.skip) - skip.setOnClickListener { storiesProgressView?.skip() } - skip.setOnTouchListener(onTouchListener) + skip.setOnClickListener { storiesProgressView.skip() } } override fun onNext() { @@ -86,7 +65,7 @@ class MainActivity : AppCompatActivity(), StoriesProgressView.StoriesListener { override fun onDestroy() { // Very important ! - storiesProgressView?.destroy() + storiesProgressView.destroy() super.onDestroy() } From b1d8299b5884456c833b22e2d939fcbf76b1b55c Mon Sep 17 00:00:00 2001 From: Joe Timmins Date: Thu, 24 Sep 2020 19:22:23 +0100 Subject: [PATCH 03/16] Add styleable attributes for gap and progress bar height --- app/src/main/res/layout/activity_main.xml | 4 +++- .../stories/StoriesProgressView.kt | 24 ++++++++++++++----- library/src/main/res/values/attrs.xml | 8 ++++--- 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 5cd040b..2d295bf 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -40,5 +40,7 @@ android:paddingLeft="8dp" android:paddingRight="8dp" app:progressBackgroundColor="@color/purple" - app:progressColor="@color/colorAccent" /> + app:progressColor="@color/colorAccent" + app:progressGap="8dp" + app:progressHeight="40dp" /> \ No newline at end of file diff --git a/library/src/main/java/com/teresaholfeld/stories/StoriesProgressView.kt b/library/src/main/java/com/teresaholfeld/stories/StoriesProgressView.kt index 97a495f..94f833b 100644 --- a/library/src/main/java/com/teresaholfeld/stories/StoriesProgressView.kt +++ b/library/src/main/java/com/teresaholfeld/stories/StoriesProgressView.kt @@ -13,8 +13,19 @@ import java.util.ArrayList class StoriesProgressView : LinearLayout { - private val progressBarLayoutParam = LayoutParams(0, LayoutParams.WRAP_CONTENT, 1f) - private val spaceLayoutParam = LayoutParams(5, LayoutParams.WRAP_CONTENT) + private var progressHeightInPixels: Int? = null + private val defaultHeight = LayoutParams.WRAP_CONTENT + private val actualHeight by lazy { progressHeightInPixels ?: defaultHeight } + private val progressBarLayoutParams by lazy { + LayoutParams(0, actualHeight, 1f) + } + + private var progressGapInPixels: Int? = null + private val defaultGap = 5 + private val gapLayoutParams by lazy { + LayoutParams(progressGapInPixels ?: defaultGap, actualHeight) + } + private val defaultColor = ContextCompat.getColor(context, R.color.progress_primary) private val defaultBackgroundColor = ContextCompat.getColor(context, R.color.progress_secondary) @@ -63,8 +74,9 @@ class StoriesProgressView : LinearLayout { val typedArray = context.obtainStyledAttributes(attrs, R.styleable.StoriesProgressView) storiesCount = typedArray.getInt(R.styleable.StoriesProgressView_progressCount, 0) progressColor = typedArray.getColor(R.styleable.StoriesProgressView_progressColor, defaultColor) - progressBackgroundColor = typedArray.getColor(R.styleable.StoriesProgressView_progressBackgroundColor, - defaultBackgroundColor) + progressBackgroundColor = typedArray.getColor(R.styleable.StoriesProgressView_progressBackgroundColor, defaultBackgroundColor) + progressHeightInPixels = typedArray.getDimensionPixelSize(R.styleable.StoriesProgressView_progressHeight, 0) + progressGapInPixels = typedArray.getDimensionPixelSize(R.styleable.StoriesProgressView_progressGap, 0) typedArray.recycle() bindViews() } @@ -85,13 +97,13 @@ class StoriesProgressView : LinearLayout { private fun createProgressBar(): PausableProgressBar { val p = PausableProgressBar(context, progressColor, progressBackgroundColor) - p.layoutParams = progressBarLayoutParam + p.layoutParams = progressBarLayoutParams return p } private fun createSpace(): View { val v = View(context) - v.layoutParams = spaceLayoutParam + v.layoutParams = gapLayoutParams return v } diff --git a/library/src/main/res/values/attrs.xml b/library/src/main/res/values/attrs.xml index 1f527d8..4717a9d 100644 --- a/library/src/main/res/values/attrs.xml +++ b/library/src/main/res/values/attrs.xml @@ -1,8 +1,10 @@ - - - + + + + + \ No newline at end of file From 127a323c8d344ca6e4f6094ed9c92e98140853b9 Mon Sep 17 00:00:00 2001 From: Joe Timmins Date: Thu, 24 Sep 2020 19:25:34 +0100 Subject: [PATCH 04/16] Make progress bars same height as parent instead of hardcoded 2dp --- app/src/main/res/layout/activity_main.xml | 2 +- library/src/main/res/layout/pausable_progress.xml | 13 +++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 2d295bf..10e980e 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -34,7 +34,7 @@ + android:layout_height="match_parent" + tools:layout_height="8dp"> + tools:visibility="visible" /> From 4fdf4759278fce0830b4ca70d18748595fe25cf6 Mon Sep 17 00:00:00 2001 From: Joe Timmins Date: Thu, 24 Sep 2020 19:35:12 +0100 Subject: [PATCH 05/16] Remove progressHeight attribute, use layout height of parent --- app/src/main/res/layout/activity_main.xml | 3 +-- .../com/teresaholfeld/stories/StoriesProgressView.kt | 10 ++-------- library/src/main/res/values/attrs.xml | 1 - 3 files changed, 3 insertions(+), 11 deletions(-) diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 10e980e..d1cd5f2 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -41,6 +41,5 @@ android:paddingRight="8dp" app:progressBackgroundColor="@color/purple" app:progressColor="@color/colorAccent" - app:progressGap="8dp" - app:progressHeight="40dp" /> + app:progressGap="8dp" /> \ No newline at end of file diff --git a/library/src/main/java/com/teresaholfeld/stories/StoriesProgressView.kt b/library/src/main/java/com/teresaholfeld/stories/StoriesProgressView.kt index 94f833b..cb11f3e 100644 --- a/library/src/main/java/com/teresaholfeld/stories/StoriesProgressView.kt +++ b/library/src/main/java/com/teresaholfeld/stories/StoriesProgressView.kt @@ -13,17 +13,12 @@ import java.util.ArrayList class StoriesProgressView : LinearLayout { - private var progressHeightInPixels: Int? = null - private val defaultHeight = LayoutParams.WRAP_CONTENT - private val actualHeight by lazy { progressHeightInPixels ?: defaultHeight } - private val progressBarLayoutParams by lazy { - LayoutParams(0, actualHeight, 1f) - } + private val progressBarLayoutParams = LayoutParams(0, LayoutParams.MATCH_PARENT, 1f) private var progressGapInPixels: Int? = null private val defaultGap = 5 private val gapLayoutParams by lazy { - LayoutParams(progressGapInPixels ?: defaultGap, actualHeight) + LayoutParams(progressGapInPixels ?: defaultGap, LayoutParams.MATCH_PARENT) } private val defaultColor = ContextCompat.getColor(context, R.color.progress_primary) @@ -75,7 +70,6 @@ class StoriesProgressView : LinearLayout { storiesCount = typedArray.getInt(R.styleable.StoriesProgressView_progressCount, 0) progressColor = typedArray.getColor(R.styleable.StoriesProgressView_progressColor, defaultColor) progressBackgroundColor = typedArray.getColor(R.styleable.StoriesProgressView_progressBackgroundColor, defaultBackgroundColor) - progressHeightInPixels = typedArray.getDimensionPixelSize(R.styleable.StoriesProgressView_progressHeight, 0) progressGapInPixels = typedArray.getDimensionPixelSize(R.styleable.StoriesProgressView_progressGap, 0) typedArray.recycle() bindViews() diff --git a/library/src/main/res/values/attrs.xml b/library/src/main/res/values/attrs.xml index 4717a9d..16fbddf 100644 --- a/library/src/main/res/values/attrs.xml +++ b/library/src/main/res/values/attrs.xml @@ -4,7 +4,6 @@ - \ No newline at end of file From acce8ebd0d9accdac46e4389c117b03a1f09271e Mon Sep 17 00:00:00 2001 From: Joe Timmins Date: Thu, 24 Sep 2020 19:38:30 +0100 Subject: [PATCH 06/16] Use mutable list instead of array list --- .../main/java/com/teresaholfeld/stories/StoriesProgressView.kt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/library/src/main/java/com/teresaholfeld/stories/StoriesProgressView.kt b/library/src/main/java/com/teresaholfeld/stories/StoriesProgressView.kt index cb11f3e..b3637da 100644 --- a/library/src/main/java/com/teresaholfeld/stories/StoriesProgressView.kt +++ b/library/src/main/java/com/teresaholfeld/stories/StoriesProgressView.kt @@ -9,7 +9,6 @@ import android.util.AttributeSet import android.view.View import android.widget.LinearLayout import androidx.core.content.ContextCompat -import java.util.ArrayList class StoriesProgressView : LinearLayout { @@ -27,7 +26,7 @@ class StoriesProgressView : LinearLayout { private var progressColor = defaultColor private var progressBackgroundColor = defaultBackgroundColor - private val progressBars = ArrayList() + private val progressBars = mutableListOf() private var storiesCount = -1 From 0ba1b74bcfcfc3b30f64bef8ee9a06d335b66002 Mon Sep 17 00:00:00 2001 From: Joe Timmins Date: Thu, 24 Sep 2020 19:42:09 +0100 Subject: [PATCH 07/16] Use nicer values in the sample app --- app/src/main/res/layout/activity_main.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index d1cd5f2..f5f9ee2 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -34,12 +34,12 @@ + app:progressGap="4dp" /> \ No newline at end of file From 84067b5fe478280d0af776f341bd089ce8dba402 Mon Sep 17 00:00:00 2001 From: Joe Timmins Date: Thu, 24 Sep 2020 20:01:59 +0100 Subject: [PATCH 08/16] Remove unnecessary inner modifier --- .../main/java/com/teresaholfeld/stories/PausableProgressBar.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/src/main/java/com/teresaholfeld/stories/PausableProgressBar.kt b/library/src/main/java/com/teresaholfeld/stories/PausableProgressBar.kt index 2b40955..eb5778c 100644 --- a/library/src/main/java/com/teresaholfeld/stories/PausableProgressBar.kt +++ b/library/src/main/java/com/teresaholfeld/stories/PausableProgressBar.kt @@ -115,7 +115,7 @@ internal class PausableProgressBar constructor(context: Context, animation = null } - private inner class PausableScaleAnimation(fromX: Float, + private class PausableScaleAnimation(fromX: Float, toX: Float, fromY: Float, toY: Float, From 7cd17f5793ebb96c0c70e9ef7f42223e3b405cfb Mon Sep 17 00:00:00 2001 From: Joe Timmins Date: Thu, 24 Sep 2020 22:02:36 +0100 Subject: [PATCH 09/16] Add material components, use it to add corner radius --- app/src/main/res/layout/activity_main.xml | 3 +- library/build.gradle | 1 + .../stories/PausableProgressBar.kt | 45 ++++++++++++------- .../stories/StoriesProgressView.kt | 12 +++-- library/src/main/res/values/attrs.xml | 1 + 5 files changed, 40 insertions(+), 22 deletions(-) diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index f5f9ee2..393cd6a 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -34,12 +34,13 @@ \ No newline at end of file diff --git a/library/build.gradle b/library/build.gradle index 1dc0656..381af1d 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -26,6 +26,7 @@ android { dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version" implementation 'androidx.appcompat:appcompat:1.2.0' + implementation 'com.google.android.material:material:1.2.1' testImplementation 'junit:junit:4.13' androidTestImplementation('androidx.test.espresso:espresso-core:3.3.0', { exclude group: 'com.android.support', module: 'support-annotations' diff --git a/library/src/main/java/com/teresaholfeld/stories/PausableProgressBar.kt b/library/src/main/java/com/teresaholfeld/stories/PausableProgressBar.kt index eb5778c..71b6735 100644 --- a/library/src/main/java/com/teresaholfeld/stories/PausableProgressBar.kt +++ b/library/src/main/java/com/teresaholfeld/stories/PausableProgressBar.kt @@ -10,13 +10,25 @@ import android.view.animation.LinearInterpolator import android.view.animation.ScaleAnimation import android.view.animation.Transformation import android.widget.FrameLayout +import androidx.core.view.ViewCompat +import com.google.android.material.shape.CornerFamily +import com.google.android.material.shape.MaterialShapeDrawable +import com.google.android.material.shape.ShapeAppearanceModel @SuppressLint("ViewConstructor") -internal class PausableProgressBar constructor(context: Context, - attrs: AttributeSet? = null, - progressColor: Int, - progressBackgroundColor: Int) - : FrameLayout(context, attrs) { +internal class PausableProgressBar( + context: Context, + attrs: AttributeSet? = null, + progressColor: Int, + progressBackgroundColor: Int, + cornerRadius: Int +) : FrameLayout(context, attrs) { + constructor( + context: Context, + progressColor: Int, + progressBackgroundColor: Int, + cornerRadius: Int + ) : this(context, null, progressColor, progressBackgroundColor, cornerRadius) private val frontProgressView: View? private val backProgressView: View? @@ -30,17 +42,16 @@ internal class PausableProgressBar constructor(context: Context, fun onFinishProgress() } - constructor(context: Context, - progressColor: Int, - progressBackgroundColor: Int) - : this(context, null, progressColor, progressBackgroundColor) - init { LayoutInflater.from(context).inflate(R.layout.pausable_progress, this) frontProgressView = findViewById(R.id.front_progress) backProgressView = findViewById(R.id.back_progress) backProgressView?.setBackgroundColor(progressBackgroundColor) frontProgressView?.setBackgroundColor(progressColor) + val allCorners = ShapeAppearanceModel().toBuilder().setAllCorners(CornerFamily.ROUNDED, cornerRadius.toFloat()).build() + val materialShapeDrawable = MaterialShapeDrawable(allCorners) + ViewCompat.setBackground(frontProgressView, materialShapeDrawable) + ViewCompat.setBackground(backProgressView, materialShapeDrawable) } fun setDuration(duration: Long) { @@ -116,13 +127,13 @@ internal class PausableProgressBar constructor(context: Context, } private class PausableScaleAnimation(fromX: Float, - toX: Float, - fromY: Float, - toY: Float, - pivotXType: Int, - pivotXValue: Float, - pivotYType: Int, - pivotYValue: Float) + toX: Float, + fromY: Float, + toY: Float, + pivotXType: Int, + pivotXValue: Float, + pivotYType: Int, + pivotYValue: Float) : ScaleAnimation(fromX, toX, fromY, toY, pivotXType, pivotXValue, pivotYType, pivotYValue) { private var mElapsedAtPause: Long = 0 diff --git a/library/src/main/java/com/teresaholfeld/stories/StoriesProgressView.kt b/library/src/main/java/com/teresaholfeld/stories/StoriesProgressView.kt index b3637da..897e657 100644 --- a/library/src/main/java/com/teresaholfeld/stories/StoriesProgressView.kt +++ b/library/src/main/java/com/teresaholfeld/stories/StoriesProgressView.kt @@ -14,12 +14,15 @@ class StoriesProgressView : LinearLayout { private val progressBarLayoutParams = LayoutParams(0, LayoutParams.MATCH_PARENT, 1f) - private var progressGapInPixels: Int? = null private val defaultGap = 5 + private var progressGapInPixels = defaultGap private val gapLayoutParams by lazy { - LayoutParams(progressGapInPixels ?: defaultGap, LayoutParams.MATCH_PARENT) + } + private val defaultCornerRadius = 0 + private var progressCornerRadius = defaultCornerRadius + private val defaultColor = ContextCompat.getColor(context, R.color.progress_primary) private val defaultBackgroundColor = ContextCompat.getColor(context, R.color.progress_secondary) @@ -70,6 +73,7 @@ class StoriesProgressView : LinearLayout { progressColor = typedArray.getColor(R.styleable.StoriesProgressView_progressColor, defaultColor) progressBackgroundColor = typedArray.getColor(R.styleable.StoriesProgressView_progressBackgroundColor, defaultBackgroundColor) progressGapInPixels = typedArray.getDimensionPixelSize(R.styleable.StoriesProgressView_progressGap, 0) + progressCornerRadius = typedArray.getDimensionPixelSize(R.styleable.StoriesProgressView_cornerRadius, 0) typedArray.recycle() bindViews() } @@ -89,14 +93,14 @@ class StoriesProgressView : LinearLayout { } private fun createProgressBar(): PausableProgressBar { - val p = PausableProgressBar(context, progressColor, progressBackgroundColor) + val p = PausableProgressBar(context, progressColor, progressBackgroundColor, progressCornerRadius) p.layoutParams = progressBarLayoutParams return p } private fun createSpace(): View { val v = View(context) - v.layoutParams = gapLayoutParams + v.layoutParams = LayoutParams(progressGapInPixels, LayoutParams.MATCH_PARENT) return v } diff --git a/library/src/main/res/values/attrs.xml b/library/src/main/res/values/attrs.xml index 16fbddf..50537c0 100644 --- a/library/src/main/res/values/attrs.xml +++ b/library/src/main/res/values/attrs.xml @@ -5,5 +5,6 @@ + \ No newline at end of file From 1cd8700bde8a0970d0f889ccc9caaa33623fcdf4 Mon Sep 17 00:00:00 2001 From: Joe Timmins Date: Thu, 24 Sep 2020 22:15:26 +0100 Subject: [PATCH 10/16] Use material shape drawable to apply rounded corners and colours --- .../stories/PausableProgressBar.kt | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/library/src/main/java/com/teresaholfeld/stories/PausableProgressBar.kt b/library/src/main/java/com/teresaholfeld/stories/PausableProgressBar.kt index 71b6735..ca8ec20 100644 --- a/library/src/main/java/com/teresaholfeld/stories/PausableProgressBar.kt +++ b/library/src/main/java/com/teresaholfeld/stories/PausableProgressBar.kt @@ -2,6 +2,7 @@ package com.teresaholfeld.stories import android.annotation.SuppressLint import android.content.Context +import android.content.res.ColorStateList import android.util.AttributeSet import android.view.LayoutInflater import android.view.View @@ -10,6 +11,7 @@ import android.view.animation.LinearInterpolator import android.view.animation.ScaleAnimation import android.view.animation.Transformation import android.widget.FrameLayout +import androidx.core.content.ContextCompat import androidx.core.view.ViewCompat import com.google.android.material.shape.CornerFamily import com.google.android.material.shape.MaterialShapeDrawable @@ -46,12 +48,17 @@ internal class PausableProgressBar( LayoutInflater.from(context).inflate(R.layout.pausable_progress, this) frontProgressView = findViewById(R.id.front_progress) backProgressView = findViewById(R.id.back_progress) - backProgressView?.setBackgroundColor(progressBackgroundColor) - frontProgressView?.setBackgroundColor(progressColor) - val allCorners = ShapeAppearanceModel().toBuilder().setAllCorners(CornerFamily.ROUNDED, cornerRadius.toFloat()).build() + ViewCompat.setBackground(frontProgressView, createBackgroundDrawable(progressColor, cornerRadius)) + ViewCompat.setBackground(backProgressView, createBackgroundDrawable(progressBackgroundColor, cornerRadius)) + } + + private fun createBackgroundDrawable(color: Int, cornerRadius: Int): MaterialShapeDrawable { + val allCorners = ShapeAppearanceModel().toBuilder() + .setAllCorners(CornerFamily.ROUNDED, cornerRadius.toFloat()) + .build() val materialShapeDrawable = MaterialShapeDrawable(allCorners) - ViewCompat.setBackground(frontProgressView, materialShapeDrawable) - ViewCompat.setBackground(backProgressView, materialShapeDrawable) + materialShapeDrawable.fillColor = ColorStateList.valueOf(color) + return materialShapeDrawable } fun setDuration(duration: Long) { From 51e0dc87c6c6de8e6f6834617fd0ec93e9b97eed Mon Sep 17 00:00:00 2001 From: Joe Timmins Date: Thu, 24 Sep 2020 22:17:09 +0100 Subject: [PATCH 11/16] Reduce height of progress bar in sample app --- app/src/main/res/layout/activity_main.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 393cd6a..c7d6502 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -34,7 +34,7 @@ Date: Thu, 24 Sep 2020 22:38:15 +0100 Subject: [PATCH 12/16] Remove import, remove unused delegate --- .../main/java/com/teresaholfeld/stories/PausableProgressBar.kt | 1 - .../main/java/com/teresaholfeld/stories/StoriesProgressView.kt | 3 --- 2 files changed, 4 deletions(-) diff --git a/library/src/main/java/com/teresaholfeld/stories/PausableProgressBar.kt b/library/src/main/java/com/teresaholfeld/stories/PausableProgressBar.kt index ca8ec20..cd6acea 100644 --- a/library/src/main/java/com/teresaholfeld/stories/PausableProgressBar.kt +++ b/library/src/main/java/com/teresaholfeld/stories/PausableProgressBar.kt @@ -11,7 +11,6 @@ import android.view.animation.LinearInterpolator import android.view.animation.ScaleAnimation import android.view.animation.Transformation import android.widget.FrameLayout -import androidx.core.content.ContextCompat import androidx.core.view.ViewCompat import com.google.android.material.shape.CornerFamily import com.google.android.material.shape.MaterialShapeDrawable diff --git a/library/src/main/java/com/teresaholfeld/stories/StoriesProgressView.kt b/library/src/main/java/com/teresaholfeld/stories/StoriesProgressView.kt index 897e657..f3836eb 100644 --- a/library/src/main/java/com/teresaholfeld/stories/StoriesProgressView.kt +++ b/library/src/main/java/com/teresaholfeld/stories/StoriesProgressView.kt @@ -16,9 +16,6 @@ class StoriesProgressView : LinearLayout { private val defaultGap = 5 private var progressGapInPixels = defaultGap - private val gapLayoutParams by lazy { - - } private val defaultCornerRadius = 0 private var progressCornerRadius = defaultCornerRadius From b25a67b4ae5645fba96ac844dcc4d09d4f571902 Mon Sep 17 00:00:00 2001 From: Joe Timmins Date: Thu, 24 Sep 2020 22:49:10 +0100 Subject: [PATCH 13/16] Use more sensible defaults --- .../java/com/teresaholfeld/stories/StoriesProgressView.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/src/main/java/com/teresaholfeld/stories/StoriesProgressView.kt b/library/src/main/java/com/teresaholfeld/stories/StoriesProgressView.kt index f3836eb..2d20b38 100644 --- a/library/src/main/java/com/teresaholfeld/stories/StoriesProgressView.kt +++ b/library/src/main/java/com/teresaholfeld/stories/StoriesProgressView.kt @@ -69,8 +69,8 @@ class StoriesProgressView : LinearLayout { storiesCount = typedArray.getInt(R.styleable.StoriesProgressView_progressCount, 0) progressColor = typedArray.getColor(R.styleable.StoriesProgressView_progressColor, defaultColor) progressBackgroundColor = typedArray.getColor(R.styleable.StoriesProgressView_progressBackgroundColor, defaultBackgroundColor) - progressGapInPixels = typedArray.getDimensionPixelSize(R.styleable.StoriesProgressView_progressGap, 0) - progressCornerRadius = typedArray.getDimensionPixelSize(R.styleable.StoriesProgressView_cornerRadius, 0) + progressGapInPixels = typedArray.getDimensionPixelSize(R.styleable.StoriesProgressView_progressGap, defaultGap) + progressCornerRadius = typedArray.getDimensionPixelSize(R.styleable.StoriesProgressView_cornerRadius, defaultCornerRadius) typedArray.recycle() bindViews() } From c128f98015d2a42e72a7f70ce90bca55a157b319 Mon Sep 17 00:00:00 2001 From: Joe Timmins Date: Wed, 26 May 2021 19:54:08 +0100 Subject: [PATCH 14/16] Bump some dependencies --- build.gradle | 4 ++-- gradle/wrapper/gradle-wrapper.properties | 2 +- library/build.gradle | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/build.gradle b/build.gradle index 6909257..a1f6ea9 100644 --- a/build.gradle +++ b/build.gradle @@ -1,14 +1,14 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { - ext.kotlin_version = '1.4.10' + ext.kotlin_version = '1.5.10' repositories { google() jcenter() mavenCentral() } dependencies { - classpath 'com.android.tools.build:gradle:4.0.1' + classpath 'com.android.tools.build:gradle:4.2.1' classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" // NOTE: Do not place your application dependencies here; they belong diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index d576996..f03a026 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.6-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-all.zip diff --git a/library/build.gradle b/library/build.gradle index 381af1d..2f597b3 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -25,9 +25,9 @@ android { dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version" - implementation 'androidx.appcompat:appcompat:1.2.0' - implementation 'com.google.android.material:material:1.2.1' - testImplementation 'junit:junit:4.13' + implementation 'androidx.appcompat:appcompat:1.3.0' + implementation 'com.google.android.material:material:1.3.0' + testImplementation 'junit:junit:4.13.2' androidTestImplementation('androidx.test.espresso:espresso-core:3.3.0', { exclude group: 'com.android.support', module: 'support-annotations' }) From 4615213dd3812655a1cc3886ecbf7b1af4d207bc Mon Sep 17 00:00:00 2001 From: Joe Timmins Date: Wed, 14 Sep 2022 13:51:54 +0100 Subject: [PATCH 15/16] Update readme --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 839e5dc..c686afe 100644 --- a/README.md +++ b/README.md @@ -135,7 +135,8 @@ To do this, you can add the attributes to your layout xml: ``` - +## Compose support +None planned. ## License From 577d58fc8a3cb4c72941eea136d9396cc2bd7f6e Mon Sep 17 00:00:00 2001 From: Joe Timmins Date: Wed, 14 Sep 2022 14:03:29 +0100 Subject: [PATCH 16/16] Update readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c686afe..657b59e 100644 --- a/README.md +++ b/README.md @@ -136,7 +136,7 @@ To do this, you can add the attributes to your layout xml: ``` ## Compose support -None planned. +None planned. PRs welcome! ## License