use of de.tum.in.tumcampusapp.component.tumui.person.model.TelSubstation in project TumCampusApp by TCA-Team.
the class PersonsDetailsActivity method displayResults.
/**
* Displays all relevant information about the given employee in the user
* interface (UI).
*
* @param employee The employee whose information should be displayed.
*/
private void displayResults(Employee employee) {
// add the employee's counterfeit
ImageView imageView = this.findViewById(R.id.ivImage);
Bitmap image = employee.getImage();
if (image == null) {
image = BitmapFactory.decodeResource(getResources(), R.drawable.photo_not_available_rectangular);
}
imageView.setImageBitmap(image);
// use a custom string buffer that helps us with line feeds and
// formatting
HTMLStringBuffer contentText = new HTMLStringBuffer();
TextView tvDetails1 = findViewById(R.id.tvDetails1);
// get the right gender
if (employee.getGender() != null && employee.getGender().equals(Person.Companion.getMALE())) {
contentText.append(getString(R.string.mr) + ' ');
} else if (employee.getGender() != null && employee.getGender().equals(Person.Companion.getFEMALE())) {
contentText.append(getString(R.string.mrs) + ' ');
}
// add title if available
if (employee.getTitle() != null) {
contentText.append(employee.getTitle() + ' ');
}
// add name
contentText.append(employee.getName() + ' ' + employee.getSurname());
tvDetails1.setText(contentText.toString());
// start new information section
contentText.clear();
TextView tvDetails2 = findViewById(R.id.tvDetails2);
// add all groups the employee belongs to
List<Group> groups = employee.getGroups();
if (groups != null) {
for (Group group : groups) {
if (group != null) {
contentText.appendField(getString(R.string.function), group.getTitle());
contentText.appendField(getString(R.string.group), group.getOrg() + " (" + group.getId() + ")<br />");
}
}
}
tvDetails2.setText(Utils.fromHtml(contentText.toString()), TextView.BufferType.SPANNABLE);
// start new section
contentText.clear();
TextView tvDetails3 = findViewById(R.id.tvDetails3);
// add contact information, if available
contentText.appendField(getString(R.string.email), employee.getEmail());
contentText.appendField(getString(R.string.homepage), employee.getBusinessContact().getHomepage());
List<TelSubstation> substations = employee.getTelSubstations();
if (substations != null) {
for (int i = 0; i < substations.size(); i++) {
if (substations.get(i) != null) {
contentText.appendField(getString(R.string.phone) + ' ' + i + 1, substations.get(i).getNumber());
}
}
}
contentText.appendField(getString(R.string.mobile_phone), employee.getBusinessContact().getMobilephone());
contentText.appendField(getString(R.string.add_info), employee.getBusinessContact().getAdditionalInfo());
tvDetails3.setText(Utils.fromHtml(contentText.toString()), TextView.BufferType.SPANNABLE);
// start new section
contentText.clear();
TextView tvDetails4 = findViewById(R.id.tvDetails4);
contentText.appendField(getString(R.string.office_hours), employee.getConsultationHours());
// add all rooms
List<Room> rooms = employee.getRooms();
if (rooms != null && !rooms.isEmpty()) {
contentText.appendField(getString(R.string.room), rooms.get(0).getLocation() + " (" + rooms.get(0).getNumber() + ')');
}
tvDetails4.setText(Utils.fromHtml(contentText.toString()), TextView.BufferType.SPANNABLE);
}
use of de.tum.in.tumcampusapp.component.tumui.person.model.TelSubstation in project TumCampusApp by TCA-Team.
the class PersonsDetailsActivity method addContact.
/**
* Adds the given employee to the users contact list
*
* @param employee Object to insert into contacts
*/
private void addContact(Employee employee) {
if (!isPermissionGranted(0)) {
return;
}
ArrayList<ContentProviderOperation> ops = new ArrayList<>();
int rawContactID = ops.size();
// Adding insert operation to operations list
// to insert a new raw contact in the table ContactsContract.RawContacts
ops.add(ContentProviderOperation.newInsert(RawContacts.CONTENT_URI).withValue(RawContacts.ACCOUNT_TYPE, null).withValue(RawContacts.ACCOUNT_NAME, null).build());
// Add full name
ops.add(ContentProviderOperation.newInsert(Data.CONTENT_URI).withValueBackReference(Data.RAW_CONTACT_ID, rawContactID).withValue(Data.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE).withValue(StructuredName.PREFIX, employee.getTitle()).withValue(StructuredName.GIVEN_NAME, employee.getName()).withValue(StructuredName.FAMILY_NAME, employee.getSurname()).build());
// Add e-mail address
if (employee.getEmail() != null) {
ops.add(ContentProviderOperation.newInsert(Data.CONTENT_URI).withValueBackReference(Data.RAW_CONTACT_ID, rawContactID).withValue(Data.MIMETYPE, CommonDataKinds.Email.CONTENT_ITEM_TYPE).withValue(CommonDataKinds.Email.DATA, employee.getEmail()).withValue(CommonDataKinds.Email.TYPE, Email.TYPE_WORK).build());
}
List<TelSubstation> substations = employee.getTelSubstations();
if (substations != null) {
for (TelSubstation sub : substations) {
ops.add(ContentProviderOperation.newInsert(Data.CONTENT_URI).withValueBackReference(Data.RAW_CONTACT_ID, rawContactID).withValue(Data.MIMETYPE, Phone.CONTENT_ITEM_TYPE).withValue(Phone.NUMBER, sub.getNumber()).withValue(Phone.TYPE, Phone.TYPE_WORK).build());
}
}
// Add work: telefon, mobile, fax, website
addContact(ops, rawContactID, employee.getBusinessContact(), true);
// Add home: telefon, mobile, fax, website
addContact(ops, rawContactID, employee.getPrivateContact(), false);
// Add organisations
if (employee.getGroups() != null) {
for (Group group : employee.getGroups()) {
ops.add(ContentProviderOperation.newInsert(Data.CONTENT_URI).withValueBackReference(Data.RAW_CONTACT_ID, rawContactID).withValue(Data.MIMETYPE, CommonDataKinds.Organization.CONTENT_ITEM_TYPE).withValue(CommonDataKinds.Organization.COMPANY, group.getOrg()).withValue(Data.MIMETYPE, CommonDataKinds.Organization.CONTENT_ITEM_TYPE).withValue(CommonDataKinds.Organization.TITLE, group.getTitle()).withValue(Data.MIMETYPE, CommonDataKinds.Organization.CONTENT_ITEM_TYPE).withValue(CommonDataKinds.Organization.TYPE, Organization.TYPE_WORK).build());
}
}
// Add office hours
StringBuilder notes = new StringBuilder();
if (employee.getConsultationHours() != null) {
notes.append(getString(R.string.office_hours)).append(": ").append(employee.getConsultationHours());
}
// add all rooms
List<Room> rooms = employee.getRooms();
if (rooms != null && !rooms.isEmpty()) {
if (!notes.toString().isEmpty()) {
notes.append('\n');
}
notes.append(getString(R.string.room)).append(": ").append(rooms.get(0).getLocation()).append(" (").append(rooms.get(0).getNumber()).append(')');
}
// Finally add notes
if (!notes.toString().isEmpty()) {
ops.add(ContentProviderOperation.newInsert(Data.CONTENT_URI).withValueBackReference(Data.RAW_CONTACT_ID, rawContactID).withValue(Data.MIMETYPE, Note.CONTENT_ITEM_TYPE).withValue(Note.NOTE, notes.toString()).build());
}
// Add image
Bitmap bitmap = employee.getImage();
if (bitmap != null) {
// If an image is selected successfully
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 75, stream);
// Adding insert operation to operations list
// to insert Photo in the table ContactsContract.Data
ops.add(ContentProviderOperation.newInsert(Data.CONTENT_URI).withValueBackReference(Data.RAW_CONTACT_ID, rawContactID).withValue(Data.IS_SUPER_PRIMARY, 1).withValue(Data.MIMETYPE, Photo.CONTENT_ITEM_TYPE).withValue(CommonDataKinds.Photo.PHOTO, stream.toByteArray()).build());
try {
stream.flush();
} catch (IOException e) {
Utils.log(e);
}
}
// Executing all the insert operations as a single database transaction
try {
getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops);
Utils.showToast(this, R.string.contact_added);
} catch (RemoteException | OperationApplicationException e) {
Utils.log(e);
}
}
Aggregations