-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAnilibriaAppTizen.cs
146 lines (128 loc) · 4.88 KB
/
AnilibriaAppTizen.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
using Tizen.NUI;
using Tizen.NUI.BaseComponents;
using System.Diagnostics;
using AnilibriaAppTizen.Services;
using AnilibriaAppTizen.Views;
namespace AnilibriaAppTizen
{
internal class Program : NUIApplication
{
private ApiService _apiService;
private FileService _fileService;
private ImageService _imageService;
private LocalSettingsService _localSettingsService;
private UserService _userService;
private Main _main;
private Release _release;
private Player _player;
/// <summary>
/// Initialize application
/// </summary>
async void Initialize()
{
// Add custom fonts
FontClient.Instance.AddCustomFontDirectory(DirectoryInfo.SharedResource + "fonts/");
// Add main key event
Window.Instance.KeyEvent += OnKeyEvent;
Window.Instance.BackgroundColor = Color.Transparent;
// Create services
_apiService = new ApiService();
_fileService = new FileService();
_imageService = new ImageService();
_localSettingsService = new LocalSettingsService(_fileService);
_userService = new UserService(_localSettingsService, _apiService);
// Views
_player = new Player();
_release = new Release(_apiService, _imageService, _player);
_main = new Main(_apiService, _imageService, _userService, _release);
// Init user session
await _imageService.InitializeAsync();
await _userService.InitializeAsync();
// Init views
_main.Initialize();
_release.Initialize();
_player.Initialize(_release, _main);
FocusManager.Instance.FocusIndicator = new View();
FocusManager.Instance.FocusChanged += FocusManager_FocusChanged;
FocusManager.Instance.SetCurrentFocusView(_main.ActiveMenuButton.View);
}
/// <summary>
/// The method called when key pressed down
/// </summary>
/// <param name="sender">Key instance</param>
/// <param name="e">Key's args</param>
private void OnKeyEvent(object sender, Window.KeyEventArgs e)
{
// Home - XF86Home
// play/pause - XF86PlayBack
// next - XF86RaiseChannel
// prev - XF86LowerChannel
// ch_push - XF86ChannelGuide
// Right, Down, Left, Up, Return
if (e.Key.State == Key.StateType.Down)
if (_player.IsActive)
{
var player = _player.Instance;
switch (e.Key.KeyPressedName)
{
case "XF86PlayBack":
if (player.State == Tizen.Multimedia.PlayerState.Playing)
player.Pause();
else if (player.State == Tizen.Multimedia.PlayerState.Paused)
player.Start();
break;
case "Right":
player.SetPlayPositionAsync(player.GetPlayPosition() + 10000, false);
break;
case "Left":
player.SetPlayPositionAsync(player.GetPlayPosition() - 10000, false);
break;
case "XF86Back":
_player.CloseVideo();
break;
default:
break;
}
}
else
{
if (e.Key.KeyPressedName == "Escape" || e.Key.KeyPressedName == "XF86Back")
{
if (_release.IsActive)
_release.Dispose();
else
Exit();
}
}
}
/// <summary>
/// The method called when focus changed
/// </summary>
/// <param name="sender">FocusManager instance</param>
/// <param name="e">FocusManager's args</param>
private void FocusManager_FocusChanged(object sender, FocusManager.FocusChangedEventArgs e)
{
if (e.NextView != null)
{
Debug.WriteLine($"{e.NextView.Name}");
}
}
/// <summary>
/// The method called when application created
/// </summary>
protected override void OnCreate()
{
base.OnCreate();
Initialize();
}
/// <summary>
/// Main function.
/// </summary>
/// <param name="args">arguments of Main (entry point)</param>
static void Main(string[] args)
{
var app = new Program();
app.Run(args);
}
}
}