// Path: mobile/src/main/java/io/ashdavies/eternity/android/StringFormatter.java
// public interface StringFormatter<T> {
// 
//   String format(T t);
// }
// 
// Path: mobile/src/main/java/io/ashdavies/eternity/android/StringResolver.java
// public class StringResolver {
// 
//   private final Resources resources;
// 
//   @Inject
//   public StringResolver(Resources resources) {
//     this.resources = resources;
//   }
// 
//   public String get(@StringRes int resId, Object... args) {
//     return resources.getString(resId, args);
//   }
// }
// 
// Path: mobile/src/main/java/io/ashdavies/eternity/android/TimeFormatter.java
// public class TimeFormatter implements StringFormatter<Long> {
// 
//   private static final String FORMAT = "MMM dd";
// 
//   private final StringResolver resolver;
//   private final SimpleDateFormat format;
// 
//   @Inject
//   public TimeFormatter(StringResolver resolver) {
//     this(resolver, new SimpleDateFormat(FORMAT, Locale.getDefault()));
//   }
// 
//   private TimeFormatter(StringResolver resolver, SimpleDateFormat format) {
//     this.resolver = resolver;
//     this.format = format;
//   }
// 
//   @Override
//   public String format(Long millis) {
//     long diff = System.currentTimeMillis() - millis;
// 
//     if (diff < TimeUnit.HOURS.toMillis(1)) {
//       return resolver.get(R.string.label_minutes, Math.max(1, TimeUnit.MILLISECONDS.toMinutes(diff)));
//     }
// 
//     if (diff < TimeUnit.DAYS.toMillis(1)) {
//       return resolver.get(R.string.label_hours, Math.max(1, TimeUnit.MILLISECONDS.toHours(diff)));
//     }
// 
//     return format.format(new Date(millis));
//   }
// }
// 
// Path: mobile/src/main/java/io/ashdavies/eternity/domain/Message.java
// @AutoValue
// @FirebaseValue
// public abstract class Message {
// 
//   public abstract String uuid();
//   public abstract String text();
//   public abstract Author author();
//   public abstract long created();
// 
//   @Nullable
//   public abstract Message original();
// 
//   public Object toFirebaseValue() {
//     return new AutoValue_Message.FirebaseValue(this);
//   }
// 
//   private static Builder builder() {
//     return new AutoValue_Message.Builder()
//         .uuid(UUID.randomUUID().toString())
//         .created(System.currentTimeMillis());
//   }
// 
//   public static Builder from(String text) {
//     return builder().text(text);
//   }
// 
//   public static Builder from(Message message) {
//     return from(message.text()).original(message);
//   }
// 
//   public static Message create(DataSnapshot snapshot) {
//     return snapshot.getValue(AutoValue_Message.FirebaseValue.class).toAutoValue();
//   }
// 
//   @AutoValue.Builder
//   public abstract static class Builder {
// 
//     public abstract Builder uuid(String uuid);
//     public abstract Builder text(String text);
//     public abstract Builder author(Author author);
//     public abstract Builder created(long created);
// 
//     public abstract Builder original(@Nullable Message message);
// 
//     public abstract Message build();
//   }
// }


