Skip to content

Commit

Permalink
Improved connection settings and fixed some other bugs #131
Browse files Browse the repository at this point in the history
Signed-off-by: Christoph Hofmann <[email protected]>
  • Loading branch information
hoffe86 committed Jan 12, 2020
1 parent 5afd81e commit f1b0370
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 17 deletions.
2 changes: 1 addition & 1 deletion OpenHAB.Windows/Controls/FrameWidget.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
SelectionMode="None">
<GridView.ItemsPanel>
<ItemsPanelTemplate>
<VariableSizedWrapGrid ItemHeight="106" ItemWidth="306" />
<VariableSizedWrapGrid ItemHeight="100" ItemWidth="300" />
</ItemsPanelTemplate>
</GridView.ItemsPanel>
</GridView>
Expand Down
6 changes: 3 additions & 3 deletions OpenHAB.Windows/Strings/en-us/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@
<value>openHAB URL</value>
</data>
<data name="MessageNotConfigured" xml:space="preserve">
<value>Connection settings are not invalid.
<value>Connection settings are not configured.
Please select demo mode or configure local/remote OpenHab connection information.</value>
</data>
<data name="MessagesNotReachable" xml:space="preserve">
Expand All @@ -180,7 +180,7 @@ Go to app settings (gear icon) to check the connection configuration.</value>
<value>Settings</value>
</data>
<data name="UsernameHeader.Text" xml:space="preserve">
<value>went</value>
<value>Username</value>
</data>
<data name="NoItemsOrOpenHabNotAvailable.Text" xml:space="preserve">
<value>No sitemaps available</value>
Expand All @@ -198,7 +198,7 @@ Go to app settings (gear icon) to check the connection configuration.</value>
<value>Loading data...</value>
</data>
<data name="MessageSettingsConnectionConfigInvalid" xml:space="preserve">
<value>Connection settings are not invalid.
<value>Connection settings are invalid.
Please select demo mode or configure local/remote connection.</value>
</data>
<data name="AppLanguage.Text" xml:space="preserve">
Expand Down
2 changes: 1 addition & 1 deletion OpenHAB.Windows/View/MainPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@
Color="Black" />
</Grid.Background>
<NavigationView x:Name="SitemapNavigation"
Header="{x:Bind Vm.SelectedSitemap.Label, Mode=OneWay}"
Header="{x:Bind Vm.Subtitle, Mode=OneWay}"
MenuItemsSource="{x:Bind Vm.Sitemaps, Mode=OneWay}"
MenuItemTemplate="{StaticResource NavSitemapTemplate}"
IsBackButtonVisible="Collapsed"
Expand Down
10 changes: 5 additions & 5 deletions OpenHAB.Windows/View/SettingsPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@
</StackPanel>
</StackPanel>
</DataTemplate>

</Page.Resources>

<ScrollViewer Grid.Row="1"
Expand Down Expand Up @@ -145,8 +144,9 @@
</Flyout>
</Button.Flyout>
<StackPanel HorizontalAlignment="Left">
<TextBlock x:Uid="LocalSettings" />
<TextBlock Text="{Binding Url}" />
<TextBlock x:Uid="LocalSettings"
FontSize="16" />
<TextBlock Text="{Binding Subtitle}" />
</StackPanel>
</Button>
<Button Margin="10"
Expand All @@ -162,8 +162,8 @@
</Flyout>
</Button.Flyout>
<StackPanel>
<TextBlock x:Uid="RemoteSettings" />
<TextBlock Text="{Binding Url}" />
<TextBlock x:Uid="RemoteSettings" FontSize="16" />
<TextBlock Text="{Binding Subtitle}" />
</StackPanel>
</Button>
</StackPanel>
Expand Down
2 changes: 0 additions & 2 deletions OpenHAB.Windows/View/SettingsPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using GalaSoft.MvvmLight.Messaging;
using Microsoft.Extensions.Logging;
using OpenHAB.Core;
using OpenHAB.Core.Messages;
using OpenHAB.Core.Services;
using OpenHAB.Core.ViewModel;
Expand Down Expand Up @@ -38,7 +37,6 @@ public SettingsPage()

