public override void OnSwiped(AndroidX.RecyclerView.Widget.RecyclerView.ViewHolder viewHolder, int direction) { //Store the position swiped. int position = viewHolder.LayoutPosition; //Store the deleted item in case of restoration. HistoryViewModel itemDeleted = null; if (direction == ItemTouchHelper.Left || direction == ItemTouchHelper.Right) { //The item was swiped. //Remove from list. itemDeleted = historyViewModels[position]; historyViewModels.RemoveAt(position); recyclerView.GetAdapter().NotifyItemRemoved(position); //Should delete PermissionHelper.ShouldDelete = true; } if (itemDeleted != null) { //The item was actually deleted. Ask for restoration. string accentColor = "#" + fragment.Context.GetColor(Resource.Color.colorAccent).ToString("X"); string primaryColor = "#" + fragment.Context.GetColor(Resource.Color.colorPrimary).ToString("X"); var snackBar = Snackbar.Make(fragment.View, $"Saved Item Deleted", Snackbar.LengthLong) .SetAction("Restore", (x) => { //Restore the item. historyViewModels.Insert(position, itemDeleted); recyclerView.GetAdapter().NotifyItemInserted(position); //Dont delete. PermissionHelper.ShouldDelete = false; }) .SetActionTextColor(Android.Graphics.Color.ParseColor(accentColor)); snackBar.AddCallback(new FileDeletionCallback(itemDeleted.FileName, fragment as HistoryFragment, historyViewModels)); snackBar.View.SetBackgroundColor(Android.Graphics.Color.ParseColor(primaryColor)); //Get the exisiting text. TextView textView = snackBar.View.FindViewById <TextView>(Resource.Id.snackbar_text); if (AppCompatDelegate.DefaultNightMode == AppCompatDelegate.ModeNightNo) { textView.SetTextColor(Android.Graphics.Color.Black); } else { textView.SetTextColor(Android.Graphics.Color.White); } snackBar.Show(); } }
public override void OnBindViewHolder(AndroidX.RecyclerView.Widget.RecyclerView.ViewHolder viewHolder, int position) { var item = imageViewModels[position]; var holder = viewHolder as HistoryAdapterViewHolder; holder.FileNameTextView.Text = item.FileName.GetFileNameWithoutExtension(); holder.SizeTextView.Text = item.FileSizeAndDayModified; var drawable = item.FileName.EndsWith("zip") ? ContextCompat.GetDrawable(mainActivity, Resource.Drawable.zip_drawable) : ContextCompat.GetDrawable(mainActivity, Resource.Drawable.pdf_drawable); Glide.With(mainActivity) .Load(drawable) .Thumbnail(0.5f) .Into(holder.FileIcon); }
// Replace the contents of a view (invoked by the layout manager) public override void OnBindViewHolder(AndroidX.RecyclerView.Widget.RecyclerView.ViewHolder viewHolder, int position) { var item = items[position]; // Replace the contents of the view with that element var holder = viewHolder as FoundImagesAdapterViewHolder; holder.FileNameTextView.Text = items[position].FileName.GetFileNameWithoutExtension(); holder.FileSizeTextView.Text = items[position].FileSize; Glide.With(Fragment) .Load(Android.Net.Uri.FromFile(new Java.IO.File(item.FullPath))) .Thumbnail(0.9f) .SetDiskCacheStrategy(DiskCacheStrategy.All) .Placeholder(Resource.Drawable.abc_spinner_mtrl_am_alpha) .Into(holder.ImageView); }
public override void OnChildViewHolderSelected(AndroidX.RecyclerView.Widget.RecyclerView parent, AndroidX.RecyclerView.Widget.RecyclerView.ViewHolder child, int position, int subposition) { base.OnChildViewHolderSelected(parent, child, position, subposition); var adapter = parent.GetAdapter() as IMvxRecyclerAdapter; var item = adapter?.GetItem(position); if (item == null) { MvxAndroidLog.Instance.Log(LogLevel.Error, "Could not retrieve item from adapter. Can't pass currently selected item through!"); return; } if (ItemSelection != null && ItemSelection.CanExecute(item)) { ItemSelection.Execute(item); } }
public override void OnSwiped(AndroidX.RecyclerView.Widget.RecyclerView.ViewHolder viewHolder, int direction) { //Store the position in case of restoration. int position = viewHolder.LayoutPosition; //Store the potentially deleted item. ImageFileNameModel itemDeleted = null; if (direction == ItemTouchHelper.Right || direction == ItemTouchHelper.Left) { //Remove the item in the model. itemDeleted = ImageFileNameModels[position]; ImageFileNameModels.RemoveAt(position); ItemCountHelper.UpdateExportItemsCount(mainActivity, ImageFileNameModels); RecyclerView.GetAdapter().NotifyItemRemoved(position); PermissionHelper.ShouldDelete = true; } if (itemDeleted != null) { //The item was actually deleted. Ask for restoration. string accentColor = "#" + Fragment.Context.GetColor(Resource.Color.colorAccent).ToString("X"); string primaryColor = "#" + Fragment.Context.GetColor(Resource.Color.colorPrimary).ToString("X"); var snackBar = Snackbar.Make(Fragment.View, $"Item Removed", Snackbar.LengthLong) .SetAction("Restore", (x) => { //Restore the item. ImageFileNameModels.Insert(position, itemDeleted); ItemCountHelper.UpdateExportItemsCount(mainActivity, ImageFileNameModels); RecyclerView.GetAdapter().NotifyItemInserted(position); mainActivity.SupportActionBar.Subtitle = $"Current count - {ImageFileNameModels.Count}"; PermissionHelper.ShouldDelete = false; }) .SetActionTextColor(Android.Graphics.Color.ParseColor(accentColor)); snackBar.AddCallback(new FileDeletionCallback(itemDeleted.FileName, mainActivity, ImageFileNameModels)); snackBar.View.SetBackgroundColor(Android.Graphics.Color.ParseColor(primaryColor)); //Get the exisiting text. TextView textView = snackBar.View.FindViewById <TextView>(Resource.Id.snackbar_text); if (AppCompatDelegate.DefaultNightMode == AppCompatDelegate.ModeNightNo) { textView.SetTextColor(Android.Graphics.Color.Black); } else { textView.SetTextColor(Android.Graphics.Color.White); } snackBar.Show(); } }
public override bool OnMove(AndroidX.RecyclerView.Widget.RecyclerView recyclerView, AndroidX.RecyclerView.Widget.RecyclerView.ViewHolder viewHolder, AndroidX.RecyclerView.Widget.RecyclerView.ViewHolder target) { throw new NotImplementedException(); }
public MvxViewHolderBoundEventArgs(int itemPosition, object dataContext, AndroidX.RecyclerView.Widget.RecyclerView.ViewHolder holder) { ItemPosition = itemPosition; DataContext = dataContext; Holder = holder; }