0

I recently updated a project that I completed a couple of years ago. The application has a fragment and a sliding pane with a list of items, pressing on which triggers a certain action and closes the pane. The pane is also closed once the fragment is open.

public View onCreateView(@NonNull LayoutInflater inflater,
                             ViewGroup container, Bundle savedInstanceState) {

        performanceViewModel = new ViewModelProvider(this).get(Model_Performance.class);
        View root = inflater.inflate(R.layout.performance_fragment_layout, container, false);

        //setHasOptionsMenu(true); //DEPRECATED

        // Create a Sliding Pane
        slidingPane = root.findViewById(R.id.performance_sliding_pane_layout);

        slidingPane.addPanelSlideListener(new SlidingPaneLayout.SimplePanelSlideListener(){
            @Override
            public void onPanelOpened(View panel) {
                //Toast.makeText(panel.getContext(), "Opened", Toast.LENGTH_SHORT).show();
                panelOpened();
            }

            @Override
            public void onPanelClosed(View panel) {
                //Toast.makeText(panel.getContext(), "Closed", Toast.LENGTH_SHORT).show();
                panelClosed();
            }

            @Override
            public void onPanelSlide(View view, float v) { }
        });


        if (slidingPane != null) {
            if (slidingPane.isOpen())
            {
                Log.i("SlidePane","is closing........");
                slidingPane.closePane();
            }
        }

        view = root;

        // +++++++++++++++++++++++++++++++
        // Left sliding panel
        // +++++++++++++++++++++++++++++++

        // Lookup the recyclerview in activity layout
        rvPerformance = root.findViewById(R.id.rvPerformanceLeft);

        adapter = new PerformanceTableAdapter(appSingleton.getListOfPirepItemsShared(), this);
        // Attach the adapter to the recyclerview to populate items
        rvPerformance.setAdapter(adapter);
        // Set layout manager to position the items
        rvPerformance.setLayoutManager(new LinearLayoutManager(root.getContext()));
        // Add horizontal dividers
        rvPerformance.addItemDecoration(new DividerItemDecoration(root.getContext(), DividerItemDecoration.HORIZONTAL));

        txtPerformance = root.findViewById(R.id.txtPerformance);

        return root;
    }

The problem is that slidingPane.closePane(); is never called. This is the message that I get in the console:

I/SlidePane: is closing........
W/System: A resource failed to call close. 

An interesting thing is that when I try to close it with a menu button, like this:

public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

        MenuHost menuHost = requireActivity();

        menuHost.addMenuProvider(new MenuProvider() {
            @Override
            public void onCreateMenu(@NonNull Menu menu, @NonNull MenuInflater menuInflater) {
                menuInflater.inflate(R.menu.top_nav_menu_performance, menu);
            }

            @Override
            public boolean onMenuItemSelected(@NonNull MenuItem menuItem) {
                if(menuItem.getItemId()==android.R.id.home) {
                    // Opening and closing the Sliding Pane
                    if (slidingPane != null) {
                        if (!slidingPane.isOpen()) { slidingPane.openPane(); }
                        else { slidingPane.closePane(); }
                    }
                }
                return true;
            }
        }, getViewLifecycleOwner(), Lifecycle.State.RESUMED);
    }

... the pane gets closed just fine. Everything used to work before.

Thanks in advance!

EDIT:

The closePane(); is only not called inside onCreateView or onViewCreated in the fragment. It is called just fine from a button click. This is driving me crazy... Just in case, this is the layout:

<?xml version="1.0" encoding="utf-8"?>
<androidx.slidingpanelayout.widget.SlidingPaneLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/background_dark_gray"
    android:id="@+id/performance_sliding_pane_layout"
    tools:context=".ui.performance.PerformanceFragment">

    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        tools:context=".ui.performance.PerformanceFragment">

        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/rvPerformanceLeft"
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:layout_marginTop="0dp"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"/>
    </androidx.constraintlayout.widget.ConstraintLayout>


    <ScrollView
        android:id="@+id/scrollviewPerformance"
        android:layout_width="match_parent"
        android:layout_height="fill_parent"
        android:fillViewport="true"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="1.0"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="1.0">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="end" >

            <TextView
                android:id="@+id/txtPerformance"
                android:textSize="16sp"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginStart="20dp"
                android:layout_marginTop="30dp"
                android:layout_marginEnd="20dp"
                android:layout_marginBottom="20dp"
                android:layout_weight="1"
                android:textColor="@color/white"
                android:text="@string/not_available" />
        </LinearLayout>
    </ScrollView>

</androidx.slidingpanelayout.widget.SlidingPaneLayout>
Igor Tupitsyn
  • 1,193
  • 3
  • 18
  • 45

1 Answers1

0

Found the culprit. In fact, the main sliding pane is the one to the right, i.e. the one with the details content. To close the left pane with a list, one needs to call slidingPane.open(), not slidingPane.closePane().

Igor Tupitsyn
  • 1,193
  • 3
  • 18
  • 45