AbstractRenderer.java 1.17 KB
Newer Older
1 2 3
package chat.rocket.android.renderer;

import android.content.Context;
4
import android.support.annotation.Nullable;
5
import android.view.View;
Yusuke Iwaki's avatar
Yusuke Iwaki committed
6

7 8 9 10 11 12 13 14 15 16 17 18
import chat.rocket.android.renderer.optional.Condition;
import chat.rocket.android.renderer.optional.Optional;

abstract class AbstractRenderer<T> {
  protected final Context context;
  protected final T object;

  protected AbstractRenderer(Context context, T object) {
    this.context = context;
    this.object = object;
  }

19
  // TODO should we get rid of this simpler version of 'shouldHandle'?
20 21 22 23
  protected boolean shouldHandle(View view) {
    return object != null && view != null;
  }

24 25 26 27 28
  protected boolean shouldHandle(View target,
                                 @Nullable Condition additionalCondition,
                                 Optional optional,
                                 @Nullable String key) {
    if (target == null) {
29 30
      return false;
    }
31 32 33 34
    if (object == null) {
      optional.onNoData(key);
    } else {
      if (additionalCondition == null || additionalCondition.isOK()) {
35
        optional.onDataExists(key);
36 37 38
        return true;
      } else {
        optional.onNoData(key);
39 40
      }
    }
41
    return false;
42 43
  }
}