diff --git a/briar-android/src/org/briarproject/android/threaded/ThreadItemAdapter.java b/briar-android/src/org/briarproject/android/threaded/ThreadItemAdapter.java index 034b6924f45500b074dddf1a5421a5a8f598311e..c8ab7f2ba0bf173f8688939167c40db894683663 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 eb566b8bd8e41c27b371ae27d2313d4a6d303f60..091dcc8a1b4f2a87df741142fd1ea8fbc3cf548e 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 0000000000000000000000000000000000000000..26df190cd2e124e96facd474e506f180f0ceb951 --- /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(); + +}