Skip to content

Commit

Permalink
Margin -> padding for display inset
Browse files Browse the repository at this point in the history
  • Loading branch information
iamrasel committed Apr 24, 2023
1 parent 7ba3765 commit c6650dc
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions app/src/main/kotlin/rasel/lunar/launcher/LauncherActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,14 @@ import android.net.Uri
import android.os.Build
import android.os.Bundle
import android.provider.Settings
import android.view.View
import android.view.ViewGroup
import android.view.WindowInsets
import android.view.WindowManager
import androidx.activity.OnBackPressedCallback
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowCompat
import androidx.core.view.WindowInsetsCompat
import androidx.core.view.updatePadding
import androidx.viewpager2.widget.ViewPager2
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import rasel.lunar.launcher.apps.AppDrawer
Expand Down Expand Up @@ -162,7 +161,7 @@ internal class LauncherActivity : AppCompatActivity() {
@Suppress("DEPRECATION")
window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN)
}
topMargin(false)
topPadding(false)
} else {
/* show status bar */
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
Expand All @@ -171,7 +170,7 @@ internal class LauncherActivity : AppCompatActivity() {
@Suppress("DEPRECATION")
window.clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN)
}
topMargin(true)
topPadding(true)
}
}

Expand All @@ -188,15 +187,10 @@ internal class LauncherActivity : AppCompatActivity() {
})
}

private fun topMargin(topMargin: Boolean) {
ViewCompat.setOnApplyWindowInsetsListener(binding.root) { v: View, windowInsets: WindowInsetsCompat ->
val insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars())
val mlp = v.layoutParams as ViewGroup.MarginLayoutParams
mlp.leftMargin = insets.left
mlp.rightMargin = insets.right
mlp.bottomMargin = insets.bottom
mlp.topMargin = if (topMargin) insets.top else 0
v.layoutParams = mlp
private fun topPadding(topPadding: Boolean) {
ViewCompat.setOnApplyWindowInsetsListener(binding.root) { view, windowInsets ->
val insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemGestures())
view.updatePadding(insets.left, if (topPadding) insets.top else 0, insets.right, insets.bottom)
WindowInsetsCompat.CONSUMED
}
}
Expand Down

0 comments on commit c6650dc

Please sign in to comment.