diff options
Diffstat (limited to 'app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/PostStatusAsyncTask.java')
-rw-r--r-- | app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/PostStatusAsyncTask.java | 40 |
1 files changed, 36 insertions, 4 deletions
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..cabcb36ad 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,13 @@ 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.activities.MainActivity; 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.client.GNUAPI; import fr.gouv.etalab.mastodon.helper.Helper; import fr.gouv.etalab.mastodon.interfaces.OnPostStatusActionInterface; import fr.gouv.etalab.mastodon.sqlite.Sqlite; @@ -54,10 +58,38 @@ public class PostStatusAsyncTask extends AsyncTask<Void, Void, Void> { @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); + + if(MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.GNU || MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA){ + 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); + } + }else { + boolean isconnected = Helper.isConnectedToInternet(contextReference.get(), Helper.getLiveInstance(contextReference.get())); + if( isconnected) { + if (account == null) { + apiResponse = new GNUAPI(this.contextReference.get()).postStatusAction(status); + } else + apiResponse = new GNUAPI(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; } |