mirror of
https://github.com/imcarlost/Friendlists.git
synced 2026-04-10 02:46:54 -04:00
implement back button navigation and toolbar labeling
This commit is contained in:
@@ -3,6 +3,7 @@ package com.hako.friendlists.view
|
||||
import android.os.Bundle
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.navigation.findNavController
|
||||
import androidx.navigation.ui.NavigationUI.setupActionBarWithNavController
|
||||
import com.hako.base.extensions.observeNonNull
|
||||
import com.hako.base.navigation.NavigationRouter
|
||||
import com.hako.friendlists.BuildConfig
|
||||
@@ -36,10 +37,17 @@ class MainActivity : AppCompatActivity() {
|
||||
// Pair.second is a Bundle
|
||||
navController.navigate(pair.first, pair.second)
|
||||
}
|
||||
|
||||
setupActionBarWithNavController(this, navController)
|
||||
}
|
||||
|
||||
private fun setupPicasso() {
|
||||
// Show cache indicator on images just for debug builds
|
||||
picasso.setIndicatorsEnabled(BuildConfig.DEBUG)
|
||||
}
|
||||
|
||||
override fun onSupportNavigateUp(): Boolean {
|
||||
navController.navigateUp()
|
||||
return super.onSupportNavigateUp()
|
||||
}
|
||||
}
|
||||
@@ -12,6 +12,9 @@ import com.hako.friendlists.R
|
||||
import com.hako.photolist.feature.PHOTOLIST_FRAGMENT_BUNDLE_ALBUM_ID
|
||||
import com.hako.userlist.navigation.UserlistNavigation
|
||||
|
||||
// This sets the fragment title, it's referenced in every navigation
|
||||
const val FRAGMENT_TITLE = "actionTitle"
|
||||
|
||||
class NavigationViewmodel : ViewModel() {
|
||||
|
||||
val navigate = MutableLiveData<Pair<@IdRes Int, Bundle>>()
|
||||
@@ -29,6 +32,7 @@ class NavigationViewmodel : ViewModel() {
|
||||
is UserlistNavigation.ClickedOnUser -> navigate.postValue(
|
||||
buildNavigation(R.id.action_userlistFragment_to_albumlistFragment, Bundle().apply {
|
||||
putInt(ALBUMLIST_FRAGMENT_BUNDLE_USER_ID, event.userId)
|
||||
putString(FRAGMENT_TITLE, event.userName)
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,8 +1,18 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/main_fragment_container"
|
||||
android:name="androidx.navigation.fragment.NavHostFragment"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
app:defaultNavHost="true"/>
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<fragment
|
||||
android:id="@+id/main_fragment_container"
|
||||
android:name="androidx.navigation.fragment.NavHostFragment"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
app:defaultNavHost="true"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
Reference in New Issue
Block a user