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

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

Loading…
Cancel
Save