contact picture generation centralized + basic registry stuff

This commit is contained in:
Daniel Gultsch 2014-03-13 03:52:41 +01:00
parent eadebeb77c
commit a80e3131be
10 changed files with 143 additions and 132 deletions

View file

@ -209,8 +209,7 @@ public class OtrEngine implements OtrEngineHost {
@Override @Override
public void unreadableMessageReceived(SessionID arg0) throws OtrException { public void unreadableMessageReceived(SessionID arg0) throws OtrException {
// TODO Auto-generated method stub throw new OtrException(new Exception("unreadable message received"));
} }
@Override @Override

View file

@ -29,6 +29,7 @@ public class Account extends AbstractEntity{
public static final int OPTION_USETLS = 0; public static final int OPTION_USETLS = 0;
public static final int OPTION_DISABLED = 1; public static final int OPTION_DISABLED = 1;
public static final int OPTION_REGISTER = 2;
public static final int STATUS_CONNECTING = 0; public static final int STATUS_CONNECTING = 0;
public static final int STATUS_DISABLED = -2; public static final int STATUS_DISABLED = -2;

View file

@ -396,7 +396,7 @@ public class XmppConnectionService extends Service {
@Override @Override
public int onStartCommand(Intent intent, int flags, int startId) { public int onStartCommand(Intent intent, int flags, int startId) {
//Log.d(LOGTAG,"calling start service. caller was:"+intent.getAction()); Log.d(LOGTAG,"calling start service. caller was:"+intent.getAction());
ConnectivityManager cm = (ConnectivityManager) getApplicationContext() ConnectivityManager cm = (ConnectivityManager) getApplicationContext()
.getSystemService(Context.CONNECTIVITY_SERVICE); .getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetwork = cm.getActiveNetworkInfo(); NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
@ -441,6 +441,7 @@ public class XmppConnectionService extends Service {
Log.d(LOGTAG,account.getJid()+": time out during connect reconnecting"); Log.d(LOGTAG,account.getJid()+": time out during connect reconnecting");
reconnectAccount(account,true); reconnectAccount(account,true);
} else { } else {
Log.d(LOGTAG,"seconds since last connect:"+((SystemClock.elapsedRealtime() - account.getXmppConnection().lastConnect) / 1000));
Log.d(LOGTAG,account.getJid()+": status="+account.getStatus()); Log.d(LOGTAG,account.getJid()+": status="+account.getStatus());
// TODO notify user of ssl cert problem or auth problem or what ever // TODO notify user of ssl cert problem or auth problem or what ever
} }
@ -836,6 +837,7 @@ public class XmppConnectionService extends Service {
} else { } else {
conversation.setMode(Conversation.MODE_SINGLE); conversation.setMode(Conversation.MODE_SINGLE);
} }
conversation.setMessages(databaseBackend.getMessages(conversation, 50));
this.databaseBackend.updateConversation(conversation); this.databaseBackend.updateConversation(conversation);
conversation.setContact(findContact(account, conversation.setContact(findContact(account,
conversation.getContactJid())); conversation.getContactJid()));
@ -887,7 +889,7 @@ public class XmppConnectionService extends Service {
public void createAccount(Account account) { public void createAccount(Account account) {
databaseBackend.createAccount(account); databaseBackend.createAccount(account);
this.accounts.add(account); this.accounts.add(account);
account.setXmppConnection(this.createConnection(account)); this.reconnectAccount(account, false);
if (accountChangedListener != null) if (accountChangedListener != null)
accountChangedListener.onAccountListChangedListener(); accountChangedListener.onAccountListChangedListener();
} }

View file

@ -95,6 +95,7 @@ public class ConversationActivity extends XmppActivity {
xmppConnectionService.createContact(contact); xmppConnectionService.createContact(contact);
} }
}; };
protected ConversationActivity activity = this;
public List<Conversation> getConversationList() { public List<Conversation> getConversationList() {
return this.conversationList; return this.conversationList;
@ -177,17 +178,8 @@ public class ConversationActivity extends XmppActivity {
((TextView) view.findViewById(R.id.conversation_lastupdate)) ((TextView) view.findViewById(R.id.conversation_lastupdate))
.setText(UIHelper.readableTimeDifference(conv.getLatestMessage().getTimeSent())); .setText(UIHelper.readableTimeDifference(conv.getLatestMessage().getTimeSent()));
Uri profilePhoto = conv.getProfilePhotoUri();
ImageView imageView = (ImageView) view.findViewById(R.id.conversation_image); ImageView imageView = (ImageView) view.findViewById(R.id.conversation_image);
if (profilePhoto!=null) { imageView.setImageBitmap(UIHelper.getContactPicture(getItem(position).getContact(), 200, activity.getApplicationContext()));
imageView.setImageURI(profilePhoto);
} else {
imageView.setImageBitmap(UIHelper.getUnknownContactPicture(getItem(position).getName(),200));
}
((ImageView) view.findViewById(R.id.conversation_image))
.setImageURI(conv.getProfilePhotoUri());
return view; return view;
} }

View file

@ -23,6 +23,7 @@ import eu.siacs.conversations.utils.PhoneHelper;
import eu.siacs.conversations.utils.UIHelper; import eu.siacs.conversations.utils.UIHelper;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.app.Fragment; import android.app.Fragment;
import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.content.IntentSender; import android.content.IntentSender;
@ -64,7 +65,7 @@ public class ConversationFragment extends Fragment {
private EditText chatMsg; private EditText chatMsg;
protected Bitmap selfBitmap; protected Bitmap selfBitmap;
private IntentSender askForPassphraseIntent = null; private IntentSender askForPassphraseIntent = null;
private OnClickListener sendMsgListener = new OnClickListener() { private OnClickListener sendMsgListener = new OnClickListener() {
@ -85,34 +86,37 @@ public class ConversationFragment extends Fragment {
} }
}; };
protected OnClickListener clickToDecryptListener = new OnClickListener() { protected OnClickListener clickToDecryptListener = new OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
Log.d("gultsch","clicked to decrypt"); Log.d("gultsch", "clicked to decrypt");
if (askForPassphraseIntent!=null) { if (askForPassphraseIntent != null) {
try { try {
getActivity().startIntentSenderForResult(askForPassphraseIntent, ConversationActivity.REQUEST_DECRYPT_PGP, null, 0, 0, 0); getActivity().startIntentSenderForResult(
askForPassphraseIntent,
ConversationActivity.REQUEST_DECRYPT_PGP, null, 0,
0, 0);
} catch (SendIntentException e) { } catch (SendIntentException e) {
Log.d("gultsch","couldnt fire intent"); Log.d("gultsch", "couldnt fire intent");
} }
} }
} }
}; };
private LinearLayout pgpInfo; private LinearLayout pgpInfo;
private LinearLayout mucError; private LinearLayout mucError;
private TextView mucErrorText; private TextView mucErrorText;
private OnClickListener clickToMuc = new OnClickListener() { private OnClickListener clickToMuc = new OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
Intent intent = new Intent(getActivity(),MucDetailsActivity.class); Intent intent = new Intent(getActivity(), MucDetailsActivity.class);
intent.setAction(MucDetailsActivity.ACTION_VIEW_MUC); intent.setAction(MucDetailsActivity.ACTION_VIEW_MUC);
intent.putExtra("uuid", conversation.getUuid()); intent.putExtra("uuid", conversation.getUuid());
startActivity(intent); startActivity(intent);
} }
}; };
public void hidePgpPassphraseBox() { public void hidePgpPassphraseBox() {
pgpInfo.setVisibility(View.GONE); pgpInfo.setVisibility(View.GONE);
} }
@ -152,13 +156,13 @@ public class ConversationFragment extends Fragment {
ImageButton sendButton = (ImageButton) view ImageButton sendButton = (ImageButton) view
.findViewById(R.id.textSendButton); .findViewById(R.id.textSendButton);
sendButton.setOnClickListener(this.sendMsgListener); sendButton.setOnClickListener(this.sendMsgListener);
pgpInfo = (LinearLayout) view.findViewById(R.id.pgp_keyentry); pgpInfo = (LinearLayout) view.findViewById(R.id.pgp_keyentry);
pgpInfo.setOnClickListener(clickToDecryptListener); pgpInfo.setOnClickListener(clickToDecryptListener);
mucError = (LinearLayout) view.findViewById(R.id.muc_error); mucError = (LinearLayout) view.findViewById(R.id.muc_error);
mucError.setOnClickListener(clickToMuc ); mucError.setOnClickListener(clickToMuc);
mucErrorText = (TextView) view.findViewById(R.id.muc_error_msg); mucErrorText = (TextView) view.findViewById(R.id.muc_error_msg);
messagesView = (ListView) view.findViewById(R.id.messages_view); messagesView = (ListView) view.findViewById(R.id.messages_view);
messageListAdapter = new ArrayAdapter<Message>(this.getActivity() messageListAdapter = new ArrayAdapter<Message>(this.getActivity()
@ -206,19 +210,13 @@ public class ConversationFragment extends Fragment {
viewHolder.imageView = (ImageView) view viewHolder.imageView = (ImageView) view
.findViewById(R.id.message_photo); .findViewById(R.id.message_photo);
if (item.getConversation().getMode() == Conversation.MODE_SINGLE) { if (item.getConversation().getMode() == Conversation.MODE_SINGLE) {
Uri uri = item.getConversation()
.getProfilePhotoUri(); viewHolder.imageView.setImageBitmap(mBitmapCache
if (uri != null) { .get(item.getConversation().getName(), item
viewHolder.imageView .getConversation().getContact(),
.setImageBitmap(mBitmapCache.get(item getActivity()
.getConversation().getName(), .getApplicationContext()));
uri));
} else {
viewHolder.imageView
.setImageBitmap(mBitmapCache.get(item
.getConversation().getName(),
null));
}
} }
break; break;
case ERROR: case ERROR:
@ -245,24 +243,30 @@ public class ConversationFragment extends Fragment {
if (item.getConversation().getMode() == Conversation.MODE_MULTI) { if (item.getConversation().getMode() == Conversation.MODE_MULTI) {
if (item.getCounterpart() != null) { if (item.getCounterpart() != null) {
viewHolder.imageView.setImageBitmap(mBitmapCache viewHolder.imageView.setImageBitmap(mBitmapCache
.get(item.getCounterpart(), null)); .get(item.getCounterpart(), null,
getActivity()
.getApplicationContext()));
} else { } else {
viewHolder.imageView viewHolder.imageView.setImageBitmap(mBitmapCache
.setImageBitmap(mBitmapCache.get(item .get(item.getConversation().getName(),
.getConversation().getName(), null)); null, getActivity()
.getApplicationContext()));
} }
} }
} }
String body = item.getBody(); String body = item.getBody();
if (body != null) { if (body != null) {
if (item.getEncryption() == Message.ENCRYPTION_PGP) { if (item.getEncryption() == Message.ENCRYPTION_PGP) {
viewHolder.messageBody.setText(getString(R.string.encrypted_message)); viewHolder.messageBody
.setText(getString(R.string.encrypted_message));
viewHolder.messageBody.setTextColor(0xff33B5E5); viewHolder.messageBody.setTextColor(0xff33B5E5);
viewHolder.messageBody.setTypeface(null,Typeface.ITALIC); viewHolder.messageBody.setTypeface(null,
Typeface.ITALIC);
} else { } else {
viewHolder.messageBody.setText(body.trim()); viewHolder.messageBody.setText(body.trim());
viewHolder.messageBody.setTextColor(0xff000000); viewHolder.messageBody.setTextColor(0xff000000);
viewHolder.messageBody.setTypeface(null, Typeface.NORMAL); viewHolder.messageBody.setTypeface(null,
Typeface.NORMAL);
} }
} }
if (item.getStatus() == Message.STATUS_UNSEND) { if (item.getStatus() == Message.STATUS_UNSEND) {
@ -296,26 +300,8 @@ public class ConversationFragment extends Fragment {
boolean showPhoneSelfContactPicture = sharedPref.getBoolean( boolean showPhoneSelfContactPicture = sharedPref.getBoolean(
"show_phone_selfcontact_picture", true); "show_phone_selfcontact_picture", true);
Bitmap self = null; return UIHelper.getSelfContactPicture(conversation.getAccount(), 200,
showPhoneSelfContactPicture, getActivity());
if (showPhoneSelfContactPicture) {
Uri selfiUri = PhoneHelper.getSefliUri(getActivity());
if (selfiUri != null) {
try {
self = BitmapFactory.decodeStream(getActivity()
.getContentResolver().openInputStream(selfiUri));
} catch (FileNotFoundException e) {
self = null;
}
}
}
if (self == null) {
self = UIHelper.getUnknownContactPicture(conversation.getAccount()
.getJid(), 200);
}
final Bitmap selfBitmap = self;
return selfBitmap;
} }
@Override @Override
@ -332,7 +318,7 @@ public class ConversationFragment extends Fragment {
final ConversationActivity activity = (ConversationActivity) getActivity(); final ConversationActivity activity = (ConversationActivity) getActivity();
activity.registerListener(); activity.registerListener();
this.conversation = activity.getSelectedConversation(); this.conversation = activity.getSelectedConversation();
if (this.conversation==null) { if (this.conversation == null) {
return; return;
} }
this.selfBitmap = findSelfPicture(); this.selfBitmap = findSelfPicture();
@ -344,7 +330,7 @@ public class ConversationFragment extends Fragment {
activity.getActionBar().setDisplayHomeAsUpEnabled(true); activity.getActionBar().setDisplayHomeAsUpEnabled(true);
activity.getActionBar().setTitle(conversation.getName()); activity.getActionBar().setTitle(conversation.getName());
activity.invalidateOptionsMenu(); activity.invalidateOptionsMenu();
} }
} }
if (queuedPqpMessage != null) { if (queuedPqpMessage != null) {
@ -354,30 +340,36 @@ public class ConversationFragment extends Fragment {
sendPgpMessage(message); sendPgpMessage(message);
} }
if (conversation.getMode() == Conversation.MODE_MULTI) { if (conversation.getMode() == Conversation.MODE_MULTI) {
activity.xmppConnectionService.setOnRenameListener(new OnRenameListener() { activity.xmppConnectionService
.setOnRenameListener(new OnRenameListener() {
@Override
public void onRename(final boolean success) {
getActivity().runOnUiThread(new Runnable() {
@Override @Override
public void run() { public void onRename(final boolean success) {
if (success) { getActivity().runOnUiThread(new Runnable() {
Toast.makeText(getActivity(), "Your nickname has been changed",Toast.LENGTH_SHORT).show();
} else { @Override
Toast.makeText(getActivity(), "Nichname is already in use",Toast.LENGTH_SHORT).show(); public void run() {
} if (success) {
Toast.makeText(
getActivity(),
"Your nickname has been changed",
Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(getActivity(),
"Nichname is already in use",
Toast.LENGTH_SHORT).show();
}
}
});
} }
}); });
}
});
} }
} }
public void updateMessages() { public void updateMessages() {
ConversationActivity activity = (ConversationActivity) getActivity(); ConversationActivity activity = (ConversationActivity) getActivity();
List<Message> encryptedMessages = new LinkedList<Message>(); List<Message> encryptedMessages = new LinkedList<Message>();
for(Message message : this.conversation.getMessages()) { for (Message message : this.conversation.getMessages()) {
if (message.getEncryption() == Message.ENCRYPTION_PGP) { if (message.getEncryption() == Message.ENCRYPTION_PGP) {
encryptedMessages.add(message); encryptedMessages.add(message);
} }
@ -394,7 +386,7 @@ public class ConversationFragment extends Fragment {
if (messageList.size() >= 1) { if (messageList.size() >= 1) {
int latestEncryption = this.conversation.getLatestMessage() int latestEncryption = this.conversation.getLatestMessage()
.getEncryption(); .getEncryption();
if (latestEncryption== Message.ENCRYPTION_DECRYPTED) { if (latestEncryption == Message.ENCRYPTION_DECRYPTED) {
conversation.nextMessageEncryption = Message.ENCRYPTION_PGP; conversation.nextMessageEncryption = Message.ENCRYPTION_PGP;
} else { } else {
conversation.nextMessageEncryption = latestEncryption; conversation.nextMessageEncryption = latestEncryption;
@ -418,8 +410,9 @@ public class ConversationFragment extends Fragment {
messagesView.setSelection(size - 1); messagesView.setSelection(size - 1);
if (!activity.shouldPaneBeOpen()) { if (!activity.shouldPaneBeOpen()) {
conversation.markRead(); conversation.markRead();
//TODO update notifications // TODO update notifications
UIHelper.updateNotification(getActivity(), activity.getConversationList(), null, false); UIHelper.updateNotification(getActivity(),
activity.getConversationList(), null, false);
activity.updateConversationList(); activity.updateConversationList();
} }
} }
@ -472,16 +465,18 @@ public class ConversationFragment extends Fragment {
xmppService.sendMessage(message, null); xmppService.sendMessage(message, null);
chatMsg.setText(""); chatMsg.setText("");
} else { } else {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); AlertDialog.Builder builder = new AlertDialog.Builder(
getActivity());
builder.setTitle("No openPGP key found"); builder.setTitle("No openPGP key found");
builder.setIconAttribute(android.R.attr.alertDialogIcon); builder.setIconAttribute(android.R.attr.alertDialogIcon);
builder.setMessage("There is no openPGP key assoziated with this contact"); builder.setMessage("There is no openPGP key assoziated with this contact");
builder.setNegativeButton("Cancel", null); builder.setNegativeButton("Cancel", null);
builder.setPositiveButton("Send plain text", builder.setPositiveButton("Send plain text",
new DialogInterface.OnClickListener() { new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog,
int which) {
conversation.nextMessageEncryption = Message.ENCRYPTION_NONE; conversation.nextMessageEncryption = Message.ENCRYPTION_NONE;
message.setEncryption(Message.ENCRYPTION_NONE); message.setEncryption(Message.ENCRYPTION_NONE);
xmppService.sendMessage(message, null); xmppService.sendMessage(message, null);
@ -492,7 +487,7 @@ public class ConversationFragment extends Fragment {
} }
} }
} }
protected void sendOtrMessage(final Message message) { protected void sendOtrMessage(final Message message) {
ConversationActivity activity = (ConversationActivity) getActivity(); ConversationActivity activity = (ConversationActivity) getActivity();
final XmppConnectionService xmppService = activity.xmppConnectionService; final XmppConnectionService xmppService = activity.xmppConnectionService;
@ -564,20 +559,15 @@ public class ConversationFragment extends Fragment {
private HashMap<String, Bitmap> bitmaps = new HashMap<String, Bitmap>(); private HashMap<String, Bitmap> bitmaps = new HashMap<String, Bitmap>();
private Bitmap error = null; private Bitmap error = null;
public Bitmap get(String name, Uri uri) { public Bitmap get(String name, Contact contact, Context context) {
if (bitmaps.containsKey(name)) { if (bitmaps.containsKey(name)) {
return bitmaps.get(name); return bitmaps.get(name);
} else { } else {
Bitmap bm; Bitmap bm;
if (uri != null) { if (contact == null) {
try { bm = UIHelper.getContactPictureByName(name, 200);
bm = BitmapFactory.decodeStream(getActivity()
.getContentResolver().openInputStream(uri));
} catch (FileNotFoundException e) {
bm = UIHelper.getUnknownContactPicture(name, 200);
}
} else { } else {
bm = UIHelper.getUnknownContactPicture(name, 200); bm = UIHelper.getContactPicture(contact, 200, context);
} }
bitmaps.put(name, bm); bitmaps.put(name, bm);
return bm; return bm;
@ -591,47 +581,49 @@ public class ConversationFragment extends Fragment {
return error; return error;
} }
} }
class DecryptMessage extends AsyncTask<Message, Void, Boolean> { class DecryptMessage extends AsyncTask<Message, Void, Boolean> {
@Override @Override
protected Boolean doInBackground(Message... params) { protected Boolean doInBackground(Message... params) {
final ConversationActivity activity = (ConversationActivity) getActivity(); final ConversationActivity activity = (ConversationActivity) getActivity();
askForPassphraseIntent = null; askForPassphraseIntent = null;
for(int i = 0; i < params.length; ++i) { for (int i = 0; i < params.length; ++i) {
if (params[i].getEncryption() == Message.ENCRYPTION_PGP) { if (params[i].getEncryption() == Message.ENCRYPTION_PGP) {
String body = params[i].getBody(); String body = params[i].getBody();
String decrypted = null; String decrypted = null;
if (activity==null) { if (activity == null) {
return false; return false;
} else if (!activity.xmppConnectionServiceBound) { } else if (!activity.xmppConnectionServiceBound) {
return false; return false;
} }
try { try {
decrypted = activity.xmppConnectionService.getPgpEngine().decrypt(body); decrypted = activity.xmppConnectionService
.getPgpEngine().decrypt(body);
} catch (UserInputRequiredException e) { } catch (UserInputRequiredException e) {
askForPassphraseIntent = e.getPendingIntent().getIntentSender(); askForPassphraseIntent = e.getPendingIntent()
.getIntentSender();
activity.runOnUiThread(new Runnable() { activity.runOnUiThread(new Runnable() {
@Override @Override
public void run() { public void run() {
pgpInfo.setVisibility(View.VISIBLE); pgpInfo.setVisibility(View.VISIBLE);
} }
}); });
return false; return false;
} catch (OpenPgpException e) { } catch (OpenPgpException e) {
Log.d("gultsch","error decrypting pgp"); Log.d("gultsch", "error decrypting pgp");
} }
if (decrypted!=null) { if (decrypted != null) {
params[i].setBody(decrypted); params[i].setBody(decrypted);
params[i].setEncryption(Message.ENCRYPTION_DECRYPTED); params[i].setEncryption(Message.ENCRYPTION_DECRYPTED);
activity.xmppConnectionService.updateMessage(params[i]); activity.xmppConnectionService.updateMessage(params[i]);
} }
if (activity!=null) { if (activity != null) {
activity.runOnUiThread(new Runnable() { activity.runOnUiThread(new Runnable() {
@Override @Override
public void run() { public void run() {
messageListAdapter.notifyDataSetChanged(); messageListAdapter.notifyDataSetChanged();
@ -639,9 +631,9 @@ public class ConversationFragment extends Fragment {
}); });
} }
} }
if (activity!=null) { if (activity != null) {
activity.runOnUiThread(new Runnable() { activity.runOnUiThread(new Runnable() {
@Override @Override
public void run() { public void run() {
activity.updateConversationList(); activity.updateConversationList();
@ -651,6 +643,6 @@ public class ConversationFragment extends Fragment {
} }
return true; return true;
} }
} }
} }

View file

@ -54,16 +54,22 @@ public class EditAccount extends DialogFragment {
final String okButtonDesc; final String okButtonDesc;
if (account != null) { if (account != null) {
builder.setTitle("Edit account");
registerAccount.setVisibility(View.GONE);
jidText.setText(account.getJid()); jidText.setText(account.getJid());
password.setText(account.getPassword()); password.setText(account.getPassword());
okButtonDesc = "Edit";
if (account.isOptionSet(Account.OPTION_USETLS)) { if (account.isOptionSet(Account.OPTION_USETLS)) {
useTLS.setChecked(true); useTLS.setChecked(true);
} else { } else {
useTLS.setChecked(false); useTLS.setChecked(false);
} }
if (account.isOptionSet(Account.OPTION_REGISTER)) {
registerAccount.setChecked(true);
builder.setTitle("Add account");
okButtonDesc = "Register";
} else {
registerAccount.setVisibility(View.GONE);
builder.setTitle("Edit account");
okButtonDesc = "Edit";
}
} else { } else {
builder.setTitle("Add account"); builder.setTitle("Add account");
okButtonDesc = "Add"; okButtonDesc = "Add";
@ -110,6 +116,7 @@ public class EditAccount extends DialogFragment {
.findViewById(R.id.account_password); .findViewById(R.id.account_password);
String password = passwordEdit.getText().toString(); String password = passwordEdit.getText().toString();
CheckBox useTLS = (CheckBox) d.findViewById(R.id.account_usetls); CheckBox useTLS = (CheckBox) d.findViewById(R.id.account_usetls);
CheckBox register = (CheckBox) d.findViewById(R.id.edit_account_register_new);
String username; String username;
String server; String server;
if (Validator.isValidJid(jid)) { if (Validator.isValidJid(jid)) {
@ -128,6 +135,7 @@ public class EditAccount extends DialogFragment {
account = new Account(username, server, password); account = new Account(username, server, password);
} }
account.setOption(Account.OPTION_USETLS, useTLS.isChecked()); account.setOption(Account.OPTION_USETLS, useTLS.isChecked());
account.setOption(Account.OPTION_REGISTER, register.isChecked());
if (listener != null) { if (listener != null) {
listener.onAccountEdited(account); listener.onAccountEdited(account);
d.dismiss(); d.dismiss();

View file

@ -64,7 +64,7 @@ public class MucDetailsActivity extends XmppActivity {
membersView = (LinearLayout) findViewById(R.id.muc_members); membersView = (LinearLayout) findViewById(R.id.muc_members);
mMoreDetails = (LinearLayout) findViewById(R.id.muc_more_details); mMoreDetails = (LinearLayout) findViewById(R.id.muc_more_details);
mMoreDetails.setVisibility(View.GONE); mMoreDetails.setVisibility(View.GONE);
contactsAdapter = new ArrayAdapter<MucOptions.User>(this, /*contactsAdapter = new ArrayAdapter<MucOptions.User>(this,
R.layout.contact, users) { R.layout.contact, users) {
@Override @Override
public View getView(int position, View view, ViewGroup parent) { public View getView(int position, View view, ViewGroup parent) {
@ -80,11 +80,10 @@ public class MucDetailsActivity extends XmppActivity {
role.setText(getReadableRole(contact.getRole())); role.setText(getReadableRole(contact.getRole()));
ImageView imageView = (ImageView) view ImageView imageView = (ImageView) view
.findViewById(R.id.contact_photo); .findViewById(R.id.contact_photo);
imageView.setImageBitmap(UIHelper.getUnknownContactPicture( imageView.setImageBitmap(UIHelper.getContactPictureByName(contact.getName(), 90));
getItem(position).getName(), 90));
return view; return view;
} }
}; };*/
getActionBar().setHomeButtonEnabled(true); getActionBar().setHomeButtonEnabled(true);
getActionBar().setDisplayHomeAsUpEnabled(true); getActionBar().setDisplayHomeAsUpEnabled(true);
@ -151,7 +150,7 @@ public class MucDetailsActivity extends XmppActivity {
} }
this.users.clear(); this.users.clear();
this.users.addAll(conversation.getMucOptions().getUsers()); this.users.addAll(conversation.getMucOptions().getUsers());
contactsAdapter.notifyDataSetChanged(); //contactsAdapter.notifyDataSetChanged();
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
membersView.removeAllViews(); membersView.removeAllViews();
for(User contact : conversation.getMucOptions().getUsers()) { for(User contact : conversation.getMucOptions().getUsers()) {
@ -163,7 +162,7 @@ public class MucDetailsActivity extends XmppActivity {
role.setText(getReadableRole(contact.getRole())); role.setText(getReadableRole(contact.getRole()));
ImageView imageView = (ImageView) view ImageView imageView = (ImageView) view
.findViewById(R.id.contact_photo); .findViewById(R.id.contact_photo);
imageView.setImageBitmap(UIHelper.getUnknownContactPicture(contact.getName(), 90)); imageView.setImageBitmap(UIHelper.getContactPictureByName(contact.getName(), 90));
membersView.addView(view); membersView.addView(view);
} }
} }

View file

@ -135,15 +135,9 @@ public class NewConversationActivity extends XmppActivity {
TextView contactJid = (TextView) view TextView contactJid = (TextView) view
.findViewById(R.id.contact_jid); .findViewById(R.id.contact_jid);
contactJid.setText(contact.getJid()); contactJid.setText(contact.getJid());
String profilePhoto = getItem(position).getProfilePhoto();
ImageView imageView = (ImageView) view ImageView imageView = (ImageView) view
.findViewById(R.id.contact_photo); .findViewById(R.id.contact_photo);
if (profilePhoto != null) { imageView.setImageBitmap(UIHelper.getContactPicture(contact,90,this.getContext()));
imageView.setImageURI(Uri.parse(profilePhoto));
} else {
imageView.setImageBitmap(UIHelper.getUnknownContactPicture(
getItem(position).getDisplayName(), 90));
}
return view; return view;
} }
}; };

View file

@ -64,7 +64,7 @@ public class UIHelper {
} }
} }
public static Bitmap getUnknownContactPicture(String name, int size) { private static Bitmap getUnknownContactPicture(String name, int size) {
String firstLetter = name.substring(0, 1).toUpperCase(Locale.US); String firstLetter = name.substring(0, 1).toUpperCase(Locale.US);
int holoColors[] = { 0xFF1da9da, 0xFFb368d9, 0xFF83b600, 0xFFffa713, int holoColors[] = { 0xFF1da9da, 0xFFb368d9, 0xFF83b600, 0xFFffa713,
@ -92,6 +92,9 @@ public class UIHelper {
} }
public static Bitmap getContactPicture(Contact contact, int size, Context context) { public static Bitmap getContactPicture(Contact contact, int size, Context context) {
if (contact==null) {
return getUnknownContactPicture(contact.getDisplayName(), size);
}
String uri = contact.getProfilePhoto(); String uri = contact.getProfilePhoto();
if (uri==null) { if (uri==null) {
return getUnknownContactPicture(contact.getDisplayName(), size); return getUnknownContactPicture(contact.getDisplayName(), size);
@ -299,4 +302,21 @@ public class UIHelper {
builder.setView(view); builder.setView(view);
return builder.create(); return builder.create();
} }
public static Bitmap getSelfContactPicture(Account account, int size, boolean showPhoneSelfContactPicture, Activity activity) {
Uri selfiUri = PhoneHelper.getSefliUri(activity);
if (selfiUri != null) {
try {
return BitmapFactory.decodeStream(activity
.getContentResolver().openInputStream(selfiUri));
} catch (FileNotFoundException e) {
return getUnknownContactPicture(account.getJid(), size);
}
}
return getUnknownContactPicture(account.getJid(), size);
}
public static Bitmap getContactPictureByName(String name, int size) {
return getUnknownContactPicture(name, size);
}
} }

View file

@ -109,6 +109,7 @@ public class XmppConnection implements Runnable {
Log.d(LOGTAG,account.getJid()+ ": connecting"); Log.d(LOGTAG,account.getJid()+ ": connecting");
lastConnect = SystemClock.elapsedRealtime(); lastConnect = SystemClock.elapsedRealtime();
try { try {
shouldAuthenticate = shouldBind = !account.isOptionSet(Account.OPTION_REGISTER);
tagReader = new XmlReader(wakeLock); tagReader = new XmlReader(wakeLock);
tagWriter = new TagWriter(); tagWriter = new TagWriter();
packetCallbacks.clear(); packetCallbacks.clear();
@ -185,6 +186,9 @@ public class XmppConnection implements Runnable {
&& (!account.isOptionSet(Account.OPTION_USETLS))) { && (!account.isOptionSet(Account.OPTION_USETLS))) {
changeStatus(Account.STATUS_SERVER_REQUIRES_TLS); changeStatus(Account.STATUS_SERVER_REQUIRES_TLS);
} }
if (account.isOptionSet(Account.OPTION_REGISTER)) {
Log.d(LOGTAG,account.getJid()+": trying to register");
}
} else if (nextTag.isStart("proceed")) { } else if (nextTag.isStart("proceed")) {
switchOverToTls(nextTag); switchOverToTls(nextTag);
} else if (nextTag.isStart("success")) { } else if (nextTag.isStart("success")) {