Skip to content

Commit

Permalink
Merge pull request #68 from aschuhardt/develop
Browse files Browse the repository at this point in the history
Fix the navbar and bookmarks/home URLs
  • Loading branch information
aschuhardt authored Nov 2, 2023
2 parents b49ed60 + 677132c commit 8aee16b
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 34 deletions.
1 change: 0 additions & 1 deletion Controls/TabCollection.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,6 @@ private void SetupTab(Tab tab)
{
tab.ParentPage = ParentPage;
tab.OpeningUrlInNewTab += (_, arg) => AddTab(arg.Uri);
tab.BookmarkChanged += BookmarkChanged;
tab.InitializedByTabCollection = true;
}

Expand Down
4 changes: 2 additions & 2 deletions Controls/Tabs/BrowserTab.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ private void BuildContextMenu(IContextMenu menu)
new ActionMenuClickHandler(async () =>
{
_browsingDatabase.Bookmarks.Remove(bookmark);
tab.OnBookmarkChanged();
tab.OnLocationChanged();
await Toast.Make(Text.MainPage_TryToggleBookmarked_Bookmark_removed).Show();
}));
}
Expand All @@ -164,7 +164,7 @@ private void BuildContextMenu(IContextMenu menu)
{
bookmark = new Bookmark { Url = tab.Location.ToString(), Title = tab.Title };
_browsingDatabase.Bookmarks.Add(bookmark);
tab.OnBookmarkChanged();
tab.OnLocationChanged();
await Toast.Make(Text.MainPage_TryToggleBookmarked_Bookmark_added).Show();
}));
}
Expand Down
10 changes: 2 additions & 8 deletions Models/Tab.cs
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,6 @@ public bool Selected

public event PropertyChangedEventHandler PropertyChanged;
public event EventHandler<UrlEventArgs> OpeningUrlInNewTab;
public event EventHandler BookmarkChanged;

protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
Expand All @@ -264,11 +263,6 @@ protected bool SetField<T>(ref T field, T value, [CallerMemberName] string prope
return true;
}

public void SetLocationWithoutLoading(Uri location)
{
_location = location;
}

public override int GetHashCode()
{
// ReSharper disable once NonReadonlyMemberInGetHashCode
Expand All @@ -290,8 +284,8 @@ public virtual void OnOpeningUrlInNewTab(UrlEventArgs e)
OpeningUrlInNewTab?.Invoke(this, e);
}

public virtual void OnBookmarkChanged()
public virtual void OnLocationChanged()
{
BookmarkChanged?.Invoke(this, EventArgs.Empty);
OnPropertyChanged(nameof(Location));
}
}
9 changes: 9 additions & 0 deletions Resources/Localization/Text.Designer.cs

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

