package org.stepic.droid.util;

import org.stepic.droid.base.MainApplication;
import org.stepic.droid.configuration.IConfig;

public class StringUtil {
    public static Double safetyParseString(String str) {
        Double doubleScore = null;
        try {
            doubleScore = Double.parseDouble(str);

        } catch (Exception ignored) {
        }
        return doubleScore;
    }

    public static String getUriForCourse(String baseUrl, String slug){
        StringBuilder stringBuilder =new StringBuilder();
        stringBuilder.append(baseUrl);
        stringBuilder.append(AppConstants.WEB_URI_SEPARATOR);
        stringBuilder.append("course");
        stringBuilder.append(AppConstants.WEB_URI_SEPARATOR);
        stringBuilder.append(slug);
        stringBuilder.append(AppConstants.WEB_URI_SEPARATOR);
        return stringBuilder.toString();
    }

    public static String getDynamicLinkForCourse(IConfig config, String slug){
        String firebaseDomain = config.getFirebaseDomain();
        if (firebaseDomain == null){
            return getUriForCourse(config.getBaseUrl(), slug);
        }


        StringBuilder stringBuilder =new StringBuilder();
        stringBuilder.append(firebaseDomain);
        stringBuilder.append("?link=");
        stringBuilder.append(config.getBaseUrl());
        stringBuilder.append(AppConstants.WEB_URI_SEPARATOR);
        stringBuilder.append("course");
        stringBuilder.append(AppConstants.WEB_URI_SEPARATOR);
        stringBuilder.append(slug);
        stringBuilder.append(AppConstants.WEB_URI_SEPARATOR);

        stringBuilder.append("&apn=");
        String packageName = MainApplication.getAppContext().getPackageName();
        if (packageName == null){
            return getUriForCourse(config.getBaseUrl(), slug);
        }
        stringBuilder.append(packageName);

//        stringBuilder.append("&ibi=com.AlexKarpov.Stepic");

        stringBuilder.append("&amv=650");
        return stringBuilder.toString();
    }

}

@@ -1572,16 +1572,57 @@
 RATOR);%0A
+        stringBuilder.append(%22&amv=650%22);
 %0A       
@@ -1948,51 +1948,8 @@
 c%22);
-%0A%0A        stringBuilder.append(%22&amv=650%22);
 %0A   

fix order of dynamic link's args for better parsing in apps