Improve split feature

This commit is contained in:
tom79 2019-05-28 15:54:02 +02:00
parent e1a371888f
commit 76a073da6b
2 changed files with 36 additions and 16 deletions

View File

@ -163,6 +163,7 @@ import static app.fedilab.android.helper.Helper.THEME_BLACK;
import static app.fedilab.android.helper.Helper.THEME_DARK;
import static app.fedilab.android.helper.Helper.THEME_LIGHT;
import static app.fedilab.android.helper.Helper.changeDrawableColor;
import static app.fedilab.android.helper.Helper.countWithEmoji;
/**
* Created by Thomas on 01/05/2017.
@ -534,8 +535,6 @@ public class TootActivity extends BaseActivity implements OnPostActionInterface,
attachments = new ArrayList<>();
int charsInCw = 0;
int charsInToot = 0;
if (!sharedUri.isEmpty()) {
uploadSharedImage(sharedUri);
@ -1539,7 +1538,7 @@ public class TootActivity extends BaseActivity implements OnPostActionInterface,
String tootContent;
if( toot_cw_content.getText() != null && toot_cw_content.getText().toString().trim().length() > 0 )
split_toot_size -= toot_cw_content.getText().toString().trim().length();
if( MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA || !split_toot || (toot_content.getText().toString().trim().length() < split_toot_size)){
if( MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA || !split_toot || (countLength() < split_toot_size)){
tootContent = toot_content.getText().toString().trim();
}else{
splitToot = Helper.splitToots(toot_content.getText().toString().trim(), split_toot_size);
@ -2119,7 +2118,7 @@ public class TootActivity extends BaseActivity implements OnPostActionInterface,
if (currentCursorPosition < oldContent.length() )
newContent += oldContent.substring(currentCursorPosition, oldContent.length());
toot_content.setText(newContent);
toot_space_left.setText(countLength());
toot_space_left.setText(String.valueOf(countLength()));
toot_content.setSelection(newPosition);
AccountsSearchAdapter accountsListAdapter = new AccountsSearchAdapter(TootActivity.this, new ArrayList<>());
toot_content.setThreshold(1);
@ -3042,14 +3041,4 @@ public class TootActivity extends BaseActivity implements OnPostActionInterface,
return cwLength + contentLength;
}
private int countWithEmoji(String text){
int emojiCount = 0;
for (int i = 0; i < text.length(); i++) {
int type = Character.getType(text.charAt(i));
if (type == Character.SURROGATE || type == Character.OTHER_SYMBOL) {
emojiCount++;
}
}
return emojiCount/2;
}
}

View File

@ -3288,7 +3288,7 @@ public class Helper {
* @return ArrayList<String> split toot
*/
public static ArrayList<String> splitToots(String content, int maxChars){
String[] splitContent = content.split("(\\.\\s){1}");
String[] splitContent = content.split("((\\.\\s)|(,\\s)|(;\\s)|(\\?\\s)|(!\\s)){1}");
ArrayList<String> splitToot = new ArrayList<>();
StringBuilder tempContent = new StringBuilder(splitContent[0]);
ArrayList<String> mentions = new ArrayList<>();
@ -3309,7 +3309,7 @@ public class Helper {
int mentionLength = mentionString.length();
int maxCharsMention = maxChars - mentionLength;
for(int i= 0 ; i < splitContent.length ; i++){
if (i < (splitContent.length - 1) && (tempContent.length() + splitContent[i + 1].length()) < (maxChars - 10)) {
if (i < (splitContent.length - 1) && (countLength(tempContent.toString()) + countLength(splitContent[i + 1])) < (maxChars - 10)) {
tempContent.append(". ").append(splitContent[i + 1]);
} else {
splitToot.add(tempContent.toString());
@ -3334,6 +3334,37 @@ public class Helper {
public static int countLength(String text){
if( text == null) {
return 0;
}
if( MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA ){
Matcher matcherALink = Patterns.WEB_URL.matcher(text);
while (matcherALink.find()){
int matchStart = matcherALink.start();
int matchEnd = matcherALink.end();
final String url = text.substring(matcherALink.start(1), matcherALink.end(1));
if( matchEnd <= text.length() && matchEnd >= matchStart){
if( url.length() > 23){
text = text.replaceFirst(url,"abcdefghijklmnopkrstuvw");
}
}
}
}
return text.length() - countWithEmoji(text);
}
public static int countWithEmoji(String text){
int emojiCount = 0;
for (int i = 0; i < text.length(); i++) {
int type = Character.getType(text.charAt(i));
if (type == Character.SURROGATE || type == Character.OTHER_SYMBOL) {
emojiCount++;
}
}
return emojiCount/2;
}
public static boolean filterToots(Context context, Status status, List<String> timedMute, RetrieveFeedsAsyncTask.Type type){
String filter;
if( status == null)