package com.xplora.xpsettings.Activity;

import android.annotation.SuppressLint;
import android.graphics.Typeface;
import android.os.Bundle;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.style.AbsoluteSizeSpan;
import android.text.style.ForegroundColorSpan;
import android.text.style.StyleSpan;
import android.text.style.UnderlineSpan;
import android.view.View;
import android.widget.Space;
import android.widget.TextView;

import com.xplora.xpsettings.R;
import com.xplora.xpsettings.Utils.ResUtils;

public class PrivacyPolicyActivity extends BaseActionActivity{
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_privacy_policy);
        initView();
    }

    @SuppressLint({"SetTextI18n", "ResourceAsColor"})
    private void initView() {
        String email = "support@xplora.com";

        for (int i = 0; i <= 26; i++) {
            int layoutId = ResUtils.getWidgetId("cpp_layout_", i);
            View view = findViewById(layoutId);

            TextView itemTitle = view.findViewById(R.id.cpp_title);
            TextView itemContent = view.findViewById(R.id.cpp_content);

            int titleId = ResUtils.getStringId("cpp_title_", i);
            int contentId = ResUtils.getStringId("cpp_content_", i);

            String title = titleId > 0 ? getString(titleId) : "";
            String content = contentId > 0 ? getString(contentId) : "";
            String joinText = title + content;

            if ((i >= 2 && i <= 10) || (i >= 12 && i <= 19) || (i >= 22 && i <= 25) || i == 26) {
                int titleIndex = joinText.indexOf(title);
                int emailIndex = joinText.indexOf(email);

                Spannable textSpan = new SpannableStringBuilder(joinText);
                if (titleIndex >= 0) {
                    textSpan.setSpan(new StyleSpan(Typeface.BOLD), titleIndex, titleIndex + title.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
                }
                if (emailIndex >= 0) {
                    textSpan.setSpan(new UnderlineSpan(), emailIndex, emailIndex + email.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
                }
                itemContent.setText(textSpan);
            } else {
                itemTitle.setText(title);
                itemContent.setText(content);
            }
        }
    }
}
