Skip to content
This repository has been archived by the owner on Dec 28, 2023. It is now read-only.

Commit

Permalink
Adds SelectModeCell for CircleListView (#332)
Browse files Browse the repository at this point in the history
  • Loading branch information
rookiejava authored Jun 18, 2020
1 parent f40fef2 commit b775010
Show file tree
Hide file tree
Showing 21 changed files with 632 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@
* limitations under the License.
*/

using ElmSharp;
using Xamarin.Forms;
using Xamarin.Forms.Platform.Tizen;
using XForms = Xamarin.Forms.Forms;

using NListView = Xamarin.Forms.Platform.Tizen.Native.ListView;
using CircleListView = Tizen.Wearable.CircularUI.Forms.CircleListView;

[assembly: ExportRenderer(typeof(CircleListView), typeof(Tizen.Wearable.CircularUI.Forms.Renderer.CircleListViewRenderer))]
Expand All @@ -36,7 +37,31 @@ public CircleListViewRenderer()

protected override Xamarin.Forms.Platform.Tizen.Native.ListView CreateNativeControl()
{
return _listView = new WatchListView(XForms.NativeParent, this.GetSurface());
_listView = new WatchListView(XForms.NativeParent, this.GetSurface());
_listView.ItemLongPressed += OnItemLongPressed;
return _listView;
}

protected override void Dispose(bool disposing)
{
if (disposing)
{
if (_listView != null)
{
_listView.ItemLongPressed -= OnItemLongPressed;
}
}
base.Dispose(disposing);
}

void OnItemLongPressed(object sender, GenListItemEventArgs args)
{
if (args.Item.Data is NListView.ItemContext itemContext)
{
var obj = itemContext.Cell.BindingContext;
var index = Element.TemplatedItems.GetGlobalIndexOfItem(obj);
Element.NotifyItemLongPressed(obj, index);
}
}

void UpdateBarColor()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved
*
* Licensed under the Flora License, Version 1.1 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://floralicense.org/license/
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

using System.Collections.Generic;
using Xamarin.Forms;
using Xamarin.Forms.Platform.Tizen;
using ElmSharp;
using Tizen.Wearable.CircularUI.Forms;
using Tizen.Wearable.CircularUI.Forms.Renderer;
using ECheck = ElmSharp.Check;

[assembly: ExportRenderer(typeof(SelectModeImageCell), typeof(SelectModeImageCellRenderer))]
namespace Tizen.Wearable.CircularUI.Forms.Renderer
{
public class SelectModeImageCellRenderer : ImageCellRenderer
{
protected SelectModeImageCellRenderer(string style) : base(style)
{
ImagePart = "elm.swallow.icon";
SelectionPart = "elm.swallow.center_check";
}

public SelectModeImageCellRenderer() : this("1icon_2text")
{
}

protected string SelectionPart { get; set; }

protected override EvasObject OnGetContent(Cell cell, string part)
{
if (cell is ISelectModeCell selectCell && selectCell.IsSelectionModeEnabled && part == SelectionPart)
{
var check = new CheckBox()
{
BindingContext = cell,
Parent = cell.Parent
};
check.SetBinding(CheckBox.IsCheckedProperty, new Binding(SelectModeTextCell.IsSelectedProperty.PropertyName));
var nativeView = Platform.GetOrCreateRenderer(check).NativeView;
if (nativeView is ECheck widget)
widget.Style = "genlist/select_mode";
nativeView.PropagateEvents = false;
nativeView.RepeatEvents = false;
return nativeView;
}
return base.OnGetContent(cell, part);
}

protected override bool OnCellPropertyChanged(Cell cell, string property, Dictionary<string, EvasObject> realizedView)
{
if (property == SelectModeCell.IsSelectedProperty.PropertyName ||
property == SelectModeCell.IsSelectionModeEnabledProperty.PropertyName)
{
return true;
}
return base.OnCellPropertyChanged(cell, property, realizedView);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved
*
* Licensed under the Flora License, Version 1.1 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://floralicense.org/license/
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

using System.Collections.Generic;
using Xamarin.Forms;
using Xamarin.Forms.Platform.Tizen;
using ElmSharp;
using Tizen.Wearable.CircularUI.Forms;
using Tizen.Wearable.CircularUI.Forms.Renderer;
using ECheck = ElmSharp.Check;

[assembly: ExportRenderer(typeof(SelectModeTextCell), typeof(SelectModeTextCellRenderer))]
namespace Tizen.Wearable.CircularUI.Forms.Renderer
{
public class SelectModeTextCellRenderer : TextCellRenderer
{
protected SelectModeTextCellRenderer(string style) : base(style)
{
SelectionPart = "elm.swallow.center_check";
}

public SelectModeTextCellRenderer() : this("1icon_2text")
{
}

protected string SelectionPart { get; set; }

protected override EvasObject OnGetContent(Cell cell, string part)
{
if (cell is ISelectModeCell selectCell && selectCell.IsSelectionModeEnabled && part == SelectionPart)
{
var check = new CheckBox()
{
BindingContext = cell,
Parent = cell.Parent
};
check.SetBinding(CheckBox.IsCheckedProperty, new Binding(SelectModeTextCell.IsSelectedProperty.PropertyName));
var nativeView = Platform.GetOrCreateRenderer(check).NativeView;
if (nativeView is ECheck widget)
widget.Style = "genlist/select_mode";
nativeView.PropagateEvents = false;
nativeView.RepeatEvents = false;
return nativeView;
}
return null;
}

protected override bool OnCellPropertyChanged(Cell cell, string property, Dictionary<string, EvasObject> realizedView)
{
if (property == SelectModeCell.IsSelectedProperty.PropertyName ||
property == SelectModeCell.IsSelectionModeEnabledProperty.PropertyName)
{
return true;
}
return base.OnCellPropertyChanged(cell, property, realizedView);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,13 @@
*/

using Xamarin.Forms;
using Xamarin.Forms.Platform.Tizen;
using Tizen.Wearable.CircularUI.Forms.Renderer;
using Tizen.Wearable.CircularUI.Forms;

[assembly: ExportRenderer(typeof(SingleTextCell), typeof(SingleTextCellRenderer))]
namespace Tizen.Wearable.CircularUI.Forms.Renderer
{
public class SingleTextCellRenderer : TextCellRenderer
public class SingleTextCellRenderer : SelectModeTextCellRenderer
{
protected SingleTextCellRenderer(string style) : base(style)
{
Expand Down
12 changes: 12 additions & 0 deletions src/Tizen.Wearable.CircularUI.Forms/CircleListView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/

using System;
using System.ComponentModel;
using Xamarin.Forms;

namespace Tizen.Wearable.CircularUI.Forms
Expand Down Expand Up @@ -59,5 +60,16 @@ public Color BarColor
/// Gets or sets a CircleSurfaceProvider.
/// </summary>
public ICircleSurfaceProvider CircleSurfaceProvider { get; set; }

/// <summary>
/// Event that is raised when a new item is long pressed.
/// </summary>
public event EventHandler<ItemLongPressedEventArgs> ItemLongPressed;

[EditorBrowsable(EditorBrowsableState.Never)]
public void NotifyItemLongPressed(object item, int index)
{
ItemLongPressed?.Invoke(this, new ItemLongPressedEventArgs(item, index));
}
}
}
34 changes: 34 additions & 0 deletions src/Tizen.Wearable.CircularUI.Forms/ISelectModeCell.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved
*
* Licensed under the Flora License, Version 1.1 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://floralicense.org/license/
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

using System;
using System.ComponentModel;
using System.Diagnostics;
using Xamarin.Forms;

namespace Tizen.Wearable.CircularUI.Forms
{
[EditorBrowsable(EditorBrowsableState.Never)]
interface ISelectModeCell
{
bool IsSelected { get; set; }
bool IsSelectionModeEnabled { get; set; }

void OnIsSelectedChanged(object sender, ToggledEventArgs e);

event EventHandler<ToggledEventArgs> SelectionChanged;
}
}
47 changes: 47 additions & 0 deletions src/Tizen.Wearable.CircularUI.Forms/ItemLongPressedEventArgs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved
*
* Licensed under the Flora License, Version 1.1 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://floralicense.org/license/
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

using System;

namespace Tizen.Wearable.CircularUI.Forms
{
/// <summary>
/// Event arguments for the ItemLongPressed event of CircleListView.
/// </summary>
public class ItemLongPressedEventArgs : EventArgs
{
/// <summary>
/// Creates a new ItemLongPressedEventArgs object.
/// </summary>
/// <param name="item">An item data of new long pressed item.</param>
/// <param name="itemIndex">An index of new long pressed item.</param>
public ItemLongPressedEventArgs(object item, int itemIndex)
{
Item = item;
ItemIndex = itemIndex;
}

/// <summary>
/// Gets the data of new long pressed item
/// </summary>
public object Item { get; private set; }

/// <summary>
/// Gets the index of new long pressed item
/// </summary>
public int ItemIndex { get; private set; }
}
}
31 changes: 31 additions & 0 deletions src/Tizen.Wearable.CircularUI.Forms/SelectModeCell.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved
*
* Licensed under the Flora License, Version 1.1 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://floralicense.org/license/
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

using Xamarin.Forms;

namespace Tizen.Wearable.CircularUI.Forms
{
static class SelectModeCell
{
public static readonly BindableProperty IsSelectedProperty = BindableProperty.Create(nameof(ISelectModeCell.IsSelected), typeof(bool), typeof(ISelectModeCell), false, propertyChanged: (obj, oldValue, newValue) =>
{
ISelectModeCell selectModetCell = (ISelectModeCell)obj;
selectModetCell.OnIsSelectedChanged(obj, new ToggledEventArgs((bool)newValue));
}, defaultBindingMode: BindingMode.TwoWay);

public static readonly BindableProperty IsSelectionModeEnabledProperty = BindableProperty.Create(nameof(ISelectModeCell.IsSelectionModeEnabled), typeof(bool), typeof(ISelectModeCell), default(bool));
}
}
Loading

0 comments on commit b775010

Please sign in to comment.