use of com.abewy.android.apps.klyph.core.fql.MessageThread in project Klyph by jonathangerbaud.
the class Threads method onListItemClick.
@Override
public void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
GraphObject object = (GraphObject) l.getItemAtPosition(position);
if (object instanceof MessageThread) {
MessageThread thread = (MessageThread) l.getItemAtPosition(position);
Intent intent = new Intent(getActivity(), MessageActivity.class);
intent.putExtra(KlyphBundleExtras.THREAD_ID, thread.getThread_id());
// intent.putExtra(KlyphBundleExtras.THREAD_NAME, thread.getName());
startActivity(intent);
}
}
use of com.abewy.android.apps.klyph.core.fql.MessageThread in project Klyph by jonathangerbaud.
the class ThreadAdapter method bindData.
@Override
public void bindData(View view, GraphObject data) {
ThreadHolder holder = (ThreadHolder) getHolder(view);
MessageThread thread = (MessageThread) data;
List<Friend> friends = new ArrayList<Friend>();
friends.addAll(thread.getRecipients_friends());
String pic = null;
if (friends.size() > 0) {
for (int i = 0; i < friends.size(); i++) {
Friend friend = friends.get(i);
if (friend.getUid().equals(KlyphSession.getSessionUserId())) {
friends.remove(friend);
i--;
} else {
if (pic == null) {
pic = friend.getPic();
}
}
}
}
if (pic == null) {
pic = "";
}
Resources res = getContext(view).getResources();
holder.getAuthorName().setText("");
int n = friends.size();
Friend friend = null;
if (n > 0) {
friend = friends.get(0);
} else {
n = 1;
friend = thread.getRecipients_friends().get(0);
pic = friend.getPic();
}
String friendName = friend.getFirst_name().length() > 0 ? friend.getFirst_name() : friend.getName();
if (n == 1) {
holder.getAuthorName().setText(String.format(res.getString(R.string.thread_one_user), friend.getName()));
} else if (n > 1) {
Friend friend2 = friends.get(1);
String friendName2 = friend2.getFirst_name().length() > 0 ? friend2.getFirst_name() : friend2.getName();
if (n == 2) {
holder.getAuthorName().setText(String.format(res.getString(R.string.thread_two_users), friendName, friendName2));
} else if (n > 2) {
holder.getAuthorName().setText(String.format(res.getString(R.string.thread_many_users), friendName, friendName2, n - 2));
}
}
String message = "";
if (thread.getSnippet_author().equals(KlyphSession.getSessionUserId())) {
message = view.getContext().getString(R.string.my_last_message, thread.getSnippet());
} else if (thread.isMultiUserConversation()) {
for (Friend friend2 : thread.getRecipients_friends()) {
if (friend2.getUid().equals(thread.getSnippet_author())) {
message = view.getContext().getString(R.string.friend_last_message, friend2.getFirst_name(), thread.getSnippet());
break;
}
}
} else {
message = thread.getSnippet();
}
holder.getMessageTextView().setText(message);
EmojiUtil.convertTextToEmoji(holder.getMessageTextView(), false);
holder.getDateTextView().setText(DateUtil.getShortDate(thread.getUpdated_time()));
int unreadCount = thread.getUnread();
if (unreadCount > 0) {
if (unreadCount <= 99)
holder.getUnreadCountTextView().setText(thread.getUnread() + "");
else
holder.getUnreadCountTextView().setText("99+");
holder.getUnreadCountTextView().setVisibility(View.VISIBLE);
holder.getAuthorName().setTypeface(null, Typeface.BOLD);
holder.getMessageTextView().setTypeface(null, Typeface.BOLD);
holder.getDateTextView().setTypeface(null, Typeface.BOLD);
} else {
holder.getUnreadCountTextView().setVisibility(View.GONE);
holder.getAuthorName().setTypeface(null, Typeface.NORMAL);
holder.getMessageTextView().setTypeface(null, Typeface.NORMAL);
holder.getDateTextView().setTypeface(null, Typeface.NORMAL);
}
ImageLoader.display(holder.getAuthorPicture(), pic, KlyphUtil.getPlaceHolder(holder.getAuthorName().getContext()));
}
use of com.abewy.android.apps.klyph.core.fql.MessageThread in project Klyph by jonathangerbaud.
the class MessageThreadSerializer method serializeObject.
@Override
public JSONObject serializeObject(GraphObject object) {
JSONObject json = new JSONObject();
serializePrimitives(object, json);
MessageThread messageThread = (MessageThread) object;
FriendSerializer fs = new FriendSerializer();
try {
json.put("recipients_friends", fs.serializeArray(messageThread.getRecipients_friends()));
} catch (JSONException e) {
Log.d("MessageThreadSerializer", "JSONException " + e.getMessage());
}
return json;
}
use of com.abewy.android.apps.klyph.core.fql.MessageThread in project Klyph by jonathangerbaud.
the class MessageThreadDeserializer method deserializeObject.
@Override
public GraphObject deserializeObject(JSONObject data) {
MessageThread messageThread = new MessageThread();
deserializePrimitives(messageThread, data);
messageThread.setRecipients(deserializeStringList(getJsonArray(data, "recipients")));
messageThread.setRecipients_friends(new FriendDeserializer().deserializeArray(getJsonArray(data, "recipients_friends"), Friend.class));
return messageThread;
}
Aggregations