Compare commits
No commits in common. "00a7eff5f84c992b08a52ff2c0a955e13e7a7587" and "ab0bc3bcf9902277859e8c9b18f07a7837bc37a5" have entirely different histories.
00a7eff5f8
...
ab0bc3bcf9
@ -78,6 +78,10 @@ namespace AlicizaX.UI
|
|||||||
{
|
{
|
||||||
typedItemRender.BindData(data, index);
|
typedItemRender.BindData(data, index);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
itemRender.Bind(data, index);
|
||||||
|
}
|
||||||
|
|
||||||
bool selected = index == choiceIndex;
|
bool selected = index == choiceIndex;
|
||||||
itemRender.SyncSelection(selected);
|
itemRender.SyncSelection(selected);
|
||||||
@ -149,14 +153,14 @@ namespace AlicizaX.UI
|
|||||||
recyclerView.RebindVisibleDataRange(index, count);
|
recyclerView.RebindVisibleDataRange(index, count);
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual void NotifyItemInserted()
|
public virtual void NotifyItemInserted(int index)
|
||||||
{
|
{
|
||||||
CoerceChoiceIndex();
|
CoerceChoiceIndex();
|
||||||
recyclerView.RequestLayout();
|
recyclerView.RequestLayout();
|
||||||
recyclerView.Refresh();
|
recyclerView.Refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual void NotifyItemRangeInserted(int count)
|
public virtual void NotifyItemRangeInserted(int index, int count)
|
||||||
{
|
{
|
||||||
if (count <= 0)
|
if (count <= 0)
|
||||||
{
|
{
|
||||||
@ -168,14 +172,14 @@ namespace AlicizaX.UI
|
|||||||
recyclerView.Refresh();
|
recyclerView.Refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual void NotifyItemRemoved()
|
public virtual void NotifyItemRemoved(int index)
|
||||||
{
|
{
|
||||||
CoerceChoiceIndex();
|
CoerceChoiceIndex();
|
||||||
recyclerView.RequestLayout();
|
recyclerView.RequestLayout();
|
||||||
recyclerView.Refresh();
|
recyclerView.Refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual void NotifyItemRangeRemoved(int count)
|
public virtual void NotifyItemRangeRemoved(int index, int count)
|
||||||
{
|
{
|
||||||
if (count <= 0)
|
if (count <= 0)
|
||||||
{
|
{
|
||||||
@ -252,7 +256,7 @@ namespace AlicizaX.UI
|
|||||||
}
|
}
|
||||||
|
|
||||||
list.Add(item);
|
list.Add(item);
|
||||||
NotifyItemInserted();
|
NotifyItemInserted(list.Count - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddRange(IEnumerable<T> collection)
|
public void AddRange(IEnumerable<T> collection)
|
||||||
@ -262,10 +266,11 @@ namespace AlicizaX.UI
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int startIndex = list.Count;
|
||||||
list.AddRange(collection);
|
list.AddRange(collection);
|
||||||
if (collection is ICollection<T> itemCollection)
|
if (collection is ICollection<T> itemCollection)
|
||||||
{
|
{
|
||||||
NotifyItemRangeInserted(itemCollection.Count);
|
NotifyItemRangeInserted(startIndex, itemCollection.Count);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -275,7 +280,7 @@ namespace AlicizaX.UI
|
|||||||
public void Insert(int index, T item)
|
public void Insert(int index, T item)
|
||||||
{
|
{
|
||||||
list.Insert(index, item);
|
list.Insert(index, item);
|
||||||
NotifyItemInserted();
|
NotifyItemInserted(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void InsertRange(int index, IEnumerable<T> collection)
|
public void InsertRange(int index, IEnumerable<T> collection)
|
||||||
@ -288,7 +293,7 @@ namespace AlicizaX.UI
|
|||||||
list.InsertRange(index, collection);
|
list.InsertRange(index, collection);
|
||||||
if (collection is ICollection<T> itemCollection)
|
if (collection is ICollection<T> itemCollection)
|
||||||
{
|
{
|
||||||
NotifyItemRangeInserted(itemCollection.Count);
|
NotifyItemRangeInserted(index, itemCollection.Count);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -306,13 +311,13 @@ namespace AlicizaX.UI
|
|||||||
if (index < 0 || index >= GetItemCount()) return;
|
if (index < 0 || index >= GetItemCount()) return;
|
||||||
|
|
||||||
list.RemoveAt(index);
|
list.RemoveAt(index);
|
||||||
NotifyItemRemoved();
|
NotifyItemRemoved(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RemoveRange(int index, int count)
|
public void RemoveRange(int index, int count)
|
||||||
{
|
{
|
||||||
list.RemoveRange(index, count);
|
list.RemoveRange(index, count);
|
||||||
NotifyItemRangeRemoved(count);
|
NotifyItemRangeRemoved(index, count);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RemoveAll(Predicate<T> match)
|
public void RemoveAll(Predicate<T> match)
|
||||||
@ -330,7 +335,7 @@ namespace AlicizaX.UI
|
|||||||
|
|
||||||
int count = list.Count;
|
int count = list.Count;
|
||||||
list.Clear();
|
list.Clear();
|
||||||
NotifyItemRangeRemoved(count);
|
NotifyItemRangeRemoved(0, count);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Reverse(int index, int count)
|
public void Reverse(int index, int count)
|
||||||
|
|||||||
@ -11,6 +11,13 @@ namespace AlicizaX.UI
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
internal interface IItemRender
|
internal interface IItemRender
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 将指定数据绑定到当前渲染实例。
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="data">待绑定的数据对象。</param>
|
||||||
|
/// <param name="index">当前数据索引。</param>
|
||||||
|
void Bind(object data, int index);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 更新当前渲染实例的选中状态。
|
/// 更新当前渲染实例的选中状态。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -58,6 +65,13 @@ namespace AlicizaX.UI
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
internal abstract void Detach();
|
internal abstract void Detach();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 以对象形式绑定数据。
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="data">待绑定的数据对象。</param>
|
||||||
|
/// <param name="index">当前数据索引。</param>
|
||||||
|
internal abstract void BindObject(object data, int index);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 更新内部记录的选中状态。
|
/// 更新内部记录的选中状态。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -71,6 +85,16 @@ namespace AlicizaX.UI
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
internal abstract void UnbindInternal();
|
internal abstract void UnbindInternal();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 由框架内部调用,将对象数据绑定到当前渲染实例。
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="data">待绑定的数据对象。</param>
|
||||||
|
/// <param name="index">当前数据索引。</param>
|
||||||
|
void IItemRender.Bind(object data, int index)
|
||||||
|
{
|
||||||
|
BindObject(data, index);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 由框架内部调用,更新当前渲染实例的选中状态。
|
/// 由框架内部调用,更新当前渲染实例的选中状态。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -182,6 +206,21 @@ namespace AlicizaX.UI
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
protected virtual RecyclerNavigationOptions NavigationOptions => RecyclerNavigationOptions.Circular;
|
protected virtual RecyclerNavigationOptions NavigationOptions => RecyclerNavigationOptions.Circular;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 以对象形式绑定数据并执行强类型校验。
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="data">待绑定的数据对象。</param>
|
||||||
|
/// <param name="index">当前数据索引。</param>
|
||||||
|
internal override void BindObject(object data, int index)
|
||||||
|
{
|
||||||
|
if (data is not TData itemData)
|
||||||
|
{
|
||||||
|
throw new InvalidCastException(
|
||||||
|
$"ItemRender '{GetType().Name}' expected data '{typeof(TData).Name}', but got '{data?.GetType().Name ?? "null"}'.");
|
||||||
|
}
|
||||||
|
|
||||||
|
BindCore(itemData, index);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 由框架内部调用,使用强类型数据执行绑定。
|
/// 由框架内部调用,使用强类型数据执行绑定。
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user