Fix some crashes

This commit is contained in:
tom79 2019-07-18 11:12:52 +02:00
parent 1b594568d2
commit 1e42bd353f
4 changed files with 57 additions and 40 deletions

View File

@ -1265,7 +1265,7 @@ public class TootActivity extends BaseActivity implements UploadStatusDelegate,
if( error != null){ if( error != null){
return; return;
} }
if( relationship.isBlocked_by() ){ if( relationship != null && relationship.isBlocked_by() ){
warning_message.setVisibility(View.VISIBLE); warning_message.setVisibility(View.VISIBLE);
} }
@ -2462,40 +2462,42 @@ public class TootActivity extends BaseActivity implements UploadStatusDelegate,
toot_content.setAdapter(emojisSearchAdapter); toot_content.setAdapter(emojisSearchAdapter);
final String oldContent = toot_content.getText().toString(); final String oldContent = toot_content.getText().toString();
String[] searchA = oldContent.substring(0,currentCursorPosition).split(":"); String[] searchA = oldContent.substring(0,currentCursorPosition).split(":");
final String search = searchA[searchA.length-1]; if( searchA.length > 0 ) {
toot_content.setOnItemClickListener(new AdapterView.OnItemClickListener() { final String search = searchA[searchA.length - 1];
@Override toot_content.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position, long id) { @Override
String shortcode = emojis.get(position).getShortcode(); public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String deltaSearch = ""; String shortcode = emojis.get(position).getShortcode();
int searchLength = 15; String deltaSearch = "";
if (currentCursorPosition < 15) { //Less than 15 characters are written before the cursor position int searchLength = 15;
searchLength = currentCursorPosition; if (currentCursorPosition < 15) { //Less than 15 characters are written before the cursor position
} searchLength = currentCursorPosition;
if( currentCursorPosition-searchLength > 0 && currentCursorPosition < oldContent.length() ) }
deltaSearch = oldContent.substring(currentCursorPosition-searchLength, currentCursorPosition); if (currentCursorPosition - searchLength > 0 && currentCursorPosition < oldContent.length())
else { deltaSearch = oldContent.substring(currentCursorPosition - searchLength, currentCursorPosition);
if( currentCursorPosition >= oldContent.length() ) else {
deltaSearch = oldContent.substring(currentCursorPosition-searchLength, oldContent.length()); if (currentCursorPosition >= oldContent.length())
} deltaSearch = oldContent.substring(currentCursorPosition - searchLength, oldContent.length());
}
if( !search.equals("")) if (!search.equals(""))
deltaSearch = deltaSearch.replace(":"+search,""); deltaSearch = deltaSearch.replace(":" + search, "");
String newContent = oldContent.substring(0,currentCursorPosition-searchLength); String newContent = oldContent.substring(0, currentCursorPosition - searchLength);
newContent += deltaSearch; newContent += deltaSearch;
newContent += ":" + shortcode + ": "; newContent += ":" + shortcode + ": ";
int newPosition = newContent.length(); int newPosition = newContent.length();
if( currentCursorPosition < oldContent.length() ) if (currentCursorPosition < oldContent.length())
newContent += oldContent.substring(currentCursorPosition, oldContent.length()-1); newContent += oldContent.substring(currentCursorPosition, oldContent.length() - 1);
toot_content.setText(newContent); toot_content.setText(newContent);
toot_space_left.setText(String.valueOf(countLength(toot_content, toot_cw_content))); toot_space_left.setText(String.valueOf(countLength(toot_content, toot_cw_content)));
toot_content.setSelection(newPosition); toot_content.setSelection(newPosition);
EmojisSearchAdapter emojisSearchAdapter = new EmojisSearchAdapter(TootActivity.this, new ArrayList<>()); EmojisSearchAdapter emojisSearchAdapter = new EmojisSearchAdapter(TootActivity.this, new ArrayList<>());
toot_content.setThreshold(1); toot_content.setThreshold(1);
toot_content.setAdapter(emojisSearchAdapter); toot_content.setAdapter(emojisSearchAdapter);
} }
}); });
}
} }
} }

