package com.xunao.effectdemo.fragment;

import static android.view.View.GONE;

import android.animation.Animator;
import android.animation.AnimatorInflater;
import android.animation.AnimatorListenerAdapter;
import android.animation.AnimatorSet;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.SimpleItemAnimator;

import com.shuyu.gsyvideoplayer.GSYVideoManager;
import com.xunao.effectdemo.R;
import com.xunao.effectdemo.activity.AudioActivity;
import com.xunao.effectdemo.adapter.AudioAdapter;
import com.xunao.effectdemo.adapter.WordCutAdapter;

import java.io.IOException;
import java.util.Objects;

public class AudioDemandFragment extends Fragment {
    private final String TAG = "AudioDemandFragment";

    private AudioActivity activity = (AudioActivity) getActivity();

    private String[] data;

    private RecyclerView rvAudio;
    private AudioAdapter audioAdapter;

    private MediaPlayer mediaPlayer;
    private String url = "http://www.mobvcasting.com/android/audio/goodmorningandroid.mp3";

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_audio_demand, container, false);

        assert getArguments() != null;
        data = getArguments().getStringArray("data");

        rvAudio = view.findViewById(R.id.rv_audio);
        ((SimpleItemAnimator) Objects.requireNonNull(rvAudio.getItemAnimator())).setSupportsChangeAnimations(false);
        // 设置横向布局
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getContext(), LinearLayoutManager.HORIZONTAL, false){
            @Override
            public boolean canScrollHorizontally() {
                return false;
            }
        };
        rvAudio.setLayoutManager(linearLayoutManager);
        audioAdapter = new AudioAdapter(data, getContext());
        rvAudio.setAdapter(audioAdapter);

        return view;
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        audioAdapter.release();
    }

    // 当前fragment 可见->不可见 或 不可见->可见时 会调用这个方法
    @Override
    public void setUserVisibleHint(boolean isVisibleToUser) {
        super.setUserVisibleHint(isVisibleToUser);
        Log.i(TAG, "setUserVisibleHint: " + isVisibleToUser + "--" + data);

    }
}
