Skip to content

Commit 2acbe57

Browse files
committed
Implemented OneDrive Provider
1 parent 4a0c1e1 commit 2acbe57

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+2481
-68
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -258,4 +258,5 @@ paket-files/
258258

259259
# Python Tools for Visual Studio (PTVS)
260260
__pycache__/
261-
*.pyc
261+
*.pyc
262+
/MusicPlayer/SecureConstents.cs

MusicPlayer/App.xaml

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
<ResourceDictionary.MergedDictionaries>
1111
<ResourceDictionary Source="base.xaml"/>
1212
<ResourceDictionary Source="themeresources.xaml"/>
13+
<ResourceDictionary Source="Controls/UWPToolkit/AadLogin/AadLogin.xaml"/>
14+
<ResourceDictionary Source="Controls/UWPToolkit/ProfileCard/ProfileCard.xaml"/>
1315
</ResourceDictionary.MergedDictionaries>
1416

1517
<SolidColorBrush x:Key="SystemControlTransparentBackgroundBrush" Color="#c0888888"></SolidColorBrush>

MusicPlayer/App.xaml.cs

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System;
1+
using Microsoft.Toolkit.Services.MicrosoftGraph;
2+
using System;
23
using System.Collections.Generic;
34
using System.ComponentModel;
45
using System.IO;
@@ -40,8 +41,10 @@ public sealed partial class App : Application, INotifyPropertyChanged
4041
public App()
4142
{
4243
_ = LocalLibrary.Instance;
44+
_ = OneDriveLibrary.Instance;
4345
this.InitializeComponent();
4446
this.Suspending += this.OnSuspending;
47+
4548
}
4649

4750
public event PropertyChangedEventHandler PropertyChanged;
@@ -53,6 +56,13 @@ public App()
5356
/// <param name="e">Details about the launch request and process.</param>
5457
protected override async void OnLaunched(LaunchActivatedEventArgs e)
5558
{
59+
60+
61+
MicrosoftGraphService.Instance.AuthenticationModel = MicrosoftGraphEnums.AuthenticationModel.V2;
62+
MicrosoftGraphService.Instance.Initialize(SecureConstents.API,
63+
MicrosoftGraphEnums.ServicesToInitialize.UserProfile,
64+
new[] { "User.Read", "Files.Read", "Files.ReadWrite.AppFolder", "UserActivity.ReadWrite.CreatedByApp" });
65+
5666

5767
var rootFrame = Window.Current.Content as Pages.ShellPage;
5868

MusicPlayer/Controls/AlbumControl.xaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ x:Name="userControl"
2929
<Setter Target="ButtonPanel.(Grid.RowSpan)" Value="3" />
3030
<!--<Setter Target="ButtonPanel.(Grid.Row)" Value="1" />-->
3131

32-
<Setter Target="userControl.Height" Value="166"/>
33-
<Setter Target="rootBorder.Height" Value="166"/>
32+
<Setter Target="userControl.Height" Value="180"/>
33+
<Setter Target="rootBorder.Height" Value="150"/>
3434

3535
<Setter Target="name.(Grid.ColumnSpan)" Value="1" />
3636
<Setter Target="Artist.(Grid.ColumnSpan)" Value="1" />

MusicPlayer/Controls/Albums.xaml.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public Albums()
7171
private async void Albums_Loaded(object sender, RoutedEventArgs e)
7272
{
7373
await Core.MusicStore.Instance.Init();
74-
await LocalLibrary.Instance.Update(default);
74+
//await LocalLibrary.Instance.Update(default);
7575
this.UpdateSize(new Size(this.ActualWidth, this.ActualHeight));
7676

7777
}

MusicPlayer/Controls/TiledBackgroundPanel.cs

+8-11
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ private async void LoopChange()
118118

119119
private async void Loop()
120120
{
121-
var library = LocalLibrary.Instance;
121+
var library = OneDriveLibrary.Instance;
122122
while (true)
123123
{
124124
try
@@ -183,17 +183,16 @@ private async void Loop()
183183
while (toUpdate != null)
184184
{
185185

186-
StorageItemThumbnail thumbnail;
186+
Uri thumbnail;
187187
do
188188
{
189189
var cover = this.covers.Next();
190190
toUpdate.Id = cover.Id;
191191
toUpdate.Provider = cover.Provider;
192192
thumbnail = await library.GetImage(toUpdate.Id, (int)(toUpdate.Size * this.ActualTileSize), default);
193193
} while (thumbnail == null);
194-
var imageSource = new BitmapImage();
194+
var imageSource = new BitmapImage(thumbnail);
195195
toUpdate.Image.Source = imageSource;
196-
await imageSource.SetSourceAsync(thumbnail);
197196
toUpdate = this.currentLayout.OfType<ImageInformation>().Distinct().Where(x => x.Image.Source == null).FirstOrDefault();
198197
}
199198

@@ -433,18 +432,16 @@ private Image CreateChild(ImageInformation information)
433432
};
434433
image.ImageFailed += async (sender, e) =>
435434
{
436-
var library = LocalLibrary.Instance;
437-
StorageItemThumbnail thumbnail;
435+
var library = OneDriveLibrary.Instance;
436+
Uri uri;
438437
do
439438
{
440439
var cover = this.covers.Next();
441440
information.Id = cover.Id;
442441
information.Provider = cover.Provider;
443-
thumbnail = await library.GetImage(information.Id, (int)(information.Size * this.ActualTileSize), default);
444-
} while (thumbnail == null);
445-
var imageSource = new BitmapImage();
446-
information.Image.Source = imageSource;
447-
await imageSource.SetSourceAsync(thumbnail);
442+
uri = await library.GetImage(information.Id, (int)(information.Size * this.ActualTileSize), default);
443+
} while (uri == null);
444+
var imageSource = new BitmapImage(uri);
448445
};
449446
return image;
450447
}

