Ver código fonte

#fix using di instead of non working binding

faqmoroz 1 semana atrás
pai
commit
e10a254cd0

+ 11 - 14
Minolta Remote/AppShell.xaml

@@ -3,19 +3,16 @@
     x:Class="Minolta_Remote.AppShell"
     xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
     xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
-    xmlns:local="clr-namespace:Minolta_Remote"
+    xmlns:local="clr-namespace:Minolta_Remote"   
     Shell.FlyoutBehavior="Disabled"
     Title="Minolta Remote"
     Shell.NavBarIsVisible="True"
     Shell.TabBarBackgroundColor="#121212"
     Shell.TabBarForegroundColor="#FFFFFF"
     Shell.TabBarTitleColor="#FFFFFF"
-    Shell.TabBarDisabledColor="#666666">
-
+    Shell.TabBarDisabledColor="#666666"
+    >
     <Shell.Resources>
-        <!-- Shared camera logic instance -->
-        <local:CameraLogic x:Key="CameraLogic" />
-
         <!-- Tab text styling -->
         <Style TargetType="TabBar">
             <Setter Property="Shell.TabBarTitleColor" Value="#FFFFFF" />
@@ -45,23 +42,23 @@
 
     <Tab Title="Auto Mode">
         <ShellContent
-            Title="Auto Mode"
-            ContentTemplate="{DataTemplate local:MainPage}"
-            Route="AutoMode" />
-    </Tab>
+            Title="Auto Mode"          
+            Route="AutoMode"
+            ContentTemplate="{DataTemplate local:MainPage}"/>          
+     </Tab>
 
     <Tab Title="Bulb Mode">
         <ShellContent
             Title="Bulb Mode"
-            ContentTemplate="{DataTemplate local:ProTab}"
-            Route="BulbMode" />
+            Route="BulbMode" 
+            ContentTemplate="{DataTemplate local:ProTab}"/>       
     </Tab>
 
     <Tab Title="TimeLapse Mode">
         <ShellContent
             Title="TimeLapse Mode"
-            ContentTemplate="{DataTemplate local:TimelapsePage}"
-            Route="TimeLapseMode" />
+            Route="TimeLapseMode"  
+            ContentTemplate="{DataTemplate local:TimelapsePage}"/>       
     </Tab>
 
 </Shell>

+ 3 - 1
Minolta Remote/AppShell.xaml.cs

@@ -1,10 +1,12 @@
+using Minolta_Remote.Services;
+
 namespace Minolta_Remote
 {
     public partial class AppShell : Shell
     {
         public AppShell()
         {
-            InitializeComponent();
+            InitializeComponent();        
         }
     }
 }

+ 2 - 3
Minolta Remote/BusinessLogic.cs → Minolta Remote/CameraLogic.cs

@@ -28,9 +28,8 @@ public class CameraLogic : IMainPageLogic, IProTabLogic, ITimelapseLogic
 {
     private readonly IEspClient _espClient;
 
-    public CameraLogic()
-    {
-        var factory = new EspClientFactory();
+    public CameraLogic(IEspClientFactory factory)
+    {        
         _espClient = factory.CreateEspClient();
     }
 

+ 3 - 3
Minolta Remote/MainPage.xaml.cs

@@ -2,12 +2,12 @@ namespace Minolta_Remote
 {
     public partial class MainPage : BasePage
     {
-        private IMainPageLogic Logic =>
-            (IMainPageLogic)((AppShell)Application.Current.MainPage).Resources["CameraLogic"];
+        public IMainPageLogic Logic { get; }
 
-        public MainPage()
+        public MainPage(IMainPageLogic Logic)
         {
             InitializeComponent();
+            this.Logic = Logic;
         }
 
         private async void Focus_Button_Clicked(object sender, EventArgs e)

+ 8 - 0
Minolta Remote/MauiProgram.cs

@@ -1,4 +1,5 @@
 using Microsoft.Extensions.Logging;
+using Minolta_Remote.Services;
 
 namespace Minolta_Remote
 {
@@ -14,6 +15,13 @@ namespace Minolta_Remote
                     fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
                     fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
                 });
+            builder.Services.AddSingleton<IEspClientFactory, EspClientFactory>();
+            builder.Services.AddSingleton<IMainPageLogic, CameraLogic>();
+            builder.Services.AddSingleton<IProTabLogic, CameraLogic>();
+            builder.Services.AddSingleton<ITimelapseLogic, CameraLogic>();
+            builder.Services.AddTransient<MainPage>();
+            builder.Services.AddTransient<ProTab>();
+            builder.Services.AddTransient<TimelapsePage>();
 
 #if DEBUG
     		builder.Logging.AddDebug();

+ 1 - 2
Minolta Remote/ProTab.xaml

@@ -2,8 +2,7 @@
 <base:BasePage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
              xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
              x:Class="Minolta_Remote.ProTab"
-               xmlns:base="clr-namespace:Minolta_Remote"
-             Title="ProTab"
+             xmlns:base="clr-namespace:Minolta_Remote"
              BackgroundColor="#121212">
 
     <ContentPage.Resources>

+ 4 - 5
Minolta Remote/ProTab.xaml.cs

@@ -2,16 +2,15 @@ namespace Minolta_Remote;
 
 public partial class ProTab : BasePage
 {
-    private IProTabLogic Logic =>
-        (IProTabLogic)((AppShell)Application.Current.MainPage).Resources["CameraLogic"];
-    
-    public ProTab()
+    public IProTabLogic Logic { get; }
+
+    public ProTab(IProTabLogic Logic)
     {
         InitializeComponent();
         ShootTime.Text = "1000";
         SelfiTimer.Text = "0";
         Prefocus.IsToggled = true;
-
+        this.Logic = Logic;
     }
 
     private async void ShootButon_Clicked(object sender, EventArgs e)

+ 2 - 1
Minolta Remote/Services/EspClientFactory.cs

@@ -18,6 +18,7 @@ namespace Minolta_Remote.Services
             var repository = new EspClientRepository(httpClient, config);
 
             return new EspClient(repository);
-        }
+        }       
+      
     }
 }

+ 1 - 2
Minolta Remote/TimelapsePage.xaml

@@ -2,8 +2,7 @@
 <base:BasePage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
              xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
              x:Class="Minolta_Remote.TimelapsePage"
-               xmlns:base="clr-namespace:Minolta_Remote"
-             Title="TimelapsePage"
+             xmlns:base="clr-namespace:Minolta_Remote"            
              BackgroundColor="#121212">
 
     <ContentPage.Resources>

+ 4 - 4
Minolta Remote/TimelapsePage.xaml.cs

@@ -2,14 +2,14 @@ namespace Minolta_Remote;
 
 public partial class TimelapsePage : BasePage
 {
-    private ITimelapseLogic Logic =>
-        (ITimelapseLogic)((AppShell)Application.Current.MainPage).Resources["CameraLogic"];
-    
-    public TimelapsePage()
+    public ITimelapseLogic Logic { get; }
+
+    public TimelapsePage(ITimelapseLogic Logic)
     {
         InitializeComponent();
         PhotoCount.Text = "1";
         Delay.Text = "1";
+        this.Logic = Logic;
     }
 
     private async void ShootButon_Clicked(object sender, EventArgs e)