Added a stop watching button to notifications that pauses all pins.

captchafix
Florens Douwes 11 years ago
parent 714bdc143a
commit 788e4c02bc
  1. BIN
      Chan/res/drawable-hdpi/ic_action_pause.png
  2. BIN
      Chan/res/drawable-mdpi/ic_action_pause.png
  3. BIN
      Chan/res/drawable-xhdpi/ic_action_pause.png
  4. BIN
      Chan/res/drawable-xxhdpi/ic_action_pause.png
  5. 2
      Chan/res/values/strings.xml
  6. 22
      Chan/src/org/floens/chan/core/watch/WatchNotifier.java
  7. 13
      Chan/src/org/floens/chan/service/WatchService.java
  8. 10
      Chan/src/org/floens/chan/ui/adapter/PinnedAdapter.java

Binary file not shown.

After

Width:  |  Height:  |  Size: 185 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 180 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 232 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 297 B

@ -103,6 +103,8 @@
<string name="open_link_confirmation">Open link?</string>
<string name="watch_pause_pins">Stop watching</string>
<string name="watch_summary_disabled">Off</string>
<string name="watch_summary_enabled">Watching pinned threads</string>
<string name="watch_info_text">To watch pins for new posts, turn the thread watcher on.</string>

@ -47,6 +47,17 @@ public class WatchNotifier {
}
}
public void onPausePinsClicked() {
nm.cancel(NOTIFICATION_ID);
List<Pin> watchingPins = ChanApplication.getPinnedManager().getWatchingPins();
for (Pin pin : watchingPins) {
pin.watching = false;
}
ChanApplication.getPinnedManager().onPinsChanged();
}
private void prepareNotification() {
List<Pin> watchingPins = ChanApplication.getPinnedManager().getWatchingPins();
@ -128,6 +139,15 @@ public class WatchNotifier {
builder.setContentInfo(contentInfo);
builder.setSmallIcon(R.drawable.ic_stat_notify);
Intent pauseWatching = new Intent(pinnedService, WatchService.class);
pauseWatching.putExtra("pause_pins", true);
PendingIntent pauseWatchingPending = PendingIntent.getService(pinnedService, 0, pauseWatching,
PendingIntent.FLAG_UPDATE_CURRENT);
builder.addAction(R.drawable.ic_action_pause, pinnedService.getString(R.string.watch_pause_pins),
pauseWatchingPending);
if (makeSound) {
builder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
}
@ -137,7 +157,7 @@ public class WatchNotifier {
style.addLine(line);
}
style.setBigContentTitle(title);
style.setSummaryText(content);
// style.setSummaryText(content);
builder.setStyle(style);

@ -14,7 +14,6 @@ import android.content.Intent;
import android.os.Handler;
import android.os.IBinder;
import android.os.Looper;
import android.widget.Toast;
public class WatchService extends Service {
private static final String TAG = "WatchService";
@ -116,13 +115,11 @@ public class WatchService extends Service {
public void onDestroy() {
super.onDestroy();
instance = null;
running = false;
if (loadThread != null) {
loadThread.interrupt();
Toast.makeText(getApplicationContext(), "Pinned thread interrupted", Toast.LENGTH_SHORT).show();
}
Logger.i(TAG, "WatchService destroyed");
@ -130,6 +127,14 @@ 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();
}
}
return START_STICKY;
}
@ -171,7 +176,6 @@ public class WatchService extends Service {
});
loadThread.start();
Toast.makeText(getApplicationContext(), "Pinned thread started", Toast.LENGTH_SHORT).show();
}
}
@ -188,6 +192,7 @@ public class WatchService extends Service {
/**
* Returns the sleep time the user specified for background iteration
*
* @return the sleep time in ms, or -1 if background reloading is disabled
*/
private long getBackgroundTimeout() {

@ -51,7 +51,7 @@ public class PinnedAdapter extends ArrayAdapter<Pin> {
TextView itemCount = (TextView) view.findViewById(R.id.drawer_item_count);
if (item.isError()) {
itemCount.setText("404");
itemCount.setText("Err");
} else {
int count = item.getPinWatcher() == null ? 0 : item.getPinWatcher().getNewPostsCount();
String total = Integer.toString(count);
@ -69,12 +69,12 @@ public class PinnedAdapter extends ArrayAdapter<Pin> {
}
});
if (item.isError()) {
if (!item.watching) {
frameLayout.setBackgroundResource(R.drawable.pin_icon_gray);
} else if (item.isError()) {
frameLayout.setBackgroundResource(R.drawable.pin_icon_red);
} else if (item.watching) {
frameLayout.setBackgroundResource(R.drawable.pin_icon_blue);
} else {
frameLayout.setBackgroundResource(R.drawable.pin_icon_gray);
frameLayout.setBackgroundResource(R.drawable.pin_icon_blue);
}
} else {
frameLayout.setVisibility(View.GONE);

Loading…
Cancel
Save