package com.foxx.androidcast;

/*********************************************************************
 * LicensesActivity.java
 * Created at: Sun 17 May 2026 22:49:49 +0200
 * Updated at: Wed 20 May 2026 15:17:13 +0200 by Anton Afanasyeu <a.afanasieff@gmail.com>
 * Commit: 5d8e82d2e60a21fff3138d2a394ee4e8b4c6dcb8
 * class LicensesActivity
 * Contributors:
 *    - Anton Afanasyeu <a.afanasieff@gmail.com> (2 commits, 50 lines)
 *    - Cursor Agent (project assistant)
 * Digest: SHA256	72a98b360bec090e011d284c520b22c97f8868107bb7fdda60be226835f2d3b0
**********************************************************************/
import android.os.Bundle;
import android.widget.Button;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;
import androidx.core.text.HtmlCompat;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;

/** Full-screen third-party and app license notice. */
public class LicensesActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_licenses);
        setTitle(R.string.licenses_title);

        TextView body = findViewById(R.id.text_licenses);
        body.setText(HtmlCompat.fromHtml(loadLicensesHtml(), HtmlCompat.FROM_HTML_MODE_LEGACY));

        findViewById(R.id.btn_licenses_accept).setOnClickListener(v -> finish());
    }

    private String loadLicensesHtml() {
        try (InputStream in = getAssets().open("licenses/combined.html");
                BufferedReader reader = new BufferedReader(
                        new InputStreamReader(in, StandardCharsets.UTF_8))) {
            StringBuilder sb = new StringBuilder();
            String line;
            while ((line = reader.readLine()) != null) {
                sb.append(line).append('\n');
            }
            return sb.toString();
        } catch (Exception e) {
            return "<p>" + getString(R.string.licenses_load_error) + "</p>";
        }
    }
}
