added warning lable if server doesn't support pubsub. refactored feature identification into seperate class
This commit is contained in:
		
							parent
							
								
									0bab1a4613
								
							
						
					
					
						commit
						937fc51b50
					
				|  | @ -276,4 +276,5 @@ | |||
|     <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="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> | ||||
|  |  | |||
|  | @ -184,7 +184,7 @@ public class ManageAccountActivity extends XmppActivity { | |||
| 						connection.setText(connectionAge + " " | ||||
| 								+ getString(R.string.mins)); | ||||
| 					} | ||||
| 					if (xmpp.hasFeatureStreamManagment()) { | ||||
| 					if (xmpp.getFeatures().sm()) { | ||||
| 						if (sessionAgeHours >= 2) { | ||||
| 							session.setText(sessionAgeHours + " " | ||||
| 									+ getString(R.string.hours)); | ||||
|  | @ -197,12 +197,12 @@ public class ManageAccountActivity extends XmppActivity { | |||
| 						stream.setText(getString(R.string.no)); | ||||
| 						session.setText(connection.getText()); | ||||
| 					} | ||||
| 					if (xmpp.hasFeaturesCarbon()) { | ||||
| 					if (xmpp.getFeatures().carbons()) { | ||||
| 						carbon.setText(getString(R.string.yes)); | ||||
| 					} else { | ||||
| 						carbon.setText(getString(R.string.no)); | ||||
| 					} | ||||
| 					if (xmpp.hasFeatureRosterManagment()) { | ||||
| 					if (xmpp.getFeatures().rosterVersioning()) { | ||||
| 						roster.setText(getString(R.string.yes)); | ||||
| 					} else { | ||||
| 						roster.setText(getString(R.string.no)); | ||||
|  |  | |||
|  | @ -32,6 +32,8 @@ public class PublishProfilePictureActivity extends XmppActivity { | |||
| 	private Uri defaultUri; | ||||
| 
 | ||||
| 	private Account account; | ||||
| 	 | ||||
| 	private boolean support = false; | ||||
| 
 | ||||
| 	private UiCallback<Avatar> avatarPublication = new UiCallback<Avatar>() { | ||||
| 
 | ||||
|  | @ -148,6 +150,9 @@ public class PublishProfilePictureActivity extends XmppActivity { | |||
| 			String jid = getIntent().getStringExtra("account"); | ||||
| 			if (jid != null) { | ||||
| 				this.account = xmppConnectionService.findAccountByJid(jid); | ||||
| 				if (this.account.getXmppConnection() != null) { | ||||
| 					this.support = this.account.getXmppConnection().getFeatures().pubsub(); | ||||
| 				} | ||||
| 				if (this.avatarUri == null) { | ||||
| 					if (this.account.getAvatar() != null) { | ||||
| 						this.avatar.setImageBitmap(this.account.getImage( | ||||
|  | @ -173,10 +178,16 @@ public class PublishProfilePictureActivity extends XmppActivity { | |||
| 		Bitmap bm = xmppConnectionService.getFileBackend().cropCenterSquare( | ||||
| 				uri, 384); | ||||
| 		this.avatar.setImageBitmap(bm); | ||||
| 		enablePublishButton(); | ||||
| 		this.publishButton.setText(R.string.publish_avatar); | ||||
| 		this.hintOrWarning.setText(R.string.publish_avatar_explanation); | ||||
| 		this.hintOrWarning.setTextColor(getPrimaryTextColor()); | ||||
| 		if (support) { | ||||
| 			enablePublishButton(); | ||||
| 			this.publishButton.setText(R.string.publish_avatar); | ||||
| 			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)) { | ||||
| 			this.secondaryHint.setVisibility(View.INVISIBLE); | ||||
| 			this.avatar.setOnLongClickListener(null); | ||||
|  |  | |||
|  | @ -64,6 +64,8 @@ public class XmppConnection implements Runnable { | |||
| 	private Socket socket; | ||||
| 	private XmlReader tagReader; | ||||
| 	private TagWriter tagWriter; | ||||
| 	 | ||||
| 	private Features features = new Features(this); | ||||
| 
 | ||||
| 	private boolean shouldBind = true; | ||||
| 	private boolean shouldAuthenticate = true; | ||||
|  | @ -662,7 +664,7 @@ public class XmppConnection implements Runnable { | |||
| 	} | ||||
| 
 | ||||
| 	private void enableAdvancedStreamFeatures() { | ||||
| 		if (hasFeaturesCarbon()) { | ||||
| 		if (getFeatures().carbons()) { | ||||
| 			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) { | ||||
| 		List<String> items = new ArrayList<String>(); | ||||
| 		for (Entry<String, List<String>> cursor : disco.entrySet()) { | ||||
|  | @ -903,4 +878,46 @@ public class XmppConnection implements Runnable { | |||
| 	public int getAttempt() { | ||||
| 		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"); | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue
	
	 iNPUTmice
						iNPUTmice