diff --git a/src/ReactiveUI.AndroidSupport/ControlFetcherMixin.cs b/src/ReactiveUI.AndroidSupport/ControlFetcherMixin.cs index 69b59ad9bb..d8de7e5950 100644 --- a/src/ReactiveUI.AndroidSupport/ControlFetcherMixin.cs +++ b/src/ReactiveUI.AndroidSupport/ControlFetcherMixin.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -7,8 +7,6 @@ using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; -using System.Text; -using Android.App; using Android.Views; using Java.Interop; using Android.Support.V7.App; diff --git a/src/ReactiveUI.AndroidSupport/ReactiveAppCompatActivity.cs b/src/ReactiveUI.AndroidSupport/ReactiveAppCompatActivity.cs index 295c02a9cb..4998ee33d7 100644 --- a/src/ReactiveUI.AndroidSupport/ReactiveAppCompatActivity.cs +++ b/src/ReactiveUI.AndroidSupport/ReactiveAppCompatActivity.cs @@ -1,32 +1,18 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. using System; -using System.Collections.Generic; using System.ComponentModel; -using System.Diagnostics.Contracts; -using System.Linq; using System.Reactive; -using System.Reactive.Concurrency; -using System.Reactive.Disposables; using System.Reactive.Linq; using System.Reactive.Subjects; using System.Reactive.Threading.Tasks; -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.Serialization; -using System.Text; -using System.Threading; using System.Threading.Tasks; using Android.App; using Android.Content; -using Android.OS; using Android.Runtime; using Android.Support.V7.App; -using Android.Views; -using Android.Widget; -using Splat; namespace ReactiveUI.AndroidSupport { @@ -42,14 +28,14 @@ protected ReactiveAppCompatActivity() { } TViewModel _ViewModel; public TViewModel ViewModel { - get { return _ViewModel; } - set { this.RaiseAndSetIfChanged(ref _ViewModel, value); } + get => _ViewModel; + set => this.RaiseAndSetIfChanged(ref _ViewModel, value); } object IViewFor.ViewModel { - get { return _ViewModel; } - set { _ViewModel = (TViewModel)value; } + get => _ViewModel; + set => _ViewModel = (TViewModel)value; } } @@ -61,8 +47,8 @@ public class ReactiveAppCompatActivity : AppCompatActivity, IReactiveObject, IRe { public event PropertyChangingEventHandler PropertyChanging { - add { PropertyChangingEventManager.AddHandler(this, value); } - remove { PropertyChangingEventManager.RemoveHandler(this, value); } + add => PropertyChangingEventManager.AddHandler(this, value); + remove => PropertyChangingEventManager.RemoveHandler(this, value); } void IReactiveObject.RaisePropertyChanging(PropertyChangingEventArgs args) @@ -72,8 +58,8 @@ void IReactiveObject.RaisePropertyChanging(PropertyChangingEventArgs args) public event PropertyChangedEventHandler PropertyChanged { - add { PropertyChangedEventManager.AddHandler(this, value); } - remove { PropertyChangedEventManager.RemoveHandler(this, value); } + add => PropertyChangedEventManager.AddHandler(this, value); + remove => PropertyChangedEventManager.RemoveHandler(this, value); } void IReactiveObject.RaisePropertyChanged(PropertyChangedEventArgs args) @@ -85,18 +71,12 @@ void IReactiveObject.RaisePropertyChanged(PropertyChangedEventArgs args) /// Represents an Observable that fires *before* a property is about to /// be changed. /// - public IObservable> Changing - { - get { return this.getChangingObservable(); } - } + public IObservable> Changing => this.getChangingObservable(); /// /// Represents an Observable that fires *after* a property has changed. /// - public IObservable> Changed - { - get { return this.getChangedObservable(); } - } + public IObservable> Changed => this.getChangedObservable(); protected ReactiveAppCompatActivity() { } @@ -116,13 +96,13 @@ public IDisposable SuppressChangeNotifications() return this.suppressChangeNotifications(); } - public IObservable ThrownExceptions { get { return this.getThrownExceptionsObservable(); } } + public IObservable ThrownExceptions => this.getThrownExceptionsObservable(); readonly Subject activated = new Subject(); - public IObservable Activated { get { return activated.AsObservable(); } } + public IObservable Activated => activated.AsObservable(); readonly Subject deactivated = new Subject(); - public IObservable Deactivated { get { return deactivated.AsObservable(); } } + public IObservable Deactivated => deactivated.AsObservable(); protected override void OnPause() { @@ -137,10 +117,7 @@ protected override void OnResume() } readonly Subject> activityResult = new Subject>(); - public IObservable> ActivityResult - { - get { return activityResult.AsObservable(); } - } + public IObservable> ActivityResult => activityResult.AsObservable(); protected override void OnActivityResult(int requestCode, Result resultCode, Intent data) { diff --git a/src/ReactiveUI.AndroidSupport/ReactiveDialogFragment.cs b/src/ReactiveUI.AndroidSupport/ReactiveDialogFragment.cs index f25ecfa54f..2d90b4406c 100644 --- a/src/ReactiveUI.AndroidSupport/ReactiveDialogFragment.cs +++ b/src/ReactiveUI.AndroidSupport/ReactiveDialogFragment.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -22,14 +22,14 @@ protected ReactiveDialogFragment() { } TViewModel _ViewModel; public TViewModel ViewModel { - get { return _ViewModel; } - set { this.RaiseAndSetIfChanged(ref _ViewModel, value); } + get => _ViewModel; + set => this.RaiseAndSetIfChanged(ref _ViewModel, value); } object IViewFor.ViewModel { - get { return _ViewModel; } - set { _ViewModel = (TViewModel)value; } + get => _ViewModel; + set => _ViewModel = (TViewModel)value; } } @@ -43,8 +43,8 @@ protected ReactiveDialogFragment() { } public event PropertyChangingEventHandler PropertyChanging { - add { PropertyChangingEventManager.AddHandler(this, value); } - remove { PropertyChangingEventManager.RemoveHandler(this, value); } + add => PropertyChangingEventManager.AddHandler(this, value); + remove => PropertyChangingEventManager.RemoveHandler(this, value); } void IReactiveObject.RaisePropertyChanging(PropertyChangingEventArgs args) @@ -54,8 +54,8 @@ void IReactiveObject.RaisePropertyChanging(PropertyChangingEventArgs args) public event PropertyChangedEventHandler PropertyChanged { - add { PropertyChangedEventManager.AddHandler(this, value); } - remove { PropertyChangedEventManager.RemoveHandler(this, value); } + add => PropertyChangedEventManager.AddHandler(this, value); + remove => PropertyChangedEventManager.RemoveHandler(this, value); } void IReactiveObject.RaisePropertyChanged(PropertyChangedEventArgs args) @@ -67,18 +67,12 @@ void IReactiveObject.RaisePropertyChanged(PropertyChangedEventArgs args) /// Represents an Observable that fires *before* a property is about to /// be changed. /// - public IObservable> Changing - { - get { return this.getChangingObservable(); } - } + public IObservable> Changing => this.getChangingObservable(); /// /// Represents an Observable that fires *after* a property has changed. /// - public IObservable> Changed - { - get { return this.getChangedObservable(); } - } + public IObservable> Changed => this.getChangedObservable(); /// /// When this method is called, an object will not fire change @@ -92,13 +86,13 @@ public IDisposable SuppressChangeNotifications() return this.suppressChangeNotifications(); } - public IObservable ThrownExceptions { get { return this.getThrownExceptionsObservable(); } } + public IObservable ThrownExceptions => this.getThrownExceptionsObservable(); readonly Subject activated = new Subject(); - public IObservable Activated { get { return activated.AsObservable(); } } + public IObservable Activated => activated.AsObservable(); readonly Subject deactivated = new Subject(); - public IObservable Deactivated { get { return deactivated.AsObservable(); } } + public IObservable Deactivated => deactivated.AsObservable(); public override void OnPause() { @@ -112,4 +106,4 @@ public override void OnResume() activated.OnNext(Unit.Default); } } -} \ No newline at end of file +} diff --git a/src/ReactiveUI.AndroidSupport/ReactiveFragment.cs b/src/ReactiveUI.AndroidSupport/ReactiveFragment.cs index ae3e0bffb6..57efa2aef2 100644 --- a/src/ReactiveUI.AndroidSupport/ReactiveFragment.cs +++ b/src/ReactiveUI.AndroidSupport/ReactiveFragment.cs @@ -1,28 +1,10 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Android.App; -using Android.Content; -using Android.OS; -using Android.Runtime; -using Android.Util; -using Android.Views; -using Android.Widget; -using System.Runtime.Serialization; using System.ComponentModel; -using System.Reflection; using System.Reactive.Subjects; -using System.Reactive.Concurrency; -using System.Threading; -using System.Reactive.Disposables; -using System.Diagnostics.Contracts; -using System.Runtime.CompilerServices; -using Splat; using System.Reactive; using System.Reactive.Linq; @@ -39,13 +21,13 @@ protected ReactiveFragment() { } TViewModel _ViewModel; public TViewModel ViewModel { - get { return _ViewModel; } - set { this.RaiseAndSetIfChanged(ref _ViewModel, value); } + get => _ViewModel; + set => this.RaiseAndSetIfChanged(ref _ViewModel, value); } object IViewFor.ViewModel { - get { return _ViewModel; } - set { _ViewModel = (TViewModel)value; } + get => _ViewModel; + set => _ViewModel = (TViewModel)value; } } @@ -58,8 +40,8 @@ public class ReactiveFragment : global::Android.Support.V4.App.Fragment, IReacti protected ReactiveFragment() { } public event PropertyChangingEventHandler PropertyChanging { - add { PropertyChangingEventManager.AddHandler(this, value); } - remove { PropertyChangingEventManager.RemoveHandler(this, value); } + add => PropertyChangingEventManager.AddHandler(this, value); + remove => PropertyChangingEventManager.RemoveHandler(this, value); } void IReactiveObject.RaisePropertyChanging(PropertyChangingEventArgs args) @@ -68,8 +50,8 @@ void IReactiveObject.RaisePropertyChanging(PropertyChangingEventArgs args) } public event PropertyChangedEventHandler PropertyChanged { - add { PropertyChangedEventManager.AddHandler(this, value); } - remove { PropertyChangedEventManager.RemoveHandler(this, value); } + add => PropertyChangedEventManager.AddHandler(this, value); + remove => PropertyChangedEventManager.RemoveHandler(this, value); } void IReactiveObject.RaisePropertyChanged(PropertyChangedEventArgs args) @@ -81,36 +63,32 @@ void IReactiveObject.RaisePropertyChanged(PropertyChangedEventArgs args) /// Represents an Observable that fires *before* a property is about to /// be changed. /// - public IObservable> Changing { - get { return this.getChangingObservable(); } - } + public IObservable> Changing => this.getChangingObservable(); /// /// Represents an Observable that fires *after* a property has changed. /// - public IObservable> Changed { - get { return this.getChangedObservable(); } - } + public IObservable> Changed => this.getChangedObservable(); /// /// When this method is called, an object will not fire change /// notifications (neither traditional nor Observable notifications) /// until the return value is disposed. /// - /// An object that, when disposed, reenables change + /// An object that, when disposed, re-enables change /// notifications. public IDisposable SuppressChangeNotifications() { return this.suppressChangeNotifications(); } - public IObservable ThrownExceptions { get { return this.getThrownExceptionsObservable(); } } + public IObservable ThrownExceptions => this.getThrownExceptionsObservable(); readonly Subject activated = new Subject(); - public IObservable Activated { get { return activated.AsObservable(); } } + public IObservable Activated => activated.AsObservable(); readonly Subject deactivated = new Subject(); - public IObservable Deactivated { get { return deactivated.AsObservable(); } } + public IObservable Deactivated => deactivated.AsObservable(); public override void OnPause() { diff --git a/src/ReactiveUI.AndroidSupport/ReactiveFragmentActivity.cs b/src/ReactiveUI.AndroidSupport/ReactiveFragmentActivity.cs index 05ad0ae7f4..5dc6ebf0f9 100644 --- a/src/ReactiveUI.AndroidSupport/ReactiveFragmentActivity.cs +++ b/src/ReactiveUI.AndroidSupport/ReactiveFragmentActivity.cs @@ -1,34 +1,19 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; using Android.App; using Android.Content; -using Android.OS; -using Android.Runtime; -using Android.Views; -using Android.Widget; -using System.Runtime.Serialization; using System.ComponentModel; -using System.Reflection; using System.Reactive.Linq; using System.Reactive.Subjects; -using System.Reactive.Concurrency; using System.Reactive.Threading.Tasks; -using System.Threading; using System.Threading.Tasks; -using System.Reactive.Disposables; -using System.Diagnostics.Contracts; -using System.Runtime.CompilerServices; -using Splat; using System.Reactive; using Android.Support.V4.App; -namespace ReactiveUI +namespace ReactiveUI.AndroidSupport { /// /// This is an Activity that is both an Activity and has ReactiveObject powers @@ -42,14 +27,14 @@ protected ReactiveFragmentActivity() { } TViewModel _ViewModel; public TViewModel ViewModel { - get { return _ViewModel; } - set { this.RaiseAndSetIfChanged(ref _ViewModel, value); } + get => _ViewModel; + set => this.RaiseAndSetIfChanged(ref _ViewModel, value); } object IViewFor.ViewModel { - get { return _ViewModel; } - set { _ViewModel = (TViewModel)value; } + get => _ViewModel; + set => _ViewModel = (TViewModel)value; } } @@ -61,8 +46,8 @@ public class ReactiveFragmentActivity : FragmentActivity, IReactiveObject, IReac { public event PropertyChangingEventHandler PropertyChanging { - add { PropertyChangingEventManager.AddHandler(this, value); } - remove { PropertyChangingEventManager.RemoveHandler(this, value); } + add => PropertyChangingEventManager.AddHandler(this, value); + remove => PropertyChangingEventManager.RemoveHandler(this, value); } void IReactiveObject.RaisePropertyChanging(PropertyChangingEventArgs args) @@ -72,8 +57,8 @@ void IReactiveObject.RaisePropertyChanging(PropertyChangingEventArgs args) public event PropertyChangedEventHandler PropertyChanged { - add { PropertyChangedEventManager.AddHandler(this, value); } - remove { PropertyChangedEventManager.RemoveHandler(this, value); } + add => PropertyChangedEventManager.AddHandler(this, value); + remove => PropertyChangedEventManager.RemoveHandler(this, value); } void IReactiveObject.RaisePropertyChanged(PropertyChangedEventArgs args) @@ -85,38 +70,32 @@ void IReactiveObject.RaisePropertyChanged(PropertyChangedEventArgs args) /// Represents an Observable that fires *before* a property is about to /// be changed. /// - public IObservable> Changing - { - get { return this.getChangingObservable(); } - } + public IObservable> Changing => this.getChangingObservable(); /// /// Represents an Observable that fires *after* a property has changed. /// - public IObservable> Changed - { - get { return this.getChangedObservable(); } - } + public IObservable> Changed => this.getChangedObservable(); /// /// When this method is called, an object will not fire change /// notifications (neither traditional nor Observable notifications) /// until the return value is disposed. /// - /// An object that, when disposed, reenables change + /// An object that, when disposed, re-enables change /// notifications. public IDisposable SuppressChangeNotifications() { return this.suppressChangeNotifications(); } - public IObservable ThrownExceptions { get { return this.getThrownExceptionsObservable(); } } + public IObservable ThrownExceptions => this.getThrownExceptionsObservable(); readonly Subject activated = new Subject(); - public IObservable Activated { get { return activated.AsObservable(); } } + public IObservable Activated => activated.AsObservable(); readonly Subject deactivated = new Subject(); - public IObservable Deactivated { get { return deactivated.AsObservable(); } } + public IObservable Deactivated => deactivated.AsObservable(); protected override void OnPause() { @@ -131,10 +110,7 @@ protected override void OnResume() } readonly Subject> activityResult = new Subject>(); - public IObservable> ActivityResult - { - get { return activityResult.AsObservable(); } - } + public IObservable> ActivityResult => activityResult.AsObservable(); protected override void OnActivityResult(int requestCode, Result resultCode, Intent data) { diff --git a/src/ReactiveUI.AndroidSupport/ReactivePagerAdapter.cs b/src/ReactiveUI.AndroidSupport/ReactivePagerAdapter.cs index fe2f950234..e18b424bad 100644 --- a/src/ReactiveUI.AndroidSupport/ReactivePagerAdapter.cs +++ b/src/ReactiveUI.AndroidSupport/ReactivePagerAdapter.cs @@ -4,39 +4,40 @@ using System; using System.Collections.Generic; +using System.Collections.Specialized; using System.Linq; using System.Reactive.Disposables; -using System.Text; using System.Threading; using Android.Support.V4.View; using Android.Views; +using DynamicData; +using DynamicData.Binding; using Splat; using Object = Java.Lang.Object; -namespace ReactiveUI.Legacy +namespace ReactiveUI.AndroidSupport { /// /// ReactivePagerAdapter is a PagerAdapter that will interface with a - /// ReactiveList, in a similar fashion to ReactiveTableViewSource. + /// Observable change set, in a similar fashion to ReactiveTableViewSource. /// - [Obsolete("ReactiveList is no longer supported. We suggest replacing it with DynamicData https://github.com/rolandpheasant/dynamicdata")] public class ReactivePagerAdapter : PagerAdapter, IEnableLogger where TViewModel : class { - readonly IReadOnlyReactiveList list; - readonly Func viewCreator; - readonly Action viewInitializer; + private readonly SourceList list; + private readonly Func viewCreator; + private readonly Action viewInitializer; IDisposable inner; - public ReactivePagerAdapter(IReadOnlyReactiveList backingList, + public ReactivePagerAdapter(IObservable> changeSet, Func viewCreator, Action viewInitializer = null) { - this.list = backingList; + this.list = new SourceList(changeSet); this.viewCreator = viewCreator; this.viewInitializer = viewInitializer; - inner = this.list.Changed.Subscribe(_ => NotifyDataSetChanged()); + inner = this.list.Connect().Subscribe(_ => NotifyDataSetChanged()); } public override bool IsViewFromObject(View view, Object @object) @@ -46,19 +47,16 @@ public override bool IsViewFromObject(View view, Object @object) public override Object InstantiateItem(ViewGroup container, int position) { - var data = list[position]; + var data = list.Items.ElementAt(position); // NB: PagerAdapter does not recycle itself. var theView = viewCreator(data, container); - var ivf = theView.GetViewHost() as IViewFor; - if (ivf != null) { + if (theView.GetViewHost() is IViewFor ivf) { ivf.ViewModel = data; } - if (viewInitializer != null) { - viewInitializer(data, theView); - } + viewInitializer?.Invoke(data, theView); container.AddView(theView, 0); return theView; @@ -70,9 +68,7 @@ public override void DestroyItem(ViewGroup container, int position, Object @obje container.RemoveView(view); } - public override int Count { - get { return list.Count; } - } + public override int Count => list.Count; protected override void Dispose(bool disposing) { @@ -80,4 +76,16 @@ protected override void Dispose(bool disposing) Interlocked.Exchange(ref inner, Disposable.Empty).Dispose(); } } + + public class ReactivePagerAdapter : ReactivePagerAdapter + where TViewModel : class + where TCollection : INotifyCollectionChanged, IEnumerable + { + public ReactivePagerAdapter(TCollection collection, + Func viewCreator, + Action viewInitializer = null) + : base(collection.ToObservableChangeSet(), viewCreator, viewInitializer) + { + } + } } diff --git a/src/ReactiveUI.AndroidSupport/ReactiveRecyclerViewAdapter.cs b/src/ReactiveUI.AndroidSupport/ReactiveRecyclerViewAdapter.cs index 57c74c0d5c..766699f341 100644 --- a/src/ReactiveUI.AndroidSupport/ReactiveRecyclerViewAdapter.cs +++ b/src/ReactiveUI.AndroidSupport/ReactiveRecyclerViewAdapter.cs @@ -17,7 +17,7 @@ using DynamicData; using DynamicData.Binding; -namespace ReactiveUI.Android.Support +namespace ReactiveUI.AndroidSupport { /// /// An adapter for the Android .