-
-
Notifications
You must be signed in to change notification settings - Fork 388
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
Add UI for image-attachment "focus" #2620
Merged
Merged
Changes from 2 commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
f3bde24
Attempt-zero implementation of a "focus" feature for image attachment…
mcclure 613358e
Remove code duplication between 'update description' and 'update focus'
mcclure 7d86015
Fix ktlint/bitrise failures
mcclure c283a4c
Make updateMediaItem private
mcclure 7b3fd74
When focus is set on a post attachment the preview focuses correctly.…
mcclure 02b5e68
Replace use of PointF for Focus where focus is represented, fix ktlint
mcclure 84926d9
Substitute 'focus' for 'focus point' in strings
mcclure a439ec5
First attempt draw focus point. Only updates on initial load. Modeled…
mcclure 5e920da
Redraw focus after each tap
mcclure 09ab141
Dark curtain where focus isn't (now looks like mastosoc)
mcclure 8f08b1b
Correct ktlint for FocusDialog
mcclure d345e62
draft: switch to overlay for focus indicator
connyduck c89cdcf
Draw focus circle, but ImageView and FocusIndicatorView seem to share…
mcclure 3437fa8
Switch focus circle to path approach
mcclure 480b07b
Correctly scale, save and load focuses. Clamp to visible area. Focus …
mcclure 0e6c942
ktlint fixes and comments
mcclure f4e4f8b
Focus indicator drawing should use device-independent pixels
mcclure d929b98
Shrink focus window when it gets unattractively tall (no linting, mis…
mcclure dab6381
Correct max-height behavior for screens in landscape mode
mcclure af5c995
Focus attachment result is are flipped on x axis; fix this
mcclure 829c151
Correctly thread focus through on scheduled posts, redrafted posts, a…
mcclure cde5d5e
More focus ktlint fixes
mcclure a93369b
Fix specific case where a draft is given a focus, then deleted, then …
mcclure 400683d
Fix accidental file change in focus PR
mcclure a81ad1c
Remerge develop with focus PR
mcclure 829a0ed
ktLint fix
mcclure fc771f3
Fix property style warnings in focus
mcclure 33d5745
Fix remaining style warnings from focus PR
mcclure File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
110 changes: 110 additions & 0 deletions
110
app/src/main/java/com/keylesspalace/tusky/components/compose/dialog/FocusDialog.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
/* Copyright 2019 Tusky Contributors | ||
* | ||
* This file is a part of Tusky. | ||
* | ||
* This program is free software; you can redistribute it and/or modify it under the terms of the | ||
* GNU General Public License as published by the Free Software Foundation; either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* Tusky 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 General | ||
* Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License along with Tusky; if not, | ||
* see <http://www.gnu.org/licenses>. */ | ||
|
||
package com.keylesspalace.tusky.components.compose.dialog | ||
|
||
import android.app.Activity | ||
import android.content.DialogInterface | ||
import android.graphics.PointF | ||
import android.graphics.drawable.Drawable | ||
import android.net.Uri | ||
import android.text.InputFilter | ||
import android.text.InputType | ||
import android.util.Log // ANDI SHOULD NOT CHECK THIS LINE IN TO GIT | ||
import android.view.WindowManager | ||
import android.widget.EditText | ||
import android.widget.ImageView; | ||
import android.widget.LinearLayout | ||
import android.widget.Toast | ||
import androidx.appcompat.app.AlertDialog | ||
import androidx.lifecycle.LifecycleOwner | ||
import androidx.lifecycle.lifecycleScope | ||
import at.connyduck.sparkbutton.helpers.Utils | ||
import com.bumptech.glide.Glide | ||
import com.bumptech.glide.load.resource.bitmap.DownsampleStrategy | ||
import com.bumptech.glide.request.target.CustomTarget | ||
import com.bumptech.glide.request.transition.Transition | ||
import com.github.chrisbanes.photoview.OnPhotoTapListener | ||
import com.github.chrisbanes.photoview.PhotoView | ||
import com.keylesspalace.tusky.R | ||
import kotlinx.coroutines.launch | ||
|
||
fun <T> T.makeFocusDialog( | ||
existingFocus: PointF?, | ||
previewUri: Uri, | ||
onUpdateFocus: suspend (PointF) -> Boolean | ||
) where T : Activity, T : LifecycleOwner { | ||
var focus = existingFocus ?: PointF(0.0f, 0.0f) // Default to center | ||
|
||
val dialogLayout = LinearLayout(this) | ||
val padding = Utils.dpToPx(this, 8) | ||
dialogLayout.setPadding(padding, padding, padding, padding) | ||
|
||
dialogLayout.orientation = LinearLayout.VERTICAL | ||
val imageView = PhotoView(this).apply { | ||
maximumScale = 6f | ||
setOnPhotoTapListener(object : OnPhotoTapListener { | ||
override fun onPhotoTap(view: ImageView, x:Float, y:Float) { | ||
focus = PointF(x*2-1, 1-y*2) // PhotoView range is 0..1 Y-down but Mastodon API range is -1..1 Y-up | ||
} | ||
}) | ||
} | ||
|
||
val margin = Utils.dpToPx(this, 4) | ||
dialogLayout.addView(imageView) | ||
(imageView.layoutParams as LinearLayout.LayoutParams).weight = 1f | ||
imageView.layoutParams.height = 0 | ||
(imageView.layoutParams as LinearLayout.LayoutParams).setMargins(0, margin, 0, 0) | ||
|
||
val okListener = { dialog: DialogInterface, _: Int -> | ||
lifecycleScope.launch { | ||
if (!onUpdateFocus(focus)) { | ||
showFailedFocusMessage() | ||
} | ||
} | ||
dialog.dismiss() | ||
} | ||
|
||
val dialog = AlertDialog.Builder(this) | ||
.setView(dialogLayout) | ||
.setPositiveButton(android.R.string.ok, okListener) | ||
.setNegativeButton(android.R.string.cancel, null) | ||
.create() | ||
|
||
val window = dialog.window | ||
window?.setSoftInputMode( | ||
WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE | ||
) | ||
|
||
dialog.show() | ||
|
||
// Load the image and manually set it into the ImageView because it doesn't have a fixed size. | ||
Glide.with(this) | ||
.load(previewUri) | ||
.downsample(DownsampleStrategy.CENTER_INSIDE) | ||
.into(object : CustomTarget<Drawable>(4096, 4096) { | ||
override fun onLoadCleared(placeholder: Drawable?) { | ||
imageView.setImageDrawable(placeholder) | ||
} | ||
|
||
override fun onResourceReady(resource: Drawable, transition: Transition<in Drawable>?) { | ||
imageView.setImageDrawable(resource) | ||
} | ||
}) | ||
} | ||
|
||
private fun Activity.showFailedFocusMessage() { | ||
Toast.makeText(this, R.string.error_failed_set_focus, Toast.LENGTH_SHORT).show() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be private?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes