optimize ChatMessage handling and remove dead code
This commit is contained in:
parent
c32a058b9b
commit
8e9f7aa1d4
4 changed files with 19 additions and 93 deletions
|
@ -22,6 +22,7 @@ import java.io.ByteArrayInputStream;
|
|||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
|
@ -334,60 +335,44 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
|||
}
|
||||
|
||||
class ChatMessageAdapter extends BaseAdapter {
|
||||
LinphoneChatMessage[] history;
|
||||
ArrayList<LinphoneChatMessage> history;
|
||||
Context context;
|
||||
|
||||
public ChatMessageAdapter(Context context, LinphoneChatMessage[] history) {
|
||||
this.history = history;
|
||||
this.history = new ArrayList<LinphoneChatMessage>(Arrays.asList(history));
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
public void destroy() {
|
||||
this.history = null;
|
||||
history = null;
|
||||
}
|
||||
|
||||
public void refreshHistory() {
|
||||
this.history = null;
|
||||
this.history = chatRoom.getHistory();
|
||||
this.history = new ArrayList<LinphoneChatMessage>(Arrays.asList(chatRoom.getHistory()));
|
||||
}
|
||||
|
||||
public void addMessage(LinphoneChatMessage message) {
|
||||
LinphoneChatMessage[] newHist = new LinphoneChatMessage[getCount() +1];
|
||||
for(int i=0; i< getCount(); i++){
|
||||
newHist[i] = this.history[i];
|
||||
}
|
||||
newHist[getCount()] = message;
|
||||
this.history = newHist;
|
||||
}
|
||||
|
||||
public void removeMessage(LinphoneChatMessage message) {
|
||||
LinphoneChatMessage[] newHist = new LinphoneChatMessage[getCount() -1];
|
||||
for(int i=0; i< getCount(); i++){
|
||||
if(this.history[i].getStorageId() != newHist[i].getStorageId())
|
||||
newHist[i] = this.history[i];
|
||||
}
|
||||
newHist[getCount()] = message;
|
||||
this.history = newHist;
|
||||
history.add(message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return history.length;
|
||||
return history.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public LinphoneChatMessage getItem(int position) {
|
||||
return history[position];
|
||||
return history.get(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
return history[position].getStorageId();
|
||||
return history.get(position).getStorageId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(final int position, View convertView, ViewGroup parent) {
|
||||
LinphoneChatMessage message = history[position];
|
||||
LinphoneChatMessage message = history.get(position);
|
||||
|
||||
BubbleChat bubble = new BubbleChat(context, message, contact);
|
||||
View v = bubble.getView();
|
||||
|
@ -753,7 +738,7 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
|||
if (newChatConversation) {
|
||||
exitNewConversationMode(lAddress.asStringUriOnly());
|
||||
} else {
|
||||
invalidate();
|
||||
displayBubbleChat(message);
|
||||
}
|
||||
|
||||
Log.i("Sent message current status: " + message.getStatus());
|
||||
|
|
|
@ -280,64 +280,14 @@ public class ChatStorage {
|
|||
return drafts;
|
||||
}
|
||||
|
||||
public List<ChatMessage> getMessages(String correspondent) {
|
||||
List<ChatMessage> chatMessages = new ArrayList<ChatMessage>();
|
||||
|
||||
if (!useNativeAPI) {
|
||||
Cursor c = db.query(TABLE_NAME, null, "remoteContact LIKE \"" + correspondent + "\"", null, null, null, "id ASC");
|
||||
|
||||
while (c.moveToNext()) {
|
||||
try {
|
||||
String message, timestamp, url;
|
||||
int id = c.getInt(c.getColumnIndex("id"));
|
||||
int direction = c.getInt(c.getColumnIndex("direction"));
|
||||
message = c.getString(c.getColumnIndex("message"));
|
||||
timestamp = c.getString(c.getColumnIndex("time"));
|
||||
int status = c.getInt(c.getColumnIndex("status"));
|
||||
byte[] rawImage = c.getBlob(c.getColumnIndex("image"));
|
||||
int read = c.getInt(c.getColumnIndex("read"));
|
||||
url = c.getString(c.getColumnIndex("url"));
|
||||
|
||||
ChatMessage chatMessage = new ChatMessage(id, message, rawImage, timestamp, direction == INCOMING, status, read == READ);
|
||||
chatMessage.setUrl(url);
|
||||
chatMessages.add(chatMessage);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
c.close();
|
||||
} else {
|
||||
LinphoneChatRoom room = LinphoneManager.getLc().getOrCreateChatRoom(correspondent);
|
||||
LinphoneChatMessage[] history = room.getHistory();
|
||||
for (int i = 0; i < history.length; i++) {
|
||||
LinphoneChatMessage message = history[i];
|
||||
|
||||
Bitmap bm = null;
|
||||
String url = message.getExternalBodyUrl();
|
||||
if (url != null && !url.startsWith("http")) {
|
||||
bm = BitmapFactory.decodeFile(url);
|
||||
}
|
||||
ChatMessage chatMessage = new ChatMessage(i+1, message.getText(), bm,
|
||||
String.valueOf(message.getTime()), !message.isOutgoing(),
|
||||
message.getStatus().toInt(), message.isRead());
|
||||
chatMessage.setUrl(url);
|
||||
chatMessages.add(chatMessage);
|
||||
}
|
||||
}
|
||||
|
||||
return chatMessages;
|
||||
}
|
||||
|
||||
public String getTextMessageForId(LinphoneChatRoom chatroom, int id) {
|
||||
String message = null;
|
||||
|
||||
if (useNativeAPI) {
|
||||
LinphoneChatMessage[] history = chatroom.getHistory();
|
||||
for (LinphoneChatMessage msg : history) {
|
||||
if (msg.getStorageId() == id) {
|
||||
message = msg.getText();
|
||||
break;
|
||||
}
|
||||
LinphoneChatMessage msg = getMessage(chatroom, id);
|
||||
|
||||
if (msg != null) {
|
||||
message = msg.getText();
|
||||
}
|
||||
} else {
|
||||
Cursor c = db.query(TABLE_NAME, null, "id LIKE " + id, null, null, null, null);
|
||||
|
@ -410,12 +360,9 @@ public class ChatStorage {
|
|||
|
||||
public void deleteMessage(LinphoneChatRoom chatroom, int id) {
|
||||
if (useNativeAPI) {
|
||||
LinphoneChatMessage[] history = chatroom.getHistory();
|
||||
for (LinphoneChatMessage message : history) {
|
||||
if (message.getStorageId() == id) {
|
||||
chatroom.deleteMessage(message);
|
||||
break;
|
||||
}
|
||||
LinphoneChatMessage msg = getMessage(chatroom, id);
|
||||
if (msg != null){
|
||||
chatroom.deleteMessage(msg);
|
||||
}
|
||||
} else {
|
||||
db.delete(TABLE_NAME, "id LIKE " + id, null);
|
||||
|
|
|
@ -864,10 +864,6 @@ public class LinphoneActivity extends Activity implements OnClickListener, Conta
|
|||
return getChatStorage().getDrafts();
|
||||
}
|
||||
|
||||
public List<ChatMessage> getChatMessages(String correspondent) {
|
||||
return getChatStorage().getMessages(correspondent);
|
||||
}
|
||||
|
||||
public void removeFromChatList(String sipUri) {
|
||||
getChatStorage().removeDiscussion(sipUri);
|
||||
}
|
||||
|
@ -876,8 +872,6 @@ public class LinphoneActivity extends Activity implements OnClickListener, Conta
|
|||
getChatStorage().deleteDraft(sipUri);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void updateMissedChatCount() {
|
||||
displayMissedChats(getUnreadMessageCount());
|
||||
}
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 392271334671ff505926215847f42ae79a136e88
|
||||
Subproject commit fa00efddbb22cda2dabf6e0629de27ad40bbe45b
|
Loading…
Reference in a new issue