From 404022a0aa5b7a5f59f867215a7ba7cecbc25b91 Mon Sep 17 00:00:00 2001 From: Yazan Tarifi Date: Mon, 30 Nov 2020 10:13:03 +0200 Subject: [PATCH] Fix Layout Direction to Pluto View and Min Sdk Version --- README.md | 3 +++ .../main/java/com/opensooq/pluto/PlutoView.kt | 18 ++++++++++++++++-- .../src/main/res/layout/layout_view_slider.xml | 1 - 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 69af501..0a930a9 100644 --- a/README.md +++ b/README.md @@ -365,6 +365,9 @@ Bind it with a `PlutoView` instance. pluto.setCustomIndicator(findViewById(R.id.custom_indicator)); ``` +> Minimum Supported Version is (17) +> Target Sdk Version is (28) + # License diff --git a/pluto/src/main/java/com/opensooq/pluto/PlutoView.kt b/pluto/src/main/java/com/opensooq/pluto/PlutoView.kt index f27151f..dc36aa5 100644 --- a/pluto/src/main/java/com/opensooq/pluto/PlutoView.kt +++ b/pluto/src/main/java/com/opensooq/pluto/PlutoView.kt @@ -16,6 +16,7 @@ import com.opensooq.pluto.base.PlutoAdapter import com.opensooq.pluto.listeners.OnSlideChangeListener import com.opensooq.pluto.listeners.OnSnapPositionChangeListener import com.opensooq.pluto.listeners.SnapOnScrollListener +import java.lang.IllegalArgumentException import java.lang.ref.WeakReference import java.util.* import kotlin.Experimental.Level @@ -36,6 +37,7 @@ class PlutoView @JvmOverloads constructor(context: Context, private var cycleTimer: Timer? = null private var cycleTask: TimerTask? = null private var plutoAdapter: PlutoAdapter<*, *>? = null + private var linearLayoutManager: LinearLayoutManager? = null private var resumingTimer: Timer? = null var isCycling: Boolean = false @@ -58,8 +60,8 @@ class PlutoView @JvmOverloads constructor(context: Context, private val mh = IncomingHandler(this) private fun setupAdapter() { - val linearLayoutManager = LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false) - linearLayoutManager.initialPrefetchItemCount = 4 + linearLayoutManager = LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false) + linearLayoutManager?.initialPrefetchItemCount = 4 rvSlider?.apply { layoutManager = linearLayoutManager adapter = plutoAdapter @@ -173,6 +175,17 @@ class PlutoView @JvmOverloads constructor(context: Context, } } + /** + * Change the Layout Direction + */ + fun isRtl(isRtl: Boolean) { + if (linearLayoutManager == null) { + throw IllegalArgumentException("Pluto Adapter Not Setup Yet call setupAdapter()") + } + + linearLayoutManager?.reverseLayout = isRtl + } + fun setOnSlideChangeListener(onSlideChangeListener: OnSlideChangeListener) { this.onSlideChangeListener = onSlideChangeListener @@ -373,6 +386,7 @@ class PlutoView @JvmOverloads constructor(context: Context, mh.removeCallbacksAndMessages(null) rvSlider?.adapter = null indicator?.destroySelf() + linearLayoutManager = null onScrollListener?.let { rvSlider?.removeOnScrollListener(it) } onScrollListener = null onSlideChangeListener = null diff --git a/pluto/src/main/res/layout/layout_view_slider.xml b/pluto/src/main/res/layout/layout_view_slider.xml index c630975..a3c8177 100644 --- a/pluto/src/main/res/layout/layout_view_slider.xml +++ b/pluto/src/main/res/layout/layout_view_slider.xml @@ -9,7 +9,6 @@ android:id="@+id/rvSlider" android:layout_width="match_parent" android:layout_height="wrap_content" - android:layoutDirection="ltr" custom:layout_constraintEnd_toEndOf="parent" custom:layout_constraintStart_toStartOf="parent" custom:layout_constraintTop_toTopOf="parent"/>