1
0
mirror of https://github.com/bitwarden/mobile synced 2026-01-07 02:53:56 +00:00

settings features page setup with analytics cell

This commit is contained in:
Kyle Spearrin
2017-05-27 14:52:37 -04:00
parent f7f4289614
commit d392dc82a1
6 changed files with 177 additions and 25 deletions

View File

@@ -0,0 +1,134 @@
using System;
using Bit.App.Abstractions;
using Bit.App.Resources;
using Xamarin.Forms;
using XLabs.Ioc;
using Bit.App.Controls;
using Acr.UserDialogs;
using Plugin.Settings.Abstractions;
using Plugin.Fingerprint.Abstractions;
using PushNotification.Plugin.Abstractions;
namespace Bit.App.Pages
{
public class SettingsFeaturesPage : ExtendedContentPage
{
private readonly IAuthService _authService;
private readonly IUserDialogs _userDialogs;
private readonly ISettings _settings;
private readonly IFingerprint _fingerprint;
private readonly IPushNotification _pushNotification;
private readonly IGoogleAnalyticsService _googleAnalyticsService;
public SettingsFeaturesPage()
{
_authService = Resolver.Resolve<IAuthService>();
_userDialogs = Resolver.Resolve<IUserDialogs>();
_settings = Resolver.Resolve<ISettings>();
_fingerprint = Resolver.Resolve<IFingerprint>();
_pushNotification = Resolver.Resolve<IPushNotification>();
_googleAnalyticsService = Resolver.Resolve<IGoogleAnalyticsService>();
Init();
}
private StackLayout StackLayout { get; set; }
private ExtendedSwitchCell AnalyticsCell { get; set; }
private Label AnalyticsLabel { get; set; }
private void Init()
{
AnalyticsCell = new ExtendedSwitchCell
{
Text = AppResources.DisableGA,
On = _settings.GetValueOrDefault(Constants.SettingGaOptOut, false)
};
var analyticsTable = new FormTableView
{
Root = new TableRoot
{
new TableSection(" ")
{
AnalyticsCell
}
}
};
AnalyticsLabel = new Label
{
Text = AppResources.DisbaleGADescription,
LineBreakMode = LineBreakMode.WordWrap,
FontSize = Device.GetNamedSize(NamedSize.Small, typeof(Label)),
Style = (Style)Application.Current.Resources["text-muted"],
Margin = new Thickness(15, (this.IsLandscape() ? 5 : 0), 15, 25)
};
StackLayout = new StackLayout
{
Children = { analyticsTable, AnalyticsLabel },
Spacing = 0
};
var scrollView = new ScrollView
{
Content = StackLayout
};
if(Device.OS == TargetPlatform.iOS)
{
analyticsTable.RowHeight = -1;
analyticsTable.EstimatedRowHeight = 70;
}
Title = AppResources.Features;
Content = scrollView;
}
protected override void OnAppearing()
{
base.OnAppearing();
AnalyticsCell.OnChanged += AnalyticsCell_Changed;
StackLayout.LayoutChanged += Layout_LayoutChanged;
}
protected override void OnDisappearing()
{
base.OnDisappearing();
AnalyticsCell.OnChanged -= AnalyticsCell_Changed;
StackLayout.LayoutChanged -= Layout_LayoutChanged;
}
private void Layout_LayoutChanged(object sender, EventArgs e)
{
AnalyticsLabel.WidthRequest = StackLayout.Bounds.Width - AnalyticsLabel.Bounds.Left * 2;
}
private void AnalyticsCell_Changed(object sender, ToggledEventArgs e)
{
var cell = sender as ExtendedSwitchCell;
if(cell == null)
{
return;
}
_settings.AddOrUpdateValue(Constants.SettingGaOptOut, cell.On);
_googleAnalyticsService.SetAppOptOut(cell.On);
}
private class FormTableView : ExtendedTableView
{
public FormTableView()
{
Intent = TableIntent.Settings;
EnableScrolling = false;
HasUnevenRows = true;
EnableSelection = true;
VerticalOptions = LayoutOptions.Start;
NoFooter = true;
}
}
}
}

View File

