Skip to content
Merged
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
39 changes: 9 additions & 30 deletions app/src/main/java/com/nextcloud/utils/extensions/ViewExtensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,12 @@ import android.content.Context
import android.graphics.Outline
import android.util.TypedValue
import android.view.View
import android.view.ViewGroup
import android.view.ViewOutlineProvider
import androidx.coordinatorlayout.widget.CoordinatorLayout
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.core.view.updatePadding
import com.nextcloud.ui.behavior.OnScrollBehavior
import com.owncloud.android.lib.common.utils.Log_OC
import com.google.android.material.behavior.HideViewOnScrollBehavior

fun View?.setVisibleIf(condition: Boolean) {
if (this == null) return
Expand Down Expand Up @@ -60,18 +58,6 @@ fun View?.makeRounded(context: Context, cornerRadius: Float) {
}
}

fun View?.setMargins(left: Int, top: Int, right: Int, bottom: Int) {
if (this == null) {
return
}

if (layoutParams is ViewGroup.MarginLayoutParams) {
val param = layoutParams as ViewGroup.MarginLayoutParams
param.setMargins(left, top, right, bottom)
requestLayout()
}
}

fun createRoundedOutline(context: Context, cornerRadiusValue: Float): ViewOutlineProvider =
object : ViewOutlineProvider() {
override fun getOutline(view: View, outline: Outline) {
Expand All @@ -89,21 +75,14 @@ fun createRoundedOutline(context: Context, cornerRadiusValue: Float): ViewOutlin
}
}

@Suppress("UNCHECKED_CAST", "ReturnCount", "TooGenericExceptionCaught")
fun <T : View?> T.slideHideBottomBehavior(visible: Boolean) {
this ?: return
val params = layoutParams as? CoordinatorLayout.LayoutParams ?: return
val behavior = params.behavior as? OnScrollBehavior<T> ?: return
post {
try {
if (visible) {
behavior.slideIn(this)
} else {
behavior.slideOut(this)
}
} catch (e: Exception) {
Log_OC.e("slideHideBottomBehavior", e.message)
}
fun View?.slideHideBottomBehavior(visible: Boolean) {
val view = this ?: return
val params = view.layoutParams as? CoordinatorLayout.LayoutParams
if (params?.behavior !is HideViewOnScrollBehavior<*>) return

val behavior = HideViewOnScrollBehavior.from(view)
view.post {
if (visible) behavior.slideIn(view) else behavior.slideOut(view)
}
}

Expand Down
Loading