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; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
import org.floens.chan.R; |
||||
import org.floens.chan.manager.PinnedManager; |
||||
import org.floens.chan.model.Pin; |
||||
|
||||
public class PinnedService /*extends Service*/ { |
||||
/** |
||||
* Base interval when the thread wakes up |
||||
*/ |
||||
private final int LOAD_BASE_INTERVAL = 20000; |
||||
|
||||
private PinnedManager pinnedManager; |
||||
import android.app.Notification; |
||||
import android.app.NotificationManager; |
||||
import android.app.Service; |
||||
import android.content.Intent; |
||||
import android.os.IBinder; |
||||
|
||||
public class PinnedService extends Service { |
||||
private Thread loadThread; |
||||
private final 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(); |
||||
} |
||||
} |
||||
} |
||||
}; |
||||
private boolean running = true; |
||||
|
||||
/*public PinnedService() { |
||||
pinnedManager = ChanApplication.getPinnedManager(); |
||||
@Override |
||||
public void onCreate() { |
||||
super.onCreate(); |
||||
|
||||
start(); |
||||
} |
||||
|
||||
private void loadPins() { |
||||
organizePins(); |
||||
@Override |
||||
public void onDestroy() { |
||||
super.onDestroy(); |
||||
|
||||
for (Pin pin : pinList) { |
||||
loadPin(pin); |
||||
} |
||||
running = false; |
||||
|
||||
showNotification("Stop"); |
||||
} |
||||
|
||||
private void loadPin(Pin pin) { |
||||
if (!pin.threadLoader.isLoading()) { |
||||
pin.startLoading(); |
||||
} |
||||
@Override |
||||
public IBinder onBind(Intent intent) { |
||||
return null; |
||||
} |
||||
|
||||
/** |
||||
* Add not yet added pins to our list. |
||||
* 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); |
||||
} |
||||
} |
||||
private void start() { |
||||
showNotification("Start"); |
||||
|
||||
for (Iterator<Pin> it = pinList.iterator(); it.hasNext();) { |
||||
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() { |
||||
loadThread = new Thread(new Runnable() { |
||||
@Override |
||||
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 |
||||
public void onCreate() { |
||||
super.onCreate(); |
||||
|
||||
testToast("Service started!"); |
||||
|
||||
if (loadThread == null) { |
||||
loadThread = new Thread(loadRunnable); |
||||
// loadThread.start();
|
||||
private void doUpdates() { |
||||
List<Pin> pins = PinnedManager.getInstance().getPins(); |
||||
for (Pin pin : pins) { |
||||
// pin.update();
|
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public void onDestroy() { |
||||
super.onDestroy(); |
||||
@SuppressWarnings("deprecation") |
||||
private void showNotification(String text) { |
||||
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