Search in sources :

Example 6 with PersistSettings

use of com.vodafone360.people.service.PersistSettings in project 360-Engine-for-Android by 360.

the class StateTable method fetchOption.

/**
     * Fetches an option from the settings table.
     *
     * @param option Specifies which option is required
     * @param readableDb Readable SQLite database for fetching the information
     * @return A PersistSettings object containing the option data if
     *         successful, null otherwise.
     */
public static PersistSettings fetchOption(final PersistSettings.Option option, final SQLiteDatabase readableDb) {
    if (Settings.ENABLED_DATABASE_TRACE) {
        DatabaseHelper.trace(false, "StateTable.fetchOption() name[" + option.tableFieldName() + "] value[" + option.defaultValue() + "] type[" + option.getType() + "]");
    }
    Cursor c = null;
    try {
        c = readableDb.rawQuery("SELECT " + option.tableFieldName() + " FROM " + TABLE_NAME + " WHERE " + Field.STATEID + " = " + PRIMARY_STATE_KEY_VALUE, null);
        if (!c.moveToFirst()) {
            LogUtils.logE("StateTable.fetchOption() Unable to find option " + "in the database, option[" + option + "]");
            return null;
        }
        final PersistSettings setting = new PersistSettings();
        Object data = null;
        if (!c.isNull(0)) {
            data = PersistSettings.fetchValueFromCursor(c, 0, c.getColumnName(0));
        }
        setting.putOptionData(option, data);
        LogUtils.logD("StateTable.fetchOption() Fetched option[" + option + "]");
        return setting;
    } catch (Exception e) {
        LogUtils.logE("StateTable.fetchOption() Exception - Unable to " + "fetch options from database", e);
        return null;
    } finally {
        CloseUtils.close(c);
        c = null;
    }
}
Also used : PersistSettings(com.vodafone360.people.service.PersistSettings) Cursor(android.database.Cursor) SQLException(android.database.SQLException) SQLiteException(android.database.sqlite.SQLiteException)

Example 7 with PersistSettings

use of com.vodafone360.people.service.PersistSettings in project 360-Engine-for-Android by 360.

the class StateTable method create.

/**
     * Create Settings Table and add a record with default setting values.
     *
     * @param writableDb A writable SQLite database.
     */
public static void create(final SQLiteDatabase writableDb) {
    DatabaseHelper.trace(true, "StateTable.create()");
    String createSql = "CREATE TABLE " + TABLE_NAME + " (" + Field.STATEID + " INTEGER PRIMARY KEY, " + Field.USERNAME + " TEXT, " + Field.PASSWORD + " BINARY, " + Field.MOBILENO + " TEXT, " + Field.SUBSCIBERID + " TEXT, " + Field.REMEMBERME + " BOOLEAN, " + Field.AUTOCONNECT + " BOOLEAN, " + Field.REGISTRATIONCOMPLETE + " BOOLEAN," + Field.SESSIONID + " TEXT," + Field.SESSIONSECRET + " TEXT," + Field.SESSIONUSERID + " LONG," + Field.SESSIONUSERNAME + " TEXT," + Field.CONTACTSREVISION + " LONG," + Field.MYCONTACTID + " LONG," + /** AA added fields to store the public key. **/
    Field.PUBLICKEYEXPONENTIAL + " BINARY," + Field.PUBLICKEYMODULO + " BINARY," + Field.PUBLICKEYBASE64 + " TEXT," + Field.PUBLICKEYX509 + " BINARY," + /** End added fields to store the public key. **/
    Field.MYCONTACTCHANGED + " BOOLEAN," + Field.MYCONTACTPICTURECHANGED + " BOOLEAN," + Field.NATIVEDBCHANGED + " BOOLEAN," + Field.LASTSTATUSUPDATE + " LONG," + Field.OLDESTSTATUSUPDATE + " LONG," + Field.LASTPHONECALLUPDATE + " LONG," + Field.OLDESTPHONECALL + " LONG," + Field.LASTSMSUPDATE + " LONG," + Field.OLDESTSMS + " LONG," + Field.LASTMMSUPDATE + " LONG," + Field.OLDESTMMS + " LONG," + Field.MEPROFILEREVISION + " LONG," + Field.MEPROFILEAVATARCHANGED + " BOOLEAN,";
    // Add additional settings from the PersistSettings object
    for (PersistSettings.Option option : PersistSettings.Option.values()) {
        createSql += option.tableFieldName() + " " + option.getType().getDbType() + ",";
    }
    createSql = createSql.substring(0, createSql.length() - 1);
    createSql += ");";
    writableDb.execSQL(createSql);
    /*
         * Insert a setting record with default values into the table
         */
    final ContentValues values = new ContentValues();
    values.put(Field.STATEID.toString(), PRIMARY_STATE_KEY_VALUE);
    final PersistSettings setting = new PersistSettings();
    for (PersistSettings.Option option : PersistSettings.Option.values()) {
        setting.putDefaultOptionData(option);
        PersistSettings.addToContentValues(values, setting);
    }
    writableDb.insertOrThrow(TABLE_NAME, null, values);
}
Also used : ContentValues(android.content.ContentValues) PersistSettings(com.vodafone360.people.service.PersistSettings)

