});
try {
Long viewID = null;
final Storage storage = Storage.getSessionStorageIfSupported();
if (storage != null) {
final String v = storage.getItem(APPLICATION.VIEW_ID);
if (v != null && !v.isEmpty()) viewID = Long.parseLong(v);
}
final PTInstruction requestData = new PTInstruction();
final JSONArray cookies = new JSONArray();
// load all cookies at startup
final Collection<String> cookieNames = Cookies.getCookieNames();
if (cookieNames != null) {
int i = 0;
for (final String cookie : cookieNames) {
final JSONObject jsoObject = new JSONObject();
jsoObject.put(PROPERTY.KEY, new JSONString(cookie));
jsoObject.put(PROPERTY.VALUE, new JSONString(Cookies.getCookie(cookie)));
cookies.set(i++, jsoObject);
}
}
requestData.put(APPLICATION.KEY, APPLICATION.KEY_.START);
requestData.put(APPLICATION.SEQ_NUM, 0);
requestData.put(HISTORY.TOKEN, History.getToken());
requestData.put(PROPERTY.COOKIES, cookies);
if (viewID != null) requestData.put(APPLICATION.VIEW_ID, viewID);
final RequestCallback requestCallback = new RequestCallback() {
@Override
public void onDataReceived(final JSONObject data) {
try {
if (data.containsKey(APPLICATION.VIEW_ID)) {
applicationViewID = (long) data.get(APPLICATION.VIEW_ID).isNumber().doubleValue();
if (storage != null) storage.setItem(APPLICATION.VIEW_ID, Long.toString(applicationViewID));
uiBuilder.init(applicationViewID, requestBuilder);
}
uiBuilder.update(data);