added warning lable if server doesn't support pubsub. refactored feature identification into seperate class

This commit is contained in:
iNPUTmice 2014-08-09 10:20:16 +02:00
parent 0bab1a4613
commit 937fc51b50
4 changed files with 64 additions and 35 deletions

View File

@ -276,4 +276,5 @@
<string name="error_publish_avatar_converting">Something went wrong while converting your picture</string> <string name="error_publish_avatar_converting">Something went wrong while converting your picture</string>
<string name="error_saving_avatar">Could not save avatar to disk</string> <string name="error_saving_avatar">Could not save avatar to disk</string>
<string name="or_long_press_for_default">(Or long press to bring back default)</string> <string name="or_long_press_for_default">(Or long press to bring back default)</string>
<string name="error_publish_avatar_no_server_support">Your server does not support the publication of avatars</string>
</resources> </resources>

View File

@ -184,7 +184,7 @@ public class ManageAccountActivity extends XmppActivity {
connection.setText(connectionAge + " " connection.setText(connectionAge + " "
+ getString(R.string.mins)); + getString(R.string.mins));
} }
if (xmpp.hasFeatureStreamManagment()) { if (xmpp.getFeatures().sm()) {
if (sessionAgeHours >= 2) { if (sessionAgeHours >= 2) {
session.setText(sessionAgeHours + " " session.setText(sessionAgeHours + " "
+ getString(R.string.hours)); + getString(R.string.hours));
@ -197,12 +197,12 @@ public class ManageAccountActivity extends XmppActivity {
stream.setText(getString(R.string.no)); stream.setText(getString(R.string.no));
session.setText(connection.getText()); session.setText(connection.getText());
} }
if (xmpp.hasFeaturesCarbon()) { if (xmpp.getFeatures().carbons()) {
carbon.setText(getString(R.string.yes)); carbon.setText(getString(R.string.yes));
} else { } else {
carbon.setText(getString(R.string.no)); carbon.setText(getString(R.string.no));
} }
if (xmpp.hasFeatureRosterManagment()) { if (xmpp.getFeatures().rosterVersioning()) {
roster.setText(getString(R.string.yes)); roster.setText(getString(R.string.yes));
} else { } else {
roster.setText(getString(R.string.no)); roster.setText(getString(R.string.no));

View File

@ -33,6 +33,8 @@ public class PublishProfilePictureActivity extends XmppActivity {
private Account account; private Account account;
private boolean support = false;
private UiCallback<Avatar> avatarPublication = new UiCallback<Avatar>() { private UiCallback<Avatar> avatarPublication = new UiCallback<Avatar>() {
@Override @Override
@ -148,6 +150,9 @@ public class PublishProfilePictureActivity extends XmppActivity {
String jid = getIntent().getStringExtra("account"); String jid = getIntent().getStringExtra("account");
if (jid != null) { if (jid != null) {
this.account = xmppConnectionService.findAccountByJid(jid); this.account = xmppConnectionService.findAccountByJid(jid);
if (this.account.getXmppConnection() != null) {
this.support = this.account.getXmppConnection().getFeatures().pubsub();
}
if (this.avatarUri == null) { if (this.avatarUri == null) {
if (this.account.getAvatar() != null) { if (this.account.getAvatar() != null) {
this.avatar.setImageBitmap(this.account.getImage( this.avatar.setImageBitmap(this.account.getImage(
@ -173,10 +178,16 @@ public class PublishProfilePictureActivity extends XmppActivity {
Bitmap bm = xmppConnectionService.getFileBackend().cropCenterSquare( Bitmap bm = xmppConnectionService.getFileBackend().cropCenterSquare(
uri, 384); uri, 384);
this.avatar.setImageBitmap(bm); this.avatar.setImageBitmap(bm);
enablePublishButton(); if (support) {
this.publishButton.setText(R.string.publish_avatar); enablePublishButton();
this.hintOrWarning.setText(R.string.publish_avatar_explanation); this.publishButton.setText(R.string.publish_avatar);
this.hintOrWarning.setTextColor(getPrimaryTextColor()); this.hintOrWarning.setText(R.string.publish_avatar_explanation);
this.hintOrWarning.setTextColor(getPrimaryTextColor());
} else {
disablePublishButton();
this.hintOrWarning.setTextColor(getWarningTextColor());
this.hintOrWarning.setText(R.string.error_publish_avatar_no_server_support);
}
if (this.defaultUri != null && uri.equals(this.defaultUri)) { if (this.defaultUri != null && uri.equals(this.defaultUri)) {
this.secondaryHint.setVisibility(View.INVISIBLE); this.secondaryHint.setVisibility(View.INVISIBLE);
this.avatar.setOnLongClickListener(null); this.avatar.setOnLongClickListener(null);

View File

@ -65,6 +65,8 @@ public class XmppConnection implements Runnable {
private XmlReader tagReader; private XmlReader tagReader;
private TagWriter tagWriter; private TagWriter tagWriter;
private Features features = new Features(this);
private boolean shouldBind = true; private boolean shouldBind = true;
private boolean shouldAuthenticate = true; private boolean shouldAuthenticate = true;
private Element streamFeatures; private Element streamFeatures;
@ -662,7 +664,7 @@ public class XmppConnection implements Runnable {
} }
private void enableAdvancedStreamFeatures() { private void enableAdvancedStreamFeatures() {
if (hasFeaturesCarbon()) { if (getFeatures().carbons()) {
sendEnableCarbons(); sendEnableCarbons();
} }
} }
@ -833,33 +835,6 @@ public class XmppConnection implements Runnable {
} }
} }
public boolean hasFeatureRosterManagment() {
if (this.streamFeatures == null) {
return false;
} else {
return this.streamFeatures.hasChild("ver");
}
}
public boolean hasFeatureStreamManagment() {
if (this.streamFeatures == null) {
return false;
} else {
return this.streamFeatures.hasChild("sm");
}
}
public boolean hasFeaturesCarbon() {
return hasDiscoFeature(account.getServer(), "urn:xmpp:carbons:2");
}
public boolean hasDiscoFeature(String server, String feature) {
if (!disco.containsKey(server)) {
return false;
}
return disco.get(server).contains(feature);
}
public List<String> findDiscoItemsByFeature(String feature) { public List<String> findDiscoItemsByFeature(String feature) {
List<String> items = new ArrayList<String>(); List<String> items = new ArrayList<String>();
for (Entry<String, List<String>> cursor : disco.entrySet()) { for (Entry<String, List<String>> cursor : disco.entrySet()) {
@ -903,4 +878,46 @@ public class XmppConnection implements Runnable {
public int getAttempt() { public int getAttempt() {
return this.attempt; return this.attempt;
} }
public Features getFeatures() {
return this.features;
}
public class Features {
XmppConnection connection;
public Features(XmppConnection connection) {
this.connection = connection;
}
private boolean hasDiscoFeature(String server, String feature) {
if (!connection.disco.containsKey(server)) {
return false;
}
return connection.disco.get(server).contains(feature);
}
public boolean carbons() {
return hasDiscoFeature(account.getServer(), "urn:xmpp:carbons:2");
}
public boolean sm() {
if (connection.streamFeatures == null) {
return false;
} else {
return connection.streamFeatures.hasChild("sm");
}
}
public boolean pubsub() {
return hasDiscoFeature(account.getServer(), "http://jabber.org/protocol/pubsub#publish");
}
public boolean rosterVersioning() {
if (connection.streamFeatures == null) {
return false;
} else {
return connection.streamFeatures.hasChild("ver");
}
}
}
} }