package sk.henrichg.phoneprofilesplus;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.provider.Settings;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.TextPaint;
import android.text.method.LinkMovementMethod;
import android.text.style.BackgroundColorSpan;
import android.text.style.ClickableSpan;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.Fragment;

public class ImportantInfoHelpFragment extends Fragment {

    boolean firstInstallation = false;

    //ExpandableLayout expandableLayoutSystem;
    //ExpandableLayout expandableLayoutProfiles;
    //ExpandableLayout expandableLayoutEvents;

    public ImportantInfoHelpFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        //return inflater.inflate(R.layout.important_info_fragment_important_info, container, false);
        return inflater.inflate(R.layout.fragment_important_info_important_info_expandable, container, false);
    }

    @SuppressLint("SetTextI18n")
    @Override
    public void onViewCreated(@NonNull View view, Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

        final ImportantInfoActivity activity = (ImportantInfoActivity)getActivity();
        if (activity == null)
            return;

        final Context context = activity.getApplicationContext();

        activity.expandableLayoutSystem = view.findViewById(R.id.fragment_important_info_expandable_system);
        activity.expandableLayoutProfiles = view.findViewById(R.id.fragment_important_info_expandable_profiles);
        activity.expandableLayoutEvents = view.findViewById(R.id.fragment_important_info_expandable_events);
        activity.expandableLayoutSystem.setOnClickListener(v -> {
            if (!activity.expandableLayoutSystem.isExpanded()) {
                activity.expandableLayoutProfiles.collapse();
                activity.expandableLayoutEvents.collapse();
            }
            activity.expandableLayoutSystem.toggleLayout();
        });
        activity.expandableLayoutProfiles.setOnClickListener(v -> {
            if (!activity.expandableLayoutProfiles.isExpanded()) {
                activity.expandableLayoutSystem.collapse();
                activity.expandableLayoutEvents.collapse();
            }
            activity.expandableLayoutProfiles.toggleLayout();
        });
        activity.expandableLayoutEvents.setOnClickListener(v -> {
            if (!activity.expandableLayoutEvents.isExpanded()) {
                activity.expandableLayoutSystem.collapse();
                activity.expandableLayoutProfiles.collapse();
            }
            activity.expandableLayoutEvents.toggleLayout();
        });

        int versionCode = 0;

        try {
            PackageInfo pInfo = context.getPackageManager().getPackageInfo(PPApplication.PACKAGE_NAME, 0);
            versionCode = PPApplicationStatic.getVersionCode(pInfo);
        } catch (Exception e) {
            PPApplicationStatic.recordException(e);
        }

        boolean news = false;
        boolean newsLatest = (!firstInstallation) && (versionCode >= PPApplication.PPP_VERSION_CODE_FOR_IMPORTANT_INFO_NEWS);

        int extenderVersion = sk.henrichg.phoneprofilesplus.PPExtenderBroadcastReceiver.isExtenderInstalled(context);
        int ppppsVersion = ActivateProfileHelper.isPPPPutSettingsInstalled(context);

        if (newsLatest) {
            news = PPApplication.SHOW_IMPORTANT_INFO_NEWS; // news is enabled, news must be also in layout
        }

        doOnViewCreated(view, this);

        if ((!firstInstallation) && (extenderVersion != 0) && (extenderVersion < PPApplication.VERSION_CODE_EXTENDER_LATEST)) {
            news = true;
            TextView infoText1 = view.findViewById(R.id.activity_info_notification_accessibility_service_new_version);
            infoText1.setVisibility(View.VISIBLE);
            infoText1 = view.findViewById(R.id.activity_info_notification_accessibility_service_new_version_2);
            infoText1.setText(getString(R.string.important_info_accessibility_service_new_version_2) +  "\u00A0»»");
            infoText1.setVisibility(View.VISIBLE);
            infoText1.setOnClickListener(v -> ExtenderDialogPreferenceFragment.installPPPExtender(getActivity(), null, false));
        }
        else {
            TextView infoText1 = view.findViewById(R.id.activity_info_notification_accessibility_service_new_version);
            infoText1.setVisibility(View.GONE);
            infoText1 = view.findViewById(R.id.activity_info_notification_accessibility_service_new_version_2);
            infoText1.setVisibility(View.GONE);
        }

        if ((!firstInstallation) && (ppppsVersion != 0) && (ppppsVersion < PPApplication.VERSION_CODE_PPPPS_LATEST)) {
            news = true;
            TextView infoText1 = view.findViewById(R.id.activity_info_notification_pppps_new_version);
            infoText1.setVisibility(View.VISIBLE);
            infoText1 = view.findViewById(R.id.activity_info_notification_pppps_new_version_2);
            infoText1.setText(getString(R.string.important_info_pppps_new_version_2) +  "\u00A0»»");
            infoText1.setVisibility(View.VISIBLE);
            infoText1.setOnClickListener(v -> PPPPSDialogPreferenceFragment.installPPPPutSettings(getActivity(), null, false));
        }
        else {
            TextView infoText1 = view.findViewById(R.id.activity_info_notification_pppps_new_version);
            infoText1.setVisibility(View.GONE);
            infoText1 = view.findViewById(R.id.activity_info_notification_pppps_new_version_2);
            infoText1.setVisibility(View.GONE);
        }



        TextView infoTextNews = view.findViewById(R.id.activity_info_notification_news);
        if (!news) {
            infoTextNews.setVisibility(View.GONE);
        } else {
            infoTextNews.setVisibility(View.VISIBLE);
            infoTextNews.setText("*** " + getString(R.string.important_info_news) + " ***");
        }

    }

    @SuppressLint("SetTextI18n")
    static void doOnViewCreated(@NonNull View view, Fragment fragment) {

        final Activity activity = fragment.getActivity();
        if (activity == null)
            return;

        final Context context = activity.getApplicationContext();

        /*        if (news4550) {
            if (Build.VERSION.SDK_INT >= 28) {
                TextView infoText21 = view.findViewById(R.id.activity_info_notification_mobileCellsScanning_location_news);
                if (infoText21 != null) {
                    infoText21.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            boolean ok = false;
                            if (GlobalGUIRoutines.activityActionExists(Settings.ACTION_LOCATION_SOURCE_SETTINGS, context)) {
                                try {
                                    Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
                                    //intent.addCategory(Intent.CATEGORY_DEFAULT);
                                    startActivity(intent);
                                    ok = true;
                                } catch (Exception ignored) {}
                            }
                            if (!ok) {
                                AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(activity);
                                dialogBuilder.setMessage(R.string.setting_screen_not_found_alert);
                                //dialogBuilder.setIcon(android.R.drawable.ic_dialog_alert);
                                dialogBuilder.setPositiveButton(android.R.string.ok, null);
                                AlertDialog dialog = dialogBuilder.create();
    //                            dialog.setOnShowListener(new DialogInterface.OnShowListener() {
    //                                @Override
    //                                public void onShow(DialogInterface dialog) {
    //                                    Button positive = ((AlertDialog)dialog).getButton(DialogInterface.BUTTON_POSITIVE);
    //                                    if (positive != null) positive.setAllCaps(false);
    //                                    Button negative = ((AlertDialog)dialog).getButton(DialogInterface.BUTTON_NEGATIVE);
    //                                    if (negative != null) negative.setAllCaps(false);
    //                                }
    //                            });
                                if (!activity.isFinishing())
                                    dialog.show();
                            }
                        }
                    });
                }
                TextView infoText22 = view.findViewById(R.id.activity_info_notification_mobileCellsScanning_location);
                if (infoText22 != null)
                    infoText22.setVisibility(View.GONE);
                news = true;
            }
            else {
                TextView infoText22 = view.findViewById(R.id.activity_info_notification_mobileCellsScanning_location);
                if (infoText22 != null)
                    infoText22.setVisibility(View.GONE);
                TextView infoText21 = view.findViewById(R.id.activity_info_notification_mobileCellsScanning_location_news);
                if (infoText21 != null)
                    infoText21.setVisibility(View.GONE);
            }
        }
        else {*/
        TextView infoText22 = view.findViewById(R.id.activity_info_notification_mobileCellsScanning_location);
        if (infoText22 != null) {
            if (Build.VERSION.SDK_INT >= 28) {
                infoText22.setText(context.getString(R.string.important_info_profile_mobileCellsScanning_location) +  "\u00A0»»");
                infoText22.setOnClickListener(v -> {
                    boolean ok = false;
                    if (GlobalGUIRoutines.activityActionExists(Settings.ACTION_LOCATION_SOURCE_SETTINGS, context)) {
                        try {
                            Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
                            //intent.addCategory(Intent.CATEGORY_DEFAULT);
                            fragment.startActivity(intent);
                            ok = true;
                        } catch (Exception e) {
                            PPApplicationStatic.recordException(e);
                        }
                    }
                    if (!ok) {
                        PPAlertDialog dialog = new PPAlertDialog(
                                activity.getString(R.string.location_settings_button_tooltip),
                                activity.getString(R.string.setting_screen_not_found_alert),
                                activity.getString(android.R.string.ok),
                                null,
                                null, null,
                                null,
                                null,
                                null,
                                null,
                                null,
                                true, true,
                                false, false,
                                true,
                                activity
                        );

                        if (!activity.isFinishing())
                            dialog.show();
                    }
                });
            } else {
                infoText22.setVisibility(View.GONE);
            }
        }
        //}

        TextView infoText20 = view.findViewById(R.id.activity_info_notification_wifiScanning_location);
        if (infoText20 != null) {
            infoText20.setText(context.getString(R.string.important_info_profile_wifiScanning_location) +  "\u00A0»»");
            infoText20.setOnClickListener(v -> {
                boolean ok = false;
                if (GlobalGUIRoutines.activityActionExists(Settings.ACTION_LOCATION_SOURCE_SETTINGS, context)) {
                    try {
                        Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
                        //intent.addCategory(Intent.CATEGORY_DEFAULT);
                        fragment.startActivity(intent);
                        ok = true;
                    } catch (Exception e) {
                        PPApplicationStatic.recordException(e);
                    }
                }
                if (!ok) {
                    PPAlertDialog dialog = new PPAlertDialog(
                            activity.getString(R.string.location_settings_button_tooltip),
                            activity.getString(R.string.setting_screen_not_found_alert),
                            activity.getString(android.R.string.ok),
                            null,
                            null, null,
                            null,
                            null,
                            null,
                            null,
                            null,
                            true, true,
                            false, false,
                            true,
                            activity
                    );

                    if (!activity.isFinishing())
                        dialog.show();
                }
            });
        }
        infoText22 = view.findViewById(R.id.activity_info_notification_bluetoothScanning_location);
        if (infoText22 != null) {
            infoText22.setText(context.getString(R.string.important_info_profile_bluetoothScanning_location) +  "\u00A0»»");
            infoText22.setOnClickListener(v -> {
                boolean ok = false;
                if (GlobalGUIRoutines.activityActionExists(Settings.ACTION_LOCATION_SOURCE_SETTINGS, context)) {
                    try {
                        Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
                        //intent.addCategory(Intent.CATEGORY_DEFAULT);
                        fragment.startActivity(intent);
                        ok = true;
                    } catch (Exception e) {
                        PPApplicationStatic.recordException(e);
                    }
                }
                if (!ok) {
                    PPAlertDialog dialog = new PPAlertDialog(
                            activity.getString(R.string.location_settings_button_tooltip),
                            activity.getString(R.string.setting_screen_not_found_alert),
                            activity.getString(android.R.string.ok),
                            null,
                            null, null,
                            null,
                            null,
                            null,
                            null,
                            null,
                            true, true,
                            false, false,
                            true,
                            activity
                    );

                    if (!activity.isFinishing())
                        dialog.show();
                }
            });
        }

        TextView infoText10a = view.findViewById(R.id.activity_info_notification_app_standby);
        if (infoText10a != null) {
            infoText10a.setText(context.getString(R.string.important_info_android_doze_mode) +  "\u00A0»»");
            infoText10a.setOnClickListener(v -> {
//                    PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
//                    String packageName = PPApplication.PACKAGE_NAME;
//                    if (pm.isIgnoringBatteryOptimizations(packageName)// ||
//                        //(!GlobalGUIRoutines.activityActionExists(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS, context))
//                    ) {
                boolean ok = false;
                if (GlobalGUIRoutines.activityActionExists(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS, context)) {
                    try {
                        Intent intent = new Intent(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS);
                        //intent.addCategory(Intent.CATEGORY_DEFAULT);
                        fragment.startActivity(intent);
                        ok = true;
                    } catch (Exception e) {
                        PPApplicationStatic.recordException(e);
                    }
                }
                if (!ok) {
                    PPAlertDialog dialog = new PPAlertDialog(
                            activity.getString(R.string.phone_profiles_pref_applicationBatteryOptimization),
                            activity.getString(R.string.setting_screen_not_found_alert),
                            activity.getString(android.R.string.ok),
                            null,
                            null, null,
                            null,
                            null,
                            null,
                            null,
                            null,
                            true, true,
                            false, false,
                            true,
                            activity
                    );

                    if (!activity.isFinishing())
                        dialog.show();
                }
            });
        }

        TextView infoText670 = view.findViewById(R.id.activity_info_notification_do_not_kill_my_app);
        if (infoText670 != null) {
            infoText670.setText(fragment.getString(R.string.important_info_do_not_kill_my_app1) + " " +
                    fragment.getString(R.string.phone_profiles_pref_applicationDoNotKillMyApp_webSiteName) + " " +
                    fragment.getString(R.string.important_info_do_not_kill_my_app2) + "\u00A0»»");
            infoText670.setOnClickListener(v -> PPApplicationStatic.showDoNotKillMyAppDialog(activity));
        }

        TextView infoText40 = view.findViewById(R.id.activity_info_default_profile);
        if (infoText40 != null) {
            infoText40.setText(context.getString(R.string.important_info_default_profile) +  "\u00A0»»");
            infoText40.setOnClickListener(v -> {
                Intent intent = new Intent(context, PhoneProfilesPrefsActivity.class);
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                intent.putExtra(PhoneProfilesPrefsActivity.EXTRA_SCROLL_TO, "profileActivationCategoryRoot");
                //intent.putExtra(PhoneProfilesPrefsActivity.EXTRA_SCROLL_TO_TYPE, "screen");
                fragment.startActivity(intent);
            });
        }

        infoText10a = view.findViewById(R.id.activity_info_notification_application_settings);
        if (infoText10a != null) {
            infoText10a.setText(context.getString(R.string.important_info_android_look_application_settings) +  "\u00A0»»");
            infoText10a.setOnClickListener(v -> {
                Intent intent = new Intent(context, PhoneProfilesPrefsActivity.class);
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                //intent.putExtra(PhoneProfilesPrefsActivity.EXTRA_SCROLL_TO, "profileActivationCategoryRoot");
                //intent.putExtra(PhoneProfilesPrefsActivity.EXTRA_SCROLL_TO_TYPE, "screen");
                fragment.startActivity(intent);
            });
        }

        TextView infoText100 = view.findViewById(R.id.activity_info_profile_activation2);
        if (infoText100 != null) {
            String text = "<ol>" +
                    "<li>" + fragment.getString(R.string.important_info_profile_activation_text2) + "</li>" +
                    "<li>" + fragment.getString(R.string.important_info_profile_activation_text3) + "</li>" +
                    "</ol>";
            infoText100.setText(StringFormatUtils.fromHtml(text, false, false, true, 1, 17, false));
        }
        infoText100 = view.findViewById(R.id.activity_info_profile_activation3);
        if (infoText100 != null) {
            String text =
                    fragment.getString(R.string.important_info_profile_activation_text4) + "\n" +
                            fragment.getString(R.string.important_info_profile_activation_text5) + "\n\n" +
                            fragment.getString(R.string.important_info_profile_activation_text6)
            ;
            infoText100.setText(text);
        }

        infoText100 = view.findViewById(R.id.activity_info_profile_activation9);
        if (infoText100 != null) {
            String text = "<ul>" +
                    "<li>" + fragment.getString(R.string.important_info_profile_activation_text9) + "</li>" +
                    "<li>" + fragment.getString(R.string.important_info_profile_activation_text10) + "</li>" +
                    "<li>" + fragment.getString(R.string.important_info_profile_activation_text11) + "</li>" +
                    "</ul>";
            infoText100.setText(StringFormatUtils.fromHtml(text, true, true, false, 0, 0, false));
        }
        infoText100 = view.findViewById(R.id.activity_info_event_activation9);
        if (infoText100 != null) {
            String text = "<ul>" +
                    "<li>" + fragment.getString(R.string.important_info_profile_activation_text9) + "</li>" +
                    "<li>" + fragment.getString(R.string.important_info_profile_activation_text10) + "</li>" +
                    "<li>" + fragment.getString(R.string.important_info_profile_activation_text11) + "</li>" +
                    "</ul>";
            infoText100.setText(StringFormatUtils.fromHtml(text, true, true, false, 0, 0, false));
        }

        infoText100 = view.findViewById(R.id.activity_info_notification_profile_preference_types);
        if (infoText100 != null) {
            String text = "<ul>" +
                    "<li>" + fragment.getString(R.string.important_info_profile_install_pppps) + "</li>" +
                    "<li>" + fragment.getString(R.string.important_info_profile_grant) + "</li>" +
                    "<li>" + fragment.getString(R.string.important_info_profile_root) + "</li>" +
                    //"<li>" + fragment.getString(R.string.important_info_profile_settings) + "</li>" +
                    "<li>" + fragment.getString(R.string.important_info_profile_interactive) +
                    "</ul>"
                    ;
            infoText100.setText(StringFormatUtils.fromHtml(text, true, false, false, 0, 0, false));
        }

        infoText100 = view.findViewById(R.id.activity_info_notification_profile_grant_1_howTo_3);
        if (infoText100 != null) {
            String text = "<ol>" +
                    "<li>" + fragment.getString(R.string.important_info_profile_grant_1_howTo_3) + "</li>" +
                    "</ol>"
            ;
            infoText100.setText(StringFormatUtils.fromHtml(text, false, false, true, 1, 17, false));
        }
        infoText100 = view.findViewById(R.id.activity_info_notification_profile_grant_1_howTo_4);
        if (infoText100 != null) {
            String text = "<ol>" +
                    "<li>" + fragment.getString(R.string.important_info_profile_grant_1_howTo_4) + "</li>" +
                    "</ol>"
            ;
            infoText100.setText(StringFormatUtils.fromHtml(text, false, false, true, 2, 17, false));
        }

        infoText100 = view.findViewById(R.id.activity_info_notification_profile_grant_1_howTo_6);
        if (infoText100 != null) {
            String text = "<ol>" +
                    "<li>" + fragment.getString(R.string.important_info_profile_grant_1_howTo_6) + "</li>" +
                    "<li>" + fragment.getString(R.string.important_info_profile_grant_1_howTo_7) + "</li>" +
                    "<li>" + fragment.getString(R.string.important_info_profile_grant_1_howTo_8) +
                    "</ol>"
            ;
            infoText100.setText(StringFormatUtils.fromHtml(text, false, false, true, 1, 17, false));
        }
        infoText100 = view.findViewById(R.id.activity_info_notification_profile_grant_1_howTo_10);
        if (infoText100 != null) {
            String text = "<ol>" +
                    "<li>" + fragment.getString(R.string.important_info_profile_grant_1_howTo_10) + "</li>" +
                    "</ol>"
            ;
            infoText100.setText(StringFormatUtils.fromHtml(text, false, false, true, 4, 17, false));
        }
        infoText100 = view.findViewById(R.id.activity_info_notification_profile_grant_1_howTo_20);
        if (infoText100 != null) {
            String text = fragment.getString(R.string.important_info_profile_grant_1_howTo_20_1) + "<br>" +
                    fragment.getString(R.string.important_info_profile_grant_1_howTo_20_2) +
                    "<ul>" +
                    "<li>" + fragment.getString(R.string.important_info_profile_grant_1_howTo_20_3) + "</li>" +
                    "<li>" + fragment.getString(R.string.important_info_profile_grant_1_howTo_20_4) + "</li>" +
                    "<li>" + fragment.getString(R.string.important_info_profile_grant_1_howTo_20_5) +
                    "</ul>" +
                    fragment.getString(R.string.important_info_profile_grant_1_howTo_20_6);
            infoText100.setText(StringFormatUtils.fromHtml(text, true, false, false, 0, 0, false));
        }

        infoText100 = view.findViewById(R.id.activity_info_notification_event_not_started_1);
        if (infoText100 != null) {
            String text = "<ol>" +
                    "<li>" + fragment.getString(R.string.info_notification_event_not_started_2) + "</li>" +
                    "<li>" + fragment.getString(R.string.info_notification_event_not_started_3) + "</li>" +
                    "<li>" + fragment.getString(R.string.info_notification_event_not_started_4) + "</li>" +
                    "<li>" + fragment.getString(R.string.info_notification_event_priority_new) +
                    "</ol>"
            ;
            infoText100.setText(StringFormatUtils.fromHtml(text, false, false, true, 1, 17, false));
        }

        infoText100 = view.findViewById(R.id.activity_info_notification_event_event_sensors_2);
        if (infoText100 != null) {
            String text = "<ol>" +
                    "<li>" + fragment.getString(R.string.important_info_event_event_sensors_waiting) + "</li>" +
                    "<li>" + fragment.getString(R.string.important_info_event_event_sensors_passed) + "</li>" +
                    "<li>" + fragment.getString(R.string.important_info_event_event_sensors_not_pased) + "</li>" +
                    "</ol>"
                    ;
            infoText100.setText(StringFormatUtils.fromHtml(text, false, false, true, 1, 17, false));
        }

        infoText100 = view.findViewById(R.id.activity_info_manage_events_from_tasker_params_1);
        if (infoText100 != null) {
            String text = "<ul>" +
                    "<li>" + fragment.getString(R.string.info_notification_manage_events_from_tasker_restart_events) + "</li>" +
                    "</ul>"
            ;
            infoText100.setText(StringFormatUtils.fromHtml(text, true, true, false, 0, 0, false));
        }
        infoText100 = view.findViewById(R.id.activity_info_manage_events_from_tasker_params_2);
        if (infoText100 != null) {
            String text = "<ul>" +
                    "<li>" + fragment.getString(R.string.info_notification_manage_events_from_tasker_enable_run_for_event) + "</li>" +
                    "</ul>"
            ;
            infoText100.setText(StringFormatUtils.fromHtml(text, true, true, false, 0, 0, false));
        }
        /*
        infoText100 = view.findViewById(R.id.activity_info_manage_events_from_tasker_params_3);
        if (infoText100 != null) {
            String text = "<ul>" +
                    "<li>" + fragment.getString(R.string.info_notification_manage_events_from_tasker_pause_event) + "</li>" +
                    "</ul>"
            ;
            infoText100.setText(StringFormatUtils.fromHtml(text, true, true, false, 0, 0, false));
        }
        */
        infoText100 = view.findViewById(R.id.activity_info_manage_events_from_tasker_params_4);
        if (infoText100 != null) {
            String text = "<ul>" +
                    "<li>" + fragment.getString(R.string.info_notification_manage_events_from_tasker_stop_event) + "</li>" +
                    "</ul>"
            ;
            infoText100.setText(StringFormatUtils.fromHtml(text, true, true, false, 0, 0, false));
        }

        TextView infoText41 = view.findViewById(R.id.activity_info_activate_profile_from_tasker_params);
        if (infoText41 != null) {
            String str = "Send Intent [\n" +  //↵
                    " Action:sk.henrichg.phoneprofilesplus.ACTION_ACTIVATE_PROFILE\n" +
                    " Extra:profile_name:profile name\n" +
                    " Target:Activity\n" +
                    "]";
            Spannable spannable = new SpannableString(str);
            //spannable.setSpan(new BackgroundColorSpan(GlobalGUIRoutines.getThemeCommandBackgroundColor(activity)), 0, str.length(),
            //        Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            spannable.setSpan(new BackgroundColorSpan(ContextCompat.getColor(activity, R.color.activityCommandBackgroundColor)),
                    0, str.length(),
                    Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            infoText41.setText(spannable);
        }

        TextView infoText42 = view.findViewById(R.id.activity_info_manage_events_from_tasker_params_restart_events);
        if (infoText42 != null) {
            String str = "Send Intent [\n" +
                    " Action:sk.henrichg.phoneprofilesplus.ACTION_RESTART_EVENTS\n" +
                    " Target:Activity\n" +
                    "]";
            Spannable spannable = new SpannableString(str);
            //spannable.setSpan(new BackgroundColorSpan(GlobalGUIRoutines.getThemeCommandBackgroundColor(activity)), 0, str.length(),
            //        Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            spannable.setSpan(new BackgroundColorSpan(ContextCompat.getColor(activity, R.color.activityCommandBackgroundColor)),
                    0, str.length(),
                    Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            infoText42.setText(spannable);
        }
        TextView infoText43 = view.findViewById(R.id.activity_info_manage_events_from_tasker_params_enable_run_for_event);
        if (infoText43 != null) {
            String str = "Send Intent [\n" +
                    " Action:sk.henrichg.phoneprofilesplus.ACTION_ENABLE_RUN_FOR_EVENT\n" +
                    " Extra:event_name:event name\n" +
                    " Target:Activity\n" +
                    "]";
            Spannable spannable = new SpannableString(str);
            //spannable.setSpan(new BackgroundColorSpan(GlobalGUIRoutines.getThemeCommandBackgroundColor(activity)), 0, str.length(),
            //        Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            spannable.setSpan(new BackgroundColorSpan(ContextCompat.getColor(activity, R.color.activityCommandBackgroundColor)),
                    0, str.length(),
                    Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            infoText43.setText(spannable);
        }
        /*
        TextView infoText44 = view.findViewById(R.id.activity_info_manage_events_from_tasker_params_pause_event);
        if (infoText44 != null) {
            String str = "Send Intent [\n" +
                    " Action:sk.henrichg.phoneprofilesplus.ACTION_PAUSE_EVENT\n" +
                    " Extra:event_name:event name\n" +
                    " Target:Activity\n" +
                    "]";
            Spannable spannable = new SpannableString(str);
            //spannable.setSpan(new BackgroundColorSpan(GlobalGUIRoutines.getThemeCommandBackgroundColor(activity)), 0, str.length(),
            //        Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            spannable.setSpan(new BackgroundColorSpan(ContextCompat.getColor(activity, R.color.activityCommandBackgroundColor)),
                    0, str.length(),
                    Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            infoText44.setText(spannable);
        }
        */
        TextView infoText45 = view.findViewById(R.id.activity_info_manage_events_from_tasker_params_stop_event);
        if (infoText45 != null) {
            String str = "Send Intent [\n" +
                    " Action:sk.henrichg.phoneprofilesplus.ACTION_STOP_EVENT\n" +
                    " Extra:event_name:event name\n" +
                    " Target:Activity\n" +
                    "]";
            Spannable spannable = new SpannableString(str);
            //spannable.setSpan(new BackgroundColorSpan(GlobalGUIRoutines.getThemeCommandBackgroundColor(activity)), 0, str.length(),
            //        Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            spannable.setSpan(new BackgroundColorSpan(ContextCompat.getColor(activity, R.color.activityCommandBackgroundColor)),
                    0, str.length(),
                    Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            infoText45.setText(spannable);
        }

        TextView infoTextADBDownload = view.findViewById(R.id.activity_info_notification_profile_grant_1_howTo_11);
        if (infoTextADBDownload != null) {
            //str = getString(R.string.important_info_profile_grant_1_howTo_11);
            String str = "https://developer.android.com/studio/releases/platform-tools.html";
            Spannable spannable = new SpannableString(str);
            //spannable.setSpan(new BackgroundColorSpan(GlobalGUIRoutines.getThemeCommandBackgroundColor(activity)), 0, str.length(),
            //        Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            spannable.setSpan(new BackgroundColorSpan(ContextCompat.getColor(activity, R.color.activityCommandBackgroundColor)),
                    0, str.length(),
                    Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            infoTextADBDownload.setText(spannable);
        }

        TextView infoTextGrant1Command = view.findViewById(R.id.activity_info_notification_dialog_info_grant_1_command);
        if (infoTextGrant1Command != null) {
            String str = "adb\u00A0shell\u00A0pm\u00A0grant\u00A0" + PPApplication.PACKAGE_NAME + "\u00A0" +
                    "android.permission.WRITE_SECURE_SETTINGS";
            Spannable spannable = new SpannableString(str);
            //spannable.setSpan(new BackgroundColorSpan(GlobalGUIRoutines.getThemeCommandBackgroundColor(activity)), 0, str.length(),
            //        Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            spannable.setSpan(new BackgroundColorSpan(ContextCompat.getColor(activity, R.color.activityCommandBackgroundColor)),
                    0, str.length(),
                    Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            infoTextGrant1Command.setText(spannable);
        }

        if (view.findViewById(R.id.activity_info_notification_contact) != null) {
            AboutApplicationActivity.emailMe(view.findViewById(R.id.activity_info_notification_contact),
                    fragment.getString(R.string.important_info_contact),
                    "", fragment.getString(R.string.about_application_support_subject),
                    AboutApplicationActivity.getEmailBodyText(/*AboutApplicationActivity.EMAIL_BODY_SUPPORT, */activity),
                    /*true,*/ activity);
        }

        TextView translationTextView = view.findViewById(R.id.activity_info_translations);
        if (translationTextView != null) {
            String str1 = fragment.getString(R.string.about_application_translations);
            String str2 = str1 + "\n" + PPApplication.CROWDIN_URL + "\u00A0»»";
            Spannable spannable = new SpannableString(str2);
            //spannable.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), 0, str1.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            ClickableSpan clickableSpan = new ClickableSpan() {
                @Override
                public void updateDrawState(TextPaint ds) {
                    ds.setColor(ds.linkColor);    // you can use custom color
                    ds.setUnderlineText(false);    // this remove the underline
                }

                @Override
                public void onClick(@NonNull View textView) {
                    String url = PPApplication.CROWDIN_URL;
                    Intent i = new Intent(Intent.ACTION_VIEW);
                    i.setData(Uri.parse(url));
                    try {
                        fragment.startActivity(Intent.createChooser(i, fragment.getString(R.string.web_browser_chooser)));
                    } catch (Exception e) {
                        PPApplicationStatic.recordException(e);
                    }
                }
            };
            spannable.setSpan(clickableSpan, str1.length() + 1, str2.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            //sbt.setSpan(new UnderlineSpan(), str1.length()+1, str2.length(), 0);
            translationTextView.setText(spannable);
            translationTextView.setMovementMethod(LinkMovementMethod.getInstance());
            /*AboutApplicationActivity.emailMe((TextView) view.findViewById(R.id.activity_info_translations),
                getString(R.string.important_info_translations),
                getString(R.string.about_application_translations2),
                getString(R.string.about_application_translations_subject),
                AboutApplicationActivity.getEmailBodyText(AboutApplicationActivity.EMAIL_BODY_TRANSLATIONS, activity),
                true, activity);*/
        }

        TextView helpForG1TextView = view.findViewById(R.id.activity_info_notification_profile_grant_1_howTo_0);
        if (helpForG1TextView != null) {
            String str1 = fragment.getString(R.string.important_info_profile_grant_1_howTo_0) + " " +
                    fragment.getString(R.string.important_info_profile_grant_1_howTo_0_1) + ":";
            String str2;
            if (DebugVersion.enabled)
                str2 = str1 + "\n" + PPApplication.HELP_HOW_TO_GRANT_G1_URL_DEVEL + "\u00A0»»";
            else
                str2 = str1 + "\n" + PPApplication.HELP_HOW_TO_GRANT_G1_URL + "\u00A0»»";
            Spannable spannable = new SpannableString(str2);
            //spannable.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), 0, str1.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            ClickableSpan clickableSpan = new ClickableSpan() {
                @Override
                public void updateDrawState(TextPaint ds) {
                    ds.setColor(ds.linkColor);    // you can use custom color
                    ds.setUnderlineText(false);    // this remove the underline
                }

                @Override
                public void onClick(@NonNull View textView) {
                    String url;
                    if (DebugVersion.enabled)
                        url = PPApplication.HELP_HOW_TO_GRANT_G1_URL_DEVEL;
                    else
                        url = PPApplication.HELP_HOW_TO_GRANT_G1_URL;
                    Intent i = new Intent(Intent.ACTION_VIEW);
                    i.setData(Uri.parse(url));
                    try {
                        fragment.startActivity(Intent.createChooser(i, fragment.getString(R.string.web_browser_chooser)));
                    } catch (Exception e) {
                        PPApplicationStatic.recordException(e);
                    }
                }
            };
            spannable.setSpan(clickableSpan, str1.length() + 1, str2.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            //sbt.setSpan(new UnderlineSpan(), str1.length()+1, str2.length(), 0);
            helpForG1TextView.setText(spannable);
            helpForG1TextView.setMovementMethod(LinkMovementMethod.getInstance());
            /*AboutApplicationActivity.emailMe((TextView) view.findViewById(R.id.activity_info_translations),
                getString(R.string.important_info_translations),
                getString(R.string.about_application_translations2),
                getString(R.string.about_application_translations_subject),
                AboutApplicationActivity.getEmailBodyText(AboutApplicationActivity.EMAIL_BODY_TRANSLATIONS, activity),
                true, activity);*/
        }

/*
        TextView configureNotificationInfoText = view.findViewById(R.id.important_info_notification_settings_configure);
        if (configureNotificationInfoText != null) {
            configureNotificationInfoText.setText(context.getString(R.string.important_info_notification_settings_configure) +  " »»");
            configureNotificationInfoText.setOnClickListener(v -> {

                synchronized (PPApplication.applicationPreferencesMutex) {
                    SharedPreferences.Editor editor = ApplicationPreferences.getEditor(context);
                    editor.putString(ApplicationPreferences.PREF_NOTIFICATION_NOTIFICATION_STYLE, "0");
                    ApplicationPreferences.notificationNotificationStyle = "0";
                    editor.putBoolean(ApplicationPreferences.PREF_NOTIFICATION_USE_DECORATION, false);
                    ApplicationPreferences.notificationUseDecoration = false;
                    editor.putBoolean(ApplicationPreferences.PREF_NOTIFICATION_SHOW_PROFILE_ICON, true);
                    ApplicationPreferences.notificationShowProfileIcon = true;
                    editor.putBoolean(ApplicationPreferences.PREF_NOTIFICATION_PREF_INDICATOR, true);
                    ApplicationPreferences.notificationPrefIndicator = true;
                    editor.putString(ApplicationPreferences.PREF_NOTIFICATION_LAYOUT_TYPE, "0");
                    ApplicationPreferences.notificationLayoutType = "0";
                    editor.apply();
                }

//
//                if (PhoneProfilesService.getInstance() != null) {
//                    synchronized (PPApplication.applicationPreferencesMutex) {
//                        PPApplication.doNotShowProfileNotification = true;
//                    }
//                    PhoneProfilesService.getInstance().clearProfileNotification();
//                }
//
//                Handler handler = new Handler(activity.getMainLooper());
//                handler.postDelayed(() -> {
////                PPApplicationStatic.logE("[IN_THREAD_HANDLER] PhoneProfilesPrefsActivity.onStop", "PhoneProfilesService.getInstance()="+PhoneProfilesService.getInstance());
//                    if (PhoneProfilesService.getInstance() != null) {
//                        synchronized (PPApplication.applicationPreferencesMutex) {
//                            PPApplication.doNotShowProfileNotification = false;
//                        }
//                        // forServiceStart must be true because of call of clearProfileNotification()
//                        PhoneProfilesService.getInstance().showProfileNotification(false, true, true);
//                    }
//                }, 1000);
                //PhoneProfilesService.getInstance().showProfileNotification(false, true, true);
//                PPApplicationStatic.logE("[PPP_NOTIFICATION] ImportantInfoHelpFragment.doOnViewCreated", "call of PPAppNotification.forceDrawNotification");
                PPAppNotification.forceDraweNotification(context.getApplicationContext());

                PPApplication.showToast(context,
                        context.getString(R.string.important_info_notification_settings_toast),
                        Toast.LENGTH_SHORT);
            });
        }
*/
        TextView helpForPPPPSTextView = view.findViewById(R.id.activity_info_notification_profile_pppps_howTo_2);
        if (helpForPPPPSTextView != null) {
            String str1 = fragment.getString(R.string.important_info_profile_pppps_howTo_2) +  "\u00A0»»";
            Spannable spannable = new SpannableString(str1);
            //spannable.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), 0, str1.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            ClickableSpan clickableSpan = new ClickableSpan() {
                @Override
                public void updateDrawState(TextPaint ds) {
                    ds.setColor(ds.linkColor);    // you can use custom color
                    ds.setUnderlineText(false);    // this remove the underline
                }

                @Override
                public void onClick(@NonNull View textView) {
                    PPPPSDialogPreferenceFragment.installPPPPutSettings(activity, null, false);
                }
            };
            spannable.setSpan(clickableSpan, 0, str1.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            //sbt.setSpan(new UnderlineSpan(), str1.length()+1, str2.length(), 0);
            helpForPPPPSTextView.setText(spannable);
            helpForPPPPSTextView.setMovementMethod(LinkMovementMethod.getInstance());
            /*AboutApplicationActivity.emailMe((TextView) view.findViewById(R.id.activity_info_translations),
                getString(R.string.important_info_translations),
                getString(R.string.about_application_translations2),
                getString(R.string.about_application_translations_subject),
                AboutApplicationActivity.getEmailBodyText(AboutApplicationActivity.EMAIL_BODY_TRANSLATIONS, activity),
                true, activity);*/
        }

    }
