mirror of
https://github.com/imcarlost/Friendlists.git
synced 2026-04-09 18:38:36 -04:00
implement back button navigation and toolbar labeling
This commit is contained in:
@@ -9,6 +9,10 @@
|
||||
android:id="@+id/albumlistFragment"
|
||||
android:name="com.hako.albumlist.feature.AlbumlistFragment"
|
||||
tools:layout="@layout/fragment_albumlist"
|
||||
android:label="AlbumlistFragment" />
|
||||
android:label="{actionTitle}">
|
||||
<argument
|
||||
android:name="actionTitle"
|
||||
app:argType="string" />
|
||||
</fragment>
|
||||
|
||||
</navigation>
|
||||
@@ -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>
|
||||
|
||||
@@ -9,6 +9,6 @@
|
||||
android:id="@+id/photolistFragment"
|
||||
android:name="com.hako.photolist.feature.PhotolistFragment"
|
||||
tools:layout="@layout/fragment_photolist"
|
||||
android:label="PhotolistFragment" />
|
||||
android:label="Photos" />
|
||||
|
||||
</navigation>
|
||||
@@ -75,7 +75,7 @@ class UserlistFragment : Fragment() {
|
||||
layoutManager = LinearLayoutManager(context)
|
||||
adapter = listAdapter.apply {
|
||||
onItemClick = {
|
||||
navigation.sendNavigation(UserlistNavigation.ClickedOnUser(it.id))
|
||||
navigation.sendNavigation(UserlistNavigation.ClickedOnUser(it.id, it.realName))
|
||||
}
|
||||
|
||||
onFavoriteClick = {
|
||||
|
||||
@@ -3,5 +3,5 @@ package com.hako.userlist.navigation
|
||||
import com.hako.base.navigation.NavigationEvent
|
||||
|
||||
sealed class UserlistNavigation : NavigationEvent {
|
||||
data class ClickedOnUser(val userId: Int) : UserlistNavigation()
|
||||
data class ClickedOnUser(val userId: Int, val userName: String) : UserlistNavigation()
|
||||
}
|
||||
|
||||
@@ -9,6 +9,6 @@
|
||||
android:id="@+id/userlistFragment"
|
||||
android:name="com.hako.userlist.feature.UserlistFragment"
|
||||
tools:layout="@layout/fragment_userlist"
|
||||
android:label="UserlistFragment" />
|
||||
android:label="Friendlist" />
|
||||
|
||||
</navigation>
|
||||
Reference in New Issue
Block a user