iskugor / Ti.SwipeRefreshLayout

Titanium module for Android's SwipeRefreshLayout.
56 stars 19 forks source link

Use new Material design version of SwipeRefresh #12

Closed yissachar closed 9 years ago

yissachar commented 9 years ago

As mentioned in https://github.com/iskugor/Ti.SwipeRefreshLayout/issues/11 there is a new version of SwipeRefresh available. I've updated the Android support files needed to make this work.

iskugor commented 9 years ago

Hi.

Thank you for pull request. There seems to be a problem when I try to run my test app on Nexus 7 with Android 5.1.1 using TiSDK 3.4.1.GA or 3.5.0.GA

[ERROR] KrollProxy: (KrollRuntimeThread) [371,371] Error creating proxy
[ERROR] KrollProxy: android.view.InflateException: Binary XML file line #1: Error inflating class com.rkam.swiperefreshlayout.MySwipeRefreshLayout
[ERROR] KrollProxy:     at android.view.LayoutInflater.createView(LayoutInflater.java:633)
[ERROR] KrollProxy:     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743)
[ERROR] KrollProxy:     at android.view.LayoutInflater.inflate(LayoutInflater.java:482)
[ERROR] KrollProxy:     at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
[ERROR] KrollProxy:     at com.rkam.swiperefreshlayout.SwipeRefresh.<init>(SwipeRefresh.java:46)
[ERROR] KrollProxy:     at com.rkam.swiperefreshlayout.SwipeRefreshProxy.<init>(SwipeRefreshProxy.java:16)
[ERROR] KrollProxy:     at java.lang.reflect.Constructor.newInstance(Native Method)
[ERROR] KrollProxy:     at java.lang.Class.newInstance(Class.java:1606)
[ERROR] KrollProxy:     at org.appcelerator.kroll.KrollProxy.createProxy(KrollProxy.java:139)
[ERROR] KrollProxy:     at org.appcelerator.kroll.runtime.v8.V8Runtime.nativeRunModule(Native Method)
[ERROR] KrollProxy:     at org.appcelerator.kroll.runtime.v8.V8Runtime.doRunModule(V8Runtime.java:177)
[ERROR] KrollProxy:     at org.appcelerator.kroll.KrollRuntime.handleMessage(KrollRuntime.java:299)
[ERROR] KrollProxy:     at org.appcelerator.kroll.runtime.v8.V8Runtime.handleMessage(V8Runtime.java:203)
[ERROR] KrollProxy:     at android.os.Handler.dispatchMessage(Handler.java:98)
[ERROR] KrollProxy:     at android.os.Looper.loop(Looper.java:135)
[ERROR] KrollProxy:     at org.appcelerator.kroll.KrollRuntime$KrollRuntimeThread.run(KrollRuntime.java:112)
[ERROR] KrollProxy: Caused by: java.lang.reflect.InvocationTargetException
[ERROR] KrollProxy:     at java.lang.reflect.Constructor.newInstance(Native Method)
[ERROR] KrollProxy:     at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
[ERROR] KrollProxy:     at android.view.LayoutInflater.createView(LayoutInflater.java:607)
[ERROR] KrollProxy:     ... 15 more
[ERROR] KrollProxy: Caused by: java.lang.NoSuchMethodError: No static method setElevation(Landroid/view/View;F)V in class Landroid/support/v4/view/ViewCompat; or its super classes (declaration of 'android.support.v4.view.ViewCompat' appears in /data/app/com.tipsyandtumbler.test2-2/base.apk)
[ERROR] KrollProxy:     at com.rkam.swiperefreshlayout.CircleImageView.<init>(CircleImageView.java:63)
[ERROR] KrollProxy:     at com.rkam.swiperefreshlayout.SwipeRefreshLayout.createProgressView(SwipeRefreshLayout.java:310)
[ERROR] KrollProxy:     at com.rkam.swiperefreshlayout.SwipeRefreshLayout.<init>(SwipeRefreshLayout.java:287)
[ERROR] KrollProxy:     at com.rkam.swiperefreshlayout.MySwipeRefreshLayout.<init>(MySwipeRefreshLayout.java:27)
[ERROR] KrollProxy:     ... 18 more
[ERROR] TiViewProxy: (KrollRuntimeThread) [2,373] Add called with a null child

