Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for localized image #183

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Passbook.Generator.Tests/GeneratorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class GeneratorTests
public void EnsurePassIsGeneratedCorrectly()
{
PassGeneratorRequest request = new PassGeneratorRequest();
request.ExpirationDate = new DateTime(2018, 1, 1, 0, 0, 0, DateTimeKind.Local);
request.ExpirationDate = new DateTime(2018, 1, 1, 0, 0, 0, DateTimeKind.Utc);
request.Nfc = new Nfc("My NFC Message", "SKLSJLKJ");

DateTime offset = new DateTime(2018, 01, 05, 12, 00, 0);
Expand Down Expand Up @@ -99,7 +99,7 @@ public void EnsureDuplicteKeysThrowAnException()
public void EnsureFieldHasLocalTime()
{
PassGeneratorRequest request = new PassGeneratorRequest();
request.ExpirationDate = new DateTime(2018, 1, 1, 0, 0, 0, DateTimeKind.Local);
request.ExpirationDate = new DateTime(2018, 1, 1, 0, 0, 0, DateTimeKind.Utc);
request.Nfc = new Nfc("My NFC Message", "SKLSJLKJ");

DateTime offset = new DateTime(2018, 01, 05, 12, 00, 0);
Expand Down
125 changes: 87 additions & 38 deletions Passbook.Generator/Images/PassbookImage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,51 +6,100 @@ public static class PassbookImageExtensions
{
public static string ToFilename(this PassbookImage passbookImage)
{
switch (passbookImage)
String filename;
switch (passbookImage.Type)
{
case PassbookImage.Icon:
return "icon.png";
case PassbookImage.Icon2X:
return "[email protected]";
case PassbookImage.Icon3X:
return "[email protected]";
case PassbookImage.Logo:
return "logo.png";
case PassbookImage.Logo2X:
return "[email protected]";
case PassbookImage.Logo3X:
return "[email protected]";
case PassbookImage.Background:
return "background.png";
case PassbookImage.Background2X:
return "[email protected]";
case PassbookImage.Background3X:
return "[email protected]";
case PassbookImage.Strip:
return "strip.png";
case PassbookImage.Strip2X:
return "[email protected]";
case PassbookImage.Strip3X:
return "[email protected]";
case PassbookImage.Thumbnail:
return "thumbnail.png";
case PassbookImage.Thumbnail2X:
return "[email protected]";
case PassbookImage.Thumbnail3X:
return "[email protected]";
case PassbookImage.Footer:
return "footer.png";
case PassbookImage.Footer2X:
return "[email protected]";
case PassbookImage.Footer3X:
return "[email protected]";
case PassbookImageType.Icon:
filename = "icon.png";
break;
case PassbookImageType.Icon2X:
filename = "[email protected]";
break;
case PassbookImageType.Icon3X:
filename = "[email protected]";
break;
case PassbookImageType.Logo:
filename = "logo.png";
break;
case PassbookImageType.Logo2X:
filename = "[email protected]";
break;
case PassbookImageType.Logo3X:
filename = "[email protected]";
break;
case PassbookImageType.Background:
filename = "background.png";
break;
case PassbookImageType.Background2X:
filename = "[email protected]";
break;
case PassbookImageType.Background3X:
filename = "[email protected]";
break;
case PassbookImageType.Strip:
filename = "strip.png";
break;
case PassbookImageType.Strip2X:
filename = "[email protected]";
break;
case PassbookImageType.Strip3X:
filename = "[email protected]";
break;
case PassbookImageType.Thumbnail:
filename = "thumbnail.png";
break;
case PassbookImageType.Thumbnail2X:
filename = "[email protected]";
break;
case PassbookImageType.Thumbnail3X:
filename = "[email protected]";
break;
case PassbookImageType.Footer:
filename = "footer.png";
break;
case PassbookImageType.Footer2X:
filename = "[email protected]";
break;
case PassbookImageType.Footer3X:
filename = "[email protected]";
break;
default:
throw new NotImplementedException("Unknown PassbookImage type.");
}
if (!String.IsNullOrEmpty(passbookImage.Culture))
{
filename = passbookImage.Culture + "/" + filename;
}
return filename;
}
}

public enum PassbookImage
public struct PassbookImage
{
public PassbookImageType Type { get; set; }
public String LanguageCode { get; set; }

public static readonly PassbookImage Background = new PassbookImage() { Type = PassbookImageType.Background };
public static readonly PassbookImage Background2X = new PassbookImage() { Type = PassbookImageType.Background2X };
public static readonly PassbookImage Background3X = new PassbookImage() { Type = PassbookImageType.Background3X };
public static readonly PassbookImage Icon = new PassbookImage() { Type = PassbookImageType.Icon };
public static readonly PassbookImage Icon2X = new PassbookImage() { Type = PassbookImageType.Icon2X };
public static readonly PassbookImage Icon3X = new PassbookImage() { Type = PassbookImageType.Icon3X };
public static readonly PassbookImage Logo = new PassbookImage() { Type = PassbookImageType.Logo };
public static readonly PassbookImage Logo2X = new PassbookImage() { Type = PassbookImageType.Logo2X };
public static readonly PassbookImage Logo3X = new PassbookImage() { Type = PassbookImageType.Logo3X };
public static readonly PassbookImage Strip = new PassbookImage() { Type = PassbookImageType.Strip };
public static readonly PassbookImage Strip2X = new PassbookImage() { Type = PassbookImageType.Strip2X };
public static readonly PassbookImage Strip3X = new PassbookImage() { Type = PassbookImageType.Strip3X };
public static readonly PassbookImage Thumbnail = new PassbookImage() { Type = PassbookImageType.Thumbnail };
public static readonly PassbookImage Thumbnail2X = new PassbookImage() { Type = PassbookImageType.Thumbnail2X };
public static readonly PassbookImage Thumbnail3X = new PassbookImage() { Type = PassbookImageType.Thumbnail3X };
public static readonly PassbookImage Footer = new PassbookImage() { Type = PassbookImageType.Footer };
public static readonly PassbookImage Footer2X = new PassbookImage() { Type = PassbookImageType.Footer2X };
public static readonly PassbookImage Footer3X = new PassbookImage() { Type = PassbookImageType.Footer3X };
}

public enum PassbookImageType
{
/// <summary>
/// Background image, 180x220 points
Expand Down