UserRenderer.java 1.44 KB
Newer Older
1 2 3 4 5
package chat.rocket.android.renderer;

import android.content.Context;
import android.widget.ImageView;
import android.widget.TextView;
Yusuke Iwaki's avatar
Yusuke Iwaki committed
6

7
import chat.rocket.android.helper.Avatar;
8
import chat.rocket.android.helper.TextUtils;
9
import chat.rocket.android.widget.AbsoluteUrl;
Tiago Cunha's avatar
Tiago Cunha committed
10
import chat.rocket.core.models.User;
Tiago Cunha's avatar
Tiago Cunha committed
11
import chat.rocket.android.widget.RocketChatAvatar;
12 13

/**
Tiago Cunha's avatar
Tiago Cunha committed
14
 * Renderer for RealmUser model.
15 16 17 18 19 20 21 22
 */
public class UserRenderer extends AbstractRenderer<User> {

  public UserRenderer(Context context, User user) {
    super(context, user);
  }

  /**
Tiago Cunha's avatar
Tiago Cunha committed
23
   * show Avatar image
24
   */
25
  public UserRenderer avatarInto(RocketChatAvatar rocketChatAvatar, AbsoluteUrl absoluteUrl) {
26
    if (!shouldHandle(rocketChatAvatar)) {
27 28 29
      return this;
    }

Tiago Cunha's avatar
Tiago Cunha committed
30
    if (!TextUtils.isEmpty(object.getUsername())) {
31
      new Avatar(absoluteUrl, object.getUsername()).into(rocketChatAvatar);
32
    }
33 34 35 36
    return this;
  }

  /**
Tiago Cunha's avatar
Tiago Cunha committed
37
   * show Username in textView
38 39 40 41 42 43
   */
  public UserRenderer usernameInto(TextView textView) {
    if (!shouldHandle(textView)) {
      return this;
    }

44
    textView.setText(object.getUsername());
45

46 47 48 49 50 51 52 53 54 55 56 57
    return this;
  }

  /**
   * show user's status color into imageView.
   */
  public UserRenderer statusColorInto(ImageView imageView) {
    if (!shouldHandle(imageView)) {
      return this;
    }

    String status = object.getStatus();
58
    imageView.setImageResource(RocketChatUserStatusProvider.getInstance().getStatusResId(status));
59 60 61 62

    return this;
  }
}