diff --git a/app/src/main/java/emu/skyline/MainActivity.kt b/app/src/main/java/emu/skyline/MainActivity.kt index 73f2ce4c..96a2fe62 100644 --- a/app/src/main/java/emu/skyline/MainActivity.kt +++ b/app/src/main/java/emu/skyline/MainActivity.kt @@ -102,7 +102,7 @@ class MainActivity : AppCompatActivity(), View.OnClickListener, View.OnLongClick } thread(start = true) { - val snackbar = Snackbar.make(findViewById(android.R.id.content), getString(R.string.searching_roms), Snackbar.LENGTH_INDEFINITE) + val snackbar = Snackbar.make(coordinatorLayout, getString(R.string.searching_roms), Snackbar.LENGTH_INDEFINITE) runOnUiThread { snackbar.show() requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_LOCKED diff --git a/app/src/main/java/emu/skyline/views/CustomLinearLayout.kt b/app/src/main/java/emu/skyline/views/CustomLinearLayout.kt new file mode 100644 index 00000000..e6ad3fd6 --- /dev/null +++ b/app/src/main/java/emu/skyline/views/CustomLinearLayout.kt @@ -0,0 +1,42 @@ +/* + * SPDX-License-Identifier: MPL-2.0 + * Copyright © 2020 Skyline Team and Contributors (https://github.com/skyline-emu/) + */ + +package emu.skyline.views + +import android.content.Context +import android.util.AttributeSet +import android.view.View +import android.widget.LinearLayout +import androidx.coordinatorlayout.widget.CoordinatorLayout +import com.google.android.material.snackbar.Snackbar.SnackbarLayout + +/** + * Custom linear layout with support for [CoordinatorLayout] to move children, when [com.google.android.material.snackbar.Snackbar] shows up. + */ +class CustomLinearLayout : LinearLayout, CoordinatorLayout.AttachedBehavior { + + constructor(context : Context) : this(context, null) + constructor(context : Context, attrs : AttributeSet?) : this(context, attrs, 0) + constructor(context : Context, attrs : AttributeSet?, defStyleAttr : Int) : super(context, attrs, defStyleAttr) + + override fun getBehavior() : CoordinatorLayout.Behavior = MoveUpwardBehavior() + + /** + * Defines behaviour when [com.google.android.material.snackbar.Snackbar] is shown. + * Simply sets an offset to y translation to move children out of the way. + */ + class MoveUpwardBehavior : CoordinatorLayout.Behavior() { + override fun layoutDependsOn(parent : CoordinatorLayout, child : CustomLinearLayout, dependency : View) : Boolean = dependency is SnackbarLayout + + override fun onDependentViewChanged(parent : CoordinatorLayout, child : CustomLinearLayout, dependency : View) : Boolean { + child.translationY = (0f).coerceAtMost(dependency.translationY - dependency.height) + return true + } + + override fun onDependentViewRemoved(parent : CoordinatorLayout, child : CustomLinearLayout, dependency : View) { + child.translationY = 0f + } + } +} diff --git a/app/src/main/res/layout/main_activity.xml b/app/src/main/res/layout/main_activity.xml index c0ac5e9b..07a23e84 100644 --- a/app/src/main/res/layout/main_activity.xml +++ b/app/src/main/res/layout/main_activity.xml @@ -3,6 +3,7 @@ @@ -15,7 +16,7 @@ android:layout_height="match_parent" app:layout_behavior="@string/appbar_scrolling_view_behavior" /> - - +