package com.draw.painting.line.ui;

import android.content.pm.PackageInfo;
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.line.R;
import com.draw.painting.line.databinding.FragmentSettingsBinding;
import com.draw.painting.line.manager.AppHelper;

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


    private String mParam1;
    private String mParam2;
    private FragmentSettingsBinding fragmentSettingBinding;

    public SettingsFragment() {

    }
    public static SettingsFragment newInstance() {
        SettingsFragment fragment = new SettingsFragment();
        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 = FragmentSettingsBinding.inflate(getLayoutInflater());
        onInit();
        return fragmentSettingBinding.getRoot();
    }

    private void onInit(){
        String version = "1.0";
        PackageInfo info = AppHelper.getInfo(requireContext());
        if(info!=null){
            version = info.versionName;
        }
        String format = String.format(getString(R.string.version_code), version);
        fragmentSettingBinding.textAppVersion.setText(format);
        
        // 设置Rate Us点击事件
        fragmentSettingBinding.rlRateUs.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showRateUsDialog();
            }
        });
    }
    
    private void showRateUsDialog() {
        RatingDialog dialog = new RatingDialog(requireContext());
        dialog.show();
    }
}

