package com.example.applock.activity;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import com.example.applock.R;
import com.example.applock.allmanager.AppManager;
import com.example.applock.value.MyAllValues;
import com.example.applock.value.Mytool;
import com.example.applock.value.onActionCallback;

public class SettingActivity extends AppCompatActivity {

    private RelativeLayout reset_password;
    private RelativeLayout app_share;
    private RelativeLayout app_rate;
    private RelativeLayout privacy_policy;
    private TextView version_text;
    private ImageView setting_back;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_setting);
        Mytool.getAllAd();
        gotofindview();
        onMyClick();
    }

    private void gotofindview() {
        setting_back = findViewById(R.id.setting_back);
        reset_password = findViewById(R.id.reset_keycode);
        app_share = findViewById(R.id.share_app);
        app_rate = findViewById(R.id.app_rate);
        privacy_policy = findViewById(R.id.privacy_policy);
        version_text = findViewById(R.id.version_text);
        String appVersions = AppManager.getAppVersions(this);
        if (appVersions == null) {
            version_text.setText("V1.0.3");
        } else {
            String format = String.format(getString(R.string.app_lock_version), appVersions);
            version_text.setText(format);
        }
    }

    private void onMyClick() {
        setting_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        reset_password.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Mytool.showAd(SettingActivity.this, new onActionCallback() {
                    @Override
                    public void onAction() {
                        Intent intent = new Intent(SettingActivity.this, KeyWordActivity.class);
                        intent.putExtra(MyAllValues.PASS_KEY_FROM,2);
                        intent.putExtra(MyAllValues.PASS_KEY_WORD,2);
                        startActivity(intent);
                        finish();
                    }
                });

            }
        });
        app_share.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                intent.setAction(Intent.ACTION_SEND);
                intent.setType("text/*");
                intent.putExtra(Intent.EXTRA_TEXT,getString(R.string.app_path));
                startActivity(Intent.createChooser(intent,"share"));
            }
        });
        app_rate.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String path = getString(R.string.app_path);
                Intent intent = new Intent(Intent.ACTION_VIEW);
                intent.setData(Uri.parse(path));
                startActivity(intent);
            }
        });
        privacy_policy.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(SettingActivity.this,PrivacyActivity.class);
                startActivity(intent);
            }
        });
    }
}