Added lastseenpost to loadables, fixed PinWatcher

captchafix
Florens Douwes 11 years ago
parent dc9419db3b
commit a9b32a3bb1
  1. 31
      Clover/app/src/main/java/org/floens/chan/core/manager/ThreadManager.java
  2. 35
      Clover/app/src/main/java/org/floens/chan/core/manager/WatchManager.java
  3. 7
      Clover/app/src/main/java/org/floens/chan/core/model/Loadable.java
  4. 40
      Clover/app/src/main/java/org/floens/chan/core/model/Pin.java
  5. 7
      Clover/app/src/main/java/org/floens/chan/core/model/Post.java
  6. 9
      Clover/app/src/main/java/org/floens/chan/core/watch/PinWatcher.java

@ -68,7 +68,6 @@ public class ThreadManager implements Loader.LoaderListener {
private final List<List<Post>> popupQueue = new ArrayList<>();
private PostRepliesFragment currentPopupFragment;
private int highlightedPost = -1;
private int lastSeenPost = -1;
private int lastPost = -1;
private Loader loader;
@ -118,18 +117,21 @@ public class ThreadManager implements Loader.LoaderListener {
}
highlightedPost = -1;
lastSeenPost = -1;
lastPost = -1;
}
public void bottomPostViewed() {
if (loader != null && loader.getLoadable().isThreadMode()) {
Pin pin = ChanApplication.getWatchManager().findPinByLoadable(loader.getLoadable());
if (pin != null) {
ChanApplication.getWatchManager().onPinViewed(pin);
List<Post> posts = loader.getCachedPosts();
if (posts.size() > 0) {
loader.getLoadable().lastViewed = posts.get(posts.size() - 1).no;
}
}
updateLastSeen();
Pin pin = ChanApplication.getWatchManager().findPinByLoadable(loader.getLoadable());
if (pin != null) {
pin.onBottomPostViewed();
ChanApplication.getWatchManager().onPinsChanged();
}
}
@ -176,7 +178,6 @@ public class ThreadManager implements Loader.LoaderListener {
if (result.size() > 0) {
lastPost = result.get(result.size() - 1).no;
}
updateLastSeen();
threadManagerListener.onThreadLoaded(result, append);
}
@ -297,7 +298,7 @@ public class ThreadManager implements Loader.LoaderListener {
}
public boolean isPostLastSeen(Post post) {
return post.no == lastSeenPost && post.no != lastPost;
return post.no == loader.getLoadable().lastViewed && post.no != lastPost;
}
private void copyToClipboard(String comment) {
@ -564,20 +565,6 @@ public class ThreadManager implements Loader.LoaderListener {
});
}
private void updateLastSeen() {
if (ChanApplication.getWatchManager().getWatchEnabled()) {
Pin pin = ChanApplication.getWatchManager().findPinByLoadable(loader.getLoadable());
if (pin != null) {
Post last = pin.getLastSeenPost();
if (last != null) {
lastSeenPost = last.no;
} else {
lastSeenPost = -1;
}
}
}
}
public interface ThreadManagerListener {
public void onThreadLoaded(List<Post> result, boolean append);

@ -55,6 +55,7 @@ public class WatchManager implements ChanApplication.ForegroundChangedListener {
updateTimerState();
updateNotificationServiceState();
updatePinWatchers();
}
/**
@ -134,7 +135,6 @@ public class WatchManager implements ChanApplication.ForegroundChangedListener {
public void removePin(Pin pin) {
pins.remove(pin);
ChanApplication.getDatabaseManager().removePin(pin);
pin.destroy();
onPinsChanged();
}
@ -164,13 +164,6 @@ public class WatchManager implements ChanApplication.ForegroundChangedListener {
}).start();
}
public void onPinViewed(Pin pin) {
if (getWatchEnabled()) {
pin.getPinWatcher().onViewed();
onPinsChanged();
}
}
public void addPinListener(PinListener l) {
listeners.add(l);
}
@ -186,6 +179,7 @@ public class WatchManager implements ChanApplication.ForegroundChangedListener {
updateTimerState();
updateNotificationServiceState();
updatePinWatchers();
}
public void pausePins() {
@ -201,11 +195,12 @@ public class WatchManager implements ChanApplication.ForegroundChangedListener {
public void onWatchEnabledChanged(boolean watchEnabled) {
updateNotificationServiceState(watchEnabled, getWatchBackgroundEnabled());
updateTimerState(watchEnabled, getWatchBackgroundEnabled());
updatePinWatchers(watchEnabled);
}
public void onBackgroundWatchingChanged(boolean backgroundEnabled) {
updateNotificationServiceState(getWatchEnabled(), backgroundEnabled);
updateTimerState(getWatchEnabled(), backgroundEnabled);
updateNotificationServiceState(getTimerEnabled(), backgroundEnabled);
updateTimerState(getTimerEnabled(), backgroundEnabled);
}
@Override
@ -214,7 +209,7 @@ public class WatchManager implements ChanApplication.ForegroundChangedListener {
updateTimerState();
}
public boolean getWatchEnabled() {
private boolean getTimerEnabled() {
// getWatchingPins returns an empty list when ChanPreferences.getWatchEnabled() is false
return getWatchingPins().size() > 0;
}
@ -223,8 +218,22 @@ public class WatchManager implements ChanApplication.ForegroundChangedListener {
return ChanPreferences.getWatchBackgroundEnabled();
}
private void updatePinWatchers() {
updatePinWatchers(ChanPreferences.getWatchEnabled());
}
private void updatePinWatchers(boolean watchEnabled) {
for (Pin pin : pins) {
if (watchEnabled) {
pin.createWatcher();
} else {
pin.destroyWatcher();
}
}
}
private void updateNotificationServiceState() {
updateNotificationServiceState(getWatchEnabled(), getWatchBackgroundEnabled());
updateNotificationServiceState(getTimerEnabled(), getWatchBackgroundEnabled());
}
private void updateNotificationServiceState(boolean watchEnabled, boolean backgroundEnabled) {
@ -237,7 +246,7 @@ public class WatchManager implements ChanApplication.ForegroundChangedListener {
}
private void updateTimerState() {
updateTimerState(getWatchEnabled(), getWatchBackgroundEnabled());
updateTimerState(getTimerEnabled(), getWatchBackgroundEnabled());
}
private void updateTimerState(boolean watchEnabled, boolean backgroundEnabled) {

@ -49,11 +49,7 @@ public class Loadable {
@DatabaseField
public int listViewTop;
/**
* When simple mode is enabled, CPU intensive methods won't get called. This
* is used for the thread watcher.
*/
public boolean simpleMode = false;
public int lastViewed = -1;
/**
* Constructs an empty loadable. The mode is INVALID.
@ -171,7 +167,6 @@ public class Loadable {
copy.title = title;
copy.listViewIndex = listViewIndex;
copy.listViewTop = listViewTop;
copy.simpleMode = simpleMode;
return copy;
}

@ -31,8 +31,6 @@ public class Pin {
@DatabaseField(canBeNull = false, foreign = true)
public Loadable loadable = new Loadable("", -1);
public PinWatcher pinWatcher;
@DatabaseField
public boolean watching = true;
@ -50,6 +48,8 @@ public class Pin {
public boolean isError = false;
private PinWatcher pinWatcher;
public int getNewPostsCount() {
if (watchLastCount < 0 || watchNewCount < 0) {
return 0;
@ -62,15 +62,29 @@ public class Pin {
return Math.max(0, quoteNewCount - quoteLastCount);
}
public Post getLastSeenPost() {
return getPinWatcher().getLastSeenPost();
public PinWatcher getPinWatcher() {
return pinWatcher;
}
public void onBottomPostViewed() {
if (pinWatcher != null) {
pinWatcher.onViewed();
}
}
public void update() {
getPinWatcher().update();
if (pinWatcher != null) {
pinWatcher.update();
}
}
public void createWatcher() {
if (pinWatcher == null) {
pinWatcher = new PinWatcher(this);
}
}
public void destroy() {
public void destroyWatcher() {
if (pinWatcher != null) {
pinWatcher.destroy();
pinWatcher = null;
@ -81,16 +95,8 @@ public class Pin {
watching = !watching;
ChanApplication.getWatchManager().onPinsChanged();
if (watching) {
getPinWatcher().update();
}
}
public PinWatcher getPinWatcher() {
if (pinWatcher == null) {
pinWatcher = new PinWatcher(this);
}
return pinWatcher;
// if (watching && pinWatcher != null) {
// .update();
// }
}
}

@ -141,7 +141,7 @@ public class Post {
}
if (rawComment != null) {
comment = parseComment(rawComment, loadable.simpleMode);
comment = parseComment(rawComment);
}
try {
@ -159,10 +159,7 @@ public class Post {
return true;
}
private CharSequence parseComment(String commentRaw, boolean simpleMode) {
if (simpleMode)
return "";
private CharSequence parseComment(String commentRaw) {
CharSequence total = new SpannableString("");
try {

@ -104,15 +104,6 @@ public class PinWatcher implements Loader.LoaderListener {
}
}
public Post getLastSeenPost() {
int i = posts.size() - pin.getNewPostsCount() - 1;
if (i >= 0 && i < posts.size()) {
return posts.get(i);
} else {
return null;
}
}
@Override
public void onError(VolleyError error) {
Logger.e(TAG, "PinWatcher onError: ", error);

Loading…
Cancel
Save