flip between crop and default image view as necessary
This commit is contained in:
parent
f2151c1536
commit
04da0fc1cf
1 changed files with 50 additions and 15 deletions
|
@ -122,18 +122,7 @@ class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener
|
||||||
}
|
}
|
||||||
|
|
||||||
isCropIntent = intent.extras?.get(CROP) == "true"
|
isCropIntent = intent.extras?.get(CROP) == "true"
|
||||||
Glide.with(this)
|
loadDefaultImageView()
|
||||||
.asBitmap()
|
|
||||||
.load(uri)
|
|
||||||
.listener(object : RequestListener<Bitmap> {
|
|
||||||
override fun onLoadFailed(e: GlideException?, model: Any?, target: Target<Bitmap>?, isFirstResource: Boolean) = false
|
|
||||||
|
|
||||||
override fun onResourceReady(bitmap: Bitmap?, model: Any?, target: Target<Bitmap>?, dataSource: DataSource?, isFirstResource: Boolean): Boolean {
|
|
||||||
initialBitmap = bitmap
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}).into(default_image_view)
|
|
||||||
|
|
||||||
setupBottomActions()
|
setupBottomActions()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -156,15 +145,41 @@ class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener
|
||||||
|
|
||||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||||
when (item.itemId) {
|
when (item.itemId) {
|
||||||
R.id.save_as -> crop_image_view.getCroppedImageAsync()
|
R.id.save_as -> saveImage()
|
||||||
R.id.edit -> editWith()
|
R.id.edit -> editWith()
|
||||||
else -> return super.onOptionsItemSelected(item)
|
else -> return super.onOptionsItemSelected(item)
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun loadDefaultImageView() {
|
||||||
|
default_image_view.beVisible()
|
||||||
|
crop_image_view.beGone()
|
||||||
|
Glide.with(this)
|
||||||
|
.asBitmap()
|
||||||
|
.load(uri)
|
||||||
|
.listener(object : RequestListener<Bitmap> {
|
||||||
|
override fun onLoadFailed(e: GlideException?, model: Any?, target: Target<Bitmap>?, isFirstResource: Boolean) = false
|
||||||
|
|
||||||
|
override fun onResourceReady(bitmap: Bitmap?, model: Any?, target: Target<Bitmap>?, dataSource: DataSource?, isFirstResource: Boolean): Boolean {
|
||||||
|
val currentFilter = getFiltersAdapter()?.getCurrentFilter()
|
||||||
|
if (initialBitmap != null && currentFilter != null && currentFilter.filter.name != getString(R.string.none)) {
|
||||||
|
default_image_view.onGlobalLayout {
|
||||||
|
applyFilter(currentFilter)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
initialBitmap = bitmap
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}).into(default_image_view)
|
||||||
|
}
|
||||||
|
|
||||||
private fun loadCropImageView() {
|
private fun loadCropImageView() {
|
||||||
|
default_image_view.beGone()
|
||||||
crop_image_view.apply {
|
crop_image_view.apply {
|
||||||
|
beVisible()
|
||||||
setOnCropImageCompleteListener(this@EditActivity)
|
setOnCropImageCompleteListener(this@EditActivity)
|
||||||
setImageUriAsync(uri)
|
setImageUriAsync(uri)
|
||||||
guidelines = CropImageView.Guidelines.ON
|
guidelines = CropImageView.Guidelines.ON
|
||||||
|
@ -177,6 +192,16 @@ class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun saveImage() {
|
||||||
|
if (crop_image_view.isVisible()) {
|
||||||
|
crop_image_view.getCroppedImageAsync()
|
||||||
|
} else {
|
||||||
|
val currentFilter = getFiltersAdapter()?.getCurrentFilter()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun getFiltersAdapter() = bottom_actions_filter_list.adapter as? FiltersAdapter
|
||||||
|
|
||||||
private fun setupBottomActions() {
|
private fun setupBottomActions() {
|
||||||
setupPrimaryActionButtons()
|
setupPrimaryActionButtons()
|
||||||
setupCropRotateActionButtons()
|
setupCropRotateActionButtons()
|
||||||
|
@ -255,6 +280,12 @@ class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updatePrimaryActionButtons() {
|
private fun updatePrimaryActionButtons() {
|
||||||
|
if (crop_image_view.isGone() && currPrimaryAction == PRIMARY_ACTION_CROP_ROTATE) {
|
||||||
|
loadCropImageView()
|
||||||
|
} else if (default_image_view.isGone() && currPrimaryAction == PRIMARY_ACTION_FILTER) {
|
||||||
|
loadDefaultImageView()
|
||||||
|
}
|
||||||
|
|
||||||
arrayOf(bottom_primary_filter, bottom_primary_crop_rotate).forEach {
|
arrayOf(bottom_primary_filter, bottom_primary_crop_rotate).forEach {
|
||||||
it.applyColorFilter(Color.WHITE)
|
it.applyColorFilter(Color.WHITE)
|
||||||
}
|
}
|
||||||
|
@ -287,8 +318,7 @@ class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener
|
||||||
|
|
||||||
val filterItems = filterThumbnailsManager.processThumbs()
|
val filterItems = filterThumbnailsManager.processThumbs()
|
||||||
val adapter = FiltersAdapter(applicationContext, filterItems) {
|
val adapter = FiltersAdapter(applicationContext, filterItems) {
|
||||||
val newBitmap = Bitmap.createBitmap(initialBitmap)
|
applyFilter(it)
|
||||||
default_image_view.setImageBitmap(it.filter.processFilter(newBitmap))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bottom_actions_filter_list.adapter = adapter
|
bottom_actions_filter_list.adapter = adapter
|
||||||
|
@ -304,6 +334,11 @@ class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun applyFilter(filterItem: FilterItem) {
|
||||||
|
val newBitmap = Bitmap.createBitmap(initialBitmap)
|
||||||
|
default_image_view.setImageBitmap(filterItem.filter.processFilter(newBitmap))
|
||||||
|
}
|
||||||
|
|
||||||
private fun updateAspectRatio(aspectRatio: Int) {
|
private fun updateAspectRatio(aspectRatio: Int) {
|
||||||
currAspectRatio = aspectRatio
|
currAspectRatio = aspectRatio
|
||||||
updateAspectRatioButtons()
|
updateAspectRatioButtons()
|
||||||
|
|
Loading…
Reference in a new issue