package org.adaptlab.chpir.android.survey.Models;

import org.adaptlab.chpir.android.activerecordcloudsync.ReceiveModel;
import org.json.JSONException;
import org.json.JSONObject;

import android.util.Log;

import com.activeandroid.annotation.Column;
import com.activeandroid.annotation.Table;
import com.activeandroid.query.Select;

@Table(name = "AdminSettings")
public class AdminSettings extends ReceiveModel {
    private static final String TAG = "AdminSettings";
    @Column(name = "DeviceIdentifier")
    private String mDeviceIdentifier;
    @Column(name = "SyncInterval")
    private int mSyncInterval;
    
    private static AdminSettings adminSettings;
    
    /**
     * This maintains a single row in the database for the admin settings, and
     * effectively is a Singleton.  This is done to piggy-back on the
     * ReceiveModel functionality.
     * 
     */
    public static AdminSettings getInstance() {
        adminSettings = new Select().from(AdminSettings.class).orderBy("Id asc").executeSingle();
        if (adminSettings == null) {
            adminSettings = new AdminSettings();
        }
        return adminSettings;
    }
    
    /**
     * Typically a Singleton constructor is private, but in this case the constructor
     * must be public for ActiveAndroid to function properly.  Do not use this
     * constructor, use getInstance() instead.
     * 
     */
    public AdminSettings() {
        super();
    }
    
    public void setDeviceIdentifier(String id) {
        mDeviceIdentifier = id;
        save();
    }
    
    public String getDeviceIdentifier() {
        return mDeviceIdentifier;
    }
    
    public int getSyncInterval() {
        return mSyncInterval;
    }
    
    public void setSyncInterval(int interval) {
        mSyncInterval = interval;
        save();
    }

    
    @Override
    public void createObjectFromJSON(JSONObject jsonObject) {
        try {
            Log.i(TAG, "Saving Admin Settings: " + jsonObject);
            setDeviceIdentifier(jsonObject.getString("device_identifier"));
            setSyncInterval(jsonObject.getInt("sync_interval"));
            this.save();
        } catch (JSONException je) {
            Log.e(TAG, "Error parsing object json", je);
        }  
    }

}

@@ -55,156 +55,32 @@
 ort 
-org.adaptlab.chpir.android.activerecordcloudsync.ReceiveModel;%0Aimport org.json.JSONException;%0Aimport org.json.JSONObject;%0A%0Aimport android.util.Log;%0A
+com.activeandroid.Model;
 %0Aimp
@@ -269,23 +269,16 @@
 extends 
-Receive
 Model %7B%0A
@@ -1697,444 +1697,6 @@
  %7D%0A%0A
-    %0A    @Override%0A    public void createObjectFromJSON(JSONObject jsonObject) %7B%0A        try %7B%0A            Log.i(TAG, %22Saving Admin Settings: %22 + jsonObject);%0A            setDeviceIdentifier(jsonObject.getString(%22device_identifier%22));%0A            setSyncInterval(jsonObject.getInt(%22sync_interval%22));%0A            this.save();%0A        %7D catch (JSONException je) %7B%0A            Log.e(TAG, %22Error parsing object json%22, je);%0A        %7D  %0A    %7D%0A%0A
 %7D%0A

Change adminsettings to regular model until its hammered out exactly how it should work