mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-19 06:09:55 +01:00
Initialise adapter in onCreate() to avoid double refreshing.
This commit is contained in:
@@ -9,7 +9,6 @@ import android.content.Intent;
|
|||||||
import android.graphics.drawable.ColorDrawable;
|
import android.graphics.drawable.ColorDrawable;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.annotation.NonNull;
|
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
import android.support.design.widget.Snackbar;
|
import android.support.design.widget.Snackbar;
|
||||||
import android.support.v4.app.ActivityCompat;
|
import android.support.v4.app.ActivityCompat;
|
||||||
@@ -63,9 +62,9 @@ public class ForumActivity extends BriarActivity implements
|
|||||||
ForumController.ForumPostListener {
|
ForumController.ForumPostListener {
|
||||||
|
|
||||||
static final String FORUM_NAME = "briar.FORUM_NAME";
|
static final String FORUM_NAME = "briar.FORUM_NAME";
|
||||||
private static final int REQUEST_FORUM_SHARED = 3;
|
|
||||||
|
|
||||||
private final static int UNDEFINED = -1;
|
private static final int REQUEST_FORUM_SHARED = 3;
|
||||||
|
private static final int UNDEFINED = -1;
|
||||||
private static final String KEY_INPUT_VISIBILITY = "inputVisibility";
|
private static final String KEY_INPUT_VISIBILITY = "inputVisibility";
|
||||||
private static final String KEY_REPLY_ID = "replyId";
|
private static final String KEY_REPLY_ID = "replyId";
|
||||||
|
|
||||||
@@ -77,6 +76,9 @@ public class ForumActivity extends BriarActivity implements
|
|||||||
@Inject
|
@Inject
|
||||||
protected ForumController forumController;
|
protected ForumController forumController;
|
||||||
|
|
||||||
|
// Protected access for testing
|
||||||
|
protected ForumAdapter forumAdapter;
|
||||||
|
|
||||||
private BriarRecyclerView recyclerView;
|
private BriarRecyclerView recyclerView;
|
||||||
private EditText textInput;
|
private EditText textInput;
|
||||||
private ViewGroup inputContainer;
|
private ViewGroup inputContainer;
|
||||||
@@ -84,8 +86,6 @@ public class ForumActivity extends BriarActivity implements
|
|||||||
|
|
||||||
private volatile GroupId groupId = null;
|
private volatile GroupId groupId = null;
|
||||||
|
|
||||||
protected ForumAdapter forumAdapter;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(final Bundle state) {
|
public void onCreate(final Bundle state) {
|
||||||
super.onCreate(state);
|
super.onCreate(state);
|
||||||
@@ -99,50 +99,46 @@ public class ForumActivity extends BriarActivity implements
|
|||||||
String forumName = i.getStringExtra(FORUM_NAME);
|
String forumName = i.getStringExtra(FORUM_NAME);
|
||||||
if (forumName != null) setTitle(forumName);
|
if (forumName != null) setTitle(forumName);
|
||||||
|
|
||||||
|
forumAdapter = new ForumAdapter();
|
||||||
|
|
||||||
inputContainer = (ViewGroup) findViewById(R.id.text_input_container);
|
inputContainer = (ViewGroup) findViewById(R.id.text_input_container);
|
||||||
inputContainer.setVisibility(GONE);
|
inputContainer.setVisibility(GONE);
|
||||||
textInput = (EditText) findViewById(R.id.input_text);
|
textInput = (EditText) findViewById(R.id.input_text);
|
||||||
recyclerView =
|
recyclerView =
|
||||||
(BriarRecyclerView) findViewById(R.id.forum_discussion_list);
|
(BriarRecyclerView) findViewById(R.id.forum_discussion_list);
|
||||||
|
recyclerView.setAdapter(forumAdapter);
|
||||||
linearLayoutManager = new LinearLayoutManager(this);
|
linearLayoutManager = new LinearLayoutManager(this);
|
||||||
recyclerView.setLayoutManager(linearLayoutManager);
|
recyclerView.setLayoutManager(linearLayoutManager);
|
||||||
recyclerView.setEmptyText(getString(R.string.no_forum_posts));
|
recyclerView.setEmptyText(getString(R.string.no_forum_posts));
|
||||||
recyclerView.showProgressBar();
|
recyclerView.showProgressBar();
|
||||||
|
|
||||||
forumController.loadForum(groupId,
|
forumController.loadForum(groupId, new UiResultHandler<Boolean>(this) {
|
||||||
new UiResultHandler<Boolean>(this) {
|
@Override
|
||||||
@Override
|
public void onResultUi(Boolean result) {
|
||||||
public void onResultUi(Boolean result) {
|
if (result) {
|
||||||
if (result) {
|
Forum forum = forumController.getForum();
|
||||||
Forum forum = forumController.getForum();
|
if (forum != null) setTitle(forum.getName());
|
||||||
if (forum != null) setTitle(forum.getName());
|
forumAdapter.setEntries(forumController.getForumEntries());
|
||||||
forumAdapter = new ForumAdapter(
|
if (state != null) {
|
||||||
forumController.getForumEntries());
|
byte[] replyId = state.getByteArray(KEY_REPLY_ID);
|
||||||
recyclerView.setAdapter(forumAdapter);
|
if (replyId != null)
|
||||||
recyclerView.startPeriodicUpdate();
|
forumAdapter.setReplyEntryById(replyId);
|
||||||
if (state != null) {
|
|
||||||
byte[] replyId =
|
|
||||||
state.getByteArray(KEY_REPLY_ID);
|
|
||||||
if (replyId != null) {
|
|
||||||
forumAdapter.setReplyEntryById(replyId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
recyclerView.showData();
|
|
||||||
} else {
|
|
||||||
// TODO Maybe an error dialog ?
|
|
||||||
finish();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
recyclerView.showData();
|
||||||
|
} else {
|
||||||
|
// TODO Maybe an error dialog ?
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onRestoreInstanceState(Bundle savedInstanceState) {
|
protected void onRestoreInstanceState(Bundle savedInstanceState) {
|
||||||
super.onRestoreInstanceState(savedInstanceState);
|
super.onRestoreInstanceState(savedInstanceState);
|
||||||
inputContainer
|
inputContainer.setVisibility(
|
||||||
.setVisibility(
|
savedInstanceState.getBoolean(KEY_INPUT_VISIBILITY) ?
|
||||||
savedInstanceState.getBoolean(KEY_INPUT_VISIBILITY) ?
|
VISIBLE : GONE);
|
||||||
VISIBLE : GONE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -250,18 +246,14 @@ public class ForumActivity extends BriarActivity implements
|
|||||||
super.onResume();
|
super.onResume();
|
||||||
notificationManager.blockNotification(groupId);
|
notificationManager.blockNotification(groupId);
|
||||||
notificationManager.clearForumPostNotification(groupId);
|
notificationManager.clearForumPostNotification(groupId);
|
||||||
if (recyclerView.getRecyclerView().getAdapter() != null) {
|
recyclerView.startPeriodicUpdate();
|
||||||
recyclerView.startPeriodicUpdate();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPause() {
|
public void onPause() {
|
||||||
super.onPause();
|
super.onPause();
|
||||||
notificationManager.unblockNotification(groupId);
|
notificationManager.unblockNotification(groupId);
|
||||||
if (recyclerView.getRecyclerView().getAdapter() != null) {
|
recyclerView.stopPeriodicUpdate();
|
||||||
recyclerView.stopPeriodicUpdate();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendMessage(View view) {
|
public void sendMessage(View view) {
|
||||||
@@ -373,23 +365,25 @@ public class ForumActivity extends BriarActivity implements
|
|||||||
|
|
||||||
public class ForumAdapter extends RecyclerView.Adapter<ForumViewHolder> {
|
public class ForumAdapter extends RecyclerView.Adapter<ForumViewHolder> {
|
||||||
|
|
||||||
private final List<ForumEntry> forumEntries;
|
private final List<ForumEntry> forumEntries = new ArrayList<>();
|
||||||
|
private final Map<ForumEntry, ValueAnimator> animatingEntries =
|
||||||
|
new HashMap<>();
|
||||||
|
|
||||||
// highlight not dependant on time
|
// highlight not dependant on time
|
||||||
private ForumEntry replyEntry;
|
private ForumEntry replyEntry;
|
||||||
// temporary highlight
|
// temporary highlight
|
||||||
private ForumEntry addedEntry;
|
private ForumEntry addedEntry;
|
||||||
Map<ForumEntry, ValueAnimator> animatingEntries = new HashMap<>();
|
|
||||||
|
|
||||||
ForumAdapter(@NonNull List<ForumEntry> forumEntries) {
|
|
||||||
this.forumEntries = forumEntries;
|
|
||||||
}
|
|
||||||
|
|
||||||
private ForumEntry getReplyEntry() {
|
private ForumEntry getReplyEntry() {
|
||||||
return replyEntry;
|
return replyEntry;
|
||||||
}
|
}
|
||||||
|
|
||||||
void addEntry(int index, ForumEntry entry,
|
void setEntries(List<ForumEntry> entries) {
|
||||||
boolean isScrolling) {
|
forumEntries.clear();
|
||||||
|
forumEntries.addAll(entries);
|
||||||
|
}
|
||||||
|
|
||||||
|
void addEntry(int index, ForumEntry entry, boolean isScrolling) {
|
||||||
forumEntries.add(index, entry);
|
forumEntries.add(index, entry);
|
||||||
boolean isShowingDescendants = false;
|
boolean isShowingDescendants = false;
|
||||||
if (entry.getLevel() > 0) {
|
if (entry.getLevel() > 0) {
|
||||||
@@ -559,7 +553,7 @@ public class ForumActivity extends BriarActivity implements
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
|
@TargetApi(11)
|
||||||
private void animateFadeOut(final ForumViewHolder ui,
|
private void animateFadeOut(final ForumViewHolder ui,
|
||||||
final ForumEntry addedEntry) {
|
final ForumEntry addedEntry) {
|
||||||
ui.setIsRecyclable(false);
|
ui.setIsRecyclable(false);
|
||||||
@@ -605,8 +599,8 @@ public class ForumActivity extends BriarActivity implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ForumViewHolder onCreateViewHolder(
|
public ForumViewHolder onCreateViewHolder(ViewGroup parent,
|
||||||
ViewGroup parent, int viewType) {
|
int viewType) {
|
||||||
View v = LayoutInflater.from(parent.getContext())
|
View v = LayoutInflater.from(parent.getContext())
|
||||||
.inflate(R.layout.forum_discussion_cell, parent, false);
|
.inflate(R.layout.forum_discussion_cell, parent, false);
|
||||||
return new ForumViewHolder(v);
|
return new ForumViewHolder(v);
|
||||||
@@ -730,5 +724,4 @@ public class ForumActivity extends BriarActivity implements
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import org.briarproject.android.forum.ForumControllerImpl;
|
|||||||
import org.mockito.Mockito;
|
import org.mockito.Mockito;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class exposes the SetupController and offers the possibility to
|
* This class exposes the ForumController and offers the possibility to
|
||||||
* override it.
|
* override it.
|
||||||
*/
|
*/
|
||||||
public class TestForumActivity extends ForumActivity {
|
public class TestForumActivity extends ForumActivity {
|
||||||
|
|||||||
Reference in New Issue
Block a user