private async void HandleSettingsUpdate(SettingsUpdatedMessage msg)
{

try
{
if (msg.IsSettingsValid)
Expand Down
2 changes: 2 additions & 0 deletions Openhab.Core/Common/OpenHABHttpClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ public static HttpClient Client(OpenHABHttpClientType connectionType, Settings s
/// <returns>The HttpClient instance.</returns>
public static HttpClient DisposableClient(OpenHABHttpClientType connectionType, Settings settings)
{
_logger = (ILogger<OpenHABHttpClient>)DIService.Instance.Services.GetService(typeof(ILogger<OpenHABHttpClient>));
_settings = settings;

return InitClient(connectionType, true);
}

Expand Down
2 changes: 1 addition & 1 deletion Openhab.Core/SDK/OpenHABClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ public async Task SendCommand(OpenHABItem item, string command)
var settings = _settingsService.Load();
var client = OpenHABHttpClient.Client(_connectionType, settings);
var content = new StringContent(command);

var result = await client.PostAsync(item.Link, content);
if (!result.IsSuccessStatusCode)
{
Expand Down
39 changes: 36 additions & 3 deletions Openhab.Core/ViewModel/ConnectionConfigViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
using GalaSoft.MvvmLight.Command;
using OpenHAB.Core.Model;
using OpenHAB.Core.SDK;
using Windows.ApplicationModel.Core;
using Windows.UI.Core;

namespace OpenHAB.Core.ViewModel
{
Expand Down Expand Up @@ -59,6 +61,31 @@ public string Url

SetProperty(ref _url, tempUrl);
_connectionConfig.Url = _url;

OnPropertyChanged(nameof(Subtitle));
}
}

/// <summary>
/// Gets the subtitle.
/// </summary>
/// <value>The subtitle.</value>
public string Subtitle
{
get
{
if (string.IsNullOrEmpty(_url))
{
return "Not configured";
}

if (Uri.TryCreate(_url, UriKind.Absolute, out Uri uri) &&
string.Compare(uri.Scheme.ToUpperInvariant(), "HTTPS", StringComparison.InvariantCulture) == 0)
{
return "Conntected to " + _url;
}

return "Unsecure connected to" + _url;
}
}

Expand Down Expand Up @@ -121,15 +148,21 @@ private async void CheckLocalUrl(object parameter)

string url = parameter.ToString();

UrlState = OpenHABUrlState.Unknown;
OpenHABUrlState urlState = OpenHABUrlState.Unknown;
if (await _openHabsdk.CheckUrlReachability(url, Common.OpenHABHttpClientType.Local).ConfigureAwait(false))
{
UrlState = OpenHABUrlState.OK;
urlState = OpenHABUrlState.OK;
}
else
{
UrlState = OpenHABUrlState.Failed;
urlState = OpenHABUrlState.Failed;
}

CoreDispatcher dispatcher = CoreApplication.MainView.CoreWindow.Dispatcher;
await dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () =>
{
UrlState = urlState;
});
}
}
}
4 changes: 3 additions & 1 deletion Openhab.Core/ViewModel/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,8 @@ await dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () =>
_openHabsdk.StartItemUpdates();
OpenLastOrDefaultSitemap();
Subtitle = SelectedSitemap.Label;
IsDataLoading = false;
});
}
Expand Down Expand Up @@ -321,7 +323,7 @@ public void WidgetGoBack()
{
OpenHABWidget widget = WidgetNavigationService.GoBack();

Subtitle = widget == null ? string.Empty : widget.Label;
Subtitle = widget == null ? SelectedSitemap.Label: widget.Label;
SetWidgetsOnScreen(widget != null ? widget.LinkedPage.Widgets : SelectedSitemap.Widgets);
}

Expand Down

0 comments on commit f1b0370

Please sign in to comment.