diff --git a/.gitignore b/.gitignore index f97964b..7538f8a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,7 @@ tmp bin -build +/build +/dist +/libs *.zip .apt_generated diff --git a/dist/com.rkam.swiperefreshlayout-android-0.1.zip b/dist/com.rkam.swiperefreshlayout-android-0.1.zip deleted file mode 100644 index a607966..0000000 Binary files a/dist/com.rkam.swiperefreshlayout-android-0.1.zip and /dev/null differ diff --git a/dist/swiperefreshlayout.jar b/dist/swiperefreshlayout.jar deleted file mode 100644 index c8b3599..0000000 Binary files a/dist/swiperefreshlayout.jar and /dev/null differ diff --git a/example/app.js b/example/app.js index ed5db12..3473a16 100644 --- a/example/app.js +++ b/example/app.js @@ -53,9 +53,8 @@ var listView = Ti.UI.createListView({ }); var swipeRefreshModule = require('com.rkam.swiperefreshlayout'); -var swipeRefresh = swipeRefreshModule.createSwipeRefresh({ - view: listView -}); +var swipeRefresh = swipeRefreshModule.createSwipeRefresh(); +swipeRefresh.add(listView) var fakeData = [ {from: "User 1", message:"Hello there"}, diff --git a/libs/armeabi-v7a/libcom.rkam.swiperefreshlayout.so b/libs/armeabi-v7a/libcom.rkam.swiperefreshlayout.so deleted file mode 100644 index 7c5ab39..0000000 Binary files a/libs/armeabi-v7a/libcom.rkam.swiperefreshlayout.so and /dev/null differ diff --git a/libs/x86/libcom.rkam.swiperefreshlayout.so b/libs/x86/libcom.rkam.swiperefreshlayout.so deleted file mode 100644 index 7cd472d..0000000 Binary files a/libs/x86/libcom.rkam.swiperefreshlayout.so and /dev/null differ diff --git a/manifest b/manifest index f5a3b35..b73555b 100644 --- a/manifest +++ b/manifest @@ -2,10 +2,10 @@ # this is your module manifest and used by Titanium # during compilation, packaging, distribution, etc. # -version: 1.0.0 -apiversion: 3 +version: 3.0.0 +apiversion: 4 description: Titanium version of SwipeRefreshLayout -architectures: armeabi-v7a x86 +architectures: arm64-v8a armeabi-v7a x86 author: Raymond Kam license: Specify your license copyright: Copyright (c) 2016 by Your Company @@ -16,4 +16,4 @@ name: swiperefreshlayout moduleid: com.rkam.swiperefreshlayout guid: fc0f2168-ac27-4239-bcb0-c51d7683eb05 platform: android -minsdk: 6.0.0 +minsdk: 7.0.0 diff --git a/src/com/rkam/swiperefreshlayout/MySwipeRefreshLayout.java b/src/com/rkam/swiperefreshlayout/MySwipeRefreshLayout.java index 8a31835..ef6f379 100644 --- a/src/com/rkam/swiperefreshlayout/MySwipeRefreshLayout.java +++ b/src/com/rkam/swiperefreshlayout/MySwipeRefreshLayout.java @@ -46,6 +46,9 @@ public boolean canChildScrollUp() { } else { nativeChildView = nativeView; } + if (nativeChildView == null) { + return false; + } if (android.os.Build.VERSION.SDK_INT < 14) { if (nativeChildView instanceof AbsListView) { final AbsListView absListView = (AbsListView) nativeChildView; diff --git a/src/com/rkam/swiperefreshlayout/SwipeRefresh.java b/src/com/rkam/swiperefreshlayout/SwipeRefresh.java index b01258b..1fa5af6 100644 --- a/src/com/rkam/swiperefreshlayout/SwipeRefresh.java +++ b/src/com/rkam/swiperefreshlayout/SwipeRefresh.java @@ -1,8 +1,6 @@ package com.rkam.swiperefreshlayout; -import org.appcelerator.kroll.KrollDict; import org.appcelerator.titanium.TiApplication; -import org.appcelerator.titanium.proxy.TiViewProxy; import org.appcelerator.titanium.view.TiUIView; import org.appcelerator.titanium.util.TiRHelper; import org.appcelerator.titanium.util.TiRHelper.ResourceNotFoundException; @@ -13,9 +11,6 @@ public class SwipeRefresh extends TiUIView { - private MySwipeRefreshLayout layout; - private TiViewProxy view; - public static final String PROPERTY_VIEW = "view"; public static final String PROPERTY_COLOR_SCHEME = "colorScheme"; private static final String TAG = "SwipeRefresh"; @@ -42,7 +37,8 @@ public SwipeRefresh(final SwipeRefreshProxy proxy) { } LayoutInflater inflater = LayoutInflater.from(TiApplication.getInstance()); - layout = (MySwipeRefreshLayout) inflater.inflate(layout_swipe_refresh, null, false); + MySwipeRefreshLayout layout = + (MySwipeRefreshLayout) inflater.inflate(layout_swipe_refresh, null, false); layout.setOnRefreshListener(new OnRefreshListener() { @Override @@ -57,25 +53,40 @@ public void onRefresh() { } @Override - public void processProperties(KrollDict d) { - if (d.containsKey(PROPERTY_VIEW)) { - Object view = d.get(PROPERTY_VIEW); - if (view != null && view instanceof TiViewProxy) { - this.view = (TiViewProxy) view; - this.layout.setNativeView(this.view.getOrCreateView().getNativeView()); - this.layout.addView(this.view.getOrCreateView().getOuterView()); - this.layout.setColorSchemeColors(color1, color2, color3, color4); - } - } - super.processProperties(d); + public void add(TiUIView child) + { + MySwipeRefreshLayout layout = (MySwipeRefreshLayout) getNativeView(); + layout.setNativeView(child.getNativeView()); + super.add(child); + layout.setColorSchemeColors(color1, color2, color3, color4); } public boolean isRefreshing() { - return this.layout.isRefreshing(); + MySwipeRefreshLayout layout = (MySwipeRefreshLayout) getNativeView(); + if (layout != null) { + return layout.isRefreshing(); + } + return false; } public void setRefreshing(boolean refreshing) { - this.layout.setRefreshing(refreshing); + MySwipeRefreshLayout layout = (MySwipeRefreshLayout) getNativeView(); + if (layout != null) { + layout.setRefreshing(refreshing); + } + } + + @Override + public void release() { + Log.d(TAG, "release"); + MySwipeRefreshLayout layout = (MySwipeRefreshLayout) getNativeView(); + if (layout != null) { + layout.removeAllViews(); + layout.setRefreshing(false); + layout.setOnRefreshListener(null); + } + super.release(); + proxy = null; } } diff --git a/src/com/rkam/swiperefreshlayout/SwipeRefreshProxy.java b/src/com/rkam/swiperefreshlayout/SwipeRefreshProxy.java index 2688b4b..d56f134 100644 --- a/src/com/rkam/swiperefreshlayout/SwipeRefreshProxy.java +++ b/src/com/rkam/swiperefreshlayout/SwipeRefreshProxy.java @@ -13,18 +13,17 @@ @Kroll.proxy(creatableInModule=SwiperefreshlayoutModule.class) public class SwipeRefreshProxy extends TiViewProxy implements Handler.Callback { - private SwipeRefresh swipeRefresh; - protected static final int MSG_SET_REFRESHING = KrollProxy.MSG_LAST_ID + 101; + private static final String TAG = "SwipeRefreshProxy"; + public SwipeRefreshProxy() { super(); } @Override public TiUIView createView(Activity activity) { - swipeRefresh = new SwipeRefresh(this); - return this.swipeRefresh; + return new SwipeRefresh(this); } /* Public API */ @@ -42,7 +41,11 @@ public void setRefreshing(boolean refreshing) { @Kroll.method @Kroll.getProperty public boolean isRefreshing() { - return this.swipeRefresh.isRefreshing(); + SwipeRefresh v = (SwipeRefresh) peekView(); + if (v != null) { + return v.isRefreshing(); + } + return false; } /* Utilities */ @@ -59,6 +62,9 @@ public boolean handleMessage(Message message) { } protected void doSetRefreshing(boolean refreshing) { - this.swipeRefresh.setRefreshing(refreshing); + SwipeRefresh v = (SwipeRefresh) peekView(); + if (v != null) { + v.setRefreshing(refreshing); + } } }