View File

@ -114,10 +114,12 @@ public class UpdateAccountInfoAsyncTask extends AsyncTask<Void, Void, Void> {
@Override @Override
protected void onPostExecute(Void result) { protected void onPostExecute(Void result) {
Intent mainActivity = new Intent(this.contextReference.get(), MainActivity.class); if( this.contextReference.get() != null) {
mainActivity.putExtra(Helper.INTENT_ACTION, Helper.ADD_USER_INTENT); Intent mainActivity = new Intent(this.contextReference.get(), MainActivity.class);
this.contextReference.get().startActivity(mainActivity); mainActivity.putExtra(Helper.INTENT_ACTION, Helper.ADD_USER_INTENT);
((Activity) this.contextReference.get()).finish(); this.contextReference.get().startActivity(mainActivity);
((Activity) this.contextReference.get()).finish();
}
} }

View File

@ -22,6 +22,7 @@ import android.os.Bundle;
import androidx.localbroadcastmanager.content.LocalBroadcastManager; import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import androidx.room.util.StringUtil;
import com.google.gson.JsonArray; import com.google.gson.JsonArray;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
@ -297,6 +298,13 @@ public class API {
}else if( MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA) { }else if( MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA) {
url_action = Helper.instanceWithProtocol(this.context, this.instance) + "/api/pleroma" + endpoint; url_action = Helper.instanceWithProtocol(this.context, this.instance) + "/api/pleroma" + endpoint;
} }
if( url_action == null){
apiResponse = new APIResponse();
APIError = new Error();
APIError.setError(context.getString(R.string.toast_error));
apiResponse.setError(APIError);
return apiResponse;
}
try { try {
String response = new HttpsConnection(context, this.instance).get(url_action, 10, params, prefKeyOauthTokenT); String response = new HttpsConnection(context, this.instance).get(url_action, 10, params, prefKeyOauthTokenT);
if( MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA){ if( MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA){
@ -1619,8 +1627,13 @@ public class API {
String response = httpsConnection.get("https://"+remoteInstance+"/api/statuses/public_timeline.json", 10, params, prefKeyOauthTokenT); String response = httpsConnection.get("https://"+remoteInstance+"/api/statuses/public_timeline.json", 10, params, prefKeyOauthTokenT);
statuses = GNUAPI.parseStatuses(context, new JSONArray(response)); statuses = GNUAPI.parseStatuses(context, new JSONArray(response));
if( statuses.size() > 0) { if( statuses.size() > 0) {
apiResponse.setSince_id(String.valueOf(Long.parseLong(statuses.get(0).getId())+1)); if(statuses.get(0).getId() != null && statuses.get(0).getId().matches("-?\\d+(\\.\\d+)?")) {
apiResponse.setMax_id(String.valueOf(Long.parseLong(statuses.get(statuses.size() - 1).getId())-1)); apiResponse.setSince_id(String.valueOf(Long.parseLong(statuses.get(0).getId()) + 1));
apiResponse.setMax_id(String.valueOf(Long.parseLong(statuses.get(statuses.size() - 1).getId()) - 1));
}else{
apiResponse.setSince_id(statuses.get(0).getId());
apiResponse.setMax_id(statuses.get(statuses.size() - 1).getId());
}
} }
} catch (NoSuchAlgorithmException e) { } catch (NoSuchAlgorithmException e) {
e.printStackTrace(); e.printStackTrace();

View File

@ -602,7 +602,7 @@ public class Status implements Parcelable{
urlText += "|"+count; urlText += "|"+count;
count++; count++;
} }
content = content.replaceFirst(Pattern.quote(beforemodification), urlText); content = content.replaceFirst(Pattern.quote(beforemodification), Matcher.quoteReplacement(urlText));
} }
} }
spannableStringContent = new SpannableString(content); spannableStringContent = new SpannableString(content);