import android.content.Context;
import android.support.v4.util.Pair;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.ToggleButton;
import butterknife.BindView;
import butterknife.ButterKnife;
import com.squareup.picasso.Picasso;
import io.ashdavies.commons.adapter.AbstractAdapter;
import io.ashdavies.eternity.R;
import io.ashdavies.eternity.android.StringFormatter;
import io.ashdavies.eternity.android.StringResolver;
import io.ashdavies.eternity.android.TimeFormatter;
import io.ashdavies.eternity.domain.Message;
    ButterKnife.bind(this, view);

    this.resolver = new StringResolver(context.getResources());
    this.formatter = new TimeFormatter(resolver);

    this.listener = listener;
  }

  @Override
  protected void bind(Pair<Message, MessageState> pair) {
    Message message = pair.first;

    if (message.original() != null) {
      reposted.setText(resolver.get(R.string.label_reposted, message.author().name()));
      reposted.setVisibility(View.VISIBLE);

      message = message.original();
    }

    Picasso.with(getContext())
        .load(message.author().avatar())
        .transform(new CircleTransform(12))
        .into(avatar);

    favourite.setChecked(pair.second.favourite());
    favourite.setVisibility(listener.favouriteEnabled() ? View.VISIBLE : View.GONE);

    author.setText(message.author().name());
    text.setText(message.text());

// Path: mobile/src/main/java/io/ashdavies/eternity/android/StringFormatter.java
// public interface StringFormatter<T> {
// 
//   String format(T t);
// }
// 
// Path: mobile/src/main/java/io/ashdavies/eternity/android/StringResolver.java
// public class StringResolver {
// 
//   private final Resources resources;
// 
//   @Inject
//   public StringResolver(Resources resources) {
//     this.resources = resources;
//   }
// 
//   public String get(@StringRes int resId, Object... args) {
//     return resources.getString(resId, args);
//   }
// }
// 
// Path: mobile/src/main/java/io/ashdavies/eternity/android/TimeFormatter.java
// public class TimeFormatter implements StringFormatter<Long> {
// 
//   private static final String FORMAT = "MMM dd";
// 
//   private final StringResolver resolver;
//   private final SimpleDateFormat format;
// 
//   @Inject
//   public TimeFormatter(StringResolver resolver) {
//     this(resolver, new SimpleDateFormat(FORMAT, Locale.getDefault()));
//   }
// 
//   private TimeFormatter(StringResolver resolver, SimpleDateFormat format) {
//     this.resolver = resolver;
//     this.format = format;
//   }
// 
//   @Override
//   public String format(Long millis) {
//     long diff = System.currentTimeMillis() - millis;
// 
//     if (diff < TimeUnit.HOURS.toMillis(1)) {
//       return resolver.get(R.string.label_minutes, Math.max(1, TimeUnit.MILLISECONDS.toMinutes(diff)));
//     }
// 
//     if (diff < TimeUnit.DAYS.toMillis(1)) {
//       return resolver.get(R.string.label_hours, Math.max(1, TimeUnit.MILLISECONDS.toHours(diff)));
//     }
// 
//     return format.format(new Date(millis));
//   }
// }
// 
// Path: mobile/src/main/java/io/ashdavies/eternity/domain/Message.java
// @AutoValue
// @FirebaseValue
// public abstract class Message {
// 
//   public abstract String uuid();
//   public abstract String text();
//   public abstract Author author();
//   public abstract long created();
// 
//   @Nullable
//   public abstract Message original();
// 
//   public Object toFirebaseValue() {
//     return new AutoValue_Message.FirebaseValue(this);
//   }
// 
//   private static Builder builder() {
//     return new AutoValue_Message.Builder()
//         .uuid(UUID.randomUUID().toString())
//         .created(System.currentTimeMillis());
//   }
// 
//   public static Builder from(String text) {
//     return builder().text(text);
//   }
// 
//   public static Builder from(Message message) {
//     return from(message.text()).original(message);
//   }
// 
//   public static Message create(DataSnapshot snapshot) {
//     return snapshot.getValue(AutoValue_Message.FirebaseValue.class).toAutoValue();
//   }
// 
//   @AutoValue.Builder
//   public abstract static class Builder {
// 
//     public abstract Builder uuid(String uuid);
//     public abstract Builder text(String text);
//     public abstract Builder author(Author author);
//     public abstract Builder created(long created);
// 
//     public abstract Builder original(@Nullable Message message);
// 
//     public abstract Message build();
//   }
// }


// Path: mobile/src/main/java/io/ashdavies/eternity/chat/MessageViewHolder.java
import android.content.Context;
import android.support.v4.util.Pair;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.ToggleButton;
import butterknife.BindView;
import butterknife.ButterKnife;
import com.squareup.picasso.Picasso;
import io.ashdavies.commons.adapter.AbstractAdapter;
import io.ashdavies.eternity.R;
import io.ashdavies.eternity.android.StringFormatter;
import io.ashdavies.eternity.android.StringResolver;
import io.ashdavies.eternity.android.TimeFormatter;
import io.ashdavies.eternity.domain.Message;

    ButterKnife.bind(this, view);

    this.resolver = new StringResolver(context.getResources());
    this.formatter = new TimeFormatter(resolver);

    this.listener = listener;
  }

  @Override
  protected void bind(Pair<Message, MessageState> pair) {
    Message message = pair.first;

    if (message.original() != null) {
      reposted.setText(resolver.get(R.string.label_reposted, message.author().name()));
      reposted.setVisibility(View.VISIBLE);

      message = message.original();
    }

    Picasso.with(getContext())
        .load(message.author().avatar())
        .transform(new CircleTransform(12))
        .into(avatar);

    favourite.setChecked(pair.second.favourite());
    favourite.setVisibility(listener.favouriteEnabled() ? View.VISIBLE : View.GONE);

    author.setText(message.author().name());
    text.setText(message.text());

    repost.setOnClickListener(new RepostClickListener(listener, message));