3 changes: 3 additions & 0 deletions Resources/Localization/Text.resx
Original file line number Diff line number Diff line change
Expand Up @@ -689,4 +689,7 @@ Try again after you've granted the app permission to do so.</value>
<data name="SettingsPage_ExportErrorLogArchive_OK" xml:space="preserve">
<value>OK</value>
</data>
<data name="MainPage_TrySetHomeUrl_Home_URL_cleared" xml:space="preserve">
<value>Home URL cleared</value>
</data>
</root>
23 changes: 10 additions & 13 deletions Views/MainPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,22 +62,20 @@
<SwipeGestureRecognizer x:Name="SwipeDownRecognizer" Direction="Down" Command="{Binding ExpandMenu}" />
<SwipeGestureRecognizer x:Name="SwipeUpRecognizer" Direction="Up" Command="{Binding HideMenu}" />
</VerticalStackLayout.GestureRecognizers>
<FlexLayout Padding="0,2,0,0" Wrap="NoWrap" x:Name="NavigationGrid">
<Grid Padding="0,2,0,0" x:Name="NavigationGrid" ColumnDefinitions="Auto,*,Auto,Auto,Auto">
<ImageButton
FlexLayout.AlignSelf="Start"
FlexLayout.Order="0"
FlexLayout.Shrink="0"
x:Name="PageInfoButton"
Grid.Column="0"
Scale="0.75" IsEnabled="{Binding CurrentTab.CanShowHostCertificate}"
Command="{Binding ShowPageCertificate}"
Source="{AppThemeBinding Light=info_dark.png, Dark=info_light.png}"
SemanticProperties.Description="{x:Static localization:Text.MainPage_PageInformation}"
SemanticProperties.Hint="{x:Static localization:Text.MainPage_PageInformationHint}" />
<Border
FlexLayout.AlignSelf="Stretch"
FlexLayout.Order="1"
FlexLayout.Grow="1"
Margin="0"
Grid.Column="1"
HeightRequest="48" x:Name="UrlEntryBorder">
<Entry
Text="{Binding CurrentTab.RenderUrl}"
Expand All @@ -92,33 +90,32 @@
</Border>
<ImageButton
FlexLayout.AlignSelf="End"
FlexLayout.Order="2"
FlexLayout.Shrink="0"
Scale="0.75" Grid.Column="2" x:Name="BookmarkButton"
Grid.Column="2"
Scale="0.75"
x:Name="BookmarkButton"
Command="{Binding ToggleBookmarked}"
Source="{Binding CurrentTab.Location, Converter={StaticResource BookmarkButtonImageConverter}}"
SemanticProperties.Description="{x:Static localization:Text.MainPage_Bookmark}"
SemanticProperties.Hint="{x:Static localization:Text.MainPage_BookmarkHint}" />
<controls:BiModalImageButton
FlexLayout.AlignSelf="End"
FlexLayout.Order="3"
FlexLayout.Shrink="0"
Scale="0.75" Grid.Column="3" x:Name="HomeButton"
Grid.Column="3"
Scale="0.75"
x:Name="HomeButton"
Command="{Binding LoadHomeUrl}" LongCommand="{Binding SetHomeUrl}"
Source="{Binding CurrentTab.Location, Converter={StaticResource HomeButtonImageConverter}}"
SemanticProperties.Description="{x:Static localization:Text.MainPage_Home}"
SemanticProperties.Hint="{x:Static localization:Text.MainPage_HomeHint}" />
<ImageButton
FlexLayout.AlignSelf="End"
FlexLayout.Order="4"
FlexLayout.Shrink="0"
Scale="0.75" Grid.Column="4" x:Name="FindNextButton"
Command="{Binding FindNextInPage}"
IsVisible="{Binding CurrentTab.HasFindNextQuery}"
Source="{AppThemeBinding Light=next_dark.png, Dark=next_light.png}"
SemanticProperties.Description="{x:Static localization:Text.MainPage_Next}"
SemanticProperties.Hint="{x:Static localization:Text.MainPage_NextHint}" />
</FlexLayout>
</Grid>
<VerticalStackLayout x:Name="ExpandableMenu" HeightRequest="0" IsClippedToBounds="True">
<Button Text="{x:Static localization:Text.MainPage_FindInPage}" HorizontalOptions="Fill"
Command="{Binding FindInPage}"
Expand Down
29 changes: 19 additions & 10 deletions Views/MainPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -638,13 +638,22 @@ private void TrySetHomeUrl()

try
{
_settingsDatabase.HomeUrl = CurrentTab.Location.ToString();
var currentHomeUrl = _settingsDatabase.HomeUrl;

_logger.LogInformation(@"Home URI set to {URI}", _settingsDatabase.HomeUrl);

CurrentTab.OnBookmarkChanged(); // force buttons to update
if (!string.IsNullOrWhiteSpace(currentHomeUrl) && CurrentTab.Location.AreGeminiUrlsEqual(currentHomeUrl))
{
_settingsDatabase.HomeUrl = null;
_logger.LogInformation(@"Home URI cleared");
this.ShowToast(Text.MainPage_TrySetHomeUrl_Home_URL_cleared, ToastDuration.Short);
}
else
{
_settingsDatabase.HomeUrl = CurrentTab.Location.ToString();
_logger.LogInformation(@"Home URI set to {URI}", _settingsDatabase.HomeUrl);
this.ShowToast(Text.MainPage_TrySetHomeUrl_Home_set, ToastDuration.Short);
}

this.ShowToast(Text.MainPage_TrySetHomeUrl_Home_set, ToastDuration.Short);
CurrentTab.OnLocationChanged(); // force buttons to update
}
catch (Exception e)
{
Expand Down Expand Up @@ -698,23 +707,23 @@ private void TryToggleBookmarked()
if (_browsingDatabase.TryGetBookmark(CurrentTab.Location, out var bookmark))
{
_browsingDatabase.Bookmarks.Remove(bookmark);
CurrentTab.OnBookmarkChanged(); // force buttons to update
CurrentTab.OnLocationChanged(); // force buttons to update

_logger.LogInformation(@"Removing bookmarked location {URI}", bookmark.Url);

this.ShowToast(Text.MainPage_TryToggleBookmarked_Bookmark_removed, ToastDuration.Short);
}
else
{
_browsingDatabase.Bookmarks.Add(new Bookmark
bookmark = new Bookmark
{
Title = CurrentTab.Title ?? CurrentTab.Location.Segments.LastOrDefault() ?? CurrentTab.Location.Host,
Url = CurrentTab.Location.ToString()
});

CurrentTab.OnBookmarkChanged(); // force buttons to update
};

_browsingDatabase.Bookmarks.Add(bookmark);
_logger.LogInformation(@"Set bookmarked location {URI}", bookmark.Url);
CurrentTab.OnLocationChanged(); // force buttons to update

this.ShowToast(Text.MainPage_TryToggleBookmarked_Bookmark_added, ToastDuration.Short);
}
Expand Down

0 comments on commit 8aee16b

Please sign in to comment.