Skip to content
Snippets Groups Projects
Commit b455dbe0 authored by Taras's avatar Taras
Browse files

Create empty splash fragment to solve start destination

parent 9b2f89d4
No related branches found
No related tags found
No related merge requests found
package com.futo.circles
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.navigation.NavController
import androidx.navigation.NavGraph
import androidx.navigation.fragment.NavHostFragment
import com.futo.circles.provider.MatrixSessionProvider
class MainActivity : AppCompatActivity(R.layout.main_activity) {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setInitialFragment()
}
private fun setInitialFragment() {
val navController: NavController =
(supportFragmentManager.findFragmentById(R.id.nav_host_fragment) as NavHostFragment).navController
val navGraph = navController.navInflater.inflate(R.navigation.nav_graph_start_host)
setStartDestination(navGraph)
navController.setGraph(navGraph, intent.extras)
}
private fun setStartDestination(navGraph: NavGraph) {
val startDestinationId = MatrixSessionProvider.currentSession?.let {
R.id.bottomNavigationFragment
} ?: R.id.logInFragment
navGraph.setStartDestination(startDestinationId)
}
}
\ No newline at end of file
class MainActivity : AppCompatActivity(R.layout.main_activity)
\ No newline at end of file
package com.futo.circles.feature.splash
import android.os.Bundle
import android.view.View
import androidx.fragment.app.Fragment
import androidx.navigation.fragment.findNavController
import com.futo.circles.R
import com.futo.circles.provider.MatrixSessionProvider
class SplashFragment : Fragment(R.layout.splash_fragment) {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
val destination = MatrixSessionProvider.currentSession?.let {
SplashFragmentDirections.toBottomNavigationFragment()
} ?: SplashFragmentDirections.toLogInFragment()
findNavController().navigate(destination)
}
}
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.fragment.app.FragmentContainerView 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/container"
android:id="@+id/nav_host_fragment"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
app:defaultNavHost="true"
app:navGraph="@navigation/nav_graph_start_host" />
<androidx.fragment.app.FragmentContainerView
android:id="@+id/nav_host_fragment"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:defaultNavHost="true" />
</FrameLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
......@@ -3,7 +3,25 @@
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/nav_graph_start_host"
app:startDestination="@id/logInFragment">
app:startDestination="@id/splashFragment">
<fragment
android:id="@+id/splashFragment"
android:name="com.futo.circles.feature.splash.SplashFragment"
android:label="Splash"
tools:layout="@layout/splash_fragment">
<action
android:id="@+id/to_logInFragment"
app:destination="@id/logInFragment"
app:popUpTo="@id/splashFragment"
app:popUpToInclusive="true" />
<action
android:id="@+id/to_bottomNavigationFragment"
app:destination="@id/bottomNavigationFragment"
app:popUpTo="@id/splashFragment"
app:popUpToInclusive="true" />
</fragment>
<fragment
android:id="@+id/logInFragment"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment