Search in sources :

Example 41 with Select

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;
}
Also used : SharedPreferences(android.content.SharedPreferences) GsonBuilder(com.google.gson.GsonBuilder) Select(com.activeandroid.query.Select)

Example 42 with Select

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);
}
Also used : ArrayList(java.util.ArrayList) Select(com.activeandroid.query.Select) Feed(cn.edu.cqupt.nmid.headline.support.repository.headline.bean.Feed)

Example 43 with Select

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();
}
Also used : Update(com.activeandroid.query.Update) Message(android.os.Message) Select(com.activeandroid.query.Select)

Example 44 with Select

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;
}
Also used : Select(com.activeandroid.query.Select)

Example 45 with Select

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");
    }
}
Also used : MissedReadingService(com.eveningoutpost.dexdrip.Services.MissedReadingService) Select(com.activeandroid.query.Select) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent)

Aggregations

Select (com.activeandroid.query.Select)80 SharedPreferences (android.content.SharedPreferences)14 From (com.activeandroid.query.From)11 MockModel (com.activeandroid.test.MockModel)11 DecimalFormat (java.text.DecimalFormat)8 ArrayList (java.util.ArrayList)7 Date (java.util.Date)7 Cursor (android.database.Cursor)6 ActiveBluetoothDevice (com.eveningoutpost.dexdrip.Models.ActiveBluetoothDevice)6 JSONException (org.json.JSONException)5 GsonBuilder (com.google.gson.GsonBuilder)4 PendingIntent (android.app.PendingIntent)2 BluetoothDevice (android.bluetooth.BluetoothDevice)2 Intent (android.content.Intent)2 Update (com.activeandroid.query.Update)2 BgReading (com.eveningoutpost.dexdrip.Models.BgReading)2 MissedReadingService (com.eveningoutpost.dexdrip.Services.MissedReadingService)2 Gson (com.google.gson.Gson)2 DateTypeAdapter (com.google.gson.internal.bind.DateTypeAdapter)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2