package com.battlelancer.seriesguide.widgets;

import android.content.Context;
import android.util.AttributeSet;
import androidx.appcompat.widget.AppCompatImageView;
import androidx.vectordrawable.graphics.drawable.VectorDrawableCompat;
import com.battlelancer.seriesguide.R;
import com.battlelancer.seriesguide.ui.episodes.EpisodeFlags;
import com.battlelancer.seriesguide.ui.episodes.EpisodeTools;
import com.battlelancer.seriesguide.util.ViewTools;

/**
 * Image view that displays a watched, skipped or watch icon depending on the given episode flag.
 */
public class WatchedBox extends AppCompatImageView {

    private int episodeFlag;
    private VectorDrawableCompat drawableWatch;

    public WatchedBox(Context context, AttributeSet attrs) {
        super(context, attrs);

        if (isInEditMode()) {
            episodeFlag = EpisodeFlags.UNWATCHED;
            updateStateImage();
        }
    }

    public int getEpisodeFlag() {
        return episodeFlag;
    }

    /**
     * Set an {@link EpisodeFlags} flag.
     */
    public void setEpisodeFlag(int episodeFlag) {
        EpisodeTools.validateFlags(episodeFlag);
        this.episodeFlag = episodeFlag;
        updateStateImage();
    }

    private void updateStateImage() {
        switch (episodeFlag) {
            case EpisodeFlags.WATCHED: {
                setImageResource(R.drawable.ic_watched_24dp);
                break;
            }
            case EpisodeFlags.SKIPPED: {
                setImageResource(R.drawable.ic_skipped_24dp);
                break;
            }
            case EpisodeFlags.UNWATCHED:
            default: {
                if (drawableWatch == null) {
                    drawableWatch = ViewTools.vectorIconActive(getContext(),
                            getContext().getTheme(), R.drawable.ic_watch_black_24dp);
                }
                setImageDrawable(drawableWatch);
                break;
            }
        }
    }
}

@@ -163,79 +163,8 @@
 ew;%0A
-import androidx.vectordrawable.graphics.drawable.VectorDrawableCompat;%0A
 impo
@@ -198,16 +198,16 @@
 uide.R;%0A
+
 import c
@@ -325,60 +325,8 @@
 ols;
-%0Aimport com.battlelancer.seriesguide.util.ViewTools;
 %0A%0A/*
@@ -483,16 +483,16 @@
 View %7B%0A%0A
+
     priv
@@ -515,56 +515,8 @@
 lag;
-%0A    private VectorDrawableCompat drawableWatch;
 %0A%0A  
@@ -1468,264 +1468,55 @@
     
-if (drawableWatch == null) %7B%0A                    drawableWatch = ViewTools.vectorIconActive(getContext(),%0A                            getContext().getTheme(), R.drawable.ic_watch_black_24dp);%0A                %7D%0A                setImageDrawable(drawableWatch
+setImageResource(R.drawable.ic_watch_black_24dp
 );%0A 

Update WatchedBox icons.