fix bug where sending toot is not possible despite it being below character limit
This commit is contained in:
parent
4fe6efe977
commit
e56386ea84
2 changed files with 26 additions and 13 deletions
|
@ -772,7 +772,7 @@ public final class ComposeActivity
|
||||||
setStatusVisibility(visibility);
|
setStatusVisibility(visibility);
|
||||||
}
|
}
|
||||||
|
|
||||||
int calculateRemainingCharacters() {
|
int calculateTextLength() {
|
||||||
int offset = 0;
|
int offset = 0;
|
||||||
URLSpan[] urlSpans = textEditor.getUrls();
|
URLSpan[] urlSpans = textEditor.getUrls();
|
||||||
if (urlSpans != null) {
|
if (urlSpans != null) {
|
||||||
|
@ -780,15 +780,15 @@ public final class ComposeActivity
|
||||||
offset += Math.max(0, span.getURL().length() - MAXIMUM_URL_LENGTH);
|
offset += Math.max(0, span.getURL().length() - MAXIMUM_URL_LENGTH);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
int remaining = maximumTootCharacters - textEditor.length() + offset;
|
int length = textEditor.length() - offset;
|
||||||
if (statusHideText) {
|
if (statusHideText) {
|
||||||
remaining -= contentWarningEditor.length();
|
length += contentWarningEditor.length();
|
||||||
}
|
}
|
||||||
return remaining;
|
return length;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateVisibleCharactersLeft() {
|
private void updateVisibleCharactersLeft() {
|
||||||
this.charactersLeft.setText(String.format(Locale.getDefault(), "%d", calculateRemainingCharacters()));
|
this.charactersLeft.setText(String.format(Locale.getDefault(), "%d", maximumTootCharacters - calculateTextLength()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onContentWarningChanged() {
|
private void onContentWarningChanged() {
|
||||||
|
@ -925,15 +925,13 @@ public final class ComposeActivity
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onReadySuccess(Status.Visibility visibility, boolean sensitive) {
|
private void onReadySuccess(Status.Visibility visibility, boolean sensitive) {
|
||||||
/* Validate the status meets the character limit. This has to be delayed until after all
|
/* Validate the status meets the character limit. */
|
||||||
* uploads finish because their links are added when the upload succeeds and that affects
|
|
||||||
* whether the limit is met or not. */
|
|
||||||
String contentText = textEditor.getText().toString();
|
String contentText = textEditor.getText().toString();
|
||||||
String spoilerText = "";
|
String spoilerText = "";
|
||||||
if (statusHideText) {
|
if (statusHideText) {
|
||||||
spoilerText = contentWarningEditor.getText().toString();
|
spoilerText = contentWarningEditor.getText().toString();
|
||||||
}
|
}
|
||||||
int characterCount = contentText.length() + spoilerText.length();
|
int characterCount = calculateTextLength();
|
||||||
if (characterCount <= 0 && mediaQueued.size()==0) {
|
if (characterCount <= 0 && mediaQueued.size()==0) {
|
||||||
textEditor.setError(getString(R.string.error_empty));
|
textEditor.setError(getString(R.string.error_empty));
|
||||||
enableButtons();
|
enableButtons();
|
||||||
|
|
|
@ -201,11 +201,27 @@ class ComposeActivityTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun whenTextContainsUrl_onlyEllipsizedURLIsCountedAgainstCharacterLimit() {
|
fun whenTextContainsNoUrl_everyCharacterIsCounted() {
|
||||||
|
val content = "This is test content please ignore thx "
|
||||||
|
insertSomeTextInContent(content)
|
||||||
|
Assert.assertEquals(activity.calculateTextLength(), content.length)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun whenTextContainsUrl_onlyEllipsizedURLIsCounted() {
|
||||||
val url = "https://www.google.dk/search?biw=1920&bih=990&tbm=isch&sa=1&ei=bmDrWuOoKMv6kwWOkIaoDQ&q=indiana+jones+i+hate+snakes+animated&oq=indiana+jones+i+hate+snakes+animated&gs_l=psy-ab.3...54174.55443.0.55553.9.7.0.0.0.0.255.333.1j0j1.2.0....0...1c.1.64.psy-ab..7.0.0....0.40G-kcDkC6A#imgdii=PSp15hQjN1JqvM:&imgrc=H0hyE2JW5wrpBM:"
|
val url = "https://www.google.dk/search?biw=1920&bih=990&tbm=isch&sa=1&ei=bmDrWuOoKMv6kwWOkIaoDQ&q=indiana+jones+i+hate+snakes+animated&oq=indiana+jones+i+hate+snakes+animated&gs_l=psy-ab.3...54174.55443.0.55553.9.7.0.0.0.0.255.333.1j0j1.2.0....0...1c.1.64.psy-ab..7.0.0....0.40G-kcDkC6A#imgdii=PSp15hQjN1JqvM:&imgrc=H0hyE2JW5wrpBM:"
|
||||||
val additionalContent = "Check out this @image #search result: "
|
val additionalContent = "Check out this @image #search result: "
|
||||||
insertSomeTextInContent(additionalContent + url)
|
insertSomeTextInContent(additionalContent + url)
|
||||||
Assert.assertEquals(activity.calculateRemainingCharacters(), activity.maximumTootCharacters - additionalContent.length - ComposeActivity.MAXIMUM_URL_LENGTH)
|
Assert.assertEquals(activity.calculateTextLength(), additionalContent.length + ComposeActivity.MAXIMUM_URL_LENGTH)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun whenTextContainsMultipleUrls_onlyEllipsizedURLIsCounted() {
|
||||||
|
val shortUrl = "https://tusky.app"
|
||||||
|
val url = "https://www.google.dk/search?biw=1920&bih=990&tbm=isch&sa=1&ei=bmDrWuOoKMv6kwWOkIaoDQ&q=indiana+jones+i+hate+snakes+animated&oq=indiana+jones+i+hate+snakes+animated&gs_l=psy-ab.3...54174.55443.0.55553.9.7.0.0.0.0.255.333.1j0j1.2.0....0...1c.1.64.psy-ab..7.0.0....0.40G-kcDkC6A#imgdii=PSp15hQjN1JqvM:&imgrc=H0hyE2JW5wrpBM:"
|
||||||
|
val additionalContent = " Check out this @image #search result: "
|
||||||
|
insertSomeTextInContent(shortUrl + additionalContent + url)
|
||||||
|
Assert.assertEquals(activity.calculateTextLength(), additionalContent.length + shortUrl.length + ComposeActivity.MAXIMUM_URL_LENGTH)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -213,8 +229,7 @@ class ComposeActivityTest {
|
||||||
val url = "https://www.google.dk/search?biw=1920&bih=990&tbm=isch&sa=1&ei=bmDrWuOoKMv6kwWOkIaoDQ&q=indiana+jones+i+hate+snakes+animated&oq=indiana+jones+i+hate+snakes+animated&gs_l=psy-ab.3...54174.55443.0.55553.9.7.0.0.0.0.255.333.1j0j1.2.0....0...1c.1.64.psy-ab..7.0.0....0.40G-kcDkC6A#imgdii=PSp15hQjN1JqvM:&imgrc=H0hyE2JW5wrpBM:"
|
val url = "https://www.google.dk/search?biw=1920&bih=990&tbm=isch&sa=1&ei=bmDrWuOoKMv6kwWOkIaoDQ&q=indiana+jones+i+hate+snakes+animated&oq=indiana+jones+i+hate+snakes+animated&gs_l=psy-ab.3...54174.55443.0.55553.9.7.0.0.0.0.255.333.1j0j1.2.0....0...1c.1.64.psy-ab..7.0.0....0.40G-kcDkC6A#imgdii=PSp15hQjN1JqvM:&imgrc=H0hyE2JW5wrpBM:"
|
||||||
val additionalContent = " Check out this @image #search result: "
|
val additionalContent = " Check out this @image #search result: "
|
||||||
insertSomeTextInContent(url + additionalContent + url)
|
insertSomeTextInContent(url + additionalContent + url)
|
||||||
Assert.assertEquals(activity.calculateRemainingCharacters(),
|
Assert.assertEquals(activity.calculateTextLength(), additionalContent.length + (ComposeActivity.MAXIMUM_URL_LENGTH * 2))
|
||||||
activity.maximumTootCharacters - additionalContent.length - (ComposeActivity.MAXIMUM_URL_LENGTH * 2))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun clickUp() {
|
private fun clickUp() {
|
||||||
|
|
Loading…
Reference in a new issue