Skip to content

Commit

Permalink
Make compatible with edge-to-edge (API 35)
Browse files Browse the repository at this point in the history
  • Loading branch information
iSoron committed May 20, 2024
1 parent 732ec1c commit e7165d9
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 7 deletions.
2 changes: 2 additions & 0 deletions uhabits-android/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,14 @@ android {

namespace = "org.isoron.uhabits"
compileSdk = 34
// compileSdkPreview = "VanillaIceCream"

defaultConfig {
versionCode = 20200
versionName = "2.2.0"
minSdk = 28
targetSdk = 34
// targetSdkPreview = "VanillaIceCream"
applicationId = "org.isoron.uhabits"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import org.isoron.uhabits.BuildConfig
import org.isoron.uhabits.R
import org.isoron.uhabits.core.models.PaletteColor
import org.isoron.uhabits.databinding.AboutBinding
import org.isoron.uhabits.utils.applyRootViewInsets
import org.isoron.uhabits.utils.currentTheme
import org.isoron.uhabits.utils.setupToolbar

Expand Down Expand Up @@ -54,5 +55,6 @@ class AboutView(
binding.tvTranslate.setOnClickListener { screen.showTranslationWebsite() }
binding.tvVersion.setOnClickListener { screen.onPressDeveloperCountdown() }
binding.tvVersion.text = String.format(version, BuildConfig.VERSION_NAME)
applyRootViewInsets()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ package org.isoron.uhabits.activities.habits.edit
import android.annotation.SuppressLint
import android.content.res.ColorStateList
import android.content.res.Resources
import android.graphics.Color
import android.os.Bundle
import android.text.Html
import android.text.Spanned
Expand Down Expand Up @@ -53,7 +52,8 @@ import org.isoron.uhabits.core.models.PaletteColor
import org.isoron.uhabits.core.models.Reminder
import org.isoron.uhabits.core.models.WeekdayList
import org.isoron.uhabits.databinding.ActivityEditHabitBinding
import org.isoron.uhabits.utils.ColorUtils
import org.isoron.uhabits.utils.applyRootViewInsets
import org.isoron.uhabits.utils.applyToolbarInsets
import org.isoron.uhabits.utils.dismissCurrentAndShow
import org.isoron.uhabits.utils.formatTime
import org.isoron.uhabits.utils.toFormattedString
Expand Down Expand Up @@ -94,6 +94,8 @@ class EditHabitActivity : AppCompatActivity() {
themeSwitcher.apply()

binding = ActivityEditHabitBinding.inflate(layoutInflater)
binding.root.applyRootViewInsets()
binding.toolbar.applyToolbarInsets()
setContentView(binding.root)

if (intent.hasExtra("habitId")) {
Expand Down Expand Up @@ -352,8 +354,7 @@ class EditHabitActivity : AppCompatActivity() {
androidColor = themeSwitcher.currentTheme.color(color).toInt()
binding.colorButton.backgroundTintList = ColorStateList.valueOf(androidColor)
if (!themeSwitcher.isNightMode) {
val darkerAndroidColor = ColorUtils.mixColors(Color.BLACK, androidColor, 0.15f)
window.statusBarColor = darkerAndroidColor
window.statusBarColor = androidColor
binding.toolbar.setBackgroundColor(androidColor)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import org.isoron.uhabits.inject.ActivityContextModule
import org.isoron.uhabits.inject.DaggerHabitsActivityComponent
import org.isoron.uhabits.inject.HabitsActivityComponent
import org.isoron.uhabits.inject.HabitsApplicationComponent
import org.isoron.uhabits.utils.applyRootViewInsets
import org.isoron.uhabits.utils.dismissCurrentDialog
import org.isoron.uhabits.utils.restartWithFade

Expand Down Expand Up @@ -100,6 +101,7 @@ class ListHabitsActivity : AppCompatActivity(), Preferences.Listener {
menu = component.listHabitsMenu
Thread.setDefaultUncaughtExceptionHandler(BaseExceptionHandler(this))
component.listHabitsBehavior.onStartup()
rootView.applyRootViewInsets()
setContentView(rootView)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import org.isoron.uhabits.core.ui.screens.habits.show.ShowHabitMenuPresenter
import org.isoron.uhabits.core.ui.screens.habits.show.ShowHabitPresenter
import org.isoron.uhabits.core.ui.views.OnDateClickedListener
import org.isoron.uhabits.intents.IntentFactory
import org.isoron.uhabits.utils.applyRootViewInsets
import org.isoron.uhabits.utils.currentTheme
import org.isoron.uhabits.utils.dismissCurrentAndShow
import org.isoron.uhabits.utils.dismissCurrentDialog
Expand Down Expand Up @@ -109,6 +110,7 @@ class ShowHabitActivity : AppCompatActivity(), CommandRunner.Listener {
)

view.setListener(presenter)
view.applyRootViewInsets()
setContentView(view)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import org.isoron.uhabits.R
import org.isoron.uhabits.activities.AndroidThemeSwitcher
import org.isoron.uhabits.core.models.PaletteColor
import org.isoron.uhabits.databinding.SettingsActivityBinding
import org.isoron.uhabits.utils.applyRootViewInsets
import org.isoron.uhabits.utils.setupToolbar

class SettingsActivity : AppCompatActivity() {
Expand All @@ -42,6 +43,7 @@ class SettingsActivity : AppCompatActivity() {
color = PaletteColor(11),
theme = themeSwitcher.currentTheme
)
binding.root.applyRootViewInsets()
setContentView(binding.root)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import androidx.appcompat.app.AppCompatActivity
import org.isoron.uhabits.HabitsApplication
import org.isoron.uhabits.activities.AndroidThemeSwitcher
import org.isoron.uhabits.core.models.HabitMatcher
import org.isoron.uhabits.utils.applyRootViewInsets

class EditSettingActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
Expand All @@ -45,6 +46,7 @@ class EditSettingActivity : AppCompatActivity() {
onSave = controller::onSave,
args = args
)
view.applyRootViewInsets()
setContentView(view)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ import androidx.annotation.StringRes
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.Toolbar
import androidx.core.content.FileProvider
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import com.google.android.material.snackbar.Snackbar
import org.isoron.platform.gui.toInt
import org.isoron.uhabits.HabitsApplication
Expand Down Expand Up @@ -180,10 +182,10 @@ fun View.setupToolbar(
} else {
theme.color(color).toInt()
}
val darkerColor = ColorUtils.mixColors(toolbarColor, Color.BLACK, 0.75f)
toolbar.background = ColorDrawable(toolbarColor)
toolbar.applyToolbarInsets()
val activity = context as AppCompatActivity
activity.window.statusBarColor = darkerColor
activity.window.statusBarColor = toolbarColor
activity.setSupportActionBar(toolbar)
activity.supportActionBar?.setDisplayHomeAsUpEnabled(displayHomeAsUpEnabled)
}
Expand Down Expand Up @@ -245,3 +247,19 @@ fun View.getCenter(): PointF {
viewLocation[1] -= this.height / 2
return PointF(viewLocation[0].toFloat(), viewLocation[1].toFloat())
}

fun View.applyRootViewInsets() {
ViewCompat.setOnApplyWindowInsetsListener(this) { view, insets ->
val systemBarsInsets = insets.getInsets(WindowInsetsCompat.Type.systemBars())
view.setPadding(systemBarsInsets.left, 0, systemBarsInsets.right, systemBarsInsets.bottom)
insets
}
}

fun View.applyToolbarInsets() {
ViewCompat.setOnApplyWindowInsetsListener(this) { view, insets ->
val systemBarsInsets = insets.getInsets(WindowInsetsCompat.Type.systemBars())
view.setPadding(0, systemBarsInsets.top, 0, 0)
insets
}
}
2 changes: 1 addition & 1 deletion uhabits-android/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@

<style name="Toolbar">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">?actionBarSize</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:background">?colorPrimary</item>
<item name="android:theme">@style/ThemeOverlay.AppCompat.Dark.ActionBar</item>
</style>
Expand Down

0 comments on commit e7165d9

Please sign in to comment.