contact picture generation centralized + basic registry stuff
This commit is contained in:
parent
eadebeb77c
commit
a80e3131be
|
@ -209,8 +209,7 @@ public class OtrEngine implements OtrEngineHost {
|
|||
|
||||
@Override
|
||||
public void unreadableMessageReceived(SessionID arg0) throws OtrException {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
throw new OtrException(new Exception("unreadable message received"));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -29,6 +29,7 @@ public class Account extends AbstractEntity{
|
|||
|
||||
public static final int OPTION_USETLS = 0;
|
||||
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_DISABLED = -2;
|
||||
|
|
|
@ -396,7 +396,7 @@ public class XmppConnectionService extends Service {
|
|||
|
||||
@Override
|
||||
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()
|
||||
.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
|
||||
|
@ -441,6 +441,7 @@ public class XmppConnectionService extends Service {
|
|||
Log.d(LOGTAG,account.getJid()+": time out during connect reconnecting");
|
||||
reconnectAccount(account,true);
|
||||
} else {
|
||||
Log.d(LOGTAG,"seconds since last connect:"+((SystemClock.elapsedRealtime() - account.getXmppConnection().lastConnect) / 1000));
|
||||
Log.d(LOGTAG,account.getJid()+": status="+account.getStatus());
|
||||
// TODO notify user of ssl cert problem or auth problem or what ever
|
||||
}
|
||||
|
@ -836,6 +837,7 @@ public class XmppConnectionService extends Service {
|
|||
} else {
|
||||
conversation.setMode(Conversation.MODE_SINGLE);
|
||||
}
|
||||
conversation.setMessages(databaseBackend.getMessages(conversation, 50));
|
||||
this.databaseBackend.updateConversation(conversation);
|
||||
conversation.setContact(findContact(account,
|
||||
conversation.getContactJid()));
|
||||
|
@ -887,7 +889,7 @@ public class XmppConnectionService extends Service {
|
|||
public void createAccount(Account account) {
|
||||
databaseBackend.createAccount(account);
|
||||
this.accounts.add(account);
|
||||
account.setXmppConnection(this.createConnection(account));
|
||||
this.reconnectAccount(account, false);
|
||||
if (accountChangedListener != null)
|
||||
accountChangedListener.onAccountListChangedListener();
|
||||
}
|
||||
|
|
|
@ -95,6 +95,7 @@ public class ConversationActivity extends XmppActivity {
|
|||
xmppConnectionService.createContact(contact);
|
||||
}
|
||||
};
|
||||
protected ConversationActivity activity = this;
|
||||
|
||||
public List<Conversation> getConversationList() {
|
||||
return this.conversationList;
|
||||
|
@ -177,17 +178,8 @@ public class ConversationActivity extends XmppActivity {
|
|||
((TextView) view.findViewById(R.id.conversation_lastupdate))
|
||||
.setText(UIHelper.readableTimeDifference(conv.getLatestMessage().getTimeSent()));
|
||||
|
||||
Uri profilePhoto = conv.getProfilePhotoUri();
|
||||
ImageView imageView = (ImageView) view.findViewById(R.id.conversation_image);
|
||||
if (profilePhoto!=null) {
|
||||
imageView.setImageURI(profilePhoto);
|
||||
} else {
|
||||
imageView.setImageBitmap(UIHelper.getUnknownContactPicture(getItem(position).getName(),200));
|
||||
}
|
||||
|
||||
|
||||
((ImageView) view.findViewById(R.id.conversation_image))
|
||||
.setImageURI(conv.getProfilePhotoUri());
|
||||
imageView.setImageBitmap(UIHelper.getContactPicture(getItem(position).getContact(), 200, activity.getApplicationContext()));
|
||||
return view;
|
||||
}
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@ import eu.siacs.conversations.utils.PhoneHelper;
|
|||
import eu.siacs.conversations.utils.UIHelper;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Fragment;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentSender;
|
||||
|
@ -91,7 +92,10 @@ public class ConversationFragment extends Fragment {
|
|||
Log.d("gultsch", "clicked to decrypt");
|
||||
if (askForPassphraseIntent != null) {
|
||||
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) {
|
||||
Log.d("gultsch", "couldnt fire intent");
|
||||
}
|
||||
|
@ -206,19 +210,13 @@ public class ConversationFragment extends Fragment {
|
|||
viewHolder.imageView = (ImageView) view
|
||||
.findViewById(R.id.message_photo);
|
||||
if (item.getConversation().getMode() == Conversation.MODE_SINGLE) {
|
||||
Uri uri = item.getConversation()
|
||||
.getProfilePhotoUri();
|
||||
if (uri != null) {
|
||||
viewHolder.imageView
|
||||
.setImageBitmap(mBitmapCache.get(item
|
||||
.getConversation().getName(),
|
||||
uri));
|
||||
} else {
|
||||
viewHolder.imageView
|
||||
.setImageBitmap(mBitmapCache.get(item
|
||||
.getConversation().getName(),
|
||||
null));
|
||||
}
|
||||
|
||||
viewHolder.imageView.setImageBitmap(mBitmapCache
|
||||
.get(item.getConversation().getName(), item
|
||||
.getConversation().getContact(),
|
||||
getActivity()
|
||||
.getApplicationContext()));
|
||||
|
||||
}
|
||||
break;
|
||||
case ERROR:
|
||||
|
@ -245,24 +243,30 @@ public class ConversationFragment extends Fragment {
|
|||
if (item.getConversation().getMode() == Conversation.MODE_MULTI) {
|
||||
if (item.getCounterpart() != null) {
|
||||
viewHolder.imageView.setImageBitmap(mBitmapCache
|
||||
.get(item.getCounterpart(), null));
|
||||
.get(item.getCounterpart(), null,
|
||||
getActivity()
|
||||
.getApplicationContext()));
|
||||
} else {
|
||||
viewHolder.imageView
|
||||
.setImageBitmap(mBitmapCache.get(item
|
||||
.getConversation().getName(), null));
|
||||
viewHolder.imageView.setImageBitmap(mBitmapCache
|
||||
.get(item.getConversation().getName(),
|
||||
null, getActivity()
|
||||
.getApplicationContext()));
|
||||
}
|
||||
}
|
||||
}
|
||||
String body = item.getBody();
|
||||
if (body != null) {
|
||||
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.setTypeface(null,Typeface.ITALIC);
|
||||
viewHolder.messageBody.setTypeface(null,
|
||||
Typeface.ITALIC);
|
||||
} else {
|
||||
viewHolder.messageBody.setText(body.trim());
|
||||
viewHolder.messageBody.setTextColor(0xff000000);
|
||||
viewHolder.messageBody.setTypeface(null, Typeface.NORMAL);
|
||||
viewHolder.messageBody.setTypeface(null,
|
||||
Typeface.NORMAL);
|
||||
}
|
||||
}
|
||||
if (item.getStatus() == Message.STATUS_UNSEND) {
|
||||
|
@ -296,26 +300,8 @@ public class ConversationFragment extends Fragment {
|
|||
boolean showPhoneSelfContactPicture = sharedPref.getBoolean(
|
||||
"show_phone_selfcontact_picture", true);
|
||||
|
||||
Bitmap self = null;
|
||||
|
||||
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;
|
||||
return UIHelper.getSelfContactPicture(conversation.getAccount(), 200,
|
||||
showPhoneSelfContactPicture, getActivity());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -354,7 +340,8 @@ public class ConversationFragment extends Fragment {
|
|||
sendPgpMessage(message);
|
||||
}
|
||||
if (conversation.getMode() == Conversation.MODE_MULTI) {
|
||||
activity.xmppConnectionService.setOnRenameListener(new OnRenameListener() {
|
||||
activity.xmppConnectionService
|
||||
.setOnRenameListener(new OnRenameListener() {
|
||||
|
||||
@Override
|
||||
public void onRename(final boolean success) {
|
||||
|
@ -363,9 +350,14 @@ public class ConversationFragment extends Fragment {
|
|||
@Override
|
||||
public void run() {
|
||||
if (success) {
|
||||
Toast.makeText(getActivity(), "Your nickname has been changed",Toast.LENGTH_SHORT).show();
|
||||
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();
|
||||
Toast.makeText(getActivity(),
|
||||
"Nichname is already in use",
|
||||
Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -419,7 +411,8 @@ public class ConversationFragment extends Fragment {
|
|||
if (!activity.shouldPaneBeOpen()) {
|
||||
conversation.markRead();
|
||||
// TODO update notifications
|
||||
UIHelper.updateNotification(getActivity(), activity.getConversationList(), null, false);
|
||||
UIHelper.updateNotification(getActivity(),
|
||||
activity.getConversationList(), null, false);
|
||||
activity.updateConversationList();
|
||||
}
|
||||
}
|
||||
|
@ -472,7 +465,8 @@ public class ConversationFragment extends Fragment {
|
|||
xmppService.sendMessage(message, null);
|
||||
chatMsg.setText("");
|
||||
} else {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(
|
||||
getActivity());
|
||||
builder.setTitle("No openPGP key found");
|
||||
builder.setIconAttribute(android.R.attr.alertDialogIcon);
|
||||
builder.setMessage("There is no openPGP key assoziated with this contact");
|
||||
|
@ -481,7 +475,8 @@ public class ConversationFragment extends Fragment {
|
|||
new DialogInterface.OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
public void onClick(DialogInterface dialog,
|
||||
int which) {
|
||||
conversation.nextMessageEncryption = Message.ENCRYPTION_NONE;
|
||||
message.setEncryption(Message.ENCRYPTION_NONE);
|
||||
xmppService.sendMessage(message, null);
|
||||
|
@ -564,20 +559,15 @@ public class ConversationFragment extends Fragment {
|
|||
private HashMap<String, Bitmap> bitmaps = new HashMap<String, Bitmap>();
|
||||
private Bitmap error = null;
|
||||
|
||||
public Bitmap get(String name, Uri uri) {
|
||||
public Bitmap get(String name, Contact contact, Context context) {
|
||||
if (bitmaps.containsKey(name)) {
|
||||
return bitmaps.get(name);
|
||||
} else {
|
||||
Bitmap bm;
|
||||
if (uri != null) {
|
||||
try {
|
||||
bm = BitmapFactory.decodeStream(getActivity()
|
||||
.getContentResolver().openInputStream(uri));
|
||||
} catch (FileNotFoundException e) {
|
||||
bm = UIHelper.getUnknownContactPicture(name, 200);
|
||||
}
|
||||
if (contact == null) {
|
||||
bm = UIHelper.getContactPictureByName(name, 200);
|
||||
} else {
|
||||
bm = UIHelper.getUnknownContactPicture(name, 200);
|
||||
bm = UIHelper.getContactPicture(contact, 200, context);
|
||||
}
|
||||
bitmaps.put(name, bm);
|
||||
return bm;
|
||||
|
@ -608,9 +598,11 @@ public class ConversationFragment extends Fragment {
|
|||
return false;
|
||||
}
|
||||
try {
|
||||
decrypted = activity.xmppConnectionService.getPgpEngine().decrypt(body);
|
||||
decrypted = activity.xmppConnectionService
|
||||
.getPgpEngine().decrypt(body);
|
||||
} catch (UserInputRequiredException e) {
|
||||
askForPassphraseIntent = e.getPendingIntent().getIntentSender();
|
||||
askForPassphraseIntent = e.getPendingIntent()
|
||||
.getIntentSender();
|
||||
activity.runOnUiThread(new Runnable() {
|
||||
|
||||
@Override
|
||||
|
|
|
@ -54,16 +54,22 @@ public class EditAccount extends DialogFragment {
|
|||
final String okButtonDesc;
|
||||
|
||||
if (account != null) {
|
||||
builder.setTitle("Edit account");
|
||||
registerAccount.setVisibility(View.GONE);
|
||||
jidText.setText(account.getJid());
|
||||
password.setText(account.getPassword());
|
||||
okButtonDesc = "Edit";
|
||||
if (account.isOptionSet(Account.OPTION_USETLS)) {
|
||||
useTLS.setChecked(true);
|
||||
} else {
|
||||
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 {
|
||||
builder.setTitle("Add account");
|
||||
okButtonDesc = "Add";
|
||||
|
@ -110,6 +116,7 @@ public class EditAccount extends DialogFragment {
|
|||
.findViewById(R.id.account_password);
|
||||
String password = passwordEdit.getText().toString();
|
||||
CheckBox useTLS = (CheckBox) d.findViewById(R.id.account_usetls);
|
||||
CheckBox register = (CheckBox) d.findViewById(R.id.edit_account_register_new);
|
||||
String username;
|
||||
String server;
|
||||
if (Validator.isValidJid(jid)) {
|
||||
|
@ -128,6 +135,7 @@ public class EditAccount extends DialogFragment {
|
|||
account = new Account(username, server, password);
|
||||
}
|
||||
account.setOption(Account.OPTION_USETLS, useTLS.isChecked());
|
||||
account.setOption(Account.OPTION_REGISTER, register.isChecked());
|
||||
if (listener != null) {
|
||||
listener.onAccountEdited(account);
|
||||
d.dismiss();
|
||||
|
|
|
@ -64,7 +64,7 @@ public class MucDetailsActivity extends XmppActivity {
|
|||
membersView = (LinearLayout) findViewById(R.id.muc_members);
|
||||
mMoreDetails = (LinearLayout) findViewById(R.id.muc_more_details);
|
||||
mMoreDetails.setVisibility(View.GONE);
|
||||
contactsAdapter = new ArrayAdapter<MucOptions.User>(this,
|
||||
/*contactsAdapter = new ArrayAdapter<MucOptions.User>(this,
|
||||
R.layout.contact, users) {
|
||||
@Override
|
||||
public View getView(int position, View view, ViewGroup parent) {
|
||||
|
@ -80,11 +80,10 @@ public class MucDetailsActivity extends XmppActivity {
|
|||
role.setText(getReadableRole(contact.getRole()));
|
||||
ImageView imageView = (ImageView) view
|
||||
.findViewById(R.id.contact_photo);
|
||||
imageView.setImageBitmap(UIHelper.getUnknownContactPicture(
|
||||
getItem(position).getName(), 90));
|
||||
imageView.setImageBitmap(UIHelper.getContactPictureByName(contact.getName(), 90));
|
||||
return view;
|
||||
}
|
||||
};
|
||||
};*/
|
||||
getActionBar().setHomeButtonEnabled(true);
|
||||
getActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
|
||||
|
@ -151,7 +150,7 @@ public class MucDetailsActivity extends XmppActivity {
|
|||
}
|
||||
this.users.clear();
|
||||
this.users.addAll(conversation.getMucOptions().getUsers());
|
||||
contactsAdapter.notifyDataSetChanged();
|
||||
//contactsAdapter.notifyDataSetChanged();
|
||||
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
membersView.removeAllViews();
|
||||
for(User contact : conversation.getMucOptions().getUsers()) {
|
||||
|
@ -163,7 +162,7 @@ public class MucDetailsActivity extends XmppActivity {
|
|||
role.setText(getReadableRole(contact.getRole()));
|
||||
ImageView imageView = (ImageView) view
|
||||
.findViewById(R.id.contact_photo);
|
||||
imageView.setImageBitmap(UIHelper.getUnknownContactPicture(contact.getName(), 90));
|
||||
imageView.setImageBitmap(UIHelper.getContactPictureByName(contact.getName(), 90));
|
||||
membersView.addView(view);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -135,15 +135,9 @@ public class NewConversationActivity extends XmppActivity {
|
|||
TextView contactJid = (TextView) view
|
||||
.findViewById(R.id.contact_jid);
|
||||
contactJid.setText(contact.getJid());
|
||||
String profilePhoto = getItem(position).getProfilePhoto();
|
||||
ImageView imageView = (ImageView) view
|
||||
.findViewById(R.id.contact_photo);
|
||||
if (profilePhoto != null) {
|
||||
imageView.setImageURI(Uri.parse(profilePhoto));
|
||||
} else {
|
||||
imageView.setImageBitmap(UIHelper.getUnknownContactPicture(
|
||||
getItem(position).getDisplayName(), 90));
|
||||
}
|
||||
imageView.setImageBitmap(UIHelper.getContactPicture(contact,90,this.getContext()));
|
||||
return view;
|
||||
}
|
||||
};
|
||||
|
|
|
@ -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);
|
||||
|
||||
int holoColors[] = { 0xFF1da9da, 0xFFb368d9, 0xFF83b600, 0xFFffa713,
|
||||
|
@ -92,6 +92,9 @@ public class UIHelper {
|
|||
}
|
||||
|
||||
public static Bitmap getContactPicture(Contact contact, int size, Context context) {
|
||||
if (contact==null) {
|
||||
return getUnknownContactPicture(contact.getDisplayName(), size);
|
||||
}
|
||||
String uri = contact.getProfilePhoto();
|
||||
if (uri==null) {
|
||||
return getUnknownContactPicture(contact.getDisplayName(), size);
|
||||
|
@ -299,4 +302,21 @@ public class UIHelper {
|
|||
builder.setView(view);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -109,6 +109,7 @@ public class XmppConnection implements Runnable {
|
|||
Log.d(LOGTAG,account.getJid()+ ": connecting");
|
||||
lastConnect = SystemClock.elapsedRealtime();
|
||||
try {
|
||||
shouldAuthenticate = shouldBind = !account.isOptionSet(Account.OPTION_REGISTER);
|
||||
tagReader = new XmlReader(wakeLock);
|
||||
tagWriter = new TagWriter();
|
||||
packetCallbacks.clear();
|
||||
|
@ -185,6 +186,9 @@ public class XmppConnection implements Runnable {
|
|||
&& (!account.isOptionSet(Account.OPTION_USETLS))) {
|
||||
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")) {
|
||||
switchOverToTls(nextTag);
|
||||
} else if (nextTag.isStart("success")) {
|
||||
|
|
Loading…
Reference in a new issue