package com.ttstd.dialer.base;

import android.content.Context;
import android.content.ContextWrapper;
import android.content.res.Resources;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;

import com.ttstd.dialer.utils.ScreenUtils;

public class BaseAlertDialogBuilder extends AlertDialog.Builder {

    /**
     *
     */
    private static final float ALERT_BASE_WIDTH = 480f;
    private static final float ALERT_BASE_WIDTH_TABLE = 640f;

    public BaseAlertDialogBuilder(@NonNull Context context) {
        super(adjustAutoSize(context));
    }

    public BaseAlertDialogBuilder(@NonNull Context context, int themeResId) {
        super(adjustAutoSize(context), themeResId);
    }

    private static Context adjustAutoSize(Context context) {
        return new ContextWrapper(context) {
            private Resources mResources;

            {
                Resources oldResources = super.getResources();
                mResources = new Resources(oldResources.getAssets(), oldResources.getDisplayMetrics(), oldResources.getConfiguration());
            }

            @Override
            public Resources getResources() {
                if (ScreenUtils.isTablet(context)) {
//                    AutoSizeCompat.autoConvertDensityBaseOnWidth(mResources, ALERT_BASE_WIDTH_TABLE);
                } else {
//                    AutoSizeCompat.autoConvertDensityBaseOnWidth(mResources, ALERT_BASE_WIDTH);
                }
                return mResources;
            }
        };
    }
}
