Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.6.10'
ext.kotlin_version = '1.6.21'
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.1.2'
classpath 'com.android.tools.build:gradle:7.1.3'
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: 2 additions & 0 deletions jitpack.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
jdk:
- openjdk11
Original file line number Diff line number Diff line change
Expand Up @@ -364,11 +364,12 @@ class KotlinActivity : AppCompatActivity() {

val listFive = mutableListOf<CarouselItem>()


for (item in DataSet.five) {
listFive.add(
CarouselItem(
imageDrawable = item.first,
caption = item.second
item.first,
item.second
)
)
}
Expand Down Expand Up @@ -423,7 +424,7 @@ class KotlinActivity : AppCompatActivity() {
val listSix = mutableListOf<CarouselItem>()

for (item in DataSet.six) {
listSix.add(CarouselItem())
listSix.add(CarouselItem(item.second))
}

binding.carousel6.setData(listSix)
Expand Down
1 change: 1 addition & 0 deletions sample/src/main/res/layout/fragment_sample.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#eee"
android:id="@+id/main"
tools:context=".SampleFragment">

<TextView
Expand Down
30 changes: 20 additions & 10 deletions whynotimagecarousel/build.gradle
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
buildscript {
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.vanniktech:gradle-maven-publish-plugin:0.19.0'
classpath 'org.jetbrains.dokka:dokka-gradle-plugin:1.6.10'
}
}

apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
apply plugin: "com.vanniktech.maven.publish"
apply plugin: "org.jetbrains.dokka"
plugins {
id 'com.android.library'
id 'kotlin-android'
id 'kotlin-kapt'
id "org.jetbrains.dokka" version "1.6.21"
id 'maven-publish'
}

android {
compileSdkVersion 31
Expand Down Expand Up @@ -62,3 +60,15 @@ dependencies {
// Circle Indicator
implementation 'me.relex:circleindicator:2.1.6'
}

afterEvaluate {
publishing {
publications {
release(MavenPublication) {
from components.release
groupId = 'com.github.simoneraffaelli'
artifactId = 'Why-Not-Image-Carousel'
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,16 @@ import androidx.core.content.ContextCompat
import androidx.lifecycle.DefaultLifecycleObserver
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleOwner
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 androidx.recyclerview.widget.*
import me.relex.circleindicator.CircleIndicator2
import org.imaginativeworld.whynotimagecarousel.adapter.FiniteCarouselAdapter
import org.imaginativeworld.whynotimagecarousel.adapter.InfiniteCarouselAdapter
import org.imaginativeworld.whynotimagecarousel.listener.CarouselListener
import org.imaginativeworld.whynotimagecarousel.listener.CarouselOnScrollListener
import org.imaginativeworld.whynotimagecarousel.model.CarouselGravity
import org.imaginativeworld.whynotimagecarousel.model.CarouselItem
import org.imaginativeworld.whynotimagecarousel.model.CarouselType
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.imaginativeworld.whynotimagecarousel.model.CarouselItem
import org.imaginativeworld.whynotimagecarousel.utils.*
import org.jetbrains.annotations.NotNull
import org.jetbrains.annotations.Nullable

Expand Down Expand Up @@ -635,17 +627,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 @@ -659,10 +651,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
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import androidx.viewbinding.ViewBinding
import org.imaginativeworld.whynotimagecarousel.databinding.ItemCarouselBinding
import org.imaginativeworld.whynotimagecarousel.listener.CarouselListener
import org.imaginativeworld.whynotimagecarousel.model.CarouselGravity
import org.imaginativeworld.whynotimagecarousel.model.CarouselItem
import org.imaginativeworld.whynotimagecarousel.model.CarouselType
import org.imaginativeworld.whynotimagecarousel.model.CarouselItem
import org.imaginativeworld.whynotimagecarousel.utils.CarouselItemDecoration
import org.imaginativeworld.whynotimagecarousel.utils.setImage

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import android.widget.ImageView
import androidx.recyclerview.widget.RecyclerView
import org.imaginativeworld.whynotimagecarousel.ImageCarousel
import org.imaginativeworld.whynotimagecarousel.model.CarouselGravity
import org.imaginativeworld.whynotimagecarousel.model.CarouselItem
import org.imaginativeworld.whynotimagecarousel.model.CarouselType
import org.imaginativeworld.whynotimagecarousel.model.CarouselItem

class InfiniteCarouselAdapter(
recyclerView: RecyclerView,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,58 +1,62 @@
package org.imaginativeworld.whynotimagecarousel.model

import android.graphics.Bitmap
import android.graphics.drawable.Drawable
import androidx.annotation.DrawableRes

data class CarouselItem constructor(
val imageUrl: String? = null,
@DrawableRes val imageDrawable: Int? = null,
class CarouselItem private constructor(
internal val imageType: CarouselItemImage<*>,
val caption: String? = null,
val headers: Map<String, String>?
val headers: Map<String, String>? = null
) {
constructor() : this(null, null, null, null)
val image = imageType.image

constructor(imageUrl: String? = null) : this(
imageUrl,
null,
null,
null
)

constructor(imageUrl: String? = null, headers: Map<String, String>? = null) : this(
imageUrl,
null,
null,
headers
constructor(
drawable: Drawable,
caption: String? = null,
headers: Map<String, String>? = null
) : this(
imageType = DrawableImageType(image = drawable),
caption = caption,
headers = headers
)

constructor(@DrawableRes imageDrawable: Int? = null) : this(
null,
imageDrawable,
null,
null
constructor(
@DrawableRes drawableRes: Int,
caption: String? = null,
headers: Map<String, String>? = null
) : this(
imageType = DrawableResImageType(image = drawableRes),
caption = caption,
headers = headers
)

constructor(imageUrl: String? = null, caption: String? = null) : this(
imageUrl,
null,
caption,
null
constructor(
bitmap: Bitmap,
caption: String? = null,
headers: Map<String, String>? = null
) : this(
imageType = BitmapImageType(image = bitmap),
caption = caption,
headers = headers
)

constructor(
imageUrl: String? = null,
imageUrl: String,
caption: String? = null,
headers: Map<String, String>? = null
) : this(
imageUrl,
null,
caption,
headers
imageType = UrlImageType(image = imageUrl),
caption = caption,
headers = headers
)

constructor(@DrawableRes imageDrawable: Int? = null, caption: String? = null) : this(
null,
imageDrawable,
caption,
null
constructor(
caption: String,
headers: Map<String, String>? = null
) : this(
imageType = StringCaptionImageType(image = caption),
caption = caption,
headers = headers
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.imaginativeworld.whynotimagecarousel.model

import android.graphics.Bitmap
import android.graphics.drawable.Drawable
import androidx.annotation.DrawableRes

sealed class CarouselItemImage<T>(val image: T)

class DrawableImageType(image: Drawable): CarouselItemImage<Drawable>(image)
class DrawableResImageType(@DrawableRes image: Int): CarouselItemImage<Int>(image)
class BitmapImageType(image: Bitmap): CarouselItemImage<Bitmap>(image)
class UrlImageType(image: String): CarouselItemImage<String>(image)
class StringCaptionImageType(image: String): CarouselItemImage<String>(image)
Loading