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.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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -21,6 +21,13 @@
|
|||
android:title="@string/delete_bookmark"
|
||||
android:orderInCategory="80"
|
||||
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
|
||||
android:id="@+id/action_accounts"
|
||||
android:orderInCategory="90"
|
||||
|
|
|
@ -406,4 +406,9 @@
|
|||
<string name="enable_all_accounts">Enable all accounts</string>
|
||||
<string name="disable_all_accounts">Disable all accounts</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>
|
||||
|
|
Loading…
Reference in New Issue