How to create BottomSheetDialogFragment using Navigation Architecture Component?

In the navigation component version 2.1.0-alpha04, Navigation Graph can contain dialog as one of the destinations. <?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/main_navigation” app:startDestination=”@id/startFragment”> <fragment android:id=”@+id/loginFragment” android:name=”com.awesomeproject.android.authentication.login.LoginFragment” android:label=”Login” tools:layout=”@layout/login_fragment” /> <dialog android:id=”@+id/bottomSheet” android:name=”com.awesomproject.android.BottomSheetFragment” tools:layout=”@layout/bottom_sheet_dialog_fragment” /> </navigation> The BottomSheetFragment will look similar to other BottomSheet. class BottomSheetFragment : BottomSheetDialogFragment() { override fun onCreateView(inflater: LayoutInflater, container: … Read more

How to implement a ViewPager with BottomNavigationView using new Navigation Architecture Component?

UPDATE (15/06/21): Starting from Navigation component version 2.4.0-alpha01 multiple back stacks are supported out of the box. According to documentation if you are using NavigationView or BottomNavigationView together with Navigation component, then multiple back stacks should work without any code changes to previous implementation. As part of this change, the NavigationUI methods of onNavDestinationSelected(), BottomNavigationView.setupWithNavController() … Read more

How to use shared element transitions in Navigation Controller

FirstFragment val extras = FragmentNavigatorExtras( imageView to “secondTransitionName”) view.findNavController().navigate(R.id.confirmationAction, null, // Bundle of args null, // NavOptions extras) first_fragment.xml <ImageView android:id=”@+id/imageView” android:transitionName=”firstTransitionName” … /> SecondFragment override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View { sharedElementEnterTransition = ChangeBounds().apply { duration = 750 } sharedElementReturnTransition= ChangeBounds().apply { duration = 750 } return inflater.inflate(R.layout.second_fragment, container, false) } … Read more

MediatorLiveData or switchMap transformation with multiple parameters

Source : https://plus.google.com/+MichielPijnackerHordijk/posts/QGXF9gRomVi To have multiple triggers for switchMap(), you need to use a custom MediatorLiveData to observe the combination of the LiveData objects – class CustomLiveData extends MediatorLiveData<Pair<String, Integer>> { public CustomLiveData(LiveData<String> code, LiveData<Integer> nbDays) { addSource(code, new Observer<String>() { public void onChanged(@Nullable String first) { setValue(Pair.create(first, nbDays.getValue())); } }); addSource(nbDays, new Observer<Integer>() { … Read more

LiveData prevent receive the last value when start observing

I`m using this EventWraper class from Google Samples inside MutableLiveData /** * Used as a wrapper for data that is exposed via a LiveData that represents an event. */ public class Event<T> { private T mContent; private boolean hasBeenHandled = false; public Event( T content) { if (content == null) { throw new IllegalArgumentException(“null values … Read more

Asynchronous Worker in Android WorkManager

I used a countdownlatch and waited for this to reach 0, which will only happen once the asynchronous callback has updated it. See this code: public WorkerResult doWork() { final WorkerResult[] result = {WorkerResult.RETRY}; CountDownLatch countDownLatch = new CountDownLatch(1); FirebaseFirestore db = FirebaseFirestore.getInstance(); db.collection(“collection”).whereEqualTo(“this”,”that”).get().addOnCompleteListener(task -> { if(task.isSuccessful()) { task.getResult().getDocuments().get(0).getReference().update(“field”, “value”) .addOnCompleteListener(task2 -> { if (task2.isSuccessful()) … Read more