Add splash screen
This commit is contained in:
@@ -0,0 +1,62 @@
|
|||||||
|
package gq.kirmanak.mealient.ui.splash
|
||||||
|
|
||||||
|
import android.os.Bundle
|
||||||
|
import android.view.LayoutInflater
|
||||||
|
import android.view.View
|
||||||
|
import android.view.ViewGroup
|
||||||
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
|
import androidx.fragment.app.Fragment
|
||||||
|
import androidx.fragment.app.viewModels
|
||||||
|
import androidx.navigation.fragment.findNavController
|
||||||
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
|
import gq.kirmanak.mealient.databinding.FragmentSplashBinding
|
||||||
|
import timber.log.Timber
|
||||||
|
|
||||||
|
@AndroidEntryPoint
|
||||||
|
class SplashFragment : Fragment() {
|
||||||
|
private val viewModel by viewModels<SplashViewModel>()
|
||||||
|
|
||||||
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
|
super.onCreate(savedInstanceState)
|
||||||
|
Timber.v("onCreate() called with: savedInstanceState = $savedInstanceState")
|
||||||
|
viewModel.nextDestination.observe(this) {
|
||||||
|
Timber.d("onCreate: next destination $it")
|
||||||
|
findNavController().navigate(it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onCreateView(
|
||||||
|
inflater: LayoutInflater,
|
||||||
|
container: ViewGroup?,
|
||||||
|
savedInstanceState: Bundle?
|
||||||
|
): View {
|
||||||
|
Timber.v("onCreateView() called with: inflater = $inflater, container = $container, savedInstanceState = $savedInstanceState")
|
||||||
|
val binding = FragmentSplashBinding.inflate(inflater, container, false)
|
||||||
|
return binding.root
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onResume() {
|
||||||
|
super.onResume()
|
||||||
|
Timber.v("onResume() called")
|
||||||
|
changeFullscreenState(true)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onPause() {
|
||||||
|
super.onPause()
|
||||||
|
Timber.v("onPause() called")
|
||||||
|
changeFullscreenState(false)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun changeFullscreenState(isFullscreen: Boolean) {
|
||||||
|
Timber.v("changeFullscreenState() called with: isFullscreen = $isFullscreen")
|
||||||
|
|
||||||
|
val supportActionBar = (activity as? AppCompatActivity)?.supportActionBar
|
||||||
|
Timber.d("changeFullscreenState: action bar = $supportActionBar")
|
||||||
|
if (isFullscreen) supportActionBar?.hide()
|
||||||
|
else supportActionBar?.show()
|
||||||
|
|
||||||
|
val decorView = activity?.window?.decorView
|
||||||
|
Timber.d("changeFullscreenState: decorView = $decorView")
|
||||||
|
decorView?.systemUiVisibility = if (isFullscreen) View.SYSTEM_UI_FLAG_FULLSCREEN else 0
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
package gq.kirmanak.mealient.ui.splash
|
||||||
|
|
||||||
|
import androidx.lifecycle.LiveData
|
||||||
|
import androidx.lifecycle.MutableLiveData
|
||||||
|
import androidx.lifecycle.ViewModel
|
||||||
|
import androidx.lifecycle.viewModelScope
|
||||||
|
import androidx.navigation.NavDirections
|
||||||
|
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||||
|
import gq.kirmanak.mealient.data.auth.AuthRepo
|
||||||
|
import gq.kirmanak.mealient.data.disclaimer.DisclaimerStorage
|
||||||
|
import kotlinx.coroutines.flow.first
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
@HiltViewModel
|
||||||
|
class SplashViewModel @Inject constructor(
|
||||||
|
private val authRepo: AuthRepo,
|
||||||
|
private val disclaimerStorage: DisclaimerStorage
|
||||||
|
) : ViewModel() {
|
||||||
|
private val _nextDestination = MutableLiveData<NavDirections>()
|
||||||
|
val nextDestination: LiveData<NavDirections> = _nextDestination
|
||||||
|
|
||||||
|
init {
|
||||||
|
viewModelScope.launch {
|
||||||
|
_nextDestination.value = if (!disclaimerStorage.isDisclaimerAccepted())
|
||||||
|
SplashFragmentDirections.actionSplashFragmentToDisclaimerFragment()
|
||||||
|
else if (!authRepo.authenticationStatuses().first())
|
||||||
|
SplashFragmentDirections.actionSplashFragmentToAuthenticationFragment()
|
||||||
|
else
|
||||||
|
SplashFragmentDirections.actionSplashFragmentToRecipesFragment()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,7 +3,8 @@
|
|||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent"
|
||||||
|
tools:context=".ui.recipes.info.RecipeInfoFragment">
|
||||||
|
|
||||||
<androidx.constraintlayout.widget.ConstraintLayout
|
<androidx.constraintlayout.widget.ConstraintLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
|||||||
19
app/src/main/res/layout/fragment_splash.xml
Normal file
19
app/src/main/res/layout/fragment_splash.xml
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<androidx.constraintlayout.widget.ConstraintLayout 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:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
tools:context=".ui.splash.SplashFragment">
|
||||||
|
|
||||||
|
<com.google.android.material.progressindicator.CircularProgressIndicator
|
||||||
|
android:id="@+id/progressBar"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:indeterminate="true"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
|
app:layout_constraintVertical_bias="0.7" />
|
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
@@ -3,7 +3,7 @@
|
|||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:id="@+id/nav_graph"
|
android:id="@+id/nav_graph"
|
||||||
app:startDestination="@id/disclaimerFragment">
|
app:startDestination="@id/splashFragment">
|
||||||
|
|
||||||
<fragment
|
<fragment
|
||||||
android:id="@+id/authenticationFragment"
|
android:id="@+id/authenticationFragment"
|
||||||
@@ -58,4 +58,25 @@
|
|||||||
app:popUpTo="@id/nav_graph"
|
app:popUpTo="@id/nav_graph"
|
||||||
app:popUpToInclusive="true" />
|
app:popUpToInclusive="true" />
|
||||||
</fragment>
|
</fragment>
|
||||||
|
<fragment
|
||||||
|
android:id="@+id/splashFragment"
|
||||||
|
android:name="gq.kirmanak.mealient.ui.splash.SplashFragment"
|
||||||
|
android:label="fragment_splash"
|
||||||
|
tools:layout="@layout/fragment_splash">
|
||||||
|
<action
|
||||||
|
android:id="@+id/action_splashFragment_to_authenticationFragment"
|
||||||
|
app:destination="@id/authenticationFragment"
|
||||||
|
app:popUpTo="@id/nav_graph"
|
||||||
|
app:popUpToInclusive="true" />
|
||||||
|
<action
|
||||||
|
android:id="@+id/action_splashFragment_to_disclaimerFragment"
|
||||||
|
app:destination="@id/disclaimerFragment"
|
||||||
|
app:popUpTo="@id/nav_graph"
|
||||||
|
app:popUpToInclusive="true" />
|
||||||
|
<action
|
||||||
|
android:id="@+id/action_splashFragment_to_recipesFragment"
|
||||||
|
app:destination="@id/recipesFragment"
|
||||||
|
app:popUpTo="@id/nav_graph"
|
||||||
|
app:popUpToInclusive="true" />
|
||||||
|
</fragment>
|
||||||
</navigation>
|
</navigation>
|
||||||
Reference in New Issue
Block a user