Iyon_Groznyy

Untitled

Apr 6th, 2022
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.95 KB | None | 0 0
  1. using Android.Content;
  2. using Android.Views;
  3. using Android.Widget;
  4. using AndroidX.ConstraintLayout.Widget;
  5. using Kdd.IdaCare.Mobile.Common.Enums;
  6. using Kdd.IdaCare.Mobile.Droid.Extensions;
  7. using Kdd.IdaCare.Mobile.Droid.Renderers.Native.Abstract;
  8. using Kdd.IdaCare.Mobile.Droid.Renderers.Native.Main.More;
  9. using Kdd.IdaCare.Mobile.Droid.Views.Controls.RecyclerViews.Adapters;
  10. using Kdd.IdaCare.Mobile.Droid.Views.ViewHolders.More;
  11. using Kdd.IdaCare.Mobile.Extensions.MvvmCross;
  12. using Kdd.IdaCare.Mobile.Resources;
  13. using Kdd.IdaCare.Mobile.UI.UI.Controls.Native.Main.More;
  14. using Kdd.IdaCare.Mobile.ViewModels.Items;
  15. using Kdd.IdaCare.Mobile.ViewModels.More;
  16. using MvvmCross.DroidX.RecyclerView;
  17. using MvvmCross.Platforms.Android.Binding;
  18.  
  19. [assembly: Xamarin.Forms.ExportRenderer(typeof(MoreView), typeof(MoreViewRenderer))]
  20. namespace Kdd.IdaCare.Mobile.Droid.Renderers.Native.Main.More
  21. {
  22. public sealed class MoreViewRenderer : BaseNativeLayoutRenderer<MoreView, ConstraintLayout, MoreViewModel>
  23. {
  24. private MvxRecyclerView _recyclerView;
  25. private TextView _usernameTextView;
  26. private TextView _workingGroupTextView;
  27. private TextView _versionTextView;
  28. private TextView _deviceIdTextView;
  29. private TextView _changesCountTextView;
  30. private TextView _lastDateTextView;
  31. private FrameLayout _syncFrameLayout;
  32. private FrameLayout _loadingOverlay;
  33. private FrameLayout _workingGroupFrameLayout;
  34. private ImageView _logoutImageView;
  35. private ImageView _syncImageView;
  36. private TextView _syncTextView;
  37.  
  38. public MoreViewRenderer(Context context)
  39. : base(context)
  40. {
  41.  
  42. }
  43.  
  44. protected override int LayoutId => Resource.Layout.layout_more;
  45.  
  46. protected override void Initialize(ConstraintLayout control)
  47. {
  48. _loadingOverlay = control.FindViewById<FrameLayout>(Resource.Id.loading_overlay);
  49. _recyclerView = control.FindViewById<MvxRecyclerView>(Resource.Id.recycler_view);
  50. _usernameTextView = control.FindViewById<TextView>(Resource.Id.username_text_view);
  51. _workingGroupTextView = control.FindViewById<TextView>(Resource.Id.working_group_text_view);
  52. _versionTextView = control.FindViewById<TextView>(Resource.Id.version_text_view);
  53. _deviceIdTextView = control.FindViewById<TextView>(Resource.Id.device_id_text_view);
  54. _changesCountTextView = control.FindViewById<TextView>(Resource.Id.changes_count_text_view);
  55. _lastDateTextView = control.FindViewById<TextView>(Resource.Id.last_date_text_view);
  56. _syncFrameLayout = control.FindViewById<FrameLayout>(Resource.Id.synced_frame_layout);
  57. _workingGroupFrameLayout = control.FindViewById<FrameLayout>(Resource.Id.working_group_frame_layout);
  58. _logoutImageView = control.FindViewById<ImageView>(Resource.Id.logout_image_view);
  59. _syncImageView = control.FindViewById<ImageView>(Resource.Id.sync_image_view);
  60. _syncTextView = control.FindViewById<TextView>(Resource.Id.sync_text_view);
  61.  
  62. var logoutTextView = control.FindViewById<TextView>(Resource.Id.logout_text_view);
  63. logoutTextView.Text = AppStrings.Logout;
  64. var syncTextView = control.FindViewById<TextView>(Resource.Id.sync_text_view);
  65. syncTextView.Text = AppStrings.SyncShort;
  66. var changesTextView = control.FindViewById<TextView>(Resource.Id.changes_text_view);
  67. changesTextView.Text = $"{AppStrings.Changes}:";
  68.  
  69. var adapter = new RecyclerAdapter(this);
  70. _recyclerView.Adapter = adapter
  71. .Register<MoreItemViewModel, MoreItemViewHolder>(Resource.Layout.item_more);
  72.  
  73. var headerView = control.FindViewById<View>(Resource.Id.header_view);
  74. headerView.SetRoundedCorners(2);
  75. _workingGroupFrameLayout.SetRoundedCorners(2);
  76. _syncFrameLayout.SetRoundedCorners(24);
  77. }
  78.  
  79. protected override void Bind()
  80. {
  81. using var bindingSet = CreateBindingSet();
  82.  
  83. bindingSet.Bind(_recyclerView).For(v => v.ItemsSource).To(vm => vm.Items);
  84. bindingSet.Bind(_recyclerView).For(v => v.ItemClick).To(vm => vm.ExecuteItemActionCommand);
  85. bindingSet.Bind(_usernameTextView).For(v => v.Text).To(vm => vm.CurrentUser);
  86. bindingSet.Bind(_workingGroupTextView).For(v => v.Text).To(vm => vm.WorkingGroupPresentation);
  87. bindingSet.Bind(_versionTextView).For(v => v.Text).To(vm => vm.SoftwareVersionPresentation);
  88. bindingSet.Bind(_deviceIdTextView).For(v => v.Text).To(vm => vm.RegisterDeviceIdPresentation);
  89. bindingSet.Bind(_changesCountTextView).For(v => v.Text).To(vm => vm.Changes);
  90. bindingSet.Bind(_lastDateTextView).For(v => v.Text).To(vm => vm.LastUpdatePresentation);
  91. bindingSet.Bind(_workingGroupFrameLayout).For(v => v.BindBackgroundColor()).To(vm => vm.WorkingGroupColorPresentation);
  92. bindingSet.Bind(_logoutImageView).For(v => v.BindTintColor()).To(vm => vm.WorkingGroupColorPresentation);
  93. bindingSet.Bind(_logoutImageView).For(v => v.BindClick()).To(vm => vm.LogoutCommand);
  94. bindingSet.Bind(_loadingOverlay).For(v => v.BindVisible()).To(vm => vm.IsBusy);
  95. bindingSet.Bind(_syncFrameLayout).For(v => v.BindBackgroundColor()).To(vm => vm.CanSync)
  96. .WithBoolConversion(AppColor.RedLightest, AppColor.BlueLightest);
  97. bindingSet.Bind(_syncImageView).For(v => v.BindTintColor()).To(vm => vm.CanSync)
  98. .WithBoolConversion(AppColor.Red, AppColor.Blue);
  99. bindingSet.Bind(_syncTextView).For(v => v.BindTextColor()).To(vm => vm.CanSync)
  100. .WithBoolConversion(AppColor.Red, AppColor.Blue);
  101. bindingSet.Bind(_syncFrameLayout).For(v => v.BindClick()).To(vm => vm.SyncCommand);
  102. }
  103. }
  104. }
Advertisement
Add Comment
Please, Sign In to add comment