package nerd.tuxmobil.fahrplan.congress.about;

import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.support.v4.content.ContextCompat;
import android.text.Html;
import android.text.TextUtils;
import android.text.method.LinkMovementMethod;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import nerd.tuxmobil.fahrplan.congress.BuildConfig;
import nerd.tuxmobil.fahrplan.congress.MyApp;
import nerd.tuxmobil.fahrplan.congress.R;

public class AboutDialog extends DialogFragment {

    @Override
    public View onCreateView(LayoutInflater inflater,
                             ViewGroup container,
                             Bundle savedInstanceState) {
        return inflater.inflate(R.layout.about_dialog, container, false);
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setStyle(DialogFragment.STYLE_NO_TITLE, R.style.Dialog);
    }

    @Override
    public void onViewCreated(View view, Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        TextView text = view.findViewById(R.id.eventVersion);
        text.setText(getString(R.string.fahrplan) + " " + MyApp.version);
        text = view.findViewById(R.id.eventTitle);
        text.setText(MyApp.title);
        text = view.findViewById(R.id.eventSubtitle);
        String subtitle = MyApp.subtitle;
        if (TextUtils.isEmpty(subtitle)) {
            subtitle = getString(R.string.app_hardcoded_subtitle);
        }
        text.setText(subtitle);
        text = view.findViewById(R.id.appVersion);
        String appVersionText = getString(R.string.appVersion, BuildConfig.VERSION_NAME);
        text.setText(appVersionText);

        Context context = getContext();

        View appDisclaimer = view.findViewById(R.id.app_disclaimer);
        //noinspection ConstantConditions
        appDisclaimer.setVisibility(BuildConfig.SHOW_APP_DISCLAIMER ? View.VISIBLE : View.GONE);

        TextView logo_copyright = view.findViewById(R.id.copyright_logo);
        logo_copyright.setText(Html.fromHtml(getString(R.string.copyright_logo)));
        logo_copyright.setLinkTextColor(ContextCompat.getColor(context, R.color.text_link_color_dark));
        logo_copyright.setMovementMethod(LinkMovementMethod.getInstance());

        TextView conferenceUrl = view.findViewById(R.id.conference_url);
        conferenceUrl.setText(Html.fromHtml(getString(R.string.conference_url)));
        conferenceUrl.setMovementMethod(LinkMovementMethod.getInstance());
        conferenceUrl.setLinkTextColor(ContextCompat.getColor(context, R.color.text_link_color_dark));

        TextView sourceCode = view.findViewById(R.id.source_code);
        sourceCode.setText(Html.fromHtml(getString(R.string.source_code)));
        sourceCode.setMovementMethod(LinkMovementMethod.getInstance());
        sourceCode.setLinkTextColor(ContextCompat.getColor(context, R.color.text_link_color_dark));

        TextView issues = view.findViewById(R.id.issues);
        issues.setText(Html.fromHtml(getString(R.string.issues)));
        issues.setMovementMethod(LinkMovementMethod.getInstance());
        issues.setLinkTextColor(ContextCompat.getColor(context, R.color.text_link_color_dark));

        TextView googlePlayStore = view.findViewById(R.id.google_play_store);
        googlePlayStore.setText(Html.fromHtml(getString(R.string.google_play_store)));
        googlePlayStore.setMovementMethod(LinkMovementMethod.getInstance());
        googlePlayStore.setLinkTextColor(ContextCompat.getColor(context, R.color.text_link_color_dark));

        // Build information

        TextView buildTimeTextView = view.findViewById(R.id.build_time);
        String buildTimeText = getString(R.string.build_info_time, BuildConfig.BUILD_TIME);
        buildTimeTextView.setText(buildTimeText);

        TextView versionCodeTextView = view.findViewById(R.id.build_version_code);
        String versionCodeText = getString(R.string.build_info_version_code, "" + BuildConfig.VERSION_CODE);
        versionCodeTextView.setText(versionCodeText);

        TextView buildHashTextView = view.findViewById(R.id.build_hash);
        String buildHashText = getString(R.string.build_info_hash, BuildConfig.GIT_SHA);
        buildHashTextView.setText(buildHashText);
    }
}

@@ -298,16 +298,59 @@
 Method;%0A
+import android.text.method.MovementMethod;%0A
 import a
@@ -2135,24 +2135,190 @@
 iew.GONE);%0A%0A
+        int linkTextColor = ContextCompat.getColor(context, R.color.text_link_color_dark);%0A        MovementMethod movementMethod = LinkMovementMethod.getInstance();%0A%0A
         Text
@@ -2506,69 +2506,21 @@
 lor(
-ContextCompat.getColor(context, R.color.text_link_color_dark)
+linkTextColor
 );%0A 
@@ -2551,37 +2551,33 @@
 tMovementMethod(
-LinkM
+m
 ovementMethod.ge
@@ -2573,30 +2573,16 @@
 ntMethod
-.getInstance()
 );%0A%0A    
@@ -2764,37 +2764,33 @@
 tMovementMethod(
-LinkM
+m
 ovementMethod.ge
@@ -2782,38 +2782,24 @@
 vementMethod
-.getInstance()
 );%0A        c
@@ -2832,69 +2832,21 @@
 lor(
-ContextCompat.getColor(context, R.color.text_link_color_dark)
+linkTextColor
 );%0A%0A
@@ -3017,37 +3017,33 @@
 tMovementMethod(
-LinkM
+m
 ovementMethod.ge
@@ -3035,38 +3035,24 @@
 vementMethod
-.getInstance()
 );%0A        s
@@ -3082,69 +3082,21 @@
 lor(
-ContextCompat.getColor(context, R.color.text_link_color_dark)
+linkTextColor
 );%0A%0A
@@ -3245,37 +3245,33 @@
 tMovementMethod(
-LinkM
+m
 ovementMethod.ge
@@ -3263,38 +3263,24 @@
 vementMethod
-.getInstance()
 );%0A        i
@@ -3306,69 +3306,21 @@
 lor(
-ContextCompat.getColor(context, R.color.text_link_color_dark)
+linkTextColor
 );%0A%0A
@@ -3526,21 +3526,17 @@
 tMethod(
-LinkM
+m
 ovementM
@@ -3540,30 +3540,16 @@
 ntMethod
-.getInstance()
 );%0A     
@@ -3588,69 +3588,21 @@
 lor(
-ContextCompat.getColor(context, R.color.text_link_color_dark)
+linkTextColor
 );%0A%0A

Load text link parameters once.