From f5898332b3adb5ca97cea775e5d7f98968dda88d Mon Sep 17 00:00:00 2001 From: Suneet Agrawal Date: Sun, 9 Jun 2019 15:41:43 +0530 Subject: [PATCH 1/2] fixed crash for typecast --- .../com/agrawalsuneet/loaders/MainActivity.kt | 2 +- dotsloader/build.gradle | 6 +++--- .../dotsloader/loaders/LinearDotsLoader.kt | 3 ++- .../agrawalsuneet/dotsloader/utils/Utils.kt | 20 +++++++++++++++++++ 4 files changed, 26 insertions(+), 5 deletions(-) create mode 100644 dotsloader/src/main/java/com/agrawalsuneet/dotsloader/utils/Utils.kt diff --git a/app/src/main/java/com/agrawalsuneet/loaders/MainActivity.kt b/app/src/main/java/com/agrawalsuneet/loaders/MainActivity.kt index a13a856..db9c2e4 100644 --- a/app/src/main/java/com/agrawalsuneet/loaders/MainActivity.kt +++ b/app/src/main/java/com/agrawalsuneet/loaders/MainActivity.kt @@ -14,7 +14,7 @@ class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - setContentView(R.layout.main_bounce) + setContentView(R.layout.main_lineardotsloader) supportActionBar?.title = "BounceLoader" diff --git a/dotsloader/build.gradle b/dotsloader/build.gradle index aa33491..0c9b8b0 100644 --- a/dotsloader/build.gradle +++ b/dotsloader/build.gradle @@ -16,7 +16,7 @@ buildscript { ext { PUBLISH_GROUP_ID = 'com.agrawalsuneet.androidlibs' PUBLISH_ARTIFACT_ID = 'dotsloader' - PUBLISH_VERSION = '1.4' + PUBLISH_VERSION = '1.4.1' } configurations { @@ -29,8 +29,8 @@ android { defaultConfig { minSdkVersion 16 targetSdkVersion 28 - versionCode 14 - versionName "1.4" + versionCode 15 + versionName "1.4.1" } buildTypes { release { diff --git a/dotsloader/src/main/java/com/agrawalsuneet/dotsloader/loaders/LinearDotsLoader.kt b/dotsloader/src/main/java/com/agrawalsuneet/dotsloader/loaders/LinearDotsLoader.kt index bef4cc6..7e94875 100644 --- a/dotsloader/src/main/java/com/agrawalsuneet/dotsloader/loaders/LinearDotsLoader.kt +++ b/dotsloader/src/main/java/com/agrawalsuneet/dotsloader/loaders/LinearDotsLoader.kt @@ -7,6 +7,7 @@ import android.util.AttributeSet import android.view.View import com.agrawalsuneet.dotsloader.R import com.agrawalsuneet.dotsloader.contracts.DotsLoaderBaseView +import com.agrawalsuneet.dotsloader.utils.Utils import java.util.* /** @@ -119,7 +120,7 @@ class LinearDotsLoader : DotsLoaderBaseView { } } - (context as Activity).runOnUiThread { invalidate() } + (Utils.scanForActivity(context))?.runOnUiThread { invalidate() } } }, 0, animDur.toLong()) } diff --git a/dotsloader/src/main/java/com/agrawalsuneet/dotsloader/utils/Utils.kt b/dotsloader/src/main/java/com/agrawalsuneet/dotsloader/utils/Utils.kt new file mode 100644 index 0000000..1934185 --- /dev/null +++ b/dotsloader/src/main/java/com/agrawalsuneet/dotsloader/utils/Utils.kt @@ -0,0 +1,20 @@ +package com.agrawalsuneet.dotsloader.utils + +import android.content.ContextWrapper +import android.app.Activity +import android.content.Context + + +object Utils { + + fun scanForActivity(context: Context?): Activity? { + return when (context) { + null -> null + is Activity -> context + is ContextWrapper -> scanForActivity(context.baseContext) + else -> null + } + + } + +} \ No newline at end of file From 2930a772a577fc58bcfe6968e709990f0ad29826 Mon Sep 17 00:00:00 2001 From: Suneet Agrawal Date: Sun, 9 Jun 2019 15:43:16 +0530 Subject: [PATCH 2/2] added fix for crash --- .../com/agrawalsuneet/dotsloader/loaders/CircularDotsLoader.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dotsloader/src/main/java/com/agrawalsuneet/dotsloader/loaders/CircularDotsLoader.kt b/dotsloader/src/main/java/com/agrawalsuneet/dotsloader/loaders/CircularDotsLoader.kt index 2b04c49..cf48d03 100644 --- a/dotsloader/src/main/java/com/agrawalsuneet/dotsloader/loaders/CircularDotsLoader.kt +++ b/dotsloader/src/main/java/com/agrawalsuneet/dotsloader/loaders/CircularDotsLoader.kt @@ -7,6 +7,7 @@ import android.util.AttributeSet import android.view.View import com.agrawalsuneet.dotsloader.R import com.agrawalsuneet.dotsloader.contracts.CircularAbstractView +import com.agrawalsuneet.dotsloader.utils.Utils import java.util.* /** @@ -68,7 +69,7 @@ class CircularDotsLoader : CircularAbstractView { selectedDotPos = 1 } - (context as Activity).runOnUiThread { invalidate() } + (Utils.scanForActivity(context))?.runOnUiThread { invalidate() } } }, 0, animDur.toLong()) }