Last active
June 6, 2020 10:51
-
-
Save Cheesebaron/8130a835a0f0d0747c10 to your computer and use it in GitHub Desktop.
Bindable SwipeRefreshLayout
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<Your.Awesome.Namespace.BindableSwipeRefreshLayout | |
xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:app="http://schemas.android.com/apk/res-auto" | |
android:id="@+id/refresher" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
app:MvxBind="Refreshing IsRefreshing; Refresh RefreshCommand"> | |
<Mvx.MvxListView | |
android:layout_height="match_parent" | |
android:layout_width="match_parent" | |
android:divider="@null" | |
app:MvxItemTemplate="@layout/listitem_awesome" | |
app:MvxBind="ItemsSource AwesomeSauce; ItemClick AwesomeCommand" /> | |
</Your.Awesome.Namespace.BindableSwipeRefreshLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Activity(Label = "Awesome!")] | |
public class ValidationView | |
: MvxActivity<AwesomeViewModel> | |
{ | |
protected override void OnCreate(Bundle bundle) | |
{ | |
base.OnCreate(bundle); | |
RequestWindowFeature(WindowFeatures.ActionBar); | |
SetContentView(Resource.Layout.awesome_layout); | |
var swipeLayout = FindViewById<BindableSwipeRefreshLayout>(Resource.Id.refresher); | |
swipeLayout.SetColorScheme( | |
Resource.Color.awesomeColor1, Resource.Color.awesomeColor2, | |
Resource.Color.awesomeColor3, Resource.Color.awesomeColor4); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class BindableSwipeRefreshLayout | |
: SwipeRefreshLayout | |
{ | |
private ICommand _refresh; | |
protected BindableSwipeRefreshLayout(IntPtr javaReference, JniHandleOwnership transfer) | |
: base(javaReference, transfer) { } | |
public BindableSwipeRefreshLayout(Context p0) | |
: this(p0, null) { } | |
public BindableSwipeRefreshLayout(Context p0, IAttributeSet p1) | |
: base(p0, p1) { } | |
public new bool Refreshing | |
{ | |
get { return base.Refreshing; } | |
set { base.Refreshing = value; } | |
} | |
public new ICommand Refresh | |
{ | |
get { return _refresh; } | |
set | |
{ | |
_refresh = value; | |
if (_refresh != null) | |
EnsureOnRefreshOverloaded(); | |
} | |
} | |
private bool _refreshOverloaded; | |
private void EnsureOnRefreshOverloaded() | |
{ | |
if (_refreshOverloaded) | |
return; | |
_refreshOverloaded = true; | |
base.Refresh += (sender, args) => ExecuteCommandOnRefresh(Refresh); | |
} | |
protected virtual void ExecuteCommandOnRefresh(ICommand command) | |
{ | |
if (command == null) | |
return; | |
if (!command.CanExecute(null)) | |
return; | |
command.Execute(null); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment