Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace Deprecated API Usages for EditImageActivity #12147

Closed
Closed
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ 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.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
Expand Down Expand Up @@ -80,7 +83,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 {
Expand All @@ -90,9 +94,25 @@ 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()
shiftLayout()
}

private fun shiftLayout() {
val navBarHeight: Float = resources.navBarHeight().toFloat()

@Suppress("MagicNumber")
val imageShiftValue = DisplayUtils.convertDpToPixel(60f, this).toFloat()

binding.cropImageView.shiftUp(imageShiftValue)
binding.editButtonsLayout.shiftUp(navBarHeight)
}

override fun onCropImageComplete(view: CropImageView, result: CropImageView.CropResult) {
Expand All @@ -105,17 +125,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?) {
Expand Down Expand Up @@ -147,6 +169,7 @@ class EditImageActivity :
finish()
true
}

else -> {
finish()
true
Expand Down Expand Up @@ -184,7 +207,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
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* 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
}
}
30 changes: 30 additions & 0 deletions app/src/main/java/com/nextcloud/utils/extensions/ViewExtensions.kt
Original file line number Diff line number Diff line change
@@ -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 <https://www.gnu.org/licenses/>.
*/

package com.nextcloud.utils.extensions

import android.view.View

fun View.shiftUp(value: Float) {
post {
translationY = -value
}
}
29 changes: 13 additions & 16 deletions app/src/main/res/layout/activity_edit_image.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@
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/>.
-->
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent"
android:background="@color/black">

Expand All @@ -31,32 +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" />

<com.canhub.cropper.CropImageView
android:id="@+id/cropImageView"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_margin="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/toolbar" />
android:layout_gravity="center"
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="0dp"/>

<LinearLayout
android:id="@+id/edit_buttons_layout"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:gravity="center_vertical"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:background="@drawable/rounded_rect"
android:backgroundTint="@color/grey_900"
android:elevation="4dp"
android:orientation="horizontal"
android:paddingLeft="8dp"
android:paddingRight="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">
android:paddingRight="8dp">

<ImageButton
android:id="@+id/rotate_left"
Expand Down Expand Up @@ -108,4 +105,4 @@
app:srcCompat="@drawable/outline_flip_24"
app:tint="@color/white" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</LinearLayout>
Loading