Commit f0a5c1e3 authored by Alexander Ivanov's avatar Alexander Ivanov

Fix line breaks.

parent f3f19141
......@@ -12,36 +12,36 @@
* You should have received a copy of the GNU General Public License,
* along with this program. If not, see http://www.gnu.org/licenses/.
*/
package com.xabber.android.data;
import android.database.sqlite.SQLiteDatabase;
/**
* Interface for registered database tables.
*
* @author alexander.ivanov
*
*/
public interface DatabaseTable {
/**
* Called on create database.
*
* @param db
*/
void create(SQLiteDatabase db);
/**
* Called on database migration.
*
* @param db
* @param toVersion
*/
void migrate(SQLiteDatabase db, int toVersion);
/**
* Called on clear database request.
*/
void clear();
}
package com.xabber.android.data;
import android.database.sqlite.SQLiteDatabase;
/**
* Interface for registered database tables.
*
* @author alexander.ivanov
*
*/
public interface DatabaseTable {
/**
* Called on create database.
*
* @param db
*/
void create(SQLiteDatabase db);
/**
* Called on database migration.
*
* @param db
* @param toVersion
*/
void migrate(SQLiteDatabase db, int toVersion);
/**
* Called on clear database request.
*/
void clear();
}
......@@ -12,21 +12,21 @@
* You should have received a copy of the GNU General Public License,
* along with this program. If not, see http://www.gnu.org/licenses/.
*/
package com.xabber.android.data;
/**
* Listener for database migration.
*
* @author alexander.ivanov
*
*/
public interface OnMigrationListener extends BaseManagerInterface {
/**
* Called on database migration for each intermediate versions.
*
* @param toVersion
*/
void onMigrate(int toVersion);
}
package com.xabber.android.data;
/**
* Listener for database migration.
*
* @author alexander.ivanov
*
*/
public interface OnMigrationListener extends BaseManagerInterface {
/**
* Called on database migration for each intermediate versions.
*
* @param toVersion
*/
void onMigrate(int toVersion);
}
......@@ -12,64 +12,64 @@
* You should have received a copy of the GNU General Public License,
* along with this program. If not, see http://www.gnu.org/licenses/.
*/
package com.xabber.android.data.account;
public class SavedStatus implements Comparable<SavedStatus> {
private final StatusMode statusMode;
private final String statusText;
public SavedStatus(StatusMode statusMode, String statusText) {
super();
this.statusMode = statusMode;
this.statusText = statusText;
}
public StatusMode getStatusMode() {
return statusMode;
}
public String getStatusText() {
return statusText;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result
+ ((statusMode == null) ? 0 : statusMode.hashCode());
result = prime * result
+ ((statusText == null) ? 0 : statusText.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
SavedStatus other = (SavedStatus) obj;
if (statusMode != other.statusMode)
return false;
if (statusText == null) {
if (other.statusText != null)
return false;
} else if (!statusText.equals(other.statusText))
return false;
return true;
}
@Override
public int compareTo(SavedStatus another) {
int result = statusMode.compareTo(another.statusMode);
if (result != 0)
return result;
return statusText.compareToIgnoreCase(another.statusText);
}
}
package com.xabber.android.data.account;
public class SavedStatus implements Comparable<SavedStatus> {
private final StatusMode statusMode;
private final String statusText;
public SavedStatus(StatusMode statusMode, String statusText) {
super();
this.statusMode = statusMode;
this.statusText = statusText;
}
public StatusMode getStatusMode() {
return statusMode;
}
public String getStatusText() {
return statusText;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result
+ ((statusMode == null) ? 0 : statusMode.hashCode());
result = prime * result
+ ((statusText == null) ? 0 : statusText.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
SavedStatus other = (SavedStatus) obj;
if (statusMode != other.statusMode)
return false;
if (statusText == null) {
if (other.statusText != null)
return false;
} else if (!statusText.equals(other.statusText))
return false;
return true;
}
@Override
public int compareTo(SavedStatus another) {
int result = statusMode.compareTo(another.statusMode);
if (result != 0)
return result;
return statusText.compareToIgnoreCase(another.statusText);
}
}
......@@ -12,25 +12,25 @@
* You should have received a copy of the GNU General Public License,
* along with this program. If not, see http://www.gnu.org/licenses/.
*/
package com.xabber.android.data.entity;
import android.database.Cursor;
/**
* Table with entity related information.
*
* @author alexander.ivanov
*/
public abstract class AbstractEntityTable extends AbstractAccountTable {
public static interface Fields extends AbstractAccountTable.Fields {
public static final String USER = "user";
}
public static String getUser(Cursor cursor) {
return cursor.getString(cursor.getColumnIndex(Fields.USER));
}
package com.xabber.android.data.entity;
import android.database.Cursor;
/**
* Table with entity related information.
*
* @author alexander.ivanov
*/
public abstract class AbstractEntityTable extends AbstractAccountTable {
public static interface Fields extends AbstractAccountTable.Fields {
public static final String USER = "user";
}
public static String getUser(Cursor cursor) {
return cursor.getString(cursor.getColumnIndex(Fields.USER));
}
}
\ No newline at end of file
/**
* Copyright (c) 2013, Redsolution LTD. All rights reserved.
*
* This file is part of Xabber project; you can redistribute it and/or
* modify it under the terms of the GNU General Public License, Version 3.
*
* Xabber is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License,
* along with this program. If not, see http://www.gnu.org/licenses/.
*/
package com.xabber.android.data.extension.avatar;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteStatement;
import android.provider.BaseColumns;
import com.xabber.android.data.AbstractTable;
import com.xabber.android.data.DatabaseManager;
/**
* Storage with avatar hashes for the users.
*
* @author alexander.ivanov
*/
class AvatarTable extends AbstractTable {
private static final class Fields implements BaseColumns {
private Fields() {
}
public static final String USER = "user";
public static final String HASH = "hash";
}
private static final String NAME = "avatars";
private static final String[] PROJECTION = new String[] { Fields.USER,
Fields.HASH, };
private final DatabaseManager databaseManager;
private SQLiteStatement writeStatement;
private final Object writeLock;
private final static AvatarTable instance;
static {
instance = new AvatarTable(DatabaseManager.getInstance());
DatabaseManager.getInstance().addTable(instance);
}
public static AvatarTable getInstance() {
return instance;
}
private AvatarTable(DatabaseManager databaseManager) {
this.databaseManager = databaseManager;
writeStatement = null;
writeLock = new Object();
}
@Override
public void create(SQLiteDatabase db) {
String sql = "CREATE TABLE " + NAME + " (" + Fields.USER
+ " TEXT PRIMARY KEY," + Fields.HASH + " TEXT);";
DatabaseManager.execSQL(db, sql);
}
@Override
public void migrate(SQLiteDatabase db, int toVersion) {
super.migrate(db, toVersion);
switch (toVersion) {
case 2:
String sql = "CREATE TABLE avatars (" + "user TEXT PRIMARY KEY,"
+ "hash TEXT);";
DatabaseManager.execSQL(db, sql);
break;
default:
break;
}
}
/**
* Saves avatar's hash for user.
*
* @param bareAddress
* @param hash
*/
void write(String bareAddress, String hash) {
synchronized (writeLock) {
if (writeStatement == null) {
SQLiteDatabase db = databaseManager.getWritableDatabase();
writeStatement = db.compileStatement("INSERT OR REPLACE INTO "
+ NAME + " (" + Fields.USER + ", " + Fields.HASH
+ ") VALUES (?, ?);");
}
writeStatement.bindString(1, bareAddress);
if (hash == null)
writeStatement.bindNull(2);
else
writeStatement.bindString(2, hash);
writeStatement.execute();
}
}
@Override
protected String getTableName() {
return NAME;
}
@Override
protected String[] getProjection() {
return PROJECTION;
}
static String getUser(Cursor cursor) {
return cursor.getString(cursor.getColumnIndex(Fields.USER));
}
static String getHash(Cursor cursor) {
return cursor.getString(cursor.getColumnIndex(Fields.HASH));
}
/**
* Copyright (c) 2013, Redsolution LTD. All rights reserved.
*
* This file is part of Xabber project; you can redistribute it and/or
* modify it under the terms of the GNU General Public License, Version 3.
*
* Xabber is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License,
* along with this program. If not, see http://www.gnu.org/licenses/.
*/
package com.xabber.android.data.extension.avatar;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteStatement;
import android.provider.BaseColumns;
import com.xabber.android.data.AbstractTable;
import com.xabber.android.data.DatabaseManager;
/**
* Storage with avatar hashes for the users.
*
* @author alexander.ivanov
*/
class AvatarTable extends AbstractTable {
private static final class Fields implements BaseColumns {
private Fields() {
}
public static final String USER = "user";
public static final String HASH = "hash";
}
private static final String NAME = "avatars";
private static final String[] PROJECTION = new String[] { Fields.USER,
Fields.HASH, };
private final DatabaseManager databaseManager;
private SQLiteStatement writeStatement;
private final Object writeLock;
private final static AvatarTable instance;
static {
instance = new AvatarTable(DatabaseManager.getInstance());
DatabaseManager.getInstance().addTable(instance);
}
public static AvatarTable getInstance() {
return instance;
}
private AvatarTable(DatabaseManager databaseManager) {
this.databaseManager = databaseManager;
writeStatement = null;
writeLock = new Object();
}
@Override
public void create(SQLiteDatabase db) {
String sql = "CREATE TABLE " + NAME + " (" + Fields.USER
+ " TEXT PRIMARY KEY," + Fields.HASH + " TEXT);";
DatabaseManager.execSQL(db, sql);
}
@Override
public void migrate(SQLiteDatabase db, int toVersion) {
super.migrate(db, toVersion);
switch (toVersion) {
case 2:
String sql = "CREATE TABLE avatars (" + "user TEXT PRIMARY KEY,"
+ "hash TEXT);";
DatabaseManager.execSQL(db, sql);
break;
default:
break;
}
}
/**
* Saves avatar's hash for user.
*
* @param bareAddress
* @param hash
*/
void write(String bareAddress, String hash) {
synchronized (writeLock) {
if (writeStatement == null) {
SQLiteDatabase db = databaseManager.getWritableDatabase();
writeStatement = db.compileStatement("INSERT OR REPLACE INTO "
+ NAME + " (" + Fields.USER + ", " + Fields.HASH
+ ") VALUES (?, ?);");
}
writeStatement.bindString(1, bareAddress);
if (hash == null)
writeStatement.bindNull(2);
else
writeStatement.bindString(2, hash);
writeStatement.execute();
}
}
@Override
protected String getTableName() {
return NAME;
}
@Override
protected String[] getProjection() {
return PROJECTION;
}
static String getUser(Cursor cursor) {
return cursor.getString(cursor.getColumnIndex(Fields.USER));
}
static String getHash(Cursor cursor) {
return cursor.getString(cursor.getColumnIndex(Fields.HASH));
}
}
\ No newline at end of file
......@@ -12,132 +12,132 @@
* You should have received a copy of the GNU General Public License,
* along with this program. If not, see http://www.gnu.org/licenses/.
*/
package com.xabber.android.data.extension.otr;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteStatement;
import com.xabber.android.data.DatabaseManager;
import com.xabber.android.data.entity.AbstractEntityTable;
/**
* Storage with OTR finger prints and trusted level.
*
* @author alexander.ivanov
*/
class OTRTable extends AbstractEntityTable {
private static final class Fields implements AbstractEntityTable.Fields {
private Fields() {
}
public static final String USER = "user";
public static final String FINGERPRINT = "fingerprint";
public static final String VERIFIED = "verified";
}
private static final String NAME = "otr";
private static final String[] PROJECTION = new String[] { Fields.ACCOUNT,
Fields.USER, Fields.FINGERPRINT, Fields.VERIFIED, };
private final DatabaseManager databaseManager;
private SQLiteStatement writeStatement;
private final Object writeLock;
private final static OTRTable instance;
static {
instance = new OTRTable(DatabaseManager.getInstance());
DatabaseManager.getInstance().addTable(instance);
}
public static OTRTable getInstance() {
return instance;
}
private OTRTable(DatabaseManager databaseManager) {
this.databaseManager = databaseManager;
writeStatement = null;
writeLock = new Object();
}
@Override
public void create(SQLiteDatabase db) {
String sql;
sql = "CREATE TABLE " + NAME + " (" + Fields.ACCOUNT + " TEXT,"
+ Fields.USER + " TEXT," + Fields.FINGERPRINT + " TEXT,"
+ Fields.VERIFIED + " INTEGER);";
DatabaseManager.execSQL(db, sql);
sql = "CREATE UNIQUE INDEX " + NAME + "_list ON " + NAME + " ("
+ Fields.ACCOUNT + ", " + Fields.USER + ", "
+ Fields.FINGERPRINT + ");";
DatabaseManager.execSQL(db, sql);
}
@Override
public void migrate(SQLiteDatabase db, int toVersion) {
super.migrate(db, toVersion);
String sql;
switch (toVersion) {
case 54:
sql = "CREATE TABLE otr (" + "account TEXT," + "user TEXT,"
+ "fingerprint TEXT," + "verified INTEGER);";
DatabaseManager.execSQL(db, sql);
sql = "CREATE UNIQUE INDEX otr_list ON otr (account, user);";
DatabaseManager.execSQL(db, sql);
break;
case 56:
sql = "DROP INDEX otr_list;";
DatabaseManager.execSQL(db, sql);
sql = "CREATE UNIQUE INDEX otr_list ON otr (account, user, fingerprint);";
DatabaseManager.execSQL(db, sql);
default:
break;
}
}
void write(String account, String user, String fingerprint, boolean verified) {
synchronized (writeLock) {
if (writeStatement == null) {
SQLiteDatabase db = databaseManager.getWritableDatabase();
writeStatement = db.compileStatement("INSERT OR REPLACE INTO "
+ NAME + " (" + Fields.ACCOUNT + ", " + Fields.USER
+ ", " + Fields.FINGERPRINT + ", " + Fields.VERIFIED
+ ") VALUES (?, ?, ?, ?);");
}
writeStatement.bindString(1, account);
writeStatement.bindString(2, user);
writeStatement.bindString(3, fingerprint);
writeStatement.bindLong(4, verified ? 1 : 0);
writeStatement.execute();
}
}
void remove(String account, String user) {
SQLiteDatabase db = databaseManager.getWritableDatabase();
db.delete(NAME, Fields.ACCOUNT + " = ? AND " + Fields.USER + " = ?",
new String[] { account, user });
}
@Override
protected String getTableName() {
return NAME;
}
@Override
protected String[] getProjection() {
return PROJECTION;
}
static String getFingerprint(Cursor cursor) {
return cursor.getString(cursor.getColumnIndex(Fields.FINGERPRINT));
}
static boolean isVerified(Cursor cursor) {
return cursor.getLong(cursor.getColumnIndex(Fields.VERIFIED)) != 0;
}
package com.xabber.android.data.extension.otr;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteStatement;
import com.xabber.android.data.DatabaseManager;
import com.xabber.android.data.entity.AbstractEntityTable;
/**
* Storage with OTR finger prints and trusted level.
*
* @author alexander.ivanov
*/
class OTRTable extends AbstractEntityTable {
private static final class Fields implements AbstractEntityTable.Fields {
private Fields() {
}
public static final String USER = "user";
public static final String FINGERPRINT = "fingerprint";
public static final String VERIFIED = "verified";
}
private static final String NAME = "otr";
private static final String[] PROJECTION = new String[] { Fields.ACCOUNT,
Fields.USER, Fields.FINGERPRINT, Fields.VERIFIED, };
private final DatabaseManager databaseManager;
private SQLiteStatement writeStatement;
private final Object writeLock;
private final static OTRTable instance;
static {
instance = new OTRTable(DatabaseManager.getInstance());
DatabaseManager.getInstance().addTable(instance);
}
public static OTRTable getInstance() {
return instance;
}
private OTRTable(DatabaseManager databaseManager) {
this.databaseManager = databaseManager;
writeStatement = null;
writeLock = new Object();
}
@Override
public void create(SQLiteDatabase db) {
String sql;
sql = "CREATE TABLE " + NAME + " (" + Fields.ACCOUNT + " TEXT,"
+ Fields.USER + " TEXT," + Fields.FINGERPRINT + " TEXT,"
+ Fields.VERIFIED + " INTEGER);";
DatabaseManager.execSQL(db, sql);
sql = "CREATE UNIQUE INDEX " + NAME + "_list ON " + NAME + " ("
+ Fields.ACCOUNT + ", " + Fields.USER + ", "
+ Fields.FINGERPRINT + ");";
DatabaseManager.execSQL(db, sql);
}
@Override
public void migrate(SQLiteDatabase db, int toVersion) {
super.migrate(db, toVersion);
String sql;
switch (toVersion) {
case 54:
sql = "CREATE TABLE otr (" + "account TEXT," + "user TEXT,"
+ "fingerprint TEXT," + "verified INTEGER);";
DatabaseManager.execSQL(db, sql);
sql = "CREATE UNIQUE INDEX otr_list ON otr (account, user);";
DatabaseManager.execSQL(db, sql);
break;
case 56:
sql = "DROP INDEX otr_list;";
DatabaseManager.execSQL(db, sql);
sql = "CREATE UNIQUE INDEX otr_list ON otr (account, user, fingerprint);";
DatabaseManager.execSQL(db, sql);
default:
break;
}
}
void write(String account, String user, String fingerprint, boolean verified) {
synchronized (writeLock) {
if (writeStatement == null) {
SQLiteDatabase db = databaseManager.getWritableDatabase();
writeStatement = db.compileStatement("INSERT OR REPLACE INTO "
+ NAME + " (" + Fields.ACCOUNT + ", " + Fields.USER
+ ", " + Fields.FINGERPRINT + ", " + Fields.VERIFIED
+ ") VALUES (?, ?, ?, ?);");
}
writeStatement.bindString(1, account);
writeStatement.bindString(2, user);
writeStatement.bindString(3, fingerprint);
writeStatement.bindLong(4, verified ? 1 : 0);
writeStatement.execute();
}
}
void remove(String account, String user) {
SQLiteDatabase db = databaseManager.getWritableDatabase();
db.delete(NAME, Fields.ACCOUNT + " = ? AND " + Fields.USER + " = ?",
new String[] { account, user });
}
@Override
protected String getTableName() {
return NAME;
}
@Override
protected String[] getProjection() {
return PROJECTION;
}
static String getFingerprint(Cursor cursor) {
return cursor.getString(cursor.getColumnIndex(Fields.FINGERPRINT));
}
static boolean isVerified(Cursor cursor) {
return cursor.getLong(cursor.getColumnIndex(Fields.VERIFIED)) != 0;
}
}
\ No newline at end of file
......@@ -12,172 +12,172 @@
* You should have received a copy of the GNU General Public License,
* along with this program. If not, see http://www.gnu.org/licenses/.
*/
package com.xabber.android.data.message.phrase;
import android.content.ContentValues;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.net.Uri;
import android.provider.BaseColumns;
import com.xabber.android.data.AbstractTable;
import com.xabber.android.data.DatabaseManager;
/**
* Storage with phrase notification settings.
*
* @author alexander.ivanov
*/
class PhraseTable extends AbstractTable {
private static final class Fields implements BaseColumns {
private Fields() {
}
/**
* Text pattern.
*/
public static final String VALUE = "value";
/**
* JID pattern.
*/
public static final String USER = "user";
/**
* Contact list group pattern.
*/
public static final String GROUP = "_group";
/**
* Whether text should be processed as regexp.
*/
public static final String REGEXP = "regexp";
/**
* Used sound.
*/
public static final String SOUND = "sound";
}
private static final String NAME = "phrase";
private static final String[] PROJECTION = new String[] { Fields._ID,
Fields.VALUE, Fields.USER, Fields.GROUP, Fields.REGEXP,
Fields.SOUND, };
private final DatabaseManager databaseManager;
private final static PhraseTable instance;
static {
instance = new PhraseTable(DatabaseManager.getInstance());
DatabaseManager.getInstance().addTable(instance);
}
public static PhraseTable getInstance() {
return instance;
}
private PhraseTable(DatabaseManager databaseManager) {
this.databaseManager = databaseManager;
}
@Override
public void create(SQLiteDatabase db) {
String sql;
sql = "CREATE TABLE " + NAME + " (" + Fields._ID
+ " INTEGER PRIMARY KEY," + Fields.VALUE + " TEXT,"
+ Fields.USER + " TEXT," + Fields.GROUP + " TEXT,"
+ Fields.REGEXP + " INTEGER," + Fields.SOUND + " TEXT);";
DatabaseManager.execSQL(db, sql);
}
@Override
public void migrate(SQLiteDatabase db, int toVersion) {
super.migrate(db, toVersion);
String sql;
switch (toVersion) {
case 63:
sql = "CREATE TABLE phrase (_id INTEGER PRIMARY KEY,"
+ "value TEXT," + "regexp INTEGER," + "sound TEXT);";
DatabaseManager.execSQL(db, sql);
break;
case 64:
sql = "ALTER TABLE phrase ADD COLUMN user TEXT;";
DatabaseManager.execSQL(db, sql);
sql = "UPDATE phrase SET user = \"\";";
DatabaseManager.execSQL(db, sql);
sql = "ALTER TABLE phrase ADD COLUMN _group TEXT;";
DatabaseManager.execSQL(db, sql);
sql = "UPDATE phrase SET _group = \"\";";
DatabaseManager.execSQL(db, sql);
break;
default:
break;
}
}
long write(Long id, String value, String user, String group,
boolean regexp, Uri sound) {
SQLiteDatabase db = databaseManager.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(Fields.VALUE, value);
values.put(Fields.USER, user);
values.put(Fields.GROUP, group);
values.put(Fields.REGEXP, regexp ? 1 : 0);
values.put(Fields.SOUND, sound.toString());
if (id == null)
return db.insert(NAME, Fields.VALUE, values);
db.update(NAME, values, Fields._ID + " = ?",
new String[] { String.valueOf(id) });
return id;
}
void remove(long id) {
SQLiteDatabase db = databaseManager.getWritableDatabase();
db.delete(NAME, Fields._ID + " = ?",
new String[] { String.valueOf(id) });
}
@Override
protected String getTableName() {
return NAME;
}
@Override
protected String[] getProjection() {
return PROJECTION;
}
@Override
protected String getListOrder() {
return Fields._ID;
}
static long getId(Cursor cursor) {
return cursor.getLong(cursor.getColumnIndex(Fields._ID));
}
static String getValue(Cursor cursor) {
return cursor.getString(cursor.getColumnIndex(Fields.VALUE));
}
static String getUser(Cursor cursor) {
return cursor.getString(cursor.getColumnIndex(Fields.USER));
}
static String getGroup(Cursor cursor) {
return cursor.getString(cursor.getColumnIndex(Fields.GROUP));
}
static boolean isRegexp(Cursor cursor) {
return cursor.getLong(cursor.getColumnIndex(Fields.REGEXP)) != 0;
}
static Uri getSound(Cursor cursor) {
return Uri.parse(cursor.getString(cursor.getColumnIndex(Fields.SOUND)));
}
package com.xabber.android.data.message.phrase;
import android.content.ContentValues;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.net.Uri;
import android.provider.BaseColumns;
import com.xabber.android.data.AbstractTable;
import com.xabber.android.data.DatabaseManager;
/**
* Storage with phrase notification settings.
*
* @author alexander.ivanov
*/
class PhraseTable extends AbstractTable {
private static final class Fields implements BaseColumns {
private Fields() {
}
/**
* Text pattern.
*/
public static final String VALUE = "value";
/**
* JID pattern.
*/
public static final String USER = "user";
/**
* Contact list group pattern.
*/
public static final String GROUP = "_group";
/**
* Whether text should be processed as regexp.
*/
public static final String REGEXP = "regexp";
/**
* Used sound.
*/
public static final String SOUND = "sound";
}
private static final String NAME = "phrase";
private static final String[] PROJECTION = new String[] { Fields._ID,
Fields.VALUE, Fields.USER, Fields.GROUP, Fields.REGEXP,
Fields.SOUND, };
private final DatabaseManager databaseManager;
private final static PhraseTable instance;
static {
instance = new PhraseTable(DatabaseManager.getInstance());
DatabaseManager.getInstance().addTable(instance);
}
public static PhraseTable getInstance() {
return instance;
}
private PhraseTable(DatabaseManager databaseManager) {
this.databaseManager = databaseManager;
}
@Override
public void create(SQLiteDatabase db) {
String sql;
sql = "CREATE TABLE " + NAME + " (" + Fields._ID
+ " INTEGER PRIMARY KEY," + Fields.VALUE + " TEXT,"
+ Fields.USER + " TEXT," + Fields.GROUP + " TEXT,"
+ Fields.REGEXP + " INTEGER," + Fields.SOUND + " TEXT);";
DatabaseManager.execSQL(db, sql);
}
@Override
public void migrate(SQLiteDatabase db, int toVersion) {
super.migrate(db, toVersion);
String sql;
switch (toVersion) {
case 63:
sql = "CREATE TABLE phrase (_id INTEGER PRIMARY KEY,"
+ "value TEXT," + "regexp INTEGER," + "sound TEXT);";
DatabaseManager.execSQL(db, sql);
break;
case 64:
sql = "ALTER TABLE phrase ADD COLUMN user TEXT;";
DatabaseManager.execSQL(db, sql);
sql = "UPDATE phrase SET user = \"\";";
DatabaseManager.execSQL(db, sql);
sql = "ALTER TABLE phrase ADD COLUMN _group TEXT;";
DatabaseManager.execSQL(db, sql);
sql = "UPDATE phrase SET _group = \"\";";
DatabaseManager.execSQL(db, sql);
break;
default:
break;
}
}
long write(Long id, String value, String user, String group,
boolean regexp, Uri sound) {
SQLiteDatabase db = databaseManager.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(Fields.VALUE, value);
values.put(Fields.USER, user);
values.put(Fields.GROUP, group);
values.put(Fields.REGEXP, regexp ? 1 : 0);
values.put(Fields.SOUND, sound.toString());
if (id == null)
return db.insert(NAME, Fields.VALUE, values);
db.update(NAME, values, Fields._ID + " = ?",
new String[] { String.valueOf(id) });
return id;
}
void remove(long id) {
SQLiteDatabase db = databaseManager.getWritableDatabase();
db.delete(NAME, Fields._ID + " = ?",
new String[] { String.valueOf(id) });
}
@Override
protected String getTableName() {
return NAME;
}
@Override
protected String[] getProjection() {
return PROJECTION;
}
@Override
protected String getListOrder() {
return Fields._ID;
}
static long getId(Cursor cursor) {
return cursor.getLong(cursor.getColumnIndex(Fields._ID));
}
static String getValue(Cursor cursor) {
return cursor.getString(cursor.getColumnIndex(Fields.VALUE));
}
static String getUser(Cursor cursor) {
return cursor.getString(cursor.getColumnIndex(Fields.USER));
}
static String getGroup(Cursor cursor) {
return cursor.getString(cursor.getColumnIndex(Fields.GROUP));
}
static boolean isRegexp(Cursor cursor) {
return cursor.getLong(cursor.getColumnIndex(Fields.REGEXP)) != 0;
}
static Uri getSound(Cursor cursor) {
return Uri.parse(cursor.getString(cursor.getColumnIndex(Fields.SOUND)));
}
}
\ No newline at end of file
/**
* Copyright (c) 2013, Redsolution LTD. All rights reserved.
*
* This file is part of Xabber project; you can redistribute it and/or
* modify it under the terms of the GNU General Public License, Version 3.
*
* Xabber is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License,
* along with this program. If not, see http://www.gnu.org/licenses/.
*/
package com.xabber.android.data.notification;
import java.util.Date;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteStatement;
import com.xabber.android.data.DatabaseManager;
import com.xabber.android.data.entity.AbstractEntityTable;
/**
* Storage with notifications.
*
* @author alexander.ivanov
*/
class NotificationTable extends AbstractEntityTable {
private static final class Fields implements AbstractEntityTable.Fields {
private Fields() {
}
/**
* Text message.
*/
public static final String TEXT = "text";
/**
* Time when last message was received.
*/
public static final String TIMESTAMP = "timestamp";
/**
* Count of not notified messages.
*/
public static final String COUNT = "count";
}
private static final String NAME = "notifications";
private static final String[] PROJECTION = new String[] { Fields.ACCOUNT,
Fields.USER, Fields.TEXT, Fields.TIMESTAMP, Fields.COUNT };
private final DatabaseManager databaseManager;
private SQLiteStatement writeStatement;
private final Object writeLock;
private final static NotificationTable instance;
static {
instance = new NotificationTable(DatabaseManager.getInstance());
DatabaseManager.getInstance().addTable(instance);
}
public static NotificationTable getInstance() {
return instance;
}
private NotificationTable(DatabaseManager databaseManager) {
this.databaseManager = databaseManager;
writeStatement = null;
writeLock = new Object();
}
@Override
public void create(SQLiteDatabase db) {
String sql;
sql = "CREATE TABLE " + NAME + " (" + Fields.ACCOUNT + " TEXT,"
+ Fields.USER + " TEXT," + Fields.TEXT + " TEXT,"
+ Fields.TIMESTAMP + " INTEGER," + Fields.COUNT + " INTEGER);";
DatabaseManager.execSQL(db, sql);
sql = "CREATE UNIQUE INDEX " + NAME + "_list ON " + NAME + " ("
+ Fields.ACCOUNT + ", " + Fields.USER + " )";
DatabaseManager.execSQL(db, sql);
}
@Override
public void migrate(SQLiteDatabase db, int toVersion) {
super.migrate(db, toVersion);
String sql;
switch (toVersion) {
case 60:
sql = "CREATE TABLE notifications (" + "account TEXT,"
+ "user TEXT," + "text TEXT," + "timestamp INTEGER,"
+ "count INTEGER);";
DatabaseManager.execSQL(db, sql);
sql = "CREATE UNIQUE INDEX notifications_list ON notifications (account, user);";
DatabaseManager.execSQL(db, sql);
break;
default:
break;
}
}
void write(String account, String user, String text, Date timeStamp,
int count) {
synchronized (writeLock) {
if (writeStatement == null) {
SQLiteDatabase db = databaseManager.getWritableDatabase();
writeStatement = db.compileStatement("INSERT OR REPLACE INTO "
+ NAME + " (" + Fields.ACCOUNT + ", " + Fields.USER
+ ", " + Fields.TEXT + ", " + Fields.TIMESTAMP + ", "
+ Fields.COUNT + ") VALUES " + "(?, ?, ?, ?, ?);");
}
writeStatement.bindString(1, account);
writeStatement.bindString(2, user);
writeStatement.bindString(3, text);
writeStatement.bindLong(4, timeStamp.getTime());
writeStatement.bindLong(5, count);
writeStatement.execute();
}
}
public void remove(String account, String user) {
SQLiteDatabase db = databaseManager.getWritableDatabase();
db.delete(NAME, Fields.ACCOUNT + " = ? AND " + Fields.USER + " = ?",
new String[] { account, user });
}
@Override
protected String getTableName() {
return NAME;
}
@Override
protected String[] getProjection() {
return PROJECTION;
}
@Override
protected String getListOrder() {
return Fields.TIMESTAMP;
}
static String getText(Cursor cursor) {
return cursor.getString(cursor.getColumnIndex(Fields.TEXT));
}
static Date getTimeStamp(Cursor cursor) {
return new Date(cursor.getLong(cursor.getColumnIndex(Fields.TIMESTAMP)));
}
static int getCount(Cursor cursor) {
return cursor.getInt(cursor.getColumnIndex(Fields.COUNT));
}
/**
* Copyright (c) 2013, Redsolution LTD. All rights reserved.
*
* This file is part of Xabber project; you can redistribute it and/or
* modify it under the terms of the GNU General Public License, Version 3.
*
* Xabber is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License,
* along with this program. If not, see http://www.gnu.org/licenses/.
*/
package com.xabber.android.data.notification;
import java.util.Date;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteStatement;
import com.xabber.android.data.DatabaseManager;
import com.xabber.android.data.entity.AbstractEntityTable;
/**
* Storage with notifications.
*
* @author alexander.ivanov
*/
class NotificationTable extends AbstractEntityTable {
private static final class Fields implements AbstractEntityTable.Fields {
private Fields() {
}
/**
* Text message.
*/
public static final String TEXT = "text";
/**
* Time when last message was received.
*/
public static final String TIMESTAMP = "timestamp";
/**
* Count of not notified messages.
*/
public static final String COUNT = "count";
}
private static final String NAME = "notifications";
private static final String[] PROJECTION = new String[] { Fields.ACCOUNT,
Fields.USER, Fields.TEXT, Fields.TIMESTAMP, Fields.COUNT };
private final DatabaseManager databaseManager;
private SQLiteStatement writeStatement;
private final Object writeLock;
private final static NotificationTable instance;
static {
instance = new NotificationTable(DatabaseManager.getInstance());
DatabaseManager.getInstance().addTable(instance);
}
public static NotificationTable getInstance() {
return instance;
}
private NotificationTable(DatabaseManager databaseManager) {
this.databaseManager = databaseManager;
writeStatement = null;
writeLock = new Object();
}
@Override
public void create(SQLiteDatabase db) {
String sql;
sql = "CREATE TABLE " + NAME + " (" + Fields.ACCOUNT + " TEXT,"
+ Fields.USER + " TEXT," + Fields.TEXT + " TEXT,"
+ Fields.TIMESTAMP + " INTEGER," + Fields.COUNT + " INTEGER);";
DatabaseManager.execSQL(db, sql);
sql = "CREATE UNIQUE INDEX " + NAME + "_list ON " + NAME + " ("
+ Fields.ACCOUNT + ", " + Fields.USER + " )";
DatabaseManager.execSQL(db, sql);
}
@Override
public void migrate(SQLiteDatabase db, int toVersion) {
super.migrate(db, toVersion);
String sql;
switch (toVersion) {
case 60:
sql = "CREATE TABLE notifications (" + "account TEXT,"
+ "user TEXT," + "text TEXT," + "timestamp INTEGER,"
+ "count INTEGER);";
DatabaseManager.execSQL(db, sql);
sql = "CREATE UNIQUE INDEX notifications_list ON notifications (account, user);";
DatabaseManager.execSQL(db, sql);
break;
default:
break;
}
}
void write(String account, String user, String text, Date timeStamp,
int count) {
synchronized (writeLock) {
if (writeStatement == null) {
SQLiteDatabase db = databaseManager.getWritableDatabase();
writeStatement = db.compileStatement("INSERT OR REPLACE INTO "
+ NAME + " (" + Fields.ACCOUNT + ", " + Fields.USER
+ ", " + Fields.TEXT + ", " + Fields.TIMESTAMP + ", "
+ Fields.COUNT + ") VALUES " + "(?, ?, ?, ?, ?);");
}
writeStatement.bindString(1, account);
writeStatement.bindString(2, user);
writeStatement.bindString(3, text);
writeStatement.bindLong(4, timeStamp.getTime());
writeStatement.bindLong(5, count);
writeStatement.execute();
}
}
public void remove(String account, String user) {
SQLiteDatabase db = databaseManager.getWritableDatabase();
db.delete(NAME, Fields.ACCOUNT + " = ? AND " + Fields.USER + " = ?",
new String[] { account, user });
}
@Override
protected String getTableName() {
return NAME;
}
@Override
protected String[] getProjection() {
return PROJECTION;
}
@Override
protected String getListOrder() {
return Fields.TIMESTAMP;
}
static String getText(Cursor cursor) {
return cursor.getString(cursor.getColumnIndex(Fields.TEXT));
}
static Date getTimeStamp(Cursor cursor) {
return new Date(cursor.getLong(cursor.getColumnIndex(Fields.TIMESTAMP)));
}
static int getCount(Cursor cursor) {
return cursor.getInt(cursor.getColumnIndex(Fields.COUNT));
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment