mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-17 05:09:53 +01:00
Moved revision counter methods into their own interface.
This commit is contained in:
@@ -6,6 +6,7 @@ import android.support.annotation.UiThread;
|
|||||||
import android.support.v7.widget.LinearLayoutManager;
|
import android.support.v7.widget.LinearLayoutManager;
|
||||||
import android.support.v7.widget.RecyclerView;
|
import android.support.v7.widget.RecyclerView;
|
||||||
|
|
||||||
|
import org.briarproject.android.util.VersionedAdapter;
|
||||||
import org.briarproject.api.sync.MessageId;
|
import org.briarproject.api.sync.MessageId;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -16,9 +17,9 @@ import java.util.Map;
|
|||||||
|
|
||||||
import static android.support.v7.widget.RecyclerView.NO_POSITION;
|
import static android.support.v7.widget.RecyclerView.NO_POSITION;
|
||||||
|
|
||||||
@UiThread
|
|
||||||
public abstract class ThreadItemAdapter<I extends ThreadItem>
|
public abstract class ThreadItemAdapter<I extends ThreadItem>
|
||||||
extends RecyclerView.Adapter<ThreadItemViewHolder<I>> {
|
extends RecyclerView.Adapter<ThreadItemViewHolder<I>>
|
||||||
|
implements VersionedAdapter {
|
||||||
|
|
||||||
static final int UNDEFINED = -1;
|
static final int UNDEFINED = -1;
|
||||||
|
|
||||||
@@ -292,25 +293,13 @@ public abstract class ThreadItemAdapter<I extends ThreadItem>
|
|||||||
animatingItems.remove(item);
|
animatingItems.remove(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
@Override
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
public int getRevision() {
|
public int getRevision() {
|
||||||
return revision;
|
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
|
@UiThread
|
||||||
|
@Override
|
||||||
public void incrementRevision() {
|
public void incrementRevision() {
|
||||||
revision++;
|
revision++;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import java.util.Collection;
|
|||||||
import static android.support.v7.util.SortedList.INVALID_POSITION;
|
import static android.support.v7.util.SortedList.INVALID_POSITION;
|
||||||
|
|
||||||
public abstract class BriarAdapter<T, V extends ViewHolder>
|
public abstract class BriarAdapter<T, V extends ViewHolder>
|
||||||
extends Adapter<V> {
|
extends Adapter<V> implements VersionedAdapter {
|
||||||
|
|
||||||
protected final Context ctx;
|
protected final Context ctx;
|
||||||
protected final SortedList<T> items;
|
protected final SortedList<T> items;
|
||||||
@@ -113,25 +113,13 @@ public abstract class BriarAdapter<T, V extends ViewHolder>
|
|||||||
return items.size() == 0;
|
return items.size() == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
@Override
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
public int getRevision() {
|
public int getRevision() {
|
||||||
return revision;
|
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
|
@UiThread
|
||||||
|
@Override
|
||||||
public void incrementRevision() {
|
public void incrementRevision() {
|
||||||
revision++;
|
revision++;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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();
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user