* [android] fix invalid init index

Project: http://git-wip-us.apache.org/repos/asf/incubator-weex/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-weex/commit/a3e85400
Tree: http://git-wip-us.apache.org/repos/asf/incubator-weex/tree/a3e85400
Diff: http://git-wip-us.apache.org/repos/asf/incubator-weex/diff/a3e85400

Branch: refs/heads/apache-0.15-dev
Commit: a3e8540066186d64663cdfaa992cc66126f7625c
Parents: ab75b9e
Author: misakuo <misa...@apache.org>
Authored: Wed Jul 12 17:56:49 2017 +0800
Committer: misakuo <misa...@apache.org>
Committed: Wed Jul 12 17:56:49 2017 +0800

----------------------------------------------------------------------
 .../com/taobao/weex/IUpdateFinishListener.java   |  9 +++++++++
 .../main/java/com/taobao/weex/WXSDKInstance.java | 19 +++++++++++++++++++
 .../com/taobao/weex/ui/component/WXSlider.java   | 11 +++++++++++
 3 files changed, 39 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/a3e85400/android/sdk/src/main/java/com/taobao/weex/IUpdateFinishListener.java
----------------------------------------------------------------------
diff --git 
a/android/sdk/src/main/java/com/taobao/weex/IUpdateFinishListener.java 
b/android/sdk/src/main/java/com/taobao/weex/IUpdateFinishListener.java
new file mode 100644
index 0000000..6824bf5
--- /dev/null
+++ b/android/sdk/src/main/java/com/taobao/weex/IUpdateFinishListener.java
@@ -0,0 +1,9 @@
+package com.taobao.weex;
+
+/**
+ * Created by moxun on 2017/7/12.
+ */
+
+public interface IUpdateFinishListener {
+  void onUpdateFinish();
+}

http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/a3e85400/android/sdk/src/main/java/com/taobao/weex/WXSDKInstance.java
----------------------------------------------------------------------
diff --git a/android/sdk/src/main/java/com/taobao/weex/WXSDKInstance.java 
b/android/sdk/src/main/java/com/taobao/weex/WXSDKInstance.java
index 9586993..c6b0553 100644
--- a/android/sdk/src/main/java/com/taobao/weex/WXSDKInstance.java
+++ b/android/sdk/src/main/java/com/taobao/weex/WXSDKInstance.java
@@ -116,6 +116,7 @@ public class WXSDKInstance implements 
IWXActivityStateListener,DomContext, View.
   private static volatile int mViewPortWidth = 750;
   private int mInstanceViewPortWidth = 750;
   private List<ICreateFinishListener> mCreateFinishListeners;
+  private List<IUpdateFinishListener> mUpdateFinishListeners;
 
   /**
    * Render strategy.
@@ -949,6 +950,11 @@ public class WXSDKInstance implements 
IWXActivityStateListener,DomContext, View.
    */
   public void onUpdateFinish() {
     WXLogUtils.d("Instance onUpdateSuccess");
+    if (mUpdateFinishListeners != null && mUpdateFinishListeners.size() > 0) {
+      for (IUpdateFinishListener listener : mUpdateFinishListeners) {
+        listener.onUpdateFinish();
+      }
+    }
   }
 
 
@@ -1610,4 +1616,17 @@ public class WXSDKInstance implements 
IWXActivityStateListener,DomContext, View.
       mCreateFinishListeners.remove(listener);
     }
   }
+
+  public void addUpdateFinishListener(IUpdateFinishListener listener) {
+    if (mUpdateFinishListeners == null) {
+      mUpdateFinishListeners = new ArrayList<>();
+    }
+    mUpdateFinishListeners.add(listener);
+  }
+
+  public void removeUpdateFinishListener(IUpdateFinishListener listener) {
+    if (mUpdateFinishListeners != null && listener != null) {
+      mUpdateFinishListeners.remove(listener);
+    }
+  }
 }

http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/a3e85400/android/sdk/src/main/java/com/taobao/weex/ui/component/WXSlider.java
----------------------------------------------------------------------
diff --git 
a/android/sdk/src/main/java/com/taobao/weex/ui/component/WXSlider.java 
b/android/sdk/src/main/java/com/taobao/weex/ui/component/WXSlider.java
index 8fbd291..b983f98 100644
--- a/android/sdk/src/main/java/com/taobao/weex/ui/component/WXSlider.java
+++ b/android/sdk/src/main/java/com/taobao/weex/ui/component/WXSlider.java
@@ -31,6 +31,7 @@ import android.view.ViewGroup.LayoutParams;
 import android.widget.FrameLayout;
 
 import com.taobao.weex.ICreateFinishListener;
+import com.taobao.weex.IUpdateFinishListener;
 import com.taobao.weex.WXEnvironment;
 import com.taobao.weex.WXSDKInstance;
 import com.taobao.weex.WXSDKManager;
@@ -524,6 +525,16 @@ public class WXSlider extends WXVContainer<FrameLayout> {
         }
       }
     });
+
+    getInstance().addUpdateFinishListener(new IUpdateFinishListener() {
+      @Override
+      public void onUpdateFinish() {
+        if (mViewPager != null && initIndex != -1) {
+          mViewPager.setCurrentItem(initIndex);
+          initIndex = -1;
+        }
+      }
+    });
   }
 
   private static class FlingGestureListener extends 
GestureDetector.SimpleOnGestureListener {

Reply via email to