io.realm.Case Java Examples
The following examples show how to use
io.realm.Case.
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: TokensRealmSource.java From alpha-wallet-android with MIT License | 6 votes |
@Override public Token updateTokenType(Token token, Wallet wallet, ContractType type) { try (Realm realm = realmManager.getRealmInstance(wallet)) { String dbKey = databaseKey(token.tokenInfo.chainId, token.tokenInfo.address); RealmToken realmToken = realm.where(RealmToken.class) .equalTo("address", dbKey, Case.INSENSITIVE) .findFirst(); if (realmToken == null) { saveToken(wallet, token, new Date()); } else { realm.beginTransaction(); realmToken.setInterfaceSpec(type.ordinal()); realmToken.setName(token.tokenInfo.name); realmToken.setSymbol(token.tokenInfo.symbol); realm.commitTransaction(); } return fetchToken(token.tokenInfo.chainId, wallet, token.getAddress()); } }
Example #2
Source File: SaturdayFragment.java From StudentAttendanceCheck with MIT License | 6 votes |
@SuppressWarnings("UnusedParameters") private void initInstances(View rootView, Bundle savedInstanceState) { // Init 'View' instance(s) with rootView.findViewById here // Note: State of variable initialized here could not be saved // in onSavedInstanceState realm = Realm.getDefaultInstance(); RealmResults<StudentModuleDao> studentModuleDao = realm.getDefaultInstance().where(StudentModuleDao.class).equalTo("day","Sat", Case.SENSITIVE).findAll(); if (studentModuleDao.size()!=0) { LinearLayoutManager rvLayoutManager = new LinearLayoutManager(getContext()); b.rvSaturdayTimeTable.setLayoutManager(rvLayoutManager); mTimeTableListAdapter = new TimeTableListAdapter(getContext(), studentModuleDao, true); b.rvSaturdayTimeTable.setAdapter(mTimeTableListAdapter); b.rvSaturdayTimeTable.setHasFixedSize(true); } else { b.rvSaturdayTimeTable.setVisibility(View.GONE); b.satNoModuleText.setText("You are free today"); b.satNoModuleText.setVisibility(View.VISIBLE); } // connectToDataBase(); }
Example #3
Source File: WednesdayFragment.java From StudentAttendanceCheck with MIT License | 6 votes |
@SuppressWarnings("UnusedParameters") private void initInstances(View rootView, Bundle savedInstanceState) { // Init 'View' instance(s) with rootView.findViewById here // Note: State of variable initialized here could not be saved // in onSavedInstanceState realm = Realm.getDefaultInstance(); RealmResults<StudentModuleDao> studentModuleDao = realm.getDefaultInstance().where(StudentModuleDao.class).equalTo("day","Wed", Case.SENSITIVE).findAll(); if (studentModuleDao.size()!=0) { LinearLayoutManager rvLayoutManager = new LinearLayoutManager(getContext()); b.rvWednesdayTimeTable.setLayoutManager(rvLayoutManager); mTimeTableListAdapter = new TimeTableListAdapter(getContext(), studentModuleDao, true); b.rvWednesdayTimeTable.setAdapter(mTimeTableListAdapter); b.rvWednesdayTimeTable.setHasFixedSize(true); } else { b.rvWednesdayTimeTable.setVisibility(View.GONE); b.wedNoModuleText.setText("You are free today"); b.wedNoModuleText.setVisibility(View.VISIBLE); } // connectToDataBase(); }
Example #4
Source File: ThursdayFragment.java From StudentAttendanceCheck with MIT License | 6 votes |
@SuppressWarnings("UnusedParameters") private void initInstances(View rootView, Bundle savedInstanceState) { // Init 'View' instance(s) with rootView.findViewById here // Note: State of variable initialized here could not be saved // in onSavedInstanceState realm = Realm.getDefaultInstance(); RealmResults<StudentModuleDao> studentModuleDao = realm.getDefaultInstance().where(StudentModuleDao.class).equalTo("day","Thu", Case.SENSITIVE).findAll(); if (studentModuleDao.size()!=0) { LinearLayoutManager rvLayoutManager = new LinearLayoutManager(getContext()); b.rvThursdayTimeTable.setLayoutManager(rvLayoutManager); mTimeTableListAdapter = new TimeTableListAdapter(getContext(), studentModuleDao, true); b.rvThursdayTimeTable.setAdapter(mTimeTableListAdapter); b.rvThursdayTimeTable.setHasFixedSize(true); } else { b.rvThursdayTimeTable.setVisibility(View.GONE); b.thuNoModuleText.setText("You are free today"); b.thuNoModuleText.setVisibility(View.VISIBLE); } // connectToDataBase(); }
Example #5
Source File: RealmMember.java From iGap-Android with GNU Affero General Public License v3.0 | 5 votes |
public static RealmResults<RealmMember> filterMember(long roomId, @Nullable String filter) { Realm realm = Realm.getDefaultInstance(); RealmRoom realmRoom = realm.where(RealmRoom.class).equalTo(RealmRoomFields.ID, roomId).findFirst(); if (realmRoom == null) { return emptyResult(realm); } RealmResults<RealmMember> searchMember = emptyResult(realm); RealmResults<RealmRegisteredInfo> findMember; if (filter != null && filter.length() > 0) { findMember = realm.where(RealmRegisteredInfo.class).contains(RealmRegisteredInfoFields.DISPLAY_NAME, filter, Case.INSENSITIVE).findAll().sort(RealmRegisteredInfoFields.DISPLAY_NAME); } else { findMember = realm.where(RealmRegisteredInfo.class).equalTo(RealmRoomFields.ID, roomId).findAll().sort(RealmRegisteredInfoFields.DISPLAY_NAME); } try { RealmQuery<RealmMember> query; if (realmRoom.getType() == GROUP) { query = realmRoom.getGroupRoom().getMembers().where(); } else { query = realmRoom.getChannelRoom().getMembers().where(); } for (int i = 0; i < findMember.size(); i++) { if (i != 0) { query = query.or(); } query = query.equalTo(RealmMemberFields.PEER_ID, findMember.get(i).getId()); } if (findMember.size() > 0 || (filter == null || filter.length() == 0)) { searchMember = query.findAll(); } } catch (Exception e) { e.printStackTrace(); } return searchMember; }
Example #6
Source File: SendDialogFragment.java From natrium-android-wallet with BSD 2-Clause "Simplified" License | 5 votes |
private void updateContactSearch() { String searchTerm = binding.sendAddress.getText().toString(); if (!searchTerm.startsWith("@")) { return; } searchTerm = searchTerm.substring(1, searchTerm.length()); List<Contact> contacts = realm.where(Contact.class).contains("name", searchTerm, Case.INSENSITIVE).findAll().sort("name"); mAdapter.updateList(contacts); // Colorize name if a valid contact if (contacts.size() > 0) { binding.contactRecyclerview.setVisibility(View.VISIBLE); binding.sendAddress.setBackground(getResources().getDrawable(R.drawable.bg_edittext_bottom_round)); String name = binding.sendAddress.getText().toString().trim(); boolean foundMatch = false; for (Contact c : contacts) { if (c.getName().equals(name)) { binding.sendAddress.setTextColor(getResources().getColor(R.color.ltblue)); foundMatch = true; break; } } if (!foundMatch) { binding.sendAddress.setTextColor(getResources().getColor(R.color.white_60)); } } else { binding.contactRecyclerview.setVisibility(View.GONE); binding.sendAddress.setBackground(getResources().getDrawable(R.drawable.bg_edittext)); binding.sendAddress.setTextColor(getResources().getColor(R.color.white_60)); } }
Example #7
Source File: SearchFragment.java From iGap-Android with GNU Affero General Public License v3.0 | 5 votes |
private void fillChat(String text) { Realm realm = Realm.getDefaultInstance(); final RealmResults<RealmRegisteredInfo> results; if (edtSearch.getText().toString().startsWith("@")) { results = realm.where(RealmRegisteredInfo.class).contains(RealmRegisteredInfoFields.USERNAME, text, Case.INSENSITIVE).equalTo(RealmRegisteredInfoFields.IS_BOT, false).findAll(); } else { results = realm.where(RealmRegisteredInfo.class).equalTo(RealmRegisteredInfoFields.IS_BOT, false).beginGroup().contains(RealmRegisteredInfoFields.USERNAME, text, Case.INSENSITIVE).or().contains(RealmRegisteredInfoFields.DISPLAY_NAME, text).endGroup().findAll(); } if (results != null && results.size() > 0) { addHeader(G.fragmentActivity.getResources().getString(R.string.member)); for (RealmRegisteredInfo contact : results) { StructSearch item = new StructSearch(); item.name = contact.getDisplayName(); item.time = contact.getLastSeen(); item.userName = contact.getUsername(); item.comment = ""; item.id = contact.getId(); item.idDetectAvatar = contact.getId(); item.type = SearchType.contact; item.initials = contact.getInitials(); item.color = contact.getColor(); item.avatar = contact.getLastAvatar(); list.add(item); } } realm.close(); }
Example #8
Source File: SearchFragment.java From iGap-Android with GNU Affero General Public License v3.0 | 5 votes |
private void fillBot(String text) { Realm realm = Realm.getDefaultInstance(); final RealmResults<RealmRegisteredInfo> results; if (edtSearch.getText().toString().startsWith("@")) { results = realm.where(RealmRegisteredInfo.class).contains(RealmRegisteredInfoFields.USERNAME, text, Case.INSENSITIVE).equalTo(RealmRegisteredInfoFields.IS_BOT, true).findAll(); } else { results = realm.where(RealmRegisteredInfo.class).beginGroup().contains(RealmRegisteredInfoFields.USERNAME, text, Case.INSENSITIVE).or().contains(RealmRegisteredInfoFields.DISPLAY_NAME, text).endGroup().equalTo(RealmRegisteredInfoFields.IS_BOT, true).findAll(); } if (results != null && results.size() > 0) { addHeader(G.fragmentActivity.getResources().getString(R.string.bot)); for (RealmRegisteredInfo contact : results) { StructSearch item = new StructSearch(); item.name = contact.getDisplayName(); item.time = contact.getLastSeen(); item.userName = contact.getUsername(); item.comment = ""; item.id = contact.getId(); item.idDetectAvatar = contact.getId(); item.type = SearchType.contact; item.initials = contact.getInitials(); item.color = contact.getColor(); item.avatar = contact.getLastAvatar(); list.add(item); } } realm.close(); }
Example #9
Source File: TodayModule.java From StudentAttendanceCheck with MIT License | 5 votes |
public RealmResults<StudentModuleDao> getTodayModule() { String weekDay = dayOfWeek(); Realm realm = Realm.getDefaultInstance(); RealmResults<StudentModuleDao> studentModuleDao = realm.getDefaultInstance() .where(StudentModuleDao.class) .equalTo("day",weekDay.trim(), Case.SENSITIVE).findAll(); return studentModuleDao; }
Example #10
Source File: FridayFragment.java From StudentAttendanceCheck with MIT License | 5 votes |
@SuppressWarnings("UnusedParameters") private void initInstances(View rootView, Bundle savedInstanceState) { // Init 'View' instance(s) with rootView.findViewById here // Note: State of variable initialized here could not be saved // in onSavedInstanceState realm = Realm.getDefaultInstance(); RealmResults<StudentModuleDao> studentModuleDao = realm.getDefaultInstance().where(StudentModuleDao.class).equalTo("day","Fri", Case.SENSITIVE).findAll(); if (studentModuleDao.size()!=0) { LinearLayoutManager rvLayoutManager = new LinearLayoutManager(getContext()); b.rvFridayTimeTable.setLayoutManager(rvLayoutManager); mTimeTableListAdapter = new TimeTableListAdapter(getContext(), studentModuleDao, true); b.rvFridayTimeTable.setAdapter(mTimeTableListAdapter); b.rvFridayTimeTable.setHasFixedSize(true); } else { b.rvFridayTimeTable.setVisibility(View.GONE); b.friNoModuleText.setText("You are free today"); b.friNoModuleText.setVisibility(View.VISIBLE); } // connectToDataBase(); }
Example #11
Source File: MondayFragment.java From StudentAttendanceCheck with MIT License | 5 votes |
private void connectToDataBase() { // hardcoded item to RecyclerView // for (int i = 0; i < 100; i++) { // //// AddModuleItem addModuleItem = new AddModuleItem("item " + i, "item2 " + i, false); // TimeTableListItem timeTableListItem = new TimeTableListItem("Mon module " + i, "A000" + i, i % 2 == 0 ? "active" : "inactive", "9-12", "School of Engineering"); // mTimeTableListItems.add(timeTableListItem); // // } realm = Realm.getDefaultInstance(); // RealmResults<StudentModuleDao> student = realm.where(StudentModuleDao.class).findAll(); // Log.w("REALM QUERY", student.get(0).getName()); RealmResults<StudentModuleDao> student = realm.where(StudentModuleDao.class).contains("day","mon",Case.SENSITIVE).findAll(); mLayoutManager = new LinearLayoutManager(getContext()); b.rvMondayTimeTable.setLayoutManager(mLayoutManager); // set layout manager of recycler view b.rvMondayTimeTable.setHasFixedSize(true); Log.e("onResume: ", String.valueOf(student.size())); if (TimeTableListAdapter == null) { TimeTableListAdapter = new TimeTableListAdapter(getContext(),student ,true); // throw data from Realm into recyclerView b.rvMondayTimeTable.setAdapter(TimeTableListAdapter); } // mTimeTableListAdapter.notifyDataSetChanged(); }
Example #12
Source File: MondayFragment.java From StudentAttendanceCheck with MIT License | 5 votes |
@SuppressWarnings("UnusedParameters") private void initInstances(View rootView, Bundle savedInstanceState) { // Init 'View' instance(s) with rootView.findViewById here // Note: State of variable initialized here could not be saved // in onSavedInstanceState // Log.w("MONDAY_module", String.valueOf(moduleToShow.size())); realm = Realm.getDefaultInstance(); RealmResults<StudentModuleDao> moduleToShow = realm.where(StudentModuleDao.class).equalTo("day","Mon",Case.SENSITIVE).findAll(); if (moduleToShow.size()!=0) { // If there is any module to show LinearLayoutManager rvLayoutManager = new LinearLayoutManager(getContext()); b.rvMondayTimeTable.setLayoutManager(rvLayoutManager); TimeTableListAdapter mTimeTableListAdapter = new TimeTableListAdapter(getContext(), moduleToShow, true); b.rvMondayTimeTable.setAdapter(mTimeTableListAdapter); b.rvMondayTimeTable.setHasFixedSize(true); } else { b.rvMondayTimeTable.setVisibility(View.GONE); b.monNoModuleText.setText("You are free today"); b.monNoModuleText.setVisibility(View.VISIBLE); } // connectToDataBase(); }
Example #13
Source File: TuesdayFragment.java From StudentAttendanceCheck with MIT License | 5 votes |
@SuppressWarnings("UnusedParameters") private void initInstances(View rootView, Bundle savedInstanceState) { // Init 'View' instance(s) with rootView.findViewById here // Note: State of variable initialized here could not be saved // in onSavedInstanceState realm = Realm.getDefaultInstance(); RealmResults<StudentModuleDao> studentModuleDao = realm.getDefaultInstance().where(StudentModuleDao.class).equalTo("day","Tue", Case.SENSITIVE).findAll(); if (studentModuleDao.size()!=0) { LinearLayoutManager rvLayoutManager = new LinearLayoutManager(getContext()); b.rvTuesdayTimeTable.setLayoutManager(rvLayoutManager); mTimeTableListAdapter = new TimeTableListAdapter(getContext(), studentModuleDao, true); b.rvTuesdayTimeTable.setAdapter(mTimeTableListAdapter); b.rvTuesdayTimeTable.setHasFixedSize(true); } else { b.rvTuesdayTimeTable.setVisibility(View.GONE); b.tueNoModuleText.setText("You are free today"); b.tueNoModuleText.setVisibility(View.VISIBLE); } // connectToDataBase(); }
Example #14
Source File: SundayFragment.java From StudentAttendanceCheck with MIT License | 5 votes |
@SuppressWarnings("UnusedParameters") private void initInstances(View rootView, Bundle savedInstanceState) { // Init 'View' instance(s) with rootView.findViewById here // Note: State of variable initialized here could not be saved // in onSavedInstanceState realm = Realm.getDefaultInstance(); RealmResults<StudentModuleDao> studentModuleDao = realm.getDefaultInstance().where(StudentModuleDao.class).equalTo("day","Sun", Case.SENSITIVE).findAll(); if (studentModuleDao.size()!=0) { LinearLayoutManager rvLayoutManager = new LinearLayoutManager(getContext()); b.rvSundayTimeTable.setLayoutManager(rvLayoutManager); mTimeTableListAdapter = new TimeTableListAdapter(getContext(), studentModuleDao, true); b.rvSundayTimeTable.setAdapter(mTimeTableListAdapter); b.rvSundayTimeTable.setHasFixedSize(true); } else { b.rvSundayTimeTable.setVisibility(View.GONE); b.sunNoModuleText.setText("You are free today"); b.sunNoModuleText.setVisibility(View.VISIBLE); } // connectToDataBase(); }
Example #15
Source File: PagedFragment.java From realm-monarchy with Apache License 2.0 | 5 votes |
@OnTextChanged(R.id.text_paged_search) public void onSearchTextChanged(Editable editable) { String text = editable.toString(); realmDataSourceFactory.updateQuery(realm -> { RealmQuery<RealmDog> query = realm.where(RealmDog.class); if(text.isEmpty()) { return query; } else { return query.contains(RealmDogFields.NAME, text.trim(), Case.INSENSITIVE); } }); }
Example #16
Source File: SearchFragment.java From iGap-Android with GNU Affero General Public License v3.0 | 4 votes |
private void fillHashtag(String text) { Realm realm = Realm.getDefaultInstance(); if (!text.startsWith("#")) { text = "#" + text; } final RealmResults<RealmRoomMessage> results = realm.where(RealmRoomMessage.class).equalTo(RealmRoomMessageFields.HAS_MESSAGE_LINK, true).contains(RealmRoomMessageFields.MESSAGE, text, Case.INSENSITIVE).equalTo(RealmRoomMessageFields.EDITED, false).isNotEmpty(RealmRoomMessageFields.MESSAGE).findAll(); if (results != null && results.size() > 0) { addHeader(G.fragmentActivity.getResources().getString(R.string.hashtag)); for (RealmRoomMessage roomMessage : results) { StructSearch item = new StructSearch(); item.time = roomMessage.getUpdateTime(); item.comment = roomMessage.getMessage(); item.id = roomMessage.getRoomId(); item.type = SearchType.message; item.messageId = roomMessage.getMessageId(); RealmRoom realmRoom = realm.where(RealmRoom.class).equalTo(RealmRoomFields.ID, roomMessage.getRoomId()).findFirst(); if (realmRoom != null) { // room exist item.name = realmRoom.getTitle(); item.initials = realmRoom.getInitials(); item.color = realmRoom.getColor(); item.roomType = realmRoom.getType(); item.avatar = realmRoom.getAvatar(); if (realmRoom.getType() == ProtoGlobal.Room.Type.CHAT && realmRoom.getChatRoom() != null) { item.idDetectAvatar = realmRoom.getChatRoom().getPeerId(); } else { item.idDetectAvatar = realmRoom.getId(); } list.add(item); } } } realm.close(); }
Example #17
Source File: SearchFragment.java From iGap-Android with GNU Affero General Public License v3.0 | 4 votes |
private void fillRoomListGroup(String text) { Realm realm = Realm.getDefaultInstance(); final RealmResults<RealmRoom> results; if (edtSearch.getText().toString().startsWith("@")) { results = realm.where(RealmRoom.class).beginGroup().contains(RealmRoomFields.CHANNEL_ROOM.USERNAME, text, Case.INSENSITIVE).or().contains(RealmRoomFields.GROUP_ROOM.USERNAME, text, Case.INSENSITIVE).endGroup().equalTo(RealmRoomFields.TYPE, "GROUP", Case.INSENSITIVE).findAll(); } else { results = realm.where(RealmRoom.class).beginGroup().contains(RealmRoomFields.TITLE, text, Case.INSENSITIVE).or().contains(RealmRoomFields.CHANNEL_ROOM.USERNAME, text, Case.INSENSITIVE).or().contains(RealmRoomFields.GROUP_ROOM.USERNAME, text, Case.INSENSITIVE).endGroup().equalTo(RealmRoomFields.TYPE, "GROUP", Case.INSENSITIVE).findAll(); } if (results != null) { if (results.size() > 0) addHeader(G.fragmentActivity.getResources().getString(R.string.Groups)); for (RealmRoom realmRoom : results) { StructSearch item = new StructSearch(); item.roomType = realmRoom.getType(); item.name = realmRoom.getTitle(); item.time = realmRoom.getUpdatedTime(); item.id = realmRoom.getId(); if (realmRoom.getType() == ProtoGlobal.Room.Type.CHAT && realmRoom.getChatRoom() != null) { item.idDetectAvatar = realmRoom.getChatRoom().getPeerId(); } else { if (realmRoom.getType() == ProtoGlobal.Room.Type.GROUP && realmRoom.getGroupRoom() != null) { item.userName = realmRoom.getGroupRoom().getUsername(); } else if (realmRoom.getType() == ProtoGlobal.Room.Type.CHANNEL && realmRoom.getChannelRoom() != null) { item.userName = realmRoom.getChannelRoom().getUsername(); } item.idDetectAvatar = realmRoom.getId(); } item.type = SearchType.room; item.initials = realmRoom.getInitials(); item.color = realmRoom.getColor(); item.avatar = realmRoom.getAvatar(); list.add(item); } } realm.close(); }
Example #18
Source File: SearchFragment.java From iGap-Android with GNU Affero General Public License v3.0 | 4 votes |
private void fillRoomListChannel(String text) { Realm realm = Realm.getDefaultInstance(); final RealmResults<RealmRoom> results; if (edtSearch.getText().toString().startsWith("@")) { results = realm.where(RealmRoom.class).beginGroup().contains(RealmRoomFields.CHANNEL_ROOM.USERNAME, text, Case.INSENSITIVE).or().contains(RealmRoomFields.GROUP_ROOM.USERNAME, text, Case.INSENSITIVE).endGroup().equalTo(RealmRoomFields.TYPE, "CHANNEL", Case.INSENSITIVE).findAll(); } else { results = realm.where(RealmRoom.class).beginGroup().contains(RealmRoomFields.TITLE, text, Case.INSENSITIVE).or().contains(RealmRoomFields.CHANNEL_ROOM.USERNAME, text, Case.INSENSITIVE).or().contains(RealmRoomFields.GROUP_ROOM.USERNAME, text, Case.INSENSITIVE).endGroup().equalTo(RealmRoomFields.TYPE, "CHANNEL", Case.INSENSITIVE).findAll(); } if (results != null && results.size() > 0) { addHeader(G.fragmentActivity.getResources().getString(R.string.channel)); for (RealmRoom realmRoom : results) { StructSearch item = new StructSearch(); item.roomType = realmRoom.getType(); item.name = realmRoom.getTitle(); item.time = realmRoom.getUpdatedTime(); item.id = realmRoom.getId(); if (realmRoom.getType() == ProtoGlobal.Room.Type.CHAT && realmRoom.getChatRoom() != null) { item.idDetectAvatar = realmRoom.getChatRoom().getPeerId(); } else { if (realmRoom.getType() == ProtoGlobal.Room.Type.GROUP && realmRoom.getGroupRoom() != null) { item.userName = realmRoom.getGroupRoom().getUsername(); } else if (realmRoom.getType() == ProtoGlobal.Room.Type.CHANNEL && realmRoom.getChannelRoom() != null) { item.userName = realmRoom.getChannelRoom().getUsername(); } item.idDetectAvatar = realmRoom.getId(); } item.type = SearchType.room; item.initials = realmRoom.getInitials(); item.color = realmRoom.getColor(); item.avatar = realmRoom.getAvatar(); list.add(item); } } realm.close(); }
Example #19
Source File: SearchFragment.java From iGap-Android with GNU Affero General Public License v3.0 | 4 votes |
private void fillContacts(String text) { int size = list.size(); Realm realm = Realm.getDefaultInstance(); final RealmResults<RealmContacts> results; if (edtSearch.getText().toString().startsWith("@")) { results = realm.where(RealmContacts.class).contains(RealmContactsFields.USERNAME, text, Case.INSENSITIVE).findAll(); } else { results = realm.where(RealmContacts.class).beginGroup().contains(RealmContactsFields.USERNAME, text, Case.INSENSITIVE).or().contains(RealmContactsFields.DISPLAY_NAME, text).endGroup().findAll(); } if (results != null) { for (RealmContacts contact : results) { Long phone = contact.getPhone(); String str = phone.toString().replaceAll(" ", ""); if (str.length() > 10) { str = str.substring(str.length() - 10, str.length()); } StructSearch item = new StructSearch(); item.name = contact.getDisplay_name(); item.time = contact.getLast_seen(); item.comment = str; item.userName = contact.getUsername(); item.id = contact.getId(); item.idDetectAvatar = contact.getId(); item.type = SearchType.contact; item.initials = contact.getInitials(); item.color = contact.getColor(); item.avatar = contact.getAvatar(); list.add(item); } } // if (size == list.size()) list.remove(size - 1); realm.close(); }
Example #20
Source File: SearchFragment.java From iGap-Android with GNU Affero General Public License v3.0 | 4 votes |
private void fillMessages(String text) { int size = list.size(); Realm realm = Realm.getDefaultInstance(); final RealmResults<RealmRoomMessage> results = realm.where(RealmRoomMessage.class).contains(RealmRoomMessageFields.MESSAGE, text, Case.INSENSITIVE).equalTo(RealmRoomMessageFields.EDITED, false).isNotEmpty(RealmRoomMessageFields.MESSAGE).findAll(); if (results != null && results.size() > 0) { addHeader(G.fragmentActivity.getResources().getString(R.string.messages)); for (RealmRoomMessage roomMessage : results) { StructSearch item = new StructSearch(); item.time = roomMessage.getUpdateTime(); item.comment = roomMessage.getMessage(); item.id = roomMessage.getRoomId(); item.type = SearchType.message; item.messageId = roomMessage.getMessageId(); RealmRoom realmRoom = realm.where(RealmRoom.class).equalTo(RealmRoomFields.ID, roomMessage.getRoomId()).findFirst(); if (realmRoom != null) { // room exist item.name = realmRoom.getTitle(); item.initials = realmRoom.getInitials(); item.color = realmRoom.getColor(); item.roomType = realmRoom.getType(); item.avatar = realmRoom.getAvatar(); if (realmRoom.getType() == ProtoGlobal.Room.Type.CHAT && realmRoom.getChatRoom() != null) { item.idDetectAvatar = realmRoom.getChatRoom().getPeerId(); } else { if (realmRoom.getType() == ProtoGlobal.Room.Type.GROUP && realmRoom.getGroupRoom() != null) { item.userName = realmRoom.getGroupRoom().getUsername(); } else if (realmRoom.getType() == ProtoGlobal.Room.Type.CHANNEL && realmRoom.getChannelRoom() != null) { item.userName = realmRoom.getChannelRoom().getUsername(); } item.idDetectAvatar = realmRoom.getId(); } list.add(item); } } } // if (size == list.size()) { // list.remove(size - 1); // } realm.close(); }