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
Browse files Browse the repository at this point in the history
  • Loading branch information
rookiejava committed Jun 18, 2020
1 parent 93cb4d7 commit d4ee5d4
Show file tree
Hide file tree
Showing 21 changed files with 620 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* limitations under the License.
*/

using ElmSharp;
using Xamarin.Forms;
using Xamarin.Forms.Platform.Tizen;
using XForms = Xamarin.Forms.Forms;
Expand All @@ -36,7 +37,27 @@ 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)
{
//TODO : need to fix below line correctly after applying header/footer related patch
Element.NotifyItemLongPressed(args.Item.Index-2);
}

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(int index)
{
ItemLongPressed?.Invoke(this, new ItemLongPressedEventArgs(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;
}
}
40 changes: 40 additions & 0 deletions src/Tizen.Wearable.CircularUI.Forms/ItemLongPressedEventArgs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* 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="itemIndex">An index of new long pressed item.</param>
public ItemLongPressedEventArgs(int itemIndex)
{
ItemIndex = itemIndex;
}

/// <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));
}
}
65 changes: 65 additions & 0 deletions src/Tizen.Wearable.CircularUI.Forms/SelectModeImageCell.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* 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 Xamarin.Forms;

namespace Tizen.Wearable.CircularUI.Forms
{
/// <summary>
/// An ImageCell supports a selection mode.
/// </summary>
public class SelectModeImageCell : ImageCell, ISelectModeCell
{
/// <summary>
/// Identifies the On bindable property.
/// </summary>
public static readonly BindableProperty IsSelectedProperty = SelectModeCell.IsSelectedProperty;

/// <summary>
/// Identifies the Text bindable property.
/// </summary>
public static readonly BindableProperty IsSelectionModeEnabledProperty = SelectModeCell.IsSelectionModeEnabledProperty;

/// <summary>
/// Gets or sets the state of the selection. This is a bindable property.
/// </summary>
public bool IsSelected
{
get { return (bool)GetValue(IsSelectedProperty); }
set { SetValue(IsSelectedProperty, value); }
}

/// <summary>
/// Gets or sets whether to enable the selection mode or not. This is a bindable property.
/// </summary>
public bool IsSelectionModeEnabled
{
get { return (bool)GetValue(IsSelectionModeEnabledProperty); }
set { SetValue(IsSelectionModeEnabledProperty, value); }
}

/// <summary>
/// Triggered when IsSelected changed.
/// </summary>
public event EventHandler<ToggledEventArgs> SelectionChanged;

void ISelectModeCell.OnIsSelectedChanged(object sender, ToggledEventArgs e)
{
SelectionChanged?.Invoke(sender, e);
}
}
}
Loading

0 comments on commit d4ee5d4

Please sign in to comment.