use of com.activeandroid.query.Select in project xDrip-plus by jamorham.
the class AlertType method fromSettings.
// Read all alerts from preference key and write them to db.
public static boolean fromSettings(Context context) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
String savedAlerts = prefs.getString("saved_alerts", "");
if (savedAlerts.isEmpty()) {
Log.i(TAG, "read saved_alerts string and it is empty");
return true;
}
Log.i(TAG, "read alerts string " + savedAlerts);
AlertType[] newAlerts = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create().fromJson(savedAlerts, AlertType[].class);
if (newAlerts == null) {
Log.e(TAG, "newAlerts is null");
return true;
}
Log.i(TAG, "read successfuly " + newAlerts.length);
// Now delete all existing alerts if we managed to unpack the json
try {
List<AlertType> alerts = new Select().from(AlertType.class).execute();
for (AlertType alert : alerts) {
alert.delete();
}
} catch (NullPointerException e) {
Log.e(TAG, "Got null pointer exception: " + e);
}
try {
for (AlertType alert : newAlerts) {
Log.e(TAG, "Saving alert " + alert.name);
alert.save();
}
} catch (NullPointerException e) {
Log.e(TAG, "Got null pointer exception 2: " + e);
}
// Delete the string, so next time we will not load the data
prefs.edit().putString("saved_alerts", "").apply();
return true;
}
use of com.activeandroid.query.Select in project nmid-headline by miao1007.
the class FavFeedFragment method loadNewFeeds.
@Override
void loadNewFeeds() {
List<Feed> feeds = new ArrayList<>();
feeds = new Select().from(Feed.class).orderBy("idMember desc").limit(this.feed_limit).execute();
if (feeds == null || feeds.isEmpty()) {
showErrorView(View.VISIBLE);
} else {
newsBeans.addAll(feeds);
adapter.notifyDataSetChanged();
}
mSwipeRefreshLayout.setRefreshing(false);
}
use of com.activeandroid.query.Select in project AnimeTaste by daimajia.
the class Animation method addToFavorite.
public void addToFavorite(final UpdateFinishCallback callback) {
IsFav = true;
new Thread() {
@Override
public void run() {
super.run();
boolean exist = new Select().from(Animation.class).where("AnimationId='" + AnimationId + "'").executeSingle() != null;
if (!exist)
save();
else
new com.activeandroid.query.Update(Animation.class).set("IsFavorite='1'").where("AnimationId='" + AnimationId + "'").execute();
Message msg = Message.obtain();
Looper.prepare();
msg.setTarget(new FavoriteHandler(callback, Method.ADD_FAVORITE));
msg.sendToTarget();
Looper.loop();
}
}.start();
}
use of com.activeandroid.query.Select in project xDrip by NightscoutFoundation.
the class Reminder method getNextActiveReminder.
public static Reminder getNextActiveReminder() {
fixUpTable(schema);
final long now = JoH.tsl();
final Reminder reminder = new Select().from(Reminder.class).where("enabled = ?", true).where("next_due < ?", now).where("snoozed_till < ?", now).where("last_fired < (? - (600000 * alerted_times))", now).orderBy("enabled desc, priority desc, next_due asc").executeSingle();
return reminder;
}
use of com.activeandroid.query.Select in project xDrip by NightscoutFoundation.
the class Reminder method firstInit.
public static synchronized void firstInit(Context context) {
fixUpTable(schema);
final Reminder reminder = new Select().from(Reminder.class).where("enabled = ?", true).executeSingle();
if (reminder != null) {
PendingIntent serviceIntent = PendingIntent.getService(xdrip.getAppContext(), 0, new Intent(xdrip.getAppContext(), MissedReadingService.class), PendingIntent.FLAG_UPDATE_CURRENT);
JoH.wakeUpIntent(xdrip.getAppContext(), Constants.MINUTE_IN_MS, serviceIntent);
UserError.Log.d(TAG, "Starting missed readings service");
}
}
Aggregations