private bool SnackbarAlreadyPresent(Snackbar newSnackbar)
 {
     return(SnackBarList.Any(snackbar =>
                             newSnackbar.Message.Equals(snackbar.Message) &&
                             newSnackbar.Severity.Equals(snackbar.Severity)
                             ));
 }
        public Snackbar Add(string message, Severity severity = Severity.Normal, Action <SnackbarOptions> configure = null)
        {
            if (message.IsEmpty())
            {
                return(null);
            }

            message = message.Trimmed();

            var options = new SnackbarOptions(severity, Configuration);

            configure?.Invoke(options);

            var snackbar = new Snackbar(message, options);

            SnackBarLock.EnterWriteLock();
            try
            {
                if (Configuration.PreventDuplicates && SnackbarAlreadyPresent(snackbar))
                {
                    return(null);
                }
                snackbar.OnClose += Remove;
                SnackBarList.Add(snackbar);
            }
            finally
            {
                SnackBarLock.ExitWriteLock();
            }

            OnSnackbarsUpdated?.Invoke();

            return(snackbar);
        }
Exemple #3
0
        public void Add(SnackbarType type, string message, Action <SnackbarOptions> configure)
        {
            if (message.IsEmpty())
            {
                return;
            }

            message = message.Trimmed();

            var options = new SnackbarOptions(type, Configuration);

            configure?.Invoke(options);

            var toast = new Snackbar(message, options);

            SnackBarLock.EnterWriteLock();
            try
            {
                if (Configuration.PreventDuplicates && ToastAlreadyPresent(toast))
                {
                    return;
                }
                toast.OnClose += Remove;
                SnackBarList.Add(toast);
            }
            finally
            {
                SnackBarLock.ExitWriteLock();
            }

            OnSnackbarsUpdated?.Invoke();
        }
Exemple #4
0
 private bool ToastAlreadyPresent(Snackbar newToast)
 {
     return(SnackBarList.Any(toast =>
                             newToast.Message.Equals(toast.Message) &&
                             newToast.Type.Equals(toast.Type)
                             ));
 }
        private void RemoveAllSnackbars(IEnumerable <Snackbar> snackbars)
        {
            if (SnackBarList.Count == 0)
            {
                return;
            }

            foreach (var snackbar in snackbars)
            {
                snackbar.OnClose -= Remove;
                snackbar.Dispose();
            }

            SnackBarList.Clear();
        }
Exemple #6
0
        private void RemoveAllToasts(IEnumerable <Snackbar> toasts)
        {
            if (SnackBarList.Count == 0)
            {
                return;
            }

            foreach (var toast in toasts)
            {
                toast.OnClose -= Remove;
                toast.Dispose();
            }

            SnackBarList.Clear();
        }
        public void Remove(Snackbar snackbar)
        {
            snackbar.Dispose();
            snackbar.OnClose -= Remove;

            SnackBarLock.EnterWriteLock();
            try
            {
                var index = SnackBarList.IndexOf(snackbar);
                if (index < 0)
                {
                    return;
                }
                SnackBarList.RemoveAt(index);
            }
            finally
            {
                SnackBarLock.ExitWriteLock();
            }

            OnSnackbarsUpdated?.Invoke();
        }