UI code refactoring

This commit is contained in:
iNPUTmice 2014-11-07 15:38:20 +01:00
parent e42b6d715b
commit e45d7bda38
3 changed files with 177 additions and 258 deletions

View File

@ -15,6 +15,7 @@ import android.os.SystemClock;
import android.provider.MediaStore; import android.provider.MediaStore;
import android.support.v4.widget.SlidingPaneLayout; import android.support.v4.widget.SlidingPaneLayout;
import android.support.v4.widget.SlidingPaneLayout.PanelSlideListener; import android.support.v4.widget.SlidingPaneLayout.PanelSlideListener;
import android.util.Log;
import android.view.KeyEvent; import android.view.KeyEvent;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
@ -31,6 +32,7 @@ import android.widget.Toast;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import eu.siacs.conversations.Config;
import eu.siacs.conversations.R; import eu.siacs.conversations.R;
import eu.siacs.conversations.entities.Contact; import eu.siacs.conversations.entities.Contact;
import eu.siacs.conversations.entities.Conversation; import eu.siacs.conversations.entities.Conversation;
@ -72,8 +74,8 @@ public class ConversationActivity extends XmppActivity implements
private List<Conversation> conversationList = new ArrayList<Conversation>(); private List<Conversation> conversationList = new ArrayList<Conversation>();
private Conversation selectedConversation = null; private Conversation selectedConversation = null;
private ListView listView; private ListView listView;
private ConversationFragment mConversationFragment;
private boolean paneShouldBeOpen = true;
private ArrayAdapter<Conversation> listAdapter; private ArrayAdapter<Conversation> listAdapter;
private Toast prepareImageToast; private Toast prepareImageToast;
@ -95,10 +97,6 @@ public class ConversationActivity extends XmppActivity implements
return this.listView; return this.listView;
} }
public boolean shouldPaneBeOpen() {
return paneShouldBeOpen;
}
public void showConversationsOverview() { public void showConversationsOverview() {
if (mContentView instanceof SlidingPaneLayout) { if (mContentView instanceof SlidingPaneLayout) {
SlidingPaneLayout mSlidingPaneLayout = (SlidingPaneLayout) mContentView; SlidingPaneLayout mSlidingPaneLayout = (SlidingPaneLayout) mContentView;
@ -143,10 +141,14 @@ public class ConversationActivity extends XmppActivity implements
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
Log.d(Config.LOGTAG, "on create");
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
if (savedInstanceState != null) { if (savedInstanceState != null) {
Log.d(Config.LOGTAG, savedInstanceState.toString());
mOpenConverstaion = savedInstanceState.getString( mOpenConverstaion = savedInstanceState.getString(
STATE_OPEN_CONVERSATION, null); STATE_OPEN_CONVERSATION, null);
Log.d(Config.LOGTAG, "recovered " + mOpenConverstaion);
mPanelOpen = savedInstanceState.getBoolean(STATE_PANEL_OPEN, true); mPanelOpen = savedInstanceState.getBoolean(STATE_PANEL_OPEN, true);
String pending = savedInstanceState.getString(STATE_PENDING_URI, null); String pending = savedInstanceState.getString(STATE_PENDING_URI, null);
if (pending != null) { if (pending != null) {
@ -156,6 +158,11 @@ public class ConversationActivity extends XmppActivity implements
setContentView(R.layout.fragment_conversations_overview); setContentView(R.layout.fragment_conversations_overview);
this.mConversationFragment = new ConversationFragment();
FragmentTransaction transaction = getFragmentManager().beginTransaction();
transaction.replace(R.id.selected_conversation, this.mConversationFragment, "conversation");
transaction.commit();
listView = (ListView) findViewById(R.id.list); listView = (ListView) findViewById(R.id.list);
getActionBar().setDisplayHomeAsUpEnabled(false); getActionBar().setDisplayHomeAsUpEnabled(false);
@ -168,13 +175,11 @@ public class ConversationActivity extends XmppActivity implements
@Override @Override
public void onItemClick(AdapterView<?> arg0, View clickedView, public void onItemClick(AdapterView<?> arg0, View clickedView,
int position, long arg3) { int position, long arg3) {
paneShouldBeOpen = false;
if (getSelectedConversation() != conversationList.get(position)) { if (getSelectedConversation() != conversationList.get(position)) {
setSelectedConversation(conversationList.get(position)); setSelectedConversation(conversationList.get(position));
swapConversationFragment(); ConversationActivity.this.mConversationFragment.reInit(getSelectedConversation());
} else {
hideConversationsOverview();
} }
hideConversationsOverview();
} }
}); });
mContentView = findViewById(R.id.content_view_spl); mContentView = findViewById(R.id.content_view_spl);
@ -191,7 +196,6 @@ public class ConversationActivity extends XmppActivity implements
@Override @Override
public void onPanelOpened(View arg0) { public void onPanelOpened(View arg0) {
paneShouldBeOpen = true;
ActionBar ab = getActionBar(); ActionBar ab = getActionBar();
if (ab != null) { if (ab != null) {
ab.setDisplayHomeAsUpEnabled(false); ab.setDisplayHomeAsUpEnabled(false);
@ -209,7 +213,6 @@ public class ConversationActivity extends XmppActivity implements
@Override @Override
public void onPanelClosed(View arg0) { public void onPanelClosed(View arg0) {
paneShouldBeOpen = false;
if ((conversationList.size() > 0) if ((conversationList.size() > 0)
&& (getSelectedConversation() != null)) { && (getSelectedConversation() != null)) {
openConversation(getSelectedConversation()); openConversation(getSelectedConversation());
@ -436,7 +439,6 @@ public class ConversationActivity extends XmppActivity implements
public void endConversation(Conversation conversation) { public void endConversation(Conversation conversation) {
conversation.setStatus(Conversation.STATUS_ARCHIVED); conversation.setStatus(Conversation.STATUS_ARCHIVED);
paneShouldBeOpen = true;
showConversationsOverview(); showConversationsOverview();
xmppConnectionService.archiveConversation(conversation); xmppConnectionService.archiveConversation(conversation);
if (conversationList.size() > 0) { if (conversationList.size() > 0) {
@ -608,23 +610,6 @@ public class ConversationActivity extends XmppActivity implements
builder.create().show(); builder.create().show();
} }
protected ConversationFragment swapConversationFragment() {
ConversationFragment selectedFragment = new ConversationFragment();
if (!isFinishing()) {
FragmentTransaction transaction = getFragmentManager()
.beginTransaction();
transaction.replace(R.id.selected_conversation, selectedFragment,
"conversation");
try {
transaction.commitAllowingStateLoss();
} catch (IllegalStateException e) {
return selectedFragment;
}
}
return selectedFragment;
}
@Override @Override
public boolean onKeyDown(int keyCode, KeyEvent event) { public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) { if (keyCode == KeyEvent.KEYCODE_BACK) {
@ -674,6 +659,7 @@ public class ConversationActivity extends XmppActivity implements
public void onSaveInstanceState(Bundle savedInstanceState) { public void onSaveInstanceState(Bundle savedInstanceState) {
Conversation conversation = getSelectedConversation(); Conversation conversation = getSelectedConversation();
if (conversation != null) { if (conversation != null) {
Log.d(Config.LOGTAG, "saving conversation: " + conversation.getName() + " " + conversation.getUuid());
savedInstanceState.putString(STATE_OPEN_CONVERSATION, savedInstanceState.putString(STATE_OPEN_CONVERSATION,
conversation.getUuid()); conversation.getUuid());
} }
@ -700,24 +686,18 @@ public class ConversationActivity extends XmppActivity implements
handleViewConversationIntent(getIntent()); handleViewConversationIntent(getIntent());
setIntent(null); setIntent(null);
} else if (mOpenConverstaion != null) { } else if (mOpenConverstaion != null) {
Log.d(Config.LOGTAG, "open conversation: " + mOpenConverstaion);
selectConversationByUuid(mOpenConverstaion); selectConversationByUuid(mOpenConverstaion);
paneShouldBeOpen = mPanelOpen; if (mPanelOpen) {
if (paneShouldBeOpen) {
showConversationsOverview(); showConversationsOverview();
} }
swapConversationFragment(); this.mConversationFragment.reInit(getSelectedConversation());
mOpenConverstaion = null; mOpenConverstaion = null;
} else { } else if (getSelectedConversation() == null) {
showConversationsOverview(); showConversationsOverview();
ConversationFragment selectedFragment = (ConversationFragment) getFragmentManager()
.findFragmentByTag("conversation");
if (selectedFragment != null) {
selectedFragment.onBackendConnected();
} else {
mPendingImageUri = null; mPendingImageUri = null;
setSelectedConversation(conversationList.get(0)); setSelectedConversation(conversationList.get(0));
swapConversationFragment(); this.mConversationFragment.reInit(getSelectedConversation());
}
} }
if (mPendingImageUri != null) { if (mPendingImageUri != null) {
@ -730,10 +710,12 @@ public class ConversationActivity extends XmppActivity implements
private void handleViewConversationIntent(Intent intent) { private void handleViewConversationIntent(Intent intent) {
String uuid = (String) intent.getExtras().get(CONVERSATION); String uuid = (String) intent.getExtras().get(CONVERSATION);
String text = intent.getExtras().getString(TEXT, null); String text = intent.getExtras().getString(TEXT, "");
selectConversationByUuid(uuid); selectConversationByUuid(uuid);
paneShouldBeOpen = false; this.mConversationFragment.reInit(getSelectedConversation());
swapConversationFragment().setText(text); this.mConversationFragment.appendText(text);
hideConversationsOverview();
openConversation(getSelectedConversation());
} }
private void selectConversationByUuid(String uuid) { private void selectConversationByUuid(String uuid) {
@ -917,19 +899,12 @@ public class ConversationActivity extends XmppActivity implements
@Override @Override
public void run() { public void run() {
updateConversationList(); updateConversationList();
if (paneShouldBeOpen) { if (conversationList.size() == 0) {
if (conversationList.size() >= 1) {
swapConversationFragment();
} else {
startActivity(new Intent(getApplicationContext(), startActivity(new Intent(getApplicationContext(),
StartConversationActivity.class)); StartConversationActivity.class));
finish(); finish();
} } else {
} ConversationActivity.this.mConversationFragment.updateMessages();
ConversationFragment selectedFragment = (ConversationFragment) getFragmentManager()
.findFragmentByTag("conversation");
if (selectedFragment != null) {
selectedFragment.updateMessages();
} }
} }
}); });
@ -937,16 +912,12 @@ public class ConversationActivity extends XmppActivity implements
@Override @Override
public void onRosterUpdate() { public void onRosterUpdate() {
final ConversationFragment fragment = (ConversationFragment) getFragmentManager()
.findFragmentByTag("conversation");
if (fragment != null) {
runOnUiThread(new Runnable() { runOnUiThread(new Runnable() {
@Override @Override
public void run() { public void run() {
fragment.updateMessages(); ConversationActivity.this.mConversationFragment.updateMessages();
} }
}); });
} }
} }
}

View File

@ -9,8 +9,6 @@ import android.content.Intent;
import android.content.IntentSender; import android.content.IntentSender;
import android.content.IntentSender.SendIntentException; import android.content.IntentSender.SendIntentException;
import android.os.Bundle; import android.os.Bundle;
import android.text.Editable;
import android.text.Selection;
import android.view.ContextMenu; import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo; import android.view.ContextMenu.ContextMenuInfo;
import android.view.Gravity; import android.view.Gravity;
@ -60,80 +58,6 @@ import eu.siacs.conversations.utils.UIHelper;
public class ConversationFragment extends Fragment { public class ConversationFragment extends Fragment {
protected Conversation conversation; protected Conversation conversation;
protected ListView messagesView;
protected LayoutInflater inflater;
protected List<Message> messageList = new ArrayList<Message>();
protected MessageAdapter messageListAdapter;
protected Contact contact;
protected String queuedPqpMessage = null;
private EditMessage mEditMessage;
private ImageButton mSendButton;
private String pastedText = null;
private RelativeLayout snackbar;
private TextView snackbarMessage;
private TextView snackbarAction;
private boolean messagesLoaded = false;
private IntentSender askForPassphraseIntent = null;
private ConcurrentLinkedQueue<Message> mEncryptedMessages = new ConcurrentLinkedQueue<Message>();
private boolean mDecryptJobRunning = false;
private OnEditorActionListener mEditorActionListener = new OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_SEND) {
InputMethodManager imm = (InputMethodManager) v.getContext()
.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
sendMessage();
return true;
} else {
return false;
}
}
};
private OnClickListener mSendButtonListener = new OnClickListener() {
@Override
public void onClick(View v) {
sendMessage();
}
};
protected OnClickListener clickToDecryptListener = new OnClickListener() {
@Override
public void onClick(View v) {
if (activity.hasPgp() && askForPassphraseIntent != null) {
try {
getActivity().startIntentSenderForResult(
askForPassphraseIntent,
ConversationActivity.REQUEST_DECRYPT_PGP, null, 0,
0, 0);
} catch (SendIntentException e) {
//
}
}
}
};
private OnClickListener clickToMuc = new OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(getActivity(),
ConferenceDetailsActivity.class);
intent.setAction(ConferenceDetailsActivity.ACTION_VIEW_MUC);
intent.putExtra("uuid", conversation.getUuid());
startActivity(intent);
}
};
private OnClickListener leaveMuc = new OnClickListener() { private OnClickListener leaveMuc = new OnClickListener() {
@Override @Override
@ -141,7 +65,6 @@ public class ConversationFragment extends Fragment {
activity.endConversation(conversation); activity.endConversation(conversation);
} }
}; };
private OnClickListener joinMuc = new OnClickListener() { private OnClickListener joinMuc = new OnClickListener() {
@Override @Override
@ -149,7 +72,6 @@ public class ConversationFragment extends Fragment {
activity.xmppConnectionService.joinMuc(conversation); activity.xmppConnectionService.joinMuc(conversation);
} }
}; };
private OnClickListener enterPassword = new OnClickListener() { private OnClickListener enterPassword = new OnClickListener() {
@Override @Override
@ -169,7 +91,18 @@ public class ConversationFragment extends Fragment {
}); });
} }
}; };
protected ListView messagesView;
protected LayoutInflater inflater;
protected List<Message> messageList = new ArrayList<Message>();
protected MessageAdapter messageListAdapter;
protected Contact contact;
protected String queuedPqpMessage = null;
private EditMessage mEditMessage;
private ImageButton mSendButton;
private RelativeLayout snackbar;
private TextView snackbarMessage;
private TextView snackbarAction;
private boolean messagesLoaded = false;
private OnScrollListener mOnScrollListener = new OnScrollListener() { private OnScrollListener mOnScrollListener = new OnScrollListener() {
@Override @Override
@ -197,7 +130,58 @@ public class ConversationFragment extends Fragment {
} }
} }
}; };
private IntentSender askForPassphraseIntent = null;
protected OnClickListener clickToDecryptListener = new OnClickListener() {
@Override
public void onClick(View v) {
if (activity.hasPgp() && askForPassphraseIntent != null) {
try {
getActivity().startIntentSenderForResult(
askForPassphraseIntent,
ConversationActivity.REQUEST_DECRYPT_PGP, null, 0,
0, 0);
} catch (SendIntentException e) {
//
}
}
}
};
private ConcurrentLinkedQueue<Message> mEncryptedMessages = new ConcurrentLinkedQueue<Message>();
private boolean mDecryptJobRunning = false;
private OnEditorActionListener mEditorActionListener = new OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_SEND) {
InputMethodManager imm = (InputMethodManager) v.getContext()
.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
sendMessage();
return true;
} else {
return false;
}
}
};
private OnClickListener mSendButtonListener = new OnClickListener() {
@Override
public void onClick(View v) {
sendMessage();
}
};
private OnClickListener clickToMuc = new OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(getActivity(),
ConferenceDetailsActivity.class);
intent.setAction(ConferenceDetailsActivity.ACTION_VIEW_MUC);
intent.putExtra("uuid", conversation.getUuid());
startActivity(intent);
}
};
private ConversationActivity activity; private ConversationActivity activity;
private Message selectedMessage; private Message selectedMessage;
@ -466,15 +450,6 @@ public class ConversationFragment extends Fragment {
} }
} }
@Override
public void onStart() {
super.onStart();
this.activity = (ConversationActivity) getActivity();
if (activity.xmppConnectionServiceBound) {
this.onBackendConnected();
}
}
@Override @Override
public void onStop() { public void onStop() {
mDecryptJobRunning = false; mDecryptJobRunning = false;
@ -484,36 +459,18 @@ public class ConversationFragment extends Fragment {
} }
} }
public void onBackendConnected() { public void reInit(Conversation conversation) {
if (this.conversation != null) {
this.conversation.setNextMessage(mEditMessage.getText().toString());
}
this.activity = (ConversationActivity) getActivity(); this.activity = (ConversationActivity) getActivity();
this.conversation = activity.getSelectedConversation(); this.conversation = conversation;
if (this.conversation == null) {
return;
}
String oldString = conversation.getNextMessage().trim();
if (this.pastedText == null) {
this.mEditMessage.setText(oldString);
} else {
if (oldString.isEmpty()) {
mEditMessage.setText(pastedText);
} else {
mEditMessage.setText(oldString + " " + pastedText);
}
pastedText = null;
}
int position = mEditMessage.length();
Editable etext = mEditMessage.getText();
Selection.setSelection(etext, position);
if (activity.isConversationsOverviewHideable()) {
if (!activity.shouldPaneBeOpen()) {
activity.hideConversationsOverview();
activity.openConversation(conversation);
}
}
if (this.conversation.getMode() == Conversation.MODE_MULTI) { if (this.conversation.getMode() == Conversation.MODE_MULTI) {
conversation.setNextPresence(null); this.conversation.setNextPresence(null);
} }
this.mEditMessage.setText("");
this.mEditMessage.append(this.conversation.getNextMessage());
this.messagesView.invalidate();
updateMessages(); updateMessages();
} }
@ -611,7 +568,7 @@ public class ConversationFragment extends Fragment {
} }
getActivity().invalidateOptionsMenu(); getActivity().invalidateOptionsMenu();
updateChatMsgHint(); updateChatMsgHint();
if (!activity.shouldPaneBeOpen()) { if (!activity.isConversationsOverviewVisable() || !activity.isConversationsOverviewHideable()) {
activity.xmppConnectionService.markRead(conversation, true); activity.xmppConnectionService.markRead(conversation, true);
activity.updateConversationList(); activity.updateConversationList();
} }
@ -888,8 +845,12 @@ public class ConversationFragment extends Fragment {
} }
} }
public void setText(String text) { public void appendText(String text) {
this.pastedText = text; String previous = this.mEditMessage.getText().toString();
if (previous.length() != 0 && !previous.endsWith(" ")) {
text = " " + text;
}
this.mEditMessage.append(text);
} }
public void clearInputField() { public void clearInputField() {

View File

@ -1,5 +1,23 @@
package eu.siacs.conversations.ui.adapter; package eu.siacs.conversations.ui.adapter;
import android.content.Intent;
import android.graphics.Typeface;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.style.ForegroundColorSpan;
import android.text.style.StyleSpan;
import android.util.DisplayMetrics;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnLongClickListener;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import java.util.List; import java.util.List;
import eu.siacs.conversations.Config; import eu.siacs.conversations.Config;
@ -11,23 +29,6 @@ import eu.siacs.conversations.entities.Message;
import eu.siacs.conversations.entities.Message.ImageParams; import eu.siacs.conversations.entities.Message.ImageParams;
import eu.siacs.conversations.ui.ConversationActivity; import eu.siacs.conversations.ui.ConversationActivity;
import eu.siacs.conversations.utils.UIHelper; import eu.siacs.conversations.utils.UIHelper;
import android.content.Intent;
import android.graphics.Typeface;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.style.ForegroundColorSpan;
import android.text.style.StyleSpan;
import android.util.DisplayMetrics;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.view.View.OnLongClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
public class MessageAdapter extends ArrayAdapter<Message> { public class MessageAdapter extends ArrayAdapter<Message> {
@ -323,10 +324,6 @@ public class MessageAdapter extends ArrayAdapter<Message> {
.findViewById(R.id.message_box); .findViewById(R.id.message_box);
viewHolder.contact_picture = (ImageView) view viewHolder.contact_picture = (ImageView) view
.findViewById(R.id.message_photo); .findViewById(R.id.message_photo);
viewHolder.contact_picture.setImageBitmap(activity
.avatarService().get(
item.getConversation().getAccount(),
activity.getPixel(48)));
viewHolder.download_button = (Button) view viewHolder.download_button = (Button) view
.findViewById(R.id.download_button); .findViewById(R.id.download_button);
viewHolder.indicator = (ImageView) view viewHolder.indicator = (ImageView) view
@ -350,11 +347,6 @@ public class MessageAdapter extends ArrayAdapter<Message> {
.findViewById(R.id.message_photo); .findViewById(R.id.message_photo);
viewHolder.download_button = (Button) view viewHolder.download_button = (Button) view
.findViewById(R.id.download_button); .findViewById(R.id.download_button);
if (item.getConversation().getMode() == Conversation.MODE_SINGLE) {
viewHolder.contact_picture.setImageBitmap(activity
.avatarService().get(item.getContact(),
activity.getPixel(48)));
}
viewHolder.indicator = (ImageView) view viewHolder.indicator = (ImageView) view
.findViewById(R.id.security_indicator); .findViewById(R.id.security_indicator);
viewHolder.image = (ImageView) view viewHolder.image = (ImageView) view
@ -363,6 +355,8 @@ public class MessageAdapter extends ArrayAdapter<Message> {
.findViewById(R.id.message_body); .findViewById(R.id.message_body);
viewHolder.time = (TextView) view viewHolder.time = (TextView) view
.findViewById(R.id.message_time); .findViewById(R.id.message_time);
viewHolder.indicatorReceived = (ImageView) view
.findViewById(R.id.indicator_received);
view.setTag(viewHolder); view.setTag(viewHolder);
break; break;
case STATUS: case STATUS:
@ -370,6 +364,16 @@ public class MessageAdapter extends ArrayAdapter<Message> {
R.layout.message_status, parent, false); R.layout.message_status, parent, false);
viewHolder.contact_picture = (ImageView) view viewHolder.contact_picture = (ImageView) view
.findViewById(R.id.message_photo); .findViewById(R.id.message_photo);
break;
default:
viewHolder = null;
break;
}
} else {
viewHolder = (ViewHolder) view.getTag();
}
if (type == STATUS) {
if (item.getConversation().getMode() == Conversation.MODE_SINGLE) { if (item.getConversation().getMode() == Conversation.MODE_SINGLE) {
viewHolder.contact_picture.setImageBitmap(activity viewHolder.contact_picture.setImageBitmap(activity
@ -394,19 +398,8 @@ public class MessageAdapter extends ArrayAdapter<Message> {
}); });
} }
break;
default:
viewHolder = null;
break;
}
} else {
viewHolder = (ViewHolder) view.getTag();
}
if (type == STATUS) {
return view; return view;
} } else if (type == NULL) {
if (type == NULL) {
if (position == getCount() - 1) { if (position == getCount() - 1) {
view.getLayoutParams().height = 1; view.getLayoutParams().height = 1;
} else { } else {
@ -415,6 +408,19 @@ public class MessageAdapter extends ArrayAdapter<Message> {
} }
view.setLayoutParams(view.getLayoutParams()); view.setLayoutParams(view.getLayoutParams());
return view; return view;
} else if (type == RECEIVED) {
Contact contact = item.getContact();
if (contact != null) {
viewHolder.contact_picture.setImageBitmap(activity.avatarService().get(contact, activity.getPixel(48)));
} else if (item.getConversation().getMode() == Conversation.MODE_MULTI) {
String name = item.getPresence();
if (name == null) {
name = item.getCounterpart();
}
viewHolder.contact_picture.setImageBitmap(activity.avatarService().get(name, activity.getPixel(48)));
}
} else if (type == SENT) {
viewHolder.contact_picture.setImageBitmap(activity.avatarService().get(item.getConversation().getAccount(), activity.getPixel(48)));
} }
if (viewHolder.contact_picture != null) { if (viewHolder.contact_picture != null) {
@ -426,7 +432,6 @@ public class MessageAdapter extends ArrayAdapter<Message> {
if (MessageAdapter.this.mOnContactPictureClickedListener != null) { if (MessageAdapter.this.mOnContactPictureClickedListener != null) {
MessageAdapter.this.mOnContactPictureClickedListener MessageAdapter.this.mOnContactPictureClickedListener
.onContactPictureClicked(item); .onContactPictureClicked(item);
;
} }
} }
@ -447,24 +452,6 @@ public class MessageAdapter extends ArrayAdapter<Message> {
}); });
} }
if (type == RECEIVED) {
if (item.getConversation().getMode() == Conversation.MODE_MULTI) {
Contact contact = item.getContact();
if (contact != null) {
viewHolder.contact_picture.setImageBitmap(activity
.avatarService()
.get(contact, activity.getPixel(48)));
} else {
String name = item.getPresence();
if (name == null) {
name = item.getCounterpart();
}
viewHolder.contact_picture.setImageBitmap(activity
.avatarService().get(name, activity.getPixel(48)));
}
}
}
if (item.getType() == Message.TYPE_IMAGE if (item.getType() == Message.TYPE_IMAGE
|| item.getDownloadable() != null) { || item.getDownloadable() != null) {
Downloadable d = item.getDownloadable(); Downloadable d = item.getDownloadable();
@ -532,6 +519,14 @@ public class MessageAdapter extends ArrayAdapter<Message> {
} }
} }
public interface OnContactPictureClicked {
public void onContactPictureClicked(Message message);
}
public interface OnContactPictureLongClicked {
public void onContactPictureLongClicked(Message message);
}
private static class ViewHolder { private static class ViewHolder {
protected LinearLayout message_box; protected LinearLayout message_box;
@ -544,12 +539,4 @@ public class MessageAdapter extends ArrayAdapter<Message> {
protected ImageView contact_picture; protected ImageView contact_picture;
} }
public interface OnContactPictureClicked {
public void onContactPictureClicked(Message message);
}
public interface OnContactPictureLongClicked {
public void onContactPictureLongClicked(Message message);
}
} }