package com.app.paintingstool.myact;

import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Bundle;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;

import com.app.paintingstool.databinding.ActivitySettingBinding;

public class SettingActivity extends AppCompatActivity {
    private ActivitySettingBinding binding;

    private  String my_package_name;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        binding = ActivitySettingBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());
        my_package_name = this.getPackageName();
        binding.back.setOnClickListener(v -> {
            finish();
        });
        String versionName = getVersionName();
        binding.tvVersion.setText(versionName);
        chipLinsner();

    }
    private void chipLinsner() {
        binding.chip.setOnClickListener(v -> {
            Intent intent = new Intent(SettingActivity.this, PrivacyPolicyActivity.class);
            startActivity(intent);
        });
        binding.chipPv3.setOnClickListener(v -> {
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setData(Uri.parse("https://play.google.com/store/apps/details?id=" + my_package_name));
            startActivity(intent);
        });
        binding.chipShare.setOnClickListener(view -> {
            Intent sendIntent = new Intent();
            sendIntent.setAction(Intent.ACTION_SEND);
            sendIntent.putExtra(Intent.EXTRA_TEXT, "https://play.google.com/store/apps/details?id=" + my_package_name);
            sendIntent.setType("text/plain");
            startActivity(sendIntent);
        });
    }

    private String getVersionName() {
        try {
            PackageInfo packageInfo = getPackageManager().getPackageInfo(getPackageName(), 0);return packageInfo.versionName;
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
            return "unknown"; // 或其他默认值
        }
    }
}