// Path: app/src/main/java/org/zephyrsoft/trackworktime/model/Week.java
// public class Week extends Base implements Comparable<Week> {
// 	private final LocalDate startDay;
// 
// 	public Week(LocalDate date) {
// 		// TODO consider locale
// 		startDay = date.with(DayOfWeek.MONDAY);
// 	}
// 
// 	public Week(long epochDay) {
// 		startDay = LocalDate.ofEpochDay(epochDay);
// 	}
// 
// 	public LocalDate getStart() {
// 		return startDay;
// 	}
// 
// 	public LocalDate getEnd() {
// 		// TODO consider locale
// 		return startDay.with(DayOfWeek.SUNDAY);
// 	}
// 
// 	public long toEpochDay() {
// 		return startDay.toEpochDay();
// 	}
// 
// 	public Week plusWeeks(long weeksToAdd) {
// 		return new Week(startDay.plusWeeks(weeksToAdd));
// 	}
// 
// 	public boolean isInWeek(LocalDate date) {
// 		return !date.isBefore(startDay) && !date.isAfter(getEnd());
// 	}
// 
// 	@Override
// 	public int compareTo(Week another) {
// 		//return compare(getStart(), another.getStart(), compare(getId(), another.getId(), 0));
// 		return compare(getStart(), another.getStart(), 0);
// 	}
// 
// 	/**
// 	 * This is used e.g. by an ArrayAdapter in a ListView and it is also useful for debugging.
// 	 *
// 	 * @see Base#toString()
// 	 */
// 	@Override
// 	public String toString() {
// 		return startDay.toString();
// 	}
// }
// 
// Path: app/src/main/java/org/zephyrsoft/trackworktime/model/WeekState.java
// public class WeekState {
// 
// 	public enum HighlightType {
// 		NONE,
// 		REGULAR_FREE,
// 		FREE,
// 		CHANGED_TARGET_TIME
// 	}
// 	
// 	public static class DayRowState {
// 		public String label = "";
// 		public HighlightType labelHighlighted = HighlightType.NONE;
// 		public String in = "";
// 		public String out = "";
// 		public String worked = "";
// 		public String flexi = "";
// 
// 		public boolean highlighted = false;
// 
// 		@NonNull @Override
// 		public String toString() {
// 			return "values: " + label + ", " + in + ", " + out + ", " + worked + ", " + flexi
// 					+ ", highlighted: " + highlighted;
// 		}
// 	}
// 	
// 	public static class SummaryRowState {
// 		public String label = "";
// 		public String worked = "";
// 		public String flexi = "";
// 
// 		@NonNull @Override
// 		public String toString() {
// 			return "values: " + label + ", " + worked + ", " + flexi;
// 		}
// 	}
// 	
// 	public String topLeftCorner = "";
// 	public final SummaryRowState totals = new SummaryRowState();
// 
// 	private final DayRowState[] dayRowStates = {
// 			new DayRowState(), new DayRowState(), new DayRowState(), new DayRowState(),
// 			new DayRowState(), new DayRowState(), new DayRowState()
// 	};
// 	
// 	public DayRowState getRowForDay(DayOfWeek dayOfWeek) {
// 		return dayRowStates[dayOfWeek.ordinal()];
// 	}
// 
// 	@NonNull @Override
// 	public String toString() {
// 		StringBuilder sb = new StringBuilder();
// 		sb.append(topLeftCorner); sb.append("\n");
// 
// 		for (DayOfWeek day : DayOfWeek.values()) {
// 			sb.append(getRowForDay(day).toString());
// 			sb.append("\n");
// 		}
// 
// 		sb.append(totals); sb.append("\n");
// 
// 		return sb.toString();
// 	}
// }
// 
// Path: app/src/main/java/org/zephyrsoft/trackworktime/weektimes/WeekTimesView.java
// public interface OnDayClickListener {
// 	void onClick(View v, DayOfWeek day);
// }


