From 653eb1a1147147d95c0e0ab185f9f9c5a0fed5e4 Mon Sep 17 00:00:00 2001 From: alperozturk Date: Thu, 9 Nov 2023 16:29:53 +0100 Subject: [PATCH 1/4] Update api usages Signed-off-by: alperozturk --- .../client/editimage/EditImageActivity.kt | 46 +++++++++++++------ 1 file changed, 32 insertions(+), 14 deletions(-) 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 3ccadd3ba52d..b8e146960074 100644 --- a/app/src/main/java/com/nextcloud/client/editimage/EditImageActivity.kt +++ b/app/src/main/java/com/nextcloud/client/editimage/EditImageActivity.kt @@ -32,6 +32,7 @@ import androidx.core.content.ContextCompat 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.owncloud.android.R import com.owncloud.android.databinding.ActivityEditImageBinding import com.owncloud.android.datamodel.OCFile @@ -80,7 +81,8 @@ class EditImageActivity : binding = ActivityEditImageBinding.inflate(layoutInflater) setContentView(binding.root) - file = intent.extras?.getParcelable(EXTRA_FILE) ?: throw IllegalArgumentException("Missing file argument") + file = intent.extras?.getParcelableArgument(EXTRA_FILE, OCFile::class.java) + ?: throw IllegalArgumentException("Missing file argument") setSupportActionBar(binding.toolbar) supportActionBar?.apply { @@ -90,7 +92,12 @@ class EditImageActivity : window.statusBarColor = ContextCompat.getColor(this, R.color.black) window.navigationBarColor = getColor(R.color.black) - window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_FULLSCREEN + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { + window.setDecorFitsSystemWindows(false) + } else { + @Suppress("DEPRECATION") + window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_FULLSCREEN + } setupCropper() } @@ -105,17 +112,19 @@ class EditImageActivity : " " + getString(R.string.image_editor_file_edited_suffix) + resultUri?.substring(resultUri.lastIndexOf('.')) - FilesUploadHelper().uploadNewFiles( - user = storageManager.user, - localPaths = arrayOf(resultUri!!), - remotePaths = arrayOf(file.parentRemotePath + File.separator + newFileName), - createRemoteFolder = false, - createdBy = UploadFileOperation.CREATED_BY_USER, - requiresWifi = false, - requiresCharging = false, - nameCollisionPolicy = NameCollisionPolicy.RENAME, - localBehavior = FileUploader.LOCAL_BEHAVIOUR_DELETE - ) + resultUri?.let { + FilesUploadHelper().uploadNewFiles( + user = storageManager.user, + localPaths = arrayOf(it), + remotePaths = arrayOf(file.parentRemotePath + File.separator + newFileName), + createRemoteFolder = false, + createdBy = UploadFileOperation.CREATED_BY_USER, + requiresWifi = false, + requiresCharging = false, + nameCollisionPolicy = NameCollisionPolicy.RENAME, + localBehavior = FileUploader.LOCAL_BEHAVIOUR_DELETE + ) + } } override fun onSetImageUriComplete(view: CropImageView, uri: Uri, error: Exception?) { @@ -147,6 +156,7 @@ class EditImageActivity : finish() true } + else -> { finish() true @@ -184,7 +194,15 @@ class EditImageActivity : // determine output file format format = when (file.mimeType) { MimeType.PNG -> Bitmap.CompressFormat.PNG - MimeType.WEBP -> Bitmap.CompressFormat.WEBP + MimeType.WEBP -> { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { + Bitmap.CompressFormat.WEBP_LOSSLESS + } else { + @Suppress("DEPRECATION") + Bitmap.CompressFormat.WEBP + } + } + else -> Bitmap.CompressFormat.JPEG } } From 55d4496ef7f174d0b7d128355b4589d6625f01e9 Mon Sep 17 00:00:00 2001 From: alperozturk Date: Tue, 14 Nov 2023 09:55:07 +0100 Subject: [PATCH 2/4] Shift layout if nav bar exist Signed-off-by: alperozturk --- .../client/editimage/EditImageActivity.kt | 36 +++++++++++++++++++ .../main/res/layout/activity_edit_image.xml | 1 + 2 files changed, 37 insertions(+) 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 b8e146960074..161259c311ed 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 @@ -100,6 +101,41 @@ class EditImageActivity : } setupCropper() + + if (hasNavigationBar()) { + shiftLayout() + } + } + + private fun shiftLayout() { + val navBarHeight: Float = getNavigationBarHeight().toFloat() + + @Suppress("MagicNumber") + val imageShiftValue = binding.editButtonsLayout.height * 1.4f + + 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/res/layout/activity_edit_image.xml b/app/src/main/res/layout/activity_edit_image.xml index 931bb15d19be..c6d1078927f0 100644 --- a/app/src/main/res/layout/activity_edit_image.xml +++ b/app/src/main/res/layout/activity_edit_image.xml @@ -45,6 +45,7 @@ app:layout_constraintTop_toBottomOf="@+id/toolbar" /> Date: Tue, 14 Nov 2023 10:30:08 +0100 Subject: [PATCH 3/4] Use extensions Signed-off-by: alperozturk --- .../client/editimage/EditImageActivity.kt | 35 ++++----------- .../utils/extensions/ResourcesExtensions.kt | 45 +++++++++++++++++++ .../utils/extensions/ViewExtensions.kt | 30 +++++++++++++ 3 files changed, 83 insertions(+), 27 deletions(-) create mode 100644 app/src/main/java/com/nextcloud/utils/extensions/ResourcesExtensions.kt create mode 100644 app/src/main/java/com/nextcloud/utils/extensions/ViewExtensions.kt 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 161259c311ed..58368430595c 100644 --- a/app/src/main/java/com/nextcloud/client/editimage/EditImageActivity.kt +++ b/app/src/main/java/com/nextcloud/client/editimage/EditImageActivity.kt @@ -20,7 +20,6 @@ */ package com.nextcloud.client.editimage -import android.annotation.SuppressLint import android.graphics.Bitmap import android.net.Uri import android.os.Build @@ -34,6 +33,9 @@ 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 @@ -102,40 +104,19 @@ class EditImageActivity : setupCropper() - if (hasNavigationBar()) { + if (resources.hasNavBar()) { shiftLayout() } } private fun shiftLayout() { - val navBarHeight: Float = getNavigationBarHeight().toFloat() + val navBarHeight: Float = resources.navBarHeight().toFloat() @Suppress("MagicNumber") - val imageShiftValue = binding.editButtonsLayout.height * 1.4f + val imageShiftValue = DisplayUtils.convertDpToPixel(60f, this).toFloat() - 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 - } + binding.cropImageView.shiftUp(imageShiftValue) + binding.editButtonsLayout.shiftUp(navBarHeight) } 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 new file mode 100644 index 000000000000..bd2559a843ce --- /dev/null +++ b/app/src/main/java/com/nextcloud/utils/extensions/ResourcesExtensions.kt @@ -0,0 +1,45 @@ +/* + * 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 new file mode 100644 index 000000000000..f189dada5075 --- /dev/null +++ b/app/src/main/java/com/nextcloud/utils/extensions/ViewExtensions.kt @@ -0,0 +1,30 @@ +/* + * 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 + } +} From 677c80ee4b0e2cdac24e86209ff5604dd02af133 Mon Sep 17 00:00:00 2001 From: alperozturk Date: Tue, 21 Nov 2023 12:51:10 +0100 Subject: [PATCH 4/4] Remove optional navbarcheck Signed-off-by: alperozturk --- .../client/editimage/EditImageActivity.kt | 6 +--- .../utils/extensions/ResourcesExtensions.kt | 9 ------ .../main/res/layout/activity_edit_image.xml | 28 ++++++++----------- 3 files changed, 13 insertions(+), 30 deletions(-) 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 58368430595c..deb954a98bfe 100644 --- a/app/src/main/java/com/nextcloud/client/editimage/EditImageActivity.kt +++ b/app/src/main/java/com/nextcloud/client/editimage/EditImageActivity.kt @@ -33,7 +33,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 @@ -103,10 +102,7 @@ class EditImageActivity : } setupCropper() - - if (resources.hasNavBar()) { - shiftLayout() - } + shiftLayout() } private fun shiftLayout() { diff --git a/app/src/main/java/com/nextcloud/utils/extensions/ResourcesExtensions.kt b/app/src/main/java/com/nextcloud/utils/extensions/ResourcesExtensions.kt index bd2559a843ce..21b9f53f59c2 100644 --- a/app/src/main/java/com/nextcloud/utils/extensions/ResourcesExtensions.kt +++ b/app/src/main/java/com/nextcloud/utils/extensions/ResourcesExtensions.kt @@ -34,12 +34,3 @@ fun Resources.navBarHeight(): Int { 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/res/layout/activity_edit_image.xml b/app/src/main/res/layout/activity_edit_image.xml index c6d1078927f0..00c2071dc1d2 100644 --- a/app/src/main/res/layout/activity_edit_image.xml +++ b/app/src/main/res/layout/activity_edit_image.xml @@ -18,9 +18,11 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see . --> - @@ -31,33 +33,27 @@ android:background="@color/black" android:elevation="4dp" android:minHeight="?attr/actionBarSize" - android:theme="@style/Theme.ownCloud.Toolbar.AppWidgetContainer" - app:layout_constraintTop_toTopOf="parent" /> + android:theme="@style/Theme.ownCloud.Toolbar.AppWidgetContainer" /> + android:layout_gravity="center" + android:layout_weight="1" + android:layout_width="match_parent" + android:layout_height="0dp"/> + android:paddingRight="8dp"> - \ No newline at end of file +