Example 8 with PersistSettings

use of com.vodafone360.people.service.PersistSettings in project 360-Engine-for-Android by 360.

the class SyncMeEngine method setFirstTimeSyncStarted.

/**
     * Helper function to update the database when the state of the
     * {@link #mFirstTimeMeSyncStarted} flag changes.
     * @param value New value to the flag. True indicates that first time sync
     *            has been started. The flag is never set to false again by the
     *            engine, it will be only set to false when a remove user data
     *            is done (and the database is deleted).
     * @return SUCCESS or a suitable error code if the database could not be
     *         updated.
     */
private ServiceStatus setFirstTimeSyncStarted(final boolean value) {
    if (mFirstTimeSyncStarted == value) {
        return ServiceStatus.SUCCESS;
    }
    PersistSettings setting = new PersistSettings();
    setting.putFirstTimeMeSyncStarted(value);
    ServiceStatus status = mDbHelper.setOption(setting);
    if (ServiceStatus.SUCCESS == status) {
        synchronized (this) {
            mFirstTimeSyncStarted = value;
        }
    }
    return status;
}
Also used : PersistSettings(com.vodafone360.people.service.PersistSettings) ServiceStatus(com.vodafone360.people.service.ServiceStatus)

Example 9 with PersistSettings

use of com.vodafone360.people.service.PersistSettings in project 360-Engine-for-Android by 360.

the class SyncMeEngine method onCreate.

@Override
public void onCreate() {
    PersistSettings setting = mDbHelper.fetchOption(PersistSettings.Option.FIRST_TIME_MESYNC_STARTED);
    if (setting != null) {
        mFirstTimeSyncStarted = setting.getFirstTimeMeSyncStarted();
    }
    setting = mDbHelper.fetchOption(PersistSettings.Option.FIRST_TIME_MESYNC_COMPLETE);
    if (setting != null) {
        mFirstTimeMeSyncComplete = setting.getFirstTimeMeSyncComplete();
    }
}
Also used : PersistSettings(com.vodafone360.people.service.PersistSettings)

Example 10 with PersistSettings

use of com.vodafone360.people.service.PersistSettings in project 360-Engine-for-Android by 360.

the class SyncMeEngine method setFirstTimeMeSyncComplete.

/**
     * Helper function to update the database when the state of the
     * {@link #mFirstTimeMeSyncComplete} flag changes.
     * @param value New value to the flag. True indicates that first time sync
     *            has been completed. The flag is never set to false again by
     *            the engine, it will be only set to false when a remove user
     *            data is done (and the database is deleted).
     * @return SUCCESS or a suitable error code if the database could not be
     *         updated.
     */
private ServiceStatus setFirstTimeMeSyncComplete(final boolean value) {
    if (mFirstTimeMeSyncComplete == value) {
        return ServiceStatus.SUCCESS;
    }
    PersistSettings setting = new PersistSettings();
    setting.putFirstTimeMeSyncComplete(value);
    ServiceStatus status = mDbHelper.setOption(setting);
    if (ServiceStatus.SUCCESS == status) {
        synchronized (this) {
            mFirstTimeMeSyncComplete = value;
        }
    }
    return status;
}
Also used : PersistSettings(com.vodafone360.people.service.PersistSettings) ServiceStatus(com.vodafone360.people.service.ServiceStatus)

Aggregations

PersistSettings (com.vodafone360.people.service.PersistSettings)13 ServiceStatus (com.vodafone360.people.service.ServiceStatus)9 ContentValues (android.content.ContentValues)1 Cursor (android.database.Cursor)1 SQLException (android.database.SQLException)1 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)1 SQLiteException (android.database.sqlite.SQLiteException)1