bitwarden-android/src/App/Pages/Settings/SettingsHelpPage.cs

189 lines
5.9 KiB
C#
Raw Normal View History

using System;
using Bit.App.Controls;
using Xamarin.Forms;
using Bit.App.Abstractions;
using XLabs.Ioc;
using Bit.App.Resources;
2017-11-21 06:39:49 +03:00
using Bit.App.Utilities;
namespace Bit.App.Pages
{
public class SettingsHelpPage : ExtendedContentPage
{
private readonly IGoogleAnalyticsService _googleAnalyticsService;
public SettingsHelpPage()
{
_googleAnalyticsService = Resolver.Resolve<IGoogleAnalyticsService>();
Init();
}
2017-02-18 05:18:59 +03:00
public ExtendedTextCell EmailCell { get; set; }
public ExtendedTextCell WebsiteCell { get; set; }
public ExtendedTextCell BugCell { get; set; }
public StackLayout StackLayout { get; set; }
private CustomLabel EmailLabel { get; set; }
private CustomLabel WebsiteLabel { get; set; }
private CustomLabel BugLabel { get; set; }
public void Init()
{
2017-02-18 05:18:59 +03:00
EmailCell = new ExtendedTextCell
2016-07-24 02:13:30 +03:00
{
Text = AppResources.EmailUs,
2016-07-24 02:13:30 +03:00
ShowDisclousure = true
};
2016-07-24 02:13:30 +03:00
var emailTable = new CustomTableView
{
Root = new TableRoot
{
2017-11-21 06:39:49 +03:00
new TableSection(Helpers.GetEmptyTableSectionTitle())
2016-07-24 02:13:30 +03:00
{
2017-02-18 05:18:59 +03:00
EmailCell
2016-07-24 02:13:30 +03:00
}
}
};
2017-02-18 05:18:59 +03:00
EmailLabel = new CustomLabel(this)
2016-07-24 02:13:30 +03:00
{
Text = AppResources.EmailUsDescription
2016-07-24 02:13:30 +03:00
};
2017-02-18 05:18:59 +03:00
WebsiteCell = new ExtendedTextCell
2016-07-24 02:13:30 +03:00
{
Text = AppResources.VisitOurWebsite,
2016-07-24 02:13:30 +03:00
ShowDisclousure = true
};
var websiteTable = new CustomTableView
{
NoHeader = true,
Root = new TableRoot
{
2017-11-21 06:39:49 +03:00
new TableSection(Helpers.GetEmptyTableSectionTitle())
2016-07-24 02:13:30 +03:00
{
2017-02-18 05:18:59 +03:00
WebsiteCell
2016-07-24 02:13:30 +03:00
}
}
};
2017-02-18 05:18:59 +03:00
WebsiteLabel = new CustomLabel(this)
2016-07-24 02:13:30 +03:00
{
Text = AppResources.VisitOurWebsiteDescription
2016-07-24 02:13:30 +03:00
};
2017-02-18 05:18:59 +03:00
BugCell = new ExtendedTextCell
2016-07-24 02:13:30 +03:00
{
Text = AppResources.FileBugReport,
2016-07-24 02:13:30 +03:00
ShowDisclousure = true
};
var bugTable = new CustomTableView
{
NoHeader = true,
Root = new TableRoot
{
2017-11-21 06:39:49 +03:00
new TableSection(Helpers.GetEmptyTableSectionTitle())
2016-07-24 02:13:30 +03:00
{
2017-02-18 05:18:59 +03:00
BugCell
2016-07-24 02:13:30 +03:00
}
}
};
2017-02-18 05:18:59 +03:00
BugLabel = new CustomLabel(this)
2016-07-24 02:13:30 +03:00
{
Text = AppResources.FileBugReportDescription
2016-07-24 02:13:30 +03:00
};
2017-02-18 05:18:59 +03:00
StackLayout = new StackLayout
2016-07-24 02:13:30 +03:00
{
2017-02-18 05:18:59 +03:00
Children = { emailTable, EmailLabel, websiteTable, WebsiteLabel, bugTable, BugLabel },
2016-07-24 02:13:30 +03:00
Spacing = 0
};
if(Device.RuntimePlatform == Device.iOS || Device.RuntimePlatform == Device.Windows)
{
2017-10-13 16:11:37 +03:00
ToolbarItems.Add(new DismissModalToolBarItem(this, AppResources.Close));
}
Title = AppResources.HelpAndFeedback;
2017-02-18 05:18:59 +03:00
Content = new ScrollView { Content = StackLayout };
}
protected override void OnAppearing()
{
base.OnAppearing();
EmailCell.Tapped += EmailCell_Tapped;
WebsiteCell.Tapped += WebsiteCell_Tapped;
BugCell.Tapped += BugCell_Tapped;
StackLayout.LayoutChanged += StackLayout_LayoutChanged;
}
protected override void OnDisappearing()
{
base.OnDisappearing();
EmailCell.Tapped -= EmailCell_Tapped;
WebsiteCell.Tapped -= WebsiteCell_Tapped;
BugCell.Tapped -= BugCell_Tapped;
StackLayout.LayoutChanged -= StackLayout_LayoutChanged;
}
private void StackLayout_LayoutChanged(object sender, EventArgs e)
{
WebsiteLabel.WidthRequest = StackLayout.Bounds.Width - WebsiteLabel.Bounds.Left * 2;
EmailLabel.WidthRequest = StackLayout.Bounds.Width - EmailLabel.Bounds.Left * 2;
BugLabel.WidthRequest = StackLayout.Bounds.Width - BugLabel.Bounds.Left * 2;
2016-07-24 02:13:30 +03:00
}
private void EmailCell_Tapped(object sender, EventArgs e)
{
_googleAnalyticsService.TrackAppEvent("HelpEmail");
2016-07-24 02:13:30 +03:00
Device.OpenUri(new Uri("mailto:hello@bitwarden.com"));
}
private void WebsiteCell_Tapped(object sender, EventArgs e)
{
_googleAnalyticsService.TrackAppEvent("HelpWebsite");
2016-10-02 07:20:45 +03:00
Device.OpenUri(new Uri("https://bitwarden.com/contact/"));
2016-07-24 02:13:30 +03:00
}
private void BugCell_Tapped(object sender, EventArgs e)
{
_googleAnalyticsService.TrackAppEvent("HelpBug");
2016-07-24 02:13:30 +03:00
Device.OpenUri(new Uri("https://github.com/bitwarden/mobile"));
}
private class CustomTableView : ExtendedTableView
{
public CustomTableView()
{
Intent = TableIntent.Settings;
EnableScrolling = false;
HasUnevenRows = true;
EnableSelection = true;
VerticalOptions = LayoutOptions.Start;
NoFooter = true;
2016-07-29 07:13:35 +03:00
2017-05-30 21:13:53 +03:00
if(Device.RuntimePlatform == Device.iOS)
2016-07-29 07:13:35 +03:00
{
RowHeight = -1;
EstimatedRowHeight = 44;
}
2016-07-24 02:13:30 +03:00
}
}
private class CustomLabel : Label
{
public CustomLabel(ContentPage page)
{
LineBreakMode = LineBreakMode.WordWrap;
FontSize = Device.GetNamedSize(NamedSize.Small, typeof(Label));
Style = (Style)Application.Current.Resources["text-muted"];
Margin = new Thickness(15, (page.IsLandscape() ? 5 : 0), 15, 25);
}
}
}
}