Пример #1
0
        private void RemindBackup()
        {
            var prefs       = PreferenceManager.GetDefaultSharedPreferences(this);
            var needsBackup = prefs.GetBoolean("needsBackup", false) && _authSource.GetAll().Any();

            if (!needsBackup)
            {
                return;
            }

            var snackbar = Snackbar.Make(_coordinatorLayout, Resource.String.backupReminder, Snackbar.LengthLong);

            snackbar.SetAnchorView(_addButton);
            snackbar.SetAction(Resource.String.backupNow, view =>
            {
                StartBackupSaveActivity();
            });

            var callback = new SnackbarCallback();

            callback.Dismiss += (sender, e) =>
            {
                if (e == Snackbar.Callback.DismissEventSwipe)
                {
                    prefs.Edit().PutBoolean("needsBackup", false).Commit();
                }
            };

            snackbar.AddCallback(callback);
            snackbar.Show();
        }
        private Task HandleTask(ToastModel model)
        {
            var taskCompletionSource = new TaskCompletionSource <bool>();

            Execute.BeginOnUIThread(() =>
            {
                var toastContainerComponent = default(ToastContainerComponent);

                var activity = _contextProvider.CurrentActivity;

                if (activity is ActivityBase activityBase)
                {
                    toastContainerComponent =
                        activityBase.ViewComponents.FirstOrDefault(x => x.Key == nameof(ToastContainerComponent)) as
                        ToastContainerComponent;
                }

                var view = toastContainerComponent == null
                    ? activity.FindViewById <ViewGroup>(Android.Resource.Id.Content).GetChildAt(0)
                    : activity.FindViewById <ViewGroup>(toastContainerComponent.ContainerId);

                if (view == null)
                {
                    taskCompletionSource.TrySetResult(false);
                    return;
                }

                var snackbar = Snackbar
                               .Make(view, model.Label, Snackbar.LengthLong)
                               .SetAction(model.CommandAction.Title, x => { model.CommandAction.Command.Execute(x); });
                var snackbarView = snackbar.View;
                snackbarView.SetBackgroundResource(_toastSettings.NotificationBgColor);
                snackbar.SetActionTextColor(snackbarView.GetColor(_toastSettings.NotificationTextColor));
                var callback = new SnackbarCallback(taskCompletionSource, model.AltCommandAction);
                snackbar.AddCallback(callback);
                snackbar.Show();
            });

            return(taskCompletionSource.Task);
        }