Set timer to 1s when starting the app/toggling watching a pin

captchafix
Florens Douwes 11 years ago
parent a9b32a3bb1
commit 71ce93b625
  1. 30
      Clover/app/src/main/java/org/floens/chan/core/manager/WatchManager.java
  2. 7
      Clover/app/src/main/java/org/floens/chan/core/model/Pin.java

@ -53,7 +53,7 @@ public class WatchManager implements ChanApplication.ForegroundChangedListener {
ChanApplication.getInstance().addForegroundChangedListener(this); ChanApplication.getInstance().addForegroundChangedListener(this);
updateTimerState(); updateTimerState(true);
updateNotificationServiceState(); updateNotificationServiceState();
updatePinWatchers(); updatePinWatchers();
} }
@ -177,11 +177,21 @@ public class WatchManager implements ChanApplication.ForegroundChangedListener {
l.onPinsChanged(); l.onPinsChanged();
} }
updateTimerState(); updateTimerState(false);
updateNotificationServiceState(); updateNotificationServiceState();
updatePinWatchers(); updatePinWatchers();
} }
public void invokeLoadNow() {
if (pendingTimer != null) {
pendingTimer.cancel();
pendingTimer = null;
Logger.d(TAG, "Canceled timer");
}
updateTimerState(true);
}
public void pausePins() { public void pausePins() {
List<Pin> watchingPins = getWatchingPins(); List<Pin> watchingPins = getWatchingPins();
for (Pin pin : watchingPins) { for (Pin pin : watchingPins) {
@ -194,19 +204,19 @@ public class WatchManager implements ChanApplication.ForegroundChangedListener {
public void onWatchEnabledChanged(boolean watchEnabled) { public void onWatchEnabledChanged(boolean watchEnabled) {
updateNotificationServiceState(watchEnabled, getWatchBackgroundEnabled()); updateNotificationServiceState(watchEnabled, getWatchBackgroundEnabled());
updateTimerState(watchEnabled, getWatchBackgroundEnabled()); updateTimerState(watchEnabled, getWatchBackgroundEnabled(), false);
updatePinWatchers(watchEnabled); updatePinWatchers(watchEnabled);
} }
public void onBackgroundWatchingChanged(boolean backgroundEnabled) { public void onBackgroundWatchingChanged(boolean backgroundEnabled) {
updateNotificationServiceState(getTimerEnabled(), backgroundEnabled); updateNotificationServiceState(getTimerEnabled(), backgroundEnabled);
updateTimerState(getTimerEnabled(), backgroundEnabled); updateTimerState(getTimerEnabled(), backgroundEnabled, false);
} }
@Override @Override
public void onForegroundChanged(final boolean foreground) { public void onForegroundChanged(final boolean foreground) {
updateNotificationServiceState(); updateNotificationServiceState();
updateTimerState(); updateTimerState(true);
} }
private boolean getTimerEnabled() { private boolean getTimerEnabled() {
@ -245,14 +255,14 @@ public class WatchManager implements ChanApplication.ForegroundChangedListener {
} }
} }
private void updateTimerState() { private void updateTimerState(boolean invokeLoadNow) {
updateTimerState(getTimerEnabled(), getWatchBackgroundEnabled()); updateTimerState(getTimerEnabled(), getWatchBackgroundEnabled(), invokeLoadNow);
} }
private void updateTimerState(boolean watchEnabled, boolean backgroundEnabled) { private void updateTimerState(boolean watchEnabled, boolean backgroundEnabled, boolean invokeLoadNow) {
if (watchEnabled) { if (watchEnabled) {
if (ChanApplication.getInstance().getApplicationInForeground()) { if (ChanApplication.getInstance().getApplicationInForeground()) {
setTimer(FOREGROUND_TIME); setTimer(invokeLoadNow ? 1 : FOREGROUND_TIME);
} else { } else {
if (backgroundEnabled) { if (backgroundEnabled) {
setTimer(ChanPreferences.getWatchBackgroundTimeout()); setTimer(ChanPreferences.getWatchBackgroundTimeout());
@ -307,7 +317,7 @@ public class WatchManager implements ChanApplication.ForegroundChangedListener {
pin.update(); pin.update();
} }
updateTimerState(); updateTimerState(false);
} }
public static interface PinListener { public static interface PinListener {

@ -73,7 +73,7 @@ public class Pin {
} }
public void update() { public void update() {
if (pinWatcher != null) { if (pinWatcher != null && watching) {
pinWatcher.update(); pinWatcher.update();
} }
} }
@ -94,9 +94,6 @@ public class Pin {
public void toggleWatch() { public void toggleWatch() {
watching = !watching; watching = !watching;
ChanApplication.getWatchManager().onPinsChanged(); ChanApplication.getWatchManager().onPinsChanged();
ChanApplication.getWatchManager().invokeLoadNow();
// if (watching && pinWatcher != null) {
// .update();
// }
} }
} }

Loading…
Cancel
Save