Skip to content

Commit

Permalink
Merge branch 'master' into TIMOB-25231
Browse files Browse the repository at this point in the history
  • Loading branch information
garymathews committed May 9, 2018
2 parents 4f7a4fb + 6de2e59 commit 0ed1375
Show file tree
Hide file tree
Showing 10 changed files with 597 additions and 227 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
// clang-format off
@Kroll.proxy(creatableInModule = UIModule.class,
propertyAccessors = {
TiC.PROPERTY_CACHE_SIZE,
TiC.PROPERTY_SHOW_PAGING_CONTROL,
TiC.PROPERTY_OVER_SCROLL_MODE
})
Expand All @@ -48,13 +49,15 @@ public class ScrollableViewProxy extends TiViewProxy
public static final int MSG_LAST_ID = MSG_FIRST_ID + 999;

private static final int DEFAULT_PAGING_CONTROL_TIMEOUT = 3000;
public static final int MIN_CACHE_SIZE = 3;

protected AtomicBoolean inScroll;

public ScrollableViewProxy()
{
super();
inScroll = new AtomicBoolean(false);
defaultValues.put(TiC.PROPERTY_CACHE_SIZE, MIN_CACHE_SIZE);
defaultValues.put(TiC.PROPERTY_SHOW_PAGING_CONTROL, false);
defaultValues.put(TiC.PROPERTY_OVER_SCROLL_MODE, 0);
}
Expand All @@ -73,51 +76,65 @@ protected TiUIScrollableView getView()
public boolean handleMessage(Message msg)
{
boolean handled = false;

TiUIScrollableView view = getView();
switch (msg.what) {
case MSG_HIDE_PAGER:
getView().hidePager();
handled = true;
if (view != null) {
view.hidePager();
handled = true;
}
break;
case MSG_MOVE_PREV:
inScroll.set(true);
getView().movePrevious();
inScroll.set(false);
handled = true;
if (view != null) {
inScroll.set(true);
view.movePrevious();
inScroll.set(false);
handled = true;
}
break;
case MSG_MOVE_NEXT:
inScroll.set(true);
getView().moveNext();
inScroll.set(false);
handled = true;
if (view != null) {
inScroll.set(true);
view.moveNext();
inScroll.set(false);
handled = true;
}
break;
case MSG_SCROLL_TO:
inScroll.set(true);
getView().scrollTo(msg.obj);
inScroll.set(false);
handled = true;
if (view != null) {
inScroll.set(true);
view.scrollTo(msg.obj);
inScroll.set(false);
handled = true;
}
break;
case MSG_SET_CURRENT:
getView().setCurrentPage(msg.obj);
handled = true;
if (view != null) {
view.setCurrentPage(msg.obj);
handled = true;
}
break;
case MSG_SET_VIEWS: {
AsyncResult holder = (AsyncResult) msg.obj;
Object views = holder.getArg();
getView().setViews(views);
if (view != null) {
view.setViews(holder.getArg());
handled = true;
}
holder.setResult(null);
handled = true;
break;
}
case MSG_ADD_VIEW: {
AsyncResult holder = (AsyncResult) msg.obj;
Object view = holder.getArg();
if (view instanceof TiViewProxy) {
getView().addView((TiViewProxy) view);
handled = true;
} else if (view != null) {
Log.w(TAG,
"addView() ignored. Expected a Titanium view object, got " + view.getClass().getSimpleName());
Object childView = holder.getArg();
if (childView instanceof TiViewProxy) {
if (view != null) {
view.addView((TiViewProxy) childView);
handled = true;
}
} else if (childView != null) {
String message = "addView() ignored. Expected a Titanium view object, got "
+ childView.getClass().getSimpleName();
Log.w(TAG, message);
}
holder.setResult(null);
break;
Expand All @@ -127,8 +144,10 @@ public boolean handleMessage(Message msg)
int insertIndex = msg.arg1;
Object arg = holder.getArg();
if (arg instanceof TiViewProxy || arg instanceof Object[]) {
getView().insertViewsAt(insertIndex, arg);
handled = true;
if (view != null) {
view.insertViewsAt(insertIndex, arg);
handled = true;
}
} else if (arg != null) {
Log.w(TAG,
"insertViewsAt() ignored. Expected a Titanium view object or a Titanium views array, got "
Expand All @@ -139,22 +158,30 @@ public boolean handleMessage(Message msg)
}
case MSG_REMOVE_VIEW: {
AsyncResult holder = (AsyncResult) msg.obj;
Object view = holder.getArg();
if (view instanceof TiViewProxy) {
getView().removeView((TiViewProxy) view);
handled = true;
} else if (view != null) {
Log.w(TAG, "removeView() ignored. Expected a Titanium view object, got "
+ view.getClass().getSimpleName());
Object object = holder.getArg();
if (object instanceof Number) {
if (view != null) {
view.removeViewByIndex(((Number) object).intValue());
handled = true;
}
} else if (object instanceof TiViewProxy) {
if (view != null) {
view.removeView((TiViewProxy) object);
handled = true;
}
} else if (object != null) {
Log.w(TAG, "removeView() argument ignored. Expected a Titanium view object or integer index. Got "
+ object.getClass().getSimpleName());
}
holder.setResult(null);
break;
}
case MSG_SET_ENABLED: {
getView().setEnabled(msg.obj);
handled = true;
case MSG_SET_ENABLED:
if (view != null) {
view.setEnabled(msg.obj);
handled = true;
}
break;
}
default:
handled = super.handleMessage(msg);
}
Expand All @@ -168,8 +195,12 @@ public boolean handleMessage(Message msg)
public Object getViews()
// clang-format on
{
List<TiViewProxy> list = new ArrayList<TiViewProxy>();
return getView().getViews().toArray(new TiViewProxy[list.size()]);
TiViewProxy[] childViewArray = new TiViewProxy[0];
TiUIScrollableView view = getView();
if (view != null) {
childViewArray = view.getViews().toArray(childViewArray);
}
return childViewArray;
}

// clang-format off
Expand Down Expand Up @@ -203,28 +234,28 @@ public void removeView(Object viewObject)
@Kroll.method
public void scrollToView(Object view)
{
if (inScroll.get())
if (inScroll.get()) {
return;

}
getMainHandler().obtainMessage(MSG_SCROLL_TO, view).sendToTarget();
}

@Kroll.method
public void movePrevious()
{
if (inScroll.get())
if (inScroll.get()) {
return;

}
getMainHandler().removeMessages(MSG_MOVE_PREV);
getMainHandler().sendEmptyMessage(MSG_MOVE_PREV);
}

@Kroll.method
public void moveNext()
{
if (inScroll.get())
if (inScroll.get()) {
return;

}
getMainHandler().removeMessages(MSG_MOVE_NEXT);
getMainHandler().sendEmptyMessage(MSG_MOVE_NEXT);
}
Expand Down Expand Up @@ -304,7 +335,8 @@ public void setScrollingEnabled(Object enabled)
public boolean getScrollingEnabled()
// clang-format on
{
return getView().getEnabled();
TiUIScrollableView view = getView();
return (view != null) ? view.getEnabled() : false;
}

// clang-format off
Expand All @@ -313,7 +345,8 @@ public boolean getScrollingEnabled()
public int getCurrentPage()
// clang-format on
{
return getView().getCurrentPage();
TiUIScrollableView view = getView();
return (view != null) ? view.getCurrentPage() : 0;
}

// clang-format off
Expand All @@ -322,7 +355,6 @@ public int getCurrentPage()
public void setCurrentPage(Object page)
// clang-format on
{
//getView().setCurrentPage(page);
getMainHandler().obtainMessage(MSG_SET_CURRENT, page).sendToTarget();
}

Expand All @@ -337,9 +369,13 @@ public void releaseViews()
public void setActivity(Activity activity)
{
super.setActivity(activity);
ArrayList<TiViewProxy> list = getView().getViews();
for (TiViewProxy proxy : list) {
proxy.setActivity(activity);

TiUIScrollableView view = getView();
if (view != null) {
ArrayList<TiViewProxy> list = view.getViews();
for (TiViewProxy proxy : list) {
proxy.setActivity(activity);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@
TiC.PROPERTY_HEADER_DIVIDERS_ENABLED,
TiC.PROPERTY_FOOTER_DIVIDERS_ENABLED,
TiC.PROPERTY_MAX_CLASSNAME,
TiC.PROPERTY_REFRESH_CONTROL
TiC.PROPERTY_REFRESH_CONTROL,
TiC.PROPERTY_SCROLLABLE
})
// clang-format on
public class TableViewProxy extends TiViewProxy
Expand Down Expand Up @@ -87,6 +88,7 @@ public TableViewProxy()
{
super();
defaultValues.put(TiC.PROPERTY_OVER_SCROLL_MODE, 0);
defaultValues.put(TiC.PROPERTY_SCROLLABLE, true);
// eventManager.addOnEventChangeListener(this);
}

Expand Down

0 comments on commit 0ed1375

Please sign in to comment.