Skip to content

Commit

Permalink
Renamed fun
Browse files Browse the repository at this point in the history
  • Loading branch information
nbradbury committed Jan 21, 2025
1 parent ee1cba8 commit f38b2bc
Show file tree
Hide file tree
Showing 18 changed files with 42 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 shouldUseEdgeToEdge() = false
override fun shouldEnforceEdgeToEdge() = false

@Preview(name = "Light Mode")
@Preview(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import org.wordpress.android.ui.WPWebViewActivity
import org.wordpress.android.ui.accounts.HelpActivity
import org.wordpress.android.util.ToastUtils
import org.wordpress.android.util.extensions.getSerializableCompat
import org.wordpress.android.util.extensions.setWindowNavigationBarColor
import org.wordpress.android.widgets.WPSnackbar
import java.util.UUID
import javax.inject.Inject
Expand Down Expand Up @@ -56,7 +55,6 @@ class SupportWebViewActivity : WPWebViewActivity(), SupportWebViewClient.Support

supportActionBar?.title = getString(R.string.help)
supportActionBar?.subtitle = ""
window.setWindowNavigationBarColor(getColor(R.color.docsbot_chat_container))

// Prevent AppBar scrolling away
val toolbar = findViewById<Toolbar>(R.id.toolbar)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class BloggingPromptsListActivity : BaseAppCompatActivity() {
observeActions()
}

override fun shouldUseEdgeToEdge() = false
override fun shouldEnforceEdgeToEdge() = 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 @@ -2,7 +2,6 @@ package org.wordpress.android.ui.debug.preferences

import android.os.Bundle
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import dagger.hilt.android.AndroidEntryPoint
Expand All @@ -28,5 +27,5 @@ class DebugSharedPreferenceFlagsActivity : BaseAppCompatActivity() {
}
}

override fun shouldUseEdgeToEdge() = false
override fun shouldEnforceEdgeToEdge() = 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 shouldUseEdgeToEdge() = false
override fun shouldEnforceEdgeToEdge() = 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 shouldUseEdgeToEdge() = false
override fun shouldEnforceEdgeToEdge() = 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 shouldUseEdgeToEdge() = false
override fun shouldEnforceEdgeToEdge() = 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 @@ -4,7 +4,6 @@ import android.os.Bundle
import android.view.View.generateViewId
import android.view.ViewGroup
import android.widget.FrameLayout
import androidx.appcompat.app.AppCompatActivity
import androidx.compose.runtime.Composable
import androidx.compose.ui.viewinterop.AndroidView
import androidx.fragment.app.commit
Expand Down Expand Up @@ -45,5 +44,5 @@ class JetpackStaticPosterActivity : BaseAppCompatActivity() {
)
}

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

override fun shouldUseEdgeToEdge() = false
override fun shouldEnforceEdgeToEdge() = 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 shouldUseEdgeToEdge() = false
override fun shouldEnforceEdgeToEdge() = 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 @@ -2,23 +2,43 @@ package org.wordpress.android.ui.main

import android.os.Build
import android.os.Bundle
import android.view.WindowInsets
import androidx.annotation.RequiresApi
import androidx.appcompat.app.AppCompatActivity
import org.wordpress.android.util.extensions.getColorFromAttribute
import org.wordpress.android.util.extensions.setWindowStatusBarColor

/**
* Base class for all activities - initially created to support Android 15's edge-to-edge, but can be extended
* in the future to handle other cases
*/
open class BaseAppCompatActivity : AppCompatActivity() {
@Override
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
if (shouldUseEdgeToEdge()) {
val statusBarColor = getColorFromAttribute(com.google.android.material.R.attr.colorSurface)
window.setWindowStatusBarColor(statusBarColor)
if (shouldEnforceEdgeToEdge()) {
enforceEdgeToEdge()
}
}

@RequiresApi(Build.VERSION_CODES.R)
private fun enforceEdgeToEdge() {
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 navBarInsets = insets.getInsets(WindowInsets.Type.navigationBars())
view.setPadding(0, statusBarInsets.top, 0, navBarInsets.bottom)

insets
}
}

/**
* Descendants can override this to return false if they don't want to use edge-to-edge - this should
* be set to false for Compose-based activities since Compose automatically handles edge-to-edge
* 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
*/
open fun shouldUseEdgeToEdge() = (Build.VERSION.SDK_INT >= Build.VERSION_CODES.VANILLA_ICE_CREAM)
open fun shouldEnforceEdgeToEdge() = (Build.VERSION.SDK_INT >= Build.VERSION_CODES.VANILLA_ICE_CREAM)
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class FeedbackFormActivity : BaseAppCompatActivity() {
)
}

override fun shouldUseEdgeToEdge() = false
override fun shouldEnforceEdgeToEdge() = 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 @@ -104,7 +104,7 @@ class MenuActivity : BaseAppCompatActivity() {
}
}

override fun shouldUseEdgeToEdge() = false
override fun shouldEnforceEdgeToEdge() = 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 shouldUseEdgeToEdge() = false
override fun shouldEnforceEdgeToEdge() = 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 shouldUseEdgeToEdge() = false
override fun shouldEnforceEdgeToEdge() = 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 shouldUseEdgeToEdge() = false
override fun shouldEnforceEdgeToEdge() = 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 shouldUseEdgeToEdge() = false
override fun shouldEnforceEdgeToEdge() = false

override fun onSaveInstanceState(outState: Bundle) {
super.onSaveInstanceState(outState)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ fun Dialog.setStatusBarAsSurfaceColor() {
window?.setWindowStatusBarColor(statusBarColor)
}


fun BottomSheetDialog.fillScreen(isDraggable: Boolean = false) {
setOnShowListener {
val bottomSheet: FrameLayout = findViewById(
Expand Down

0 comments on commit f38b2bc

Please sign in to comment.