public List<Integer> getSearchMessagesIds(String search) { List<Integer> ids = new ArrayList<>(); if (search == null || search.isEmpty()) return ids; Cursor cursor = null; try { cursor = SawimApplication.getDatabaseHelper() .getReadableDatabase() .query( DatabaseHelper.TABLE_CHAT_HISTORY, null, WHERE_ACC_CONTACT_ID, new String[] {protocolId, uniqueUserId}, null, null, null); if (cursor.moveToFirst()) { for (int i = 0; i < cursor.getCount(); i++) { cursor.moveToPosition(i); String messTxt = cursor.getString(cursor.getColumnIndex(DatabaseHelper.MESSAGE)); if (messTxt.toLowerCase().contains(search)) { ids.add(i); } } } } catch (Exception e) { DebugLog.panic(e); } finally { if (cursor != null) { cursor.close(); } } return ids; }
public boolean getCheckBoxValue(String controlId) { try { return get(controlId).selected; } catch (Exception e) { DebugLog.panic("getChoiceItemValue", e); } return false; }
public String getSelectorString(String controlId) { try { return get(controlId).items[get(controlId).current]; } catch (Exception e) { DebugLog.panic("getSelectorString", e); } return null; }
public int getSelectorValue(String controlId) { try { return get(controlId).current; } catch (Exception e) { DebugLog.panic("getSelectorValue", e); } return 0; }
public String getTextFieldValue(String controlId) { try { return get(controlId).text; } catch (Exception e) { DebugLog.panic("getTextFieldValue", e); } return null; }
public int getGaugeValue(String controlId) { try { return get(controlId).level; } catch (Exception e) { DebugLog.panic("getGaugeValue", e); } return 0; }
public synchronized boolean hasLastMessage(Chat chat, Message message) { Contact contact = chat.getContact(); boolean hasMessage = false; Cursor cursor = null; try { cursor = SawimApplication.getDatabaseHelper() .getReadableDatabase() .query( DatabaseHelper.TABLE_CHAT_HISTORY, null, DatabaseHelper.CONTACT_ID + " = ?", new String[] {uniqueUserId}, null, null, DatabaseHelper.DATE + " DESC", String.valueOf(60)); if (cursor.moveToLast()) { do { short rowData = cursor.getShort(cursor.getColumnIndex(DatabaseHelper.ROW_DATA)); MessData mess = Chat.buildMessage( contact, message, contact.isConference() ? message.getName() : chat.getFrom(message), false, Chat.isHighlight(message.getProcessedText(), contact.getMyName())); MessData messFromDataBase = buildMessage(chat, cursor); boolean isMessage = (rowData & MessData.PRESENCE) == 0 && (rowData & MessData.SERVICE) == 0 && (rowData & MessData.PROGRESS) == 0; if (isMessage) { hasMessage = hasMessage(mess, messFromDataBase); if (hasMessage) { return true; } } } while (cursor.moveToPrevious()); } } catch (Exception e) { DebugLog.panic(e); } finally { if (cursor != null) { cursor.close(); } } return hasMessage; }
public void removeHistory() { try { Contact contact = RosterHelper.getInstance().getProtocol(protocolId).getItemByUID(uniqueUserId); contact.firstServerMsgId = ""; // RosterStorage.updateFirstServerMsgId(contact); RosterHelper.getInstance() .getProtocol(protocolId) .getStorage() .updateUnreadMessagesCount(protocolId, uniqueUserId, 0); SawimApplication.getDatabaseHelper() .getWritableDatabase() .delete( DatabaseHelper.TABLE_CHAT_HISTORY, WHERE_ACC_CONTACT_ID, new String[] {protocolId, uniqueUserId}); } catch (Exception e) { DebugLog.panic(e); } }
public synchronized long getMessageTime(boolean last) { long lastMessageTime = 0; Cursor cursor = null; try { cursor = SawimApplication.getDatabaseHelper() .getReadableDatabase() .query( DatabaseHelper.TABLE_CHAT_HISTORY, null, WHERE_ACC_CONTACT_ID, new String[] {protocolId, uniqueUserId}, null, null, DatabaseHelper.DATE + " ASC"); if (last ? cursor.moveToLast() : cursor.moveToFirst()) { do { boolean isIncoming = cursor.getInt(cursor.getColumnIndex(DatabaseHelper.INCOMING)) == 0; int sendingState = cursor.getInt(cursor.getColumnIndex(DatabaseHelper.SENDING_STATE)); short rowData = cursor.getShort(cursor.getColumnIndex(DatabaseHelper.ROW_DATA)); boolean isMessage = (rowData & MessData.PRESENCE) == 0 && (rowData & MessData.SERVICE) == 0 && (rowData & MessData.PROGRESS) == 0; if ((isMessage && sendingState == Message.NOTIFY_FROM_SERVER && !isIncoming) || isMessage) { lastMessageTime = cursor.getLong(cursor.getColumnIndex(DatabaseHelper.DATE)); break; } } while (last ? cursor.moveToPrevious() : cursor.moveToFirst()); } } catch (Exception e) { DebugLog.panic(e); } finally { if (cursor != null) { cursor.close(); } } return lastMessageTime; }