Show affiliation instead of role in MucDetails and offer 'advanced mode' to display role
This commit is contained in:
parent
8264474a0c
commit
bdb335e6b0
|
@ -4,15 +4,55 @@ import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.CopyOnWriteArrayList;
|
import java.util.concurrent.CopyOnWriteArrayList;
|
||||||
|
|
||||||
|
import eu.siacs.conversations.R;
|
||||||
import eu.siacs.conversations.crypto.PgpEngine;
|
import eu.siacs.conversations.crypto.PgpEngine;
|
||||||
import eu.siacs.conversations.xml.Element;
|
import eu.siacs.conversations.xml.Element;
|
||||||
import eu.siacs.conversations.xmpp.jid.InvalidJidException;
|
import eu.siacs.conversations.xmpp.jid.InvalidJidException;
|
||||||
import eu.siacs.conversations.xmpp.jid.Jid;
|
import eu.siacs.conversations.xmpp.jid.Jid;
|
||||||
import eu.siacs.conversations.xmpp.stanzas.PresencePacket;
|
import eu.siacs.conversations.xmpp.stanzas.PresencePacket;
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
|
|
||||||
@SuppressLint("DefaultLocale")
|
@SuppressLint("DefaultLocale")
|
||||||
public class MucOptions {
|
public class MucOptions {
|
||||||
|
|
||||||
|
public enum Affiliation {
|
||||||
|
OWNER(R.string.owner),
|
||||||
|
ADMIN(R.string.admin),
|
||||||
|
MEMBER(R.string.member),
|
||||||
|
OUTCAST(R.string.outcast),
|
||||||
|
NONE(R.string.no_affiliation);
|
||||||
|
|
||||||
|
private Affiliation(int resId) {
|
||||||
|
this.resId = resId;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int resId;
|
||||||
|
|
||||||
|
public int getResId() {
|
||||||
|
return resId;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
;
|
||||||
|
|
||||||
|
public enum Role {
|
||||||
|
MODERATOR(R.string.moderator),
|
||||||
|
VISITOR(R.string.visitor),
|
||||||
|
PARTICIPANT(R.string.participant),
|
||||||
|
NONE(R.string.no_role);
|
||||||
|
|
||||||
|
private Role(int resId) {
|
||||||
|
this.resId = resId;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int resId;
|
||||||
|
|
||||||
|
public int getResId() {
|
||||||
|
return resId;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static final int ERROR_NO_ERROR = 0;
|
public static final int ERROR_NO_ERROR = 0;
|
||||||
public static final int ERROR_NICK_IN_USE = 1;
|
public static final int ERROR_NICK_IN_USE = 1;
|
||||||
public static final int ERROR_UNKNOWN = 2;
|
public static final int ERROR_UNKNOWN = 2;
|
||||||
|
@ -30,6 +70,7 @@ public class MucOptions {
|
||||||
|
|
||||||
private interface OnEventListener {
|
private interface OnEventListener {
|
||||||
public void onSuccess();
|
public void onSuccess();
|
||||||
|
|
||||||
public void onFailure();
|
public void onFailure();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,18 +83,8 @@ public class MucOptions {
|
||||||
}
|
}
|
||||||
|
|
||||||
public class User {
|
public class User {
|
||||||
public static final int ROLE_MODERATOR = 3;
|
private Role role;
|
||||||
public static final int ROLE_NONE = 0;
|
private Affiliation affiliation;
|
||||||
public static final int ROLE_PARTICIPANT = 2;
|
|
||||||
public static final int ROLE_VISITOR = 1;
|
|
||||||
public static final int AFFILIATION_ADMIN = 4;
|
|
||||||
public static final int AFFILIATION_OWNER = 3;
|
|
||||||
public static final int AFFILIATION_MEMBER = 2;
|
|
||||||
public static final int AFFILIATION_OUTCAST = 1;
|
|
||||||
public static final int AFFILIATION_NONE = 0;
|
|
||||||
|
|
||||||
private int role;
|
|
||||||
private int affiliation;
|
|
||||||
private String name;
|
private String name;
|
||||||
private Jid jid;
|
private Jid jid;
|
||||||
private long pgpKeyId = 0;
|
private long pgpKeyId = 0;
|
||||||
|
@ -74,7 +105,7 @@ public class MucOptions {
|
||||||
return this.jid;
|
return this.jid;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getRole() {
|
public Role getRole() {
|
||||||
return this.role;
|
return this.role;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,35 +113,41 @@ public class MucOptions {
|
||||||
role = role.toLowerCase();
|
role = role.toLowerCase();
|
||||||
switch (role) {
|
switch (role) {
|
||||||
case "moderator":
|
case "moderator":
|
||||||
this.role = ROLE_MODERATOR;
|
this.role = Role.MODERATOR;
|
||||||
break;
|
break;
|
||||||
case "participant":
|
case "participant":
|
||||||
this.role = ROLE_PARTICIPANT;
|
this.role = Role.PARTICIPANT;
|
||||||
break;
|
break;
|
||||||
case "visitor":
|
case "visitor":
|
||||||
this.role = ROLE_VISITOR;
|
this.role = Role.VISITOR;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
this.role = ROLE_NONE;
|
this.role = Role.NONE;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getAffiliation() {
|
public Affiliation getAffiliation() {
|
||||||
return this.affiliation;
|
return this.affiliation;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAffiliation(String affiliation) {
|
public void setAffiliation(String affiliation) {
|
||||||
if (affiliation.equalsIgnoreCase("admin")) {
|
affiliation = affiliation.toLowerCase();
|
||||||
this.affiliation = AFFILIATION_ADMIN;
|
switch (affiliation) {
|
||||||
} else if (affiliation.equalsIgnoreCase("owner")) {
|
case "admin":
|
||||||
this.affiliation = AFFILIATION_OWNER;
|
this.affiliation = Affiliation.ADMIN;
|
||||||
} else if (affiliation.equalsIgnoreCase("member")) {
|
break;
|
||||||
this.affiliation = AFFILIATION_MEMBER;
|
case "owner":
|
||||||
} else if (affiliation.equalsIgnoreCase("outcast")) {
|
this.affiliation = Affiliation.OWNER;
|
||||||
this.affiliation = AFFILIATION_OUTCAST;
|
break;
|
||||||
} else {
|
case "member":
|
||||||
this.affiliation = AFFILIATION_NONE;
|
this.affiliation = Affiliation.MEMBER;
|
||||||
|
break;
|
||||||
|
case "outcast":
|
||||||
|
this.affiliation = Affiliation.OUTCAST;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
this.affiliation = Affiliation.NONE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -168,7 +205,7 @@ public class MucOptions {
|
||||||
if (!from.isBareJid()) {
|
if (!from.isBareJid()) {
|
||||||
final String name = from.getResourcepart();
|
final String name = from.getResourcepart();
|
||||||
final String type = packet.getAttribute("type");
|
final String type = packet.getAttribute("type");
|
||||||
final Element x = packet.findChild("x","http://jabber.org/protocol/muc#user");
|
final Element x = packet.findChild("x", "http://jabber.org/protocol/muc#user");
|
||||||
final List<String> codes = getStatusCodes(x);
|
final List<String> codes = getStatusCodes(x);
|
||||||
if (type == null) {
|
if (type == null) {
|
||||||
User user = new User();
|
User user = new User();
|
||||||
|
@ -261,10 +298,10 @@ public class MucOptions {
|
||||||
private List<String> getStatusCodes(Element x) {
|
private List<String> getStatusCodes(Element x) {
|
||||||
List<String> codes = new ArrayList<String>();
|
List<String> codes = new ArrayList<String>();
|
||||||
if (x != null) {
|
if (x != null) {
|
||||||
for(Element child : x.getChildren()) {
|
for (Element child : x.getChildren()) {
|
||||||
if (child.getName().equals("status")) {
|
if (child.getName().equals("status")) {
|
||||||
String code = child.getAttribute("code");
|
String code = child.getAttribute("code");
|
||||||
if (code!=null) {
|
if (code != null) {
|
||||||
codes.add(code);
|
codes.add(code);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -389,7 +426,7 @@ public class MucOptions {
|
||||||
|
|
||||||
public Jid createJoinJid(String nick) {
|
public Jid createJoinJid(String nick) {
|
||||||
try {
|
try {
|
||||||
return Jid.fromString(this.conversation.getJid().toBareJid().toString() + "/"+nick);
|
return Jid.fromString(this.conversation.getJid().toBareJid().toString() + "/" + nick);
|
||||||
} catch (final InvalidJidException e) {
|
} catch (final InvalidJidException e) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,6 +31,7 @@ import eu.siacs.conversations.entities.Account;
|
||||||
import eu.siacs.conversations.entities.Bookmark;
|
import eu.siacs.conversations.entities.Bookmark;
|
||||||
import eu.siacs.conversations.entities.Contact;
|
import eu.siacs.conversations.entities.Contact;
|
||||||
import eu.siacs.conversations.entities.Conversation;
|
import eu.siacs.conversations.entities.Conversation;
|
||||||
|
import eu.siacs.conversations.entities.MucOptions;
|
||||||
import eu.siacs.conversations.entities.MucOptions.User;
|
import eu.siacs.conversations.entities.MucOptions.User;
|
||||||
import eu.siacs.conversations.services.XmppConnectionService.OnMucRosterUpdate;
|
import eu.siacs.conversations.services.XmppConnectionService.OnMucRosterUpdate;
|
||||||
import eu.siacs.conversations.services.XmppConnectionService.OnConversationUpdate;
|
import eu.siacs.conversations.services.XmppConnectionService.OnConversationUpdate;
|
||||||
|
@ -59,6 +60,8 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers
|
||||||
private List<User> users = new ArrayList<>();
|
private List<User> users = new ArrayList<>();
|
||||||
private User mSelectedUser = null;
|
private User mSelectedUser = null;
|
||||||
|
|
||||||
|
private boolean mAdvancedMode = false;
|
||||||
|
|
||||||
private UiCallback<Conversation> renameCallback = new UiCallback<Conversation>() {
|
private UiCallback<Conversation> renameCallback = new UiCallback<Conversation>() {
|
||||||
@Override
|
@Override
|
||||||
public void success(Conversation object) {
|
public void success(Conversation object) {
|
||||||
|
@ -66,7 +69,7 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
Toast.makeText(ConferenceDetailsActivity.this,getString(R.string.your_nick_has_been_changed),Toast.LENGTH_SHORT).show();
|
Toast.makeText(ConferenceDetailsActivity.this,getString(R.string.your_nick_has_been_changed),Toast.LENGTH_SHORT).show();
|
||||||
populateView();
|
updateView();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -94,7 +97,7 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
populateView();
|
updateView();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -105,7 +108,7 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
populateView();
|
updateView();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -171,23 +174,16 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers
|
||||||
case R.id.action_delete_bookmark:
|
case R.id.action_delete_bookmark:
|
||||||
deleteBookmark();
|
deleteBookmark();
|
||||||
break;
|
break;
|
||||||
|
case R.id.action_advanced_mode:
|
||||||
|
this.mAdvancedMode = !menuItem.isChecked();
|
||||||
|
menuItem.setChecked(this.mAdvancedMode);
|
||||||
|
invalidateOptionsMenu();
|
||||||
|
updateView();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
return super.onOptionsItemSelected(menuItem);
|
return super.onOptionsItemSelected(menuItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getReadableRole(int role) {
|
|
||||||
switch (role) {
|
|
||||||
case User.ROLE_MODERATOR:
|
|
||||||
return getString(R.string.moderator);
|
|
||||||
case User.ROLE_PARTICIPANT:
|
|
||||||
return getString(R.string.participant);
|
|
||||||
case User.ROLE_VISITOR:
|
|
||||||
return getString(R.string.visitor);
|
|
||||||
default:
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String getShareableUri() {
|
protected String getShareableUri() {
|
||||||
if (mConversation != null) {
|
if (mConversation != null) {
|
||||||
|
@ -201,6 +197,8 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers
|
||||||
public boolean onPrepareOptionsMenu(Menu menu) {
|
public boolean onPrepareOptionsMenu(Menu menu) {
|
||||||
MenuItem menuItemSaveBookmark = menu.findItem(R.id.action_save_as_bookmark);
|
MenuItem menuItemSaveBookmark = menu.findItem(R.id.action_save_as_bookmark);
|
||||||
MenuItem menuItemDeleteBookmark = menu.findItem(R.id.action_delete_bookmark);
|
MenuItem menuItemDeleteBookmark = menu.findItem(R.id.action_delete_bookmark);
|
||||||
|
MenuItem menuItemAdvancedMode = menu.findItem(R.id.action_advanced_mode);
|
||||||
|
menuItemAdvancedMode.setChecked(mAdvancedMode);
|
||||||
Account account = mConversation.getAccount();
|
Account account = mConversation.getAccount();
|
||||||
if (account.hasBookmarkFor(mConversation.getJid().toBareJid())) {
|
if (account.hasBookmarkFor(mConversation.getJid().toBareJid())) {
|
||||||
menuItemSaveBookmark.setVisible(false);
|
menuItemSaveBookmark.setVisible(false);
|
||||||
|
@ -290,16 +288,15 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers
|
||||||
this.mConversation = xmppConnectionService
|
this.mConversation = xmppConnectionService
|
||||||
.findConversationByUuid(uuid);
|
.findConversationByUuid(uuid);
|
||||||
if (this.mConversation != null) {
|
if (this.mConversation != null) {
|
||||||
populateView();
|
updateView();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void populateView() {
|
private void updateView() {
|
||||||
mAccountJid.setText(getString(R.string.using_account, mConversation
|
mAccountJid.setText(getString(R.string.using_account, mConversation
|
||||||
.getAccount().getJid().toBareJid()));
|
.getAccount().getJid().toBareJid()));
|
||||||
mYourPhoto.setImageBitmap(avatarService().get(
|
mYourPhoto.setImageBitmap(avatarService().get(mConversation.getAccount(), getPixel(48)));
|
||||||
mConversation.getAccount(), getPixel(48)));
|
|
||||||
setTitle(mConversation.getName());
|
setTitle(mConversation.getName());
|
||||||
mFullJid.setText(mConversation.getJid().toBareJid().toString());
|
mFullJid.setText(mConversation.getJid().toBareJid().toString());
|
||||||
mYourNick.setText(mConversation.getMucOptions().getActualNick());
|
mYourNick.setText(mConversation.getMucOptions().getActualNick());
|
||||||
|
@ -307,18 +304,12 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers
|
||||||
if (mConversation.getMucOptions().online()) {
|
if (mConversation.getMucOptions().online()) {
|
||||||
mMoreDetails.setVisibility(View.VISIBLE);
|
mMoreDetails.setVisibility(View.VISIBLE);
|
||||||
User self = mConversation.getMucOptions().getSelf();
|
User self = mConversation.getMucOptions().getSelf();
|
||||||
switch (self.getAffiliation()) {
|
final String status = getStatus(self);
|
||||||
case User.AFFILIATION_ADMIN:
|
if (status != null) {
|
||||||
mRoleAffiliaton.setText(getReadableRole(self.getRole()) + " ("
|
mRoleAffiliaton.setVisibility(View.VISIBLE);
|
||||||
+ getString(R.string.admin) + ")");
|
mRoleAffiliaton.setText(status);
|
||||||
break;
|
} else {
|
||||||
case User.AFFILIATION_OWNER:
|
mRoleAffiliaton.setVisibility(View.GONE);
|
||||||
mRoleAffiliaton.setText(getReadableRole(self.getRole()) + " ("
|
|
||||||
+ getString(R.string.owner) + ")");
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
mRoleAffiliaton.setText(getReadableRole(self.getRole()));
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.users.clear();
|
this.users.clear();
|
||||||
|
@ -337,32 +328,31 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers
|
||||||
});
|
});
|
||||||
registerForContextMenu(view);
|
registerForContextMenu(view);
|
||||||
view.setTag(user);
|
view.setTag(user);
|
||||||
TextView name = (TextView) view
|
TextView tvDisplayName = (TextView) view.findViewById(R.id.contact_display_name);
|
||||||
.findViewById(R.id.contact_display_name);
|
TextView tvKey = (TextView) view.findViewById(R.id.key);
|
||||||
TextView key = (TextView) view.findViewById(R.id.key);
|
TextView tvStatus = (TextView) view.findViewById(R.id.contact_jid);
|
||||||
TextView role = (TextView) view.findViewById(R.id.contact_jid);
|
if (mAdvancedMode && user.getPgpKeyId() != 0) {
|
||||||
if (user.getPgpKeyId() != 0) {
|
tvKey.setVisibility(View.VISIBLE);
|
||||||
key.setVisibility(View.VISIBLE);
|
tvKey.setOnClickListener(new OnClickListener() {
|
||||||
key.setOnClickListener(new OnClickListener() {
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
viewPgpKey(user);
|
viewPgpKey(user);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
key.setText(OpenPgpUtils.convertKeyIdToHex(user.getPgpKeyId()));
|
tvKey.setText(OpenPgpUtils.convertKeyIdToHex(user.getPgpKeyId()));
|
||||||
}
|
}
|
||||||
Bitmap bm;
|
Bitmap bm;
|
||||||
Contact contact = user.getContact();
|
Contact contact = user.getContact();
|
||||||
if (contact != null) {
|
if (contact != null) {
|
||||||
bm = avatarService().get(contact, getPixel(48));
|
bm = avatarService().get(contact, getPixel(48));
|
||||||
name.setText(contact.getDisplayName());
|
tvDisplayName.setText(contact.getDisplayName());
|
||||||
role.setText(user.getName() + " \u2022 "
|
tvStatus.setText(user.getName() + " \u2022 " + getStatus(user));
|
||||||
+ getReadableRole(user.getRole()));
|
|
||||||
} else {
|
} else {
|
||||||
bm = avatarService().get(user.getName(), getPixel(48));
|
bm = avatarService().get(user.getName(), getPixel(48));
|
||||||
name.setText(user.getName());
|
tvDisplayName.setText(user.getName());
|
||||||
role.setText(getReadableRole(user.getRole()));
|
tvStatus.setText(getStatus(user));
|
||||||
|
|
||||||
}
|
}
|
||||||
ImageView iv = (ImageView) view.findViewById(R.id.contact_photo);
|
ImageView iv = (ImageView) view.findViewById(R.id.contact_photo);
|
||||||
iv.setImageBitmap(bm);
|
iv.setImageBitmap(bm);
|
||||||
|
@ -370,6 +360,19 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String getStatus(User user) {
|
||||||
|
if (mAdvancedMode) {
|
||||||
|
StringBuilder builder = new StringBuilder();
|
||||||
|
builder.append(getString(user.getAffiliation().getResId()));
|
||||||
|
builder.append(" (");
|
||||||
|
builder.append(getString(user.getRole().getResId()));
|
||||||
|
builder.append(')');
|
||||||
|
return builder.toString();
|
||||||
|
} else {
|
||||||
|
return getString(user.getAffiliation().getResId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
|
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
|
||||||
private void setListItemBackgroundOnView(View view) {
|
private void setListItemBackgroundOnView(View view) {
|
||||||
|
|
|
@ -21,6 +21,13 @@
|
||||||
android:title="@string/delete_bookmark"
|
android:title="@string/delete_bookmark"
|
||||||
android:orderInCategory="80"
|
android:orderInCategory="80"
|
||||||
android:showAsAction="never" />
|
android:showAsAction="never" />
|
||||||
|
<item
|
||||||
|
android:id="@+id/action_advanced_mode"
|
||||||
|
android:title="@string/advanced_mode"
|
||||||
|
android:checkable="true"
|
||||||
|
android:checked="false"
|
||||||
|
android:orderInCategory="85"
|
||||||
|
android:showAsAction="never" />
|
||||||
<item
|
<item
|
||||||
android:id="@+id/action_accounts"
|
android:id="@+id/action_accounts"
|
||||||
android:orderInCategory="90"
|
android:orderInCategory="90"
|
||||||
|
|
|
@ -406,4 +406,9 @@
|
||||||
<string name="enable_all_accounts">Enable all accounts</string>
|
<string name="enable_all_accounts">Enable all accounts</string>
|
||||||
<string name="disable_all_accounts">Disable all accounts</string>
|
<string name="disable_all_accounts">Disable all accounts</string>
|
||||||
<string name="perform_action_with">Perform action with</string>
|
<string name="perform_action_with">Perform action with</string>
|
||||||
|
<string name="no_affiliation">No affiliation</string>
|
||||||
|
<string name="no_role">No role</string>
|
||||||
|
<string name="outcast">Outcast</string>
|
||||||
|
<string name="member">Member</string>
|
||||||
|
<string name="advanced_mode">Advanced mode</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
Loading…
Reference in a new issue