示例#1
0
 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;
 }
示例#2
0
文件: Forms.java 项目: TLemur/SawimNE
 public boolean getCheckBoxValue(String controlId) {
   try {
     return get(controlId).selected;
   } catch (Exception e) {
     DebugLog.panic("getChoiceItemValue", e);
   }
   return false;
 }
示例#3
0
文件: Forms.java 项目: TLemur/SawimNE
 public String getSelectorString(String controlId) {
   try {
     return get(controlId).items[get(controlId).current];
   } catch (Exception e) {
     DebugLog.panic("getSelectorString", e);
   }
   return null;
 }
示例#4
0
文件: Forms.java 项目: TLemur/SawimNE
 public int getSelectorValue(String controlId) {
   try {
     return get(controlId).current;
   } catch (Exception e) {
     DebugLog.panic("getSelectorValue", e);
   }
   return 0;
 }
示例#5
0
文件: Forms.java 项目: TLemur/SawimNE
 public String getTextFieldValue(String controlId) {
   try {
     return get(controlId).text;
   } catch (Exception e) {
     DebugLog.panic("getTextFieldValue", e);
   }
   return null;
 }
示例#6
0
文件: Forms.java 项目: TLemur/SawimNE
 public int getGaugeValue(String controlId) {
   try {
     return get(controlId).level;
   } catch (Exception e) {
     DebugLog.panic("getGaugeValue", e);
   }
   return 0;
 }
示例#7
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;
 }
示例#8
0
 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);
   }
 }
示例#9
0
 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;
 }