code clean up in contact details presence handling

Daniel Gultsch created

Change summary

build.gradle                                                        |  2 
src/main/java/eu/siacs/conversations/entities/Contact.java          |  5 
src/main/java/eu/siacs/conversations/ui/ContactDetailsActivity.java | 26 
3 files changed, 12 insertions(+), 21 deletions(-)

Detailed changes

build.gradle 🔗

@@ -35,7 +35,7 @@ dependencies {
         exclude group: 'com.google.firebase', module: 'firebase-core'
     }
     implementation 'org.sufficientlysecure:openpgp-api:10.0'
-    implementation 'com.theartofdev.edmodo:android-image-cropper:2.7.+'
+    implementation 'com.theartofdev.edmodo:android-image-cropper:2.7.0'
     implementation "com.android.support:support-v13:$supportLibVersion"
     implementation "com.android.support:appcompat-v7:$supportLibVersion"
     implementation "com.android.support:cardview-v7:$supportLibVersion"

src/main/java/eu/siacs/conversations/entities/Contact.java 🔗

@@ -340,7 +340,10 @@ public class Contact implements ListItem, Blockable {
 		String ask = item.getAttribute("ask");
 		String subscription = item.getAttribute("subscription");
 
-		if (subscription != null) {
+		if (subscription == null) {
+			this.resetOption(Options.FROM);
+			this.resetOption(Options.TO);
+		} else {
 			switch (subscription) {
 				case "to":
 					this.resetOption(Options.FROM);

src/main/java/eu/siacs/conversations/ui/ContactDetailsActivity.java 🔗

@@ -61,39 +61,27 @@ public class ContactDetailsActivity extends OmemoActivity implements OnAccountUp
 	private OnCheckedChangeListener mOnSendCheckedChange = new OnCheckedChangeListener() {
 
 		@Override
-		public void onCheckedChanged(CompoundButton buttonView,
-		                             boolean isChecked) {
+		public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
 			if (isChecked) {
-				if (contact
-						.getOption(Contact.Options.PENDING_SUBSCRIPTION_REQUEST)) {
-					xmppConnectionService.sendPresencePacket(contact
-									.getAccount(),
-							xmppConnectionService.getPresenceGenerator()
-									.sendPresenceUpdatesTo(contact));
+				if (contact.getOption(Contact.Options.PENDING_SUBSCRIPTION_REQUEST)) {
+					xmppConnectionService.sendPresencePacket(contact.getAccount(), xmppConnectionService.getPresenceGenerator().sendPresenceUpdatesTo(contact));
 				} else {
 					contact.setOption(Contact.Options.PREEMPTIVE_GRANT);
 				}
 			} else {
 				contact.resetOption(Contact.Options.PREEMPTIVE_GRANT);
-				xmppConnectionService.sendPresencePacket(contact.getAccount(),
-						xmppConnectionService.getPresenceGenerator()
-								.stopPresenceUpdatesTo(contact));
+				xmppConnectionService.sendPresencePacket(contact.getAccount(),xmppConnectionService.getPresenceGenerator().stopPresenceUpdatesTo(contact));
 			}
 		}
 	};
 	private OnCheckedChangeListener mOnReceiveCheckedChange = new OnCheckedChangeListener() {
 
 		@Override
-		public void onCheckedChanged(CompoundButton buttonView,
-		                             boolean isChecked) {
+		public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
 			if (isChecked) {
-				xmppConnectionService.sendPresencePacket(contact.getAccount(),
-						xmppConnectionService.getPresenceGenerator()
-								.requestPresenceUpdatesFrom(contact));
+				xmppConnectionService.sendPresencePacket(contact.getAccount(), xmppConnectionService.getPresenceGenerator().requestPresenceUpdatesFrom(contact));
 			} else {
-				xmppConnectionService.sendPresencePacket(contact.getAccount(),
-						xmppConnectionService.getPresenceGenerator()
-								.stopPresenceUpdatesFrom(contact));
+				xmppConnectionService.sendPresencePacket(contact.getAccount(), xmppConnectionService.getPresenceGenerator().stopPresenceUpdatesFrom(contact));
 			}
 		}
 	};