private View getStartView(RecyclerView.LayoutManager layoutManager, OrientationHelper helper) { var linearLayoutManager = (LinearLayoutManager)layoutManager; var firstChildIndex = linearLayoutManager.FindFirstVisibleItemPosition(); if (firstChildIndex == RecyclerView.NoPosition) { return(null); } subject.OnNext(linearLayoutManager.FindFirstCompletelyVisibleItemPosition() + 1); var lastItemIndex = linearLayoutManager.ItemCount - 1; var isLastItem = linearLayoutManager.FindLastCompletelyVisibleItemPosition() == lastItemIndex; if (isLastItem) { return(null); } var firstView = layoutManager.FindViewByPosition(firstChildIndex); var decoratedEnd = helper.GetDecoratedEnd(firstView); var threshold = helper.GetDecoratedMeasurement(firstView) / 2; if (decoratedEnd >= threshold && decoratedEnd > 0) { return(firstView); } return(layoutManager.FindViewByPosition(firstChildIndex + 1)); }
private View GetStartView( RecyclerView.LayoutManager layoutManager, OrientationHelper helper, out int viewPosition) { viewPosition = -1; if (!(layoutManager is LinearLayoutManager manager)) { return(base.FindSnapView(layoutManager)); } int firstChild = manager.FindFirstVisibleItemPosition(); bool isLastItem = manager.FindLastCompletelyVisibleItemPosition() == layoutManager.ItemCount - 1; if (isLastItem) { if (WeakNativeView.TryGetTarget(out var target)) { target.CurrentSnapIndex = layoutManager.ItemCount - 1; // System.Diagnostics.Debug.WriteLine($">>>>>> CurrentSnapIndex: {target.CurrentSnapIndex}"); } return(null); } if (firstChild == RecyclerView.NoPosition) { return(null); } View child = layoutManager.FindViewByPosition(firstChild); if (helper.GetDecoratedEnd(child) >= helper.GetDecoratedMeasurement(child) / 2 && helper.GetDecoratedEnd(child) > 0) { viewPosition = firstChild; return(child); } viewPosition = firstChild + 1; return(layoutManager.FindViewByPosition(firstChild + 1)); }
void OnItemSelected(int position) { var CardViewModel = ViewModel.GetCardViewModel(position); var intent = CardDetailActivity.CreateIntent(this, CardViewModel.Card); var selectedItemViewHolder = layoutManager.FindViewByPosition(position); var sharedView = selectedItemViewHolder.FindViewById(Resource.Id.CardImageView); var transitionName = GetString(Resource.String.cardimage); var transitionActivityOptions = ActivityOptions.MakeSceneTransitionAnimation(this, sharedView, transitionName); StartActivity(intent, transitionActivityOptions.ToBundle()); }
private View GetStartView( RecyclerView.LayoutManager layoutManager, OrientationHelper helper, out int viewPosition) { viewPosition = -1; if (!(layoutManager is LinearLayoutManager manager)) { return(base.FindSnapView(layoutManager)); } int firstChild = manager.FindFirstVisibleItemPosition(); bool isLastItem = manager.FindLastCompletelyVisibleItemPosition() == layoutManager.ItemCount - 1; if (firstChild == RecyclerView.NoPosition || isLastItem) { return(null); } View child = layoutManager.FindViewByPosition(firstChild); if (helper.GetDecoratedEnd(child) >= helper.GetDecoratedMeasurement(child) / 2 && helper.GetDecoratedEnd(child) > 0) { viewPosition = firstChild; return(child); } if (manager.FindLastCompletelyVisibleItemPosition() == layoutManager.ItemCount - 1) { return(null); } viewPosition = firstChild + 1; return(layoutManager.FindViewByPosition(firstChild + 1)); }
public void OnItemLongClick(int position) { if (position == 0 && workingPath.Length != 1) { return; } var item = items[workingPath.Length == 1 ? position : (position - 1)]; var view = layoutManager.FindViewByPosition(position); var popup = new PopupMenu(Context, view); popup.MenuInflater.Inflate(Resource.Menu.file_actions, popup.Menu); if (item.IsDirectory) { popup.Menu.FindItem(Resource.Id.action_download).SetVisible(false); } if (item.IsReadOnly) { popup.Menu.FindItem(Resource.Id.action_rename).SetVisible(false); popup.Menu.FindItem(Resource.Id.action_move).SetVisible(false); popup.Menu.FindItem(Resource.Id.action_delete).SetVisible(false); } if (item.Attributes.HasFlag(FileAttributes.Device)) { popup.Menu.FindItem(Resource.Id.action_rename).SetVisible(false); popup.Menu.FindItem(Resource.Id.action_move).SetVisible(false); } popup.MenuItemClick += (o, e) => { switch (e.Item.ItemId) { case Resource.Id.action_download: { opSource = item; this.StartActivityForResult(typeof(ChooseFolderActivity), CallbackDownload); return; } case Resource.Id.action_move: { opSource = item; var intent = new Intent(Context, typeof(ChooseDestinationActivity)); var deviceRoot = workingPath.Substring(1); var nextSeparator = deviceRoot.IndexOf(Path.AltDirectorySeparatorChar); if (nextSeparator == -1) { deviceRoot = "/" + deviceRoot; } else { deviceRoot = "/" + deviceRoot.Substring(0, nextSeparator); } intent.PutExtra(ChooseDestinationActivity.ExtraRootPath, deviceRoot); StartActivityForResult(intent, CallbackMove); return; } case Resource.Id.action_rename: { Activity.ShowEditorAlert(GetString(Resource.String.new_file_name), item.Name, item.Name, GetString(Resource.String.action_save), text => { if (string.IsNullOrWhiteSpace(text)) { Activity.ShowAlert(GetString(Resource.String.bad_file_name), null); return; } if (text == item.Name) { return; } #pragma warning disable 0618 var progress = new Android.App.ProgressDialog(Context); progress.SetCancelable(false); progress.SetMessage(GetString(Resource.String.renaming)); progress.Show(); #pragma warning restore 0618 Task.Run(async() => { try { var path = Path.Combine(workingPath, item.Name); await fileSystem.RenameAsync(path, text).ConfigureAwait(false); Activity.RunOnUiThread(() => { progress.Dismiss(); RefreshDirectory(this, EventArgs.Empty); }); } catch (HttpRequestException exception) { Activity.RunOnUiThread(() => { progress.Dismiss(); Activity.ShowAlert(GetString(Resource.String.error_remote), exception.Message); }); } catch (Exception exception) { Activity.RunOnUiThread(() => { progress.Dismiss(); Activity.ShowAlert(GetString(Resource.String.error_rename_file), exception.GetType().Name); }); } }); }, GetString(Resource.String.action_cancel), null); return; } case Resource.Id.action_delete: { Activity.ShowAlert(GetString(Resource.String.delete_permanently), GetString(Resource.String.delete_all_contents, item.Name), GetString(Resource.String.action_cancel), null, GetString(Resource.String.action_delete), () => { #pragma warning disable 0618 var progress = new Android.App.ProgressDialog(Context); progress.SetCancelable(false); progress.SetMessage(GetString(Resource.String.deleting)); progress.Show(); #pragma warning restore 0618 Task.Run(async() => { try { var path = Path.Combine(workingPath, item.Name); if (item.IsDirectory) { path += Path.AltDirectorySeparatorChar; } await fileSystem.DeleteAsync(path).ConfigureAwait(false); Activity.RunOnUiThread(() => { progress.Dismiss(); RefreshDirectory(this, EventArgs.Empty); }); } catch (HttpRequestException exception) { Activity.RunOnUiThread(() => { progress.Dismiss(); Activity.ShowAlert(GetString(Resource.String.error_remote), exception.Message); }); } catch (Exception exception) { Activity.RunOnUiThread(() => { progress.Dismiss(); Activity.ShowAlert(GetString(Resource.String.error_delete_file), exception.GetType().Name); }); } }); }); return; } } }; if (popup.Menu.Size() != 0) { var helper = new MenuPopupHelper(Context, (MenuBuilder)popup.Menu, view); helper.SetForceShowIcon(true); helper.Show(); } }