package com.spiddekauga.android.ui;

import android.support.annotation.StringRes;
import android.support.design.widget.Snackbar;
import android.view.View;

import com.spiddekauga.android.AppActivity;

/**
 * Some helper methods for creating simple snackbars
 */
public class SnackbarHelper {
/**
 * Create a simple {@link android.support.design.widget.Snackbar} with a message
 * @param message the message to show
 */
public static void showSnackbar(String message) {
	View rootView = AppActivity.getRootView();
	Snackbar.make(rootView, message, Snackbar.LENGTH_LONG).show();
}

/**
 * Create a simple {@link android.support.design.widget.Snackbar} with a message
 * @param stringId id of the message to show
 */
public static void showSnackbar(@StringRes int stringId) {
	View rootView = AppActivity.getRootView();
	Snackbar.make(rootView, stringId, Snackbar.LENGTH_LONG).show();
}

/**
 * Create a simple {@link android.support.design.widget.Snackbar} with a message and an action
 * @param message the message to show
 * @param actionTitle button title
 * @param action the action to take
 */
public static void showSnackbar(String message, String actionTitle, View.OnClickListener action) {
	View rootView = AppActivity.getRootView();
	Snackbar snackbar = Snackbar.make(rootView, message, Snackbar.LENGTH_LONG);
	snackbar.setAction(actionTitle, action);
	snackbar.show();
}

/**
 * Create a simple {@link android.support.design.widget.Snackbar} with a message
 * @param stringId id of the message to show
 * @param actionTitleId button title as a string resource id
 * @param action the action to take
 */
public static void showSnackbar(@StringRes int stringId, @StringRes int actionTitleId, View.OnClickListener action) {
	View rootView = AppActivity.getRootView();
	Snackbar snackbar = Snackbar.make(rootView, stringId, Snackbar.LENGTH_LONG);
	snackbar.setAction(actionTitleId, action);
	snackbar.show();
}
}

@@ -285,16 +285,360 @@
 elper %7B%0A
+@Snackbar.Duration%0Aprivate static final int DURATION_SHORT = Snackbar.LENGTH_SHORT;%0A@Snackbar.Duration%0Aprivate static final int DURATION_MEDIUM = Snackbar.LENGTH_LONG;%0Aprivate static final int LENGTH_MEDIUM_CHARACTERS = 0;%0A@Snackbar.Duration%0Aprivate static final int DURATION_LONG = 6000;%0Aprivate static final int LENGTH_LONG_CHARACTERS = 20;%0A%0A
 /**%0A * C
@@ -716,39 +716,46 @@
 ssage%0A * @param 
-message
+stringId id of
  the message to 
@@ -799,131 +799,68 @@
 bar(
+@
 String
- message) %7B%0A%09View rootView = AppActivity.getRootView();%0A%09Snackbar.make(rootView, message, Snackbar.LENGTH_LONG).show(
+Res int stringId) %7B%0A%09showSnackbar(getString(stringId)
 );%0A%7D
@@ -952,38 +952,31 @@
 e%0A * @param 
-stringId id of
+message
  the message
@@ -1012,32 +1012,121 @@
 id showSnackbar(
+String message) %7B%0A%09showSnackbar(message, null, null);%0A%7D%0A%0Aprivate static String getString(
 @StringRes int s
@@ -1133,39 +1133,30 @@
 tringId) %7B%0A%09
-View rootView =
+return
  AppActivity
@@ -1163,82 +1163,52 @@
 .get
-RootView();%0A%09Snackbar.make(rootView, stringId, Snackbar.LENGTH_LONG).show(
+Activity().getResources().getString(stringId
 );%0A%7D
@@ -1556,32 +1556,76 @@
 .getRootView();%0A
+%09int duration = calculateDuration(message);%0A
 %09Snackbar snackb
@@ -1662,39 +1662,74 @@
 essage, 
-Snackbar.LENGTH_LONG);%0A
+duration);%0A%09if (actionTitle != null && action != null) %7B%0A%09
 %09snackba
@@ -1754,32 +1754,35 @@
 Title, action);%0A
+%09%7D%0A
 %09snackbar.show()
@@ -1782,24 +1782,279 @@
 .show();%0A%7D%0A%0A
+private static int calculateDuration(String message) %7B%0A%09if (message.length() %3E LENGTH_LONG_CHARACTERS) %7B%0A%09%09return DURATION_LONG;%0A%09%7D else if (message.length() %3E LENGTH_MEDIUM_CHARACTERS) %7B%0A%09%09return DURATION_MEDIUM;%0A%09%7D else %7B%0A%09%09return DURATION_SHORT;%0A%09%7D%0A%7D%0A%0A
 /**%0A * Creat
@@ -2395,104 +2395,39 @@
  %7B%0A%09
-View rootView = AppActivity.getRootView();%0A%09Snackbar snackbar = Snackbar.make(rootView, 
+showSnackbar(getString(
 stringId
 , Sn
@@ -2426,52 +2426,20 @@
 ngId
+)
 , 
-Snackbar.LENGTH_LONG);%0A%09snackbar.setAction
+getString
 (act
@@ -2448,16 +2448,17 @@
 nTitleId
+)
 , action
@@ -2460,30 +2460,12 @@
 ction);%0A
-%09snackbar.show();%0A
 %7D%0A%7D%0A

Change SnackbarHelper to automatically set message duration