package com.atmob.voiceai.module.cloning;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;

import androidx.annotation.Nullable;

import com.atmob.app.lib.base.BaseActivity;
import com.atmob.voiceai.data.repositories.CloneRepository;
import com.atmob.voiceai.databinding.ActivityVoiceCloneBinding;
import com.tencent.qgame.animplayer.util.ScaleType;

import dagger.hilt.android.AndroidEntryPoint;

@AndroidEntryPoint
public class VoiceCloningActivity extends BaseActivity<ActivityVoiceCloneBinding> {

    private VoiceCloningViewModel voiceCloningViewModel;

    public static void start(Context context) {
        Intent intent = new Intent(context, VoiceCloningActivity.class);
        if (!(context instanceof Activity)) {
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        }
        context.startActivity(intent);
    }


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initView();
        initObserver();
        startAnim();
    }

    private void initView() {

    }

    private void initObserver() {
        voiceCloningViewModel.getFinishEvent().observe(this, o -> finish());
    }

    private void startAnim() {
        binding.animView.setScaleType(ScaleType.FIT_XY);
        binding.animView.setLoop(Integer.MAX_VALUE);
        binding.animView.startPlay(this.getAssets(), "anim/voice_ai_clone_loading.mp4");
    }


    @Override
    protected void onDestroy() {
        super.onDestroy();
        stopAnim();
    }

    private void stopAnim() {
        binding.animView.stopPlay();
    }

    @Override
    protected void initViewModel() {
        super.initViewModel();
        voiceCloningViewModel = getViewModelProvider().get(VoiceCloningViewModel.class);
        binding.setVoiceViewModel(voiceCloningViewModel);
    }


    @Override
    protected boolean shouldImmersion() {
        return true;
    }


    @Override
    public void onBackPressed() {

    }
}
