Skip to content

Commit

Permalink
Bug fixing
Browse files Browse the repository at this point in the history
  • Loading branch information
FrayxRulez committed Jun 28, 2017
1 parent 969a089 commit 89f026c
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 85 deletions.
41 changes: 27 additions & 14 deletions Unigram/Unigram.Core/Helpers/ImageHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,25 +127,38 @@ public static async Task<Color[]> GetAccentAsync(StorageFile sourceFile)
{
var result = new Color[2];

using (var imageStream = await sourceFile.OpenReadAsync())
try
{
var decoder = await BitmapDecoder.CreateAsync(imageStream);
var transform = new BitmapTransform
using (var imageStream = await sourceFile.OpenReadAsync())
{
ScaledWidth = 1,
ScaledHeight = 1
};
var decoder = await BitmapDecoder.CreateAsync(imageStream);
var transform = new BitmapTransform
{
ScaledWidth = 1,
ScaledHeight = 1
};

var pixelData = await decoder.GetPixelDataAsync(decoder.BitmapPixelFormat, decoder.BitmapAlphaMode, transform, ExifOrientationMode.RespectExifOrientation, ColorManagementMode.DoNotColorManage);
var detach = pixelData.DetachPixelData();
var pixelData = await decoder.GetPixelDataAsync(decoder.BitmapPixelFormat, decoder.BitmapAlphaMode, transform, ExifOrientationMode.RespectExifOrientation, ColorManagementMode.DoNotColorManage);
var detach = pixelData.DetachPixelData();

var hsv = ColorsHelper.RgbToHsv(detach[2], detach[1], detach[0]);
hsv[1] = Math.Min(1.0, hsv[1] + 0.05 + 0.1 * (1.0 - hsv[1]));
hsv[2] = Math.Max(0, hsv[2] * 0.65);
var hsv = ColorsHelper.RgbToHsv(detach[2], detach[1], detach[0]);
hsv[1] = Math.Min(1.0, hsv[1] + 0.05 + 0.1 * (1.0 - hsv[1]));
hsv[2] = Math.Max(0, hsv[2] * 0.65);

var rgb = ColorsHelper.HsvToRgb(hsv[0], hsv[1], hsv[2]);
result[0] = Color.FromArgb(0x66, rgb[0], rgb[1], rgb[2]);
result[1] = Color.FromArgb(0x88, rgb[0], rgb[1], rgb[2]);
var rgb = ColorsHelper.HsvToRgb(hsv[0], hsv[1], hsv[2]);
result[0] = Color.FromArgb(0x66, rgb[0], rgb[1], rgb[2]);
result[1] = Color.FromArgb(0x88, rgb[0], rgb[1], rgb[2]);
}
}
catch { }

if (result[0] == null)
{
result[0] = Color.FromArgb(0x66, 0x7A, 0x8A, 0x96);
}
if (result[1] == null)
{
result[1] = Color.FromArgb(0x88, 0x7A, 0x8A, 0x96);
}

return result;
Expand Down
20 changes: 12 additions & 8 deletions Unigram/Unigram.Core/Models/StorageMedia.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,24 @@ public string Caption

private async void LoadThumbnail()
{
if (!File.Attributes.HasFlag(FileAttributes.Temporary))
try
{
using (var thumbnail = await File.GetThumbnailAsync(ThumbnailMode.ListView, 96, ThumbnailOptions.UseCurrentScale))
if (!File.Attributes.HasFlag(FileAttributes.Temporary))
{
if (thumbnail != null)
using (var thumbnail = await File.GetThumbnailAsync(ThumbnailMode.ListView, 96, ThumbnailOptions.UseCurrentScale))
{
var bitmapImage = new BitmapImage();
await bitmapImage.SetSourceAsync(thumbnail);
_thumbnail = bitmapImage;
if (thumbnail != null)
{
var bitmapImage = new BitmapImage();
await bitmapImage.SetSourceAsync(thumbnail);
_thumbnail = bitmapImage;
}
}
}

RaisePropertyChanged(() => Thumbnail);
RaisePropertyChanged(() => Thumbnail);
}
}
catch { }
}

public virtual StorageMedia Clone()
Expand Down
78 changes: 27 additions & 51 deletions Unigram/Unigram/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -228,40 +228,6 @@ public override Task OnInitializeAsync(IActivatedEventArgs args)

