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:
@@ -9,6 +9,10 @@
|
|||||||
android:id="@+id/albumlistFragment"
|
android:id="@+id/albumlistFragment"
|
||||||
android:name="com.hako.albumlist.feature.AlbumlistFragment"
|
android:name="com.hako.albumlist.feature.AlbumlistFragment"
|
||||||
tools:layout="@layout/fragment_albumlist"
|
tools:layout="@layout/fragment_albumlist"
|
||||||
android:label="AlbumlistFragment" />
|
android:label="{actionTitle}">
|
||||||
|
<argument
|
||||||
|
android:name="actionTitle"
|
||||||
|
app:argType="string" />
|
||||||
|
</fragment>
|
||||||
|
|
||||||
</navigation>
|
</navigation>
|
||||||
@@ -3,6 +3,7 @@ package com.hako.friendlists.view
|
|||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import androidx.navigation.findNavController
|
import androidx.navigation.findNavController
|
||||||
|
import androidx.navigation.ui.NavigationUI.setupActionBarWithNavController
|
||||||
import com.hako.base.extensions.observeNonNull
|
import com.hako.base.extensions.observeNonNull
|
||||||
import com.hako.base.navigation.NavigationRouter
|
import com.hako.base.navigation.NavigationRouter
|
||||||
import com.hako.friendlists.BuildConfig
|
import com.hako.friendlists.BuildConfig
|
||||||
@@ -36,10 +37,17 @@ class MainActivity : AppCompatActivity() {
|
|||||||
// Pair.second is a Bundle
|
// Pair.second is a Bundle
|
||||||
navController.navigate(pair.first, pair.second)
|
navController.navigate(pair.first, pair.second)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setupActionBarWithNavController(this, navController)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setupPicasso() {
|
private fun setupPicasso() {
|
||||||
// Show cache indicator on images just for debug builds
|
// Show cache indicator on images just for debug builds
|
||||||
picasso.setIndicatorsEnabled(BuildConfig.DEBUG)
|
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.photolist.feature.PHOTOLIST_FRAGMENT_BUNDLE_ALBUM_ID
|
||||||
import com.hako.userlist.navigation.UserlistNavigation
|
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() {
|
class NavigationViewmodel : ViewModel() {
|
||||||
|
|
||||||
val navigate = MutableLiveData<Pair<@IdRes Int, Bundle>>()
|
val navigate = MutableLiveData<Pair<@IdRes Int, Bundle>>()
|
||||||
@@ -29,6 +32,7 @@ class NavigationViewmodel : ViewModel() {
|
|||||||
is UserlistNavigation.ClickedOnUser -> navigate.postValue(
|
is UserlistNavigation.ClickedOnUser -> navigate.postValue(
|
||||||
buildNavigation(R.id.action_userlistFragment_to_albumlistFragment, Bundle().apply {
|
buildNavigation(R.id.action_userlistFragment_to_albumlistFragment, Bundle().apply {
|
||||||
putInt(ALBUMLIST_FRAGMENT_BUNDLE_USER_ID, event.userId)
|
putInt(ALBUMLIST_FRAGMENT_BUNDLE_USER_ID, event.userId)
|
||||||
|
putString(FRAGMENT_TITLE, event.userName)
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,18 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?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"
|
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_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent">
|
||||||
app:defaultNavHost="true"/>
|
|
||||||
|
<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:id="@+id/photolistFragment"
|
||||||
android:name="com.hako.photolist.feature.PhotolistFragment"
|
android:name="com.hako.photolist.feature.PhotolistFragment"
|
||||||
tools:layout="@layout/fragment_photolist"
|
tools:layout="@layout/fragment_photolist"
|
||||||
android:label="PhotolistFragment" />
|
android:label="Photos" />
|
||||||
|
|
||||||
</navigation>
|
</navigation>
|
||||||
@@ -75,7 +75,7 @@ class UserlistFragment : Fragment() {
|
|||||||
layoutManager = LinearLayoutManager(context)
|
layoutManager = LinearLayoutManager(context)
|
||||||
adapter = listAdapter.apply {
|
adapter = listAdapter.apply {
|
||||||
onItemClick = {
|
onItemClick = {
|
||||||
navigation.sendNavigation(UserlistNavigation.ClickedOnUser(it.id))
|
navigation.sendNavigation(UserlistNavigation.ClickedOnUser(it.id, it.realName))
|
||||||
}
|
}
|
||||||
|
|
||||||
onFavoriteClick = {
|
onFavoriteClick = {
|
||||||
|
|||||||
@@ -3,5 +3,5 @@ package com.hako.userlist.navigation
|
|||||||
import com.hako.base.navigation.NavigationEvent
|
import com.hako.base.navigation.NavigationEvent
|
||||||
|
|
||||||
sealed class UserlistNavigation : 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:id="@+id/userlistFragment"
|
||||||
android:name="com.hako.userlist.feature.UserlistFragment"
|
android:name="com.hako.userlist.feature.UserlistFragment"
|
||||||
tools:layout="@layout/fragment_userlist"
|
tools:layout="@layout/fragment_userlist"
|
||||||
android:label="UserlistFragment" />
|
android:label="Friendlist" />
|
||||||
|
|
||||||
</navigation>
|
</navigation>
|
||||||
Reference in New Issue
Block a user