mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-11-01 15:23:54 +01:00
Merge 7df1c65654 into b9bb9bcf34
This commit is contained in:
commit
73d34ca827
3 changed files with 33 additions and 22 deletions
|
|
@ -31,9 +31,11 @@ import java.io.File
|
|||
*/
|
||||
class EditActivity : AppCompatActivity() {
|
||||
private var imageUri = ""
|
||||
private var imageRotation = 0
|
||||
private lateinit var vm: EditViewModel
|
||||
private val sourceExifAttributeList = mutableListOf<Pair<String, String?>>()
|
||||
private lateinit var binding: ActivityEditBinding
|
||||
private var totalRotation = 0
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
|
@ -42,6 +44,8 @@ class EditActivity : AppCompatActivity() {
|
|||
supportActionBar?.title = ""
|
||||
val intent = intent
|
||||
imageUri = intent.getStringExtra("image") ?: ""
|
||||
imageRotation = intent.getIntExtra("rotation",0)
|
||||
totalRotation = imageRotation
|
||||
vm = ViewModelProvider(this).get(EditViewModel::class.java)
|
||||
val sourceExif = imageUri.toUri().path?.let { ExifInterface(it) }
|
||||
val exifTags = arrayOf(
|
||||
|
|
@ -87,7 +91,7 @@ class EditActivity : AppCompatActivity() {
|
|||
private fun init() {
|
||||
binding.iv.adjustViewBounds = true
|
||||
binding.iv.scaleType = ImageView.ScaleType.MATRIX
|
||||
binding.iv.post(Runnable {
|
||||
binding.iv.post {
|
||||
val options = BitmapFactory.Options()
|
||||
options.inJustDecodeBounds = true
|
||||
BitmapFactory.decodeFile(imageUri, options)
|
||||
|
|
@ -103,6 +107,8 @@ class EditActivity : AppCompatActivity() {
|
|||
options.inJustDecodeBounds = false
|
||||
val scaledBitmap = BitmapFactory.decodeFile(imageUri, options)
|
||||
binding.iv.setImageBitmap(scaledBitmap)
|
||||
binding.iv.rotation = (imageRotation % 360).toFloat()
|
||||
imageRotation = 0
|
||||
// Update the ImageView with the scaled bitmap
|
||||
val scale = binding.iv.measuredWidth.toFloat() / scaledBitmap.width.toFloat()
|
||||
binding.iv.layoutParams.height = (scale * scaledBitmap.height).toInt()
|
||||
|
|
@ -112,12 +118,13 @@ class EditActivity : AppCompatActivity() {
|
|||
options.inJustDecodeBounds = false
|
||||
val bitmap = BitmapFactory.decodeFile(imageUri, options)
|
||||
binding.iv.setImageBitmap(bitmap)
|
||||
|
||||
binding.iv.rotation = (imageRotation % 360).toFloat()
|
||||
imageRotation = 0
|
||||
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()
|
||||
}
|
||||
|
|
@ -126,12 +133,10 @@ class EditActivity : AppCompatActivity() {
|
|||
}
|
||||
}
|
||||
|
||||
var imageRotation = 0
|
||||
|
||||
/**
|
||||
* Animates the height, rotation, and scale of an ImageView to provide a smooth
|
||||
* transition effect when rotating an image by 90 degrees.
|
||||
*
|
||||
* @param shouldRotate A boolean indicating whether the image should rotate by 90 degrees.
|
||||
* This function calculates the new height, rotation, and scale for the ImageView
|
||||
* based on the current image rotation angle and animates the changes using a
|
||||
* ValueAnimator. It also disables a rotate button during the animation to prevent
|
||||
|
|
@ -176,6 +181,8 @@ class EditActivity : AppCompatActivity() {
|
|||
|
||||
override fun onAnimationEnd(animation: Animator) {
|
||||
imageRotation = newRotation % 360
|
||||
val t1 = totalRotation % 360
|
||||
totalRotation = t1 + 90
|
||||
binding.rotateBtn.setEnabled(true)
|
||||
}
|
||||
|
||||
|
|
@ -233,7 +240,7 @@ class EditActivity : AppCompatActivity() {
|
|||
val file = filePath?.let { File(it) }
|
||||
|
||||
|
||||
val rotatedImage = file?.let { vm.rotateImage(imageRotation, it) }
|
||||
val rotatedImage = if(totalRotation == 360 || totalRotation == 0) file else file?.let { vm.rotateImage(totalRotation, it) }
|
||||
if (rotatedImage == null) {
|
||||
Toast.makeText(this, "Failed to rotate to image", Toast.LENGTH_LONG).show()
|
||||
}
|
||||
|
|
@ -244,6 +251,7 @@ class EditActivity : AppCompatActivity() {
|
|||
}
|
||||
val resultIntent = Intent()
|
||||
resultIntent.putExtra("editedImageFilePath", rotatedImage?.toUri()?.path ?: "Error");
|
||||
resultIntent.putExtra("editedImageRotation",totalRotation)
|
||||
setResult(RESULT_OK, resultIntent);
|
||||
finish();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -66,6 +66,11 @@ public class UploadMediaDetailFragment extends UploadBaseFragment implements
|
|||
|
||||
private int indexOfFragment;
|
||||
|
||||
/**
|
||||
* Stores the rotation angle of the image in degrees.
|
||||
*/
|
||||
private int rotation = 0;
|
||||
|
||||
/**
|
||||
* A key for applicationKvStore. By this key we can retrieve the location of last UploadItem ex.
|
||||
* 12.3433,54.78897 from applicationKvStore.
|
||||
|
|
@ -129,7 +134,7 @@ public class UploadMediaDetailFragment extends UploadBaseFragment implements
|
|||
private UploadItem editableUploadItem;
|
||||
|
||||
private BasicKvStore basicKvStore;
|
||||
|
||||
|
||||
private final String keyForShowingAlertDialog = "isNoNetworkAlertDialogShowing";
|
||||
|
||||
private UploadMediaDetailFragmentCallback callback;
|
||||
|
|
@ -183,18 +188,18 @@ public class UploadMediaDetailFragment extends UploadBaseFragment implements
|
|||
}
|
||||
|
||||
if(savedInstanceState!=null){
|
||||
if(uploadMediaDetailAdapter.getItems().size()==0 && callback != null){
|
||||
uploadMediaDetailAdapter.setItems(savedInstanceState.getParcelableArrayList(UPLOAD_MEDIA_DETAILS));
|
||||
presenter.setUploadMediaDetails(uploadMediaDetailAdapter.getItems(),
|
||||
indexOfFragment);
|
||||
}
|
||||
if(uploadMediaDetailAdapter.getItems().size()==0 && callback != null){
|
||||
uploadMediaDetailAdapter.setItems(savedInstanceState.getParcelableArrayList(UPLOAD_MEDIA_DETAILS));
|
||||
presenter.setUploadMediaDetails(uploadMediaDetailAdapter.getItems(),
|
||||
indexOfFragment);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
if(!presenter.getImageQuality(indexOfFragment, inAppPictureLocation, getActivity())) {
|
||||
startActivityWithFlags(
|
||||
getActivity(), MainActivity.class, Intent.FLAG_ACTIVITY_CLEAR_TOP,
|
||||
Intent.FLAG_ACTIVITY_SINGLE_TOP);
|
||||
getActivity(), MainActivity.class, Intent.FLAG_ACTIVITY_CLEAR_TOP,
|
||||
Intent.FLAG_ACTIVITY_SINGLE_TOP);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
}
|
||||
|
|
@ -223,7 +228,7 @@ public class UploadMediaDetailFragment extends UploadBaseFragment implements
|
|||
|
||||
// If the image EXIF data contains the location, show the map icon with a green tick
|
||||
if (inAppPictureLocation != null ||
|
||||
(uploadableFile != null && uploadableFile.hasLocation())) {
|
||||
(uploadableFile != null && uploadableFile.hasLocation())) {
|
||||
Drawable mapTick = getResources().getDrawable(R.drawable.ic_map_available_20dp);
|
||||
binding.locationImageView.setImageDrawable(mapTick);
|
||||
binding.locationTextView.setText(R.string.edit_location);
|
||||
|
|
@ -600,6 +605,7 @@ public class UploadMediaDetailFragment extends UploadBaseFragment implements
|
|||
editableUploadItem = uploadItem;
|
||||
Intent intent = new Intent(getContext(), EditActivity.class);
|
||||
intent.putExtra("image", uploadableFile.getFilePath().toString());
|
||||
intent.putExtra("rotation",rotation);
|
||||
startActivityForResult(intent, REQUEST_CODE_FOR_EDIT_ACTIVITY);
|
||||
}
|
||||
|
||||
|
|
@ -680,6 +686,7 @@ public class UploadMediaDetailFragment extends UploadBaseFragment implements
|
|||
}
|
||||
if (requestCode == REQUEST_CODE_FOR_EDIT_ACTIVITY && resultCode == RESULT_OK) {
|
||||
String result = data.getStringExtra("editedImageFilePath");
|
||||
rotation = data.getIntExtra("editedImageRotation",0);
|
||||
|
||||
if (Objects.equals(result, "Error")) {
|
||||
Timber.e("Error in rotating image");
|
||||
|
|
@ -903,4 +910,4 @@ public class UploadMediaDetailFragment extends UploadBaseFragment implements
|
|||
super.onDestroy();
|
||||
binding = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue