package com.cygnusa.hyperm;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.WindowManager;
import android.webkit.WebSettings;
import android.webkit.WebView;

import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;

import com.github.mikephil.charting.charts.BarChart;
import com.cygnusa.hyperm.util.GlobalData;

public class AboutActivity extends AppCompatActivity {
    private BarChart mChart;
    WebSettings webSettings;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE,
                WindowManager.LayoutParams.FLAG_SECURE);
        setContentView(R.layout.activity_about);
        WebView about = findViewById(R.id.txt_about);
        webSettings = about.getSettings();
        webSettings.setJavaScriptEnabled(true);
        //about.setText(Html.fromHtml(getString(R.string.about_html)));
        String htmlText = " %s ";
        String myData = "<html><body style=\"text-align:justify\"><b>HYPER-M</b> (HYPERM Talent-Development And Recognition Program) is a continuous engagement program for the Sales Staff of HYPER-M Dealers. Enrolment &amp; engagement in HYPER-M Program helps sales staff to get desired knowledge &amp; skills through classroom training, on job training and supported by online learning via <b>HYPER-M APP</b>. Performance in learning is now linked with rewards and dealer sales team can learn and earn reward points, get recognized at all levels from an area to national level.</p></body></Html>";
        about.loadData(String.format(htmlText, myData), "text/html", "utf-8");
        setupWindowAnimations();
        Toolbar toolbar = findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        toolbar.setContentInsetStartWithNavigation(0);
        toolbar.setTitle("");
        getSupportActionBar().setTitle("");
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setDisplayShowHomeEnabled(true);
        @SuppressLint("PrivateResource")
        Drawable backArrow = getResources().getDrawable(R.drawable.abc_ic_ab_back_material);
        backArrow.setColorFilter(getResources().getColor(R.color.btn_bg_color), PorterDuff.Mode.SRC_ATOP);
        getSupportActionBar().setHomeAsUpIndicator(backArrow);
    }

    @Override
    public void onBackPressed() {
        Intent result = new Intent();
        setResult(Activity.RESULT_CANCELED, result);
        finish();
        this.overridePendingTransition(R.anim.animation_f_enter,
                R.anim.animation_f_leave);
    }

    private void setupWindowAnimations() {
        this.overridePendingTransition(R.anim.animation_enter,
                R.anim.animation_leave);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        if (item.getItemId() == android.R.id.home) {
            finish();
            overridePendingTransition(R.anim.animation_f_enter,
                    R.anim.animation_f_leave);
        }
        return super.onOptionsItemSelected(item);
    }

    @Override
    protected void onResume() {
        super.onResume();
        if (GlobalData.canLogout) {
            finish();
        }
    }

}
