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();
}
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();
}
}
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...: ");
}
}
}
}
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();
}
}
}
}
}
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;
}
Aggregations