Skip to content
Snippets Groups Projects
Commit decebc7c authored by Kamal Bramwell's avatar Kamal Bramwell
Browse files

Created WindowManager interface to handle fullscreen requests from frags

parent 163d5cdc
No related branches found
No related tags found
No related merge requests found
...@@ -4,51 +4,39 @@ import android.content.Intent ...@@ -4,51 +4,39 @@ import android.content.Intent
import android.os.Bundle import android.os.Bundle
import androidx.activity.viewModels import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowCompat import androidx.core.view.WindowCompat
import androidx.core.view.WindowInsetsCompat import androidx.core.view.WindowInsetsCompat
import androidx.core.view.WindowInsetsControllerCompat import androidx.core.view.WindowInsetsControllerCompat
import androidx.lifecycle.Lifecycle import androidx.lifecycle.Lifecycle
import androidx.lifecycle.lifecycleScope import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle import androidx.lifecycle.repeatOnLifecycle
import io.xxlabs.messenger.R
import io.elixxir.core.ui.util.openLink import io.elixxir.core.ui.util.openLink
import io.xxlabs.messenger.databinding.ActivityMainBinding
import io.xxlabs.messenger.main.model.* import io.xxlabs.messenger.main.model.*
import io.xxlabs.messenger.main.window.WindowManager
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
/** /**
* The single Activity that hosts all Fragments. * The single Activity that hosts all Fragments.
* Responsible for navigation between features and enforces minimum app version. * Responsible for navigation between features and enforces minimum app version.
*/ */
class MainActivity : AppCompatActivity() { class MainActivity : AppCompatActivity(), WindowManager {
private val viewModel: MainViewModel by viewModels() private val viewModel: MainViewModel by viewModels()
private var mainIntent: Intent? = null private lateinit var binding: ActivityMainBinding
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
lifecycleScope.launch { lifecycleScope.launch {
repeatOnLifecycle(Lifecycle.State.STARTED) { repeatOnLifecycle(Lifecycle.State.STARTED) {
observeState() observeState()
} }
} }
WindowCompat.setDecorFitsSystemWindows(window, false)
hideSystemBars()
intent?.let { handleIntent(it) } intent?.let { handleIntent(it) }
setContentView(R.layout.activity_main)
}
private fun hideSystemBars() { binding = ActivityMainBinding.inflate(layoutInflater)
val windowInsetsController = setContentView(binding.root)
ViewCompat.getWindowInsetsController(window.decorView) ?: return
// Configure the behavior of the hidden system bars
windowInsetsController.systemBarsBehavior =
WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
// Hide both the status bar and the navigation bar
windowInsetsController.hide(WindowInsetsCompat.Type.systemBars())
} }
override fun onNewIntent(intent: Intent) { override fun onNewIntent(intent: Intent) {
...@@ -70,11 +58,11 @@ class MainActivity : AppCompatActivity() { ...@@ -70,11 +58,11 @@ class MainActivity : AppCompatActivity() {
} }
private fun invitationIntent(username: String) { private fun invitationIntent(username: String) {
TODO("Go to requests screen") TODO("Navigate to requests screen")
} }
private fun notificationIntent(intent: Intent) { private fun notificationIntent(intent: Intent) {
TODO("Go to chat/group chat") TODO("Navigate to chat/group chat")
} }
private fun observeState() { private fun observeState() {
...@@ -84,10 +72,10 @@ class MainActivity : AppCompatActivity() { ...@@ -84,10 +72,10 @@ class MainActivity : AppCompatActivity() {
when (versionState) { when (versionState) {
is VersionOk -> { is VersionOk -> {
if (userState == UserState.NewUser) navigateToRegistration() if (userState == UserState.NewUser) navigateToRegistration()
else navigateToHome() else navigateToMain()
} }
is UpdateRecommended -> showVersionAlert(versionState.alertUi) is UpdateRecommended -> showAlert(versionState.alertUi)
is UpdateRequired -> showVersionAlert(versionState.alertUi) is UpdateRequired -> showAlert(versionState.alertUi)
else -> {} else -> {}
} }
} }
...@@ -104,15 +92,38 @@ class MainActivity : AppCompatActivity() { ...@@ -104,15 +92,38 @@ class MainActivity : AppCompatActivity() {
} }
private fun navigateToRegistration() { private fun navigateToRegistration() {
TODO("Navigate to nav_registration graph")
}
private fun navigateToMain() {
TODO("Navigate to nav_main graph")
} }
private fun navigateToHome() { private fun showAlert(alertUi: VersionAlertUi) {
TODO()
}
override fun setFullScreen(fullScreen: Boolean) {
if (fullScreen) {
hideSystemUI()
} else {
showSystemUI()
}
} }
private fun showVersionAlert(alertUi: VersionAlertUi) { private fun hideSystemUI() {
WindowCompat.setDecorFitsSystemWindows(window, false)
WindowInsetsControllerCompat(window, binding.root).let { controller ->
controller.hide(WindowInsetsCompat.Type.systemBars())
controller.systemBarsBehavior =
WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
}
}
private fun showSystemUI() {
WindowCompat.setDecorFitsSystemWindows(window, true)
WindowInsetsControllerCompat(window, binding.root)
.show(WindowInsetsCompat.Type.systemBars())
} }
companion object { companion object {
......
package io.xxlabs.messenger.main.window
interface WindowManager {
fun setFullScreen(fullScreen: Boolean)
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment