Pins database and notifications changes

Pins are saved in the database when pause pins is pressed from the notification. This because it can be (and will possibly be) the last thing the app does.
Pins are not notified about if there was an error with them.

In the future it should be a retry system, where if a pin failed to load 3 times, indicate it as an error. Also differentiate between 404 and load error in the future.
captchafix
Florens Douwes 11 years ago
parent 159131865e
commit e828739666
  1. 18
      Chan/src/org/floens/chan/core/watch/PinWatcher.java
  2. 14
      Chan/src/org/floens/chan/core/watch/WatchNotifier.java
  3. 2
      Chan/src/org/floens/chan/service/WatchService.java

@ -20,6 +20,7 @@ public class PinWatcher implements Loader.LoaderListener {
private boolean isError = false;
private final List<Post> posts = new ArrayList<Post>();
private boolean wereNewQuotes = false;
public PinWatcher(Pin pin) {
this.pin = pin;
@ -77,6 +78,15 @@ public class PinWatcher implements Loader.LoaderListener {
}
}
public boolean getWereNewQuotes() {
if (wereNewQuotes) {
wereNewQuotes = false;
return true;
} else {
return false;
}
}
public boolean isError() {
return isError;
}
@ -85,8 +95,6 @@ public class PinWatcher implements Loader.LoaderListener {
public void onError(VolleyError error) {
Logger.e(TAG, "PinWatcher onError: ", error);
isError = true;
pin.watchLastCount = 0;
pin.watchNewCount = 0;
WatchService.onPinWatcherResult();
}
@ -114,6 +122,8 @@ public class PinWatcher implements Loader.LoaderListener {
}
}
int lastQuoteCount = pin.quoteNewCount;
// Find posts quoting these saved posts
pin.quoteNewCount = 0;
for (Post resultPost : result) {
@ -125,6 +135,10 @@ public class PinWatcher implements Loader.LoaderListener {
}
}
if (pin.quoteNewCount > lastQuoteCount) {
wereNewQuotes = true;
}
WatchService.onPinWatcherResult();
}
}

@ -21,6 +21,8 @@ import android.media.RingtoneManager;
import android.support.v4.app.NotificationCompat;
public class WatchNotifier {
private static final String TAG = "WatchNotifier";
private final int NOTIFICATION_ID = 1;
private final WatchService pinnedService;
@ -58,6 +60,7 @@ public class WatchNotifier {
}
ChanApplication.getPinnedManager().onPinsChanged();
ChanApplication.getPinnedManager().updateAll(); // Can be the last thing this app does
}
private void prepareNotification() {
@ -68,11 +71,11 @@ public class WatchNotifier {
int newQuotesCount = 0;
List<Post> posts = new ArrayList<Post>();
boolean makeSound = false;
boolean show = false;
boolean show = true;
for (Pin pin : watchingPins) {
PinWatcher watcher = pin.getPinWatcher();
if (watcher == null)
if (watcher == null || watcher.isError())
continue;
boolean add = false;
@ -91,10 +94,13 @@ public class WatchNotifier {
if (watcher.getNewQuoteCount() > 0) {
newQuotesCount += watcher.getNewQuoteCount();
show = true;
makeSound = true;
add = true;
}
if (watcher.getWereNewQuotes()) {
makeSound = true;
}
if (add) {
pins.add(pin);
}
@ -173,7 +179,7 @@ public class WatchNotifier {
builder.setStyle(style);
Logger.test("SHOWING NOTIFICATION!");
Logger.i(TAG, "Showing notification");
nm.notify(NOTIFICATION_ID, builder.getNotification());
}

@ -127,8 +127,6 @@ public class WatchService extends Service {
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Logger.test("Startcommand " + startId);
if (intent.getExtras() != null && intent.getExtras().getBoolean("pause_pins", false)) {
if (watchNotifier != null) {
watchNotifier.onPausePinsClicked();

Loading…
Cancel
Save