Java Code Examples for io.realm.RealmResults#isEmpty()
The following examples show how to use
io.realm.RealmResults#isEmpty() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MusicPlayer.java From iGap-Android with GNU Affero General Public License v3.0 | 6 votes |
public static boolean downloadNextMusic(String messageId) { boolean result = false; RealmResults<RealmRoomMessage> roomMessages = getRealm().where(RealmRoomMessage.class).equalTo(RealmRoomMessageFields.ROOM_ID, roomId).equalTo(RealmRoomMessageFields.DELETED, false).greaterThan(RealmRoomMessageFields.MESSAGE_ID, Long.parseLong(messageId)).findAll().sort(RealmRoomMessageFields.CREATE_TIME); if (!roomMessages.isEmpty()) { for (RealmRoomMessage rm : roomMessages) { if (isVoice) { if (rm.getMessageType().toString().equals(ProtoGlobal.RoomMessageType.VOICE.toString())) { result = startDownload(rm); break; } } else { if (rm.getMessageType().toString().equals(ProtoGlobal.RoomMessageType.AUDIO.toString()) || rm.getMessageType().toString().equals(ProtoGlobal.RoomMessageType.AUDIO_TEXT.toString())) { result = startDownload(rm); break; } } } } return result; }
Example 2
Source File: Stat.java From HAPP with GNU General Public License v3.0 | 6 votes |
public static List<Stat> statsCOB(Date startTime, Realm realm) { DecimalFormat df = new DecimalFormat("#"); df.setMaximumFractionDigits(1); RealmResults<Stat> results = realm.where(Stat.class) .greaterThanOrEqualTo("timestamp", startTime) .equalTo("type", "cob") .findAllSorted("timestamp", Sort.DESCENDING); if (results.isEmpty()) { return null; } else { return results; } //return new Select() // .from(Stats.class) // .where("datetime >= " + df.format(startTime)) // .where("type = 'cob'") // .orderBy("datetime desc") // .limit(number) // .execute(); }
Example 3
Source File: MeizhiFetchingService.java From GankMeizhi with Apache License 2.0 | 5 votes |
@Override protected void onHandleIntent(Intent intent) { Realm realm = Realm.getDefaultInstance(); RealmResults<Image> latest = Image.all(realm); int fetched = 0; try { if (latest.isEmpty()) { Log.d(TAG, "no latest, fresh fetch"); fetched = fetchLatest(realm); } else if (ACTION_FETCH_FORWARD.equals(intent.getAction())) { Log.d(TAG, "latest fetch: " + latest.first().getUrl()); fetched = fetchSince(realm, latest.first().getPublishedAt()); } else if (ACTION_FETCH_BACKWARD.equals(intent.getAction())) { Log.d(TAG, "earliest fetch: " + latest.last().getUrl()); fetched = fetchBefore(realm, latest.last().getPublishedAt()); } } catch (IOException e) { Log.e(TAG, "failed to issue network request", e); } realm.close(); Log.d(TAG, "finished fetching, actual fetched " + fetched); Intent broadcast = new Intent(ACTION_UPDATE_RESULT); broadcast.putExtra(EXTRA_FETCHED, fetched); broadcast.putExtra(EXTRA_TRIGGER, intent.getAction()); localBroadcastManager.sendBroadcast(broadcast); }
Example 4
Source File: TempBasal.java From HAPP with GNU General Public License v3.0 | 5 votes |
public static TempBasal getTempBasalByID(String uuid, Realm realm) { RealmResults<TempBasal> results = realm.where(TempBasal.class) .equalTo("id", uuid) .findAllSorted("start_time", Sort.DESCENDING); if (results.isEmpty()) { return null; } else { return results.first(); } }
Example 5
Source File: Carb.java From HAPP with GNU General Public License v3.0 | 5 votes |
public static Carb getCarb(String uuid, Realm realm) { RealmResults<Carb> results = realm.where(Carb.class) .equalTo("id", uuid) .findAllSorted("timestamp", Sort.DESCENDING); if (results.isEmpty()) { return null; } else { return results.first(); } }
Example 6
Source File: TempBasal.java From HAPP with GNU General Public License v3.0 | 5 votes |
public static TempBasal last(Realm realm) { RealmResults<TempBasal> results = realm.where(TempBasal.class) .findAllSorted("start_time", Sort.DESCENDING); if (results.isEmpty()) { return new TempBasal(); //returns an empty TempBasal, other than null } else { return results.first(); } }
Example 7
Source File: Stat.java From HAPP with GNU General Public License v3.0 | 5 votes |
public static Stat last(Realm realm) { RealmResults<Stat> results = realm.where(Stat.class) .findAllSorted("timestamp", Sort.DESCENDING); if (results.isEmpty()) { return null; } else { return results.first(); } //return new Select() // .from(Stats.class) // .orderBy("datetime desc") // .executeSingle(); }
Example 8
Source File: Bolus.java From HAPP with GNU General Public License v3.0 | 5 votes |
public static List<Bolus> getBolusList(Realm realm){ RealmResults<Bolus> results = realm.where(Bolus.class) .findAllSorted("timestamp", Sort.DESCENDING); if (results.isEmpty()) { return null; } else { return results; } }
Example 9
Source File: Bolus.java From HAPP with GNU General Public License v3.0 | 5 votes |
public static Bolus getBolus(String uuid, Realm realm) { RealmResults<Bolus> results = realm.where(Bolus.class) .equalTo("id", uuid) .findAllSorted("timestamp", Sort.DESCENDING); if (results.isEmpty()) { return null; } else { return results.first(); } }
Example 10
Source File: Integration.java From HAPP with GNU General Public License v3.0 | 5 votes |
public static Integration getIntegrationByID(String uuid, Realm realm) { RealmResults<Integration> results = realm.where(Integration.class) .equalTo("id", uuid) .findAllSorted("timestamp", Sort.DESCENDING); if (results.isEmpty()) { return null; } else { return results.first(); } }
Example 11
Source File: Bg.java From HAPP with GNU General Public License v3.0 | 5 votes |
public static boolean haveBGTimestamped(Date timestamp, Realm realm){ RealmResults<Bg> results = realm.where(Bg.class) .equalTo("datetime", timestamp) .findAllSorted("datetime", Sort.DESCENDING); if (results.isEmpty()){ return false; } else { return true; } }
Example 12
Source File: ReadLaterArticlesLocalSource.java From WanAndroid with Apache License 2.0 | 5 votes |
@Override public boolean isExist(int userId, int id) { Realm realm = RealmHelper.newRealmInstance(); RealmResults<ReadLaterArticleData> list = realm.where(ReadLaterArticleData.class) .equalTo("userId", userId) .and() .equalTo("id", id) .findAll(); return !list.isEmpty(); }
Example 13
Source File: DatabaseManager.java From redgram-for-reddit with GNU General Public License v3.0 | 5 votes |
public List<User> getUsers(){ Realm realm = getInstance(); RealmResults<User> users = DatabaseHelper.getUsers(realm); List<User> usableUsers = new ArrayList<>(); if(users != null && !users.isEmpty()){ for(User user : users){ usableUsers.add(realm.copyFromRealm(user)); } } close(realm); return usableUsers; }
Example 14
Source File: AccountManager.java From quill with MIT License | 5 votes |
public static void deleteBlog(@NonNull String blogUrl) { RealmResults<BlogMetadata> matchingBlogs = findAllBlogsMatchingUrl(blogUrl); if (matchingBlogs.isEmpty()) { throw new IllegalStateException("No blog found matching the URL: " + blogUrl); } // we don't allow adding more than 1 blog with the same URL, so this should never happen if (matchingBlogs.size() > 1) { throw new IllegalStateException("More than 1 blog found matching the URL: " + blogUrl); } // delete blog metadata before data because data without metadata is harmless, but vice-versa is not // keep a copy of the metadata around so we can delete the data Realm after this final Realm realm = Realm.getDefaultInstance(); BlogMetadata blogToDelete = matchingBlogs.get(0); RealmConfiguration dataRealmToDelete = realm.copyFromRealm(blogToDelete).getDataRealmConfig(); RealmUtils.executeTransaction(realm, r -> { RealmObject.deleteFromRealm(blogToDelete); }); // delete blog data Realm.deleteRealm(dataRealmToDelete); // if the active blog was deleted, set the active blog to a different one if (blogUrl.equals(getActiveBlogUrl())) { List<BlogMetadata> allBlogs = getAllBlogs(); if (!allBlogs.isEmpty()) { setActiveBlog(allBlogs.get(0).getBlogUrl()); } else { setActiveBlog(""); } } }
Example 15
Source File: GreenHubDb.java From batteryhub with Apache License 2.0 | 5 votes |
public Iterator<Integer> allSamplesIds() { ArrayList<Integer> list = new ArrayList<>(); RealmResults<Sample> samples = mRealm.where(Sample.class).findAll(); if (!samples.isEmpty()) { for (Sample sample : samples) { list.add(sample.id); } } return list.iterator(); }
Example 16
Source File: GoBeesLocalDataSource.java From go-bees with GNU General Public License v3.0 | 5 votes |
@Override public void getRecording(long apiaryId, long hiveId, Date start, Date end, @NonNull GetRecordingCallback callback) { // Get apiary Apiary apiary = realm.where(Apiary.class).equalTo(ID, apiaryId).findFirst(); if (apiary == null || apiary.getMeteoRecords() == null) { callback.onDataNotAvailable(); return; } // Get hive Hive hive = realm.where(Hive.class).equalTo(ID, hiveId).findFirst(); if (hive == null || hive.getRecords() == null) { callback.onDataNotAvailable(); return; } // Get records RealmResults<Record> records = hive.getRecords() .where() .greaterThanOrEqualTo(TIMESTAMP, DateTimeUtils.setTime(start, 0, 0, 0, 0)) .lessThanOrEqualTo(TIMESTAMP, DateTimeUtils.setTime(end, 23, 59, 59, 999)) .findAll() .sort(TIMESTAMP); if (records.isEmpty()) { callback.onDataNotAvailable(); return; } // Get weather data RealmResults<MeteoRecord> meteoRecords = apiary.getMeteoRecords() .where() .greaterThanOrEqualTo(TIMESTAMP, records.first().getTimestamp()) .lessThanOrEqualTo(TIMESTAMP, records.last().getTimestamp()) .findAll() .sort(TIMESTAMP); // Create recording Recording recording = new Recording(start, realm.copyFromRealm(records), realm.copyFromRealm(meteoRecords)); callback.onRecordingLoaded(recording); }
Example 17
Source File: ComicVoMapper.java From DaggerWorkshopGDG with Apache License 2.0 | 5 votes |
public static List<ComicBo> toBo(RealmResults<ComicVo> vos) { List<ComicBo> bos = null; if (vos != null && !vos.isEmpty()) { bos = new ArrayList<>(); for (ComicVo vo : vos) { bos.add(toBo(vo)); } } return bos; }
Example 18
Source File: NotesFragment.java From ForPDA with GNU General Public License v3.0 | 5 votes |
@Override public void loadCacheData() { super.loadCacheData(); if (!realm.isClosed()) { setRefreshing(true); RealmResults<NoteItemBd> results = realm.where(NoteItemBd.class).findAllSorted("id", Sort.DESCENDING); if (results.isEmpty()) { if (!contentController.contains(ContentController.TAG_NO_DATA)) { FunnyContent funnyContent = new FunnyContent(getContext()) .setImage(R.drawable.ic_bookmark) .setTitle(R.string.funny_notes_nodata_title); contentController.addContent(funnyContent, ContentController.TAG_NO_DATA); } contentController.showContent(ContentController.TAG_NO_DATA); } else { contentController.hideContent(ContentController.TAG_NO_DATA); } ArrayList<NoteItem> nonBdResult = new ArrayList<>(); for (NoteItemBd item : results) { nonBdResult.add(new NoteItem(item)); } adapter.addAll(nonBdResult); } setRefreshing(false); }
Example 19
Source File: Bg.java From HAPP with GNU General Public License v3.0 | 5 votes |
public static Bg last(Realm realm) { RealmResults<Bg> results = realm.where(Bg.class) .findAllSorted("datetime", Sort.DESCENDING); if (results.isEmpty()) { return null; } else { return results.first(); } //return new Select() // .from(Bg.class) // .orderBy("datetime desc") // .executeSingle(); }
Example 20
Source File: GoBeesLocalDataSource.java From go-bees with GNU General Public License v3.0 | 4 votes |
@Override public void getHiveWithRecordings(long hiveId, @NonNull GetHiveCallback callback) { try { // Get hive Hive hive = realm.where(Hive.class).equalTo(ID, hiveId).findFirst(); if (hive == null || hive.getRecords() == null) { callback.onDataNotAvailable(); return; } // Get records RealmResults<Record> records = hive.getRecords().where().findAll().sort(TIMESTAMP); // Classify records by date into recordings Date day; // Actual date of the recording Date nextDay = new Date(0); // Next day to the recording RealmResults<Record> filteredRecords; List<Recording> recordings = new ArrayList<>(); while (true) { // Get all records greater than last recordings records = records.where().greaterThanOrEqualTo(TIMESTAMP, nextDay).findAll(); if (records.isEmpty()) { break; } // Get range of days to filter day = DateTimeUtils.getDateOnly(records.first().getTimestamp()); nextDay = DateTimeUtils.getNextDay(day); // Filter records of that date and create recording filteredRecords = records.where() .greaterThanOrEqualTo(TIMESTAMP, day) .lessThan(TIMESTAMP, DateTimeUtils.getNextDay(nextDay)) .findAll(); // Create recording recordings.add(new Recording(day, new ArrayList<>(filteredRecords))); } // Sort recordings (newest - oldest) Collections.reverse(recordings); // Set recordings to hive hive.setRecordings(recordings); // Return hive callback.onHiveLoaded(hive); } catch (Exception e) { Log.e(e, "Error: getHiveWithRecordings()"); callback.onDataNotAvailable(); } }