Skip to content

Commit

Permalink
Merge pull request #63 from egvijayanand/working
Browse files Browse the repository at this point in the history
C# version of SpaceXhistory App
  • Loading branch information
egvijayanand authored Dec 13, 2022
2 parents 0e8c5f3 + a6bf9f4 commit ea2187d
Show file tree
Hide file tree
Showing 62 changed files with 2,359 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Available under the `src` directory:
* `EmbeddedAndroid` - .NET MAUI Page embedded in a Native Android App, targeting .NET 6 (`net6.0-android`)
* `MediaElement` - Sample project in both .NET 6 and 7. Now made available in Preview bits as part of the .NET MAUI CommunityToolkit - And it'll be a separate NuGet package titled `CommunityToolkit.Maui.MediaElement`
* `MauiHotReload` - Sample project to demonstrate **C# Hot Reload** feature supported via [MetadataUpdateHandler](https://learn.microsoft.com/en-us/dotnet/api/system.reflection.metadata.metadataupdatehandlerattribute?view=net-6.0) (refer to HotReloadService.cs). Core logic is abstracted into a base page named `MauiPage`, inherit the content pages from it and implement the UI logic in the override of the abstract `Build()` method. Source is available in the `src\MauiHotReload` folder.
* `WindowsUnpackagedApp` - Sample project to demonstrate running Windows targeted WinUI 3 project as Unpackaged app type.