Works fine with older module version.

Could you take a look? I can send you test project if you want (it's basically simple Alloy project).

Thanks.

yissachar commented 9 years ago

Sorry, I had tested on TiSDK 4.1.0 which seems to have a newer version of the support library where those methods exist. I've patched the files so that it will run even on older versions of Titanium now. I've tested on 4.1.0, 3.5.0, and 3.4.1.

Let me know if this fixes the issue for you.

iskugor commented 9 years ago

Much better, thank you.

However, there's one more issue.

This line:

$.swipeRefresh.setRefreshing(false);

crashes app.

[WARN]  W/System.err: android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
[WARN]  W/System.err:   at android.view.ViewRootImpl.checkThread(ViewRootImpl.java:6357)
[WARN]  W/System.err:   at android.view.ViewRootImpl.invalidateChildInParent(ViewRootImpl.java:909)
[WARN]  W/System.err:   at android.view.ViewGroup.invalidateChild(ViewGroup.java:4690)
[WARN]  W/System.err:   at android.view.View.invalidateInternal(View.java:11801)
[WARN]  W/System.err:   at android.view.View.invalidate(View.java:11765)
[WARN]  W/System.err:   at android.view.View.invalidateParentIfNeeded(View.java:11954)
[WARN]  W/System.err:   at android.view.View.clearAnimation(View.java:17870)
[WARN]  W/System.err:   at com.rkam.swiperefreshlayout.SwipeRefreshLayout.startScaleDownAnimation(SwipeRefreshLayout.java:418)
[WARN]  W/System.err:   at com.rkam.swiperefreshlayout.SwipeRefreshLayout.setRefreshing(SwipeRefreshLayout.java:404)
[WARN]  W/System.err:   at com.rkam.swiperefreshlayout.SwipeRefreshLayout.setRefreshing(SwipeRefreshLayout.java:357)
[WARN]  W/System.err:   at com.rkam.swiperefreshlayout.SwipeRefresh.setRefreshing(SwipeRefresh.java:88)
[WARN]  W/System.err:   at com.rkam.swiperefreshlayout.SwipeRefreshProxy.setRefreshing(SwipeRefreshProxy.java:27)
[WARN]  W/System.err:   at org.appcelerator.kroll.runtime.v8.V8Function.nativeInvoke(Native Method)
[WARN]  W/System.err:   at org.appcelerator.kroll.runtime.v8.V8Function.callSync(V8Function.java:57)
[WARN]  W/System.err:   at org.appcelerator.kroll.runtime.v8.V8Function.call(V8Function.java:43)
[WARN]  W/System.err:   at ti.modules.titanium.TitaniumModule$Timer.run(TitaniumModule.java:152)
[WARN]  W/System.err:   at android.os.Handler.handleCallback(Handler.java:739)
[WARN]  W/System.err:   at android.os.Handler.dispatchMessage(Handler.java:95)
[WARN]  W/System.err:   at android.os.Looper.loop(Looper.java:135)
[WARN]  W/System.err:   at org.appcelerator.kroll.KrollRuntime$KrollRuntimeThread.run(KrollRuntime.java:112)
[ERROR] TiExceptionHandler: (main) [27267,27267] ----- Titanium Javascript Runtime Error -----
[ERROR] TiExceptionHandler: (main) [1,27268] - In alloy/controllers/index.js:1,69
[ERROR] TiExceptionHandler: (main) [0,27268] - Message: Uncaught Error: Only the original thread that created a view hierarchy can touch its views.
[ERROR] TiExceptionHandler: (main) [0,27268] - Source: stener("refreshing",function(){setTimeout(function(){t.swipeRefresh.setRefresh
[ERROR] V8Exception: Exception occurred at alloy/controllers/index.js:1: Uncaught Error: Only the original thread that created a view hierarchy can touch its views.

You might know what's the problem?

yissachar commented 9 years ago

Missed that one since I wasn't using setTimeout in my code. I've added the code to ensure that refresh takes place on the UI thread and I don't receive that error any more.

Hopefully that was the last bug :)

iskugor commented 9 years ago

Awesome, works great now. Thanks! :+1:

yissachar commented 9 years ago

Great, thanks for merging!