Commit ccccd253 authored by Grigory Fedorov's avatar Grigory Fedorov

extension/muc: light code formatting and refactoring.

parent 743096a8
......@@ -91,8 +91,9 @@ public class Occupant implements Comparable<Occupant> {
@Override
public int compareTo(Occupant another) {
int result = another.role.ordinal() - role.ordinal();
if (result != 0)
if (result != 0) {
return result;
}
return nickname.compareTo(another.nickname);
}
......
......@@ -22,8 +22,7 @@ import com.xabber.android.data.entity.BaseEntity;
import com.xabber.android.data.notification.EntityNotificationItem;
import com.xabber.android.ui.ConferenceAdd;
public class RoomAuthorizationError extends BaseEntity implements
EntityNotificationItem {
public class RoomAuthorizationError extends BaseEntity implements EntityNotificationItem {
public RoomAuthorizationError(String account, String user) {
super(account, user);
......@@ -31,8 +30,7 @@ public class RoomAuthorizationError extends BaseEntity implements
@Override
public Intent getIntent() {
return ConferenceAdd.createIntent(Application.getInstance(),
account, user);
return ConferenceAdd.createIntent(Application.getInstance(), account, user);
}
@Override
......@@ -42,8 +40,7 @@ public class RoomAuthorizationError extends BaseEntity implements
@Override
public String getText() {
return Application.getInstance().getString(
R.string.AUTHENTICATION_FAILED);
return Application.getInstance().getString(R.string.AUTHENTICATION_FAILED);
}
}
......@@ -46,8 +46,7 @@ public class RoomInvite extends BaseEntity implements EntityNotificationItem {
*/
private final String password;
public RoomInvite(String account, String user, String inviter,
String reason, String password) {
public RoomInvite(String account, String user, String inviter, String reason, String password) {
super(account, user);
this.inviter = inviter;
this.reason = reason == null ? "" : reason;
......@@ -73,19 +72,18 @@ public class RoomInvite extends BaseEntity implements EntityNotificationItem {
* @return Text for the confirmation.
*/
public String getConfirmation() {
String accountName = AccountManager.getInstance().getVerboseName(
account);
String inviterName = RosterManager.getInstance().getName(account,
inviter);
if (reason == null || "".equals(reason))
String accountName = AccountManager.getInstance().getVerboseName(account);
String inviterName = RosterManager.getInstance().getName(account, inviter);
if (reason == null || "".equals(reason)) {
return Application.getInstance()
.getString(R.string.muc_invite_confirm, accountName,
inviterName, user);
else
} else {
return Application.getInstance().getString(
R.string.muc_invite_confirm_reason, accountName,
inviterName, user, reason);
}
}
public String getInviter() {
return inviter;
......
......@@ -62,29 +62,40 @@ public enum RoomState {
* @return Status mode used in contact list.
*/
StatusMode toStatusMode() {
if (this == RoomState.available)
switch (this) {
case available:
return StatusMode.available;
else if (this == RoomState.occupation)
case occupation:
case joining:
case creating:
case waiting:
return StatusMode.connection;
else if (this == RoomState.joining)
return StatusMode.connection;
else if (this == RoomState.creating)
return StatusMode.connection;
else if (this == RoomState.unavailable)
case unavailable:
return StatusMode.unavailable;
else if (this == RoomState.waiting)
return StatusMode.connection;
else if (this == RoomState.error)
case error:
return StatusMode.unsubscribed;
else
default:
throw new IllegalStateException();
}
}
/**
* @return Connected is establish or connection is in progress.
*/
boolean inUse() {
return this == RoomState.available || this == RoomState.occupation
|| this == RoomState.creating || this == RoomState.joining;
switch (this) {
case available:
case occupation:
case joining:
case creating:
return true;
case unavailable:
case waiting:
case error:
default:
return false;
}
}
}
......@@ -56,9 +56,8 @@ class RoomTable extends AbstractAccountTable {
}
private static final String NAME = "rooms";
private static final String[] PROJECTION = new String[]{Fields._ID,
Fields.ACCOUNT, Fields.ROOM, Fields.NICKNAME, Fields.PASSWORD,
Fields.NEED_JOIN,};
private static final String[] PROJECTION = new String[]{ Fields._ID,
Fields.ACCOUNT, Fields.ROOM, Fields.NICKNAME, Fields.PASSWORD, Fields.NEED_JOIN };
private final DatabaseManager databaseManager;
private SQLiteStatement writeStatement;
......@@ -123,20 +122,12 @@ class RoomTable extends AbstractAccountTable {
/**
* Adds or updates room.
*
* @param account
* @param room
* @param nickname
* @param password
* @param join
*/
void write(String account, String room, String nickname, String password,
boolean join) {
void write(String account, String room, String nickname, String password, boolean join) {
synchronized (writeLock) {
if (writeStatement == null) {
SQLiteDatabase db = databaseManager.getWritableDatabase();
writeStatement = db
.compileStatement("INSERT OR REPLACE INTO " + NAME
writeStatement = db.compileStatement("INSERT OR REPLACE INTO " + NAME
+ " (" + Fields.ACCOUNT + ", " + Fields.ROOM
+ ", " + Fields.NICKNAME + ", "
+ Fields.PASSWORD + ", " + Fields.NEED_JOIN
......@@ -153,14 +144,10 @@ class RoomTable extends AbstractAccountTable {
/**
* Removes room.
*
* @param account
* @param room
*/
void remove(String account, String room) {
SQLiteDatabase db = databaseManager.getWritableDatabase();
db.delete(NAME, Fields.ACCOUNT + " = ? AND " + Fields.ROOM + " = ?",
new String[]{account, room});
db.delete(NAME, Fields.ACCOUNT + " = ? AND " + Fields.ROOM + " = ?", new String[]{account, room});
}
@Override
......
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