Revert "Use extensions"

This reverts commit 411a133e41.
This commit is contained in:
ZetaTom 2023-11-27 11:16:57 +01:00
parent c0db2b91d6
commit 25452ddf91
No known key found for this signature in database
GPG key ID: 3536EB6B4203D957
3 changed files with 27 additions and 83 deletions

View file

@ -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) {

View file

@ -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 <https://www.gnu.org/licenses/>.
*/
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)
}

View file

@ -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 <https://www.gnu.org/licenses/>.
*/
package com.nextcloud.utils.extensions
import android.view.View
fun View.shiftUp(value: Float) {
post {
translationY = -value
}
}