@@ -40,7 +40,6 @@ namespace Bit.App.Pages
private ExtendedTextCell TwoStepCell { get; set; }
private ExtendedTextCell ChangeMasterPasswordCell { get; set; }
private ExtendedTextCell ChangeEmailCell { get; set; }
private ExtendedSwitchCell AnalyticsCell { get; set; }
private ExtendedTextCell FoldersCell { get; set; }
private ExtendedTextCell SyncCell { get; set; }
private ExtendedTextCell LockCell { get; set; }
@@ -48,6 +47,7 @@ namespace Bit.App.Pages
private ExtendedTextCell AboutCell { get; set; }
private ExtendedTextCell HelpCell { get; set; }
private ExtendedTextCell RateCell { get; set; }
private ExtendedTextCell FeaturesCell { get; set; }
private LongDetailViewCell RateCellLong { get; set; }
private ExtendedTableView Table { get; set; }
@@ -104,12 +104,6 @@ namespace Bit.App.Pages
ShowDisclousure = true
};
AnalyticsCell = new ExtendedSwitchCell
{
Text = AppResources.DisableGA,
On = _settings.GetValueOrDefault(Constants.SettingGaOptOut, false)
};
FoldersCell = new ExtendedTextCell
{
Text = AppResources.Folders,
@@ -144,9 +138,15 @@ namespace Bit.App.Pages
ShowDisclousure = true
};
FeaturesCell = new ExtendedTextCell
{
Text = AppResources.Features,
ShowDisclousure = true
};
var otherSection = new TableSection(AppResources.Other)
{
AnalyticsCell,
FeaturesCell,
AboutCell,
HelpCell
};
@@ -201,7 +201,6 @@ namespace Bit.App.Pages
base.OnAppearing();
PinCell.OnChanged += PinCell_Changed;
AnalyticsCell.OnChanged += AnalyticsCell_Changed;
LockOptionsCell.Tapped += LockOptionsCell_Tapped;
TwoStepCell.Tapped += TwoStepCell_Tapped;
ChangeMasterPasswordCell.Tapped += ChangeMasterPasswordCell_Tapped;
@@ -216,8 +215,9 @@ namespace Bit.App.Pages
SyncCell.Tapped += SyncCell_Tapped;
LockCell.Tapped += LockCell_Tapped;
LogOutCell.Tapped += LogOutCell_Tapped;
AboutCell.Tapped += AboutCell_Tapped;
AboutCell.Tapped += AboutCell_Tapped;
HelpCell.Tapped += HelpCell_Tapped;
FeaturesCell.Tapped += FeaturesCell_Tapped;
if(RateCellLong != null)
{
@@ -235,7 +235,6 @@ namespace Bit.App.Pages
base.OnDisappearing();
PinCell.OnChanged -= PinCell_Changed;
AnalyticsCell.OnChanged -= AnalyticsCell_Changed;
LockOptionsCell.Tapped -= LockOptionsCell_Tapped;
TwoStepCell.Tapped -= TwoStepCell_Tapped;
ChangeMasterPasswordCell.Tapped -= ChangeMasterPasswordCell_Tapped;
@@ -252,6 +251,7 @@ namespace Bit.App.Pages
LogOutCell.Tapped -= LogOutCell_Tapped;
AboutCell.Tapped -= AboutCell_Tapped;
HelpCell.Tapped -= HelpCell_Tapped;
FeaturesCell.Tapped -= FeaturesCell_Tapped;
if(RateCellLong != null)
{
@@ -421,18 +421,6 @@ namespace Bit.App.Pages
}
}
private void AnalyticsCell_Changed(object sender, ToggledEventArgs e)
{
var cell = sender as ExtendedSwitchCell;
if (cell == null)
{
return;
}
_settings.AddOrUpdateValue(Constants.SettingGaOptOut, cell.On);
_googleAnalyticsService.SetAppOptOut(cell.On);
}
private void PinEntered(SettingsPinPage page)
{
page.PinControl.Entry.Unfocus();
@@ -450,6 +438,11 @@ namespace Bit.App.Pages
}
}
private void FeaturesCell_Tapped(object sender, EventArgs e)
{
Navigation.PushModalAsync(new ExtendedNavigationPage(new SettingsFeaturesPage()));
}
private void FoldersCell_Tapped(object sender, EventArgs e)
{
Navigation.PushModalAsync(new ExtendedNavigationPage(new SettingsListFoldersPage()));