Sort chatrooms in chatrooms list
This commit is contained in:
parent
4fa623033d
commit
e760604c46
1 changed files with 123 additions and 110 deletions
|
@ -26,9 +26,7 @@ import android.graphics.Typeface;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.BaseAdapter;
|
|
||||||
import android.widget.CheckBox;
|
import android.widget.CheckBox;
|
||||||
import android.widget.CompoundButton;
|
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
@ -41,11 +39,14 @@ import org.linphone.contacts.LinphoneContact;
|
||||||
import org.linphone.core.Address;
|
import org.linphone.core.Address;
|
||||||
import org.linphone.core.ChatMessage;
|
import org.linphone.core.ChatMessage;
|
||||||
import org.linphone.core.ChatRoom;
|
import org.linphone.core.ChatRoom;
|
||||||
|
import org.linphone.core.EventLog;
|
||||||
import org.linphone.ui.ListSelectionAdapter;
|
import org.linphone.ui.ListSelectionAdapter;
|
||||||
import org.linphone.ui.ListSelectionHelper;
|
import org.linphone.ui.ListSelectionHelper;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class ChatRoomsAdapter extends ListSelectionAdapter {
|
public class ChatRoomsAdapter extends ListSelectionAdapter {
|
||||||
|
@ -84,6 +85,18 @@ public class ChatRoomsAdapter extends ListSelectionAdapter {
|
||||||
|
|
||||||
public void refresh() {
|
public void refresh() {
|
||||||
mRooms = new ArrayList<>(Arrays.asList(LinphoneManager.getLc().getChatRooms()));
|
mRooms = new ArrayList<>(Arrays.asList(LinphoneManager.getLc().getChatRooms()));
|
||||||
|
Collections.sort(mRooms, new Comparator<ChatRoom>() {
|
||||||
|
public int compare(ChatRoom cr1, ChatRoom cr2) {
|
||||||
|
EventLog cr1Logs[] = cr1.getHistoryEvents(1);
|
||||||
|
EventLog cr2Logs[] = cr2.getHistoryEvents(1);
|
||||||
|
if (cr1Logs.length <= 0) return -1;
|
||||||
|
if (cr2Logs.length <= 0) return 1;
|
||||||
|
long timeDiff = cr1Logs[0].getCreationTime() - cr2Logs[0].getCreationTime();
|
||||||
|
if (timeDiff > 0) return 1;
|
||||||
|
else if (timeDiff == 0) return 0;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
});
|
||||||
notifyDataSetChanged();
|
notifyDataSetChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue