package R.helper;

import android.content.Context;
import android.content.res.Resources;
import android.os.Build;
import android.support.annotation.NonNull;
import android.util.DisplayMetrics;

import java.util.List;

/**
 * Created by duynk on 12/29/15.
 */
public class Common {
    public static boolean isLollipopOrLater() {
        return Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP;
    }

    public static boolean isMarshMallowOrLater() {
        return Build.VERSION.SDK_INT >= Build.VERSION_CODES.M;
    }

    public static boolean isVersionOrLater(int version) {
        return Build.VERSION.SDK_INT >= version;
    }

    public static int sign(float a) {
        return a > 0?1:(a<0?-1:0);
    }

    public static float lerp(float start, float end, float percent) {
        float dt = Math.abs(start - end);
        float min = Math.max(Math.abs(start) * 0.1f, Math.abs(end) * 0.1f);
        if (dt <= min) {
            start = end;
        }
        return (start + percent * (end - start));
    }

    public static int lerp(int start, int end, float percent) {
        float dt = Math.abs(start - end);
        float min = Math.max(Math.abs(start) * 0.1f, Math.abs(end) * 0.1f);
        if (dt <= min) {
            start = end;
        }
        return (int) (start + percent * (end - start));
    }

    public static float convertDpToPixel(float dp) {
        Resources resources = BaseApplication.sInstance.getResources();
        DisplayMetrics metrics = resources.getDisplayMetrics();
        return dp * (metrics.densityDpi / 160f);
    }

    public static float convertPixelsToDp(float px, Context context){
        Resources resources = BaseApplication.sInstance.getResources();
        DisplayMetrics metrics = resources.getDisplayMetrics();
        return px / (metrics.densityDpi / 160f);
    }

    public static void acceptAllSSL() {
        NukeSSLCerts.nuke();
    }

    public static String join(List<String> list,@NonNull String delim) {
        String tmp_delim = "";
        StringBuilder sb = new StringBuilder();
        for (String s:list) {
            sb.append(tmp_delim);
            sb.append(s);
            tmp_delim = delim;
        }
        return sb.toString();
    }
}

@@ -44,16 +44,56 @@
 ontext;%0A
+import android.content.DialogInterface;%0A
 import a
@@ -209,51 +209,148 @@
 oid.
-util.DisplayMetrics;%0A%0Aimport java.util.List
+support.v7.app.AlertDialog;%0Aimport android.util.DisplayMetrics;%0A%0Aimport java.util.Calendar;%0Aimport java.util.List;%0Aimport java.util.TimeZone
 ;%0A%0A/
@@ -2373,11 +2373,1330 @@
 );%0A    %7D
+%0A%0A    public static long getMillis() %7B%0A        return Calendar.getInstance(TimeZone.getTimeZone(%22GMT%22)).getTimeInMillis();%0A    %7D%0A%0A    public final static long ONE_SEC = 1000;%0A    public final static long ONE_MINUTE = ONE_SEC*60;%0A    public final static long HALF_HOUR = ONE_MINUTE*30;%0A    public final static long ONE_HOUR = ONE_MINUTE*60;%0A    public final static long HALF_DAY = ONE_HOUR*12;%0A    public final static long ONE_DAY = ONE_HOUR*24;%0A    public final static long ONE_WEEK = ONE_DAY*7;%0A    public final static long ONE_WORKING_WEEK = ONE_DAY*5;%0A    public final static long HALF_MONTH = ONE_DAY*15;%0A    public final static long ONE_MONTH = ONE_DAY*30;%0A%0A    public static class Dialog %7B%0A        public static void alert(final Context ctx, String message, final Callback callback) %7B%0A            new AlertDialog.Builder(ctx)%0A                    .setTitle(%22Alert%22)%0A                    .setMessage(message)%0A                    .setCancelable(false)%0A                    .setPositiveButton(%22ok%22, new DialogInterface.OnClickListener() %7B%0A                        @Override%0A                        public void onClick(DialogInterface dialog, int which) %7B%0A                            callback.onCompleted(ctx, new CallbackSuccess(null));%0A                        %7D%0A                    %7D).create().show();%0A        %7D%0A    %7D%0A%0A
 %0A%7D%0A

add utils