use of i2p.bote.packet.dht.Contact in project i2p.i2p-bote by i2p.
the class ContactAdapter method onBindViewHolder.
// Replace the contents of a view (invoked by the layout manager)
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
switch(holder.getItemViewType()) {
case R.layout.listitem_empty:
((TextView) holder.itemView).setText(mCtx.getResources().getString(R.string.address_book_empty));
break;
case R.layout.listitem_contact:
final ContactViewHolder cvh = (ContactViewHolder) holder;
Contact contact = mContacts.get(position);
String pic = contact.getPictureBase64();
if (pic != null && !pic.isEmpty())
cvh.mPicture.setImageBitmap(BoteHelper.decodePicture(pic));
else {
ViewGroup.LayoutParams lp = cvh.mPicture.getLayoutParams();
cvh.mPicture.setImageBitmap(BoteHelper.getIdenticonForAddress(contact.getBase64Dest(), lp.width, lp.height));
}
cvh.mName.setText(contact.getName());
cvh.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
mListener.onContactSelected(mContacts.get(cvh.getAdapterPosition()));
}
});
break;
default:
break;
}
}
use of i2p.bote.packet.dht.Contact in project i2p.i2p-bote by i2p.
the class EditContactFragment method initializeContact.
private void initializeContact() {
String newDest = getArguments().getString(NEW_DESTINATION);
if (mDestination != null) {
try {
Contact contact = BoteHelper.getContact(mDestination);
String pic = contact.getPictureBase64();
if (pic != null && !pic.isEmpty()) {
setPictureB64(pic);
}
mNameField.setText(contact.getName());
mTextField.setText(contact.getText());
} catch (PasswordException e) {
// TODO Handle
e.printStackTrace();
}
} else if (newDest != null) {
mNameField.setText(getArguments().getString(NEW_NAME));
mDestinationField.setText(newDest);
}
}
use of i2p.bote.packet.dht.Contact in project i2p.i2p-bote by i2p.
the class AddressBook method loadFromProperties.
protected boolean loadFromProperties(Properties properties, boolean append, boolean replace) {
if (contacts == null || !append) {
contacts = new TreeSet<Contact>(new ContactComparator());
}
int index = 0;
while (true) {
String prefix = "contact" + index + ".";
String name = properties.getProperty(prefix + "name");
if (name == null)
break;
String destBase64 = properties.getProperty(prefix + "destination");
if (destBase64 == null)
continue;
try {
EmailDestination destination = new EmailDestination(destBase64);
String pictureBase64 = properties.getProperty(prefix + "picture");
String text = properties.getProperty(prefix + "text");
Contact contact = new Contact(name, destination, pictureBase64, text);
if (append && replace && contacts.contains(contact)) {
contacts.remove(contact);
}
contacts.add(contact);
} catch (GeneralSecurityException e) {
log.error("Not a valid Email Destination: <" + destBase64 + ">", e);
}
index++;
}
return index > 0;
}
use of i2p.bote.packet.dht.Contact in project i2p.i2p-bote by i2p.
the class AddressBook method readContacts.
/**
* Reads an <code>AddressBook</code> from the encrypted address book file.
* Each contact is defined by one line that contains an Email Destination
* and a name, separated by a tab character.
* @throws PasswordException
*/
private void readContacts() throws PasswordException {
if (!addressFile.exists()) {
log.debug("Address file does not exist: <" + addressFile.getAbsolutePath() + ">");
contacts = new TreeSet<Contact>(new ContactComparator());
return;
}
log.debug("Reading address book from <" + addressFile.getAbsolutePath() + ">");
BufferedReader input = null;
try {
InputStream encryptedStream = new EncryptedInputStream(new FileInputStream(addressFile), passwordHolder);
input = new BufferedReader(new InputStreamReader(encryptedStream));
// No PasswordException occurred, so parse the input stream
Properties properties = new Properties();
properties.load(new InputStreamReader(encryptedStream));
loadFromProperties(properties, false, false);
} catch (PasswordException e) {
throw e;
} catch (Exception e) {
log.error("Can't read address book.", e);
} finally {
if (input != null)
try {
input.close();
} catch (IOException e) {
log.error("Error closing input stream.", e);
}
}
}
use of i2p.bote.packet.dht.Contact in project i2p.i2p-bote by i2p.
the class AddressDisplayFilter method getNameAndDestination.
/**
* Looks up the name associated with a Base64-encoded Email Destination
* in the address book and the local identities, and returns a string
* that contains the name and the Base64-encoded destination.<br/>
* If <code>address</code> already contains a name, it is replaced with
* the one from the address book or identities.<br/>
* If no name is found in the address book or the identities, or if
* <code>address</code> does not contain a valid Email Destination,
* <code>address</code> is returned.
* @param address A Base64-encoded Email Destination, and optionally a name
* @throws PasswordException
* @throws GeneralSecurityException
* @throws IOException
*/
public String getNameAndDestination(String address) throws PasswordException, IOException, GeneralSecurityException {
String base64dest = EmailDestination.extractBase64Dest(address);
if (base64dest != null) {
// try the address book
Contact contact = addressBook.get(base64dest);
if (contact != null)
return contact.getName() + " <" + contact.getBase64Dest() + ">";
// if no address book entry, try the email identities
EmailIdentity identity = identities.get(base64dest);
if (identity != null)
return identity.getPublicName() + " <" + identity.toBase64() + ">";
}
return address;
}
Aggregations