Upload and share photo

This commit is contained in:
2016-01-20 14:33:12 +01:00
parent 0acfaecb59
commit ca793f7ff4
13 changed files with 103 additions and 44 deletions
+12 -12
View File
@@ -20,23 +20,23 @@ namespace YJMPD_UWP
// =======================
// SINGLETONS
// =======================
private static GeoHandler geohandler = new GeoHandler();
private static PhotoHandler photohandler = new PhotoHandler();
public static GeoHandler Geo
public static PhotoHandler Photo
{
get
{
return geohandler;
return photohandler;
}
}
private static CompassHandler compasshandler = new CompassHandler();
private static GameHandler gamehandler = new GameHandler();
public static CompassHandler Compass
public static GameHandler Game
{
get
{
return compasshandler;
return gamehandler;
}
}
@@ -60,23 +60,23 @@ namespace YJMPD_UWP
}
}
private static GameHandler gamehandler = new GameHandler();
private static GeoHandler geohandler = new GeoHandler();
public static GameHandler Game
public static GeoHandler Geo
{
get
{
return gamehandler;
return geohandler;
}
}
private static PhotoHandler photohandler = new PhotoHandler();
private static CompassHandler compasshandler = new CompassHandler();
public static PhotoHandler Photo
public static CompassHandler Compass
{
get
{
return photohandler;
return compasshandler;
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.8 KiB

@@ -4,9 +4,9 @@ namespace YJMPD_UWP.Helpers.EventArgs
{
public class PhotoTakenEventArgs : System.EventArgs
{
public SoftwareBitmapSource Photo { get; private set; }
public string Photo { get; private set; }
public PhotoTakenEventArgs(SoftwareBitmapSource photo)
public PhotoTakenEventArgs(string photo)
{
Photo = photo;
}
+16 -3
View File
@@ -58,7 +58,10 @@ namespace YJMPD_UWP.Model
App.Game.MoveToWaiting();
break;
case Command.PictureUrl:
//Download picture from URL and display to participants
if (!App.Game.Selected)
App.Photo.UpdatePhotoTaken(o[Command.PictureUrl.ToString()].ToString());
App.Game.MoveToStarted();
break;
default:
//Do nothing
@@ -98,7 +101,6 @@ namespace YJMPD_UWP.Model
lon = App.Geo.Position.Coordinate.Point.Position.Longitude,
lat = App.Geo.Position.Coordinate.Point.Position.Latitude
});
Debug.WriteLine(obj.ToString(Formatting.None));
await App.Network.Write(obj.ToString(Formatting.None));
return true;
@@ -111,7 +113,18 @@ namespace YJMPD_UWP.Model
command = Command.PlayerRemoved.ToString(),
name = Settings.Username
});
Debug.WriteLine(obj.ToString(Formatting.None));
await App.Network.Write(obj.ToString(Formatting.None));
return true;
}
public async Task<bool> SendPicture(string url)
{
JObject obj = JObject.FromObject(new
{
command = Command.PictureUrl.ToString(),
pictureurl = url
});
await App.Network.Write(obj.ToString(Formatting.None));
return true;
+13 -4
View File
@@ -53,6 +53,12 @@ namespace YJMPD_UWP.Model
{
Players = new List<Player>();
Status = GameStatus.STOPPED;
App.Photo.OnPhotoTaken += Photo_OnPhotoTaken;
}
private void Photo_OnPhotoTaken(object sender, PhotoTakenEventArgs e)
{
App.Api.SendPicture(e.Photo);
}
public void AddPlayer(string username)
@@ -78,6 +84,12 @@ namespace YJMPD_UWP.Model
UpdateGameStatus(GameStatus.WAITING);
}
public void MoveToStarted()
{
App.Navigate(typeof(GameView));
UpdateGameStatus(GameStatus.STARTED);
}
public void RemovePlayer(string username)
{
for(int i=Players.Count-1; i>=0; i--)
@@ -179,10 +191,7 @@ namespace YJMPD_UWP.Model
App.Navigate(typeof(WaitingView));
break;
case GameStatus.STARTED:
if (Selected && App.Photo.Photo == null)
App.Navigate(typeof(PhotoView));
else
App.Navigate(typeof(GameView));
App.Navigate(typeof(GameView));
break;
case GameStatus.ENDED:
App.Navigate(typeof(ScoreView));
+2
View File
@@ -58,6 +58,8 @@ namespace YJMPD_UWP.Model
if (Status != NetworkStatus.CONNECTED)
return false;
Debug.WriteLine(data);
dout.WriteString(data + Environment.NewLine);
await dout.StoreAsync();
await dout.FlushAsync();
+11 -6
View File
@@ -1,6 +1,8 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Threading.Tasks;
using Windows.Graphics.Imaging;
@@ -17,7 +19,7 @@ namespace YJMPD_UWP.Model
public delegate void OnPhotoTakenHandler(object sender, PhotoTakenEventArgs e);
public event OnPhotoTakenHandler OnPhotoTaken;
public SoftwareBitmapSource Photo { get; private set; }
public string Photo { get; private set; }
public PhotoHandler()
{
@@ -29,7 +31,7 @@ namespace YJMPD_UWP.Model
Photo = null;
}
private void UpdatePhotoTaken(SoftwareBitmapSource photo)
public void UpdatePhotoTaken(string photo)
{
Photo = photo;
@@ -63,9 +65,9 @@ namespace YJMPD_UWP.Model
SoftwareBitmapSource bitmapSource = new SoftwareBitmapSource();
await bitmapSource.SetBitmapAsync(softwareBitmapBGR8);
await UploadImage(stream.AsStream());
string photoURL = await UploadImage(stream.AsStream());
UpdatePhotoTaken(bitmapSource);
UpdatePhotoTaken(photoURL);
}
public async Task<string> UploadImage(Stream file)
@@ -79,8 +81,11 @@ namespace YJMPD_UWP.Model
{
var response = await hc.PostAsync(url, postdata);
response.EnsureSuccessStatusCode();
Debug.WriteLine(await response.Content.ReadAsStringAsync());
return await response.Content.ReadAsStringAsync();
string imageurl = await response.Content.ReadAsStringAsync();
string imageid = new List<string>(imageurl.Split('/')).Last();
return imageurl + "/" + imageid;
}
catch
{
+36 -4
View File
@@ -1,20 +1,49 @@
using Windows.UI.Xaml.Media;
using System;
using System.Diagnostics;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Media.Imaging;
namespace YJMPD_UWP.ViewModels
{
public class PhotoVM : TemplateVM
{
private ImageSource photo;
private string photo;
DispatcherTimer timer;
int secondsleft = 60;
public PhotoVM() : base("Photo")
{
App.Photo.OnPhotoTaken += Photo_OnPhotoTaken;
photo = App.Photo.Photo;
timer = new DispatcherTimer();
timer.Interval = TimeSpan.FromSeconds(1);
timer.Tick += Timer_Tick;
if (ControlsVisible)
timer.Start();
}
private void Timer_Tick(object sender, object e)
{
NotifyPropertyChanged(nameof(TimeOut));
secondsleft--;
if(secondsleft <= 0)
{
App.Game.Stop();
}
}
private void Photo_OnPhotoTaken(object sender, Helpers.EventArgs.PhotoTakenEventArgs e)
{
dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
{
timer.Stop();
secondsleft = 60;
photo = e.Photo;
NotifyPropertyChanged(nameof(Photo));
NotifyPropertyChanged(nameof(PhotoVisible));
@@ -42,7 +71,7 @@ namespace YJMPD_UWP.ViewModels
{
get
{
return "Take a photo within 1 minute";
return "Take a photo within " + secondsleft + " seconds";
}
}
@@ -50,7 +79,10 @@ namespace YJMPD_UWP.ViewModels
{
get
{
return photo;
if (photo == null || photo == "")
return new BitmapImage(new Uri("ms-appx:///Assets/Error.png"));
return new BitmapImage(new Uri(photo));
}
}
}
+10 -10
View File
@@ -11,14 +11,14 @@
<Page.Resources>
<convert:BoolToVisibilityConverter x:Key="BoolToVisConverter" />
</Page.Resources>
<ScrollViewer>
<Grid Style="{StaticResource BaseGrid}">
<Image Name="Photo" Stretch="UniformToFill" Source="{Binding Photo}" Visibility="{Binding PhotoVisible, Converter={StaticResource BoolToVisConverter}}"/>
<StackPanel Visibility="{Binding ControlsVisible, Converter={StaticResource BoolToVisConverter}}">
<TextBlock Text="{Binding TimeOut}" />
<Button Content="Take Photo" Style="{StaticResource Green}" Click="PhotoButton_Click" />
</StackPanel>
</Grid>
</ScrollViewer>
<Grid Style="{StaticResource BaseGrid}">
<ScrollViewer VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto" ZoomMode="Enabled" Visibility="{Binding PhotoVisible, Converter={StaticResource BoolToVisConverter}}">
<Image Name="Photo" Source="{Binding Photo}"/>
</ScrollViewer>
<StackPanel Visibility="{Binding ControlsVisible, Converter={StaticResource BoolToVisConverter}}">
<TextBlock Text="{Binding TimeOut}" />
<Button Content="Take Photo" Style="{StaticResource Green}" Click="PhotoButton_Click" />
</StackPanel>
</Grid>
</Page>
+1 -3
View File
@@ -159,9 +159,7 @@
</ItemGroup>
<ItemGroup>
<Content Include="Assets\4-[Omgezet].png" />
<Content Include="Assets\about-button.png" />
<Content Include="Assets\settings-button.png" />
<Content Include="Assets\start-button2.png" />
<Content Include="Assets\Error.png" />
<Content Include="Properties\Default.rd.xml" />
<Content Include="Assets\LockScreenLogo.scale-200.png" />
<Content Include="Assets\SplashScreen.scale-200.png" />