Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b5999ef4 authored by Vladislav Kaznacheev's avatar Vladislav Kaznacheev
Browse files

Fix drag and drop in Files app.

It got broken after the migration to Recycler view.
This patch might be not the perfect fix, but it returns
drag and drop into a working condition.

Testing requires recompile with DEBUG_ENABLE_DND=true

Bug: 22725110
Change-Id: I82cf01af68c6284878af8e46e290d117a0e505c1
parent 860f9846
Loading
Loading
Loading
Loading
+16 −2
Original line number Original line Diff line number Diff line
@@ -86,6 +86,7 @@ import android.view.MotionEvent;
import android.view.View;
import android.view.View;
import android.view.View.OnLayoutChangeListener;
import android.view.View.OnLayoutChangeListener;
import android.view.ViewGroup;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.widget.ImageView;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.Toast;
@@ -1459,7 +1460,7 @@ public class DirectoryFragment extends Fragment {
                    return true;
                    return true;


                case DragEvent.ACTION_DROP:
                case DragEvent.ACTION_DROP:
                    int dstPosition = mRecView.getChildAdapterPosition(v);
                    int dstPosition = mRecView.getChildAdapterPosition(getContainingItemView(v));
                    DocumentInfo dstDir = null;
                    DocumentInfo dstDir = null;
                    if (dstPosition != android.widget.AdapterView.INVALID_POSITION) {
                    if (dstPosition != android.widget.AdapterView.INVALID_POSITION) {
                        Cursor dstCursor = mModel.getItem(dstPosition);
                        Cursor dstCursor = mModel.getItem(dstPosition);
@@ -1474,6 +1475,19 @@ public class DirectoryFragment extends Fragment {
        }
        }
    };
    };


    private View getContainingItemView(View view) {
        while (true) {
            if (view.getLayoutParams() instanceof RecyclerView.LayoutParams) {
                return view;
            }
            ViewParent parent = view.getParent();
            if (parent == null || !(parent instanceof View)) {
                return null;
            }
            view = (View) parent;
        }
    }

    private View.OnLongClickListener mLongClickListener = new View.OnLongClickListener() {
    private View.OnLongClickListener mLongClickListener = new View.OnLongClickListener() {
        @Override
        @Override
        public boolean onLongClick(View v) {
        public boolean onLongClick(View v) {
@@ -1492,7 +1506,7 @@ public class DirectoryFragment extends Fragment {
    };
    };


    private List<DocumentInfo> getDraggableDocuments(View currentItemView) {
    private List<DocumentInfo> getDraggableDocuments(View currentItemView) {
        int position = mRecView.getChildAdapterPosition(currentItemView);
        int position = mRecView.getChildAdapterPosition(getContainingItemView(currentItemView));
        if (position == android.widget.AdapterView.INVALID_POSITION) {
        if (position == android.widget.AdapterView.INVALID_POSITION) {
            return Collections.EMPTY_LIST;
            return Collections.EMPTY_LIST;
        }
        }