|
3 | 3 | * |
4 | 4 | * @author David González Verdugo |
5 | 5 | * @author Aitor Ballesteros Pavón |
| 6 | + * @author Jorge Aguado Recio |
6 | 7 | * |
7 | | - * Copyright (C) 2024 ownCloud GmbH. |
| 8 | + * Copyright (C) 2026 ownCloud GmbH. |
8 | 9 | * |
9 | 10 | * This program is free software: you can redistribute it and/or modify |
10 | 11 | * it under the terms of the GNU General Public License version 2, |
@@ -32,14 +33,21 @@ import android.content.pm.ResolveInfo |
32 | 33 | import android.net.Uri |
33 | 34 | import android.text.method.LinkMovementMethod |
34 | 35 | import android.util.TypedValue |
| 36 | +import android.view.View |
| 37 | +import android.view.ViewGroup |
35 | 38 | import android.view.inputmethod.InputMethodManager |
36 | 39 | import android.webkit.MimeTypeMap |
37 | 40 | import android.widget.LinearLayout |
38 | 41 | import android.widget.TextView |
39 | 42 | import android.widget.Toast |
40 | 43 | import androidx.appcompat.app.AppCompatActivity |
| 44 | +import androidx.appcompat.widget.Toolbar |
41 | 45 | import androidx.core.content.FileProvider |
42 | 46 | import androidx.core.text.HtmlCompat |
| 47 | +import androidx.core.view.ViewCompat |
| 48 | +import androidx.core.view.WindowInsetsCompat |
| 49 | +import androidx.core.view.updateLayoutParams |
| 50 | +import androidx.core.view.updateMargins |
43 | 51 | import androidx.fragment.app.FragmentActivity |
44 | 52 | import androidx.lifecycle.Lifecycle |
45 | 53 | import androidx.lifecycle.lifecycleScope |
@@ -74,6 +82,7 @@ import kotlinx.coroutines.launch |
74 | 82 | import org.koin.android.ext.android.inject |
75 | 83 | import timber.log.Timber |
76 | 84 | import java.io.File |
| 85 | +import kotlin.math.min |
77 | 86 |
|
78 | 87 | fun Activity.showErrorInSnackbar(genericErrorMessageId: Int, throwable: Throwable?) = |
79 | 88 | throwable?.let { |
@@ -495,3 +504,41 @@ fun <T> FragmentActivity.collectLatestLifecycleFlow( |
495 | 504 | } |
496 | 505 | } |
497 | 506 | } |
| 507 | + |
| 508 | +fun Activity.adaptInfiniteEdges(root: View) { |
| 509 | + val typedValue = TypedValue() |
| 510 | + var actionBarHeight = 0 |
| 511 | + if (theme.resolveAttribute(android.R.attr.actionBarSize, typedValue, true)) { |
| 512 | + actionBarHeight = TypedValue.complexToDimensionPixelSize(typedValue.data, resources.displayMetrics) |
| 513 | + } |
| 514 | + |
| 515 | + val maxInsetPx = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 32f, resources.displayMetrics).toInt() |
| 516 | + val extraTopPx = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 12f, resources.displayMetrics).toInt() |
| 517 | + |
| 518 | + // Adapt toolbar for infinite edges |
| 519 | + findViewById<View>(R.id.toolbar).apply { |
| 520 | + ViewCompat.setOnApplyWindowInsetsListener(this) { _, insets -> |
| 521 | + val systemInsets = insets.getInsets(WindowInsetsCompat.Type.systemBars()) |
| 522 | + val usedInsetFinal = min(systemInsets.top, maxInsetPx) + extraTopPx |
| 523 | + updateLayoutParams { height = actionBarHeight + usedInsetFinal } |
| 524 | + insets |
| 525 | + } |
| 526 | + } |
| 527 | + |
| 528 | + // Adapt text in the toolbar |
| 529 | + findViewById<Toolbar>(R.id.standard_toolbar).apply { |
| 530 | + ViewCompat.setOnApplyWindowInsetsListener(this) { _, insets -> |
| 531 | + val systemInsets = insets.getInsets(WindowInsetsCompat.Type.systemBars()) |
| 532 | + val usedInsetFinal = min(systemInsets.top, maxInsetPx) + extraTopPx |
| 533 | + updateLayoutParams<ViewGroup.MarginLayoutParams> { updateMargins(top = usedInsetFinal) } |
| 534 | + insets |
| 535 | + } |
| 536 | + } |
| 537 | + |
| 538 | + // Adapt content for infinite edges |
| 539 | + ViewCompat.setOnApplyWindowInsetsListener(root) { _, insets -> |
| 540 | + val systemInsets = insets.getInsets(WindowInsetsCompat.Type.systemBars()) |
| 541 | + root.setPadding(systemInsets.left, root.paddingTop, systemInsets.right, systemInsets.bottom) |
| 542 | + insets |
| 543 | + } |
| 544 | +} |
0 commit comments