diff --git a/app/src/main/java/com/nextcloud/client/editimage/EditImageActivity.kt b/app/src/main/java/com/nextcloud/client/editimage/EditImageActivity.kt index 5836843059..161259c311 100644 --- a/app/src/main/java/com/nextcloud/client/editimage/EditImageActivity.kt +++ b/app/src/main/java/com/nextcloud/client/editimage/EditImageActivity.kt @@ -20,6 +20,7 @@ */ package com.nextcloud.client.editimage +import android.annotation.SuppressLint import android.graphics.Bitmap import android.net.Uri import android.os.Build @@ -33,9 +34,6 @@ import androidx.core.graphics.drawable.DrawableCompat import com.canhub.cropper.CropImageView import com.nextcloud.client.di.Injectable import com.nextcloud.utils.extensions.getParcelableArgument -import com.nextcloud.utils.extensions.hasNavBar -import com.nextcloud.utils.extensions.navBarHeight -import com.nextcloud.utils.extensions.shiftUp import com.owncloud.android.R import com.owncloud.android.databinding.ActivityEditImageBinding import com.owncloud.android.datamodel.OCFile @@ -104,19 +102,40 @@ class EditImageActivity : setupCropper() - if (resources.hasNavBar()) { + if (hasNavigationBar()) { shiftLayout() } } private fun shiftLayout() { - val navBarHeight: Float = resources.navBarHeight().toFloat() + val navBarHeight: Float = getNavigationBarHeight().toFloat() @Suppress("MagicNumber") - val imageShiftValue = DisplayUtils.convertDpToPixel(60f, this).toFloat() + val imageShiftValue = binding.editButtonsLayout.height * 1.4f - binding.cropImageView.shiftUp(imageShiftValue) - binding.editButtonsLayout.shiftUp(navBarHeight) + binding.cropImageView.post { + binding.cropImageView.translationY = -imageShiftValue + } + binding.editButtonsLayout.post { + binding.editButtonsLayout.translationY = -navBarHeight + } + } + + @SuppressLint("DiscouragedApi") + private fun hasNavigationBar(): Boolean { + val id = resources.getIdentifier("config_showNavigationBar", "bool", "android") + return id > 0 && resources.getBoolean(id) + } + + @SuppressLint("InternalInsetResource", "DiscouragedApi") + private fun getNavigationBarHeight(): Int { + val resourceId: Int = resources.getIdentifier("navigation_bar_height", "dimen", "android") + + return if (resourceId > 0) { + resources.getDimensionPixelSize(resourceId) + } else { + 0 + } } override fun onCropImageComplete(view: CropImageView, result: CropImageView.CropResult) { diff --git a/app/src/main/java/com/nextcloud/utils/extensions/ResourcesExtensions.kt b/app/src/main/java/com/nextcloud/utils/extensions/ResourcesExtensions.kt deleted file mode 100644 index bd2559a843..0000000000 --- a/app/src/main/java/com/nextcloud/utils/extensions/ResourcesExtensions.kt +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Nextcloud Android client application - * - * @author Alper Ozturk - * Copyright (C) 2023 Alper Ozturk - * Copyright (C) 2023 Nextcloud GmbH - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package com.nextcloud.utils.extensions - -import android.annotation.SuppressLint -import android.content.res.Resources - -@SuppressLint("DiscouragedApi", "InternalInsetResource") -fun Resources.navBarHeight(): Int { - val resourceId: Int = getIdentifier("navigation_bar_height", "dimen", "android") - - return if (resourceId > 0) { - getDimensionPixelSize(resourceId) - } else { - 0 - } -} - -/** - * This method only works in real device - */ -@SuppressLint("DiscouragedApi") -fun Resources.hasNavBar(): Boolean { - val id = getIdentifier("config_showNavigationBar", "bool", "android") - return id > 0 && getBoolean(id) -} diff --git a/app/src/main/java/com/nextcloud/utils/extensions/ViewExtensions.kt b/app/src/main/java/com/nextcloud/utils/extensions/ViewExtensions.kt deleted file mode 100644 index f189dada50..0000000000 --- a/app/src/main/java/com/nextcloud/utils/extensions/ViewExtensions.kt +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Nextcloud Android client application - * - * @author Alper Ozturk - * Copyright (C) 2023 Alper Ozturk - * Copyright (C) 2023 Nextcloud GmbH - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package com.nextcloud.utils.extensions - -import android.view.View - -fun View.shiftUp(value: Float) { - post { - translationY = -value - } -}