Removing Tizen.Xamarin.Forms.Extensions
[profile/tv/apps/dotnet/mediahub.git] / TVMediaHub / TVMediaHub.Tizen / Extensions / ToastImplementation.cs
1 using System;
2 using Tizen.Xamarin.Forms.Extension.Renderer;
3 using Xamarin.Forms;
4 using Xamarin.Forms.Platform.Tizen;\r
5 using EPopup = ElmSharp.Popup;
6 using TForms = Xamarin.Forms.Platform.Tizen.Forms;
7
8 [assembly: Dependency(typeof(ToastImplementation))]
9
10 namespace Tizen.Xamarin.Forms.Extension.Renderer
11 {
12     internal class ToastImplementation : IToast, IDisposable
13     {
14         static readonly string DefaultStyle = "toast";
15         static readonly string DefaultPart = "default";
16
17         int _duration = 3000;
18         string _text = string.Empty;
19         EPopup _control = null;
20         bool _isDisposed = false;
21
22         public int Duration
23         {
24             get
25             {
26                 return _duration;
27             }
28             set
29             {
30                 _duration = value;
31                 UpdateDuration();
32             }
33         }
34
35         public string Text
36         {
37             get
38             {
39                 return _text;
40             }
41             set
42             {
43                 _text = value;
44                 UpdateText();
45             }
46         }
47
48         public ToastImplementation()
49         {
50             _control = new EPopup((TForms.Context as FormsApplication).MainWindow)
51             {
52                 Style = DefaultStyle,
53                 AllowEvents = true,
54             };
55
56             UpdateText();
57             UpdateDuration();
58         }
59
60         ~ToastImplementation()
61         {
62             Dispose(false);
63         }
64
65         public void Show()
66         {
67             _control.Show();
68         }
69
70         public void Dismiss()
71         {
72             _control.Dismiss();
73         }
74
75         public void Dispose()
76         {
77             Dispose(true);
78             GC.SuppressFinalize(this);
79         }
80
81         protected virtual void Dispose(bool isDisposing)
82         {
83             if (_isDisposed)
84                 return;
85
86             if (isDisposing)
87             {
88                 if (_control != null)
89                 {
90                     _control.Unrealize();
91                     _control = null;
92                 }
93             }
94
95             _isDisposed = true;
96         }
97
98         void UpdateDuration()
99         {
100             _control.Timeout = Duration / 1000.0;
101         }
102
103         void UpdateText()
104         {
105             _control.SetPartText(DefaultPart, Text);
106         }
107     }
108 }