Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.hoc.flowmvi.ui.add
import android.content.Context
import android.content.Intent
import android.view.MenuItem
import android.view.ViewGroup
import androidx.core.view.isInvisible
import androidx.transition.AutoTransition
import androidx.transition.TransitionManager
Expand Down Expand Up @@ -98,6 +99,10 @@ class AddActivity : AbstractMviActivity<ViewIntent, ViewState, SingleEvent, AddV
}
}

override fun rootView(): ViewGroup {
return addBinding.root
}

override fun viewIntents(): Flow<ViewIntent> =
addBinding.run {
merge(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.hoc.flowmvi.ui.main

import android.view.Menu
import android.view.MenuItem
import android.view.ViewGroup
import androidx.core.view.isVisible
import androidx.recyclerview.widget.ItemTouchHelper
import androidx.recyclerview.widget.LinearLayoutManager
Expand Down Expand Up @@ -78,6 +79,10 @@ class MainActivity : AbstractMviActivity<ViewIntent, ViewState, SingleEvent, Mai
}
}

override fun rootView(): ViewGroup {
return mainBinding.root
}

override fun viewIntents(): Flow<ViewIntent> =
merge(
flowOf(ViewIntent.Initial),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.content.Intent
import android.content.res.Configuration
import android.view.Menu
import android.view.MenuItem
import android.view.ViewGroup
import androidx.appcompat.widget.SearchView
import androidx.core.view.isInvisible
import androidx.core.view.isVisible
Expand Down Expand Up @@ -112,6 +113,10 @@ class SearchActivity : AbstractMviActivity<ViewIntent, ViewState, SingleEvent, S
}
}

override fun rootView(): ViewGroup {
return binding.root
}

override fun onOptionsItemSelected(item: MenuItem): Boolean =
when (item.itemId) {
android.R.id.home -> finish().let { true }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
package com.hoc.flowmvi.mvi_base

import android.os.Build
import android.os.Bundle
import android.view.ViewGroup
import android.view.ViewTreeObserver
import androidx.activity.enableEdgeToEdge
import androidx.annotation.CallSuper
import androidx.annotation.LayoutRes
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.WindowInsetsCompat
import androidx.lifecycle.lifecycleScope
import com.hoc.flowmvi.core_ui.collectIn
import com.hoc.flowmvi.core_ui.debugCheckImmediateMainDispatcher
Expand All @@ -24,9 +29,13 @@ abstract class AbstractMviActivity<
@CallSuper
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

//
enableEdgeToEdge()
//
setupViews()
bindVM()
//
adaptFullScreen()
}

private fun bindVM() {
Expand All @@ -50,4 +59,33 @@ abstract class AbstractMviActivity<
}

protected abstract fun setupViews()


private fun adaptFullScreen() {
//
window.decorView.viewTreeObserver.addOnGlobalLayoutListener(
object : ViewTreeObserver.OnGlobalLayoutListener {
override fun onGlobalLayout() {
//
window.decorView.viewTreeObserver.removeOnGlobalLayoutListener(this)
//
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
//
val systemBarsInsets = WindowInsetsCompat.toWindowInsetsCompat(window.decorView.rootWindowInsets).getInsets(WindowInsetsCompat.Type.systemBars())
//
val actionBarHeight = supportActionBar?.height ?: 0
//
rootView().run {
val newLayoutParams = layoutParams as? ViewGroup.MarginLayoutParams ?: throw IllegalStateException("root view must have MarginLayoutParams")
newLayoutParams.topMargin = systemBarsInsets.top + actionBarHeight
newLayoutParams.bottomMargin = systemBarsInsets.bottom
layoutParams = newLayoutParams
}
}
}
},
)
}

protected abstract fun rootView(): ViewGroup
}