From 9bb16b424fe4b583f85e1405fb2ad59fbca04adb Mon Sep 17 00:00:00 2001
From: akwizgran <akwizgran@users.sourceforge.net>
Date: Thu, 20 Oct 2016 12:38:13 +0100
Subject: [PATCH] Moved revision counter methods into their own interface.

---
 .../android/threaded/ThreadItemAdapter.java   | 21 ++++-----------
 .../android/util/BriarAdapter.java            | 18 +++----------
 .../android/util/VersionedAdapter.java        | 26 +++++++++++++++++++
 3 files changed, 34 insertions(+), 31 deletions(-)
 create mode 100644 briar-android/src/org/briarproject/android/util/VersionedAdapter.java

diff --git a/briar-android/src/org/briarproject/android/threaded/ThreadItemAdapter.java b/briar-android/src/org/briarproject/android/threaded/ThreadItemAdapter.java
index 034b6924f4..c8ab7f2ba0 100644
--- a/briar-android/src/org/briarproject/android/threaded/ThreadItemAdapter.java
+++ b/briar-android/src/org/briarproject/android/threaded/ThreadItemAdapter.java
@@ -6,6 +6,7 @@ import android.support.annotation.UiThread;
 import android.support.v7.widget.LinearLayoutManager;
 import android.support.v7.widget.RecyclerView;
 
+import org.briarproject.android.util.VersionedAdapter;
 import org.briarproject.api.sync.MessageId;
 
 import java.util.ArrayList;
@@ -16,9 +17,9 @@ import java.util.Map;
 
 import static android.support.v7.widget.RecyclerView.NO_POSITION;
 
-@UiThread
 public abstract class ThreadItemAdapter<I extends ThreadItem>
-		extends RecyclerView.Adapter<ThreadItemViewHolder<I>> {
+		extends RecyclerView.Adapter<ThreadItemViewHolder<I>>
+		implements VersionedAdapter {
 
 	static final int UNDEFINED = -1;
 
@@ -292,25 +293,13 @@ public abstract class ThreadItemAdapter<I extends ThreadItem>
 		animatingItems.remove(item);
 	}
 
-	/**
-	 * Returns the adapter's revision counter. This method should be called on
-	 * any thread before starting an asynchronous load that could overwrite
-	 * other changes to the adapter, and called again on the UI thread before
-	 * applying the changes from the asynchronous load. If the revision has
-	 * changed between the two calls, the asynchronous load should be restarted
-	 * without applying its changes. Otherwise {@link #incrementRevision()}
-	 * should be called before applying the changes.
-	 */
+	@Override
 	public int getRevision() {
 		return revision;
 	}
 
-	/**
-	 * Increments the adapter's revision counter. This method should be called
-	 * on the UI thread before applying any changes to the adapter that could
-	 * be overwritten by an asynchronous load.
-	 */
 	@UiThread
+	@Override
 	public void incrementRevision() {
 		revision++;
 	}
diff --git a/briar-android/src/org/briarproject/android/util/BriarAdapter.java b/briar-android/src/org/briarproject/android/util/BriarAdapter.java
index eb566b8bd8..091dcc8a1b 100644
--- a/briar-android/src/org/briarproject/android/util/BriarAdapter.java
+++ b/briar-android/src/org/briarproject/android/util/BriarAdapter.java
@@ -12,7 +12,7 @@ import java.util.Collection;
 import static android.support.v7.util.SortedList.INVALID_POSITION;
 
 public abstract class BriarAdapter<T, V extends ViewHolder>
-		extends Adapter<V> {
+		extends Adapter<V> implements VersionedAdapter {
 
 	protected final Context ctx;
 	protected final SortedList<T> items;
@@ -113,25 +113,13 @@ public abstract class BriarAdapter<T, V extends ViewHolder>
 		return items.size() == 0;
 	}
 
-	/**
-	 * Returns the adapter's revision counter. This method should be called on
-	 * any thread before starting an asynchronous load that could overwrite
-	 * other changes to the adapter, and called again on the UI thread before
-	 * applying the changes from the asynchronous load. If the revision has
-	 * changed between the two calls, the asynchronous load should be restarted
-	 * without applying its changes. Otherwise {@link #incrementRevision()}
-	 * should be called before applying the changes.
-	 */
+	@Override
 	public int getRevision() {
 		return revision;
 	}
 
-	/**
-	 * Increments the adapter's revision counter. This method should be called
-	 * on the UI thread before applying any changes to the adapter that could
-	 * be overwritten by an asynchronous load.
-	 */
 	@UiThread
+	@Override
 	public void incrementRevision() {
 		revision++;
 	}
diff --git a/briar-android/src/org/briarproject/android/util/VersionedAdapter.java b/briar-android/src/org/briarproject/android/util/VersionedAdapter.java
new file mode 100644
index 0000000000..26df190cd2
--- /dev/null
+++ b/briar-android/src/org/briarproject/android/util/VersionedAdapter.java
@@ -0,0 +1,26 @@
+package org.briarproject.android.util;
+
+import android.support.annotation.UiThread;
+
+public interface VersionedAdapter {
+
+	/**
+	 * Returns the adapter's revision counter. This method should be called on
+	 * any thread before starting an asynchronous load that could overwrite
+	 * other changes to the adapter, and called again on the UI thread before
+	 * applying the changes from the asynchronous load. If the revision has
+	 * changed between the two calls, the asynchronous load should be restarted
+	 * without applying its changes. Otherwise {@link #incrementRevision()}
+	 * should be called before applying the changes.
+	 */
+	int getRevision();
+
+	/**
+	 * Increments the adapter's revision counter. This method should be called
+	 * on the UI thread before applying any changes to the adapter that could
+	 * be overwritten by an asynchronous load.
+	 */
+	@UiThread
+	void incrementRevision();
+
+}
-- 
GitLab