Skip to content

Commit

Permalink
updated for preview 10
Browse files Browse the repository at this point in the history
Still some workarounds for open bugs to Border and Shadow and BindableLayouts
  • Loading branch information
davidortinau committed Nov 9, 2021
1 parent b5dba8c commit 67909ee
Show file tree
Hide file tree
Showing 49 changed files with 1,942 additions and 2,109 deletions.
2 changes: 2 additions & 0 deletions src/WeatherTwentyOne/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
<Image Source="tab_settings.png"
VerticalOptions="Center"
HorizontalOptions="Center"
WidthRequest="40"
HeightRequest="40"
>

</Image>
Expand Down
32 changes: 14 additions & 18 deletions src/WeatherTwentyOne/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,25 +1,21 @@
using Microsoft.Maui;
using Microsoft.Maui.Controls;
using Microsoft.Maui.Controls.Xaml;
using WeatherTwentyOne.Pages;
using WeatherTwentyOne.Pages;

namespace WeatherTwentyOne
namespace WeatherTwentyOne;

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

if(Device.Idiom == TargetIdiom.Phone)
Shell.Current.CurrentItem = PhoneTabs;
if (Device.Idiom == TargetIdiom.Phone)
Shell.Current.CurrentItem = PhoneTabs;

Routing.RegisterRoute("settings", typeof(SettingsPage));
}
Routing.RegisterRoute("settings", typeof(SettingsPage));
}

void TapGestureRecognizer_Tapped(System.Object sender, System.EventArgs e)
{
Shell.Current.GoToAsync("///settings");
}
void TapGestureRecognizer_Tapped(System.Object sender, System.EventArgs e)
{
Shell.Current.GoToAsync("///settings");
}
}
}
52 changes: 23 additions & 29 deletions src/WeatherTwentyOne/Converters/ActiveTabConverter.cs
Original file line number Diff line number Diff line change
@@ -1,37 +1,31 @@
using Microsoft.Maui.Controls;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Globalization;

namespace WeatherTwentyOne.Converters
namespace WeatherTwentyOne.Converters;

public class ActiveTabConverter : IValueConverter
{
public class ActiveTabConverter : IValueConverter
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var target = (string)value;
var tab = (string)parameter;
var target = (string)value;
var tab = (string)parameter;

switch(tab)
{
case "Home":
return (target == "Home") ? "tab_home_on.png" : "tab_home.png";
case "Map":
return (target == "Map") ? "tab_map_on.png" : "tab_map.png";
case "Favorites":
return (target == "Favorites") ? "tab_favorites_on.png" : "tab_favorites.png";
case "Settings":
default:
return (target == "Settings") ? "tab_settings_on.png" : "tab_settings.png";
}
switch(tab)
{
case "Home":
return (target == "Home") ? "tab_home_on.png" : "tab_home.png";
case "Map":
return (target == "Map") ? "tab_map_on.png" : "tab_map.png";
case "Favorites":
return (target == "Favorites") ? "tab_favorites_on.png" : "tab_favorites.png";
case "Settings":
default:
return (target == "Settings") ? "tab_settings_on.png" : "tab_settings.png";
}
}


public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return (string)value;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return (string)value;
}
}
}
32 changes: 14 additions & 18 deletions src/WeatherTwentyOne/Converters/MaxTempOffsetConverter.cs
Original file line number Diff line number Diff line change
@@ -1,25 +1,21 @@
using System;
using System.Globalization;
using Microsoft.Maui;
using Microsoft.Maui.Controls;
using System.Globalization;

namespace WeatherTwentyOne.Converters
namespace WeatherTwentyOne.Converters;

public class MaxTempOffsetConverter : IValueConverter
{
public class MaxTempOffsetConverter : IValueConverter
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
const double max = 90 * 3;
const double max = 90 * 3;

var maxTemp = System.Convert.ToDouble(value) * 3;
var topMargin = max - maxTemp;
var maxTemp = System.Convert.ToDouble(value) * 3;
var topMargin = max - maxTemp;

return new Thickness(0, topMargin, 0, 0);
}
return new Thickness(0, topMargin, 0, 0);
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotSupportedException();
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotSupportedException();
}
}
}
32 changes: 14 additions & 18 deletions src/WeatherTwentyOne/Converters/MinTempOffsetConverter.cs
Original file line number Diff line number Diff line change
@@ -1,25 +1,21 @@
using System;
using System.Globalization;
using Microsoft.Maui;
using Microsoft.Maui.Controls;
using System.Globalization;

namespace WeatherTwentyOne.Converters
namespace WeatherTwentyOne.Converters;

