package com.draw.painting.test.ui;

import android.content.Intent;
import android.content.pm.PackageInfo;
import android.net.Uri;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.fragment.app.Fragment;

import com.draw.painting.test.R;
import com.draw.painting.test.databinding.FragmentSettingBinding;
import com.draw.painting.test.manager.Utils;

public class SettingFragment extends Fragment {
    private static final String ARG_PARAM1 = "param1";
    private static final String ARG_PARAM2 = "param2";


    private String mParam1;
    private String mParam2;
    private FragmentSettingBinding fragmentSettingBinding;

    public SettingFragment() {

    }
    public static SettingFragment newInstance() {
        SettingFragment fragment = new SettingFragment();
        Bundle args = new Bundle();

        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            mParam1 = getArguments().getString(ARG_PARAM1);
            mParam2 = getArguments().getString(ARG_PARAM2);
        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        fragmentSettingBinding = FragmentSettingBinding.inflate(getLayoutInflater());
        onInit();
        return fragmentSettingBinding.getRoot();
    }

    private void onInit(){
        fragmentSettingBinding.rlPrivacy.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(getString(R.string.url_privacy)));
                startActivity(intent);

            }
        });

        String version = "1.0.0";
        PackageInfo info = Utils.getInfo(requireContext());
        if(info!=null){
            version = info.versionName;
        }
        String format = String.format(getString(R.string.version_code), version);
        fragmentSettingBinding.textAppVersion.setText(format);
    }
}