Search in sources :

Example 1 with Select

use of com.activeandroid.query.Select in project AnimeTaste by daimajia.

the class DownloadRecord method deleteAll.

public static void deleteAll() {
    List<DownloadRecord> records = new Select().from(DownloadRecord.class).execute();
    for (int i = 0; i < records.size(); i++) {
        DownloadRecord r = records.get(i);
        String p = r.SaveDir + r.SaveFileName;
        File f = new File(p);
        if (f.exists() && f.isFile()) {
            f.delete();
        }
    }
    new Delete().from(DownloadRecord.class).execute();
}
Also used : Delete(com.activeandroid.query.Delete) Select(com.activeandroid.query.Select) File(java.io.File)

Example 2 with Select

use of com.activeandroid.query.Select in project AnimeTaste by daimajia.

the class DownloadRecord method save.

public static void save(Animation animation, M3U8Mission mission) {
    DownloadRecord record = new Select().from(DownloadRecord.class).where("AnimationId = ?", animation.AnimationId).executeSingle();
    if (record == null) {
        new DownloadRecord(animation, mission).save();
    } else {
        int status;
        if (mission.isDone()) {
            status = mission.isSuccess() ? STATUS.SUCCESS : STATUS.ERROR;
            status = mission.isCanceled() ? STATUS.CANCELED : status;
        } else {
            status = STATUS.DOWNLOADING;
        }
        new Update(DownloadRecord.class).set("Size = ?," + "DownloadedSize = ?," + "Duration = ?," + "DownloadedDuration = ?," + "Segments = ?," + "DownloadedSegments = ?," + "DownloadedPercentage = ?," + "RangeStart = ?," + "Status = ?," + "Extra = ?," + "SaveDir = ?," + "SaveFileName = ? ," + "UsingDownloadUrl = ? ", mission.getFilesize(), mission.getDownloaded(), mission.getVideoDuration(), mission.getDownloadedDuration(), mission.getSegmentsCount(), mission.getDownloadedSegmentCount(), mission.getPercentage(), mission.getCurrentSegmentDownloaded(), status, "", mission.getSaveDir(), mission.getSaveName(), mission.getUri()).where("AnimationId = ?", animation.AnimationId).execute();
    }
}
Also used : Select(com.activeandroid.query.Select) Update(com.activeandroid.query.Update)

Example 3 with Select

use of com.activeandroid.query.Select in project xDrip by NightscoutFoundation.

the class ShareTest method attemptConnection.

public void attemptConnection() {
    mBluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);
    if (device != null) {
        details.append("\nConnection state: " + " Device is not null");
        mConnectionState = mBluetoothManager.getConnectionState(device, BluetoothProfile.GATT);
    }
    Log.i(TAG, "Connection state: " + mConnectionState);
    details.append("\nConnection state: " + mConnectionState);
    if (mConnectionState == STATE_DISCONNECTED || mConnectionState == STATE_DISCONNECTING) {
        ActiveBluetoothDevice btDevice = new Select().from(ActiveBluetoothDevice.class).orderBy("_ID desc").executeSingle();
        if (btDevice != null) {
            details.append("\nBT Device: " + btDevice.name);
            mDeviceName = btDevice.name;
            mDeviceAddress = btDevice.address;
            mBluetoothAdapter = mBluetoothManager.getAdapter();
            boolean newConnection = true;
            if (newConnection) {
                is_connected = connect(mDeviceAddress);
                details.append("\nConnecting...: ");
            }
        }
    }
}
Also used : ActiveBluetoothDevice(com.eveningoutpost.dexdrip.Models.ActiveBluetoothDevice) Select(com.activeandroid.query.Select)

Example 4 with Select

use of com.activeandroid.query.Select in project xDrip by NightscoutFoundation.

the class ListenerService method syncActiveBtDeviceData.

private void syncActiveBtDeviceData(DataMap dataMap, Context context) {
    // KS
    Log.d(TAG, "syncActiveBtDeviceData");
    if (dataMap != null) {
        String name = dataMap.getString("name", "");
        String address = dataMap.getString("address", "");
        Boolean connected = dataMap.getBoolean("connected", false);
        Log.d(TAG, "syncActiveBtDeviceData add ActiveBluetoothDevice for name=" + name + " address=" + address + " connected=" + connected);
        // ensure database has already been initialized
        Sensor.InitDb(context);
        if (name != null && !name.isEmpty() && address != null && !address.isEmpty()) {
            final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
            synchronized (ActiveBluetoothDevice.table_lock) {
                ActiveBluetoothDevice btDevice = new Select().from(ActiveBluetoothDevice.class).orderBy("_ID desc").executeSingle();
                prefs.edit().putString("last_connected_device_address", address).apply();
                if (btDevice == null) {
                    ActiveBluetoothDevice newBtDevice = new ActiveBluetoothDevice();
                    newBtDevice.name = name;
                    newBtDevice.address = address;
                    newBtDevice.connected = connected;
                    newBtDevice.save();
                } else {
                    btDevice.name = name;
                    btDevice.address = address;
                    btDevice.connected = connected;
                    btDevice.save();
                }
            }
        }
    }
}
Also used : ActiveBluetoothDevice(com.eveningoutpost.dexdrip.Models.ActiveBluetoothDevice) SharedPreferences(android.content.SharedPreferences) Select(com.activeandroid.query.Select)

Example 5 with Select

use of com.activeandroid.query.Select in project xDrip by NightscoutFoundation.

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)

Aggregations

Select (com.activeandroid.query.Select)74 SharedPreferences (android.content.SharedPreferences)14 From (com.activeandroid.query.From)11 MockModel (com.activeandroid.test.MockModel)11 DecimalFormat (java.text.DecimalFormat)8 Date (java.util.Date)7 Cursor (android.database.Cursor)6 ActiveBluetoothDevice (com.eveningoutpost.dexdrip.Models.ActiveBluetoothDevice)6 ArrayList (java.util.ArrayList)5 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