public class MinTempOffsetConverter : IValueConverter
{
public class MinTempOffsetConverter : IValueConverter
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
const double min = 40 * 3;
const double min = 40 * 3;

var minTemp = System.Convert.ToDouble(value) * 3;
var bottomMargin = minTemp - min;
var minTemp = System.Convert.ToDouble(value) * 3;
var bottomMargin = minTemp - min;

return new Thickness(0, 0, 0, bottomMargin);
}
return new Thickness(0, 0, 0, bottomMargin);
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotSupportedException();
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotSupportedException();
}
}
}
31 changes: 14 additions & 17 deletions src/WeatherTwentyOne/Converters/TempSpanConverter.cs
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
using System;
using System.Globalization;
using Microsoft.Maui.Controls;
using System.Globalization;

namespace WeatherTwentyOne.Converters
namespace WeatherTwentyOne.Converters;

public class TempSpanConverter : IMultiValueConverter
{
public class TempSpanConverter : IMultiValueConverter
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
// two values
var minTemp = double.Parse(values[0].ToString()) * 3;
var maxTemp = double.Parse(values[1].ToString()) * 3;
// two values
var minTemp = double.Parse(values[0].ToString()) * 3;
var maxTemp = double.Parse(values[1].ToString()) * 3;

var diff = maxTemp - minTemp;
var diff = maxTemp - minTemp;

return diff;
}
return diff;
}

public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
{
throw new NotSupportedException();
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
{
throw new NotSupportedException();
}
}
14 changes: 14 additions & 0 deletions src/WeatherTwentyOne/GlobalUsings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
global using Microsoft.Extensions.DependencyInjection;
global using Microsoft.Maui;
global using Microsoft.Maui.Controls;
global using Microsoft.Maui.Controls.Hosting;
global using Microsoft.Maui.Controls.Xaml;
global using Microsoft.Maui.Essentials;
global using Microsoft.Maui.Hosting;
global using System;
global using System.Collections.Generic;
global using System.IO;
global using System.Linq;
global using System.Net.Http;
global using System.Threading;
global using System.Threading.Tasks;
63 changes: 27 additions & 36 deletions src/WeatherTwentyOne/MauiProgram.cs
Original file line number Diff line number Diff line change
@@ -1,50 +1,41 @@
using Microsoft.Maui;
using System;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Maui.Hosting;
using Microsoft.Maui.Controls;
using Microsoft.Maui.Controls.Compatibility;
using Microsoft.Maui.Controls.Hosting;
using WeatherTwentyOne.Services;
using Microsoft.Maui.LifecycleEvents;
using Microsoft.Maui.LifecycleEvents;

namespace WeatherTwentyOne
namespace WeatherTwentyOne;

public static class MauiProgram
{
public static class MauiProgram
public static MauiApp CreateMauiApp()
{
public static MauiApp CreateMauiApp()
{
var builder = MauiApp.CreateBuilder();
builder
.UseMauiApp<App>()
.ConfigureFonts(fonts => {
fonts.AddFont("fa-solid-900.ttf", "FontAwesome");
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
fonts.AddFont("OpenSans-SemiBold.ttf", "OpenSansSemiBold");
});
builder.ConfigureLifecycleEvents(lifecycle => {
var builder = MauiApp.CreateBuilder();
builder
.UseMauiApp<App>()
.ConfigureFonts(fonts => {
fonts.AddFont("fa-solid-900.ttf", "FontAwesome");
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
fonts.AddFont("OpenSans-SemiBold.ttf", "OpenSansSemiBold");
});
builder.ConfigureLifecycleEvents(lifecycle => {
#if WINDOWS
lifecycle
.AddWindows(windows => windows.OnLaunched((app, args) => {
var winuiApp = (Microsoft.UI.Xaml.Window)MauiWinUIApplication.Current.Application.Windows[0].Handler!.NativeView!;
winuiApp.SetIcon("Platforms/Windows/trayicon.ico");
}));
lifecycle
.AddWindows(windows => windows.OnLaunched((app, args) => {
var winuiApp = (Microsoft.UI.Xaml.Window)MauiWinUIApplication.Current.Application.Windows[0].Handler!.NativeView!;
winuiApp.SetIcon("Platforms/Windows/trayicon.ico");
}));
#endif
});
});

var services = builder.Services;
var services = builder.Services;
#if WINDOWS
services.AddSingleton<ITrayService, WinUI.TrayService>();
services.AddSingleton<INotificationService, WinUI.NotificationService>();
services.AddSingleton<ITrayService, WinUI.TrayService>();
services.AddSingleton<INotificationService, WinUI.NotificationService>();
#elif MACCATALYST
services.AddSingleton<ITrayService, MacCatalyst.TrayService>();
services.AddSingleton<INotificationService, MacCatalyst.NotificationService>();
services.AddSingleton<ITrayService, MacCatalyst.TrayService>();
services.AddSingleton<INotificationService, MacCatalyst.NotificationService>();
#endif




return builder.Build();
}
return builder.Build();
}
}
}
Loading

0 comments on commit 67909ee

Please sign in to comment.