diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ControlCenterv2.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ControlCenterv2.java index dfb9a910a..497593f6e 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ControlCenterv2.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ControlCenterv2.java @@ -57,6 +57,7 @@ import androidx.core.app.ActivityCompat; import androidx.core.app.NotificationManagerCompat; import androidx.core.content.ContextCompat; import androidx.core.view.GravityCompat; +import androidx.core.view.MenuProvider; import androidx.drawerlayout.widget.DrawerLayout; import androidx.fragment.app.DialogFragment; import androidx.fragment.app.Fragment; @@ -240,9 +241,21 @@ public class ControlCenterv2 extends AppCompatActivity // Sync ViewPager changes with BottomNavigationView viewPager.registerOnPageChangeCallback(new ViewPager2.OnPageChangeCallback() { + private MenuProvider existingMenuProvider = null; + @Override public void onPageSelected(int position) { navigationView.getMenu().getItem(position).setChecked(true); + + // Ensure the menu provider is set to the current fragment + if (existingMenuProvider != null) { + ControlCenterv2.this.removeMenuProvider(existingMenuProvider); + } + final Fragment fragment = getSupportFragmentManager().findFragmentByTag("f" + position); + if (fragment instanceof MenuProvider) { + existingMenuProvider = (MenuProvider) fragment; + ControlCenterv2.this.addMenuProvider(existingMenuProvider); + } } }); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/DashboardFragment.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/DashboardFragment.java index 6e520a320..6840251f4 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/DashboardFragment.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/DashboardFragment.java @@ -130,7 +130,6 @@ public class DashboardFragment extends Fragment implements MenuProvider { public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { super.onCreateView(inflater, container, savedInstanceState); View dashboardView = inflater.inflate(R.layout.fragment_dashboard, container, false); - requireActivity().addMenuProvider(this); textViewDate = dashboardView.findViewById(R.id.dashboard_date); gridLayout = dashboardView.findViewById(R.id.dashboard_gridlayout);