From 4b1bcf297ba114b4c690e6a1cb9f8f7f177e738d Mon Sep 17 00:00:00 2001
From: Marcus Terasa <m.terasa@neusta.de>
Date: Thu, 10 Mar 2016 10:54:24 +0100
Subject: [PATCH 1/2] Exposed methods to manually set the selected item

---
 .../java/com/roughike/swipeselector/SwipeAdapter.java     | 15 +++++++++++++++
 .../java/com/roughike/swipeselector/SwipeSelector.java    |  8 ++++++++
 2 files changed, 23 insertions(+)

diff --git a/swipe-selector/src/main/java/com/roughike/swipeselector/SwipeAdapter.java b/swipe-selector/src/main/java/com/roughike/swipeselector/SwipeAdapter.java
index f7a19a8..244ca98 100644
--- a/swipe-selector/src/main/java/com/roughike/swipeselector/SwipeAdapter.java
+++ b/swipe-selector/src/main/java/com/roughike/swipeselector/SwipeAdapter.java
@@ -281,6 +281,21 @@ protected SwipeItem getSelectedItem() {
         return mItems.get(mCurrentPosition);
     }
 
+    public void setSelectedItem(int position) {
+        if (position >= 0 && position < mItems.size()) {
+            mViewPager.setCurrentItem(position, true);
+        }
+    }
+
+    public void setSelectedItem(SwipeItem item) {
+        for (int i = 0; i < mItems.size(); i++) {
+            if (mItems.get(i).equals(item)) {
+                mViewPager.setCurrentItem(i, true);
+                break;
+            }
+        }
+    }
+
     protected Bundle onSaveInstanceState() {
         Bundle bundle = new Bundle();
         bundle.putInt(STATE_CURRENT_POSITION, mCurrentPosition);
diff --git a/swipe-selector/src/main/java/com/roughike/swipeselector/SwipeSelector.java b/swipe-selector/src/main/java/com/roughike/swipeselector/SwipeSelector.java
index bc43b72..18e6d1a 100644
--- a/swipe-selector/src/main/java/com/roughike/swipeselector/SwipeSelector.java
+++ b/swipe-selector/src/main/java/com/roughike/swipeselector/SwipeSelector.java
@@ -187,4 +187,12 @@ protected void dispatchSaveInstanceState(SparseArray<Parcelable> container) {
     protected void dispatchRestoreInstanceState(SparseArray<Parcelable> container) {
         dispatchThawSelfOnly(container);
     }
+
+    public void setSelectedItem(int position) {
+        mAdapter.setSelectedItem(position);
+    }
+
+    public void setSelectedItem(SwipeItem item) {
+        mAdapter.setSelectedItem(item);
+    }
 }

From d63fe054d2a6c9744e4313891afebbe5cc12e8c3 Mon Sep 17 00:00:00 2001
From: Marcus Terasa <m.terasa@neusta.de>
Date: Thu, 10 Mar 2016 10:55:11 +0100
Subject: [PATCH 2/2] Hide the description label if description is null

---
 .../main/java/com/roughike/swipeselector/SwipeAdapter.java |  7 ++++++-
 .../src/main/res/layout/swipeselector_content_item.xml     | 14 +++++++++-----
 2 files changed, 15 insertions(+), 6 deletions(-)

diff --git a/swipe-selector/src/main/java/com/roughike/swipeselector/SwipeAdapter.java b/swipe-selector/src/main/java/com/roughike/swipeselector/SwipeAdapter.java
index 244ca98..dc72015 100644
--- a/swipe-selector/src/main/java/com/roughike/swipeselector/SwipeAdapter.java
+++ b/swipe-selector/src/main/java/com/roughike/swipeselector/SwipeAdapter.java
@@ -318,7 +318,12 @@ public Object instantiateItem(ViewGroup container, int position) {
 
         SwipeItem slideItem = mItems.get(position);
         title.setText(slideItem.title);
-        description.setText(slideItem.description);
+        if (slideItem.description == null) {
+            description.setVisibility(View.GONE);
+        } else {
+            description.setVisibility(View.VISIBLE);
+            description.setText(slideItem.description);
+        }
 
         // We shouldn't get here if the typeface didn't exist.
         // But just in case, because we're paranoid.
diff --git a/swipe-selector/src/main/res/layout/swipeselector_content_item.xml b/swipe-selector/src/main/res/layout/swipeselector_content_item.xml
index 8acce52..1e4da67 100644
--- a/swipe-selector/src/main/res/layout/swipeselector_content_item.xml
+++ b/swipe-selector/src/main/res/layout/swipeselector_content_item.xml
@@ -1,23 +1,27 @@
 <?xml version="1.0" encoding="utf-8"?>
 <LinearLayout
-    android:orientation="vertical"
-    android:layout_width="match_parent"
-    android:layout_height="wrap_content"
-    android:gravity="center_horizontal"
-    xmlns:android="http://schemas.android.com/apk/res/android">
+        android:orientation="vertical"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:gravity="center"
+        xmlns:android="http://schemas.android.com/apk/res/android"
+        xmlns:tools="http://schemas.android.com/tools">
 
     <TextView
         android:id="@+id/swipeselector_content_title"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
+        tools:text="Title"
         android:textAppearance="@style/TextAppearance.AppCompat.Body2"/>
 
+
     <TextView
         android:id="@+id/swipeselector_content_description"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_gravity="center_horizontal"
         android:layout_marginTop="4dp"
+        tools:text="Description"
         android:textAppearance="@style/TextAppearance.AppCompat.Caption"/>
 
 </LinearLayout>
\ No newline at end of file
