package com.lock.arcanvasart.activity;

import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

import com.lock.arcanvasart.R;


public class SettingActivity extends AppCompatActivity {

    private PackageInfo packageInfo;

    private String format;


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

        TextView version = findViewById(R.id.text_version);
        View share = findViewById(R.id.share);
        ImageView back = findViewById(R.id.back);

        back.setOnClickListener(v -> finish());

        try {
            packageInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
            String versionName = packageInfo.versionName;
            format = String.format(getString(R.string.gp), packageInfo.packageName);
            version.setText(versionName);
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
            version.setText("1.0.0");
            format = String.format(getString(R.string.gp), "com.sketch.papertracingart");
        }

        Log.d("----------------", "---------format" + format);

        share.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                shareString(format);

            }
        });

    }


    /**
     * 分享纯文本
     *
     * @param content 内容
     */
    public void shareString(String content) {
        Intent sendIntent = new Intent();
        sendIntent.setAction(Intent.ACTION_SEND);
        sendIntent.putExtra(Intent.EXTRA_TEXT, content);//分享的文本内容
        sendIntent.setType("text/plain");
        startActivity(Intent.createChooser(sendIntent, "Share to"));
    }

}