package de.fu_berlin.cdv.chasingpictures.util;

import android.annotation.SuppressLint;
import android.content.Context;
import android.os.Handler;
import android.support.annotation.Nullable;
import android.support.annotation.StringRes;
import android.widget.Toast;

import xdroid.toaster.Toaster;

/**
 * Class that provides utility methods.
 *
 * @author Simon Kalt
 */
public class Utilities {
    /**
     * @param context      The current context
     * @param formatString The message to be displayed
     * @param args         Arguments to be formatted into the string
     * @deprecated Use {@link #showError(Context, int, Object...)} if possible.
     */
    @Deprecated
    public static void showError(Context context, String formatString, Object... args) {
        String message = args.length == 0 ? formatString : String.format(formatString, args);
        Toaster.toast(message);
    }

    /**
     * Displays an error to the user.
     * Currently does the same thing as {@link #showToast(Context, int, Object...)} but
     * could later be changed to look differently.
     *
     * @param context The current context
     * @param resID   A string resource to be displayed
     * @param args    Arguments to be formatted into the string
     */
    public static void showError(Context context, @StringRes int resID, Object... args) {
        showToast(context, resID, args);
    }

    /**
     * Displays a message to the user.
     *
     * @param context The current context
     * @param resID   A string resource to be displayed
     * @param args    Arguments to be formatted into the string
     */
    public static void showToast(Context context, @StringRes final int resID, final Object... args) {
        String message = context.getString(resID);
        message = args.length == 0 ? message : String.format(message, args);
        Toaster.toast(message);
    }

    /**
     * Displays a message to the user.
     *
     * @param context The current context
     * @param resID   A string resource to be displayed
     * @param handler The handler to post {@link Toast#show()} to
     * @param args    Arguments to be formatted into the string
     */
    public static void showToast(Context context, @StringRes final int resID, @Nullable Handler handler, final Object... args) {
        @SuppressLint("ShowToast")
        final Toast toast = Toast.makeText(
                context,
                String.format(context.getString(resID), args),
                Toast.LENGTH_SHORT
        );

        // Display on main looper.
        if (handler != null) {
            handler.post(new Runnable() {
                @Override
                public void run() {
                    toast.show();
                }
            });
        } else {
            toast.show();
        }
    }
}

@@ -1889,938 +1889,7 @@
    %7D
-%0A%0A    /**%0A     * Displays a message to the user.%0A     *%0A     * @param context The current context%0A     * @param resID   A string resource to be displayed%0A     * @param handler The handler to post %7B@link Toast#show()%7D to%0A     * @param args    Arguments to be formatted into the string%0A     */%0A    public static void showToast(Context context, @StringRes final int resID, @Nullable Handler handler, final Object... args) %7B%0A        @SuppressLint(%22ShowToast%22)%0A        final Toast toast = Toast.makeText(%0A                context,%0A                String.format(context.getString(resID), args),%0A                Toast.LENGTH_SHORT%0A        );%0A%0A        // Display on main looper.%0A        if (handler != null) %7B%0A            handler.post(new Runnable() %7B%0A                @Override%0A                public void run() %7B%0A                    toast.show();%0A                %7D%0A            %7D);%0A        %7D else %7B%0A            toast.show();%0A        %7D%0A    %7D
 %0A%7D%0A

Remove obsolete utility method