/*
    static private void installExtenderFromGitHub(Activity activity, boolean finishActivity) {
        if (activity == null) {
            return;
        }

        AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(activity);
        dialogBuilder.setTitle(R.string.install_extender_dialog_title);

        LayoutInflater inflater = activity.getLayoutInflater();
        View layout = inflater.inflate(R.layout.dialog_install_ppp_pppe_from_github, null);
        dialogBuilder.setView(layout);

        TextView text = layout.findViewById(R.id.install_ppp_pppe_from_github_dialog_info_text);

        String dialogText = "";
        int extenderVersion = PPExtenderBroadcastReceiver.isExtenderInstalled(activity.getApplicationContext());
        if (extenderVersion != 0) {
            String extenderVersionName = PPExtenderBroadcastReceiver.getExtenderVersionName(activity.getApplicationContext());
            dialogText = dialogText + activity.getString(R.string.install_extender_installed_version) + " " + extenderVersionName + " (" + extenderVersion + ")\n";
        }
        dialogText = dialogText + activity.getString(R.string.install_extender_required_version) +
                " " + PPApplication.VERSION_NAME_EXTENDER_LATEST + " (" + PPApplication.VERSION_CODE_EXTENDER_LATEST + ")\n\n";
        dialogText = dialogText + activity.getString(R.string.install_extender_text1) + " \"" + activity.getString(R.string.alert_button_install) + "\"\n";
        dialogText = dialogText + activity.getString(R.string.install_extender_text2) + "\n";
        dialogText = dialogText + activity.getString(R.string.install_extender_text3);


        text.setText(dialogText);

        dialogBuilder.setPositiveButton(R.string.alert_button_install, (dialog, which) -> {
            //String url = PPApplication.GITHUB_PPPE_RELEASES_URL;
            //String url = PPApplication.GITHUB_PPPE_DOWNLOAD_URL_1 + PPApplication.VERSION_NAME_EXTENDER_LATEST + PPApplication.GITHUB_PPPE_DOWNLOAD_URL_2;
            String url = PPApplication.GITHUB_PPPE_DOWNLOAD_URL;

            Intent i = new Intent(Intent.ACTION_VIEW);
            i.setData(Uri.parse(url));
            try {
                activity.startActivity(Intent.createChooser(i, activity.getString(R.string.web_browser_chooser)));
                if (finishActivity)
                    activity.finish();
            } catch (Exception e) {
                PPApplicationStatic.recordException(e);
            }
        });
        dialogBuilder.setNegativeButton(android.R.string.cancel, (dialog, which) -> {
            if (finishActivity)
                activity.finish();
        });
        dialogBuilder.setCancelable(false);

        final AlertDialog dialog = dialogBuilder.create();

        text = layout.findViewById(R.id.install_ppp_pppe_from_github_dialog_github_releases);
        CharSequence str1 = activity.getString(R.string.install_extender_github_releases);
        CharSequence str2 = str1 + " " + PPApplication.GITHUB_PPPE_RELEASES_URL + "\u00A0»»";
        Spannable sbt = new SpannableString(str2);
        sbt.setSpan(new StyleSpan(android.graphics.Typeface.NORMAL), 0, str1.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        ClickableSpan clickableSpan = new ClickableSpan() {
            @Override
            public void updateDrawState(TextPaint ds) {
                ds.setColor(ds.linkColor);    // you can use custom color
                ds.setUnderlineText(false);    // this remove the underline
            }

            @Override
            public void onClick(@NonNull View textView) {
                String url = PPApplication.GITHUB_PPPE_RELEASES_URL;
                Intent i = new Intent(Intent.ACTION_VIEW);
                i.setData(Uri.parse(url));
                try {
                    dialog.cancel();
                    //if (activity != null)
                    if (finishActivity)
                        activity.finish();
                    activity.startActivity(Intent.createChooser(i, activity.getString(R.string.web_browser_chooser)));
                } catch (Exception e) {
                    PPApplicationStatic.recordException(e);
                }
            }
        };
        sbt.setSpan(clickableSpan, str1.length()+1, str2.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        //sbt.setSpan(new UnderlineSpan(), str1.length()+1, str2.length(), 0);
        text.setText(sbt);
        text.setMovementMethod(LinkMovementMethod.getInstance());


//        dialog.setOnShowListener(new DialogInterface.OnShowListener() {
//            @Override
//            public void onShow(DialogInterface dialog) {
//                Button positive = ((AlertDialog)dialog).getButton(DialogInterface.BUTTON_POSITIVE);
//                if (positive != null) positive.setAllCaps(false);
//                Button negative = ((AlertDialog)dialog).getButton(DialogInterface.BUTTON_NEGATIVE);
//                if (negative != null) negative.setAllCaps(false);
//            }
//        });

        if (!activity.isFinishing())
            dialog.show();
    }

    static void installExtender(Activity activity, boolean finishActivity) {
        if (activity == null) {
            return;
        }

        PackageManager packageManager = activity.getPackageManager();
        Intent _intent = packageManager.getLaunchIntentForPackage("com.sec.android.app.samsungapps");
        boolean galaxyStoreInstalled = (_intent != null);

        if (PPApplication.deviceIsSamsung && PPApplication.romIsGalaxy && galaxyStoreInstalled) {
            AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(activity);
            dialogBuilder.setTitle(R.string.install_extender_dialog_title);

            LayoutInflater inflater = activity.getLayoutInflater();
            View layout = inflater.inflate(R.layout.dialog_install_pppe_from_store, null);
            dialogBuilder.setView(layout);

            TextView text = layout.findViewById(R.id.install_pppe_from_store_dialog_info_text);

            String dialogText = "";

            int extenderVersion = PPExtenderBroadcastReceiver.isExtenderInstalled(activity.getApplicationContext());
            if (extenderVersion != 0) {
                String extenderVersionName = PPExtenderBroadcastReceiver.getExtenderVersionName(activity.getApplicationContext());
                dialogText = dialogText + activity.getString(R.string.install_extender_installed_version) + " " + extenderVersionName + " (" + extenderVersion + ")\n";
            }
            dialogText = dialogText + activity.getString(R.string.install_extender_required_version) +
                    " " + PPApplication.VERSION_NAME_EXTENDER_LATEST + " (" + PPApplication.VERSION_CODE_EXTENDER_LATEST + ")\n\n";
            dialogText = dialogText + activity.getString(R.string.install_extender_text1) + " \"" + activity.getString(R.string.alert_button_install) + "\".";

            text.setText(dialogText);

            dialogBuilder.setPositiveButton(R.string.alert_button_install, (dialog, which) -> {
                Intent intent = new Intent(Intent.ACTION_VIEW,
                        Uri.parse("samsungapps://ProductDetail/sk.henrichg.phoneprofilesplusextender"));
                try {
                    activity.startActivity(intent);
                    if (finishActivity)
                        activity.finish();
                } catch (Exception e) {
                    PPApplicationStatic.recordException(e);
                }
            });
            dialogBuilder.setNegativeButton(android.R.string.cancel, (dialog, which) -> {
                if (finishActivity)
                    activity.finish();
            });
            dialogBuilder.setCancelable(false);

            Button button = layout.findViewById(R.id.install_pppe_from_store_dialog_installFromGitHub);

            final AlertDialog dialog = dialogBuilder.create();

            button.setText(activity.getString(R.string.alert_button_install_extender_from_github));
            button.setOnClickListener(v -> {
                dialog.cancel();
                installExtenderFromGitHub(activity, finishActivity);
            });

//        dialog.setOnShowListener(new DialogInterface.OnShowListener() {
//            @Override
//            public void onShow(DialogInterface dialog) {
//                Button positive = ((AlertDialog)dialog).getButton(DialogInterface.BUTTON_POSITIVE);
//                if (positive != null) positive.setAllCaps(false);
//                Button negative = ((AlertDialog)dialog).getButton(DialogInterface.BUTTON_NEGATIVE);
//                if (negative != null) negative.setAllCaps(false);
//            }
//        });

            if (!activity.isFinishing())
                dialog.show();
        }
        else
            installExtenderFromGitHub(activity, finishActivity);
    }

    static void installPPPPutSettings(Activity activity,
                                      boolean finishActivity) {
        if (activity == null) {
            return;
        }

        AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(activity);
        dialogBuilder.setTitle(R.string.install_pppps_dialog_title);

        LayoutInflater inflater = activity.getLayoutInflater();
        View layout = inflater.inflate(R.layout.dialog_install_pppps, null);
        dialogBuilder.setView(layout);

        TextView text = layout.findViewById(R.id.install_pppps_from_github_dialog_info_text);

        String dialogText = "";

        dialogText = dialogText + activity.getString(R.string.install_pppps_text1) + " \"" + activity.getString(R.string.alert_button_install) + "\"\n";
        dialogText = dialogText + activity.getString(R.string.install_pppps_text2) + "\n";
        dialogText = dialogText + activity.getString(R.string.install_pppps_text3) + "\n\n";
        dialogText = dialogText + activity.getString(R.string.install_pppps_text4);
        text.setText(dialogText);

        dialogBuilder.setPositiveButton(R.string.alert_button_install, (dialog, which) -> {
            String url = PPApplication.GITHUB_PPPPS_DOWNLOAD_URL;

            Intent i = new Intent(Intent.ACTION_VIEW);
            i.setData(Uri.parse(url));
            try {
                activity.startActivity(Intent.createChooser(i, activity.getString(R.string.web_browser_chooser)));
                if (finishActivity)
                    activity.finish();
            } catch (Exception e) {
                PPApplicationStatic.recordException(e);
            }
        });
        dialogBuilder.setNegativeButton(android.R.string.cancel, (dialog, which) -> {
            if (finishActivity)
                activity.finish();
        });
        dialogBuilder.setCancelable(false);

        final AlertDialog dialog = dialogBuilder.create();

        text = layout.findViewById(R.id.install_pppps_from_github_dialog_github_releases);
        CharSequence str1 = activity.getString(R.string.install_extender_github_releases);
        CharSequence str2 = str1 + " " + PPApplication.GITHUB_PPPPS_RELEASES_URL + "\u00A0»»";
        Spannable sbt = new SpannableString(str2);
        sbt.setSpan(new StyleSpan(android.graphics.Typeface.NORMAL), 0, str1.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        ClickableSpan clickableSpan = new ClickableSpan() {
            @Override
            public void updateDrawState(TextPaint ds) {
                ds.setColor(ds.linkColor);    // you can use custom color
                ds.setUnderlineText(false);    // this remove the underline
            }

            @Override
            public void onClick(@NonNull View textView) {
                String url = PPApplication.GITHUB_PPPPS_RELEASES_URL;
                Intent i = new Intent(Intent.ACTION_VIEW);
                i.setData(Uri.parse(url));
                try {
                    dialog.cancel();
                    //if (activity != null)
                    if (finishActivity)
                        activity.finish();
                    activity.startActivity(Intent.createChooser(i, activity.getString(R.string.web_browser_chooser)));
                } catch (Exception e) {
                    PPApplicationStatic.recordException(e);
                }
            }
        };
        sbt.setSpan(clickableSpan, str1.length()+1, str2.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        //sbt.setSpan(new UnderlineSpan(), str1.length()+1, str2.length(), 0);
        text.setText(sbt);
        text.setMovementMethod(LinkMovementMethod.getInstance());


//        dialog.setOnShowListener(new DialogInterface.OnShowListener() {
//            @Override
//            public void onShow(DialogInterface dialog) {
//                Button positive = ((AlertDialog)dialog).getButton(DialogInterface.BUTTON_POSITIVE);
//                if (positive != null) positive.setAllCaps(false);
//                Button negative = ((AlertDialog)dialog).getButton(DialogInterface.BUTTON_NEGATIVE);
//                if (negative != null) negative.setAllCaps(false);
//            }
//        });

        if (!activity.isFinishing())
            dialog.show();

    }
*/
}
