package com.youra.qlicker.Acitvitys.CGU;
import com.youra.qlicker.Acitvitys.LoginActivity;
import com.youra.qlicker.R;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.TextPaint;
import android.text.method.LinkMovementMethod;
import android.text.style.ClickableSpan;
import android.view.View;
import android.widget.CheckBox;
import android.widget.TextView;

public class CGU1Activity extends AppCompatActivity {

    private CheckBox checkBox ;
    private TextView btn_next , txt_policy ;
    private static boolean isActive = false ;

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

        checkBox = (CheckBox) findViewById(R.id.checkbox_accept);
        btn_next = (TextView) findViewById(R.id.btn_next);
        txt_policy = (TextView) findViewById(R.id.txt_policy);

        checkBox.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if ( checkBox.isChecked() ) {
                    btn_next.setVisibility(View.VISIBLE);
                }
                else {
                    btn_next.setVisibility(View.GONE);

                }
            }
        });

        btn_next.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                Intent intent = new Intent(CGU1Activity.this , LoginActivity.class );
                startActivity( intent );
            }
        });

        ///traitement
        SpannableString ss = new SpannableString(  txt_policy.getText().toString() );

        ClickableSpan clickableSpan1 = new ClickableSpan() {
            @Override
            public void onClick(View widget) {
                Intent intent = new Intent(CGU1Activity.this , CGU2Activity.class );
                startActivity(intent);
            }
            @Override
            public void updateDrawState(TextPaint ds) {
                super.updateDrawState(ds);
                ds.setColor( getResources().getColor(R.color.primary));
                ds.setUnderlineText(false);
            }
        };

        ClickableSpan clickableSpan2 = new ClickableSpan() {
            @Override
            public void onClick(View widget) {
                Intent intent = new Intent(CGU1Activity.this , CGU3Activity.class );
                startActivity(intent);

            }
            @Override
            public void updateDrawState(TextPaint ds) {
                super.updateDrawState(ds);
                ds.setColor( getResources().getColor(R.color.primary));
                ds.setUnderlineText(false);
            }
        };

        ss.setSpan(clickableSpan1, 161, 196, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        ss.setSpan(clickableSpan2, 205, 234, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

        txt_policy.setText(ss);
        txt_policy.setMovementMethod(LinkMovementMethod.getInstance());
    }
}