Update app navigation

This commit is contained in:
Tommaso Berlose 2021-01-06 21:31:01 +01:00
parent 329eee6339
commit fb853975e0
4 changed files with 25 additions and 17 deletions

View File

@ -26,6 +26,7 @@ import androidx.lifecycle.lifecycleScope
import androidx.navigation.NavController
import androidx.navigation.Navigation
import androidx.navigation.fragment.FragmentNavigatorExtras
import androidx.navigation.fragment.NavHostFragment
import com.google.android.material.badge.BadgeDrawable
import com.google.android.material.tabs.TabLayoutMediator
import com.google.android.material.transition.MaterialSharedAxis
@ -107,10 +108,16 @@ class MainFragment : Fragment(), SharedPreferences.OnSharedPreferenceChangeList
.show()
}
// Navigation.findNavController(settings_fragment).addOnDestinationChangedListener { controller, destination, _ ->
// action_back?.isVisible = destination.id != R.id.tabSelectorFragment
// Log.d("ciao", "${controller.currentDestination?.displayName} ${destination.id} - ${R.id.tabSelectorFragment}")
// }
val navHost = childFragmentManager.findFragmentById(R.id.settings_fragment) as? NavHostFragment?
navHost?.navController?.addOnDestinationChangedListener { controller, destination, _ ->
val show = destination.id != R.id.tabSelectorFragment
action_back?.animate()?.alpha(if (show) 1f else 0f)?.setDuration(200)?.translationX((if (show) 0f else 4f).convertDpToPixel(requireContext()))?.start()
action_back?.setOnClickListener {
controller.navigateUp()
}
action_settings?.animate()?.alpha(if (!show) 1f else 0f)?.setDuration(200)?.translationX((if (!show) 0f else -4f).convertDpToPixel(requireContext()))?.start()
fragment_title?.text = if (show) destination.label.toString() else getString(R.string.app_name)
}
}
private var uiJob: Job? = null

View File

@ -23,13 +23,12 @@
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="56dp"
android:gravity="center_vertical"
android:paddingLeft="8dp"
android:paddingRight="8dp">
android:gravity="center_vertical">
<ImageView
android:layout_width="48dp"
android:layout_height="48dp"
android:padding="10dp"
android:padding="12dp"
android:layout_marginTop="2dp"
android:src="@drawable/round_arrow_back_24"
android:clickable="true"
android:focusable="true"
@ -37,7 +36,9 @@
app:tint="@color/colorPrimaryText"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:visibility="gone"
android:alpha="0"
android:layout_marginLeft="8dp"
android:translationX="4dp"
android:id="@+id/action_back"/>
<LinearLayout
android:layout_width="wrap_content"

View File

@ -158,7 +158,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/AnotherWidget.Settings.Title"
android:text="Calendar"/>
android:text="@string/settings_calendar_title"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
@ -223,7 +223,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/AnotherWidget.Settings.Title"
android:text="Weather"/>
android:text="@string/settings_weather_title"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
@ -287,7 +287,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/AnotherWidget.Settings.Title"
android:text="Clock"/>
android:text="@string/settings_clock_title"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
@ -351,7 +351,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/AnotherWidget.Settings.Title"
android:text="Glance"/>
android:text="@string/settings_at_a_glance_title"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"

View File

@ -6,15 +6,15 @@
<fragment
android:id="@+id/calendarTabFragment"
android:name="com.tommasoberlose.anotherwidget.ui.fragments.CalendarTabFragment"
android:label="CalendarTabFragment" />
android:label="@string/settings_calendar_title" />
<fragment
android:id="@+id/clockTabFragment"
android:name="com.tommasoberlose.anotherwidget.ui.fragments.ClockTabFragment"
android:label="ClockTabFragment" />
android:label="@string/settings_clock_title" />
<fragment
android:id="@+id/glanceTabFragment"
android:name="com.tommasoberlose.anotherwidget.ui.fragments.GlanceTabFragment"
android:label="GlanceTabFragment" />
android:label="@string/settings_at_a_glance_title" />
<fragment
android:id="@+id/generalTabFragment"
android:name="com.tommasoberlose.anotherwidget.ui.fragments.GeneralTabFragment"
@ -22,7 +22,7 @@
<fragment
android:id="@+id/weatherTabFragment"
android:name="com.tommasoberlose.anotherwidget.ui.fragments.WeatherTabFragment"
android:label="WeatherTabFragment" />
android:label="@string/settings_weather_title" />
<fragment
android:id="@+id/tabSelectorFragment"
android:name="com.tommasoberlose.anotherwidget.ui.fragments.TabSelectorFragment"