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