diff options
author | Daniel Gultsch <inputmice@siacs.eu> | 2015-01-05 15:06:39 +0100 |
---|---|---|
committer | Daniel Gultsch <inputmice@siacs.eu> | 2015-01-05 15:06:39 +0100 |
commit | bdb335e6b08d35a23468ca1d5730330c520a6a90 (patch) | |
tree | 42d480b20b63551220482c519ee446311589d338 /src/main/java | |
parent | 8264474a0c7552368c4f0468b8c29977917eef30 (diff) |
Show affiliation instead of role in MucDetails and offer 'advanced mode' to display role
Diffstat (limited to 'src/main/java')
-rw-r--r-- | src/main/java/eu/siacs/conversations/entities/MucOptions.java | 103 | ||||
-rw-r--r-- | src/main/java/eu/siacs/conversations/ui/ConferenceDetailsActivity.java | 93 |
2 files changed, 118 insertions, 78 deletions
diff --git a/src/main/java/eu/siacs/conversations/entities/MucOptions.java b/src/main/java/eu/siacs/conversations/entities/MucOptions.java index 97a63532..ce2c5b04 100644 --- a/src/main/java/eu/siacs/conversations/entities/MucOptions.java +++ b/src/main/java/eu/siacs/conversations/entities/MucOptions.java @@ -4,15 +4,55 @@ import java.util.ArrayList; import java.util.List; import java.util.concurrent.CopyOnWriteArrayList; +import eu.siacs.conversations.R; import eu.siacs.conversations.crypto.PgpEngine; import eu.siacs.conversations.xml.Element; import eu.siacs.conversations.xmpp.jid.InvalidJidException; import eu.siacs.conversations.xmpp.jid.Jid; import eu.siacs.conversations.xmpp.stanzas.PresencePacket; + import android.annotation.SuppressLint; @SuppressLint("DefaultLocale") 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_NICK_IN_USE = 1; public static final int ERROR_UNKNOWN = 2; @@ -30,6 +70,7 @@ public class MucOptions { private interface OnEventListener { public void onSuccess(); + public void onFailure(); } @@ -42,18 +83,8 @@ public class MucOptions { } public class User { - public static final int ROLE_MODERATOR = 3; - public static final int ROLE_NONE = 0; - 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 Role role; + private Affiliation affiliation; private String name; private Jid jid; private long pgpKeyId = 0; @@ -74,7 +105,7 @@ public class MucOptions { return this.jid; } - public int getRole() { + public Role getRole() { return this.role; } @@ -82,35 +113,41 @@ public class MucOptions { role = role.toLowerCase(); switch (role) { case "moderator": - this.role = ROLE_MODERATOR; + this.role = Role.MODERATOR; break; case "participant": - this.role = ROLE_PARTICIPANT; + this.role = Role.PARTICIPANT; break; case "visitor": - this.role = ROLE_VISITOR; + this.role = Role.VISITOR; break; default: - this.role = ROLE_NONE; + this.role = Role.NONE; break; } } - public int getAffiliation() { + public Affiliation getAffiliation() { return this.affiliation; } public void setAffiliation(String affiliation) { - if (affiliation.equalsIgnoreCase("admin")) { - this.affiliation = AFFILIATION_ADMIN; - } else if (affiliation.equalsIgnoreCase("owner")) { - this.affiliation = AFFILIATION_OWNER; - } else if (affiliation.equalsIgnoreCase("member")) { - this.affiliation = AFFILIATION_MEMBER; - } else if (affiliation.equalsIgnoreCase("outcast")) { - this.affiliation = AFFILIATION_OUTCAST; - } else { - this.affiliation = AFFILIATION_NONE; + affiliation = affiliation.toLowerCase(); + switch (affiliation) { + case "admin": + this.affiliation = Affiliation.ADMIN; + break; + case "owner": + this.affiliation = Affiliation.OWNER; + break; + case "member": + 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()) { final String name = from.getResourcepart(); 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); if (type == null) { User user = new User(); @@ -204,7 +241,7 @@ public class MucOptions { msg = ""; } user.setPgpKeyId(pgp.fetchKeyId(account, msg, - signed.getContent())); + signed.getContent())); } } } @@ -261,10 +298,10 @@ public class MucOptions { private List<String> getStatusCodes(Element x) { List<String> codes = new ArrayList<String>(); if (x != null) { - for(Element child : x.getChildren()) { + for (Element child : x.getChildren()) { if (child.getName().equals("status")) { String code = child.getAttribute("code"); - if (code!=null) { + if (code != null) { codes.add(code); } } @@ -389,7 +426,7 @@ public class MucOptions { public Jid createJoinJid(String nick) { try { - return Jid.fromString(this.conversation.getJid().toBareJid().toString() + "/"+nick); + return Jid.fromString(this.conversation.getJid().toBareJid().toString() + "/" + nick); } catch (final InvalidJidException e) { return null; } diff --git a/src/main/java/eu/siacs/conversations/ui/ConferenceDetailsActivity.java b/src/main/java/eu/siacs/conversations/ui/ConferenceDetailsActivity.java index eeb015f3..5a30d761 100644 --- a/src/main/java/eu/siacs/conversations/ui/ConferenceDetailsActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/ConferenceDetailsActivity.java @@ -31,6 +31,7 @@ import eu.siacs.conversations.entities.Account; import eu.siacs.conversations.entities.Bookmark; import eu.siacs.conversations.entities.Contact; import eu.siacs.conversations.entities.Conversation; +import eu.siacs.conversations.entities.MucOptions; import eu.siacs.conversations.entities.MucOptions.User; import eu.siacs.conversations.services.XmppConnectionService.OnMucRosterUpdate; 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 User mSelectedUser = null; + private boolean mAdvancedMode = false; + private UiCallback<Conversation> renameCallback = new UiCallback<Conversation>() { @Override public void success(Conversation object) { @@ -66,7 +69,7 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers @Override public void run() { 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 public void run() { - populateView(); + updateView(); } }); } @@ -105,7 +108,7 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers @Override public void run() { - populateView(); + updateView(); } }); } @@ -171,23 +174,16 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers case R.id.action_delete_bookmark: deleteBookmark(); break; + case R.id.action_advanced_mode: + this.mAdvancedMode = !menuItem.isChecked(); + menuItem.setChecked(this.mAdvancedMode); + invalidateOptionsMenu(); + updateView(); + break; } 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 protected String getShareableUri() { if (mConversation != null) { @@ -201,6 +197,8 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers public boolean onPrepareOptionsMenu(Menu menu) { MenuItem menuItemSaveBookmark = menu.findItem(R.id.action_save_as_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(); if (account.hasBookmarkFor(mConversation.getJid().toBareJid())) { menuItemSaveBookmark.setVisible(false); @@ -290,16 +288,15 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers this.mConversation = xmppConnectionService .findConversationByUuid(uuid); if (this.mConversation != null) { - populateView(); + updateView(); } } } - private void populateView() { + private void updateView() { mAccountJid.setText(getString(R.string.using_account, mConversation .getAccount().getJid().toBareJid())); - mYourPhoto.setImageBitmap(avatarService().get( - mConversation.getAccount(), getPixel(48))); + mYourPhoto.setImageBitmap(avatarService().get(mConversation.getAccount(), getPixel(48))); setTitle(mConversation.getName()); mFullJid.setText(mConversation.getJid().toBareJid().toString()); mYourNick.setText(mConversation.getMucOptions().getActualNick()); @@ -307,18 +304,12 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers if (mConversation.getMucOptions().online()) { mMoreDetails.setVisibility(View.VISIBLE); User self = mConversation.getMucOptions().getSelf(); - switch (self.getAffiliation()) { - case User.AFFILIATION_ADMIN: - mRoleAffiliaton.setText(getReadableRole(self.getRole()) + " (" - + getString(R.string.admin) + ")"); - break; - case User.AFFILIATION_OWNER: - mRoleAffiliaton.setText(getReadableRole(self.getRole()) + " (" - + getString(R.string.owner) + ")"); - break; - default: - mRoleAffiliaton.setText(getReadableRole(self.getRole())); - break; + final String status = getStatus(self); + if (status != null) { + mRoleAffiliaton.setVisibility(View.VISIBLE); + mRoleAffiliaton.setText(status); + } else { + mRoleAffiliaton.setVisibility(View.GONE); } } this.users.clear(); @@ -337,32 +328,31 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers }); registerForContextMenu(view); view.setTag(user); - TextView name = (TextView) view - .findViewById(R.id.contact_display_name); - TextView key = (TextView) view.findViewById(R.id.key); - TextView role = (TextView) view.findViewById(R.id.contact_jid); - if (user.getPgpKeyId() != 0) { - key.setVisibility(View.VISIBLE); - key.setOnClickListener(new OnClickListener() { + TextView tvDisplayName = (TextView) view.findViewById(R.id.contact_display_name); + TextView tvKey = (TextView) view.findViewById(R.id.key); + TextView tvStatus = (TextView) view.findViewById(R.id.contact_jid); + if (mAdvancedMode && user.getPgpKeyId() != 0) { + tvKey.setVisibility(View.VISIBLE); + tvKey.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { viewPgpKey(user); } }); - key.setText(OpenPgpUtils.convertKeyIdToHex(user.getPgpKeyId())); + tvKey.setText(OpenPgpUtils.convertKeyIdToHex(user.getPgpKeyId())); } Bitmap bm; Contact contact = user.getContact(); if (contact != null) { bm = avatarService().get(contact, getPixel(48)); - name.setText(contact.getDisplayName()); - role.setText(user.getName() + " \u2022 " - + getReadableRole(user.getRole())); + tvDisplayName.setText(contact.getDisplayName()); + tvStatus.setText(user.getName() + " \u2022 " + getStatus(user)); } else { bm = avatarService().get(user.getName(), getPixel(48)); - name.setText(user.getName()); - role.setText(getReadableRole(user.getRole())); + tvDisplayName.setText(user.getName()); + tvStatus.setText(getStatus(user)); + } ImageView iv = (ImageView) view.findViewById(R.id.contact_photo); 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") @TargetApi(Build.VERSION_CODES.JELLY_BEAN) private void setListItemBackgroundOnView(View view) { |