No watching when the thread is closed.

captchafix
Florens Douwes 11 years ago
parent f5181f7922
commit b229ad3cc6
  1. 2
      Chan/src/org/floens/chan/ChanApplication.java
  2. 5
      Chan/src/org/floens/chan/core/loader/Loader.java
  3. 21
      Chan/src/org/floens/chan/core/manager/ThreadManager.java
  4. 4
      Chan/src/org/floens/chan/ui/adapter/PostAdapter.java

@ -22,7 +22,7 @@ import com.android.volley.toolbox.ImageLoader;
import com.android.volley.toolbox.Volley; import com.android.volley.toolbox.Volley;
public class ChanApplication extends Application implements PinListener { public class ChanApplication extends Application implements PinListener {
public static final boolean DEVELOPER_MODE = false; public static final boolean DEVELOPER_MODE = true;
private static ChanApplication instance; private static ChanApplication instance;
private static RequestQueue volleyRequestQueue; private static RequestQueue volleyRequestQueue;

@ -175,6 +175,10 @@ public class Loader {
return lastLoadTime + waitTime - System.currentTimeMillis(); return lastLoadTime + waitTime - System.currentTimeMillis();
} }
} }
public List<Post> getCachedPosts() {
return cachedPosts;
}
private void setTimer(int postCount) { private void setTimer(int postCount) {
clearTimer(); clearTimer();
@ -259,6 +263,7 @@ public class Loader {
} }
lastLoadTime = System.currentTimeMillis(); lastLoadTime = System.currentTimeMillis();
if (loadable.isThreadMode()) { if (loadable.isThreadMode()) {
setTimer(result.size()); setTimer(result.size());
} }

@ -65,7 +65,7 @@ public class ThreadManager implements Loader.LoaderListener {
public void onStart() { public void onStart() {
if (loader != null) { if (loader != null) {
if (loader.getLoadable().isThreadMode()) { if (shouldWatch()) {
loader.setAutoLoadMore(true); loader.setAutoLoadMore(true);
loader.requestMoreDataAndResetTimer(); loader.requestMoreDataAndResetTimer();
} }
@ -84,7 +84,7 @@ public class ThreadManager implements Loader.LoaderListener {
} }
loader = LoaderPool.getInstance().obtain(loadable, this); loader = LoaderPool.getInstance().obtain(loadable, this);
if (loadable.isThreadMode()) { if (shouldWatch()) {
loader.setAutoLoadMore(true); loader.setAutoLoadMore(true);
} }
} }
@ -110,6 +110,11 @@ public class ThreadManager implements Loader.LoaderListener {
} }
} }
public boolean shouldWatch() {
boolean closed = loader.getCachedPosts().size() > 0 && loader.getCachedPosts().get(0).closed;
return loader.getLoadable().isThreadMode() && !closed;
}
public void requestData() { public void requestData() {
if (loader != null) { if (loader != null) {
loader.requestData(); loader.requestData();
@ -136,6 +141,10 @@ public class ThreadManager implements Loader.LoaderListener {
@Override @Override
public void onData(List<Post> result, boolean append) { public void onData(List<Post> result, boolean append) {
if (!shouldWatch()) {
loader.setAutoLoadMore(false);
}
threadManagerListener.onThreadLoaded(result, append); threadManagerListener.onThreadLoaded(result, append);
} }
@ -292,7 +301,7 @@ public class ThreadManager implements Loader.LoaderListener {
* When the user clicks a post: a. when there's one linkable, open the * When the user clicks a post: a. when there's one linkable, open the
* linkable. b. when there's more than one linkable, show the user multiple * linkable. b. when there's more than one linkable, show the user multiple
* options to select from. * options to select from.
* *
* @param post * @param post
* The post that was clicked. * The post that was clicked.
*/ */
@ -338,7 +347,7 @@ public class ThreadManager implements Loader.LoaderListener {
/** /**
* Handle when a linkable has been clicked. * Handle when a linkable has been clicked.
* *
* @param linkable * @param linkable
* the selected linkable. * the selected linkable.
*/ */
@ -369,7 +378,7 @@ public class ThreadManager implements Loader.LoaderListener {
/** /**
* When a linkable to a post has been clicked, show a dialog with the * When a linkable to a post has been clicked, show a dialog with the
* referenced post in it. * referenced post in it.
* *
* @param linkable * @param linkable
* the clicked linkable. * the clicked linkable.
*/ */
@ -399,7 +408,7 @@ public class ThreadManager implements Loader.LoaderListener {
/** /**
* Open an url. * Open an url.
* *
* @param linkable * @param linkable
* Linkable with an url. * Linkable with an url.
*/ */

@ -37,7 +37,7 @@ public class PostAdapter extends BaseAdapter {
@Override @Override
public int getCount() { public int getCount() {
if (threadManager.getLoadable().isBoardMode() || threadManager.getLoadable().isThreadMode()) { if (threadManager.getLoadable().isBoardMode() || threadManager.shouldWatch()) {
return postList.size() + 1; return postList.size() + 1;
} else { } else {
return postList.size(); return postList.size();
@ -86,7 +86,7 @@ public class PostAdapter extends BaseAdapter {
} }
private View createThreadEndView() { private View createThreadEndView() {
if (threadManager.getLoadable().isThreadMode()) { if (threadManager.shouldWatch()) {
ThreadWatchCounterView view = new ThreadWatchCounterView(context); ThreadWatchCounterView view = new ThreadWatchCounterView(context);
Utils.setPressedDrawable(view); Utils.setPressedDrawable(view);
view.init(threadManager, listView, this); view.init(threadManager, listView, this);

Loading…
Cancel
Save