MusicPlayer/Controls/TransportControls.cs

+22-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System;
1+
using MusicPlayer.Helpers;
2+
using System;
23
using System.Collections.Generic;
34
using System.IO;
45
using System.Linq;
@@ -24,8 +25,6 @@ public sealed class TransportControls : MediaTransportControls
2425
{
2526

2627

27-
28-
2928
public MediaPlaybackList PlayList
3029
{
3130
get { return (MediaPlaybackList)this.GetValue(PlayListProperty); }
@@ -84,6 +83,20 @@ private async void CurrentMediaPlaybackItemChanged(MediaPlaybackItem newValue)
8483
}
8584
}
8685

86+
87+
88+
public ICommand GoToSettingsCommand
89+
{
90+
get { return (ICommand)this.GetValue(GoToSettingsCommandProperty); }
91+
set { this.SetValue(GoToSettingsCommandProperty, value); }
92+
}
93+
94+
// Using a DependencyProperty as the backing store for GoToSettingsCommand. This enables animation, styling, binding, etc...
95+
public static readonly DependencyProperty GoToSettingsCommandProperty =
96+
DependencyProperty.Register("GoToSettingsCommand", typeof(ICommand), typeof(TransportControls), new PropertyMetadata(DisabledCommand.Instance));
97+
98+
99+
87100
public ICommand NextCommand
88101
{
89102
get { return (ICommand)this.GetValue(NextCommandProperty); }
@@ -301,6 +314,11 @@ private void SetCommands()
301314
this.RepeateCommand = new MediaBehaviorWithStateCommand(this.mediaPlayerElement.MediaPlayer.CommandManager.AutoRepeatModeBehavior, this.SwitchRepeat, this.IsRepeate);
302315
//this.mediaPlayerElement.RegisterPropertyChangedCallback(MediaPlayerElement.SourceProperty, this.SourceChanged);
303316

317+
this.GoToSettingsCommand = new DelegateCommand(() =>
318+
{
319+
App.Shell.Frame.Navigate(typeof(Pages.SettingsPage));
320+
});
321+
304322
this.SwitchFullScreenCommand = new DelegateCommand(() => this.IsFullscreen = !this.IsFullscreen);
305323
this.IsShuffled = this.PlayList.ShuffleEnabled;
306324
this.IsRepeate = this.PlayList.AutoRepeatEnabled;
@@ -318,7 +336,7 @@ MediaPlayerElement FindParent(DependencyObject current)
318336
}
319337

320338

321-
339+
322340

