Skip to content

Commit

Permalink
refactor: move status bar color change
Browse files Browse the repository at this point in the history
  • Loading branch information
RobozinhoD authored and mikehardy committed Aug 19, 2024
1 parent 91b984a commit cb366dc
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ import android.content.Context
import android.content.Intent
import android.os.Bundle
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.widget.ThemeUtils
import com.ichi2.anki.R
import com.ichi2.anki.SingleFragmentActivity
import com.ichi2.anki.utils.navBarNeedsScrim
import kotlin.reflect.KClass
import kotlin.reflect.jvm.jvmName

Expand All @@ -31,6 +34,12 @@ class CardViewerActivity : SingleFragmentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
enableEdgeToEdge() // TODO assess moving this to SingleFragmentActivity
super.onCreate(savedInstanceState)

// use the screen background color if the nav bar doesn't need a scrim when using a
// transparent background. e.g. when navigation gestures are enabled
if (!navBarNeedsScrim) {
window.navigationBarColor = ThemeUtils.getThemeAttrColor(this, R.attr.alternativeBackgroundColor)
}
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import android.view.MenuItem
import android.view.View
import android.webkit.WebView
import androidx.activity.result.contract.ActivityResultContracts
import androidx.appcompat.widget.ThemeUtils
import androidx.appcompat.widget.Toolbar
import androidx.core.os.BundleCompat
import androidx.core.os.bundleOf
Expand All @@ -45,7 +44,6 @@ import com.ichi2.anki.cardviewer.CardMediaPlayer
import com.ichi2.anki.snackbar.BaseSnackbarBuilderProvider
import com.ichi2.anki.snackbar.SnackbarBuilder
import com.ichi2.anki.utils.ext.sharedPrefs
import com.ichi2.anki.utils.navBarNeedsScrim
import com.ichi2.annotations.NeedsTest
import com.ichi2.utils.performClickIfEnabled
import kotlinx.coroutines.flow.collectLatest
Expand Down Expand Up @@ -179,14 +177,6 @@ class PreviewerFragment :
if (sharedPrefs().getBoolean("safeDisplay", false)) {
view.findViewById<MaterialCardView>(R.id.webview_container).elevation = 0F
}

with(requireActivity()) {
// use the screen background color if the nav bar doesn't need a scrim when using a
// transparent background. e.g. when navigation gestures are enabled
if (!navBarNeedsScrim) {
window.navigationBarColor = ThemeUtils.getThemeAttrColor(this, R.attr.alternativeBackgroundColor)
}
}
}

private fun setupFlagMenu(menu: Menu) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import com.ichi2.anki.cardviewer.CardMediaPlayer
import com.ichi2.anki.snackbar.BaseSnackbarBuilderProvider
import com.ichi2.anki.snackbar.SnackbarBuilder
import com.ichi2.anki.utils.ext.sharedPrefs
import com.ichi2.anki.utils.navBarNeedsScrim
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.launch
Expand Down Expand Up @@ -120,11 +119,6 @@ class TemplatePreviewerFragment :
}

with(requireActivity()) {
// use the screen background color if the nav bar doesn't need a scrim when using a
// transparent background. e.g. when navigation gestures are enabled
if (!navBarNeedsScrim) {
window.navigationBarColor = ThemeUtils.getThemeAttrColor(this, R.attr.alternativeBackgroundColor)
}
window.statusBarColor = ThemeUtils.getThemeAttrColor(this, R.attr.appBarColor)
}
if (inFragmentedActivity) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import android.widget.FrameLayout
import androidx.activity.result.contract.ActivityResultContracts
import androidx.annotation.StringRes
import androidx.appcompat.view.menu.MenuBuilder
import androidx.appcompat.widget.ThemeUtils
import androidx.appcompat.widget.Toolbar
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.core.view.ViewCompat
Expand Down Expand Up @@ -57,7 +56,6 @@ import com.ichi2.anki.snackbar.showSnackbar
import com.ichi2.anki.utils.ext.collectIn
import com.ichi2.anki.utils.ext.collectLatestIn
import com.ichi2.anki.utils.ext.sharedPrefs
import com.ichi2.anki.utils.navBarNeedsScrim
import com.ichi2.libanki.sched.Counts
import com.ichi2.utils.increaseHorizontalPaddingOfOverflowMenuIcons
import kotlinx.coroutines.launch
Expand Down Expand Up @@ -102,13 +100,6 @@ class ReviewerFragment :
}
}

with(requireActivity()) {
if (!navBarNeedsScrim) {
window.navigationBarColor =
ThemeUtils.getThemeAttrColor(this, R.attr.alternativeBackgroundColor)
}
}

viewModel.actionFeedbackFlow.flowWithLifecycle(lifecycle)
.collectIn(lifecycleScope) { message ->
showSnackbar(message, duration = 500)
Expand Down

0 comments on commit cb366dc

Please sign in to comment.