Start Neko job service after reboot (if needed)
Change-Id: I8350ab922ba534b529876bb73c1023935f5529a9 Fixes: 29922511
This commit is contained in:
@@ -102,6 +102,14 @@ public class NekoService extends JobService {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void registerJobIfNeeded(Context context, long intervalMinutes) {
|
||||
JobScheduler jss = context.getSystemService(JobScheduler.class);
|
||||
JobInfo info = jss.getPendingJob(JOB_ID);
|
||||
if (info == null) {
|
||||
registerJob(context, intervalMinutes);
|
||||
}
|
||||
}
|
||||
|
||||
public static void registerJob(Context context, long intervalMinutes) {
|
||||
JobScheduler jss = context.getSystemService(JobScheduler.class);
|
||||
jss.cancel(JOB_ID);
|
||||
|
||||
@@ -68,6 +68,9 @@ public class NekoTile extends TileService implements PrefsListener {
|
||||
Tile tile = getQsTile();
|
||||
int foodState = mPrefs.getFoodState();
|
||||
Food food = new Food(foodState);
|
||||
if (foodState != 0) {
|
||||
NekoService.registerJobIfNeeded(this, food.getInterval(this));
|
||||
}
|
||||
tile.setIcon(food.getIcon(this));
|
||||
tile.setLabel(food.getName(this));
|
||||
tile.setState(foodState != 0 ? Tile.STATE_ACTIVE : Tile.STATE_INACTIVE);
|
||||
|
||||
@@ -43,13 +43,11 @@ public class PrefState implements OnSharedPreferenceChangeListener {
|
||||
public void addCat(Cat cat) {
|
||||
mPrefs.edit()
|
||||
.putString(CAT_KEY_PREFIX + String.valueOf(cat.getSeed()), cat.getName())
|
||||
.commit();
|
||||
.apply();
|
||||
}
|
||||
|
||||
public void removeCat(Cat cat) {
|
||||
mPrefs.edit()
|
||||
.remove(CAT_KEY_PREFIX + String.valueOf(cat.getSeed()))
|
||||
.commit();
|
||||
mPrefs.edit().remove(CAT_KEY_PREFIX + String.valueOf(cat.getSeed())).apply();
|
||||
}
|
||||
|
||||
public List<Cat> getCats() {
|
||||
@@ -71,7 +69,7 @@ public class PrefState implements OnSharedPreferenceChangeListener {
|
||||
}
|
||||
|
||||
public void setFoodState(int foodState) {
|
||||
mPrefs.edit().putInt(FOOD_STATE, foodState).commit();
|
||||
mPrefs.edit().putInt(FOOD_STATE, foodState).apply();
|
||||
}
|
||||
|
||||
public void setListener(PrefsListener listener) {
|
||||
|
||||
Reference in New Issue
Block a user