Skip to content

Commit

Permalink
Renamed funs
Browse files Browse the repository at this point in the history
  • Loading branch information
nbradbury committed Jan 22, 2025
1 parent 939a91d commit 1811e4f
Show file tree
Hide file tree
Showing 17 changed files with 31 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class DesignSystemActivity : BaseAppCompatActivity() {
}
}

override fun shouldEnforceEdgeToEdge() = false
override fun shouldAdjustSystemBarsForEdgeToEdge() = false

@Preview(name = "Light Mode")
@Preview(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class BloggingPromptsListActivity : BaseAppCompatActivity() {
observeActions()
}

override fun shouldEnforceEdgeToEdge() = false
override fun shouldAdjustSystemBarsForEdgeToEdge() = false

/**
* Since we're declaring that this Activity handles orientation changes by itself in the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ class DebugSharedPreferenceFlagsActivity : BaseAppCompatActivity() {
}
}

override fun shouldEnforceEdgeToEdge() = false
override fun shouldAdjustSystemBarsForEdgeToEdge() = false
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class DomainManagementActivity : BaseAppCompatActivity() {
viewModel.actionEvents.onEach(this::handleActionEvents).launchIn(lifecycleScope)
}

override fun shouldEnforceEdgeToEdge() = false
override fun shouldAdjustSystemBarsForEdgeToEdge() = false

private fun handleActionEvents(actionEvent: ActionEvent) {
when (actionEvent) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class NewDomainSearchActivity : BaseAppCompatActivity() {
observeActions()
}

override fun shouldEnforceEdgeToEdge() = false
override fun shouldAdjustSystemBarsForEdgeToEdge() = false

private fun observeActions() {
viewModel.actionEvents.onEach(this::handleActionEvents).launchIn(lifecycleScope)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class PurchaseDomainActivity : BaseAppCompatActivity() {
observeActions()
}

override fun shouldEnforceEdgeToEdge() = false
override fun shouldAdjustSystemBarsForEdgeToEdge() = false

private fun observeActions() {
viewModel.actionEvents.onEach(this::handleActionEvents).launchIn(lifecycleScope)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,5 @@ class JetpackStaticPosterActivity : BaseAppCompatActivity() {
)
}

override fun shouldEnforceEdgeToEdge() = false
override fun shouldAdjustSystemBarsForEdgeToEdge() = false
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class JetpackFullPluginInstallActivity : BaseAppCompatActivity() {
observeActionEvents()
}

override fun shouldEnforceEdgeToEdge() = false
override fun shouldAdjustSystemBarsForEdgeToEdge() = false

@Suppress("OVERRIDE_DEPRECATION","MissingSuperCall")
override fun onBackPressed() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class JetpackRemoteInstallActivity : BaseAppCompatActivity() {
}
}

override fun shouldEnforceEdgeToEdge() = false
override fun shouldAdjustSystemBarsForEdgeToEdge() = false

private fun initViewModel(savedInstanceState: Bundle?) {
val site = requireNotNull(intent.getSerializableExtraCompat<SiteModel>(WordPress.SITE))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,36 +15,40 @@ open class BaseAppCompatActivity : AppCompatActivity() {
@Override
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
if ((Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) && shouldEnforceEdgeToEdge()) {
enforceEdgeToEdge()
if ((Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) && shouldAdjustSystemBarsForEdgeToEdge()) {
adjustSystemBarsForEdgeToEdge()
}
}

@RequiresApi(Build.VERSION_CODES.R)
private fun enforceEdgeToEdge() {
private fun adjustSystemBarsForEdgeToEdge() {
window.decorView.setOnApplyWindowInsetsListener { view, insets ->
// set the system bars color
val systemBarColor = getColorFromAttribute(com.google.android.material.R.attr.colorSurface)
view.setBackgroundColor(systemBarColor)

// Adjust system bars padding to avoid overlap
val statusBarInsets = insets.getInsets(WindowInsets.Type.statusBars())
val navigationBarInsets = insets.getInsets(WindowInsets.Type.navigationBars())
view.setPadding(
0,
statusBarInsets.top,
getTopOffset(insets),
0,
navigationBarInsets.bottom
getBottomOffset(insets)
)

insets
}
}

/**
* Defaults to enforcing edge-to-edge on Android 15+, but descendants can override this to return
* false for cases such as Compose-based activities where edge-to-edge is automatically supported,
* or full-screen activities where we don't want to alter the window insets
* Defaults to enforcing system bar padding for edge-to-edge on Android 15+ - descendants can override this and
* return false for cases such as Compose-based activities where edge-to-edge is automatically supported,
* or full-screen activities where we don't want to alter the window insets.
*/
open fun shouldEnforceEdgeToEdge() = (Build.VERSION.SDK_INT >= Build.VERSION_CODES.VANILLA_ICE_CREAM)
open fun shouldAdjustSystemBarsForEdgeToEdge() = (Build.VERSION.SDK_INT >= Build.VERSION_CODES.VANILLA_ICE_CREAM)

@RequiresApi(Build.VERSION_CODES.R)
open fun getTopOffset(insets: WindowInsets) = insets.getInsets(WindowInsets.Type.statusBars()).top

@RequiresApi(Build.VERSION_CODES.R)
open fun getBottomOffset(insets: WindowInsets) = insets.getInsets(WindowInsets.Type.navigationBars()).bottom
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class FeedbackFormActivity : BaseAppCompatActivity() {
)
}

override fun shouldEnforceEdgeToEdge() = false
override fun shouldAdjustSystemBarsForEdgeToEdge() = false

private fun navigateToHelpScreen() {
val intent = Intent(this, HelpActivity::class.java)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
}

@Override
public boolean shouldEnforceEdgeToEdge() {
public boolean shouldAdjustSystemBarsForEdgeToEdge() {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class MenuActivity : BaseAppCompatActivity() {
}
}

override fun shouldEnforceEdgeToEdge() = false
override fun shouldAdjustSystemBarsForEdgeToEdge() = false

@Suppress("OVERRIDE_DEPRECATION")
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class PersonalizationActivity : BaseAppCompatActivity() {
viewModel.onSelectedSiteMissing.observe(this) { finish() }
}

override fun shouldEnforceEdgeToEdge() = false
override fun shouldAdjustSystemBarsForEdgeToEdge() = false

@OptIn(ExperimentalMaterial3Api::class)
@Composable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class EditJetpackSocialShareMessageActivity : BaseAppCompatActivity() {
}
}

override fun shouldEnforceEdgeToEdge() = false
override fun shouldAdjustSystemBarsForEdgeToEdge() = false

@Composable
private fun Loaded(state: UiState.Loaded) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class ExperimentalFeaturesActivity : BaseAppCompatActivity() {
}
}

override fun shouldEnforceEdgeToEdge() = false
override fun shouldAdjustSystemBarsForEdgeToEdge() = false
}

@OptIn(ExperimentalMaterial3Api::class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class SelfHostedUsersActivity : BaseAppCompatActivity() {
)
}

override fun shouldEnforceEdgeToEdge() = false
override fun shouldAdjustSystemBarsForEdgeToEdge() = false

override fun onSaveInstanceState(outState: Bundle) {
super.onSaveInstanceState(outState)
Expand Down

0 comments on commit 1811e4f

Please sign in to comment.