Fixed ThreadWatchCounterView not invalidating itself all the tme.

captchafix
Florens Douwes 12 years ago
parent c62c353f8d
commit 0d98a1abd9
  1. 8
      Chan/src/org/floens/chan/activity/BoardActivity.java
  2. 4
      Chan/src/org/floens/chan/adapter/PostAdapter.java
  3. 6
      Chan/src/org/floens/chan/manager/ThreadManager.java
  4. 29
      Chan/src/org/floens/chan/view/ThreadWatchCounterView.java
  5. 13
      Chan/src/org/floens/chan/watch/WatchLogic.java

@ -206,7 +206,7 @@ public class BoardActivity extends BaseActivity implements ActionBar.OnNavigatio
if (threadPane.isOpen()) { if (threadPane.isOpen()) {
boardFragment.reload(); boardFragment.reload();
} else { } else {
if (threadFragment.getThreadManager().hasThread()) { if (threadFragment.getThreadManager().hasLoadable()) {
threadFragment.reload(); threadFragment.reload();
} }
} }
@ -215,14 +215,14 @@ public class BoardActivity extends BaseActivity implements ActionBar.OnNavigatio
if (threadPane.isOpen()) { if (threadPane.isOpen()) {
boardFragment.getThreadManager().openReply(true); // todo if tablet boardFragment.getThreadManager().openReply(true); // todo if tablet
} else { } else {
if (threadFragment.getThreadManager().hasThread()) { if (threadFragment.getThreadManager().hasLoadable()) {
threadFragment.getThreadManager().openReply(true); // todo if tablet threadFragment.getThreadManager().openReply(true); // todo if tablet
} }
} }
return true; return true;
case R.id.action_pin: case R.id.action_pin:
if (threadFragment.getThreadManager().hasThread()) { if (threadFragment.getThreadManager().hasLoadable()) {
Pin pin = new Pin(); Pin pin = new Pin();
pin.loadable = threadLoadable; pin.loadable = threadLoadable;
@ -236,7 +236,7 @@ public class BoardActivity extends BaseActivity implements ActionBar.OnNavigatio
if (threadPane.isOpen()) { if (threadPane.isOpen()) {
showUrlOpenPicker(ChanUrls.getBoardUrlDesktop(boardLoadable.board)); showUrlOpenPicker(ChanUrls.getBoardUrlDesktop(boardLoadable.board));
} else { } else {
if (threadFragment.getThreadManager().hasThread()) { if (threadFragment.getThreadManager().hasLoadable()) {
showUrlOpenPicker(ChanUrls.getThreadUrlDesktop(threadLoadable.board, threadLoadable.no)); showUrlOpenPicker(ChanUrls.getThreadUrlDesktop(threadLoadable.board, threadLoadable.no));
} }
} }

@ -6,6 +6,7 @@ import java.util.List;
import org.floens.chan.R; import org.floens.chan.R;
import org.floens.chan.manager.ThreadManager; import org.floens.chan.manager.ThreadManager;
import org.floens.chan.model.Post; import org.floens.chan.model.Post;
import org.floens.chan.utils.ViewUtils;
import org.floens.chan.view.PostView; import org.floens.chan.view.PostView;
import org.floens.chan.view.ThreadWatchCounterView; import org.floens.chan.view.ThreadWatchCounterView;
@ -84,7 +85,8 @@ public class PostAdapter extends BaseAdapter {
private View createThreadEndView() { private View createThreadEndView() {
if (threadManager.getWatchLogic() != null) { if (threadManager.getWatchLogic() != null) {
ThreadWatchCounterView view = new ThreadWatchCounterView(context); ThreadWatchCounterView view = new ThreadWatchCounterView(context);
view.init(threadManager, listView); ViewUtils.setPressedDrawable(view);
view.init(threadManager, listView, this);
int padding = context.getResources().getDimensionPixelSize(R.dimen.general_padding); int padding = context.getResources().getDimensionPixelSize(R.dimen.general_padding);
view.setPadding(padding, padding, padding, padding); view.setPadding(padding, padding, padding, padding);
view.setGravity(Gravity.CENTER); view.setGravity(Gravity.CENTER);

@ -110,7 +110,7 @@ public class ThreadManager implements ThreadLoader.ThreadLoaderListener, WatchLi
threadListener.onThreadLoaded(result); threadListener.onThreadLoaded(result);
} }
public boolean hasThread() { public boolean hasLoadable() {
return loadable != null; return loadable != null;
} }
@ -125,6 +125,8 @@ public class ThreadManager implements ThreadLoader.ThreadLoaderListener, WatchLi
public void startLoading(Loadable loadable) { public void startLoading(Loadable loadable) {
this.loadable = loadable; this.loadable = loadable;
stop();
threadLoader.start(loadable); threadLoader.start(loadable);
Pin pin = PinnedManager.getInstance().findPinByLoadable(loadable); Pin pin = PinnedManager.getInstance().findPinByLoadable(loadable);
@ -157,8 +159,6 @@ public class ThreadManager implements ThreadLoader.ThreadLoaderListener, WatchLi
if (loadable == null) { if (loadable == null) {
Log.e("Chan", "ThreadManager: loadable null"); Log.e("Chan", "ThreadManager: loadable null");
} else { } else {
stop();
if (loadable.isBoardMode()) { if (loadable.isBoardMode()) {
loadable.no = 0; loadable.no = 0;
loadable.listViewIndex = 0; loadable.listViewIndex = 0;

@ -4,13 +4,16 @@ import org.floens.chan.manager.ThreadManager;
import org.floens.chan.watch.WatchLogic; import org.floens.chan.watch.WatchLogic;
import android.content.Context; import android.content.Context;
import android.os.Handler;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.view.View; import android.view.View;
import android.widget.BaseAdapter;
import android.widget.ListView; import android.widget.ListView;
import android.widget.TextView; import android.widget.TextView;
public class ThreadWatchCounterView extends TextView { public class ThreadWatchCounterView extends TextView implements View.OnClickListener {
private boolean detached = false; private boolean detached = false;
private ThreadManager tm;
public ThreadWatchCounterView(Context activity) { public ThreadWatchCounterView(Context activity) {
super(activity); super(activity);
@ -24,28 +27,21 @@ public class ThreadWatchCounterView extends TextView {
super(activity, attbs, style); super(activity, attbs, style);
} }
public void init(final ThreadManager threadManager, final ListView listView) { public void init(final ThreadManager threadManager, final ListView listView, final BaseAdapter adapter) {
updateCounterText(threadManager); tm = threadManager;
postInvalidateDelayed(1000); updateCounterText(threadManager);
postDelayed(new Runnable() { new Handler().postDelayed(new Runnable() {
@Override @Override
public void run() { public void run() {
if (!detached) { if (!detached) {
updateCounterText(threadManager); adapter.notifyDataSetChanged();
// TODO: This sometimes fails to recreate this view
listView.invalidateViews();
} }
} }
}, 1000); }, 1000);
setOnClickListener(new OnClickListener() { setOnClickListener(this);
@Override
public void onClick(View v) {
threadManager.loadMore();
}
});
} }
@Override @Override
@ -57,6 +53,11 @@ public class ThreadWatchCounterView extends TextView {
detached = true; detached = true;
} }
@Override
public void onClick(View v) {
tm.loadMore();
}
private void updateCounterText(ThreadManager threadManager) { private void updateCounterText(ThreadManager threadManager) {
WatchLogic logic = threadManager.getWatchLogic(); WatchLogic logic = threadManager.getWatchLogic();

@ -19,6 +19,9 @@ public class WatchLogic {
this.listener = listener; this.listener = listener;
} }
/**
* Stops the timer and removes the listener
*/
public void destroy() { public void destroy() {
this.listener = null; this.listener = null;
clearTimer(); clearTimer();
@ -36,12 +39,18 @@ public class WatchLogic {
scheduleTimer(); scheduleTimer();
} }
/**
* Stops the timer
*/
public void stopTimer() { public void stopTimer() {
Logger.test("WatchLogic timer paused"); Logger.test("WatchLogic timer paused");
clearTimer(); clearTimer();
} }
/**
* Call onWatchReloadRequested on the listener and reset the timer
*/
public void loadNow() { public void loadNow() {
clearTimer(); clearTimer();
lastLoadTime = 0; lastLoadTime = 0;
@ -54,7 +63,7 @@ public class WatchLogic {
/** /**
* Call this to notify of new posts. * Call this to notify of new posts.
* @param wereNewPosts set this to true when there were new posts, false otherwise * @param postCount how many posts there were loaded
*/ */
public void onLoaded(int postCount) { public void onLoaded(int postCount) {
Logger.test("WatchLogic onLoaded: " + (postCount > lastPostCount)); Logger.test("WatchLogic onLoaded: " + (postCount > lastPostCount));
@ -72,7 +81,7 @@ public class WatchLogic {
} }
/** /**
* Time time in ms left before a reload is necessary. * Time in ms left before a reload is necessary.
* @return * @return
*/ */
public long timeLeft() { public long timeLeft() {

Loading…
Cancel
Save