From fe17eae351c45bf55ece0496deaf7e52ad534df5 Mon Sep 17 00:00:00 2001 From: stom79 Date: Fri, 25 Jan 2019 16:54:48 +0100 Subject: [PATCH] Fix issue #755 --- .../mastodon/activities/BaseMainActivity.java | 4 ---- .../mastodon/activities/TootActivity.java | 21 +++++++++++++----- .../asynctasks/PostStatusAsyncTask.java | 22 +++++++++++++++---- app/src/main/res/values/strings.xml | 1 + 4 files changed, 34 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/activities/BaseMainActivity.java b/app/src/main/java/fr/gouv/etalab/mastodon/activities/BaseMainActivity.java index c8fa1a46c..2f0d545ac 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/activities/BaseMainActivity.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/activities/BaseMainActivity.java @@ -55,7 +55,6 @@ import android.support.v7.widget.Toolbar; import android.text.Editable; import android.text.InputFilter; import android.text.TextWatcher; -import android.util.Log; import android.util.Patterns; import android.util.SparseArray; import android.view.Gravity; @@ -2283,7 +2282,6 @@ public abstract class BaseMainActivity extends BaseActivity @Override public void onCompleted(String dbName) { - Log.v(Helper.TAG,"onCompleted"); Toasty.success(getApplicationContext(),getString(R.string.data_import_success_simple),Toast.LENGTH_LONG).show(); Intent changeAccount = new Intent(activity, MainActivity.class); changeAccount.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); @@ -2293,8 +2291,6 @@ public abstract class BaseMainActivity extends BaseActivity @Override public void onError(Exception e) { - Log.v(Helper.TAG,"onError"); - e.printStackTrace(); Toasty.error(getApplicationContext(),getString(R.string.data_import_error_simple),Toast.LENGTH_LONG).show(); } }); diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/activities/TootActivity.java b/app/src/main/java/fr/gouv/etalab/mastodon/activities/TootActivity.java index 6b4baefe8..d7176d4e9 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/activities/TootActivity.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/activities/TootActivity.java @@ -1786,10 +1786,14 @@ public class TootActivity extends BaseActivity implements OnPostActionInterface, toot_it.setEnabled(true); if( apiResponse.getError().getError().contains("422")){ showAToast(getString(R.string.toast_error_char_limit)); - }else { + return; + }else if( apiResponse.getError().getStatusCode() == -33){ + storeToot(false, true); + } else { showAToast(apiResponse.getError().getError()); + return; } - return; + } final SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); boolean split_toot = sharedpreferences.getBoolean(Helper.SET_AUTOMATICALLY_SPLIT_TOOTS, false); @@ -1836,10 +1840,15 @@ public class TootActivity extends BaseActivity implements OnPostActionInterface, isSensitive = false; toot_sensitive.setVisibility(View.GONE); currentToId = -1; - if( scheduledstatus == null && !isScheduled) - Toasty.success(TootActivity.this, getString(R.string.toot_sent), Toast.LENGTH_LONG).show(); - else - Toasty.success(TootActivity.this, getString(R.string.toot_scheduled), Toast.LENGTH_LONG).show(); + if(apiResponse.getError() == null) { + if (scheduledstatus == null && !isScheduled) + Toasty.success(TootActivity.this, getString(R.string.toot_sent), Toast.LENGTH_LONG).show(); + else + Toasty.success(TootActivity.this, getString(R.string.toot_scheduled), Toast.LENGTH_LONG).show(); + }else { + if(apiResponse.getError().getStatusCode() == -33) + Toasty.info(TootActivity.this, getString(R.string.toast_toot_saved_error), Toast.LENGTH_LONG).show(); + } toot_it.setEnabled(true); //It's a reply, so the user will be redirect to its answer if( tootReply != null){ diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/PostStatusAsyncTask.java b/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/PostStatusAsyncTask.java index 6bfbdf306..ce72d712f 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/PostStatusAsyncTask.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/PostStatusAsyncTask.java @@ -22,9 +22,11 @@ import java.lang.ref.WeakReference; import java.util.List; import java.util.regex.Matcher; +import fr.gouv.etalab.mastodon.R; import fr.gouv.etalab.mastodon.client.API; import fr.gouv.etalab.mastodon.client.APIResponse; import fr.gouv.etalab.mastodon.client.Entities.Account; +import fr.gouv.etalab.mastodon.client.Entities.Error; import fr.gouv.etalab.mastodon.helper.Helper; import fr.gouv.etalab.mastodon.interfaces.OnPostStatusActionInterface; import fr.gouv.etalab.mastodon.sqlite.Sqlite; @@ -54,10 +56,22 @@ public class PostStatusAsyncTask extends AsyncTask { @Override protected Void doInBackground(Void... params) { - if( account == null) - apiResponse = new API(this.contextReference.get()).postStatusAction(status); - else - apiResponse = new API(this.contextReference.get(), account.getInstance(), account.getToken()).postStatusAction(status); + + + boolean isconnected = Helper.isConnectedToInternet(contextReference.get(), Helper.getLiveInstance(contextReference.get())); + if( isconnected) { + if (account == null) { + apiResponse = new API(this.contextReference.get()).postStatusAction(status); + } else + apiResponse = new API(this.contextReference.get(), account.getInstance(), account.getToken()).postStatusAction(status); + }else { + apiResponse = new APIResponse(); + Error error = new Error(); + error.setError(contextReference.get().getString(R.string.no_internet)); + error.setStatusCode(-33); + apiResponse.setError(error); + } + return null; } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 540fe1b91..3f2f03ab7 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -862,6 +862,7 @@ Please, don\'t kill the app while processing. That can\'t be quite long. Add a public comment Send comment + There is no Internet connection. Your message has been stored in drafts.