-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/performance-check' into develop
- Loading branch information
Showing
11 changed files
with
194 additions
and
21 deletions.
There are no files selected for viewing
93 changes: 93 additions & 0 deletions
93
app/src/main/java/com/smarttoolfactory/propertyfindar/MainFragmentBottomNav.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package com.smarttoolfactory.propertyfindar | ||
|
||
import android.os.Bundle | ||
import android.view.View | ||
import androidx.core.os.bundleOf | ||
import androidx.fragment.app.activityViewModels | ||
import androidx.navigation.dynamicfeatures.fragment.DynamicNavHostFragment | ||
import androidx.navigation.fragment.findNavController | ||
import com.google.android.material.bottomnavigation.BottomNavigationView | ||
import com.smarttoolfactory.core.ui.fragment.DynamicNavigationFragment | ||
import com.smarttoolfactory.core.ui.fragment.navhost.BaseDynamicNavHostFragment | ||
import com.smarttoolfactory.core.util.observe | ||
import com.smarttoolfactory.core.util.setupWithNavController | ||
import com.smarttoolfactory.core.viewmodel.PropertyDetailNavigationVM | ||
import com.smarttoolfactory.propertyfindar.databinding.FragmentMainBottomNavBinding | ||
|
||
/** | ||
* Alternative of MainFragment with only [BottomNavigationView] | ||
* that has [DynamicNavHostFragment]s as root fragment of each | ||
* tab with [BaseDynamicNavHostFragment]s that extend [DynamicNavHostFragment]. | ||
* | ||
* | ||
*/ | ||
class MainFragmentBottomNav : DynamicNavigationFragment<FragmentMainBottomNavBinding>() { | ||
|
||
/** | ||
* ViewModel for navigating to property detail screen from Main Fragment | ||
*/ | ||
private val propertyDetailNavigationVM by activityViewModels<PropertyDetailNavigationVM>() | ||
|
||
override fun getLayoutRes(): Int = R.layout.fragment_main_bottom_nav | ||
|
||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
super.onViewCreated(view, savedInstanceState) | ||
|
||
if (savedInstanceState == null) { | ||
setupBottomNavigationBar() | ||
} // Else, need to wait for onRestoreInstanceState | ||
|
||
subscribePropertyDetailNavigation() | ||
} | ||
|
||
override fun onViewStateRestored(savedInstanceState: Bundle?) { | ||
super.onViewStateRestored(savedInstanceState) | ||
// Now that BottomNavigationBar has restored its instance state | ||
// and its selectedItemId, we can proceed with setting up the | ||
// BottomNavigationBar with Navigation | ||
setupBottomNavigationBar() | ||
} | ||
|
||
/** | ||
* Called on first creation and when restoring state. | ||
*/ | ||
private fun setupBottomNavigationBar() { | ||
|
||
val bottomNavigationView = dataBinding!!.bottomNav | ||
|
||
val navGraphIds = listOf( | ||
R.navigation.nav_graph_dfm_home_start, | ||
R.navigation.nav_graph_dfm_favorites_start, | ||
R.navigation.nav_graph_dfm_notification_start, | ||
R.navigation.nav_graph_dfm_account_start | ||
) | ||
|
||
// Setup the bottom navigation view with a list of navigation graphs | ||
val controller = bottomNavigationView.setupWithNavController( | ||
navGraphIds = navGraphIds, | ||
fragmentManager = childFragmentManager, | ||
containerId = R.id.nav_host_container, | ||
intent = requireActivity().intent | ||
) | ||
} | ||
|
||
/** | ||
* Navigates to Property Detail fragment from this fragment that replacing main fragment | ||
* that contains [BottomNavigationView] | ||
*/ | ||
private fun subscribePropertyDetailNavigation() { | ||
|
||
viewLifecycleOwner.observe(propertyDetailNavigationVM.goToPropertyDetailFromMain) { | ||
|
||
it.getContentIfNotHandled()?.let { propertyItem -> | ||
val bundle = bundleOf("property" to propertyItem) | ||
|
||
findNavController() | ||
.navigate( | ||
R.id.action_mainFragment_to_propertyDetailFragment, | ||
bundle | ||
) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<layout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto"> | ||
|
||
<androidx.constraintlayout.widget.ConstraintLayout | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent"> | ||
|
||
<androidx.fragment.app.FragmentContainerView | ||
android:id="@+id/nav_host_container" | ||
android:layout_width="0dp" | ||
android:layout_height="0dp" | ||
app:layout_constraintBottom_toTopOf="@+id/bottomNav" | ||
app:layout_constraintLeft_toLeftOf="parent" | ||
app:layout_constraintRight_toRightOf="parent" | ||
app:layout_constraintTop_toTopOf="parent" /> | ||
|
||
<com.google.android.material.bottomnavigation.BottomNavigationView | ||
android:id="@+id/bottomNav" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
app:layout_constraintBottom_toBottomOf="parent" | ||
app:menu="@menu/menu_bottom" /> | ||
|
||
</androidx.constraintlayout.widget.ConstraintLayout> | ||
|
||
</layout> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?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_main_bottom_bottom_nav" | ||
app:startDestination="@id/mainFragment"> | ||
|
||
|
||
<fragment | ||
android:id="@+id/mainFragment" | ||
android:name="com.smarttoolfactory.propertyfindar.MainFragmentBottomNav" | ||
android:label="MainFragment" | ||
tools:layout="@layout/fragment_main"> | ||
|
||
<action | ||
android:id="@+id/action_mainFragment_to_propertyDetailFragment" | ||
app:destination="@id/nav_graph_property_detail" | ||
app:enterAnim="@anim/slide_in_right" | ||
app:exitAnim="@anim/slide_out_left" | ||
app:popEnterAnim="@anim/slide_in_left" | ||
app:popExitAnim="@anim/slide_out_right" /> | ||
|
||
</fragment> | ||
|
||
|
||
<!-- Property Detail dynamic feature module --> | ||
<include-dynamic | ||
android:id="@+id/nav_graph_property_detail" | ||
android:name="com.smarttoolfactory.property_detail" | ||
app:graphResName="nav_graph_property_detail" | ||
app:moduleName="property_detail"> | ||
|
||
<argument | ||
android:name="property" | ||
app:argType="com.smarttoolfactory.domain.model.PropertyItem" /> | ||
|
||
</include-dynamic> | ||
</navigation> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters