Fix crashes

This commit is contained in:
tom79 2019-07-27 18:34:48 +02:00
parent 8ae5566054
commit c5a8adca51
4 changed files with 42 additions and 33 deletions

View File

@ -2574,7 +2574,7 @@ public class TootActivity extends BaseActivity implements UploadStatusDelegate,
int cwSize = toot_cw_content.getText().toString().trim().length();
int size = toot_content.getText().toString().trim().length() + cwSize;
if( split_toot && splitToot != null && (size >= split_toot_size) && stepSpliToot < splitToot.size()){
if( split_toot && splitToot != null && stepSpliToot < splitToot.size()){
String tootContent = splitToot.get(stepSpliToot);
stepSpliToot += 1;
Status toot = new Status();

View File

@ -19,7 +19,6 @@ import android.content.Intent;
import android.content.SharedPreferences;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.util.Log;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
@ -4789,7 +4788,6 @@ public class API {
status.setVisibility(resobj.get("visibility").toString());
}catch (Exception e){status.setVisibility("public"); e.printStackTrace();}
status.setUrl("https://" + instance + "/notes/" + resobj.get("id").toString());
Log.v(Helper.TAG,"ici: " + resobj);
//Retrieves attachments
if( resobj.has("media")) {
JSONArray arrayAttachement = resobj.getJSONArray("media");
@ -5642,7 +5640,6 @@ public class API {
private static Account parseMisskeyAccountResponse(Context context, String instance, JSONObject resobj){
Account account = new Account();
Log.v(Helper.TAG,"account: " + resobj);
try {
account.setId(resobj.get("id").toString());
account.setUsername(resobj.get("username").toString());
@ -5679,7 +5676,6 @@ public class API {
}
}
account.setEmojis(emojiList);
Log.v(Helper.TAG,"accountxx: " + account);
} catch (JSONException ignored) {ignored.printStackTrace();}
return account;
}

View File

@ -52,7 +52,6 @@ import android.text.method.LinkMovementMethod;
import android.text.style.ClickableSpan;
import android.text.style.ForegroundColorSpan;
import android.text.style.URLSpan;
import android.util.Log;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.MenuItem;
@ -519,7 +518,7 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
int cwSize = toot_cw_content.getText().toString().trim().length();
int size = toot_content.getText().toString().trim().length() + cwSize;
if( split_toot && splitToot != null && (size >= split_toot_size) && stepSpliToot < splitToot.size()){
if( split_toot && splitToot != null && stepSpliToot < splitToot.size()){
String tootContent = splitToot.get(stepSpliToot);
stepSpliToot += 1;
Status toot = new Status();

View File

@ -3429,55 +3429,69 @@ public class Helper {
*/
public static ArrayList<String> splitToots(String content, int maxChars){
String[] splitContent = content.split("\\s");
ArrayList<String> splitToot = new ArrayList<>();
StringBuilder tempContent = new StringBuilder(splitContent[0]);
ArrayList<String> mentions = new ArrayList<>();
Matcher matcher = mentionLongPattern.matcher(content);
while (matcher.find()) {
String mentionLong = matcher.group(1);
mentions.add(mentionLong);
}
matcher = mentionPattern.matcher(content);
matcher = mentionLongPattern.matcher(content);
while (matcher.find()) {
String mentionLong = matcher.group(1);
mentions.add(mentionLong);
if( !mentions.contains(mentionLong)) {
mentions.add(mentionLong);
}
}
matcher = mentionPattern.matcher(content);
while (matcher.find()) {
String mention = matcher.group(1);
if( !mentions.contains(mention)) {
mentions.add(mention);
}
}
StringBuilder mentionString = new StringBuilder();
for(String mention: mentions){
mentionString.append(mention).append(" ");
}
int mentionLength = mentionString.length();
int maxCharsMention = maxChars - mentionLength;
for(int i= 0 ; i < splitContent.length ; i++){
if (i < (splitContent.length - 1) && (countLength(tempContent.toString()) + countLength(splitContent[i + 1])) < (maxChars - 10)) {
tempContent.append(" ").append(splitContent[i + 1]);
int mentionLength = mentionString.length()+1;
int maxCharsPerMessage = (maxChars-10) - mentionLength;
int totalCurrent = 0;
ArrayList<String> reply = new ArrayList<>();
int index = 0;
for(int i= 0 ; i < splitContent.length ; i++) {
if ((totalCurrent + splitContent[i].length()+1) < maxCharsPerMessage) {
totalCurrent += (splitContent[i].length()+1);
} else {
splitToot.add(tempContent.toString());
if (i < (splitContent.length - 1)) {
if( maxCharsMention > 0){
maxChars = maxCharsMention;
tempContent = new StringBuilder(mentionString+splitContent[i + 1]);
}else{
tempContent = new StringBuilder(splitContent[i + 1]);
}
if (content.length() > totalCurrent && totalCurrent > 0) {
String tempContent = content.substring(0, (totalCurrent-1));
content = content.substring(totalCurrent);
reply.add(index, tempContent);
index++;
totalCurrent = 0;
}
}
}
int i=1;
ArrayList<String> reply = new ArrayList<>();
for(String newContent : splitToot){
if( splitToot.size() > 1 ) {
reply.add((i - 1), newContent + " - " + i + "/" + splitToot.size());
}else{
reply.add((i - 1), newContent);
if( totalCurrent > 0 ){
reply.add(index, content);
}
if( reply.size() > 1 ){
int i = 0;
for(String r: reply){
if( mentions.size() > 0 ){
reply.set(i, r + " " + mentionString + " - " + (i+1) + "/" + reply.size());
}else{
reply.set(i, r + " - " + (i+1) + "/" + reply.size());
}
i++;
}
i++;
}
return reply;
}
public static int countLength(String text){
if( text == null) {
return 0;