/**
 * Cobub Razor
 * <p>
 * An open source analytics android sdk for mobile applications
 *
 * @package Cobub Razor
 * @author WBTECH Dev Team
 * @copyright Copyright (c) 2011 - 2012, NanJing Western Bridge Co.,Ltd.
 * @license http://www.cobub.com/products/cobub-razor/license
 * @link http://www.cobub.com/products/cobub-razor/
 * @filesource
 * @since Version 0.1
 */
package com.oo.seex.oo_statistics_lib.dao;

import android.content.Context;
import android.text.TextUtils;

import com.oo.seex.oo_statistics_lib.bean.StatistivsBean;
import com.oo.seex.oo_statistics_lib.utils.CommonUtil;
import com.oo.seex.oo_statistics_lib.utils.MyDbUtils;
import com.oo.seex.oo_statistics_lib.utils.xutils_dbutils.exception.DbException;


/**
 * save data to xutils db
 *
 * @author duzhou.xu
 */
public class SaveInfo extends Thread {
    public Context context;
    public StatistivsBean object;


    public SaveInfo(Context context, StatistivsBean object) {
        super();
        this.object = object;
        this.context = context;
    }

    @Override
    public void run() {
        super.run();
        if (object == null || TextUtils.isEmpty(object.getType())) {
            return;
        }
        try {
            switch (object.getType()) {
                case "eventInfo":
                    if (object.getEventInfo() != null)
                        MyDbUtils.getInstance(context).saveStatistics(context, object.getEventInfo());
                    break;
                case "activityInfo":
                    if (object.getActivityInfo() != null )
                        MyDbUtils.getInstance(context).saveStatistics(context, object.getActivityInfo());
                    break;
                case "fragmentInfo":
                    if (object.getFragmentInfo() != null)
                        MyDbUtils.getInstance(context).saveStatistics(context, object.getFragmentInfo());
                    break;
                case "clientData":
                    if (object.getClientData() != null )
                        MyDbUtils.getInstance(context).saveStatistics(context, object.getClientData());
                    break;
                case "errorInfo":
                    if (object.getErrorInfo() != null )
                        MyDbUtils.getInstance(context).saveStatistics(context, object.getErrorInfo());
                    break;
            }
        } catch (DbException e) {
            CommonUtil.printLog("OOAgent", "error_save_info");
            CommonUtil.printLog(e);
        }
    }
}
