Ejemplo n.º 1
0
    private async Task LoadingDelayAsync(LoadingConfig config, int loadingCount)
    {
        if (loadingCount % 2 == 0)
        {
            Timer timer = null;

            await Task.WhenAll(Task.Delay(TimeSpan.FromSeconds(5)), Task.Run(() =>
            {
                timer = new Timer((_) =>
                {
                    if (config.Progress.HasValue)
                    {
                        config.Progress++;
                    }
                    else
                    {
                        config.Progress = 0;
                    }
                }, null, 0, 40);
            }));

            timer.Dispose();
        }
        else
        {
            await Task.Delay(TimeSpan.FromSeconds(5));
        }
    }
Ejemplo n.º 2
0
        public IDisposable Loading(Activity activity, LoadingConfig config)
        {
            if (_progress != null && _progress.IsShowing)
            {
                _progress.Dismiss();
            }

            _progress = KProgressHUD.Create(activity, KProgressHUD.Style.SpinIndeterminate).SetLabel(config.Text);

            _progress.SetCancellable(config.Cancellable);

            if (config.Cancellable)
            {
                _progress.SetCancelAction(() =>
                {
                    _progress.Dismiss();

                    config.CancelAction?.Invoke();
                });
            }

            if (config.MarkType == MarkType.Black)
            {
                _progress.SetDimAmount(0.5f);
            }

            _progress.Show();

            if (config.Duration != null)
            {
                DelayDismiss((int)config.Duration.Value.TotalMilliseconds);
            }

            return(new DisposableAction(() => _progress.Dismiss()));
        }
Ejemplo n.º 3
0
    /// <summary>
    ///     Display a loading dialog.
    /// </summary>
    /// <param name="config">The dialog configuration.</param>
    public virtual IDisposable Loading(LoadingConfig config)
    {
        // If available, call the delegate to see if presenting this dialog is allowed.
        if (MessagingServiceCore.Delegate == null || MessagingServiceCore.Delegate.OnLoadingRequested(config))
        {
            return(PresentLoading(config));
        }

        return(null);
    }
Ejemplo n.º 4
0
    public async void Loading()
    {
        var config = new LoadingConfig {
            Title = "Loading", Message = "Hello World!"
        };

        var loading = MessagingService.Instance.Loading(config);

        await LoadingDelayAsync(config, _loadingCount ++);

        loading.Dispose();
    }
Ejemplo n.º 5
0
        public static IDisposable Loading(UIApplication app, UIView view, LoadingConfig config)
        {
            app.SafeInvokeOnMainThread(() =>
            {
                _loadingHub                     = MBProgressHUD.ShowHUD(view, true);
                _loadingHub.Mode                = MBProgressHUDMode.Indeterminate;
                _loadingHub.Label.Text          = config.Text;
                _loadingHub.Label.LineBreakMode = UILineBreakMode.WordWrap;
                _loadingHub.Label.Lines         = int.MaxValue;
                _loadingHub.MinShowTime         = 1;         // The minimum time (in seconds) that the HUD is shown.

                if (config.MarkType == MarkType.Black)
                {
                    _loadingHub.BackgroundView.Style = MBProgressHUDBackgroundStyle.SolidColor;
                    _loadingHub.BackgroundView.Color = UIColor.Black.ColorWithAlpha(0.5f);
                }

                if (config.Cancellable)
                {
                    _loadingHub.Button.SetTitle(config.CancelText, UIControlState.Normal);
                    _loadingHub.Button.AddTarget((_1, _2) =>
                    {
                        config.CancelAction?.Invoke();
                        _loadingHub.Hide(true);
                    }, UIControlEvent.TouchUpInside);
                }

                _loadingHub.Show(true);

                if (config.Duration.HasValue)
                {
                    _loadingHub.Hide(true, config.Duration.Value.TotalSeconds);
                }

                //_loadingHub.Hide(true, 3);  // seconds
            });

            return(new DisposableAction(() => _loadingHub.Hide(true)));
        }
Ejemplo n.º 6
0
        async Task LoadingTest()
        {
            var config = new LoadingConfig();

            Configurations.LoadingConfig = config;

            Loading.Instance.Show();
            await Task.Delay(100);

            Loading.Instance.Hide();

            await Task.Delay(100);

            await Loading.Instance.StartAsync(async p =>
            {
                Debug.WriteLine("Default1");
                await Task.Delay(250);
            });

            await Task.Delay(100);

            await Loading.Instance.StartAsync(async p =>
            {
                Debug.WriteLine("Default2");
                await Task.Delay(250);
            }, "hoge", true);

            await Task.Delay(100);

            Loading.Instance.Dispose();

            config.IsReusable = true;

            Loading.Instance.Show();
            await Task.Delay(100);

            Loading.Instance.Hide();

            await Task.Delay(100);

            await Loading.Instance.StartAsync(async p =>
            {
                Debug.WriteLine("Default3");
                await Task.Delay(250);
            });

            await Task.Delay(100);

            await Loading.Instance.StartAsync(async p =>
            {
                Debug.WriteLine("Default4");
                await Task.Delay(250);
            }, "hoge", true);

            await Task.Delay(100);

            // 通過テスト 通過できればOKとする
            var result = new TestItem
            {
                Name   = "Loading Default",
                Result = true
            };

            TestResults.Add(result);

            Loading.Instance.Dispose();

            await Task.Delay(500);

            var loading  = new LoadingTestView();
            var reusable = Loading.Instance.Create(loading);

            await reusable.StartAsync(async p =>
            {
                await Task.Delay(50);
                p.Report(0.3);
                await Task.Delay(50);
                p.Report(0.6);
                await Task.Delay(50);
                p.Report(0.9);
                await Task.Delay(50);
            });

            await Task.Delay(500);

            TestResults.Add(new TestItem
            {
                Name   = "Loading Custom",
                Result = loading.Assert.All(x => x) && loading.Assert.Count == 3, // ReuseなのでDestroyはなし
                Detail = string.Join(", ", loading.Assert.Select((x, index) => new { index, result = x })
                                     .Where(x => !x.result).Select(x => x.index + 1))
            });


            await reusable.StartAsync(async p =>
            {
                await Task.Delay(50);
                p.Report(0.3);
                await Task.Delay(50);
                p.Report(0.6);
                await Task.Delay(50);
                p.Report(0.9);
                await Task.Delay(50);
            }, true);

            await Task.Delay(500);

            TestResults.Add(new TestItem
            {
                Name = "Loading Custom Reuse",
                // 2回目は前回のインスタンスを使用している
                Result = loading.Assert.Count == 6 && loading.seq == 5 && loading.progressCnt == 6,
            });

            reusable.Dispose();

            TestResults.Add(new TestItem
            {
                Name   = "Loading Custom Dispose",
                Result = loading.Assert.Count == 7 && loading.seq == 6 && loading.progressCnt == 6
            });
        }