refresh ui after device list update only if list has changed

Daniel Gultsch created

Change summary

src/main/java/eu/siacs/conversations/crypto/axolotl/AxolotlService.java | 13 
src/main/java/eu/siacs/conversations/parser/MessageParser.java          |  1 
src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java  |  5 
3 files changed, 13 insertions(+), 6 deletions(-)

Detailed changes

src/main/java/eu/siacs/conversations/crypto/axolotl/AxolotlService.java 🔗

@@ -483,9 +483,18 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded {
 				publishOwnDeviceId(deviceIds);
 			}
 		}
+		final Set<Integer> oldSet = this.deviceIds.get(jid);
+		final boolean changed = oldSet == null || oldSet.hashCode() != hash;
 		this.deviceIds.put(jid, deviceIds);
-		mXmppConnectionService.updateConversationUi(); //update the lock icon
-		mXmppConnectionService.keyStatusUpdated(null);
+		if (changed) {
+			mXmppConnectionService.updateConversationUi(); //update the lock icon
+			mXmppConnectionService.keyStatusUpdated(null);
+			if (me) {
+				mXmppConnectionService.updateAccountUi();
+			}
+		} else {
+			Log.d(Config.LOGTAG,"skipped device list update because it hasn't changed");
+		}
 	}
 
 	public void wipeOtherPepDevices() {

src/main/java/eu/siacs/conversations/parser/MessageParser.java 🔗

@@ -211,7 +211,6 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece
 			Log.d(Config.LOGTAG, AxolotlService.getLogprefix(account) + "Received PEP device list " + deviceIds + " update from " + from + ", processing... ");
 			AxolotlService axolotlService = account.getAxolotlService();
 			axolotlService.registerDevices(from, deviceIds);
-			mXmppConnectionService.updateAccountUi();
 		} else if (Namespace.BOOKMARKS.equals(node)) {
 			Log.d(Config.LOGTAG,"received bookmarks from "+from);
 			if (account.getJid().asBareJid().equals(from)) {

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

@@ -1110,13 +1110,13 @@ public class StartConversationActivity extends XmppActivity implements XmppConne
 
 		@Override
 		public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
-			assert (0 <= position && position < fragments.length);
 			FragmentTransaction trans = fragmentManager.beginTransaction();
 			trans.remove(fragments[position]);
 			trans.commit();
 			fragments[position] = null;
 		}
 
+		@NonNull
 		@Override
 		public Fragment instantiateItem(@NonNull ViewGroup container, int position) {
 			Fragment fragment = getItem(position);
@@ -1149,8 +1149,7 @@ public class StartConversationActivity extends XmppActivity implements XmppConne
 			}
 		}
 
-		public Fragment getItem(int position) {
-			assert (0 <= position && position < fragments.length);
+		Fragment getItem(int position) {
 			if (fragments[position] == null) {
 				final MyListFragment listFragment = new MyListFragment();
 				if (position == 1) {