package cc.winboll.studio.midiplayer;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import androidx.appcompat.widget.Toolbar;
import cc.winboll.studio.libappbase.LogUtils;
import cc.winboll.studio.libappbase.LogView;
import com.hjq.toast.ToastUtils;
import java.io.File;

public class MainActivity extends WinBoLLActivity {

    LogView mLogView;

    @Override
    public Activity getActivity() {
        return this;
    }

    @Override
    public String getTag() {
        return TAG;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

		Toolbar toolbar=(Toolbar)findViewById(R.id.toolbar);
		setSupportActionBar(toolbar);

        mLogView = findViewById(R.id.logview);

        ToastUtils.show("onCreate");
		copyAssetsMidiFiles();
    }

	public void onOpenMidiPlayer(View view) {
		App.getWinBoLLActivityManager().startWinBoLLActivity(this, MidiPlayerActivity.class);
	}

    @Override
    protected void onResume() {
        super.onResume();
        mLogView.start();
    }
	
	// 在需要拷贝的地方调用（如Activity的onCreate中）
	private void copyAssetsMidiFiles() {
		// 新建拷贝工具类实例
		final AssetMidiCopier copier = new AssetMidiCopier(this);

		// 开启子线程执行拷贝（避免主线程阻塞）
		new Thread(new Runnable() {
				@Override
				public void run() {
					final boolean success = copier.copyMidiFiles();
					// 拷贝结果可通过Handler通知主线程更新UI
					runOnUiThread(new Runnable() {
							@Override
							public void run() {
								if (success) {
									// 拷贝成功，获取目标目录
									File midiDir = copier.getMidiTargetDir();
									LogUtils.d(TAG, "文件保存路径: " + midiDir.getAbsolutePath());
									// 可在这里加载MIDI文件
								} else {
									// 拷贝失败，提示用户
								}
							}
						});
				}
			}).start();
	}
	
}
