mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-10-31 13:03:20 -07:00
fix<CommitViewer>: auto hide/show avatar mask
This commit is contained in:
parent
400b8c3af5
commit
9532d4cf8f
2 changed files with 14 additions and 9 deletions
|
@ -42,7 +42,7 @@
|
|||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<Border Grid.Row="0" Grid.RowSpan="3" Grid.Column="0" Width="64" Height="64" HorizontalAlignment="Right" Background="Gray">
|
||||
<Border Grid.Row="0" Grid.RowSpan="3" Grid.Column="0" x:Name="authorAvatarMask" Width="64" Height="64" HorizontalAlignment="Right" Background="Gray">
|
||||
<Path Style="{StaticResource Style.Icon}" Width="56" Height="56" Data="{StaticResource Icon.User}" VerticalAlignment="Bottom"/>
|
||||
</Border>
|
||||
|
||||
|
@ -69,7 +69,7 @@
|
|||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<Border Grid.Row="0" Grid.RowSpan="3" Grid.Column="0" Width="64" Height="64" HorizontalAlignment="Right" Background="Gray">
|
||||
<Border Grid.Row="0" Grid.RowSpan="3" Grid.Column="0" x:Name="committerAvatarMask" Width="64" Height="64" HorizontalAlignment="Right" Background="Gray">
|
||||
<Path Style="{StaticResource Style.Icon}" Width="56" Height="56" Data="{StaticResource Icon.User}" VerticalAlignment="Bottom"/>
|
||||
</Border>
|
||||
|
||||
|
|
|
@ -107,7 +107,7 @@ namespace SourceGit.UI {
|
|||
if (commit.Committer.Time == commit.Author.Time) {
|
||||
committerPanel.Visibility = Visibility.Hidden;
|
||||
|
||||
SetAvatar(authorAvatar, commit.Author.Email);
|
||||
SetAvatar(authorAvatar, authorAvatarMask, commit.Author.Email);
|
||||
} else {
|
||||
committerPanel.Visibility = Visibility.Visible;
|
||||
|
||||
|
@ -115,8 +115,8 @@ namespace SourceGit.UI {
|
|||
committerEmail.Text = commit.Committer.Email;
|
||||
committerTime.Text = commit.Committer.Time;
|
||||
|
||||
SetAvatar(authorAvatar, commit.Author.Email);
|
||||
SetAvatar(committerAvatar, commit.Committer.Email, false);
|
||||
SetAvatar(authorAvatar, authorAvatarMask, commit.Author.Email);
|
||||
SetAvatar(committerAvatar, committerAvatarMask, commit.Committer.Email, false);
|
||||
}
|
||||
} else {
|
||||
committerPanel.Visibility = Visibility.Visible;
|
||||
|
@ -125,8 +125,8 @@ namespace SourceGit.UI {
|
|||
committerEmail.Text = commit.Committer.Email;
|
||||
committerTime.Text = commit.Committer.Time;
|
||||
|
||||
SetAvatar(authorAvatar, commit.Author.Email);
|
||||
SetAvatar(committerAvatar, commit.Committer.Email);
|
||||
SetAvatar(authorAvatar, authorAvatarMask, commit.Author.Email);
|
||||
SetAvatar(committerAvatar, committerAvatarMask, commit.Committer.Email);
|
||||
}
|
||||
|
||||
if (commit.Decorators.Count == 0) {
|
||||
|
@ -136,7 +136,7 @@ namespace SourceGit.UI {
|
|||
}
|
||||
}
|
||||
|
||||
private void SetAvatar(Image img, string email, bool save = true) {
|
||||
private void SetAvatar(Image img, Border mask, string email, bool save = true) {
|
||||
byte[] hash = MD5.Create().ComputeHash(Encoding.Default.GetBytes(email.ToLower().Trim()));
|
||||
string md5 = "";
|
||||
for (int i = 0; i < hash.Length; i++) md5 += hash[i].ToString("x2");
|
||||
|
@ -144,9 +144,13 @@ namespace SourceGit.UI {
|
|||
|
||||
if (!Directory.Exists(AVATAR_PATH)) Directory.CreateDirectory(AVATAR_PATH);
|
||||
|
||||
mask.Visibility = Visibility.Visible;
|
||||
var sha = commit.SHA;
|
||||
|
||||
string filePath = Path.Combine(AVATAR_PATH, md5);
|
||||
if (File.Exists(filePath)) {
|
||||
img.Source = new BitmapImage(new Uri(filePath));
|
||||
mask.Visibility = Visibility.Hidden;
|
||||
} else {
|
||||
var bitmap = new BitmapImage(new Uri("https://www.gravatar.com/avatar/" + md5 + "?d=404"));
|
||||
if (save) {
|
||||
|
@ -159,10 +163,11 @@ namespace SourceGit.UI {
|
|||
encoder.Save(fs);
|
||||
}
|
||||
}
|
||||
|
||||
if (commit.SHA == sha) mask.Visibility = Visibility.Hidden;
|
||||
};
|
||||
}
|
||||
img.Source = bitmap;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue