Search in sources :

Example 1 with EventLog

use of com.wingjay.jianshi.db.model.EventLog in project jianshi by wingjay.

the class SyncManager method syncLog.

public synchronized void syncLog() {
    final List<EventLog> logItems = SQLite.select().from(EventLog.class).queryList();
    JsonObject syncLog = new JsonObject();
    JsonArray array = new JsonArray();
    for (EventLog eventLog : logItems) {
        array.add(new Gson().toJsonTree(eventLog));
    }
    syncLog.add("log_items", array);
    userService.syncLog(syncLog).subscribe(new Action1<JsonDataResponse<JsonObject>>() {

        @Override
        public void call(JsonDataResponse<JsonObject> jsonObjectJsonDataResponse) {
            if (jsonObjectJsonDataResponse.getRc() == Constants.ServerResultCode.RESULT_OK) {
                JsonObject object = jsonObjectJsonDataResponse.getData();
                int syncedCount = object.get("synced_count").getAsInt();
                Timber.i("synced log count %d", syncedCount);
                for (EventLog eventLog : logItems) {
                    SQLite.delete(EventLog.class).where(EventLog_Table.id.eq(eventLog.getId())).execute();
                    syncedCount--;
                    if (syncedCount <= 0) {
                        break;
                    }
                }
            }
        }
    }, new Action1<Throwable>() {

        @Override
        public void call(Throwable throwable) {
            Timber.e(throwable, "SyncLog failed");
        }
    });
}
Also used : JsonArray(com.google.gson.JsonArray) JsonDataResponse(com.wingjay.jianshi.network.JsonDataResponse) EventLog(com.wingjay.jianshi.db.model.EventLog) JsonObject(com.google.gson.JsonObject) Gson(com.google.gson.Gson)

Example 2 with EventLog

use of com.wingjay.jianshi.db.model.EventLog in project jianshi by wingjay.

the class Blaster method log.

public static void log(String eventName, String pageSource) {
    EventLog eventLog = new EventLog();
    eventLog.setEventName(eventName);
    eventLog.setPageSource(pageSource);
    eventLog.setTimeCreated(DateUtil.getCurrentTimeStamp());
    eventLog.save();
}
Also used : EventLog(com.wingjay.jianshi.db.model.EventLog)

Aggregations

EventLog (com.wingjay.jianshi.db.model.EventLog)2 Gson (com.google.gson.Gson)1 JsonArray (com.google.gson.JsonArray)1 JsonObject (com.google.gson.JsonObject)1 JsonDataResponse (com.wingjay.jianshi.network.JsonDataResponse)1