package com.xplora.xpsettings.Activity;

import android.os.Bundle;
import android.os.RecoverySystem;
import android.util.Log;
import android.widget.Button;
import android.widget.TextView;

import com.xplora.xpsettings.R;

import java.io.IOException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;


public class RestoreActivity extends BaseActivity {
    private static final String TAG = "RestoreActivity";

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

    private void initView() {
        TextView mHintText = findViewById(R.id.hintText);
        Button btnCancel = findViewById(R.id.button1);
        Button btnConfirm = findViewById(R.id.button2);

        mHintText.setText(R.string.restore_factory_settings);
        btnCancel.setText(R.string.button_no);
        btnConfirm.setText(R.string.button_yes);

        btnCancel.setOnClickListener(v -> finish());
        btnConfirm.setOnClickListener(v -> {
            Log.d(TAG, "on confirm click");
            doReset();
        });

    }

    private void doReset() {
        ExecutorService task = Executors.newSingleThreadExecutor();
        task.execute(() -> {
            try {
                RecoverySystem.rebootWipeUserData(RestoreActivity.this);
            } catch (IOException e) {
                e.printStackTrace();
            }
        });
    }
}