Skip to content

Commit

Permalink
Merge branch '7_1_X' into TIMOB-25619_71X
Browse files Browse the repository at this point in the history
  • Loading branch information
Lokesh Choudhary committed Feb 28, 2018
2 parents 8eacf49 + e8115d7 commit 6544fed
Show file tree
Hide file tree
Showing 3 changed files with 1,058 additions and 92 deletions.
191 changes: 105 additions & 86 deletions android/modules/ui/src/java/ti/modules/titanium/ui/TableViewProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import ti.modules.titanium.ui.widget.TiUITableView;
import ti.modules.titanium.ui.widget.tableview.TableViewModel.Item;

import android.app.Activity;
import android.os.Message;
// clang-format off
Expand All @@ -44,7 +45,7 @@
TiC.PROPERTY_FOOTER_DIVIDERS_ENABLED,
TiC.PROPERTY_MAX_CLASSNAME,
TiC.PROPERTY_REFRESH_CONTROL
})
})
// clang-format on
public class TableViewProxy extends TiViewProxy
{
Expand Down Expand Up @@ -280,7 +281,7 @@ private void handleAppendRow(Object rows)
}
}

getTableView().setModelDirty();
setModelDirtyIfNecessary();
updateView();
}

Expand Down Expand Up @@ -333,14 +334,23 @@ public void deleteRow(Object row, @Kroll.argument(optional = true) KrollDict opt
}
}

private void setModelDirtyIfNecessary()
{
TiUITableView nativeTableViewReference = ((TiUITableView) peekView());
if (nativeTableViewReference != null) {
nativeTableViewReference.setModelDirty();
}
}

