В моем проекте у меня есть три файла навигации. Один из файлов навигации - home_activity_nav_graph.xml
, в котором есть несколько global actions
, а другой файл навигации - nav_graph.xml
, в котором также есть фрагмент с именем PresentationFragment
с несколькими actions
. Итак, что происходит после чистой сборки или создания проекта: PresentationFragmentDirections.java
файл создается в каталоге сборки со всеми глобальными действиями вместо его собственных действий.
nav_graph. xml
<?xml version="1.0" encoding="utf-8"?>
<navigation 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:id="@+id/nav_graph"
app:startDestination="@id/presentationFragment">
<fragment
android:id="@+id/presentationFragment"
android:name="com.mdacne.mdacne.view.ui.presentation.PresentationFragment"
android:label="fragment_presentation"
tools:layout="@layout/fragment_presentation">
<action
android:id="@+id/action_presentationFragment_to_GenderFragment"
app:destination="@id/genderFragment" />
<action
android:id="@+id/action_presentationFragment_to_subscriptionFragment"
app:destination="@id/subscriptionFragment"
app:popUpTo="@id/nav_graph"
app:popUpToInclusive="true" />
<action
android:id="@+id/action_presentationFragment_to_loginBottomSheetDialog"
app:destination="@id/loginBottomSheetDialog" />
<action
android:id="@+id/action_presentationFragment_to_TreatmentAriivedFragment"
app:destination="@id/hasYourTreatmentArrivedFragment"
app:popUpTo="@id/nav_graph"
app:popUpToInclusive="true" />
<action
android:id="@+id/action_presentationFragment_to_HomePageActivity"
app:destination="@id/subscriberActivity" />
<action
android:id="@+id/action_presentationFragment_to_analysisBlackheadFragment"
app:destination="@id/analysisBlackheadFragment"
app:popUpTo="@+id/nav_graph"
app:popUpToInclusive="true" />
</fragment>
</navigation>
home_activity_nav_graph. xml
<?xml version="1.0" encoding="utf-8"?>
<navigation 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:id="@+id/home_activity_nav_graph"
app:startDestination="@id/homePageFragment">
<!-- Global actions -->
<action
android:id="@+id/action_to_RewardProduct"
app:destination="@id/rewardsFragment"
app:enterAnim="@anim/slide_left" />
<action
android:id="@+id/action_to_homePageFragment"
app:destination="@id/homePageFragment"
app:enterAnim="@anim/slide_up"
app:popUpTo="@id/home_activity_nav_graph" />
<action
android:id="@+id/action_to_contactSupportFragment_popUpTo_manageMembershipCancelationReasionFragment"
app:destination="@id/contactSupportFragment"
app:popUpTo="@id/manageMembershipCancelationReasionFragment" />
<action
android:id="@+id/action_to_productDetailFragment2"
app:destination="@id/productDetailFragment">
<argument
android:name="product"
app:argType="com.mdacne.mdacne.model.db.table.MDAcneProductTable" />
</action>
</navigation>
PresentationFragmentDirections . java, созданный в каталоге сборки
public class PresentationFragmentDirections {
private PresentationFragmentDirections() {
}
@NonNull
public static NavDirections actionToRewardProduct() {
return HomeActivityNavGraphDirections.actionToRewardProduct();
}
@NonNull
public static NavDirections actionToHomePageFragment() {
return HomeActivityNavGraphDirections.actionToHomePageFragment();
}
@NonNull
public static NavDirections actionToContactSupportFragmentPopUpToManageMembershipCancelationReasionFragment() {
return HomeActivityNavGraphDirections.actionToContactSupportFragmentPopUpToManageMembershipCancelationReasionFragment();
}
@NonNull
public static HomeActivityNavGraphDirections.ActionToProductDetailFragment2 actionToProductDetailFragment2(@NonNull MDAcneProductTable product) {
return HomeActivityNavGraphDirections.actionToProductDetailFragment2(product);
}
}
Видите, PresentationFragmentDirections.java
имеет все глобальные действия как NavDirections
, не считая его собственных действий. Я использую apply plugin: "androidx.navigation.safeargs"
в build.gradle