public override async Task OnStartAsync(StartKind startKind, IActivatedEventArgs args)
{
//NavigationService.Navigate(typeof(PlaygroundPage2));
//return;
//return Task.CompletedTask;

//PhoneCallPage newPlayer = null;
//CoreApplicationView newView = CoreApplication.CreateNewView();
//var newViewId = 0;
//await newView.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
//{
// newPlayer = new PhoneCallPage();
// Window.Current.Content = newPlayer;
// Window.Current.Activate();
// newViewId = ApplicationView.GetForCurrentView().Id;
//});

//await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () =>
//{
// var overlay = ApplicationView.GetForCurrentView().IsViewModeSupported(ApplicationViewMode.CompactOverlay);
// if (overlay)
// {
// var preferences = ViewModePreferences.CreateDefault(ApplicationViewMode.CompactOverlay);
// preferences.CustomSize = new Size(340, 200);

// var viewShown = await ApplicationViewSwitcher.TryShowAsViewModeAsync(newViewId, ApplicationViewMode.CompactOverlay, preferences);
// }
// else
// {
// //await ApplicationViewSwitcher.SwitchAsync(newViewId);
// await ApplicationViewSwitcher.TryShowAsStandaloneAsync(newViewId);
// }
//});

//return;

if (SettingsHelper.IsAuthorized)
{
if (args is ShareTargetActivatedEventArgs share)
Expand Down Expand Up @@ -293,14 +259,34 @@ public override async Task OnStartAsync(StartKind startKind, IActivatedEventArgs
var backgroundBrush = Application.Current.Resources["TelegramBackgroundTitlebarBrush"] as SolidColorBrush;
contact.ContactPanel.HeaderColor = backgroundBrush.Color;

var store = await ContactManager.RequestStoreAsync(ContactStoreAccessType.AppContactsReadWrite);
var annotationStore = await ContactManager.RequestAnnotationStoreAsync(ContactAnnotationStoreAccessType.AppAnnotationsReadWrite);
var full = await store.GetContactAsync(contact.Contact.Id);
var annotations = await annotationStore.FindAnnotationsForContactAsync(full);

var remote = annotations[0].RemoteId;

NavigationService.Navigate(typeof(DialogPage), new TLPeerUser { UserId = int.Parse(remote.Substring(1)) });
var store = await ContactManager.RequestStoreAsync(ContactStoreAccessType.AppContactsReadWrite);
if (store != null && annotationStore != null)
{
var full = await store.GetContactAsync(contact.Contact.Id);
var annotations = await annotationStore.FindAnnotationsForContactAsync(full);
var first = annotations.FirstOrDefault();
if (first != null)
{
var remote = first.RemoteId;
if (int.TryParse(remote.Substring(1), out int userId))
{
NavigationService.Navigate(typeof(DialogPage), new TLPeerUser { UserId = userId });
}
else
{
NavigationService.Navigate(typeof(MainPage));
}
}
else
{
NavigationService.Navigate(typeof(MainPage));
}
}
else
{
NavigationService.Navigate(typeof(MainPage));
}
}
else if (args is ProtocolActivatedEventArgs protocol)
{
Expand All @@ -319,16 +305,6 @@ public override async Task OnStartAsync(StartKind startKind, IActivatedEventArgs
NavigationService.Navigate(typeof(SignInWelcomePage));
}

// NO! Many tv models have borders!
//// Remove borders on Xbox
//var device = Windows.ApplicationModel.Resources.Core.ResourceContext.GetForCurrentView().QualifierValues;
//bool isXbox = (device.ContainsKey("DeviceFamily") && device["DeviceFamily"] == "Xbox");

//if (isXbox == true)
//{
// Windows.UI.ViewManagement.ApplicationView.GetForCurrentView().SetDesiredBoundsMode(Windows.UI.ViewManagement.ApplicationViewBoundsMode.UseCoreWindow);
//}

Window.Current.Activated -= Window_Activated;
Window.Current.Activated += Window_Activated;
Window.Current.VisibilityChanged -= Window_VisibilityChanged;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
Style="{StaticResource BodyTextBlockStyle}"
TextWrapping="NoWrap"
TextTrimming="CharacterEllipsis">
<Run x:Name="DisplayLabel" Text="{x:Bind ViewModel.Peer.DisplayName}"/>
<Run x:Name="DisplayLabel" Text="{x:Bind ViewModel.Peer.FullName}"/>
<Run Text="{x:Bind ConvertCount(ViewModel, ViewModel.Items.Count)}"/>
</TextBlock>
<TextBlock Text="{x:Bind Convert.DateExtended(ViewModel.Message.Date)}"
Expand Down
25 changes: 14 additions & 11 deletions Unigram/Unigram/Controls/Views/ProxyView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,18 +96,21 @@ public string Password

private void ContentDialog_PrimaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args)
{
if (string.IsNullOrEmpty(Server) || !IPAddress.TryParse(Server, out IPAddress server))
{
VisualUtilities.ShakeView(FieldServer);
args.Cancel = true;
return;
}
if (IsProxyEnabled)
{
if (string.IsNullOrEmpty(Server) || !IPAddress.TryParse(Server, out IPAddress server))
{
VisualUtilities.ShakeView(FieldServer);
args.Cancel = true;
return;
}

if (string.IsNullOrEmpty(Port) || !int.TryParse(Port, out int port))
{
VisualUtilities.ShakeView(FieldPort);
args.Cancel = true;
return;
if (string.IsNullOrEmpty(Port) || !int.TryParse(Port, out int port))
{
VisualUtilities.ShakeView(FieldPort);
args.Cancel = true;
return;
}
}
}

Expand Down
4 changes: 4 additions & 0 deletions Unigram/Unigram/ViewModels/DialogViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1759,6 +1759,10 @@ public async Task ForwardMessagesAsync(IEnumerable<TLMessage> forwardMessages)
clone.FwdFrom.ChannelPost = fwdMessage.Id;
}
}
}
else if (fwdMessage.ToId is TLPeerUser peerUser && peerUser.UserId == SettingsHelper.UserId)
{

}
else
{
Expand Down
4 changes: 4 additions & 0 deletions Unigram/Unigram/ViewModels/ShareViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,10 @@ private void SendExecute()
clone.FwdFrom.ChannelPost = fwdMessage.Id;
}
}
}
else if (fwdMessage.ToId is TLPeerUser peerUser && peerUser.UserId == SettingsHelper.UserId)
{

}
else
{
Expand Down

0 comments on commit 89f026c

Please sign in to comment.