Skip to content

Commit

Permalink
Merge pull request #73 from ImaginativeShohag/dev
Browse files Browse the repository at this point in the history
Version 2.0.6 released
  • Loading branch information
ImaginativeShohag authored Jan 10, 2022
2 parents 7566ed2 + 9c86d79 commit 45427d7
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 43 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
Change Log
==========

## Version 2.0.5 *(2021-09-30)* 🚀
## Version 2.0.6 *(2022-01-11)* 🚀

* 🐞 Fixed [#72](https://github.com/ImaginativeShohag/Why-Not-Image-Carousel/issues/72): Indicator
will now indicate first item after data replace.
* ⬆ Updated deprecated lifecycle code.
* ⬆ Kotlin and other libs upgraded to the latest version.

## Version 2.0.5 *(2021-09-30)*

* 🐞 Fixed [#50](https://github.com/ImaginativeShohag/Why-Not-Image-Carousel/issues/50): Fixed a
crash when dataset changed.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ dependencies {
// Circle Indicator (To fix the xml preview "Missing classes" error)
implementation 'me.relex:circleindicator:2.1.6'
implementation 'org.imaginativeworld.whynotimagecarousel:whynotimagecarousel:2.0.5'
implementation 'org.imaginativeworld.whynotimagecarousel:whynotimagecarousel:2.0.6'
}
```

Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
ext.kotlin_version = '1.5.31'
ext.kotlin_version = '1.6.10'
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.0.2'
classpath 'com.android.tools.build:gradle:7.0.4'
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
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ kotlin.code.style=official
# ----------------
GROUP=org.imaginativeworld.whynotimagecarousel
POM_ARTIFACT_ID=whynotimagecarousel
VERSION_NAME=2.0.5
VERSION_NAME=2.0.6
# ----------------
POM_NAME=Why Not! Image Carousel!
POM_DESCRIPTION=An easy, super simple and customizable image carousel view for Android.
Expand Down
8 changes: 4 additions & 4 deletions sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ dependencies {
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'

implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'androidx.core:core-ktx:1.6.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.1'
implementation 'androidx.appcompat:appcompat:1.4.0'
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.2'

// Why Not! Image Carousel! Library
implementation project(':whynotimagecarousel')
Expand All @@ -66,7 +66,7 @@ dependencies {
kapt 'com.github.bumptech.glide:compiler:4.12.0'

// Fragment
implementation "androidx.fragment:fragment-ktx:1.3.6"
implementation "androidx.fragment:fragment-ktx:1.4.0"

// debugImplementation because LeakCanary should only run in debug builds.
debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.7'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class TestActivity : AppCompatActivity() {
)
}

binding.carousel2.setData(listOne)
binding.carousel2.setData(listTwo)

// --------------------------------

Expand All @@ -69,15 +69,15 @@ class TestActivity : AppCompatActivity() {
}

binding.btnMultiAppend.setOnClickListener {
binding.carousel1.addData(listOne)
binding.carousel2.addData(listOne)
binding.carousel1.addData(listOne.take(3))
binding.carousel2.addData(listTwo.take(3))
}

// --------------------------------

binding.btnLoadData.setOnClickListener {
binding.carousel1.setData(listOne)
binding.carousel2.setData(listOne)
binding.carousel2.setData(listTwo)
}

binding.btnClearData.setOnClickListener {
Expand Down
6 changes: 3 additions & 3 deletions whynotimagecarousel/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])

implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'androidx.core:core-ktx:1.6.0'
implementation 'androidx.appcompat:appcompat:1.4.0'
implementation 'androidx.core:core-ktx:1.7.0'

implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.2'
implementation 'androidx.recyclerview:recyclerview:1.2.1'

// Glide
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,14 @@ import androidx.annotation.IdRes
import androidx.annotation.LayoutRes
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.core.content.ContextCompat
import androidx.lifecycle.DefaultLifecycleObserver
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleObserver
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.OnLifecycleEvent
import androidx.recyclerview.widget.*
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.LinearSnapHelper
import androidx.recyclerview.widget.PagerSnapHelper
import androidx.recyclerview.widget.RecyclerView
import androidx.recyclerview.widget.SnapHelper
import me.relex.circleindicator.CircleIndicator2
import org.imaginativeworld.whynotimagecarousel.adapter.FiniteCarouselAdapter
import org.imaginativeworld.whynotimagecarousel.adapter.InfiniteCarouselAdapter
Expand All @@ -33,14 +36,18 @@ import org.imaginativeworld.whynotimagecarousel.listener.CarouselOnScrollListene
import org.imaginativeworld.whynotimagecarousel.model.CarouselGravity
import org.imaginativeworld.whynotimagecarousel.model.CarouselItem
import org.imaginativeworld.whynotimagecarousel.model.CarouselType
import org.imaginativeworld.whynotimagecarousel.utils.*
import org.imaginativeworld.whynotimagecarousel.utils.CarouselLinearLayoutManager
import org.imaginativeworld.whynotimagecarousel.utils.LinearStartSnapHelper
import org.imaginativeworld.whynotimagecarousel.utils.dpToPx
import org.imaginativeworld.whynotimagecarousel.utils.getSnapPosition
import org.imaginativeworld.whynotimagecarousel.utils.spToPx
import org.jetbrains.annotations.NotNull
import org.jetbrains.annotations.Nullable

class ImageCarousel(
@NotNull context: Context,
@Nullable private var attributeSet: AttributeSet?
) : ConstraintLayout(context, attributeSet), LifecycleObserver {
) : ConstraintLayout(context, attributeSet), DefaultLifecycleObserver {

companion object {
const val TAG = "ImageCarousel"
Expand Down Expand Up @@ -533,27 +540,18 @@ class ImageCarousel(
return super.dispatchTouchEvent(event)
}

@OnLifecycleEvent(Lifecycle.Event.ON_PAUSE)
private fun pauseAutoPlay() {
if (autoPlay) {
autoPlayHandler.removeCallbacksAndMessages(null)
}
}

@OnLifecycleEvent(Lifecycle.Event.ON_RESUME)
private fun resumeAutoPlay() {
if (autoPlay) {
initAutoPlay()
}
}

@OnLifecycleEvent(Lifecycle.Event.ON_RESUME)
private fun onResumeCheckForStartPositionForInfiniteCarousel() {
if (infiniteCarousel && !isCarouselCentered && dataSize != 0) {
initStartPositionForInfiniteCarousel()
}
}

private fun initViews() {
carouselView = LayoutInflater.from(context).inflate(R.layout.image_carousel, this)

Expand Down Expand Up @@ -632,17 +630,17 @@ class ImageCarousel(
).toInt()

carouselType = carouselTypeArray[
getInteger(
R.styleable.ImageCarousel_carouselType,
CarouselType.BLOCK.ordinal
)
getInteger(
R.styleable.ImageCarousel_carouselType,
CarouselType.BLOCK.ordinal
)
]

carouselGravity = carouselGravityArray[
getInteger(
R.styleable.ImageCarousel_carouselGravity,
CarouselGravity.CENTER.ordinal
)
getInteger(
R.styleable.ImageCarousel_carouselGravity,
CarouselGravity.CENTER.ordinal
)
]

showIndicator = getBoolean(
Expand All @@ -656,10 +654,10 @@ class ImageCarousel(
).toInt()

imageScaleType = scaleTypeArray[
getInteger(
R.styleable.ImageCarousel_imageScaleType,
ImageView.ScaleType.CENTER_CROP.ordinal
)
getInteger(
R.styleable.ImageCarousel_imageScaleType,
ImageView.ScaleType.CENTER_CROP.ordinal
)
]

carouselBackground = getDrawable(
Expand Down Expand Up @@ -976,7 +974,7 @@ class ImageCarousel(

private fun createIndicator() {
indicator?.apply {
createIndicators(dataSize, currentVirtualPosition)
createIndicators(dataSize, 0)
}
}

Expand Down Expand Up @@ -1213,4 +1211,21 @@ class ImageCarousel(
fun stop() {
autoPlay = false
}

// ----------------------------------------------------------------
// Lifecycle events
// ----------------------------------------------------------------

override fun onPause(owner: LifecycleOwner) {
pauseAutoPlay()
}

override fun onResume(owner: LifecycleOwner) {
resumeAutoPlay()

// Check for start position for InfiniteCarousel
if (infiniteCarousel && !isCarouselCentered && dataSize != 0) {
initStartPositionForInfiniteCarousel()
}
}
}

0 comments on commit 45427d7

Please sign in to comment.