Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Edge to edge #91

Merged
merged 10 commits into from
Jan 10, 2025
Merged
4 changes: 2 additions & 2 deletions config.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ ext {

buildConfig = [
"minSdk" : 21,
"compileSdk": 34,
"targetSdk" : 34,
"compileSdk": 35,
"targetSdk" : 35,
"buildTools": "34.0.0"
]
releaseConfig = [
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ ktlintplugin = "11.3.1"
ktlint = "0.45.2"
cpd = "3.3"
dokka = "1.8.10"
chucker = "4.0.0"
chucker = "4.1.0"
collar = "1.4.0"
dbinspector = "5.4.9"
leakcanary = "2.11"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.infinum.sentinel.sample

import android.os.Bundle
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import com.infinum.sentinel.sample.databinding.ActivityBundleBinding

Expand All @@ -9,6 +10,7 @@ class BundleActivity : AppCompatActivity() {
private lateinit var viewBinding: ActivityBundleBinding

override fun onCreate(savedInstanceState: Bundle?) {
enableEdgeToEdge()
super.onCreate(savedInstanceState)

viewBinding = ActivityBundleBinding.inflate(layoutInflater)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
package com.infinum.sentinel.sample;

import android.content.res.Configuration;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.view.Window;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.view.WindowCompat;

import com.infinum.sentinel.Sentinel;
import com.infinum.sentinel.sample.databinding.ActivityJavaMainBinding;
Expand All @@ -23,8 +28,8 @@ public class JavaMainActivity extends AppCompatActivity {

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
setEdgeToEdge();
super.onCreate(savedInstanceState);

final ActivityJavaMainBinding viewBinding = ActivityJavaMainBinding.inflate(getLayoutInflater());
setContentView(viewBinding.getRoot());

Expand All @@ -35,11 +40,34 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
tools.add(new GooglePlayTool());
tools.add(new ThimbleTool());
tools.add(new TimberTool());
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O){
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
tools.add(new CertificateTool());
}
Sentinel.watch(tools);

viewBinding.showSentinel.setOnClickListener(v -> Sentinel.show());
}

private void setEdgeToEdge() {
Window window = getWindow();
WindowCompat.setDecorFitsSystemWindows(window, false);
window.setStatusBarColor(Color.TRANSPARENT);
window.setNavigationBarColor(Color.TRANSPARENT);

handleStatusBarFlag(window);
}

private void handleStatusBarFlag(Window window) {
View decorView = window.getDecorView();
int flags = View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;
if (isLightMode() && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
flags |= View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
}
decorView.setSystemUiVisibility(flags);
}

private boolean isLightMode() {
int currentNightMode = getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK;
return currentNightMode != Configuration.UI_MODE_NIGHT_YES;
}
}
19 changes: 19 additions & 0 deletions sample/src/main/kotlin/com/infinum/sentinel/sample/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ import android.content.Intent
import android.content.SharedPreferences
import android.os.Bundle
import android.util.Log
import android.view.ViewGroup
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.core.view.updateLayoutParams
import androidx.preference.PreferenceManager
import androidx.security.crypto.EncryptedSharedPreferences
import androidx.security.crypto.MasterKey
Expand All @@ -23,10 +28,14 @@ class MainActivity : AppCompatActivity() {

@Suppress("TooGenericExceptionCaught", "LongMethod")
override fun onCreate(savedInstanceState: Bundle?) {
enableEdgeToEdge()
super.onCreate(savedInstanceState)

viewBinding = ActivityMainBinding.inflate(layoutInflater)
setContentView(viewBinding.root)

applyInsetsToLastElement()

val allPrefs = listOf(
PreferenceManager.getDefaultSharedPreferences(applicationContext),
applicationContext.getSharedPreferences(
Expand Down Expand Up @@ -158,6 +167,16 @@ class MainActivity : AppCompatActivity() {
}
}

private fun applyInsetsToLastElement() {
ViewCompat.setOnApplyWindowInsetsListener(viewBinding.generateErrorException) { view, insets ->
val systemBarsInsets = insets.getInsets(WindowInsetsCompat.Type.systemBars())
view.updateLayoutParams<ViewGroup.MarginLayoutParams> {
bottomMargin = systemBarsInsets.bottom
}
insets
}
}

private fun putRandomIntoPreferences(sharedPreferences: SharedPreferences) =
sharedPreferences.edit()
.putBoolean(randomizeName(Boolean::class.simpleName), Random.nextBoolean())
Expand Down
2 changes: 1 addition & 1 deletion sample/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<resources>
<style name="AppTheme" parent="Theme.Material3.DayNight">
<style name="AppTheme" parent="Theme.Material3.DayNight.NoActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
</style>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ internal data class ApplicationData(
val applicationIcon: Drawable,
val applicationName: String,
val versionCode: String,
val versionName: String,
val versionName: String?,
val firstInstall: String,
val lastUpdate: String,
val minSdk: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ internal class HtmlFormatter(
.apply {
applicationCollector().let {
addDiv(R.string.sentinel_version_code, it.versionCode)
addDiv(R.string.sentinel_version_name, it.versionName)
addDiv(R.string.sentinel_version_name, it.versionName ?: "")
addDiv(R.string.sentinel_first_install, it.firstInstall)
addDiv(R.string.sentinel_last_update, it.lastUpdate)
addDiv(R.string.sentinel_min_sdk, it.minSdk)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ internal class JsonFormatter(
JSONObject().apply {
applicationCollector().let {
addKey(R.string.sentinel_version_code, it.versionCode)
addKey(R.string.sentinel_version_name, it.versionName)
addKey(R.string.sentinel_version_name, it.versionName ?: "")
addKey(R.string.sentinel_first_install, it.firstInstall)
addKey(R.string.sentinel_last_update, it.lastUpdate)
addKey(R.string.sentinel_min_sdk, it.minSdk)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ internal class XmlFormatter(
startTag(NAMESPACE, APPLICATION)
applicationCollector().let {
addNode(R.string.sentinel_version_code, it.versionCode)
addNode(R.string.sentinel_version_name, it.versionName)
addNode(R.string.sentinel_version_name, it.versionName ?: "")
addNode(R.string.sentinel_first_install, it.firstInstall)
addNode(R.string.sentinel_last_update, it.lastUpdate)
addNode(R.string.sentinel_min_sdk, it.minSdk)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ internal abstract class StringBuilderFormatter {

internal fun addApplicationData(builder: StringBuilder, data: ApplicationData) {
addLine(builder, R.string.sentinel_version_code, data.versionCode)
addLine(builder, R.string.sentinel_version_name, data.versionName)
addLine(builder, R.string.sentinel_version_name, data.versionName ?: "")
addLine(builder, R.string.sentinel_first_install, data.firstInstall)
addLine(builder, R.string.sentinel_last_update, data.lastUpdate)
addLine(builder, R.string.sentinel_min_sdk, data.minSdk)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ internal class ApplicationFragment :
when (state) {
is ApplicationState.Data -> with(binding) {
versionCodeView.data = state.value.versionCode
versionNameView.data = state.value.versionName
versionNameView.data = state.value.versionName ?: ""
firstInstallView.data = state.value.firstInstall
lastUpdateView.data = state.value.lastUpdate
minSdkView.data = state.value.minSdk
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.infinum.sentinel.ui.shared.base
import android.content.res.Configuration
import android.os.Build
import android.os.Bundle
import androidx.activity.enableEdgeToEdge
import androidx.annotation.CallSuper
import androidx.annotation.RestrictTo
import androidx.core.content.ContextCompat
Expand All @@ -17,6 +18,8 @@ internal abstract class BaseActivity<State, Event> : FragmentActivity(), BaseVie
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

enableEdgeToEdge()

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
when (resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK) {
Configuration.UI_MODE_NIGHT_YES -> false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:colorBackground"
android:fitsSystemWindows="true"
app:layout_behavior="com.google.android.material.appbar.AppBarLayout$Behavior"
app:liftOnScroll="true"
app:liftOnScrollTargetViewId="@id/recyclerView">
Expand Down
1 change: 1 addition & 0 deletions sentinel/src/main/res/layout/sentinel_fragment_bundles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:colorBackground"
android:fitsSystemWindows="true"
app:layout_behavior="com.google.android.material.appbar.AppBarLayout$Behavior"
app:liftOnScroll="true"
app:liftOnScrollTargetViewId="@id/recyclerView">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:colorBackground"
android:fitsSystemWindows="true"
app:layout_behavior="com.google.android.material.appbar.AppBarLayout$Behavior"
app:liftOnScroll="true"
app:liftOnScrollTargetViewId="@id/recyclerView">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:colorBackground"
android:fitsSystemWindows="true"
app:layout_behavior="com.google.android.material.appbar.AppBarLayout$Behavior"
app:liftOnScroll="true"
app:liftOnScrollTargetViewId="@id/recyclerView">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:colorBackground"
android:fitsSystemWindows="true"
app:layout_behavior="com.google.android.material.appbar.AppBarLayout$Behavior"
app:liftOnScroll="true"
app:liftOnScrollTargetViewId="@id/recyclerView">
Expand Down
1 change: 1 addition & 0 deletions sentinel/src/main/res/layout/sentinel_fragment_crashes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:colorBackground"
android:fitsSystemWindows="true"
app:layout_behavior="com.google.android.material.appbar.AppBarLayout$Behavior"
app:liftOnScroll="true"
app:liftOnScrollTargetViewId="@id/recyclerView">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:colorBackground"
android:fitsSystemWindows="true"
app:layout_behavior="com.google.android.material.appbar.AppBarLayout$Behavior"
app:liftOnScroll="true"
app:liftOnScrollTargetViewId="@id/nestedScrollView">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:colorBackground"
android:fitsSystemWindows="true"
Copy link
Contributor

@AsimRibo AsimRibo Jan 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't fitsSystemWindows go to root parent so it handles both top and bottom insets?

app:layout_behavior="com.google.android.material.appbar.AppBarLayout$Behavior"
app:liftOnScroll="true"
app:liftOnScrollTargetViewId="@id/nestedScrollView">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:colorBackground"
android:fitsSystemWindows="true"
app:layout_behavior="com.google.android.material.appbar.AppBarLayout$Behavior"
app:liftOnScroll="true"
app:liftOnScrollTargetViewId="@id/recyclerView">
Expand Down
1 change: 1 addition & 0 deletions tool-timber/src/main/res/layout/sentinel_activity_logs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:colorBackground"
android:fitsSystemWindows="true"
app:layout_behavior="com.google.android.material.appbar.AppBarLayout$Behavior"
app:liftOnScroll="true"
app:liftOnScrollTargetViewId="@id/recyclerView">
Expand Down
Loading