/** * Loads the news feed as well as all future updates. */ @UiThread public Flowable<RealmResults<NYTimesStory>> loadNewsFeed(@NonNull String sectionKey, boolean forceReload) { // Start loading data from the network if needed // It will put all data into Realm if (forceReload || timeSinceLastNetworkRequest(sectionKey) > MINIMUM_NETWORK_WAIT_SEC) { dataLoader.loadData(sectionKey, apiKey, realm, networkLoading); lastNetworkRequest.put(sectionKey, System.currentTimeMillis()); } // Return the data in Realm. The query result will be automatically updated when the network requests // save data in Realm return realm.where(NYTimesStory.class) .equalTo(NYTimesStory.API_SECTION, sectionKey) .findAllSortedAsync(NYTimesStory.PUBLISHED_DATE, Sort.DESCENDING) .asFlowable(); }
private static SortDescriptor getInstance( FieldDescriptor.SchemaProxy proxy, Table table, String[] fieldDescriptions, @Nullable Sort[] sortOrders, Set<RealmFieldType> legalInternalTypes, Set<RealmFieldType> legalTerminalTypes, String message) { //noinspection ConstantConditions if (fieldDescriptions == null || fieldDescriptions.length == 0) { throw new IllegalArgumentException("You must provide at least one field name."); } long[][] columnIndices = new long[fieldDescriptions.length][]; // Force aggressive parsing of the FieldDescriptors, so that only valid SortDescriptor objects are created. for (int i = 0; i < fieldDescriptions.length; i++) { FieldDescriptor descriptor = FieldDescriptor.createFieldDescriptor(proxy, table, fieldDescriptions[i], legalInternalTypes, null); checkFieldType(descriptor, legalTerminalTypes, message, fieldDescriptions[i]); columnIndices[i] = descriptor.getColumnIndices(); } return new SortDescriptor(table, columnIndices, sortOrders); }
@Test public void getInstanceForSort_multipleFields() { RealmFieldType stringType = RealmFieldType.STRING; long stringColumn = table.addColumn(stringType, stringType.name()); RealmFieldType intType = RealmFieldType.INTEGER; long intColumn = table.addColumn(intType, intType.name()); SortDescriptor sortDescriptor = SortDescriptor.getInstanceForSort(null, table, new String[] { stringType.name(), intType.name()}, new Sort[] {Sort.ASCENDING, Sort.DESCENDING}); assertEquals(2, sortDescriptor.getAscendings().length); assertEquals(2, sortDescriptor.getColumnIndices().length); assertEquals(1, sortDescriptor.getColumnIndices()[0].length); assertEquals(stringColumn, sortDescriptor.getColumnIndices()[0][0]); assertTrue(sortDescriptor.getAscendings()[0]); assertEquals(1, sortDescriptor.getColumnIndices()[1].length); assertEquals(intColumn, sortDescriptor.getColumnIndices()[1][0]); assertFalse(sortDescriptor.getAscendings()[1]); }
private void getData() { if (showID != -1) { result = realm.where(RealmEpisode.class) .equalTo("showID", showID) .equalTo("watched", false) .notEqualTo("seasonNumber", 0) .findAllSortedAsync("details", Sort.ASCENDING); result.addChangeListener(callback); } else { singleEpisode = realm.where(RealmEpisode.class) .equalTo("episodeID", episodeID) .findFirstAsync(); singleEpisode.addChangeListener(singleEpisodeCallback); } }
private RealmResults<Album> getResults() { RealmResults<Album> results = null; switch (Media.getSortType()) { case ALPHABETICAL: { if (Media.isShowHidden()) { results = realm.where(Album.class).findAll().sort("name", Media.isSortAscending() ? Sort.ASCENDING : Sort.DESCENDING); break; } else { results = realm.where(Album.class).equalTo("hidden", false).findAll().sort("name", Media.isSortAscending() ? Sort.ASCENDING : Sort.DESCENDING); break; } } case SIZE: { if (Media.isShowHidden()) { results = realm.where(Album.class).findAll().sort("size", Media.isSortAscending() ? Sort.ASCENDING : Sort.DESCENDING); break; } else { results = realm.where(Album.class).equalTo("hidden", false).findAll().sort("size", Media.isSortAscending() ? Sort.ASCENDING : Sort.DESCENDING); break; } } } return results; }
public static void updateCoverPhotos() { long time = System.currentTimeMillis(); Realm realm = Realm.getDefaultInstance(); realm.beginTransaction(); for (Album a : realm.where(Album.class).findAll()) { switch (Media.getMediaSortType()) { case ALPHABETICAL: { a.setCoverPath(a.getMedia().sort("name", Media.isMediaSortAscending() ? Sort.ASCENDING : Sort.DESCENDING).first().getPath()); break; } case DATE: { a.setCoverPath(a.getMedia().sort("date", Media.isMediaSortAscending() ? Sort.ASCENDING : Sort.DESCENDING).first().getPath()); break; } } } realm.commitTransaction(); realm.close(); Log.d(Util.LOG_TAG, "Reloading all cover photos took " + (System.currentTimeMillis() - time)); }
public static void updateSingleCover(String key) { long time = System.currentTimeMillis(); Realm realm = Realm.getDefaultInstance(); realm.beginTransaction(); Album a = realm.where(Album.class).equalTo("path",key).findFirst(); switch (Media.getMediaSortType()) { case ALPHABETICAL: { a.setCoverPath(a.getMedia().sort("name", Media.isMediaSortAscending() ? Sort.ASCENDING : Sort.DESCENDING).first().getPath()); break; } case DATE: { a.setCoverPath(a.getMedia().sort("date", Media.isMediaSortAscending() ? Sort.ASCENDING : Sort.DESCENDING).first().getPath()); break; } } realm.commitTransaction(); realm.close(); Log.d(Util.LOG_TAG, "Reloading all cover photos took " + (System.currentTimeMillis() - time)); }
@Override public Observable<List<Company>> searchCompanies(@NonNull String keyWords) { Realm rlm = RealmHelper.newRealmInstance(); List<Company> results = rlm.copyFromRealm( rlm.where(Company.class) .like("name","*" + keyWords + "*", Case.INSENSITIVE) .or() .like("tel", "*" + keyWords + "*", Case.INSENSITIVE) .or() .like("website", "*" + keyWords + "*", Case.INSENSITIVE) .or() .like("alphabet", "*" + keyWords + "*", Case.INSENSITIVE) .findAllSorted("alphabet", Sort.ASCENDING)); return Observable.fromIterable(results) .toList() .toObservable(); }
/** * method mencari semua Profil */ public ArrayList<ProfilModel> findAllProfil(){ ArrayList<ProfilModel> data = new ArrayList<>(); realmResultProfil = realm.where(Profil.class).findAll(); realmResultProfil.sort("id", Sort.DESCENDING); if (realmResultProfil.size() > 0){ showLog("Size : " + realmResultProfil.size()); for (int i = 0; i < realmResultProfil.size(); i++) { String nama, email, instansi; int id = realmResultProfil.get(i).getId(); nama = realmResultProfil.get(i).getNama(); email = realmResultProfil.get(i).getEmail(); instansi = realmResultProfil.get(i).getInstansi(); data.add(new ProfilModel(id, nama, email, instansi)); } } else { showLog("Size : 0"); } return data; }
/** * method mencari semua Lainnya */ public ArrayList<LainnyaModel> findAllLainnya(){ ArrayList<LainnyaModel> data = new ArrayList<>(); realmResultLainnya = realm.where(Lainnya.class).findAll(); realmResultLainnya.sort("id", Sort.DESCENDING); if (realmResultLainnya.size() > 0){ showLog("Size : " + realmResultLainnya.size()); for (int i = 0; i < realmResultLainnya.size(); i++) { String judul, jenis, deadline, deskripsi, done; int id = realmResultLainnya.get(i).getId(); judul = realmResultLainnya.get(i).getJudul(); deadline = realmResultLainnya.get(i).getDeadline(); deskripsi = realmResultLainnya.get(i).getDeskripsi(); done = realmResultLainnya.get(i).getDone(); data.add(new LainnyaModel(id, judul, deadline, deskripsi, done)); } } else { showLog("Size : 0"); } return data; }
@Override public Iterable<Preview> getAll(ItemsPerPreview itemsPerPreview) { Realm realm = Realm.getInstance(configuration); RealmResults<TodoListDAO> allTodoListDAO = realm.where(TodoListDAO.class).findAllSorted("position", Sort.DESCENDING); RealmResults<NoteDAO> allNoteDAO = realm.where(NoteDAO.class).findAllSorted("position", Sort.DESCENDING); List<Preview> previews = new ArrayList<>(allTodoListDAO.size() + allNoteDAO.size()); for (TodoListDAO todoListDAO : allTodoListDAO) { previews.add(constructPreview(realm, todoListDAO, itemsPerPreview)); } for (NoteDAO noteDAO : allNoteDAO) { previews.add(new NotePreview(RealmConverter.convert(noteDAO))); } realm.close(); return previews; }
private List<TodoListItem> getItemPreviewOfHeader(Realm realm, TodoListHeader header, ItemsPerPreview itemsPerPreview) { if (header == null || itemsPerPreview.areZero()) return new ArrayList<>(0); RealmResults<TodoListItemDAO> itemDAOs = realm.where(TodoListItemDAO.class) .equalTo("parentTodoListUuid", header.getParentTodoListUuid()) .equalTo("parentHeaderUuid", header.getUuid()) .findAllSorted("position", Sort.DESCENDING); int size = Math.min(itemDAOs.size(), itemsPerPreview.getCount()); List<TodoListItem> items = new ArrayList<>(size); if (size > 0) { for (TodoListItemDAO itemDAO : itemDAOs.subList(0, size)) { items.add(RealmConverter.convert(itemDAO)); } } return items; }
static void parseRawData() { Realm realmRawData = Realm.getInstance(realmConfigRawData); Realm realmProcessedData = Realm.getInstance(realmConfigProcessedData); // if processed data realm is empty if (realmProcessedData.isEmpty() && !realmRawData.isEmpty()) { // parse data from raw realm into processed data realm Log.i(LOG_ID, "Parsing data raw_data realm to processed_data realm."); realmProcessedData.beginTransaction(); for (RawTagData rawTagData : realmRawData.where(RawTagData.class) .findAllSorted(RawTagData.DATE, Sort.ASCENDING)) { realmProcessedData.copyToRealmOrUpdate(new ReadingData(rawTagData)); } realmProcessedData.commitTransaction(); } realmProcessedData.close(); realmRawData.close(); }
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_log_list, container, false); // Set the adapter if (view instanceof RecyclerView) { Context context = view.getContext(); RecyclerView recyclerView = (RecyclerView) view; recyclerView.setLayoutManager(new LinearLayoutManager(context)); recyclerView.setAdapter(new LogRecyclerViewAdapter(this, mRealmProcessedData .where(ReadingData.class) .isNotEmpty(ReadingData.TREND) .findAllSortedAsync(ReadingData.DATE, Sort.DESCENDING) )); recyclerView.setHasFixedSize(true); recyclerView.addItemDecoration( new DividerItemDecoration(this.getContext(), DividerItemDecoration.VERTICAL_LIST) ); registerForContextMenu(recyclerView); } return view; }
Observable<LatestNews> getLatestNewsFromDB() { return Observable.fromCallable(new Callable<LatestNews>() { @Override public LatestNews call() throws Exception { Realm realm = Realm.getDefaultInstance(); RealmResults<LatestNewsDB> result; LatestNews latestNews; try { result = realm.where(LatestNewsDB.class).findAll(); result = result.sort("date", Sort.DESCENDING); if (result.size() < 1) { return null; } latestNews = Mapper.getLatestNews(result); return latestNews; } finally { if (realm != null) { realm.close(); } } } }); }
public Observable<List<Notification>> getNotPinnedNotification() { return Observable.create(new OnSubscribeRealm<List<Notification>>() { @Override public List<Notification> get(Realm realm) { RealmResults<Notification> realmResults = realm.where(Notification.class) .equalTo(Notification.TEAM_ID, BizLogic.getTeamId()) .notEqualTo(Notification.IS_PINNED, true) .findAllSorted(Notification.UPDATED_AT, Sort.DESCENDING); List<Notification> notifications = new ArrayList<>(realmResults.size()); for (Notification realmResult : realmResults) { Notification notification = new Notification(); copy(notification, realmResult); copyObject(notification, realmResult); notifications.add(notification); } return notifications; } }); }
public Observable<List<Notification>> getPinnedNotification() { return Observable.create(new OnSubscribeRealm<List<Notification>>() { @Override public List<Notification> get(Realm realm) { RealmResults<Notification> realmResults = realm.where(Notification.class) .equalTo(Notification.TEAM_ID, BizLogic.getTeamId()) .equalTo(Notification.IS_PINNED, true) .findAllSorted(Notification.UPDATED_AT, Sort.DESCENDING); List<Notification> notifications = new ArrayList<>(realmResults.size()); for (Notification realmResult : realmResults) { Notification notification = new Notification(); copy(notification, realmResult); copyObject(notification, realmResult); notifications.add(notification); } return notifications; } }).subscribeOn(Schedulers.io()); }
public Observable<List<Notification>> getNotifications(final int count) { return Observable.create(new OnSubscribeRealm<List<Notification>>() { @Override public List<Notification> get(Realm realm) { RealmResults<Notification> realmResults = realm.where(Notification.class) .equalTo(Notification.TEAM_ID, BizLogic.getTeamId()) .findAll(); realmResults.sort(Notification.UPDATED_AT, Sort.DESCENDING); List<Notification> notifications = new ArrayList<>(realmResults.size()); int currCount = 0; for (Notification realmResult : realmResults) { currCount++; Notification notification = new Notification(); copy(notification, realmResult); notifications.add(notification); if (currCount >= count) { break; } } return notifications; } }).subscribeOn(Schedulers.io()); }
public Observable<List<Member>> getMemberNotAdnim() { return Observable.create(new OnSubscribeRealm<List<Member>>() { @Override public List<Member> get(Realm realm) { final RealmResults<Member> realmResults = realm.where(Member.class) .equalTo(Member.TEAM_ID, BizLogic.getTeamId()) .equalTo(Member.IS_QUIT, false) .notEqualTo(Member.ROLE, Member.ADMIN) .findAllSorted(Member.ALIAS_PINYIN, Sort.ASCENDING); final List<Member> members = new ArrayList<>(realmResults.size()); for (Member realmResult : realmResults) { Member member = new Member(); copy(member, realmResult); members.add(member); } return members; } }).subscribeOn(Schedulers.io()); }
public List<Member> getMemberNotAdminWithCurrentThread() { final List<Member> members = new ArrayList<>(); Realm realm = RealmProvider.getInstance(); try { realm.beginTransaction(); final RealmResults<Member> realmResults = realm.where(Member.class) .equalTo(Member.TEAM_ID, BizLogic.getTeamId()) .equalTo(Member.IS_QUIT, false) .equalTo(Member.ROLE, Member.MEMBER) .findAllSorted(Member.ALIAS_PINYIN, Sort.ASCENDING); for (Member realmResult : realmResults) { Member member = new Member(); copy(member, realmResult); members.add(member); } realm.commitTransaction(); } catch (Exception e) { e.printStackTrace(); realm.cancelTransaction(); } finally { realm.close(); } return members; }
public List<Member> getQuitMemberWithCurrentThread() { final List<Member> members = new ArrayList<>(); Realm realm = RealmProvider.getInstance(); try { realm.beginTransaction(); RealmResults<Member> realmResults = realm.where(Member.class) .equalTo(Member.TEAM_ID, BizLogic.getTeamId()) .equalTo(Member.IS_QUIT, true) .findAll(); realmResults.sort(Member.ALIAS_PINYIN, Sort.ASCENDING); for (Member realmResult : realmResults) { Member member = new Member(); copy(member, realmResult); members.add(member); } realm.commitTransaction(); } catch (Exception e) { e.printStackTrace(); realm.cancelTransaction(); } finally { realm.close(); } return members; }
public List<Member> getAllMemberExceptMeWithCurrentThread() { final List<Member> members = new ArrayList<>(); Realm realm = RealmProvider.getInstance(); try { realm.beginTransaction(); RealmResults<Member> realmResults = realm.where(Member.class) .equalTo(Member.TEAM_ID, BizLogic.getTeamId()) .equalTo(Member.IS_QUIT, false) .notEqualTo(Member.ID, BizLogic.getUserInfo().get_id()) .findAll(); realmResults.sort(Member.ALIAS_PINYIN, Sort.ASCENDING); for (Member realmResult : realmResults) { Member member = new Member(); copy(member, realmResult); members.add(member); } realm.commitTransaction(); } catch (Exception e) { e.printStackTrace(); realm.cancelTransaction(); } finally { realm.close(); } return members; }
public List<Member> getNotQuitAndNotRobotMemberWithCurrentThread() { final List<Member> members = new ArrayList<>(); Realm realm = RealmProvider.getInstance(); try { realm.beginTransaction(); RealmResults<Member> realmResults = realm.where(Member.class) .equalTo(Member.TEAM_ID, BizLogic.getTeamId()) .equalTo(Member.IS_QUIT, false) .equalTo(Member.IS_ROBOT, false) .findAll(); realmResults.sort(Member.ALIAS_PINYIN, Sort.ASCENDING); for (Member realmResult : realmResults) { Member member = new Member(); copy(member, realmResult); members.add(member); } realm.commitTransaction(); } catch (Exception e) { e.printStackTrace(); realm.cancelTransaction(); } finally { realm.close(); } return members; }
public List<Member> getNotRobotMemberWithCurrentThread() { final List<Member> members = new ArrayList<>(); Realm realm = RealmProvider.getInstance(); try { realm.beginTransaction(); RealmResults<Member> realmResults = realm.where(Member.class) .equalTo(Member.TEAM_ID, BizLogic.getTeamId()) .equalTo(Member.IS_ROBOT, false) .findAll(); realmResults.sort(Member.ALIAS_PINYIN, Sort.ASCENDING); for (Member realmResult : realmResults) { Member member = new Member(); copy(member, realmResult); members.add(member); } realm.commitTransaction(); } catch (Exception e) { e.printStackTrace(); realm.cancelTransaction(); } finally { realm.close(); } return members; }
/** * 查询不是退出,不是归档 * * @return 查询到的所有数据 */ public List<Room> getRoomOnNotQuitOnNotArchivedWithCurrentThread() { final List<Room> rooms = new ArrayList<>(); Realm realm = RealmProvider.getInstance(); try { realm.beginTransaction(); RealmResults<Room> realmResults = realm.where(Room.class) .equalTo(Room.TEAM_ID, BizLogic.getTeamId()) .equalTo(Room.IS_QUIT, false) .equalTo(Room.IS_ARCHIVED, false) .findAll(); realmResults.sort(Room.PINYIN, Sort.ASCENDING); for (int i = 0; i < realmResults.size(); i++) { Room room = new Room(); copy(room, realmResults.get(i)); rooms.add(room); } realm.commitTransaction(); } catch (Exception e) { e.printStackTrace(); realm.cancelTransaction(); } finally { realm.close(); } return rooms; }
/** * 查询所有不是归档的Room * * @return 查询到的所有数据 */ public List<Room> getRoomOnNotArchivedWithCurrentThread() { List<Room> rooms = new ArrayList<>(); Realm realm = RealmProvider.getInstance(); try { realm.beginTransaction(); RealmResults<Room> realmResults = realm.where(Room.class) .equalTo(Room.TEAM_ID, BizLogic.getTeamId()) .equalTo(Room.IS_ARCHIVED, false) .findAll(); realmResults.sort(Room.PINYIN, Sort.ASCENDING); for (int i = 0; i < realmResults.size(); i++) { Room room = new Room(); copy(room, realmResults.get(i)); rooms.add(room); } realm.commitTransaction(); } catch (Exception e) { e.printStackTrace(); realm.cancelTransaction(); } finally { realm.close(); } return rooms; }
/** * 查询所有归档的Room * * @return 查询到的所有数据 */ public List<Room> getRoomOnArchivedWithCurrentThread() { List<Room> rooms = new ArrayList<>(); Realm realm = RealmProvider.getInstance(); try { realm.beginTransaction(); RealmResults<Room> realmResults = realm.where(Room.class) .equalTo(Room.TEAM_ID, BizLogic.getTeamId()) .equalTo(Room.IS_ARCHIVED, true) .findAll(); realmResults.sort(Room.PINYIN, Sort.ASCENDING); for (int i = 0; i < realmResults.size(); i++) { Room room = new Room(); copy(room, realmResults.get(i)); rooms.add(room); } realm.commitTransaction(); } catch (Exception e) { e.printStackTrace(); realm.cancelTransaction(); } finally { realm.close(); } return rooms; }
public Observable<List<Room>> getJoinedRooms() { return Observable.create(new OnSubscribeRealm<List<Room>>() { @Override public List<Room> get(Realm realm) { List<Room> rooms = new ArrayList<>(); RealmResults<Room> realmResults = realm.where(Room.class) .equalTo(Room.TEAM_ID, BizLogic.getTeamId()) .equalTo(Room.IS_ARCHIVED, false) .equalTo(Room.IS_QUIT, false) .findAll(); realmResults.sort(Room.PINYIN, Sort.ASCENDING); for (int i = 0; i < realmResults.size(); i++) { Room room = new Room(); copy(room, realmResults.get(i)); rooms.add(room); } return rooms; } }); }
public Observable<List<Room>> getToJoinRooms() { return Observable.create(new OnSubscribeRealm<List<Room>>() { @Override public List<Room> get(Realm realm) { List<Room> rooms = new ArrayList<>(); RealmResults<Room> realmResults = realm.where(Room.class) .equalTo(Room.TEAM_ID, BizLogic.getTeamId()) .equalTo(Room.IS_ARCHIVED, false) .equalTo(Room.IS_QUIT, true) .findAll(); realmResults.sort(Room.PINYIN, Sort.ASCENDING); for (int i = 0; i < realmResults.size(); i++) { Room room = new Room(); copy(room, realmResults.get(i)); rooms.add(room); } return rooms; } }); }
@Override protected void onHandleIntent(Intent intent) { Log.d(TAG, "onHandleIntent called"); Realm mRealm = Realm.getDefaultInstance(); RealmResults<PumpStatusEvent> all_records = mRealm .where(PumpStatusEvent.class) .notEqualTo("sgv", 0) .findAllSorted("eventDate", Sort.DESCENDING); // get the most recent record and send that if (all_records.size() > 0) { List<PumpStatusEvent> records = all_records.subList(0, 1); doXDripUpload(records); } mRealm.close(); XDripPlusUploadReceiver.completeWakefulIntent(intent); }
@NonNull public static List<Folder> getAll(Realm realm, boolean onlyUnread) { RealmQuery<Folder> query = null; if(onlyUnread) { RealmResults<Feed> unreadFeeds = realm.where(Feed.class).greaterThan(Feed.UNREAD_COUNT, 0).notEqualTo(Feed.FOLDER_ID, 0).findAll(); if(unreadFeeds.size() > 0) { Iterator<Feed> feedIterator = unreadFeeds.iterator(); query = realm.where(Folder.class) .equalTo(Folder.ID, feedIterator.next().getFolderId()); while (feedIterator.hasNext()) { query.or().equalTo(Folder.ID, feedIterator.next().getFolderId()); } } } else { query = realm.where(Folder.class); } return query != null ? query.findAllSorted(Folder.NAME, Sort.ASCENDING) : Collections.emptyList(); }
public static void removeExcessItems(Realm realm, final int maxItems) { final RealmResults<Item> expendableItems = realm.where(Item.class) .equalTo(Item.UNREAD, false) .equalTo(Item.STARRED, false) .equalTo(Item.ACTIVE, false) .findAllSorted(Item.LAST_MODIFIED, Sort.ASCENDING); final int itemsToDelete = expendableItems.size() - maxItems; if(itemsToDelete > 0) { realm.executeTransaction(realm1 -> { for (int i = 0; i < itemsToDelete; i++) { expendableItems.deleteFirstFromRealm(); } }); } }
public Observable<List<HistoryItem>> getHistory() { return Observable.fromCallable(() -> { List<HistoryItem> items = new ArrayList<>(); try (Realm realm = Realm.getDefaultInstance()) { RealmResults<HistoryItemBd> results = realm .where(HistoryItemBd.class) .findAllSorted("unixTime", Sort.DESCENDING); for(HistoryItemBd itemBd: results){ items.add(new HistoryItem(itemBd)); } } return items; }) .subscribeOn(schedulers.io()) .observeOn(schedulers.ui()); }
/** * Returns a list of past logs which are available for viewing. If there is an import running, the current log will * be the first item. If there are no past logs, and there isn't an import running, the list will be empty. * @return List of logs which may be viewed currently, or empty if there are none. */ public final List<String> getLogList() { ArrayList<String> logList = new ArrayList<>(); // Add the current log if we're logging. if (isLogging) logList.add(Minerva.get().getString(R.string.log_label_current_import_uc)); // Add all past logs. try (Realm realm = Realm.getDefaultInstance()) { // Get the list of past logs from Realm. RealmResults<RImportLog> logs = realm.where(RImportLog.class) .findAllSorted("endTime", Sort.DESCENDING); // Create and add their labels. for (RImportLog log : logs) logList.add(Minerva.get().getString(R.string.log_label_from_uc, Util.getRelTimeString(log.endTime))); } return logList; }
public Observable<Rollback> getNotConfirmedRollback(String packageName) { return Observable.fromCallable(() -> database.get()) .flatMap(realm -> realm.where(Rollback.class) .equalTo(Rollback.PACKAGE_NAME, packageName) .equalTo(Rollback.CONFIRMED, false) .findAllSorted(Rollback.TIMESTAMP, Sort.DESCENDING) .asObservable() .unsubscribeOn(RealmSchedulers.getScheduler())) .flatMap(rollbacks -> database.copyFromRealm(rollbacks)) .map(rollbacks -> { if (rollbacks.size() > 0) { return rollbacks.get(0); } else { return null; } }) .subscribeOn(RealmSchedulers.getScheduler()) .observeOn(Schedulers.io()); }
/** * Moves the {@link Item} whose unique ID is {@code itemToMoveId} to somewhere before the {@link Item} whose unique * ID is {@code targetItemId}. * @param itemToMoveId Unique ID of item to move. * @param targetItemId Unique ID of item which item whose unique ID is {@code itemToMoveId} will be moved before. */ public static void moveItemToBefore(long itemToMoveId, long targetItemId) { try (Realm realm = Realm.getDefaultInstance()) { Item itemToMove = realm.where(Item.class).equalTo("uniqueId", itemToMoveId).findFirst(); Item targetItem = realm.where(Item.class).equalTo("uniqueId", targetItemId).findFirst(); if (itemToMove == null || targetItem == null) throw new IllegalArgumentException("Neither item may be null."); if (itemToMove.uniqueId == targetItem.uniqueId) return; // Get the items which come before targetItem. RealmResults<Item> beforeTarget = realm.where(Item.class) .lessThan("position", targetItem.position) .findAllSorted("position", Sort.DESCENDING); // Move itemToMove to between beforeTarget.first()/null and targetItem. moveItemToBetween(realm, itemToMove, beforeTarget.isEmpty() ? null : beforeTarget.first(), targetItem); } }
private void setupRecentView() { //TODO:: what about a horizontal blurred image that expands into AnimeActivity? recentAnime = realm.where(Anime.class).equalTo("isLastWatched", true).findFirst(); if (recentAnime != null) { final ImageView cover = (ImageView) recentView.findViewById(R.id.recent_anime_cover); if (recentAnime.coverURL == null || recentAnime.coverURL.isEmpty()) { KitsuApi.getInstance().fetchCoverUrl(recentAnime.title); } else { Picasso.with(getContext()).load(recentAnime.coverURL).placeholder(R.drawable.placeholder).into(cover); } //TODO:: could have lastwatched in anime field and set a listener for anime in animeactivity that updates when episode -> hasWatched RealmResults<Episode> watchedEpisodes = recentAnime.episodes.where().equalTo("hasWatched", true).findAllSorted("name", Sort.DESCENDING); if (watchedEpisodes.size() > 0) { TextView episodeName = (TextView) recentView.findViewById(R.id.recent_episode_name); episodeName.setText(watchedEpisodes.first().name); } recentView.setVisibility(View.VISIBLE); } else { recentView.setVisibility(View.GONE); } }
private SavedState(Parcel in) { super(in); // Read general variables' values back. int tmpTheme = in.readInt(); this.theme = tmpTheme == -1 ? null : RuqusTheme.values()[tmpTheme]; this.ruq = in.readParcelable(RealmUserQuery.class.getClassLoader()); int tmpMode = in.readInt(); this.mode = tmpMode == -1 ? null : Mode.values()[tmpMode]; if (this.mode == Mode.C_BUILD) { // If we were in condition builder mode, read those variables' values back. this.currPartIdx = in.readInt(); this.currFieldName = in.readString(); this.currTransName = in.readString(); this.currArgsString = in.readString(); } else if (this.mode == Mode.S_BUILD) { // If we were in sort builder mode, read those variables' values back. this.currSortFields = in.createStringArrayList(); this.currSortDirs = new ArrayList<>(); ArrayList<Integer> temp = new ArrayList<>(); in.readList(temp, null); for (Integer sortOrdinal : temp) this.currSortDirs.add(Sort.values()[sortOrdinal]); } }