code clean up

This commit is contained in:
Daniel Gultsch 2022-09-14 17:51:22 +02:00
parent 9ae0475413
commit 82efb6f1db
3 changed files with 34 additions and 39 deletions

View file

@ -125,31 +125,31 @@ public class Account extends AbstractEntity implements AvatarService.Avatarable
public static Account fromCursor(final Cursor cursor) {
final Jid jid;
try {
String resource = cursor.getString(cursor.getColumnIndex(RESOURCE));
String resource = cursor.getString(cursor.getColumnIndexOrThrow(RESOURCE));
jid = Jid.of(
cursor.getString(cursor.getColumnIndex(USERNAME)),
cursor.getString(cursor.getColumnIndex(SERVER)),
cursor.getString(cursor.getColumnIndexOrThrow(USERNAME)),
cursor.getString(cursor.getColumnIndexOrThrow(SERVER)),
resource == null || resource.trim().isEmpty() ? null : resource);
} 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);
}
return new Account(cursor.getString(cursor.getColumnIndex(UUID)),
return new Account(cursor.getString(cursor.getColumnIndexOrThrow(UUID)),
jid,
cursor.getString(cursor.getColumnIndex(PASSWORD)),
cursor.getInt(cursor.getColumnIndex(OPTIONS)),
cursor.getString(cursor.getColumnIndex(ROSTERVERSION)),
cursor.getString(cursor.getColumnIndex(KEYS)),
cursor.getString(cursor.getColumnIndex(AVATAR)),
cursor.getString(cursor.getColumnIndex(DISPLAY_NAME)),
cursor.getString(cursor.getColumnIndex(HOSTNAME)),
cursor.getInt(cursor.getColumnIndex(PORT)),
Presence.Status.fromShowString(cursor.getString(cursor.getColumnIndex(STATUS))),
cursor.getString(cursor.getColumnIndex(STATUS_MESSAGE)));
cursor.getString(cursor.getColumnIndexOrThrow(PASSWORD)),
cursor.getInt(cursor.getColumnIndexOrThrow(OPTIONS)),
cursor.getString(cursor.getColumnIndexOrThrow(ROSTERVERSION)),
cursor.getString(cursor.getColumnIndexOrThrow(KEYS)),
cursor.getString(cursor.getColumnIndexOrThrow(AVATAR)),
cursor.getString(cursor.getColumnIndexOrThrow(DISPLAY_NAME)),
cursor.getString(cursor.getColumnIndexOrThrow(HOSTNAME)),
cursor.getInt(cursor.getColumnIndexOrThrow(PORT)),
Presence.Status.fromShowString(cursor.getString(cursor.getColumnIndexOrThrow(STATUS))),
cursor.getString(cursor.getColumnIndexOrThrow(STATUS_MESSAGE)));
}
public boolean httpUploadAvailable(long filesize) {
return xmppConnection != null && xmppConnection.getFeatures().httpUpload(filesize);
public boolean httpUploadAvailable(long size) {
return xmppConnection != null && xmppConnection.getFeatures().httpUpload(size);
}
public boolean httpUploadAvailable() {

View file

@ -967,33 +967,28 @@ public class DatabaseBackend extends SQLiteOpenHelper {
}
public List<Jid> getAccountJids(final boolean enabledOnly) {
SQLiteDatabase db = this.getReadableDatabase();
final SQLiteDatabase db = this.getReadableDatabase();
final List<Jid> jids = new ArrayList<>();
final String[] columns = new String[]{Account.USERNAME, Account.SERVER};
String where = enabledOnly ? "not options & (1 <<1)" : null;
Cursor cursor = db.query(Account.TABLENAME, columns, where, null, null, null, null);
try {
while (cursor.moveToNext()) {
final String where = enabledOnly ? "not options & (1 <<1)" : null;
try (final Cursor cursor = db.query(Account.TABLENAME, columns, where, null, null, null, null)) {
while (cursor != null && cursor.moveToNext()) {
jids.add(Jid.of(cursor.getString(0), cursor.getString(1), null));
}
} catch (final Exception e) {
return jids;
} catch (Exception e) {
return jids;
} finally {
if (cursor != null) {
cursor.close();
}
}
return jids;
}
private List<Account> getAccounts(SQLiteDatabase db) {
List<Account> list = new ArrayList<>();
Cursor cursor = db.query(Account.TABLENAME, null, null, null, null,
null, null);
while (cursor.moveToNext()) {
list.add(Account.fromCursor(cursor));
final List<Account> list = new ArrayList<>();
try (final Cursor cursor =
db.query(Account.TABLENAME, null, null, null, null, null, null)) {
while (cursor != null && cursor.moveToNext()) {
list.add(Account.fromCursor(cursor));
}
}
cursor.close();
return list;
}

View file

@ -87,19 +87,19 @@ public class MessageAdapter extends ArrayAdapter<Message> {
private OnContactPictureClicked mOnContactPictureClickedListener;
private OnContactPictureLongClicked mOnContactPictureLongClickedListener;
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);
this.audioPlayer = new AudioPlayer(this);
this.activity = activity;
metrics = getContext().getResources().getDisplayMetrics();
updatePreferences();
this.mForceNames = forceNames;
}
public MessageAdapter(XmppActivity activity, List<Message> messages, boolean forceNames) {
this(activity, messages);
mForceNames = forceNames;
public MessageAdapter(final XmppActivity activity, final List<Message> messages) {
this(activity, messages, false);
}
private static void resetClickListener(View... views) {