Skip to content

Commit

Permalink
Merge branch 'feature/performance-check' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
SmartToolFactory committed Sep 9, 2020
2 parents 4c133de + f207d37 commit 1d9e412
Show file tree
Hide file tree
Showing 11 changed files with 194 additions and 21 deletions.
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
)
}
}
}
}
2 changes: 1 addition & 1 deletion app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
app:layout_constraintBottom_toBottomOf="parent"

app:defaultNavHost="true"
app:navGraph="@navigation/nav_graph_main"/>
app:navGraph="@navigation/nav_graph_main_bottom_nav"/>

</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
28 changes: 28 additions & 0 deletions app/src/main/res/layout/fragment_main_bottom_nav.xml
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>

38 changes: 38 additions & 0 deletions app/src/main/res/navigation/nav_graph_main_bottom_nav.xml
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>
10 changes: 5 additions & 5 deletions config/detekt/detekt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,11 @@ complexity:
TooManyFunctions:
active: true
excludes: ['**/test/**', '**/test-utils/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**']
thresholdInFiles: 11
thresholdInClasses: 11
thresholdInInterfaces: 11
thresholdInObjects: 11
thresholdInEnums: 11
thresholdInFiles: 12
thresholdInClasses: 12
thresholdInInterfaces: 12
thresholdInObjects: 12
thresholdInEnums: 12
ignoreDeprecated: false
ignorePrivate: false
ignoreOverridden: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ class PropertyListFlowFragment : DynamicNavigationFragment<FragmentPropertyListB
}

override fun bindViews() {
dataBinding.viewModel = viewModel
dataBinding!!.viewModel = viewModel

dataBinding.recyclerView.apply {
dataBinding!!.recyclerView.apply {

// Set Layout manager
this.layoutManager =
Expand All @@ -58,7 +58,7 @@ class PropertyListFlowFragment : DynamicNavigationFragment<FragmentPropertyListB
this.adapter = itemListAdapter
}

val swipeRefreshLayout = dataBinding.swipeRefreshLayout
val swipeRefreshLayout = dataBinding!!.swipeRefreshLayout

swipeRefreshLayout.setOnRefreshListener {
swipeRefreshLayout.isRefreshing = false
Expand Down Expand Up @@ -150,4 +150,9 @@ class PropertyListFlowFragment : DynamicNavigationFragment<FragmentPropertyListB
super.onPause()
toolbarVM.queryBySort.removeObservers(viewLifecycleOwner)
}

override fun onDestroyView() {
dataBinding!!.swipeRefreshLayout.setOnRefreshListener(null)
super.onDestroyView()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ class PagedPropertyListFragment :
}

override fun bindViews() {
dataBinding.viewModel = viewModel
dataBinding!!.viewModel = viewModel

dataBinding.recyclerView.apply {
dataBinding!!.recyclerView.apply {

// Set Layout manager
val linearLayoutManager =
Expand All @@ -75,7 +75,7 @@ class PagedPropertyListFragment :
this.addOnScrollListener(endlessScrollListener)
}

val swipeRefreshLayout = dataBinding.swipeRefreshLayout
val swipeRefreshLayout = dataBinding!!.swipeRefreshLayout

swipeRefreshLayout.setOnRefreshListener {
swipeRefreshLayout.isRefreshing = false
Expand Down Expand Up @@ -150,4 +150,9 @@ class PagedPropertyListFragment :
override fun onScrollToBottom() {
viewModel.getPropertyList()
}

override fun onDestroyView() {
dataBinding!!.swipeRefreshLayout.setOnRefreshListener(null)
super.onDestroyView()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ class PropertyListRxjava3Fragment : DynamicNavigationFragment<FragmentPropertyLi
}

override fun bindViews() {
dataBinding.viewModel = viewModel
dataBinding!!.viewModel = viewModel

dataBinding.recyclerView.apply {
dataBinding!!.recyclerView.apply {

// Set Layout manager
this.layoutManager =
Expand All @@ -57,7 +57,7 @@ class PropertyListRxjava3Fragment : DynamicNavigationFragment<FragmentPropertyLi
this.adapter = itemListAdapter
}

val swipeRefreshLayout = dataBinding.swipeRefreshLayout
val swipeRefreshLayout = dataBinding!!.swipeRefreshLayout

swipeRefreshLayout.setOnRefreshListener {
swipeRefreshLayout.isRefreshing = false
Expand Down Expand Up @@ -127,4 +127,9 @@ class PropertyListRxjava3Fragment : DynamicNavigationFragment<FragmentPropertyLi
super.onPause()
toolbarVM.queryBySort.removeObservers(viewLifecycleOwner)
}

override fun onDestroyView() {
dataBinding!!.swipeRefreshLayout.setOnRefreshListener(null)
super.onDestroyView()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class PropertyDetailFragment : DynamicNavigationFragment<FragmentPropertyDetailB
override fun bindViews() {
// Get Post from navigation component arguments
val property = arguments?.get("property") as PropertyItem
dataBinding.item = property
dataBinding!!.item = property
}

override fun onCreate(savedInstanceState: Bundle?) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ abstract class BaseDataBindingFragment<ViewBinding : ViewDataBinding> : Fragment

private var _dataBinding: ViewBinding? = null

lateinit var dataBinding: ViewBinding
var dataBinding: ViewBinding? = null

/**
* This method gets the layout id from the derived fragment to bind to that layout via data-binding
Expand Down Expand Up @@ -67,9 +67,9 @@ abstract class BaseDataBindingFragment<ViewBinding : ViewDataBinding> : Fragment
* again, and when onDestroyView is called removes this binding to liveData
* since it's bound to View instead of Fragment(this).
*/
dataBinding.lifecycleOwner = viewLifecycleOwner
dataBinding!!.lifecycleOwner = viewLifecycleOwner

val rootView = dataBinding.root
val rootView = dataBinding!!.root

// Get width and height of the fragment
rootView.post {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import android.os.Bundle
import androidx.annotation.NavigationRes
import androidx.fragment.app.activityViewModels
import androidx.navigation.dynamicfeatures.fragment.DynamicNavHostFragment
import androidx.navigation.fragment.NavHostFragment
import com.smarttoolfactory.core.error.NavigationException
import com.smarttoolfactory.core.util.Event
import com.smarttoolfactory.core.viewmodel.NavControllerViewModel
Expand All @@ -14,7 +13,7 @@ import com.smarttoolfactory.core.viewmodel.NavControllerViewModel
* uses [BaseDynamicNavHostFragment.createDynamicNavHostFragment] function with navigation graph
* parameter
*/
class BaseDynamicNavHostFragment : NavHostFragment() {
class BaseDynamicNavHostFragment : DynamicNavHostFragment() {

private val navControllerViewModel by activityViewModels<NavControllerViewModel>()

Expand Down

0 comments on commit 1d9e412

Please sign in to comment.