mirror of https://github.com/kurisufriend/Clover
parent
1d14b01be8
commit
75d6583ff6
@ -0,0 +1,16 @@ |
|||||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||||
|
<inset xmlns:android="http://schemas.android.com/apk/res/android" |
||||||
|
android:insetLeft="8dp" |
||||||
|
android:insetTop="8dp" |
||||||
|
android:insetRight="8dp" |
||||||
|
android:insetBottom="8dp" > |
||||||
|
<shape> |
||||||
|
<solid |
||||||
|
android:color="#FF0099CC" /> |
||||||
|
|
||||||
|
<corners |
||||||
|
android:radius="4dp" /> |
||||||
|
|
||||||
|
</shape> |
||||||
|
|
||||||
|
</inset> |
@ -1,23 +0,0 @@ |
|||||||
<?xml version="1.0" encoding="utf-8"?> |
|
||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" |
|
||||||
android:layout_width="match_parent" |
|
||||||
android:layout_height="wrap_content" > |
|
||||||
<TextView |
|
||||||
android:id="@+id/drawer_item_text" |
|
||||||
android:layout_width="match_parent" |
|
||||||
android:layout_height="wrap_content" |
|
||||||
android:minHeight="48dp" |
|
||||||
android:paddingTop="8dp" |
|
||||||
android:paddingBottom="8dp" |
|
||||||
android:paddingLeft="16dp" |
|
||||||
android:paddingRight="56dp" |
|
||||||
android:textSize="19sp" |
|
||||||
android:textColor="#fff" |
|
||||||
android:gravity="center_vertical" |
|
||||||
android:ellipsize="end" |
|
||||||
android:lines="1" |
|
||||||
android:singleLine="true" |
|
||||||
android:orientation="vertical" > |
|
||||||
</TextView> |
|
||||||
</LinearLayout> |
|
||||||
|
|
@ -0,0 +1,41 @@ |
|||||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||||
|
<LinearLayout |
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android" |
||||||
|
android:layout_width="match_parent" |
||||||
|
android:layout_height="48dp" |
||||||
|
android:orientation="horizontal" > |
||||||
|
|
||||||
|
<TextView |
||||||
|
android:id="@+id/drawer_item_text" |
||||||
|
android:layout_width="0dp" |
||||||
|
android:layout_height="48dp" |
||||||
|
android:layout_weight="1" |
||||||
|
android:paddingTop="8dp" |
||||||
|
android:paddingBottom="8dp" |
||||||
|
android:paddingLeft="16dp" |
||||||
|
android:paddingRight="8dp" |
||||||
|
android:textSize="19sp" |
||||||
|
android:textColor="#fff" |
||||||
|
android:gravity="center_vertical" |
||||||
|
android:ellipsize="end" |
||||||
|
android:lines="1" |
||||||
|
android:singleLine="true"> |
||||||
|
</TextView> |
||||||
|
|
||||||
|
<FrameLayout |
||||||
|
android:background="@drawable/pin_icon" |
||||||
|
android:layout_width="48dp" |
||||||
|
android:layout_height="48dp" > |
||||||
|
|
||||||
|
<TextView |
||||||
|
android:id="@+id/drawer_item_count" |
||||||
|
android:layout_width="match_parent" |
||||||
|
android:layout_height="match_parent" |
||||||
|
android:gravity="center" |
||||||
|
android:textSize="16dp" |
||||||
|
android:textColor="#fff" |
||||||
|
android:text="99+" /> |
||||||
|
|
||||||
|
</FrameLayout> |
||||||
|
|
||||||
|
</LinearLayout> |
@ -1,113 +1,84 @@ |
|||||||
package org.floens.chan.service; |
package org.floens.chan.service; |
||||||
|
|
||||||
import java.util.ArrayList; |
import java.util.List; |
||||||
|
|
||||||
|
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; |
||||||
|
|
||||||
public class PinnedService /*extends Service*/ { |
import android.app.Notification; |
||||||
/** |
import android.app.NotificationManager; |
||||||
* Base interval when the thread wakes up |
import android.app.Service; |
||||||
*/ |
import android.content.Intent; |
||||||
private final int LOAD_BASE_INTERVAL = 20000; |
import android.os.IBinder; |
||||||
|
|
||||||
private PinnedManager pinnedManager; |
public class PinnedService extends Service { |
||||||
private Thread loadThread; |
private Thread loadThread; |
||||||
private final boolean running = true; |
private boolean running = true; |
||||||
|
|
||||||
private final ArrayList<Pin> pinList = new ArrayList<Pin>(); |
|
||||||
|
|
||||||
private final Runnable loadRunnable = new Runnable() { |
|
||||||
@Override |
|
||||||
public void run() { |
|
||||||
while (running) { |
|
||||||
// loadPins();
|
|
||||||
|
|
||||||
try { |
|
||||||
Thread.sleep(LOAD_BASE_INTERVAL); |
|
||||||
} catch (InterruptedException e) { |
|
||||||
e.printStackTrace(); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
}; |
|
||||||
|
|
||||||
/*public PinnedService() { |
@Override |
||||||
pinnedManager = ChanApplication.getPinnedManager(); |
public void onCreate() { |
||||||
|
super.onCreate(); |
||||||
|
|
||||||
|
start(); |
||||||
} |
} |
||||||
|
|
||||||
private void loadPins() { |
@Override |
||||||
organizePins(); |
public void onDestroy() { |
||||||
|
super.onDestroy(); |
||||||
|
|
||||||
for (Pin pin : pinList) { |
running = false; |
||||||
loadPin(pin); |
|
||||||
} |
showNotification("Stop"); |
||||||
} |
} |
||||||
|
|
||||||
private void loadPin(Pin pin) { |
@Override |
||||||
if (!pin.threadLoader.isLoading()) { |
public IBinder onBind(Intent intent) { |
||||||
pin.startLoading(); |
return null; |
||||||
} |
|
||||||
} |
} |
||||||
|
|
||||||
/** |
private void start() { |
||||||
* Add not yet added pins to our list. |
showNotification("Start"); |
||||||
* Remove old/unwatched pins from our list. |
|
||||||
|
|
||||||
private void organizePins() { |
|
||||||
ArrayList<Pin> managerList = pinnedManager.getPinnedThreads(); |
|
||||||
|
|
||||||
for (Pin pin : managerList) { |
|
||||||
if (pin.getShouldWatch() && !pinList.contains(pin)) { |
|
||||||
// Add pin to watcher
|
|
||||||
pinList.add(pin); |
|
||||||
|
|
||||||
testToast("Added pin: " + pin.loadable.title); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
for (Iterator<Pin> it = pinList.iterator(); it.hasNext();) { |
loadThread = new Thread(new Runnable() { |
||||||
Pin pin = it.next(); |
|
||||||
if (!pin.getShouldWatch() || !managerList.contains(pin)) { |
|
||||||
// Remove pin from watcher
|
|
||||||
it.remove(); |
|
||||||
|
|
||||||
testToast("Removed pin: " + pin.loadable.title); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
private void testToast(final String text) { |
|
||||||
new Handler(Looper.getMainLooper()).post(new Runnable() { |
|
||||||
@Override |
@Override |
||||||
public void run() { |
public void run() { |
||||||
Toast.makeText(PinnedService.this, text, Toast.LENGTH_SHORT).show(); |
while (running) { |
||||||
|
doUpdates(); |
||||||
|
|
||||||
|
try { |
||||||
|
Thread.sleep(60000); |
||||||
|
} catch (InterruptedException e) { |
||||||
|
e.printStackTrace(); |
||||||
|
} |
||||||
|
} |
||||||
} |
} |
||||||
}); |
}); |
||||||
|
|
||||||
|
loadThread.start(); |
||||||
} |
} |
||||||
|
|
||||||
@Override |
private void doUpdates() { |
||||||
public void onCreate() { |
List<Pin> pins = PinnedManager.getInstance().getPins(); |
||||||
super.onCreate(); |
for (Pin pin : pins) { |
||||||
|
// pin.update();
|
||||||
testToast("Service started!"); |
|
||||||
|
|
||||||
if (loadThread == null) { |
|
||||||
loadThread = new Thread(loadRunnable); |
|
||||||
// loadThread.start();
|
|
||||||
} |
} |
||||||
} |
} |
||||||
|
|
||||||
@Override |
@SuppressWarnings("deprecation") |
||||||
public void onDestroy() { |
private void showNotification(String text) { |
||||||
super.onDestroy(); |
NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); |
||||||
|
|
||||||
|
Notification.Builder builder = new Notification.Builder(this); |
||||||
|
builder.setTicker(text); |
||||||
|
builder.setContentTitle(text); |
||||||
|
builder.setContentText(text); |
||||||
|
builder.setSmallIcon(R.drawable.ic_stat_notify); |
||||||
|
|
||||||
testToast("Service stopped!"); |
nm.notify(1, builder.getNotification()); |
||||||
} |
} |
||||||
|
|
||||||
@Override |
|
||||||
public IBinder onBind(Intent intent) { |
|
||||||
return null; |
|
||||||
}*/ |
|
||||||
|
|
||||||
} |
} |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in new issue