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();
            }
        }
Exemple #2
0
        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);
            }
        }
        private void ShowCheckCircles()
        {
            var adapter = recView.GetAdapter() as ImageShortCutAdapter;

            if (adapter != null)
            {
                ImageButton takePctrBtn = first.FindViewById <ImageButton>(Resource.Id.takePictureBtn);
                ImageButton doneBtn     = first.FindViewById <ImageButton>(Resource.Id.doneBtn);

                doneBtn.Click += (sender, e) =>
                {
                    List <string> ImagesForPreview = new List <string>();

                    var imgs = getPhotosFromGallery();

                    foreach (var pos in adapter.CheckedPositions)
                    {
                        ImagesForPreview.Add(imgs.ElementAt(pos));
                    }

                    SelectedImgsFromGallery(ImagesForPreview);
                };

                if (takePctrBtn.Visibility == ViewStates.Visible)
                {
                    takePctrBtn.Visibility = ViewStates.Invisible;
                    doneBtn.Visibility     = ViewStates.Visible;
                }
                else
                {
                    doneBtn.Visibility     = ViewStates.Invisible;
                    takePctrBtn.Visibility = ViewStates.Visible;
                }
                adapter.ClickOnChoseFew();
            }
        }
Exemple #4
0
        public override async void OnActivityResult(int requestCode, int resultCode, Intent data)
        {
            if (null == data)
            {
                SelectButtonIsVisible = true;

                SavedState.PutBoolean(FILE_CHOOSER_VISIBILTY, SelectButtonIsVisible);
            }

            if (requestCode == FileRequestCode && resultCode == (int)Result.Ok)
            {
                //Before performing a new task, clean up the temp.
                PathHelper.DeleteAllTempFiles();

                //Save the filename to memory.
                PathHelper.OriginalPDFName = data.Data.GetFileNameFromURIWithoutExtension();
                await Task.Run(() =>
                {
                    try

                    {
                        context.RunOnUiThread(() =>
                        {
                            //Turn off the fileChooser
                            fileChooserCard.Visibility = ViewStates.Gone;

                            SelectButtonIsVisible = false;

                            SavedState.PutBoolean(FILE_CHOOSER_VISIBILTY, SelectButtonIsVisible);
                        });

                        //Try extract images from the supplied pdf.
                        //Create the temp folder.

                        string directory = PathHelper.GetOrCreateExtractRTempDirectory();

                        //Build the save Path.
                        string savePath = string.Empty;

                        if (!string.IsNullOrEmpty(directory))
                        {
                            savePath = System.IO.Path.Combine(directory, PathHelper.OriginalPDFName);
                        }

                        var stream = context.ContentResolver.OpenInputStream(data.Data);

                        ImageExtractor imageExtractor = new ImageExtractor(stream);

                        imageExtractor.ImageSaved += (s, e) =>
                        {
                            context.RunOnUiThread(() =>
                            {
                                //Try updating the progressbar.
                                processingProgressBar.SetProgress(e.Progress, true);
                            });
                        };

                        if (imageExtractor != null)
                        {
                            context.RunOnUiThread(() =>
                            {
                                //Show the processing group.
                                if (processingGroup.Visibility == ViewStates.Gone)
                                {
                                    processingGroup.Visibility = ViewStates.Visible;
                                }

                                //Set the text in the processing textview.
                                processingTextView.Text = $"ExtractR is scanning your document...";
                            });

                            //Extract data from the pdf.
                            var elements = imageExtractor.ExtractElementsData();

                            context.RunOnUiThread(() =>
                            {
                                if (null == elements || elements.Result.Count == 0)
                                {
                                    //No need to waste time. Break out of the function.
                                    ReportNothingFound();
                                    return;
                                }
                                //Update the text in the processing textview again to reflect the total elements found.
                                processingTextView.Text = $"Processing {elements.Result.Count} possible images...";

                                processingProgressBar.SetProgress(0, true);
                                processingProgressBar.Max = elements.Result.Count;
                            });

                            if (elements != null)
                            {
                                var savedImagePaths = imageExtractor.ProcessData(elements.Result, savePath).Result;

                                //Remove all current items.
                                ImageFileNameModels.Clear();

                                foreach (var path in savedImagePaths)
                                {
                                    System.Diagnostics.Debug.WriteLine(path);

                                    ImageFileNameModels.Add(new ImageFileNameModel
                                    {
                                        FileName = path,
                                        FullPath = System.IO.Path.Combine(PathHelper.ExtractRDirectory, path)
                                    });;
                                }
                            }

                            context.RunOnUiThread(() =>
                            {
                                processingGroup.Visibility = ViewStates.Gone;

                                var count = ImageFileNameModels.Count;
                                mainActivity.toolbar.Subtitle = count > 0 ? $"Found {count} possible images." : "No image found.";
                                ItemCountHelper.UpdateExportItemsCount(mainActivity, ImageFileNameModels);
                                _recyclerView.GetAdapter().NotifyDataSetChanged();
                            });
                        }
                    }
                    catch (System.Exception ex)
                    {
                        System.Diagnostics.Debug.WriteLine(ex.Message);
                    }
                });
            }

            base.OnActivityResult(requestCode, resultCode, data);
        }