import static androidx.recyclerview.widget.RecyclerView.NO_POSITION;
import android.content.Context;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.lifecycle.LiveData;
import androidx.recyclerview.widget.RecyclerView;
import org.zephyrsoft.trackworktime.model.Week;
import org.zephyrsoft.trackworktime.model.WeekState;
import org.zephyrsoft.trackworktime.weektimes.WeekTimesView.OnDayClickListener;
import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
			@Nullable OnDayClickListener onDayClickListener,
			@Nullable OnClickListener onClickListener) {
		this.weekStateLoaderManager = weekStateLoaderManager;
		this.onDayClickListener = onDayClickListener;
		this.onClickListener = onClickListener;
		setHasStableIds(true);
	}

	@NonNull @Override
	public WeekTimesViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
		Context context = parent.getContext();
		WeekTimesView weekTimesView = createView(context);
		return new WeekTimesViewHolder(weekTimesView);
	}

	private WeekTimesView createView(Context context) {
		WeekTimesView weekTimesView = new WeekTimesView(context);
		weekTimesView.setLayoutParams(LAYOUT_PARAMS);
		weekTimesView.setOnDayClickListener(onDayClickListener);		
		weekTimesView.setOnClickListener(onClickListener);
		return weekTimesView;
	}

	@Override
	public void onBindViewHolder(@NonNull WeekTimesViewHolder holder, int position) {
		Week week = WeekIndexConverter.getWeekForIndex(position);
		int requestId = position;
		// Cancel request before starting new one. It's possible same week is still being loaded,
		// but holder hasn't been recycled yet.
		weekStateLoaderManager.cancelRequest(requestId);
// Path: app/src/main/java/org/zephyrsoft/trackworktime/model/Week.java
// public class Week extends Base implements Comparable<Week> {
// 	private final LocalDate startDay;
// 
// 	public Week(LocalDate date) {
// 		// TODO consider locale
// 		startDay = date.with(DayOfWeek.MONDAY);
// 	}
// 
// 	public Week(long epochDay) {
// 		startDay = LocalDate.ofEpochDay(epochDay);
// 	}
// 
// 	public LocalDate getStart() {
// 		return startDay;
// 	}
// 
// 	public LocalDate getEnd() {
// 		// TODO consider locale
// 		return startDay.with(DayOfWeek.SUNDAY);
// 	}
// 
// 	public long toEpochDay() {
// 		return startDay.toEpochDay();
// 	}
// 
// 	public Week plusWeeks(long weeksToAdd) {
// 		return new Week(startDay.plusWeeks(weeksToAdd));
// 	}
// 
// 	public boolean isInWeek(LocalDate date) {
// 		return !date.isBefore(startDay) && !date.isAfter(getEnd());
// 	}
// 
// 	@Override
// 	public int compareTo(Week another) {
// 		//return compare(getStart(), another.getStart(), compare(getId(), another.getId(), 0));
// 		return compare(getStart(), another.getStart(), 0);
// 	}
// 
// 	/**
// 	 * This is used e.g. by an ArrayAdapter in a ListView and it is also useful for debugging.
// 	 *
// 	 * @see Base#toString()
// 	 */
// 	@Override
// 	public String toString() {
// 		return startDay.toString();
// 	}
// }
// 
// Path: app/src/main/java/org/zephyrsoft/trackworktime/model/WeekState.java
// public class WeekState {
// 
// 	public enum HighlightType {
// 		NONE,
// 		REGULAR_FREE,
// 		FREE,
// 		CHANGED_TARGET_TIME
// 	}
// 	
// 	public static class DayRowState {
// 		public String label = "";
// 		public HighlightType labelHighlighted = HighlightType.NONE;
// 		public String in = "";
// 		public String out = "";
// 		public String worked = "";
// 		public String flexi = "";
// 
// 		public boolean highlighted = false;
// 
// 		@NonNull @Override
// 		public String toString() {
// 			return "values: " + label + ", " + in + ", " + out + ", " + worked + ", " + flexi
// 					+ ", highlighted: " + highlighted;
// 		}
// 	}
// 	
// 	public static class SummaryRowState {
// 		public String label = "";
// 		public String worked = "";
// 		public String flexi = "";
// 
// 		@NonNull @Override
// 		public String toString() {
// 			return "values: " + label + ", " + worked + ", " + flexi;
// 		}
// 	}
// 	
// 	public String topLeftCorner = "";
// 	public final SummaryRowState totals = new SummaryRowState();
// 
// 	private final DayRowState[] dayRowStates = {
// 			new DayRowState(), new DayRowState(), new DayRowState(), new DayRowState(),
// 			new DayRowState(), new DayRowState(), new DayRowState()
// 	};
// 	
// 	public DayRowState getRowForDay(DayOfWeek dayOfWeek) {
// 		return dayRowStates[dayOfWeek.ordinal()];
// 	}
// 
// 	@NonNull @Override
// 	public String toString() {
// 		StringBuilder sb = new StringBuilder();
// 		sb.append(topLeftCorner); sb.append("\n");
// 
// 		for (DayOfWeek day : DayOfWeek.values()) {
// 			sb.append(getRowForDay(day).toString());
// 			sb.append("\n");
// 		}
// 
// 		sb.append(totals); sb.append("\n");
// 
// 		return sb.toString();
// 	}
// }
// 
// Path: app/src/main/java/org/zephyrsoft/trackworktime/weektimes/WeekTimesView.java
// public interface OnDayClickListener {
// 	void onClick(View v, DayOfWeek day);
// }


// Path: app/src/main/java/org/zephyrsoft/trackworktime/weektimes/WeekAdapter.java
import static androidx.recyclerview.widget.RecyclerView.NO_POSITION;
import android.content.Context;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.lifecycle.LiveData;
import androidx.recyclerview.widget.RecyclerView;
import org.zephyrsoft.trackworktime.model.Week;
import org.zephyrsoft.trackworktime.model.WeekState;
import org.zephyrsoft.trackworktime.weektimes.WeekTimesView.OnDayClickListener;
import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;

			@Nullable OnDayClickListener onDayClickListener,
			@Nullable OnClickListener onClickListener) {
		this.weekStateLoaderManager = weekStateLoaderManager;
		this.onDayClickListener = onDayClickListener;
		this.onClickListener = onClickListener;
		setHasStableIds(true);
	}

	@NonNull @Override
	public WeekTimesViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
		Context context = parent.getContext();
		WeekTimesView weekTimesView = createView(context);
		return new WeekTimesViewHolder(weekTimesView);
	}

	private WeekTimesView createView(Context context) {
		WeekTimesView weekTimesView = new WeekTimesView(context);
		weekTimesView.setLayoutParams(LAYOUT_PARAMS);
		weekTimesView.setOnDayClickListener(onDayClickListener);		
		weekTimesView.setOnClickListener(onClickListener);
		return weekTimesView;
	}

	@Override
	public void onBindViewHolder(@NonNull WeekTimesViewHolder holder, int position) {
		Week week = WeekIndexConverter.getWeekForIndex(position);
		int requestId = position;
		// Cancel request before starting new one. It's possible same week is still being loaded,
		// but holder hasn't been recycled yet.
		weekStateLoaderManager.cancelRequest(requestId);
		LiveData<WeekState> weekState = weekStateLoaderManager.requestWeekState(week, requestId);