|
|
|
@ -5,6 +5,7 @@ import java.util.List; |
|
|
|
import org.floens.chan.R; |
|
|
|
import org.floens.chan.R; |
|
|
|
import org.floens.chan.manager.PinnedManager; |
|
|
|
import org.floens.chan.manager.PinnedManager; |
|
|
|
import org.floens.chan.model.Pin; |
|
|
|
import org.floens.chan.model.Pin; |
|
|
|
|
|
|
|
import org.floens.chan.utils.Logger; |
|
|
|
|
|
|
|
|
|
|
|
import android.app.Notification; |
|
|
|
import android.app.Notification; |
|
|
|
import android.app.NotificationManager; |
|
|
|
import android.app.NotificationManager; |
|
|
|
@ -15,9 +16,37 @@ import android.os.IBinder; |
|
|
|
import android.os.Looper; |
|
|
|
import android.os.Looper; |
|
|
|
|
|
|
|
|
|
|
|
public class PinnedService extends Service { |
|
|
|
public class PinnedService extends Service { |
|
|
|
|
|
|
|
private static final long FOREGROUND_INTERVAL = 10000L; |
|
|
|
|
|
|
|
private static final long BACKGROUND_INTERVAL = 60000L; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static PinnedService instance; |
|
|
|
|
|
|
|
private static boolean activityInForeground = false; |
|
|
|
|
|
|
|
|
|
|
|
private Thread loadThread; |
|
|
|
private Thread loadThread; |
|
|
|
private boolean running = true; |
|
|
|
private boolean running = true; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public PinnedService() { |
|
|
|
|
|
|
|
instance = this; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Get the PinnedService instance |
|
|
|
|
|
|
|
* @return the instance or null |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public static PinnedService getInstance() { |
|
|
|
|
|
|
|
return instance; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static void onActivityStart() { |
|
|
|
|
|
|
|
Logger.test("onActivityStart"); |
|
|
|
|
|
|
|
activityInForeground = true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static void onActivityStop() { |
|
|
|
|
|
|
|
Logger.test("onActivityStop"); |
|
|
|
|
|
|
|
activityInForeground = false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void onCreate() { |
|
|
|
public void onCreate() { |
|
|
|
super.onCreate(); |
|
|
|
super.onCreate(); |
|
|
|
@ -30,26 +59,25 @@ public class PinnedService extends Service { |
|
|
|
super.onDestroy(); |
|
|
|
super.onDestroy(); |
|
|
|
|
|
|
|
|
|
|
|
running = false; |
|
|
|
running = false; |
|
|
|
|
|
|
|
|
|
|
|
showNotification("Stop"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public IBinder onBind(Intent intent) { |
|
|
|
|
|
|
|
return null; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void start() { |
|
|
|
private void start() { |
|
|
|
showNotification("Start"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
loadThread = new Thread(new Runnable() { |
|
|
|
loadThread = new Thread(new Runnable() { |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void run() { |
|
|
|
public void run() { |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
Thread.sleep(2000); |
|
|
|
|
|
|
|
} catch (InterruptedException e1) { |
|
|
|
|
|
|
|
e1.printStackTrace(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
while (running) { |
|
|
|
while (running) { |
|
|
|
doUpdates(); |
|
|
|
doUpdates(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
long timeout = activityInForeground ? FOREGROUND_INTERVAL : BACKGROUND_INTERVAL; |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
try { |
|
|
|
Thread.sleep(60000); |
|
|
|
Thread.sleep(timeout); |
|
|
|
} catch (InterruptedException e) { |
|
|
|
} catch (InterruptedException e) { |
|
|
|
e.printStackTrace(); |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -64,7 +92,6 @@ public class PinnedService extends Service { |
|
|
|
List<Pin> pins = PinnedManager.getInstance().getPins(); |
|
|
|
List<Pin> pins = PinnedManager.getInstance().getPins(); |
|
|
|
for (Pin pin : pins) { |
|
|
|
for (Pin pin : pins) { |
|
|
|
pin.updateWatch(); |
|
|
|
pin.updateWatch(); |
|
|
|
// pin.newPostCount++;
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -89,6 +116,11 @@ public class PinnedService extends Service { |
|
|
|
|
|
|
|
|
|
|
|
nm.notify(1, builder.getNotification()); |
|
|
|
nm.notify(1, builder.getNotification()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public IBinder onBind(Intent intent) { |
|
|
|
|
|
|
|
return null; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|