package com.gani.lib.ui.alert;

import android.content.Context;
import android.os.Handler;
import android.view.Gravity;
import android.widget.Toast;

import com.gani.lib.ui.Ui;

public class ToastUtils {
//  // TODO: Remove. If you can pass a context, might as well use a snack bar
//  public static void showToastInCenter(Context context, int resId) {
//    Toast toast = Toast.makeText(context, resId, Toast.LENGTH_SHORT);
//    toast.setGravity(Gravity.TOP, 0, context.getResources().getDisplayMetrics().heightPixels / 2);
//    toast.show();
//  }
//
//  // TODO: Remove. If you can pass a context, might as well use a snack bar
//  public static void showNormal(RichContainer container, int resId) {
//    showNormal(container, App.str(resId));
//  }
//
//  // TODO: Remove. If you can pass a context, might as well use a snack bar
//  public static void showNormal(RichContainer container, final String str) {
//    final RichActivity activity = container.getGActivity();
//    if (activity != null) {
//      activity.runOnUiThread(new Runnable() {
//        @Override
//        public void run() {
//          Toast.makeText(activity, str, Toast.LENGTH_SHORT).show();
//        }
//      });
//    }
//  }
//
//  // TODO: Remove. If you can pass a context, might as well use a snack bar
//  public static void showGenericSuccess(RichContainer container) {
//    showNormal(container, R.string.dialog_success);
//  }

  // Can be run from a background thread, e.g. HttpCallback.Rest.onRestSuccess()
  public static void showNormal(final String str) {
    Handler mainHandler = new Handler(Ui.context().getMainLooper());
    Runnable myRunnable = new Runnable() {
      @Override
      public void run() {
        Toast.makeText(Ui.context(), str, Toast.LENGTH_SHORT).show();
      }
    };
    mainHandler.post(myRunnable);
  }

  public static void showNormal(int strId) {
    showNormal(Ui.str(strId));
  }

//  public static void showGenericSuccess() {
//    showNormal(R.string.dialog_success);
//  }

  public static void showToastInCenter(int resId) {
    Toast toast = Toast.makeText(Ui.context(), resId, Toast.LENGTH_SHORT);
    toast.setGravity(Gravity.TOP, 0, Ui.resources().getDisplayMetrics().heightPixels / 2);
    toast.show();
  }
}

@@ -29,40 +29,8 @@
 t;%0A%0A
-import android.content.Context;%0A
 impo
@@ -52,16 +52,16 @@
 andler;%0A
+
 import a
@@ -169,700 +169,40 @@
 s %7B%0A
-//  // TODO: Remove. If you can pass a context, might as well use a snack bar%0A//  public static void showToastInCenter(Context context, int resId) %7B%0A//    Toast toast = Toast.makeText(context, resId, Toast.LENGTH_SHORT);%0A//    toast.setGravity(Gravity.TOP, 0, context.getResources().getDisplayMetrics().heightPixels / 2);%0A//    toast.show();%0A//  %7D%0A//%0A//  // TODO: Remove. If you can pass a context, might as well use a snack bar%0A//  public static void showNormal(RichContainer container, int resId) %7B%0A//    showNormal(container, App.str(resId));%0A//  %7D%0A//%0A//  // TODO: Remove. If you can pass a context, might as well use a snack bar%0A//  public static void showNormal(RichContainer container, 
+  public static void showNormal(
 fina
@@ -221,512 +221,49 @@
 ) %7B%0A
-//
     
-final RichActivity activity = container.getGActivity();%0A//    if (activity != null) %7B%0A//      activity.runOnUiThread(new Runnable() %7B%0A//        @Override%0A//        public void run() %7B%0A//          Toast.makeText(activity, str, Toast.LENGTH_SHORT).show();%0A//        %7D%0A//      %7D);%0A//    %7D%0A//  %7D%0A//%0A//  // TODO: Remove. If you can pass a context, might as well use a snack bar%0A//  public static void showGenericSuccess(RichContainer container) %7B%0A//    showNormal(container, R.string.dialog_success);%0A//
+showNormal(str, Toast.LENGTH_SHORT);%0A
   %7D%0A
@@ -384,32 +384,52 @@
 final String str
+, final int duration
 ) %7B%0A    Handler 
@@ -612,34 +612,24 @@
 ), str, 
-Toast.LENGTH_SHORT
+duration
 ).show()
@@ -769,104 +769,8 @@
  %7D%0A%0A
-//  public static void showGenericSuccess() %7B%0A//    showNormal(R.string.dialog_success);%0A//  %7D%0A%0A
   pu

improve toast