mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-29 05:43:55 +01:00
Issue-5662-kotlinstyle (#5833)
* *.kt: bulk correction of formatting using ktlint --format * *.kt: replace wildcard imports and second stage auto format ktlint --format * QuizQuestionTest.kt: modified property names to camel case to meet ktlint standard * LevelControllerTest.kt: modified property names to camel case to meet ktlint standard * QuizActivityUnitTest.kt: modified property names to camel case to meet ktlint standard * MediaDetailFragmentUnitTests.kt: modified property names to camel case to meet ktlint standard * UploadWorker.kt: modified property names to camel case to meet ktlint standard * UploadClient.kt: modified property names to camel case to meet ktlint standard * BasePagingPresenter.kt: modified property names to camel case to meet ktlint standard * DescriptionEditActivity.kt: modified property names to camel case to meet ktlint standard * OnSwipeTouchListener.kt: modified property names to camel case to meet ktlint standard * MediaDetailFragmentUnitTests.kt: corrected excessive line length to meet ktlint standard * DepictedItem.kt: corrected property name format and catch format to for ktlint standard * UploadCategoryAdapter.kt: corrected class definition format to meet ktlint standard * CustomSelectorActivity.kt: reformatted function names to first letter lowercase to meet ktlint standard * MediaDetailFragmentUnitTests.kt: fix string literal indentation to meet ktlint standard * NotForUploadDao.kt: file renamed to match class name, new file NotForUploadStatusDao.kt * UploadedDao.kt: file renamed to match class name, new file UploadedStatusDao.kt * Urls.kt: fixed excessive line length for ktLint standard * Snak_partial.kt & Statement_partial.kt: refactored to remove underscores in class names to meet ktLint standard * *.kt: fixed consecutive KDOC error for ktLint * PageableBaseDataSourceTest.kt & UploadPresenterTest.kt: fixed excessive line lengths to meet ktLint standard * CheckboxTriStatesTest.kt: renamed file to match class name to meet ktLint standard * .kt: resolved backing-property-naming error in ktLint, made matching properties public, matched names and refactored * TestConnectionFactory.kt: fixed property naming to adhere to ktLint standard
This commit is contained in:
parent
950539c55c
commit
2d82a430c4
405 changed files with 11032 additions and 9137 deletions
|
|
@ -44,31 +44,32 @@ class EditActivity : AppCompatActivity() {
|
|||
imageUri = intent.getStringExtra("image") ?: ""
|
||||
vm = ViewModelProvider(this).get(EditViewModel::class.java)
|
||||
val sourceExif = imageUri.toUri().path?.let { ExifInterface(it) }
|
||||
val exifTags = arrayOf(
|
||||
ExifInterface.TAG_APERTURE,
|
||||
ExifInterface.TAG_DATETIME,
|
||||
ExifInterface.TAG_EXPOSURE_TIME,
|
||||
ExifInterface.TAG_FLASH,
|
||||
ExifInterface.TAG_FOCAL_LENGTH,
|
||||
ExifInterface.TAG_GPS_ALTITUDE,
|
||||
ExifInterface.TAG_GPS_ALTITUDE_REF,
|
||||
ExifInterface.TAG_GPS_DATESTAMP,
|
||||
ExifInterface.TAG_GPS_LATITUDE,
|
||||
ExifInterface.TAG_GPS_LATITUDE_REF,
|
||||
ExifInterface.TAG_GPS_LONGITUDE,
|
||||
ExifInterface.TAG_GPS_LONGITUDE_REF,
|
||||
ExifInterface.TAG_GPS_PROCESSING_METHOD,
|
||||
ExifInterface.TAG_GPS_TIMESTAMP,
|
||||
ExifInterface.TAG_IMAGE_LENGTH,
|
||||
ExifInterface.TAG_IMAGE_WIDTH,
|
||||
ExifInterface.TAG_ISO,
|
||||
ExifInterface.TAG_MAKE,
|
||||
ExifInterface.TAG_MODEL,
|
||||
ExifInterface.TAG_ORIENTATION,
|
||||
ExifInterface.TAG_WHITE_BALANCE,
|
||||
ExifInterface.WHITEBALANCE_AUTO,
|
||||
ExifInterface.WHITEBALANCE_MANUAL
|
||||
)
|
||||
val exifTags =
|
||||
arrayOf(
|
||||
ExifInterface.TAG_APERTURE,
|
||||
ExifInterface.TAG_DATETIME,
|
||||
ExifInterface.TAG_EXPOSURE_TIME,
|
||||
ExifInterface.TAG_FLASH,
|
||||
ExifInterface.TAG_FOCAL_LENGTH,
|
||||
ExifInterface.TAG_GPS_ALTITUDE,
|
||||
ExifInterface.TAG_GPS_ALTITUDE_REF,
|
||||
ExifInterface.TAG_GPS_DATESTAMP,
|
||||
ExifInterface.TAG_GPS_LATITUDE,
|
||||
ExifInterface.TAG_GPS_LATITUDE_REF,
|
||||
ExifInterface.TAG_GPS_LONGITUDE,
|
||||
ExifInterface.TAG_GPS_LONGITUDE_REF,
|
||||
ExifInterface.TAG_GPS_PROCESSING_METHOD,
|
||||
ExifInterface.TAG_GPS_TIMESTAMP,
|
||||
ExifInterface.TAG_IMAGE_LENGTH,
|
||||
ExifInterface.TAG_IMAGE_WIDTH,
|
||||
ExifInterface.TAG_ISO,
|
||||
ExifInterface.TAG_MAKE,
|
||||
ExifInterface.TAG_MODEL,
|
||||
ExifInterface.TAG_ORIENTATION,
|
||||
ExifInterface.TAG_WHITE_BALANCE,
|
||||
ExifInterface.WHITEBALANCE_AUTO,
|
||||
ExifInterface.WHITEBALANCE_MANUAL,
|
||||
)
|
||||
for (tag in exifTags) {
|
||||
val attribute = sourceExif?.getAttribute(tag.toString())
|
||||
sourceExifAttributeList.add(Pair(tag.toString(), attribute))
|
||||
|
|
@ -87,37 +88,38 @@ class EditActivity : AppCompatActivity() {
|
|||
private fun init() {
|
||||
binding.iv.adjustViewBounds = true
|
||||
binding.iv.scaleType = ImageView.ScaleType.MATRIX
|
||||
binding.iv.post(Runnable {
|
||||
val options = BitmapFactory.Options()
|
||||
options.inJustDecodeBounds = true
|
||||
BitmapFactory.decodeFile(imageUri, options)
|
||||
binding.iv.post(
|
||||
Runnable {
|
||||
val options = BitmapFactory.Options()
|
||||
options.inJustDecodeBounds = true
|
||||
BitmapFactory.decodeFile(imageUri, options)
|
||||
|
||||
val bitmapWidth = options.outWidth
|
||||
val bitmapHeight = options.outHeight
|
||||
val bitmapWidth = options.outWidth
|
||||
val bitmapHeight = options.outHeight
|
||||
|
||||
// Check if the bitmap dimensions exceed a certain threshold
|
||||
val maxBitmapSize = 2000 // Set your maximum size here
|
||||
if (bitmapWidth > maxBitmapSize || bitmapHeight > maxBitmapSize) {
|
||||
val scaleFactor = calculateScaleFactor(bitmapWidth, bitmapHeight, maxBitmapSize)
|
||||
options.inSampleSize = scaleFactor
|
||||
options.inJustDecodeBounds = false
|
||||
val scaledBitmap = BitmapFactory.decodeFile(imageUri, options)
|
||||
binding.iv.setImageBitmap(scaledBitmap)
|
||||
// Update the ImageView with the scaled bitmap
|
||||
val scale = binding.iv.measuredWidth.toFloat() / scaledBitmap.width.toFloat()
|
||||
binding.iv.layoutParams.height = (scale * scaledBitmap.height).toInt()
|
||||
binding.iv.imageMatrix = scaleMatrix(scale, scale)
|
||||
} else {
|
||||
// Check if the bitmap dimensions exceed a certain threshold
|
||||
val maxBitmapSize = 2000 // Set your maximum size here
|
||||
if (bitmapWidth > maxBitmapSize || bitmapHeight > maxBitmapSize) {
|
||||
val scaleFactor = calculateScaleFactor(bitmapWidth, bitmapHeight, maxBitmapSize)
|
||||
options.inSampleSize = scaleFactor
|
||||
options.inJustDecodeBounds = false
|
||||
val scaledBitmap = BitmapFactory.decodeFile(imageUri, options)
|
||||
binding.iv.setImageBitmap(scaledBitmap)
|
||||
// Update the ImageView with the scaled bitmap
|
||||
val scale = binding.iv.measuredWidth.toFloat() / scaledBitmap.width.toFloat()
|
||||
binding.iv.layoutParams.height = (scale * scaledBitmap.height).toInt()
|
||||
binding.iv.imageMatrix = scaleMatrix(scale, scale)
|
||||
} else {
|
||||
options.inJustDecodeBounds = false
|
||||
val bitmap = BitmapFactory.decodeFile(imageUri, options)
|
||||
binding.iv.setImageBitmap(bitmap)
|
||||
|
||||
options.inJustDecodeBounds = false
|
||||
val bitmap = BitmapFactory.decodeFile(imageUri, options)
|
||||
binding.iv.setImageBitmap(bitmap)
|
||||
|
||||
val scale = binding.iv.measuredWidth.toFloat() / bitmapWidth.toFloat()
|
||||
binding.iv.layoutParams.height = (scale * bitmapHeight).toInt()
|
||||
binding.iv.imageMatrix = scaleMatrix(scale, scale)
|
||||
}
|
||||
})
|
||||
val scale = binding.iv.measuredWidth.toFloat() / bitmapWidth.toFloat()
|
||||
binding.iv.layoutParams.height = (scale * bitmapHeight).toInt()
|
||||
binding.iv.imageMatrix = scaleMatrix(scale, scale)
|
||||
}
|
||||
},
|
||||
)
|
||||
binding.rotateBtn.setOnClickListener {
|
||||
animateImageHeight()
|
||||
}
|
||||
|
|
@ -138,8 +140,16 @@ class EditActivity : AppCompatActivity() {
|
|||
* further rotation actions.
|
||||
*/
|
||||
private fun animateImageHeight() {
|
||||
val drawableWidth: Float = binding.iv.getDrawable().getIntrinsicWidth().toFloat()
|
||||
val drawableHeight: Float = binding.iv.getDrawable().getIntrinsicHeight().toFloat()
|
||||
val drawableWidth: Float =
|
||||
binding.iv
|
||||
.getDrawable()
|
||||
.getIntrinsicWidth()
|
||||
.toFloat()
|
||||
val drawableHeight: Float =
|
||||
binding.iv
|
||||
.getDrawable()
|
||||
.getIntrinsicHeight()
|
||||
.toFloat()
|
||||
val viewWidth: Float = binding.iv.getMeasuredWidth().toFloat()
|
||||
val viewHeight: Float = binding.iv.getMeasuredHeight().toFloat()
|
||||
val rotation = imageRotation % 360
|
||||
|
|
@ -152,7 +162,6 @@ class EditActivity : AppCompatActivity() {
|
|||
Timber.d("Rotation $rotation")
|
||||
Timber.d("new Rotation $newRotation")
|
||||
|
||||
|
||||
if (rotation == 0 || rotation == 180) {
|
||||
imageScale = viewWidth / drawableWidth
|
||||
newImageScale = viewWidth / drawableHeight
|
||||
|
|
@ -169,23 +178,24 @@ class EditActivity : AppCompatActivity() {
|
|||
|
||||
animator.interpolator = AccelerateDecelerateInterpolator()
|
||||
|
||||
animator.addListener(object : AnimatorListener {
|
||||
override fun onAnimationStart(animation: Animator) {
|
||||
binding.rotateBtn.setEnabled(false)
|
||||
}
|
||||
animator.addListener(
|
||||
object : AnimatorListener {
|
||||
override fun onAnimationStart(animation: Animator) {
|
||||
binding.rotateBtn.setEnabled(false)
|
||||
}
|
||||
|
||||
override fun onAnimationEnd(animation: Animator) {
|
||||
imageRotation = newRotation % 360
|
||||
binding.rotateBtn.setEnabled(true)
|
||||
}
|
||||
override fun onAnimationEnd(animation: Animator) {
|
||||
imageRotation = newRotation % 360
|
||||
binding.rotateBtn.setEnabled(true)
|
||||
}
|
||||
|
||||
override fun onAnimationCancel(animation: Animator) {
|
||||
}
|
||||
override fun onAnimationCancel(animation: Animator) {
|
||||
}
|
||||
|
||||
override fun onAnimationRepeat(animation: Animator) {
|
||||
}
|
||||
|
||||
})
|
||||
override fun onAnimationRepeat(animation: Animator) {
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
animator.addUpdateListener { animation ->
|
||||
val animVal = animation.animatedValue as Float
|
||||
|
|
@ -195,20 +205,21 @@ class EditActivity : AppCompatActivity() {
|
|||
val animatedScale = complementaryAnimVal * imageScale + animVal * newImageScale
|
||||
val animatedRotation = complementaryAnimVal * rotation + animVal * newRotation
|
||||
binding.iv.getLayoutParams().height = animatedHeight
|
||||
val matrix: Matrix = rotationMatrix(
|
||||
animatedRotation,
|
||||
drawableWidth / 2,
|
||||
drawableHeight / 2
|
||||
)
|
||||
val matrix: Matrix =
|
||||
rotationMatrix(
|
||||
animatedRotation,
|
||||
drawableWidth / 2,
|
||||
drawableHeight / 2,
|
||||
)
|
||||
matrix.postScale(
|
||||
animatedScale,
|
||||
animatedScale,
|
||||
drawableWidth / 2,
|
||||
drawableHeight / 2
|
||||
drawableHeight / 2,
|
||||
)
|
||||
matrix.postTranslate(
|
||||
-(drawableWidth - binding.iv.getMeasuredWidth()) / 2,
|
||||
-(drawableHeight - binding.iv.getMeasuredHeight()) / 2
|
||||
-(drawableHeight - binding.iv.getMeasuredHeight()) / 2,
|
||||
)
|
||||
binding.iv.setImageMatrix(matrix)
|
||||
binding.iv.requestLayout()
|
||||
|
|
@ -228,11 +239,9 @@ class EditActivity : AppCompatActivity() {
|
|||
* as a result, and finishes the current activity.
|
||||
*/
|
||||
fun getRotatedImage() {
|
||||
|
||||
val filePath = imageUri.toUri().path
|
||||
val file = filePath?.let { File(it) }
|
||||
|
||||
|
||||
val rotatedImage = file?.let { vm.rotateImage(imageRotation, it) }
|
||||
if (rotatedImage == null) {
|
||||
Toast.makeText(this, "Failed to rotate to image", Toast.LENGTH_LONG).show()
|
||||
|
|
@ -243,9 +252,9 @@ class EditActivity : AppCompatActivity() {
|
|||
copyExifData(editedImageExif)
|
||||
}
|
||||
val resultIntent = Intent()
|
||||
resultIntent.putExtra("editedImageFilePath", rotatedImage?.toUri()?.path ?: "Error");
|
||||
setResult(RESULT_OK, resultIntent);
|
||||
finish();
|
||||
resultIntent.putExtra("editedImageFilePath", rotatedImage?.toUri()?.path ?: "Error")
|
||||
setResult(RESULT_OK, resultIntent)
|
||||
finish()
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -257,7 +266,6 @@ class EditActivity : AppCompatActivity() {
|
|||
* @param editedImageExif The ExifInterface object for the edited image.
|
||||
*/
|
||||
private fun copyExifData(editedImageExif: ExifInterface?) {
|
||||
|
||||
for (attr in sourceExifAttributeList) {
|
||||
Log.d("Tag is ${attr.first}", "Value is ${attr.second}")
|
||||
editedImageExif!!.setAttribute(attr.first, attr.second)
|
||||
|
|
@ -282,7 +290,11 @@ class EditActivity : AppCompatActivity() {
|
|||
* The scale factor ensures that the scaled bitmap will fit within the maximum size
|
||||
* while maintaining aspect ratio.
|
||||
*/
|
||||
private fun calculateScaleFactor(originalWidth: Int, originalHeight: Int, maxSize: Int): Int {
|
||||
private fun calculateScaleFactor(
|
||||
originalWidth: Int,
|
||||
originalHeight: Int,
|
||||
maxSize: Int,
|
||||
): Int {
|
||||
var scaleFactor = 1
|
||||
|
||||
if (originalWidth > maxSize || originalHeight > maxSize) {
|
||||
|
|
@ -295,7 +307,4 @@ class EditActivity : AppCompatActivity() {
|
|||
|
||||
return scaleFactor
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,8 +9,7 @@ import java.io.File
|
|||
* This ViewModel class is responsible for managing image editing operations, such as
|
||||
* rotating images. It utilizes a TransformImage implementation to perform image transformations.
|
||||
*/
|
||||
class EditViewModel() : ViewModel() {
|
||||
|
||||
class EditViewModel : ViewModel() {
|
||||
// Ideally should be injected using DI
|
||||
private val transformImage: TransformImage = TransformImageImpl()
|
||||
|
||||
|
|
@ -21,7 +20,8 @@ class EditViewModel() : ViewModel() {
|
|||
* @param imageFile The File representing the image to be rotated.
|
||||
* @return The rotated image File, or null if the rotation operation fails.
|
||||
*/
|
||||
fun rotateImage(degree: Int, imageFile: File): File? {
|
||||
return transformImage.rotateImage(imageFile, degree)
|
||||
}
|
||||
}
|
||||
fun rotateImage(
|
||||
degree: Int,
|
||||
imageFile: File,
|
||||
): File? = transformImage.rotateImage(imageFile, degree)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@ import java.io.File
|
|||
* implementations to provide specific functionality for tasks like rotating images.
|
||||
*/
|
||||
interface TransformImage {
|
||||
|
||||
/**
|
||||
* Rotates the specified image file by the given degree.
|
||||
*
|
||||
|
|
@ -17,5 +16,8 @@ interface TransformImage {
|
|||
* @param degree The degree by which to rotate the image.
|
||||
* @return The rotated image File, or null if the rotation operation fails.
|
||||
*/
|
||||
fun rotateImage(imageFile: File, degree : Int ):File?
|
||||
}
|
||||
fun rotateImage(
|
||||
imageFile: File,
|
||||
degree: Int,
|
||||
): File?
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,8 +15,7 @@ import java.io.FileOutputStream
|
|||
* function for rotating images by a specified degree using the LLJTran library. Right now it reads
|
||||
* the input image file, performs the rotation, and saves the rotated image to a new file.
|
||||
*/
|
||||
class TransformImageImpl() : TransformImage {
|
||||
|
||||
class TransformImageImpl : TransformImage {
|
||||
/**
|
||||
* Rotates the specified image file by the given degree.
|
||||
*
|
||||
|
|
@ -24,46 +23,50 @@ class TransformImageImpl() : TransformImage {
|
|||
* @param degree The degree by which to rotate the image.
|
||||
* @return The rotated image File, or null if the rotation operation fails.
|
||||
*/
|
||||
override fun rotateImage(imageFile: File, degree : Int): File? {
|
||||
|
||||
override fun rotateImage(
|
||||
imageFile: File,
|
||||
degree: Int,
|
||||
): File? {
|
||||
Timber.tag("Trying to rotate image").d("Starting")
|
||||
|
||||
val path = Environment.getExternalStoragePublicDirectory(
|
||||
Environment.DIRECTORY_DOWNLOADS
|
||||
)
|
||||
val path =
|
||||
Environment.getExternalStoragePublicDirectory(
|
||||
Environment.DIRECTORY_DOWNLOADS,
|
||||
)
|
||||
|
||||
val imagePath = System.currentTimeMillis()
|
||||
val file: File = File(path, "$imagePath.jpg")
|
||||
|
||||
val output = file
|
||||
|
||||
val rotated = try {
|
||||
val lljTran = LLJTran(imageFile)
|
||||
lljTran.read(
|
||||
LLJTran.READ_ALL,
|
||||
false,
|
||||
) // This could throw an LLJTranException. I am not catching it for now... Let's see.
|
||||
lljTran.transform(
|
||||
when(degree){
|
||||
90 -> LLJTran.ROT_90
|
||||
180 -> LLJTran.ROT_180
|
||||
270 -> LLJTran.ROT_270
|
||||
else -> {
|
||||
LLJTran.ROT_90
|
||||
}
|
||||
},
|
||||
LLJTran.OPT_DEFAULTS or LLJTran.OPT_XFORM_ORIENTATION
|
||||
)
|
||||
BufferedOutputStream(FileOutputStream(output)).use { writer ->
|
||||
lljTran.save(writer, LLJTran.OPT_WRITE_ALL )
|
||||
val rotated =
|
||||
try {
|
||||
val lljTran = LLJTran(imageFile)
|
||||
lljTran.read(
|
||||
LLJTran.READ_ALL,
|
||||
false,
|
||||
) // This could throw an LLJTranException. I am not catching it for now... Let's see.
|
||||
lljTran.transform(
|
||||
when (degree) {
|
||||
90 -> LLJTran.ROT_90
|
||||
180 -> LLJTran.ROT_180
|
||||
270 -> LLJTran.ROT_270
|
||||
else -> {
|
||||
LLJTran.ROT_90
|
||||
}
|
||||
},
|
||||
LLJTran.OPT_DEFAULTS or LLJTran.OPT_XFORM_ORIENTATION,
|
||||
)
|
||||
BufferedOutputStream(FileOutputStream(output)).use { writer ->
|
||||
lljTran.save(writer, LLJTran.OPT_WRITE_ALL)
|
||||
}
|
||||
lljTran.freeMemory()
|
||||
true
|
||||
} catch (e: LLJTranException) {
|
||||
Timber.tag("Error").d(e)
|
||||
return null
|
||||
false
|
||||
}
|
||||
lljTran.freeMemory()
|
||||
true
|
||||
} catch (e: LLJTranException) {
|
||||
Timber.tag("Error").d(e)
|
||||
return null
|
||||
false
|
||||
}
|
||||
|
||||
if (rotated) {
|
||||
Timber.tag("Done rotating image").d("Done")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue