Basic logic for load more in comments fragments. Parts may be broken, still need to reload models on success

pull/14/head
Sam Bosley 11 years ago
parent 0bc9b0b253
commit f30b1044c2

@ -15,6 +15,7 @@ import android.content.Intent;
import android.content.res.Resources;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
@ -26,6 +27,7 @@ import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.view.ViewGroup;
import android.view.inputmethod.EditorInfo;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ListView;
@ -62,6 +64,7 @@ public abstract class CommentsFragment extends SherlockListFragment {
protected UpdateAdapter updateAdapter;
protected EditText addCommentField;
protected ViewGroup listHeader;
protected Button footerView = null;
protected ImageButton pictureButton;
@ -120,6 +123,10 @@ public abstract class CommentsFragment extends SherlockListFragment {
protected abstract void performFetch(boolean manual, SyncMessageCallback done);
protected abstract boolean canLoadMoreHistory();
protected abstract void loadMoreHistory(int offset, SyncMessageCallback callback);
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
@ -266,32 +273,47 @@ public abstract class CommentsFragment extends SherlockListFragment {
if (activity instanceof CommentsActivity)
setLastViewed();
if (footerView != null) {
listView.removeFooterView(footerView);
if (canLoadMoreHistory()) {
footerView = new Button(getActivity());
footerView.setText(R.string.TEA_load_more);
footerView.setBackgroundColor(Color.alpha(0));
footerView.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
loadMoreHistory(0, doneRunnable);
}
});
}
}
}
protected void setLastViewed() {
//
}
private final SyncMessageCallback doneRunnable = new SyncMessageCallback() {
@Override
public void runOnSuccess() {
synchronized (this) {
Activity activity = getActivity();
if (activity != null)
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
refreshUpdatesList();
}
});
}
}
@Override
public void runOnErrors(List<JSONArray> errors) {/**/}
};
protected void refreshActivity(boolean manual) {
if (actFmPreferenceService.isLoggedIn()) {
SyncMessageCallback doneRunnable = new SyncMessageCallback() {
@Override
public void runOnSuccess() {
synchronized (this) {
Activity activity = getActivity();
if (activity != null)
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
refreshUpdatesList();
}
});
}
}
@Override
public void runOnErrors(List<JSONArray> errors) {/**/}
};
if (hasModel()) {
performFetch(manual, doneRunnable);
} else {

@ -88,6 +88,17 @@ public class TagCommentsFragment extends CommentsFragment {
return (tagData == null) ? UpdateAdapter.FROM_RECENT_ACTIVITY_VIEW : UpdateAdapter.FROM_TAG_VIEW;
}
@Override
protected boolean canLoadMoreHistory() {
return tagData.getValue(TagData.HISTORY_HAS_MORE) > 0;
}
@Override
protected void loadMoreHistory(int offset, SyncMessageCallback callback) {
new FetchHistory<TagData>(tagDataDao, TagData.HISTORY_FETCH_DATE, TagData.HISTORY_HAS_MORE, NameMaps.TABLE_ID_TAGS,
tagData.getUuid(), null, 0, offset, true, callback).execute();
}
@Override
protected void addHeaderToListView(ListView listView) {
if (AstridPreferences.useTabletLayout(getActivity()) && tagData != null) {

@ -79,6 +79,17 @@ public class TaskCommentsFragment extends CommentsFragment {
// Do nothing
}
@Override
protected boolean canLoadMoreHistory() {
return task.getValue(Task.HISTORY_HAS_MORE) > 0;
}
@Override
protected void loadMoreHistory(int offset, SyncMessageCallback callback) {
new FetchHistory<Task>(taskDao, Task.HISTORY_FETCH_DATE, Task.HISTORY_HAS_MORE, NameMaps.TABLE_ID_TASKS,
task.getUuid(), task.getValue(Task.TITLE), 0, offset, false, callback).execute();
}
@Override
protected void performFetch(boolean manual, SyncMessageCallback done) {
if (task != null) {

Loading…
Cancel
Save