code clean up
This commit is contained in:
parent
9ae0475413
commit
82efb6f1db
|
@ -125,31 +125,31 @@ public class Account extends AbstractEntity implements AvatarService.Avatarable
|
||||||
public static Account fromCursor(final Cursor cursor) {
|
public static Account fromCursor(final Cursor cursor) {
|
||||||
final Jid jid;
|
final Jid jid;
|
||||||
try {
|
try {
|
||||||
String resource = cursor.getString(cursor.getColumnIndex(RESOURCE));
|
String resource = cursor.getString(cursor.getColumnIndexOrThrow(RESOURCE));
|
||||||
jid = Jid.of(
|
jid = Jid.of(
|
||||||
cursor.getString(cursor.getColumnIndex(USERNAME)),
|
cursor.getString(cursor.getColumnIndexOrThrow(USERNAME)),
|
||||||
cursor.getString(cursor.getColumnIndex(SERVER)),
|
cursor.getString(cursor.getColumnIndexOrThrow(SERVER)),
|
||||||
resource == null || resource.trim().isEmpty() ? null : resource);
|
resource == null || resource.trim().isEmpty() ? null : resource);
|
||||||
} catch (final IllegalArgumentException ignored) {
|
} catch (final IllegalArgumentException ignored) {
|
||||||
Log.d(Config.LOGTAG, cursor.getString(cursor.getColumnIndex(USERNAME)) + "@" + cursor.getString(cursor.getColumnIndex(SERVER)));
|
Log.d(Config.LOGTAG, cursor.getString(cursor.getColumnIndexOrThrow(USERNAME)) + "@" + cursor.getString(cursor.getColumnIndexOrThrow(SERVER)));
|
||||||
throw new AssertionError(ignored);
|
throw new AssertionError(ignored);
|
||||||
}
|
}
|
||||||
return new Account(cursor.getString(cursor.getColumnIndex(UUID)),
|
return new Account(cursor.getString(cursor.getColumnIndexOrThrow(UUID)),
|
||||||
jid,
|
jid,
|
||||||
cursor.getString(cursor.getColumnIndex(PASSWORD)),
|
cursor.getString(cursor.getColumnIndexOrThrow(PASSWORD)),
|
||||||
cursor.getInt(cursor.getColumnIndex(OPTIONS)),
|
cursor.getInt(cursor.getColumnIndexOrThrow(OPTIONS)),
|
||||||
cursor.getString(cursor.getColumnIndex(ROSTERVERSION)),
|
cursor.getString(cursor.getColumnIndexOrThrow(ROSTERVERSION)),
|
||||||
cursor.getString(cursor.getColumnIndex(KEYS)),
|
cursor.getString(cursor.getColumnIndexOrThrow(KEYS)),
|
||||||
cursor.getString(cursor.getColumnIndex(AVATAR)),
|
cursor.getString(cursor.getColumnIndexOrThrow(AVATAR)),
|
||||||
cursor.getString(cursor.getColumnIndex(DISPLAY_NAME)),
|
cursor.getString(cursor.getColumnIndexOrThrow(DISPLAY_NAME)),
|
||||||
cursor.getString(cursor.getColumnIndex(HOSTNAME)),
|
cursor.getString(cursor.getColumnIndexOrThrow(HOSTNAME)),
|
||||||
cursor.getInt(cursor.getColumnIndex(PORT)),
|
cursor.getInt(cursor.getColumnIndexOrThrow(PORT)),
|
||||||
Presence.Status.fromShowString(cursor.getString(cursor.getColumnIndex(STATUS))),
|
Presence.Status.fromShowString(cursor.getString(cursor.getColumnIndexOrThrow(STATUS))),
|
||||||
cursor.getString(cursor.getColumnIndex(STATUS_MESSAGE)));
|
cursor.getString(cursor.getColumnIndexOrThrow(STATUS_MESSAGE)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean httpUploadAvailable(long filesize) {
|
public boolean httpUploadAvailable(long size) {
|
||||||
return xmppConnection != null && xmppConnection.getFeatures().httpUpload(filesize);
|
return xmppConnection != null && xmppConnection.getFeatures().httpUpload(size);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean httpUploadAvailable() {
|
public boolean httpUploadAvailable() {
|
||||||
|
|
|
@ -967,33 +967,28 @@ public class DatabaseBackend extends SQLiteOpenHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Jid> getAccountJids(final boolean enabledOnly) {
|
public List<Jid> getAccountJids(final boolean enabledOnly) {
|
||||||
SQLiteDatabase db = this.getReadableDatabase();
|
final SQLiteDatabase db = this.getReadableDatabase();
|
||||||
final List<Jid> jids = new ArrayList<>();
|
final List<Jid> jids = new ArrayList<>();
|
||||||
final String[] columns = new String[]{Account.USERNAME, Account.SERVER};
|
final String[] columns = new String[]{Account.USERNAME, Account.SERVER};
|
||||||
String where = enabledOnly ? "not options & (1 <<1)" : null;
|
final String where = enabledOnly ? "not options & (1 <<1)" : null;
|
||||||
Cursor cursor = db.query(Account.TABLENAME, columns, where, null, null, null, null);
|
try (final Cursor cursor = db.query(Account.TABLENAME, columns, where, null, null, null, null)) {
|
||||||
try {
|
while (cursor != null && cursor.moveToNext()) {
|
||||||
while (cursor.moveToNext()) {
|
|
||||||
jids.add(Jid.of(cursor.getString(0), cursor.getString(1), null));
|
jids.add(Jid.of(cursor.getString(0), cursor.getString(1), null));
|
||||||
}
|
}
|
||||||
|
} catch (final Exception e) {
|
||||||
return jids;
|
return jids;
|
||||||
} catch (Exception e) {
|
}
|
||||||
return jids;
|
return jids;
|
||||||
} finally {
|
|
||||||
if (cursor != null) {
|
|
||||||
cursor.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<Account> getAccounts(SQLiteDatabase db) {
|
private List<Account> getAccounts(SQLiteDatabase db) {
|
||||||
List<Account> list = new ArrayList<>();
|
final List<Account> list = new ArrayList<>();
|
||||||
Cursor cursor = db.query(Account.TABLENAME, null, null, null, null,
|
try (final Cursor cursor =
|
||||||
null, null);
|
db.query(Account.TABLENAME, null, null, null, null, null, null)) {
|
||||||
while (cursor.moveToNext()) {
|
while (cursor != null && cursor.moveToNext()) {
|
||||||
list.add(Account.fromCursor(cursor));
|
list.add(Account.fromCursor(cursor));
|
||||||
}
|
}
|
||||||
cursor.close();
|
}
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -87,19 +87,19 @@ public class MessageAdapter extends ArrayAdapter<Message> {
|
||||||
private OnContactPictureClicked mOnContactPictureClickedListener;
|
private OnContactPictureClicked mOnContactPictureClickedListener;
|
||||||
private OnContactPictureLongClicked mOnContactPictureLongClickedListener;
|
private OnContactPictureLongClicked mOnContactPictureLongClickedListener;
|
||||||
private boolean mUseGreenBackground = false;
|
private boolean mUseGreenBackground = false;
|
||||||
private boolean mForceNames = false;
|
private final boolean mForceNames;
|
||||||
|
|
||||||
public MessageAdapter(XmppActivity activity, List<Message> messages) {
|
public MessageAdapter(final XmppActivity activity, final List<Message> messages, final boolean forceNames) {
|
||||||
super(activity, 0, messages);
|
super(activity, 0, messages);
|
||||||
this.audioPlayer = new AudioPlayer(this);
|
this.audioPlayer = new AudioPlayer(this);
|
||||||
this.activity = activity;
|
this.activity = activity;
|
||||||
metrics = getContext().getResources().getDisplayMetrics();
|
metrics = getContext().getResources().getDisplayMetrics();
|
||||||
updatePreferences();
|
updatePreferences();
|
||||||
|
this.mForceNames = forceNames;
|
||||||
}
|
}
|
||||||
|
|
||||||
public MessageAdapter(XmppActivity activity, List<Message> messages, boolean forceNames) {
|
public MessageAdapter(final XmppActivity activity, final List<Message> messages) {
|
||||||
this(activity, messages);
|
this(activity, messages, false);
|
||||||
mForceNames = forceNames;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void resetClickListener(View... views) {
|
private static void resetClickListener(View... views) {
|
||||||
|
|
Loading…
Reference in a new issue