Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion AnkiDroid/src/main/java/com/ichi2/anki/DeckPicker.kt
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import androidx.core.util.component2
import androidx.core.view.MenuItemCompat
import androidx.core.view.OnReceiveContentListener
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.core.view.WindowInsetsCompat.Type.displayCutout
import androidx.core.view.WindowInsetsCompat.Type.navigationBars
import androidx.core.view.WindowInsetsCompat.Type.systemBars
Expand Down Expand Up @@ -705,7 +706,9 @@ open class DeckPicker :
ViewCompat.setOnApplyWindowInsetsListener(studyoptionsView) { studyOptions, insets ->
val bars = insets.getInsets(systemBars() or displayCutout())
studyOptions.updatePadding(right = bars.right, bottom = bars.bottom)
insets
// insets are applied by padding. CONSUMED means hosted fragments don't apply them
// again (e.g. ScheduleRemindersFragment).
WindowInsetsCompat.CONSUMED
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,9 @@ class StudyOptionsActivity :
WindowInsetsCompat.Type.systemBars() or WindowInsetsCompat.Type.displayCutout(),
)
view.updatePadding(left = bars.left, right = bars.right, bottom = bars.bottom)
insets
// insets are applied by padding. CONSUMED means hosted fragments don't apply them
// again (e.g. ScheduleRemindersFragment).
WindowInsetsCompat.CONSUMED
}
}

Expand Down
35 changes: 35 additions & 0 deletions AnkiDroid/src/main/java/com/ichi2/anki/utils/Insets.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,14 @@
package com.ichi2.anki.utils

import android.view.View
import androidx.core.graphics.Insets
import androidx.core.view.RoundedCornerCompat
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.core.view.marginBottom
import androidx.core.view.marginLeft
import androidx.core.view.marginRight
import androidx.core.view.marginTop

/**
* The radius, in pixels, of the larger of the two bottom corner radii.
Expand Down Expand Up @@ -34,3 +40,32 @@ fun WindowInsetsCompat.bottomCornerClearance(view: View): Int {
// arc), so the content never dips into the corner.
return (bottomRoundedCornerRadius - endInset).coerceAtLeast(0)
}

/**
* A view's padding and margins from when [doOnApplyWindowInsets] was called.
*/
class InitialSpacing(
val padding: Insets,
val margins: Insets,
)

/**
* Sets a window insets listener which is also supplied with the view's [InitialSpacing].
*
* Inset handlers usually add an inset to a padding or margin from the layout file. Deriving the
* new value from the view compounds it when the insets are dispatched more than once, so [block]
* is given the values from when the listener was set and sets absolute values based on them.
*
* The insets are returned unconsumed, so sibling views also receive them.
*/
fun View.doOnApplyWindowInsets(block: (view: View, insets: WindowInsetsCompat, initial: InitialSpacing) -> Unit) {
val initial =
InitialSpacing(
padding = Insets.of(paddingLeft, paddingTop, paddingRight, paddingBottom),
margins = Insets.of(marginLeft, marginTop, marginRight, marginBottom),
)
ViewCompat.setOnApplyWindowInsetsListener(this) { view, insets ->
block(view, insets, initial)
insets
}
}
2 changes: 2 additions & 0 deletions AnkiDroid/src/main/java/com/ichi2/utils/ViewUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ value class Dp(
) {
// TODO: improve once we have context parameters
fun toPx(context: Context) = dp.dpToPx(context)

operator fun plus(other: Dp) = Dp(dp = dp + other.dp)
Comment thread
david-allison marked this conversation as resolved.
}

private fun Float.dpToPx(context: Context): Int = (this * context.resources.displayMetrics.density + 0.5f).toInt()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
app:title="Troubleshooting" />

<ScrollView
android:id="@+id/scroll_view"
android:layout_width="match_parent"
android:layout_height="match_parent">

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import com.ichi2.anki.RobolectricTest
import com.ichi2.anki.common.time.MockTime
import com.ichi2.anki.common.time.TimeManager
import com.ichi2.anki.libanki.EpochMilliseconds
import com.ichi2.anki.settings.Prefs
import kotlinx.serialization.InternalSerializationApi
import kotlinx.serialization.KSerializer
import kotlinx.serialization.builtins.MapSerializer
Expand Down Expand Up @@ -112,13 +113,18 @@ class ReviewRemindersDatabaseTest : RobolectricTest() {
@Before
override fun setUp() {
super.setUp()
ReviewRemindersDatabase.remindersSharedPrefs.edit { clear() }
clearRemindersState()
}

@After
override fun tearDown() {
super.tearDown()
clearRemindersState()
}

private fun clearRemindersState() {
ReviewRemindersDatabase.remindersSharedPrefs.edit { clear() }
Prefs.reviewReminderDeserializationErrors = ""
}

@Test
Expand Down
Loading
Loading