mirror of
https://github.com/bitwarden/android.git
synced 2024-12-18 23:31:52 +03:00
ExtendedTextCell and ExtendedViewCell for iOS and Android. BackgroundColor and Disclousure Indicators
This commit is contained in:
parent
e9999adcf2
commit
72c807a5b2
14 changed files with 186 additions and 26 deletions
|
@ -197,6 +197,7 @@
|
|||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Controls\ExtendedEditorRenderer.cs" />
|
||||
<Compile Include="Controls\ExtendedViewCellRenderer.cs" />
|
||||
<Compile Include="Controls\ExtendedTextCellRenderer.cs" />
|
||||
<Compile Include="Controls\ExtendedPickerRenderer.cs" />
|
||||
<Compile Include="Controls\ExtendedEntryRenderer.cs" />
|
||||
|
|
|
@ -6,6 +6,7 @@ using Bit.App.Controls;
|
|||
using Xamarin.Forms;
|
||||
using Xamarin.Forms.Platform.Android;
|
||||
using AView = Android.Views.View;
|
||||
using Android.Widget;
|
||||
|
||||
[assembly: ExportRenderer(typeof(ExtendedTextCell), typeof(ExtendedTextCellRenderer))]
|
||||
namespace Bit.Android.Controls
|
||||
|
@ -16,11 +17,29 @@ namespace Bit.Android.Controls
|
|||
|
||||
protected override AView GetCellCore(Cell item, AView convertView, ViewGroup parent, Context context)
|
||||
{
|
||||
var View = base.GetCellCore(item, convertView, parent, context);
|
||||
var View = (BaseCellView)base.GetCellCore(item, convertView, parent, context);
|
||||
var extendedCell = (ExtendedTextCell)item;
|
||||
|
||||
var cell = (ExtendedTextCell)item;
|
||||
if(View != null)
|
||||
{
|
||||
View.SetBackgroundColor(extendedCell.BackgroundColor.ToAndroid());
|
||||
|
||||
View.SetBackgroundColor(cell.BackgroundColor.ToAndroid());
|
||||
if(extendedCell.ShowDisclousure)
|
||||
{
|
||||
// TODO: different image
|
||||
var resourceId = Resource.Drawable.fa_folder_open;
|
||||
if(!string.IsNullOrWhiteSpace(extendedCell.DisclousureImage))
|
||||
{
|
||||
var fileName = System.IO.Path.GetFileNameWithoutExtension(extendedCell.DisclousureImage);
|
||||
resourceId = context.Resources.GetIdentifier(fileName, "drawable", context.PackageName);
|
||||
}
|
||||
|
||||
var image = new ImageView(context);
|
||||
image.SetImageResource(resourceId);
|
||||
image.SetPadding(0, 0, 30, 0);
|
||||
View.SetAccessoryView(image);
|
||||
}
|
||||
}
|
||||
|
||||
return View;
|
||||
}
|
||||
|
@ -35,6 +54,8 @@ namespace Bit.Android.Controls
|
|||
{
|
||||
View.SetBackgroundColor(cell.BackgroundColor.ToAndroid());
|
||||
}
|
||||
|
||||
// TODO: other properties
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
42
src/Android/Controls/ExtendedViewCellRenderer.cs
Normal file
42
src/Android/Controls/ExtendedViewCellRenderer.cs
Normal file
|
@ -0,0 +1,42 @@
|
|||
using Android.Content;
|
||||
using System.ComponentModel;
|
||||
using Android.Views;
|
||||
using Bit.Android.Controls;
|
||||
using Bit.App.Controls;
|
||||
using Xamarin.Forms;
|
||||
using Xamarin.Forms.Platform.Android;
|
||||
using AView = Android.Views.View;
|
||||
|
||||
[assembly: ExportRenderer(typeof(ExtendedViewCell), typeof(ExtendedViewCellRenderer))]
|
||||
namespace Bit.Android.Controls
|
||||
{
|
||||
public class ExtendedViewCellRenderer : ViewCellRenderer
|
||||
{
|
||||
protected AView View { get; private set; }
|
||||
|
||||
protected override AView GetCellCore(Cell item, AView convertView, ViewGroup parent, Context context)
|
||||
{
|
||||
var View = base.GetCellCore(item, convertView, parent, context);
|
||||
var extendedCell = (ExtendedViewCell)item;
|
||||
|
||||
if(View != null)
|
||||
{
|
||||
View.SetBackgroundColor(extendedCell.BackgroundColor.ToAndroid());
|
||||
}
|
||||
|
||||
return View;
|
||||
}
|
||||
|
||||
protected override void OnCellPropertyChanged(object sender, PropertyChangedEventArgs args)
|
||||
{
|
||||
base.OnCellPropertyChanged(sender, args);
|
||||
|
||||
var cell = (ExtendedTextCell)Cell;
|
||||
|
||||
if(args.PropertyName == ExtendedTextCell.BackgroundColorProperty.PropertyName)
|
||||
{
|
||||
View.SetBackgroundColor(cell.BackgroundColor.ToAndroid());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -52,6 +52,7 @@
|
|||
<Compile Include="Controls\ExtendedPicker.cs" />
|
||||
<Compile Include="Controls\ExtendedEntry.cs" />
|
||||
<Compile Include="Controls\ExtendedTabbedPage.cs" />
|
||||
<Compile Include="Controls\ExtendedViewCell.cs" />
|
||||
<Compile Include="Controls\FormEditorCell.cs" />
|
||||
<Compile Include="Controls\ExtendedTextCell.cs" />
|
||||
<Compile Include="Controls\LabeledValueCell.cs" />
|
||||
|
|
|
@ -1,17 +1,34 @@
|
|||
using System;
|
||||
using Xamarin.Forms;
|
||||
using Xamarin.Forms;
|
||||
|
||||
namespace Bit.App.Controls
|
||||
{
|
||||
public class ExtendedTextCell : TextCell
|
||||
{
|
||||
public static readonly BindableProperty BackgroundColorProperty =
|
||||
BindableProperty.Create(nameof(BackgroundColor), typeof(Color), typeof(ExtendedTextCell), Color.Transparent);
|
||||
BindableProperty.Create(nameof(BackgroundColor), typeof(Color), typeof(ExtendedTextCell), Color.White);
|
||||
|
||||
public static readonly BindableProperty ShowDisclousureProperty =
|
||||
BindableProperty.Create(nameof(DisclousureImage), typeof(bool), typeof(ExtendedTextCell), false);
|
||||
|
||||
public static readonly BindableProperty DisclousureImageProperty =
|
||||
BindableProperty.Create(nameof(DisclousureImage), typeof(string), typeof(ExtendedTextCell), string.Empty);
|
||||
|
||||
public Color BackgroundColor
|
||||
{
|
||||
get { return (Color)GetValue(BackgroundColorProperty); }
|
||||
set { SetValue(BackgroundColorProperty, value); }
|
||||
}
|
||||
|
||||
public bool ShowDisclousure
|
||||
{
|
||||
get { return (bool)GetValue(ShowDisclousureProperty); }
|
||||
set { SetValue(ShowDisclousureProperty, value); }
|
||||
}
|
||||
|
||||
public string DisclousureImage
|
||||
{
|
||||
get { return (string)GetValue(DisclousureImageProperty); }
|
||||
set { SetValue(DisclousureImageProperty, value); }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
16
src/App/Controls/ExtendedViewCell.cs
Normal file
16
src/App/Controls/ExtendedViewCell.cs
Normal file
|
@ -0,0 +1,16 @@
|
|||
using Xamarin.Forms;
|
||||
|
||||
namespace Bit.App.Controls
|
||||
{
|
||||
public class ExtendedViewCell : ViewCell
|
||||
{
|
||||
public static readonly BindableProperty BackgroundColorProperty =
|
||||
BindableProperty.Create(nameof(BackgroundColor), typeof(Color), typeof(ExtendedTextCell), Color.White);
|
||||
|
||||
public Color BackgroundColor
|
||||
{
|
||||
get { return (Color)GetValue(BackgroundColorProperty); }
|
||||
set { SetValue(BackgroundColorProperty, value); }
|
||||
}
|
||||
}
|
||||
}
|
|
@ -3,7 +3,7 @@ using Xamarin.Forms;
|
|||
|
||||
namespace Bit.App.Controls
|
||||
{
|
||||
public class FormEditorCell : ViewCell
|
||||
public class FormEditorCell : ExtendedViewCell
|
||||
{
|
||||
public FormEditorCell(Keyboard entryKeyboard = null, double? height = null)
|
||||
{
|
||||
|
@ -20,8 +20,7 @@ namespace Bit.App.Controls
|
|||
|
||||
var stackLayout = new StackLayout
|
||||
{
|
||||
Padding = new Thickness(15),
|
||||
BackgroundColor = Color.White
|
||||
Padding = new Thickness(15)
|
||||
};
|
||||
|
||||
stackLayout.Children.Add(Editor);
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
using System;
|
||||
using Xamarin.Forms;
|
||||
using Xamarin.Forms;
|
||||
|
||||
namespace Bit.App.Controls
|
||||
{
|
||||
public class FormEntryCell : ViewCell
|
||||
public class FormEntryCell : ExtendedViewCell
|
||||
{
|
||||
public FormEntryCell(string labelText, Keyboard entryKeyboard = null, bool IsPassword = false)
|
||||
{
|
||||
|
@ -25,8 +24,7 @@ namespace Bit.App.Controls
|
|||
|
||||
var stackLayout = new StackLayout
|
||||
{
|
||||
Padding = new Thickness(15),
|
||||
BackgroundColor = Color.White
|
||||
Padding = new Thickness(15)
|
||||
};
|
||||
|
||||
stackLayout.Children.Add(Label);
|
||||
|
|
|
@ -4,7 +4,7 @@ using Xamarin.Forms;
|
|||
|
||||
namespace Bit.App.Controls
|
||||
{
|
||||
public class FormPickerCell : ViewCell
|
||||
public class FormPickerCell : ExtendedViewCell
|
||||
{
|
||||
public FormPickerCell(string labelText, string[] pickerItems)
|
||||
{
|
||||
|
@ -31,8 +31,7 @@ namespace Bit.App.Controls
|
|||
|
||||
var stackLayout = new StackLayout
|
||||
{
|
||||
Padding = new Thickness(15),
|
||||
BackgroundColor = Color.White
|
||||
Padding = new Thickness(15)
|
||||
};
|
||||
|
||||
stackLayout.Children.Add(Label);
|
||||
|
|
|
@ -1,13 +1,8 @@
|
|||
using Acr.UserDialogs;
|
||||
using Bit.App.Abstractions;
|
||||
using Bit.App.Resources;
|
||||
using System;
|
||||
using Xamarin.Forms;
|
||||
using XLabs.Ioc;
|
||||
using Xamarin.Forms;
|
||||
|
||||
namespace Bit.App.Controls
|
||||
{
|
||||
public class LabeledValueCell : ViewCell
|
||||
public class LabeledValueCell : ExtendedViewCell
|
||||
{
|
||||
public LabeledValueCell(
|
||||
string labelText = null,
|
||||
|
@ -18,7 +13,6 @@ namespace Bit.App.Controls
|
|||
var containerStackLayout = new StackLayout
|
||||
{
|
||||
Padding = new Thickness(15),
|
||||
BackgroundColor = Color.White,
|
||||
Orientation = StackOrientation.Horizontal
|
||||
};
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ namespace Bit.App.Pages
|
|||
|
||||
private void Init()
|
||||
{
|
||||
var foldersCell = new TextCell { Text = "Folders" };
|
||||
var foldersCell = new ExtendedTextCell { Text = "Folders", ShowDisclousure = true };
|
||||
foldersCell.Tapped += FoldersCell_Tapped;
|
||||
|
||||
var table = new ExtendedTableView
|
||||
|
|
45
src/iOS/Controls/ExtendedTextCellRenderer.cs
Normal file
45
src/iOS/Controls/ExtendedTextCellRenderer.cs
Normal file
|
@ -0,0 +1,45 @@
|
|||
using Bit.App.Controls;
|
||||
using Bit.iOS.Controls;
|
||||
using UIKit;
|
||||
using Xamarin.Forms;
|
||||
using Xamarin.Forms.Platform.iOS;
|
||||
using CoreGraphics;
|
||||
|
||||
[assembly: ExportRenderer(typeof(ExtendedTextCell), typeof(ExtendedTextCellRenderer))]
|
||||
namespace Bit.iOS.Controls
|
||||
{
|
||||
public class ExtendedTextCellRenderer : TextCellRenderer
|
||||
{
|
||||
public override UITableViewCell GetCell(Cell item, UITableViewCell reusableCell, UITableView tv)
|
||||
{
|
||||
var extendedCell = (ExtendedTextCell)item;
|
||||
var cell = base.GetCell(item, reusableCell, tv);
|
||||
|
||||
if(cell != null)
|
||||
{
|
||||
cell.BackgroundColor = extendedCell.BackgroundColor.ToUIColor();
|
||||
if(extendedCell.ShowDisclousure)
|
||||
{
|
||||
cell.Accessory = UITableViewCellAccessory.DisclosureIndicator;
|
||||
if(!string.IsNullOrEmpty(extendedCell.DisclousureImage))
|
||||
{
|
||||
var detailDisclosureButton = UIButton.FromType(UIButtonType.Custom);
|
||||
detailDisclosureButton.SetImage(UIImage.FromBundle(extendedCell.DisclousureImage), UIControlState.Normal);
|
||||
detailDisclosureButton.SetImage(UIImage.FromBundle(extendedCell.DisclousureImage), UIControlState.Selected);
|
||||
|
||||
detailDisclosureButton.Frame = new CGRect(0f, 0f, 30f, 30f);
|
||||
detailDisclosureButton.TouchUpInside += (sender, e) =>
|
||||
{
|
||||
var index = tv.IndexPathForCell(cell);
|
||||
tv.SelectRow(index, true, UITableViewScrollPosition.None);
|
||||
tv.Source.AccessoryButtonTapped(tv, index);
|
||||
};
|
||||
cell.AccessoryView = detailDisclosureButton;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return cell;
|
||||
}
|
||||
}
|
||||
}
|
25
src/iOS/Controls/ExtendedViewCellRenderer.cs
Normal file
25
src/iOS/Controls/ExtendedViewCellRenderer.cs
Normal file
|
@ -0,0 +1,25 @@
|
|||
using Bit.App.Controls;
|
||||
using Bit.iOS.Controls;
|
||||
using UIKit;
|
||||
using Xamarin.Forms;
|
||||
using Xamarin.Forms.Platform.iOS;
|
||||
|
||||
[assembly: ExportRenderer(typeof(ExtendedViewCell), typeof(ExtendedViewCellRenderer))]
|
||||
namespace Bit.iOS.Controls
|
||||
{
|
||||
public class ExtendedViewCellRenderer : ViewCellRenderer
|
||||
{
|
||||
public override UITableViewCell GetCell(Cell item, UITableViewCell reusableCell, UITableView tv)
|
||||
{
|
||||
var extendedCell = (ExtendedViewCell)item;
|
||||
var cell = base.GetCell(item, reusableCell, tv);
|
||||
|
||||
if(cell != null)
|
||||
{
|
||||
cell.BackgroundColor = extendedCell.BackgroundColor.ToUIColor();
|
||||
}
|
||||
|
||||
return cell;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -102,6 +102,8 @@
|
|||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Controls\ContentPageRenderer.cs" />
|
||||
<Compile Include="Controls\ExtendedViewCellRenderer.cs" />
|
||||
<Compile Include="Controls\ExtendedTextCellRenderer.cs" />
|
||||
<Compile Include="Controls\ExtendedTableViewRenderer.cs" />
|
||||
<Compile Include="Controls\ExtendedPickerRenderer.cs" />
|
||||
<Compile Include="Controls\ExtendedEntryRenderer.cs" />
|
||||
|
|
Loading…
Reference in a new issue