Skip to content

Commit

Permalink
Merge pull request #12 from farukguler/feature/image-slider
Browse files Browse the repository at this point in the history
Add indicator visibility choice.
  • Loading branch information
bilgehankalkan authored Dec 13, 2019
2 parents 34bd97b + 686ebb5 commit c275c0f
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package com.trendyol.uicomponents.imageslider

import android.annotation.TargetApi
import android.app.Activity
import android.content.Context
import android.os.Build
import android.util.AttributeSet
import android.widget.FrameLayout
import androidx.appcompat.app.AppCompatActivity
Expand Down Expand Up @@ -46,8 +44,12 @@ class ImageSliderView : FrameLayout, ImagesPagerAdapter.SliderAdapterItemClickLi
}

fun setViewState(imageSliderViewState: ImageSliderViewState?) {
if (imageSliderViewState == null) return
setImages(imageSliderViewState)
imageSliderViewState?.let {
binding.viewState = it
binding.executePendingBindings()

setImages(imageSliderViewState)
}
}

private fun setImages(imageSliderViewState: ImageSliderViewState?) {
Expand All @@ -63,6 +65,8 @@ class ImageSliderView : FrameLayout, ImagesPagerAdapter.SliderAdapterItemClickLi
}
}



override fun onImageItemClicked(imageUrlList: List<String>, position: Int) {
imageSliderViewListener?.onImageSliderItemClicked(imageUrlList, position)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,29 @@
package com.trendyol.uicomponents.imageslider

import android.view.View

data class ImageSliderViewState(
val imageList: List<String>,
var isImageDynamic: Boolean? = null,
var imageHeight: Int? = null
var imageHeight: Int? = null,
var isIndicatorAlwaysVisible: Boolean = false
) {

fun isSingleImage() = imageList.size == 1

fun isSingleImageVisible() = isSingleImage()

private fun isMultiImage() = imageList.size.greaterThan(1)
fun isMultiImage() = imageList.size.greaterThan(1)

fun getIndicatorVisibility(): Int {
return if (isIndicatorAlwaysVisible) {
View.VISIBLE
} else {
if (isMultiImage()) {
View.VISIBLE
} else {
View.GONE
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:app="http://schemas.android.com/apk/res-auto">

<data>

<variable
name="viewState"
type="com.trendyol.uicomponents.imageslider.ImageSliderViewState" />

</data>

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
Expand All @@ -21,6 +29,7 @@
android:paddingTop="@dimen/indicator_padding_vertical"
android:paddingRight="@dimen/indicator_padding_horizontal"
android:paddingBottom="@dimen/indicator_padding_vertical"
android:visibility="@{viewState.indicatorVisibility}"
app:ci_animator="@animator/animator_alpha"
app:ci_animator_reverse="@animator/animator_alpha"
app:ci_drawable="@drawable/shape_indicator_selected"
Expand Down

0 comments on commit c275c0f

Please sign in to comment.