323341
private void MediaPlayer_MediaEnded(MediaPlayer sender, object args)
324342
{
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using System;
6+
using Windows.UI.Xaml.Controls;
7+
8+
namespace Microsoft.Toolkit.Uwp.UI.Controls.Graph
9+
{
10+
/// <summary>
11+
/// Defines the events for the <see cref="AadLogin"/> control.
12+
/// </summary>
13+
public partial class AadLogin : Button
14+
{
15+
/// <summary>
16+
/// Occurs when the user is logged in.
17+
/// </summary>
18+
public event EventHandler<SignInEventArgs> SignInCompleted;
19+
20+
/// <summary>
21+
/// Occurs when the user is logged out.
22+
/// </summary>
23+
public event EventHandler SignOutCompleted;
24+
}
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using System;
6+
using Microsoft.Toolkit.Services.MicrosoftGraph;
7+
using Windows.UI.Xaml;
8+
using Windows.UI.Xaml.Controls;
9+
using Windows.UI.Xaml.Media.Imaging;
10+
11+
namespace Microsoft.Toolkit.Uwp.UI.Controls.Graph
12+
{
13+
/// <summary>
14+
/// Defines the properties for the <see cref="AadLogin"/> control.
15+
/// </summary>
16+
public partial class AadLogin : Button
17+
{
18+
/// <summary>
19+
/// Gets the <see cref="MicrosoftGraphService"/> instance
20+
/// </summary>
21+
public static MicrosoftGraphService GraphService => MicrosoftGraphService.Instance;
22+
23+
/// <summary>
24+
/// Gets required delegated permissions for the <see cref="AadLogin"/> control
25+
/// </summary>
26+
public static string[] RequiredDelegatedPermissions
27+
{
28+
get
29+
{
30+
return new string[] { "User.Read" };
31+
}
32+
}
33+
34+
/// <summary>
35+
/// Identifies the <see cref="DefaultImage"/> dependency property.
36+
/// </summary>
37+
public static readonly DependencyProperty DefaultImageProperty = DependencyProperty.Register(
38+
nameof(DefaultImage),
39+
typeof(BitmapImage),
40+
typeof(AadLogin),
41+
new PropertyMetadata(null));
42+
43+
/// <summary>
44+
/// Identifies the <see cref="View"/> dependency property.
45+
/// </summary>
46+
public static readonly DependencyProperty ViewProperty = DependencyProperty.Register(
47+
nameof(View),
48+
typeof(ViewType),
49+
typeof(AadLogin),
50+
new PropertyMetadata(ViewType.PictureOnly));
51+
52+
/// <summary>
53+
/// Identifies the <see cref="AllowSignInAsDifferentUser"/> dependency property.
54+
/// </summary>
55+
public static readonly DependencyProperty AllowSignInAsDifferentUserProperty = DependencyProperty.Register(
56+
nameof(AllowSignInAsDifferentUser),
57+
typeof(bool),
58+
typeof(AadLogin),
59+
new PropertyMetadata(true));
60+
61+
/// <summary>
62+
/// Identifies the <see cref="SignInDefaultText"/> dependency property.
63+
/// </summary>
64+
public static readonly DependencyProperty SignInDefaultTextProperty = DependencyProperty.Register(
65+
nameof(SignInDefaultText),
66+
typeof(string),
67+
typeof(AadLogin),
68+
new PropertyMetadata("Sign In"));
69+
70+
/// <summary>
71+
/// Identifies the <see cref="SignOutDefaultText"/> dependency property.
72+
/// </summary>
73+
public static readonly DependencyProperty SignOutDefaultTextProperty = DependencyProperty.Register(
74+
nameof(SignOutDefaultText),
75+
typeof(string),
76+
typeof(AadLogin),
77+
new PropertyMetadata("Sign Out"));
78+
79+
/// <summary>
80+
/// Identifies the <see cref="SignInAnotherUserDefaultText"/> dependency property.
81+
/// </summary>
82+
public static readonly DependencyProperty SignInAnotherUserDefaultTextProperty = DependencyProperty.Register(
83+
nameof(SignInAnotherUserDefaultText),
84+
typeof(string),
85+
typeof(AadLogin),
86+
new PropertyMetadata("Sign in with another account"));
87+
88+
/// <summary>
89+
/// Identifies the <see cref="CurrentUserId"/> dependency property.
90+
/// </summary>
91+
public static readonly DependencyProperty CurrentUserIdProperty = DependencyProperty.Register(
92+
nameof(CurrentUserId),
93+
typeof(string),
94+
typeof(AadLogin),
95+
new PropertyMetadata(null));
96+
97+
/// <summary>
98+
/// Gets or sets the default user photo
99+
/// </summary>
100+
public BitmapImage DefaultImage
101+
{
102+
get { return (BitmapImage)GetValue(DefaultImageProperty); }
103+
set { SetValue(DefaultImageProperty, value); }
104+
}
105+
106+
/// <summary>
107+
/// Gets or sets a value indicating which view type will be presented, the default value is PictureOnly.
108+
/// </summary>
109+
public ViewType View
110+
{
111+
get { return (ViewType)GetValue(ViewProperty); }
112+
set { SetValue(ViewProperty, value); }
113+
}
114+
115+
/// <summary>
116+
/// Gets or sets a value indicating whether AllowSignInAsDifferentUser menu button is enabled for logged in user.
117+
/// </summary>
118+
public bool AllowSignInAsDifferentUser
119+
{
120+
get { return (bool)GetValue(AllowSignInAsDifferentUserProperty); }
121+
set { SetValue(AllowSignInAsDifferentUserProperty, value); }
122+
}
123+
124+
/// <summary>
125+
/// Gets or sets a value for default sign-in text.
126+
/// </summary>
127+
public string SignInDefaultText
128+
{
129+
get { return (string)GetValue(SignInDefaultTextProperty); }
130+
set { SetValue(SignInDefaultTextProperty, value); }
131+
}
132+
133+
/// <summary>
134+
/// Gets or sets a value for default sign-out text.
135+
/// </summary>
136+
public string SignOutDefaultText
137+
{
138+
get { return (string)GetValue(SignOutDefaultTextProperty); }
139+
set { SetValue(SignOutDefaultTextProperty, value); }
140+
}
141+
142+
/// <summary>
143+
/// Gets or sets a value for default text of the Sign-in-with-another-account button.
144+
/// </summary>
145+
public string SignInAnotherUserDefaultText
146+
{
147+
get { return (string)GetValue(SignInAnotherUserDefaultTextProperty); }
148+
set { SetValue(SignInAnotherUserDefaultTextProperty, value); }
149+
}
150+
151+
/// <summary>
152+
/// Gets the unique identifier for current signed in user.
153+
/// </summary>
154+
public string CurrentUserId
155+
{
156+
get { return (string)GetValue(CurrentUserIdProperty); }
157+
private set { SetValue(CurrentUserIdProperty, value); }
158+
}
159+
}
160+
}

0 commit comments

Comments
 (0)