package com.battlelancer.seriesguide.widgets;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;
import butterknife.BindView;
import butterknife.ButterKnife;
import com.battlelancer.seriesguide.R;
import com.battlelancer.seriesguide.sync.SyncProgress;

public class SyncStatusView extends LinearLayout {

    @BindView(R.id.progressBarSyncStatus) ProgressBar progressBar;
    @BindView(R.id.imageViewSyncStatus) ImageView imageView;
    @BindView(R.id.textViewSyncStatus) TextView textView;

    public SyncStatusView(Context context) {
        this(context, null);
    }

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

        setOrientation(HORIZONTAL);
        LayoutInflater.from(context).inflate(R.layout.view_sync_status, this);
    }

    @Override
    protected void onFinishInflate() {
        super.onFinishInflate();
        ButterKnife.bind(this);

        imageView.setVisibility(GONE);
    }

    /**
     * If there is progress or a failure result, displays it. Otherwise sets the view {@link
     * View#GONE}.
     */
    public void setProgress(SyncProgress.SyncEvent event) {
        if (event.isSyncing()) {
            progressBar.setVisibility(View.VISIBLE);
            imageView.setVisibility(GONE);
            setVisibility(VISIBLE);
        } else {
            // Finished.
            progressBar.setVisibility(View.GONE);

            if (event.isFinishedWithError()) {
                imageView.setVisibility(VISIBLE);
                setVisibility(VISIBLE);
            } else {
                // Successful.
                imageView.setVisibility(GONE);
                setVisibility(GONE);
                return; // No need to update status text.
            }
        }
        textView.setText(event.getDescription(getContext()));
    }
}

@@ -194,514 +194,242 @@
 get.
-ImageView;%0Aimport android.widget.LinearLayout;%0Aimport android.widget.ProgressBar;%0Aimport android.widget.TextView;%0Aimport butterknife.BindView;%0Aimport butterknife.ButterKnife;%0Aimport com.battlelancer.seriesguide.R;%0Aimport com.battlelancer.seriesguide.sync.SyncProgress;%0A%0Apublic class SyncStatusView extends LinearLayout %7B%0A%0A    @BindView(R.id.progressBarSyncStatus) ProgressBar progressBar;%0A    @BindView(R.id.imageViewSyncStatus) ImageView imageView;%0A    @BindView(R.id.textViewSyncStatus) TextView textView
+LinearLayout;%0Aimport com.battlelancer.seriesguide.databinding.ViewSyncStatusBinding;%0Aimport com.battlelancer.seriesguide.sync.SyncProgress;%0A%0Apublic class SyncStatusView extends LinearLayout %7B%0A%0A    private ViewSyncStatusBinding binding
 ;%0A%0A 
@@ -600,25 +600,24 @@
 xt, attrs);%0A
-%0A
         setO
@@ -640,24 +640,25 @@
 ONTAL);%0A
+%0A
         
 LayoutIn
@@ -653,70 +653,76 @@
     
-LayoutInflater.from(context).inflate(R.layout.view_sync_status
+binding = ViewSyncStatusBinding.inflate(LayoutInflater.from(context)
 , th
@@ -831,50 +831,35 @@
     
-ButterKnife.bind(this);%0A%0A        imageView
+binding.imageViewSyncStatus
 .set
@@ -952,16 +952,23 @@
 lays it.
+%0A     *
  Otherwi
@@ -990,23 +990,16 @@
 w %7B@link
-%0A     *
  View#GO
@@ -1108,32 +1108,40 @@
 ) %7B%0A            
+binding.
 progressBar.setV
@@ -1127,32 +1127,42 @@
 ding.progressBar
+SyncStatus
 .setVisibility(V
@@ -1179,32 +1179,40 @@
 E);%0A            
+binding.
 imageView.setVis
@@ -1196,32 +1196,42 @@
 inding.imageView
+SyncStatus
 .setVisibility(G
@@ -1326,16 +1326,24 @@
         
+binding.
 progress
@@ -1345,16 +1345,26 @@
 gressBar
+SyncStatus
 .setVisi
@@ -1438,32 +1438,40 @@
                 
+binding.
 imageView.setVis
@@ -1455,32 +1455,42 @@
 inding.imageView
+SyncStatus
 .setVisibility(V
@@ -1606,16 +1606,24 @@
         
+binding.
 imageVie
@@ -1619,24 +1619,34 @@
 ng.imageView
+SyncStatus
 .setVisibili
@@ -1786,16 +1786,34 @@
     
-textView
+binding.textViewSyncStatus
 .set

use view binding.