package com.aserbao.androidcustomcamera.whole.jiaozivideo;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.SeekBar;
import android.widget.Toast;

import com.aserbao.androidcustomcamera.R;

/**
 * Manage UI
 * Created by Nathen
 * On 2016/04/10 15:45
 */
public class JZVideoPlayerSimple extends JZVideoPlayer {

    public JZVideoPlayerSimple(Context context) {
        super(context);
    }

    public JZVideoPlayerSimple(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    public int getLayoutId() {
        return R.layout.jz_layout_base;
    }

    @Override
    public void setUp(String url, int screen, Object... objects) {
        super.setUp(url, screen, objects);
        updateFullscreenButton();
        fullscreenButton.setVisibility(View.GONE);
    }

    private void updateStartImage() {
        if (currentState == CURRENT_STATE_PLAYING) {
            startButton.setImageResource(R.drawable.jz_click_pause_selector);
        } else if (currentState == CURRENT_STATE_ERROR) {
            startButton.setImageResource(R.drawable.jz_click_error_selector);
        } else {
            startButton.setImageResource(R.drawable.jz_click_play_selector);
        }
    }

    public void updateFullscreenButton() {
        if (currentScreen == SCREEN_WINDOW_FULLSCREEN) {
            fullscreenButton.setImageResource(R.drawable.jz_shrink);
        } else {
            fullscreenButton.setImageResource(R.drawable.jz_enlarge);
        }
    }

    @Override
    public void onClick(View v) {
        if (v.getId() == R.id.fullscreen && currentState == CURRENT_STATE_NORMAL) {
            Toast.makeText(getContext(), "Play video first", Toast.LENGTH_LONG).show();
            return;
        }
        super.onClick(v);
    }


    @Override
    public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
        if (fromUser) {
            if (currentState == CURRENT_STATE_NORMAL) {
                Toast.makeText(getContext(), "Play video first", Toast.LENGTH_LONG).show();
                return;
            }
        }
        super.onProgressChanged(seekBar, progress, fromUser);
    }
}