private void handleDeleteRow(Object row) throws IllegalStateException
{

if (row instanceof Integer) {
int index = (Integer) row;
RowResult rr = new RowResult();
if (locateIndex(index, rr)) {
rr.section.removeRowAt(rr.rowIndexInSection);
getTableView().setModelDirty();
setModelDirtyIfNecessary();
updateView();
} else {
Log.e(TAG, "Unable to delete row. Index out of range. Non-existent row at " + index);
Expand All @@ -350,7 +360,7 @@ private void handleDeleteRow(Object row) throws IllegalStateException
TiViewProxy section = rowProxy.getParent();
if (section instanceof TableViewSectionProxy) {
((TableViewSectionProxy) section).remove(rowProxy);
getTableView().setModelDirty();
setModelDirtyIfNecessary();
updateView();
} else {
Log.e(TAG, "Unable to delete row. The row is not added to the table yet.");
Expand Down Expand Up @@ -513,7 +523,7 @@ private void handleInsertRowAfter(int index, Object data) throws IllegalStateExc
// TODO check for section
TableViewRowProxy rowProxy = rowProxyFor(data);
rr.section.insertRowAt(rr.rowIndexInSection + 1, rowProxy);
getTableView().setModelDirty();
setModelDirtyIfNecessary();
updateView();
} else {
throw new IllegalStateException("Index out of range. Non-existent row at " + index);
Expand Down Expand Up @@ -844,7 +854,7 @@ private boolean locateIndex(int index, RowResult rowResult)
public void updateView()
{
if (TiApplication.isUIThread()) {
getTableView().updateView();
setModelDirtyIfNecessary();
return;
}

Expand Down Expand Up @@ -880,89 +890,98 @@ public void scrollToTop(int index)
@Override
public boolean handleMessage(Message msg)
{
if (getTableView() == null) {
return false;
}
if (msg.what == MSG_UPDATE_VIEW) {
getTableView().updateView();
((AsyncResult) msg.obj).setResult(null);
return true;
} else if (msg.what == MSG_SCROLL_TO_INDEX) {
getTableView().scrollToIndex(msg.arg1);
return true;
} else if (msg.what == MSG_SET_DATA) {
AsyncResult result = (AsyncResult) msg.obj;
Object[] data = (Object[]) result.getArg();
handleSetData(data);
result.setResult(null);
return true;
} else if (msg.what == MSG_INSERT_ROW) {
AsyncResult result = (AsyncResult) msg.obj;
try {
if (msg.arg1 == INSERT_ROW_AFTER) {
handleInsertRowAfter(msg.arg2, result.getArg());

} else {
handleInsertRowBefore(msg.arg2, result.getArg());
}
result.setResult(null);

} catch (IllegalStateException e) {
result.setResult(e);
}
return true;
} else if (msg.what == MSG_APPEND_ROW) {
AsyncResult result = (AsyncResult) msg.obj;
handleAppendRow(result.getArg());
result.setResult(null);
return true;
} else if (msg.what == MSG_DELETE_ROW) {
AsyncResult result = (AsyncResult) msg.obj;
try {
handleDeleteRow(result.getArg());
result.setResult(null);
} catch (IllegalStateException e) {
result.setResult(e);
}
return true;
} else if (msg.what == MSG_INSERT_SECTION) {
AsyncResult result = (AsyncResult) msg.obj;
try {
if (msg.arg1 == INSERT_SECTION_AFTER) {
handleInsertSectionAfter(msg.arg2, result.getArg());

} else {
handleInsertSectionBefore(msg.arg2, result.getArg());
TiUITableView tableNativeView = ((TiUITableView) peekView());
boolean tableNativeViewCreated = (tableNativeView != null);
AsyncResult result = null;
Object asyncResult = null;
switch (msg.what) {
case MSG_UPDATE_VIEW:
result = (AsyncResult) msg.obj;
if (tableNativeViewCreated) {
tableNativeView.updateView();
}
result.setResult(null);

} catch (IllegalStateException e) {
result.setResult(e);
}
return true;
} else if (msg.what == MSG_APPEND_SECTION) {
AsyncResult result = (AsyncResult) msg.obj;
handleAppendSection(result.getArg());
result.setResult(null);
return true;
} else if (msg.what == MSG_DELETE_SECTION) {
AsyncResult result = (AsyncResult) msg.obj;
try {
handleDeleteSection((Integer) result.getArg());
result.setResult(null);
} catch (IllegalStateException e) {
result.setResult(e);
}
return true;
} else if (msg.what == MSG_SCROLL_TO_TOP) {
getTableView().scrollToTop(msg.arg1);
return true;
} else if (msg.what == MSG_SELECT_ROW) {
getTableView().selectRow(msg.arg1);
return true;
break;
case MSG_SCROLL_TO_INDEX:
if (tableNativeViewCreated) {
tableNativeView.scrollToIndex(msg.arg1);
}
return true;
case MSG_SET_DATA:
result = ((AsyncResult) msg.obj);
Object[] data = (Object[]) result.getArg();
handleSetData(data);
break;
case MSG_INSERT_ROW:
result = ((AsyncResult) msg.obj);
try {
if (msg.arg1 == INSERT_ROW_AFTER) {
handleInsertRowAfter(msg.arg2, result.getArg());
} else {
handleInsertRowBefore(msg.arg2, result.getArg());
}
result = (AsyncResult) msg.obj;
} catch (IllegalStateException e) {
asyncResult = e;
e.printStackTrace();
}
break;
case MSG_APPEND_ROW:
result = ((AsyncResult) msg.obj);
handleAppendRow(result.getArg());
break;
case MSG_DELETE_ROW:
result = ((AsyncResult) msg.obj);
try {
handleDeleteRow(result.getArg());
} catch (IllegalStateException e) {
asyncResult = e;
e.printStackTrace();
}
break;
case MSG_INSERT_SECTION:
result = ((AsyncResult) msg.obj);
try {
if (msg.arg1 == INSERT_SECTION_AFTER) {
handleInsertSectionAfter(msg.arg2, result.getArg());
} else {
handleInsertSectionBefore(msg.arg2, result.getArg());
}
} catch (IllegalStateException e) {
asyncResult = e;
e.printStackTrace();
}
break;
case MSG_APPEND_SECTION:
result = ((AsyncResult) msg.obj);
handleAppendSection(result.getArg());
break;
case MSG_DELETE_SECTION:
result = ((AsyncResult) msg.obj);
try {
handleDeleteSection((Integer) result.getArg());
} catch (IllegalStateException e) {
asyncResult = e;
e.printStackTrace();
}
break;
case MSG_SCROLL_TO_TOP:
if (tableNativeViewCreated) {
tableNativeView.scrollToTop(msg.arg1);
}
break;
case MSG_SELECT_ROW:
if (tableNativeViewCreated) {
tableNativeView.selectRow(msg.arg1);
}
break;
default:
return super.handleMessage(msg);
}

return super.handleMessage(msg);
if (result != null) {
result.setResult(asyncResult);
}
return true;
}

// labels only send out click events when they are explicitly told to do so.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1157,7 +1157,7 @@ private void applyCustomBackground(boolean reuseCurrentDrawable)

/**
* @param props View's property dictionary
* @return true if touch feedback can be applied.
* @return true if touch feedback can be applied.
*/
protected boolean canApplyTouchFeedback(@NonNull KrollDict props)
{
Expand All @@ -1166,17 +1166,17 @@ protected boolean canApplyTouchFeedback(@NonNull KrollDict props)
}

/**
* Applies touch feedback. Should check canApplyTouchFeedback() before calling this.
* @param backgroundColor The background color of the view.
* Applies touch feedback. Should check canApplyTouchFeedback() before calling this.
* @param backgroundColor The background color of the view.
* @param rippleColor The ripple color.
*/
private void applyTouchFeedback(@NonNull Integer backgroundColor, @Nullable Integer rippleColor)
{
if (rippleColor == null) {
Context context = TiApplication.getInstance();
Context context = proxy.getActivity();
TypedValue attribute = new TypedValue();
if (context.getTheme().resolveAttribute(android.R.attr.colorControlHighlight, attribute, true)) {
rippleColor = context.getResources().getColor(attribute.resourceId);
rippleColor = attribute.data;
} else {
throw new RuntimeException("android.R.attr.colorControlHighlight cannot be resolved into Drawable");
}
Expand Down

0 comments on commit 6544fed

Please sign in to comment.