package com.app.rewardapp.ui.activity;

import static com.app.rewardapp.util.Constant_Api.App;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.text.Html;
import android.view.View;
import androidx.appcompat.app.AppCompatActivity;
import com.app.rewardapp.R;
import com.app.rewardapp.databinding.ActivityAboutusBinding;
import com.app.rewardapp.adsManager.AdManager;

public class AboutusActivity extends AppCompatActivity {
    ActivityAboutusBinding binding;
    Activity activity;
    AdManager adManager;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding=ActivityAboutusBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());
        activity=AboutusActivity.this;

        adManager=new AdManager(activity);
        adManager.loadBannerAd(null);
        binding.toolbar.setText(getString(R.string.about_us));

        binding.desc.setText(Html.fromHtml(App.getData().get(0).getAppDescription()));
        binding.company.setText(App.getData().get(0).getAppAuthor());
        binding.website.setText(App.getData().get(0).getAppWebsite());


        binding.telegram.setOnClickListener(v -> {
            Telegram();
        });


        binding.email.setOnClickListener(v -> {
            emailsend();
        });

        binding.facebook.setOnClickListener(v -> {
            Fb();
        });

        binding.back.setOnClickListener(v->{
           onBackPressed();
        });

    }

    public void Fb() {
        if (App.getData().get(0).getFb() != null) {
            startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(App.getData().get(0).getFb())));
        }
    }

    public void Telegram() {
        try {
            String url = App.getData().get(0).getTelegram();
            if (!url.startsWith("http://") && !url.startsWith("https://")) {
                url = "http://" + url;
            }
            Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
            startActivity(browserIntent);
        } catch (Exception e) {

           }
    }

    public void emailsend() {
        try {
            Intent emailIntent = new Intent(Intent.ACTION_VIEW);
            emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[]{App.getData().get(0).getAppEmail()});
            emailIntent.setData(Uri.parse("mailto:"));
            startActivity(emailIntent);
        } catch (android.content.ActivityNotFoundException ex) {

        }
    }


    @Override
    public void onBackPressed() {
        super.onBackPressed();
    }

    public void back(View view) {
        onBackPressed();
    }


}
