Search in sources :

Example 1 with HTMLStringBuffer

use of de.tum.in.tumcampusapp.utils.HTMLStringBuffer 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);
}
Also used : Group(de.tum.in.tumcampusapp.component.tumui.person.model.Group) Bitmap(android.graphics.Bitmap) TextView(android.widget.TextView) TelSubstation(de.tum.in.tumcampusapp.component.tumui.person.model.TelSubstation) ImageView(android.widget.ImageView) Room(de.tum.in.tumcampusapp.component.tumui.person.model.Room) HTMLStringBuffer(de.tum.in.tumcampusapp.utils.HTMLStringBuffer)

Aggregations

Bitmap (android.graphics.Bitmap)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 Group (de.tum.in.tumcampusapp.component.tumui.person.model.Group)1 Room (de.tum.in.tumcampusapp.component.tumui.person.model.Room)1 TelSubstation (de.tum.in.tumcampusapp.component.tumui.person.model.TelSubstation)1 HTMLStringBuffer (de.tum.in.tumcampusapp.utils.HTMLStringBuffer)1