* C# Samples - C# version of the [.NET MAUI UI Challenge](https://aka.ms/maui/UIChallenge) - [Awesome UIs](https://github.com/jsuarezruiz/dotnet-maui-showcase) without any XAML usage - Stay tuned for more samples ...
- Made available under the `src/C#-Samples/` folder
Expand All @@ -49,3 +50,4 @@ Available under the `src` directory:
- [News App](https://github.com/henduck/MAUINewsApp)
* There's some issue in making use of FlexLayout as a BindableLayout in C# Markup hence replaced it with StackLayout and Grid on two of the pages
- [MAUI Pets](https://github.com/BryanOroxon/MAUIPETS)
- [SpaceX History](https://github.com/EduardoReisDev/SpaceXhistory)
27 changes: 27 additions & 0 deletions src/C#-Samples/SpaceXhistory/SpaceXhistory.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 17.0.31611.283
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SpaceXhistory", "SpaceXhistory\SpaceXhistory.csproj", "{68F3EA60-A5E8-4156-BD93-89448C8F4876}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{68F3EA60-A5E8-4156-BD93-89448C8F4876}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{68F3EA60-A5E8-4156-BD93-89448C8F4876}.Debug|Any CPU.Build.0 = Debug|Any CPU
{68F3EA60-A5E8-4156-BD93-89448C8F4876}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
{68F3EA60-A5E8-4156-BD93-89448C8F4876}.Release|Any CPU.ActiveCfg = Release|Any CPU
{68F3EA60-A5E8-4156-BD93-89448C8F4876}.Release|Any CPU.Build.0 = Release|Any CPU
{68F3EA60-A5E8-4156-BD93-89448C8F4876}.Release|Any CPU.Deploy.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {61F7FB11-1E47-470C-91E2-47F8143E1572}
EndGlobalSection
EndGlobal
12 changes: 12 additions & 0 deletions src/C#-Samples/SpaceXhistory/SpaceXhistory/App.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace SpaceXhistory;

public partial class App : Application
{
public App()
{
InitializeComponent();

MainPage = new Views.BottomTabPage();
}
}

14 changes: 14 additions & 0 deletions src/C#-Samples/SpaceXhistory/SpaceXhistory/App.designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System;
namespace SpaceXhistory.Helpers
{
public static class Constants
{
public static string BaseUrl = "https://api.spacexdata.com/v4/";
}
}

10 changes: 10 additions & 0 deletions src/C#-Samples/SpaceXhistory/SpaceXhistory/Imports.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
global using CommunityToolkit.Maui.Markup;
global using VijayAnand.Toolkit.Markup;

global using MauiFrame = Microsoft.Maui.Controls.Frame;

global using static Microsoft.Maui.Graphics.Colors;
global using static CommunityToolkit.Maui.Markup.GridRowsColumns;
global using static VijayAnand.Toolkit.Markup.ResourceHelper;
global using static VijayAnand.Toolkit.Markup.SwipeViewHelper;
global using static VijayAnand.Toolkit.Markup.VisualStateHelper;
32 changes: 32 additions & 0 deletions src/C#-Samples/SpaceXhistory/SpaceXhistory/MauiProgram.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using CommunityToolkit.Maui;
using Microsoft.Extensions.Logging;

namespace SpaceXhistory;

public static class MauiProgram
{
public static MauiApp CreateMauiApp()
{
var builder = MauiApp.CreateBuilder();
builder
.UseMauiApp<App>()
.UseMauiCommunityToolkit()
.ConfigureFonts(fonts =>
{
fonts.AddFont("GemunuLibre-Bold.ttf", "Bold");
fonts.AddFont("GemunuLibre-ExtraBold.ttf", "ExtraBold");
fonts.AddFont("GemunuLibre-ExtraLight.ttf", "ExtraLight");
fonts.AddFont("GemunuLibre-Light.ttf", "Light");
fonts.AddFont("GemunuLibre-Medium.ttf", "Medium");
fonts.AddFont("GemunuLibre-Regular.ttf", "Regular");
fonts.AddFont("GemunuLibre-SemiBold.ttf", "SemiBold");
});

#if DEBUG
builder.Logging.AddDebug();
#endif

return builder.Build();
}
}

11 changes: 11 additions & 0 deletions src/C#-Samples/SpaceXhistory/SpaceXhistory/Models/Links.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System;
namespace SpaceXhistory.Models
{
public class Links
{
public Patch patch { get; set; }
public string webcast { get; set; }
public object wikipedia { get; set; }
}
}

10 changes: 10 additions & 0 deletions src/C#-Samples/SpaceXhistory/SpaceXhistory/Models/Patch.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System;
namespace SpaceXhistory.Models
{
public class Patch
{
public object small { get; set; }
public object large { get; set; }
}
}

13 changes: 13 additions & 0 deletions src/C#-Samples/SpaceXhistory/SpaceXhistory/Models/Roadster.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
namespace SpaceXhistory.Models
{
public class Roadster
{
public double speed_kph { get; set; }
public double earth_distance_km { get; set; }
public double mars_distance_km { get; set; }
public string wikipedia { get; set; }
public string video { get; set; }
}
}

68 changes: 68 additions & 0 deletions src/C#-Samples/SpaceXhistory/SpaceXhistory/Models/Root.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
using System;
using Newtonsoft.Json;

namespace SpaceXhistory.Models
{
public class Root
{
public Links links { get; set; }
public object success { get; set; }
public string name { get; set; }
public DateTime date_utc { get; set; }
public DateTime date_local { get; set; }
public bool upcoming { get; set; }

[JsonIgnore]
public string Status
{
get
{
if (upcoming)
{
return "upcoming";
}

if (success is bool value)
{
if (value)
{
return "successful";
}
else
{
return "failed";
}
}

return "failed";
}
}

[JsonIgnore]
public Color StatusColor
{
get
{
if (upcoming)
{
return Color.FromHex("#3a86ff");
}

if (success is bool value)
{
if (value)
{
return Color.FromHex("#76c893");
}
else
{
return Color.FromHex("#e63946");
}
}

return Color.FromHex("#e63946");
}
}
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<application android:allowBackup="true" android:icon="@mipmap/appicon" android:roundIcon="@mipmap/appicon_round" android:supportsRtl="true"></application>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using Android.App;
using Android.Content.PM;
using Android.OS;

namespace SpaceXhistory;

[Activity(Theme = "@style/Maui.SplashTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize | ConfigChanges.Density)]
public class MainActivity : MauiAppCompatActivity
{
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using Android.App;
using Android.Runtime;

namespace SpaceXhistory;

[Application]
public class MainApplication : MauiApplication
{
public MainApplication(IntPtr handle, JniHandleOwnership ownership)
: base(handle, ownership)
{
}

protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp();
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#512BD4</color>
<color name="colorPrimaryDark">#2B0B98</color>
<color name="colorAccent">#2B0B98</color>
</resources>

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using Foundation;

namespace SpaceXhistory;

[Register("AppDelegate")]
public class AppDelegate : MauiUIApplicationDelegate
{
protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp();
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>UIDeviceFamily</key>
<array>
<integer>1</integer>
<integer>2</integer>
</array>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>arm64</string>
</array>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>XSAppIconAssets</key>
<string>Assets.xcassets/appicon.appiconset</string>
</dict>
</plist>
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using ObjCRuntime;
using UIKit;

namespace SpaceXhistory;

public class Program
{
// This is the main entry point of the application.
static void Main(string[] args)
{
// if you want to use a different Application Delegate class from "AppDelegate"
// you can specify it here.
UIApplication.Main(args, null, typeof(AppDelegate));
}
}

17 changes: 17 additions & 0 deletions src/C#-Samples/SpaceXhistory/SpaceXhistory/Platforms/Tizen/Main.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;
using Microsoft.Maui;
using Microsoft.Maui.Hosting;

namespace SpaceXhistory;

class Program : MauiApplication
{
protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp();

static void Main(string[] args)
{
var app = new Program();
app.Run(args);
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest package="maui-application-id-placeholder" version="0.0.0" api-version="7" xmlns="http://tizen.org/ns/packages">
<profile name="common" />
<ui-application appid="maui-application-id-placeholder" exec="SpaceXhistory.dll" multiple="false" nodisplay="false" taskmanage="true" type="dotnet" launch_mode="single">
<label>maui-application-title-placeholder</label>
<icon>maui-appicon-placeholder</icon>
<metadata key="http://tizen.org/metadata/prefer_dotnet_aot" value="true" />
</ui-application>
<shortcut-list />
<privileges>
<privilege>http://tizen.org/privilege/internet</privilege>
</privileges>
<dependencies />
<provides-appdefined-privileges />
</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<maui:MauiWinUIApplication
x:Class="SpaceXhistory.WinUI.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:maui="using:Microsoft.Maui"
xmlns:local="using:SpaceXhistory.WinUI">

</maui:MauiWinUIApplication>

Loading

0 comments on commit ea2187d

Please sign in to comment.