Skip to content
This repository has been archived by the owner on Sep 20, 2021. It is now read-only.

MvvmLight.Platform.AndroidX Library #81

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions GalaSoft.MvvmLight/GalaSoft.MvvmLight (VS2017).sln
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GalaSoft.MvvmLight.Platform
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GalaSoft.MvvmLight.Test (PNET45)", "Tests\PCL\GalaSoft.MvvmLight.Test (PNET45)\GalaSoft.MvvmLight.Test (PNET45).csproj", "{B2EF9514-C8C2-444E-AF84-960AC9989A08}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GalaSoft.MvvmLight.Platform.AndroidX", "GalaSoft.MvvmLight.AndroidX\GalaSoft.MvvmLight.Platform.AndroidX.csproj", "{FAA2B9A7-6FB5-4980-9A22-9A6F48DA0BDA}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Ad-Hoc|Any CPU = Ad-Hoc|Any CPU
Expand Down Expand Up @@ -741,6 +743,54 @@ Global
{B2EF9514-C8C2-444E-AF84-960AC9989A08}.Release|x64.Build.0 = Release|Any CPU
{B2EF9514-C8C2-444E-AF84-960AC9989A08}.Release|x86.ActiveCfg = Release|Any CPU
{B2EF9514-C8C2-444E-AF84-960AC9989A08}.Release|x86.Build.0 = Release|Any CPU
{FAA2B9A7-6FB5-4980-9A22-9A6F48DA0BDA}.Ad-Hoc|Any CPU.ActiveCfg = Release|Any CPU
{FAA2B9A7-6FB5-4980-9A22-9A6F48DA0BDA}.Ad-Hoc|Any CPU.Build.0 = Release|Any CPU
{FAA2B9A7-6FB5-4980-9A22-9A6F48DA0BDA}.Ad-Hoc|ARM.ActiveCfg = Release|Any CPU
{FAA2B9A7-6FB5-4980-9A22-9A6F48DA0BDA}.Ad-Hoc|ARM.Build.0 = Release|Any CPU
{FAA2B9A7-6FB5-4980-9A22-9A6F48DA0BDA}.Ad-Hoc|iPhone.ActiveCfg = Release|Any CPU
{FAA2B9A7-6FB5-4980-9A22-9A6F48DA0BDA}.Ad-Hoc|iPhone.Build.0 = Release|Any CPU
{FAA2B9A7-6FB5-4980-9A22-9A6F48DA0BDA}.Ad-Hoc|iPhoneSimulator.ActiveCfg = Release|Any CPU
{FAA2B9A7-6FB5-4980-9A22-9A6F48DA0BDA}.Ad-Hoc|iPhoneSimulator.Build.0 = Release|Any CPU
{FAA2B9A7-6FB5-4980-9A22-9A6F48DA0BDA}.Ad-Hoc|x64.ActiveCfg = Release|Any CPU
{FAA2B9A7-6FB5-4980-9A22-9A6F48DA0BDA}.Ad-Hoc|x64.Build.0 = Release|Any CPU
{FAA2B9A7-6FB5-4980-9A22-9A6F48DA0BDA}.Ad-Hoc|x86.ActiveCfg = Release|Any CPU
{FAA2B9A7-6FB5-4980-9A22-9A6F48DA0BDA}.Ad-Hoc|x86.Build.0 = Release|Any CPU
{FAA2B9A7-6FB5-4980-9A22-9A6F48DA0BDA}.AppStore|Any CPU.ActiveCfg = Release|Any CPU
{FAA2B9A7-6FB5-4980-9A22-9A6F48DA0BDA}.AppStore|Any CPU.Build.0 = Release|Any CPU
{FAA2B9A7-6FB5-4980-9A22-9A6F48DA0BDA}.AppStore|ARM.ActiveCfg = Release|Any CPU
{FAA2B9A7-6FB5-4980-9A22-9A6F48DA0BDA}.AppStore|ARM.Build.0 = Release|Any CPU
{FAA2B9A7-6FB5-4980-9A22-9A6F48DA0BDA}.AppStore|iPhone.ActiveCfg = Release|Any CPU
{FAA2B9A7-6FB5-4980-9A22-9A6F48DA0BDA}.AppStore|iPhone.Build.0 = Release|Any CPU
{FAA2B9A7-6FB5-4980-9A22-9A6F48DA0BDA}.AppStore|iPhoneSimulator.ActiveCfg = Release|Any CPU
{FAA2B9A7-6FB5-4980-9A22-9A6F48DA0BDA}.AppStore|iPhoneSimulator.Build.0 = Release|Any CPU
{FAA2B9A7-6FB5-4980-9A22-9A6F48DA0BDA}.AppStore|x64.ActiveCfg = Release|Any CPU
{FAA2B9A7-6FB5-4980-9A22-9A6F48DA0BDA}.AppStore|x64.Build.0 = Release|Any CPU
{FAA2B9A7-6FB5-4980-9A22-9A6F48DA0BDA}.AppStore|x86.ActiveCfg = Release|Any CPU
{FAA2B9A7-6FB5-4980-9A22-9A6F48DA0BDA}.AppStore|x86.Build.0 = Release|Any CPU
{FAA2B9A7-6FB5-4980-9A22-9A6F48DA0BDA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FAA2B9A7-6FB5-4980-9A22-9A6F48DA0BDA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FAA2B9A7-6FB5-4980-9A22-9A6F48DA0BDA}.Debug|ARM.ActiveCfg = Debug|Any CPU
{FAA2B9A7-6FB5-4980-9A22-9A6F48DA0BDA}.Debug|ARM.Build.0 = Debug|Any CPU
{FAA2B9A7-6FB5-4980-9A22-9A6F48DA0BDA}.Debug|iPhone.ActiveCfg = Debug|Any CPU
{FAA2B9A7-6FB5-4980-9A22-9A6F48DA0BDA}.Debug|iPhone.Build.0 = Debug|Any CPU
{FAA2B9A7-6FB5-4980-9A22-9A6F48DA0BDA}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU
{FAA2B9A7-6FB5-4980-9A22-9A6F48DA0BDA}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU
{FAA2B9A7-6FB5-4980-9A22-9A6F48DA0BDA}.Debug|x64.ActiveCfg = Debug|Any CPU
{FAA2B9A7-6FB5-4980-9A22-9A6F48DA0BDA}.Debug|x64.Build.0 = Debug|Any CPU
{FAA2B9A7-6FB5-4980-9A22-9A6F48DA0BDA}.Debug|x86.ActiveCfg = Debug|Any CPU
{FAA2B9A7-6FB5-4980-9A22-9A6F48DA0BDA}.Debug|x86.Build.0 = Debug|Any CPU
{FAA2B9A7-6FB5-4980-9A22-9A6F48DA0BDA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FAA2B9A7-6FB5-4980-9A22-9A6F48DA0BDA}.Release|Any CPU.Build.0 = Release|Any CPU
{FAA2B9A7-6FB5-4980-9A22-9A6F48DA0BDA}.Release|ARM.ActiveCfg = Release|Any CPU
{FAA2B9A7-6FB5-4980-9A22-9A6F48DA0BDA}.Release|ARM.Build.0 = Release|Any CPU
{FAA2B9A7-6FB5-4980-9A22-9A6F48DA0BDA}.Release|iPhone.ActiveCfg = Release|Any CPU
{FAA2B9A7-6FB5-4980-9A22-9A6F48DA0BDA}.Release|iPhone.Build.0 = Release|Any CPU
{FAA2B9A7-6FB5-4980-9A22-9A6F48DA0BDA}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU
{FAA2B9A7-6FB5-4980-9A22-9A6F48DA0BDA}.Release|iPhoneSimulator.Build.0 = Release|Any CPU
{FAA2B9A7-6FB5-4980-9A22-9A6F48DA0BDA}.Release|x64.ActiveCfg = Release|Any CPU
{FAA2B9A7-6FB5-4980-9A22-9A6F48DA0BDA}.Release|x64.Build.0 = Release|Any CPU
{FAA2B9A7-6FB5-4980-9A22-9A6F48DA0BDA}.Release|x86.ActiveCfg = Release|Any CPU
{FAA2B9A7-6FB5-4980-9A22-9A6F48DA0BDA}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\Xamarin.AndroidX.Migration.1.0.6.1\build\monoandroid90\Xamarin.AndroidX.Migration.props" Condition="Exists('..\packages\Xamarin.AndroidX.Migration.1.0.6.1\build\monoandroid90\Xamarin.AndroidX.Migration.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{FAA2B9A7-6FB5-4980-9A22-9A6F48DA0BDA}</ProjectGuid>
<ProjectTypeGuids>{EFBA0AD7-5A72-4C68-AF49-83D382785DCF};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>GalaSoft.MvvmLight</RootNamespace>
<AssemblyName>GalaSoft.MvvmLight.Platform.AndroidX</AssemblyName>
<FileAlignment>512</FileAlignment>
<AndroidResgenFile>Resources\Resource.Designer.cs</AndroidResgenFile>
<GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
<TargetFrameworkVersion>v9.0</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>TRACE;XAMARIN;ANDROID;DEBUG</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<DocumentationFile>bin\Debug\GalaSoft.MvvmLight.Platform.AndroidX.XML</DocumentationFile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE;XAMARIN;ANDROID</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<DocumentationFile>bin\Release\GalaSoft.MvvmLight.Platform.AndroidX.XML</DocumentationFile>
</PropertyGroup>
<ItemGroup>
<Reference Include="Mono.Android" />
<Reference Include="mscorlib" />
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Xml" />
<Reference Include="Xamarin.AndroidX.MultiDex">
<HintPath>..\packages\Xamarin.AndroidX.MultiDex.2.0.1.1\lib\monoandroid90\Xamarin.AndroidX.MultiDex.dll</HintPath>
</Reference>
<Reference Include="Java.Interop" />
<Reference Include="Xamarin.AndroidX.Annotation">
<HintPath>..\packages\Xamarin.AndroidX.Annotation.1.1.0.1\lib\monoandroid90\Xamarin.AndroidX.Annotation.dll</HintPath>
</Reference>
<Reference Include="Xamarin.AndroidX.Arch.Core.Common">
<HintPath>..\packages\Xamarin.AndroidX.Arch.Core.Common.2.1.0.1\lib\monoandroid90\Xamarin.AndroidX.Arch.Core.Common.dll</HintPath>
</Reference>
<Reference Include="Xamarin.AndroidX.Collection">
<HintPath>..\packages\Xamarin.AndroidX.Collection.1.1.0.1\lib\monoandroid90\Xamarin.AndroidX.Collection.dll</HintPath>
</Reference>
<Reference Include="Xamarin.AndroidX.Lifecycle.Common">
<HintPath>..\packages\Xamarin.AndroidX.Lifecycle.Common.2.2.0.1\lib\monoandroid90\Xamarin.AndroidX.Lifecycle.Common.dll</HintPath>
</Reference>
<Reference Include="Xamarin.AndroidX.Lifecycle.Runtime">
<HintPath>..\packages\Xamarin.AndroidX.Lifecycle.Runtime.2.2.0.1\lib\monoandroid90\Xamarin.AndroidX.Lifecycle.Runtime.dll</HintPath>
</Reference>
<Reference Include="Xamarin.AndroidX.VersionedParcelable">
<HintPath>..\packages\Xamarin.AndroidX.VersionedParcelable.1.1.1.1\lib\monoandroid90\Xamarin.AndroidX.VersionedParcelable.dll</HintPath>
</Reference>
<Reference Include="Xamarin.AndroidX.Core">
<HintPath>..\packages\Xamarin.AndroidX.Core.1.2.0.1\lib\monoandroid90\Xamarin.AndroidX.Core.dll</HintPath>
</Reference>
<Reference Include="Xamarin.AndroidX.CustomView">
<HintPath>..\packages\Xamarin.AndroidX.CustomView.1.0.0.1\lib\monoandroid90\Xamarin.AndroidX.CustomView.dll</HintPath>
</Reference>
<Reference Include="Xamarin.AndroidX.RecyclerView">
<HintPath>..\packages\Xamarin.AndroidX.RecyclerView.1.1.0.1\lib\monoandroid90\Xamarin.AndroidX.RecyclerView.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="..\GalaSoft.MvvmLight.Platform (NET45)\Properties\AssemblyInfo.cs">
<Link>Properties\AssemblyInfo.cs</Link>
</Compile>
<Compile Include="Helpers\CachingViewHolder.cs" />
<Compile Include="Helpers\ExtensionsAndroid2.cs" />
<Compile Include="Helpers\ObservableRecyclerAdapter.cs" />
<Compile Include="Resources\Resource.Designer.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\GalaSoft.MvvmLight.Platform %28Android%29\GalaSoft.MvvmLight.Platform %28Android%29.csproj">
<Project>{A5B7741D-E331-438C-B3BF-596B048DB622}</Project>
<Name>GalaSoft.MvvmLight.Platform (Android)</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
<Import Project="..\packages\Xamarin.AndroidX.MultiDex.2.0.1.1\build\monoandroid90\Xamarin.AndroidX.MultiDex.targets" Condition="Exists('..\packages\Xamarin.AndroidX.MultiDex.2.0.1.1\build\monoandroid90\Xamarin.AndroidX.MultiDex.targets')" />
<Import Project="..\packages\Xamarin.AndroidX.Migration.1.0.6.1\build\monoandroid90\Xamarin.AndroidX.Migration.targets" Condition="Exists('..\packages\Xamarin.AndroidX.Migration.1.0.6.1\build\monoandroid90\Xamarin.AndroidX.Migration.targets')" />
<Import Project="..\packages\Xamarin.AndroidX.Annotation.1.1.0.1\build\monoandroid90\Xamarin.AndroidX.Annotation.targets" Condition="Exists('..\packages\Xamarin.AndroidX.Annotation.1.1.0.1\build\monoandroid90\Xamarin.AndroidX.Annotation.targets')" />
<Import Project="..\packages\Xamarin.AndroidX.Arch.Core.Common.2.1.0.1\build\monoandroid90\Xamarin.AndroidX.Arch.Core.Common.targets" Condition="Exists('..\packages\Xamarin.AndroidX.Arch.Core.Common.2.1.0.1\build\monoandroid90\Xamarin.AndroidX.Arch.Core.Common.targets')" />
<Import Project="..\packages\Xamarin.AndroidX.Collection.1.1.0.1\build\monoandroid90\Xamarin.AndroidX.Collection.targets" Condition="Exists('..\packages\Xamarin.AndroidX.Collection.1.1.0.1\build\monoandroid90\Xamarin.AndroidX.Collection.targets')" />
<Import Project="..\packages\Xamarin.AndroidX.Lifecycle.Common.2.2.0.1\build\monoandroid90\Xamarin.AndroidX.Lifecycle.Common.targets" Condition="Exists('..\packages\Xamarin.AndroidX.Lifecycle.Common.2.2.0.1\build\monoandroid90\Xamarin.AndroidX.Lifecycle.Common.targets')" />
<Import Project="..\packages\Xamarin.AndroidX.Lifecycle.Runtime.2.2.0.1\build\monoandroid90\Xamarin.AndroidX.Lifecycle.Runtime.targets" Condition="Exists('..\packages\Xamarin.AndroidX.Lifecycle.Runtime.2.2.0.1\build\monoandroid90\Xamarin.AndroidX.Lifecycle.Runtime.targets')" />
<Import Project="..\packages\Xamarin.AndroidX.VersionedParcelable.1.1.1.1\build\monoandroid90\Xamarin.AndroidX.VersionedParcelable.targets" Condition="Exists('..\packages\Xamarin.AndroidX.VersionedParcelable.1.1.1.1\build\monoandroid90\Xamarin.AndroidX.VersionedParcelable.targets')" />
<Import Project="..\packages\Xamarin.AndroidX.Core.1.2.0.1\build\monoandroid90\Xamarin.AndroidX.Core.targets" Condition="Exists('..\packages\Xamarin.AndroidX.Core.1.2.0.1\build\monoandroid90\Xamarin.AndroidX.Core.targets')" />
<Import Project="..\packages\Xamarin.AndroidX.CustomView.1.0.0.1\build\monoandroid90\Xamarin.AndroidX.CustomView.targets" Condition="Exists('..\packages\Xamarin.AndroidX.CustomView.1.0.0.1\build\monoandroid90\Xamarin.AndroidX.CustomView.targets')" />
<Import Project="..\packages\Xamarin.AndroidX.RecyclerView.1.1.0.1\build\monoandroid90\Xamarin.AndroidX.RecyclerView.targets" Condition="Exists('..\packages\Xamarin.AndroidX.RecyclerView.1.1.0.1\build\monoandroid90\Xamarin.AndroidX.RecyclerView.targets')" />
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
using System;
using System.Collections.Generic;
using Android.Runtime;
using AndroidX.RecyclerView.Widget;
using Android.Views;

namespace GalaSoft.MvvmLight.Helpers
{
/// <summary>
/// An extension of <see cref="RecyclerView.ViewHolder"/> optimized for usage with the
/// <see cref="ObservableRecyclerAdapter{TItem, THolder}"/>. Provides additional features
/// that can be used with the MVVM Light data binding system.
/// </summary>
////[ClassInfo(typeof(ObservableAdapter<T>))]
public class CachingViewHolder : RecyclerView.ViewHolder
{
private readonly Dictionary<object, Binding> _bindings = new Dictionary<object, Binding>();
private readonly Dictionary<int, View> _cachedViews = new Dictionary<int, View>();
private Action<int, View> _clickCallback;

/// <summary>
/// A callback that will be executed when the corresponding item is clicked or tapped
/// by the user.
/// </summary>
public Action<int, View> ClickCallback
{
get
{
return _clickCallback;
}
set
{
if (value == null)
{
ItemView.Click -= OnViewClick;
}
else
{
ItemView.Click += OnViewClick;
}

_clickCallback = value;
}
}

/// <summary>
/// Initializes an instance of this class. In most cases this method
/// is not used by the developer.
/// </summary>
/// <param name="javaReference"></param>
/// <param name="transfer"></param>
public CachingViewHolder(IntPtr javaReference, JniHandleOwnership transfer)
: base(javaReference, transfer)
{
}

/// <summary>
/// Initializes an instance of this class.
/// </summary>
/// <param name="itemView">The view that this holder is attached to.</param>
public CachingViewHolder(View itemView)
: base(itemView)
{
}

/// <summary>
/// Detaches and removes a binding from this holder.
/// Use this method (in case a view is getting recycled) to clean up
/// existing bindings before attaching new ones. The binding that needs
/// to be detached must have been added to the holder using the <see cref="SaveBinding"/> method.
/// </summary>
/// <param name="key">The key corresponding to the binding to detach and delete. This is the
/// same key that was used in the <see cref="SaveBinding"/> method.</param>
/// <returns>The binding that has been detached and deleted, in case further processing
/// is necessary/</returns>
public Binding DeleteBinding(object key)
{
lock (_bindings)
{
if (_bindings.ContainsKey(key))
{
var binding = _bindings[key];
binding.Detach();
_bindings.Remove(key);
return binding;
}

return null;
}
}

/// <summary>
/// Explores the attached view and returns the UI element corresponding
/// to the viewId. If no element is found with this ID, the method returns null.
/// </summary>
/// <typeparam name="TView">The type of the view to be returned.</typeparam>
/// <param name="viewId">The ID of the subview that needs to be retrieved.</param>
/// <returns>The sub view corresponding to the viewId, or null if no corresponding sub view is found.</returns>
public TView FindCachedViewById<TView>(int viewId)
where TView : View
{
if (_cachedViews.ContainsKey(viewId))
{
return (TView)_cachedViews[viewId];
}

var view = ItemView.FindViewById<TView>(viewId);
_cachedViews.Add(viewId, view);
return view;
}

/// <summary>
/// Saves a binding between a element of the view and an element of the data item
/// represented by the view.
/// If the view is getting recycled, the binding should be deleted using the
/// <see cref="DeleteBinding"/> method.
/// </summary>
/// <param name="key">The key used to retriev the binding later. Typically
/// the key is the view to which the binding is attached (if there is only
/// one binding for this view).</param>
/// <param name="binding">The binding to be saved.</param>
public void SaveBinding(object key, Binding binding)
{
lock (_bindings)
{
if (_bindings.ContainsKey(key))
{
_bindings[key].Detach();
_bindings[key] = binding;
}
else
{
_bindings.Add(key, binding);
}
}
}

private void OnViewClick(object sender, EventArgs e)
{
var position = AdapterPosition;

if (position != RecyclerView.NoPosition)
{
_clickCallback?.Invoke(position, ItemView);
}
}
}
}
Loading