diff options
Diffstat (limited to 'app/src/main/java/fr/gouv/etalab/mastodon/asynctasks')
8 files changed, 70 insertions, 81 deletions
diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/ManagePollAsyncTask.java b/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/ManagePollAsyncTask.java index 209da409f..9df82ac9e 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/ManagePollAsyncTask.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/ManagePollAsyncTask.java @@ -58,7 +58,7 @@ public class ManagePollAsyncTask extends AsyncTask<Void, Void, Void> { if (type == type_s.SUBMIT){ poll = new API(contextReference.get()).submiteVote(status.getPoll().getId(),choices); }else if( type == type_s.REFRESH){ - poll = new API(contextReference.get()).getPoll(status.getPoll().getId()); + poll = new API(contextReference.get()).getPoll(status); } return null; } diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/PostActionAsyncTask.java b/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/PostActionAsyncTask.java index 22879a673..5e18f1389 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/PostActionAsyncTask.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/PostActionAsyncTask.java @@ -22,6 +22,7 @@ import java.util.List; 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.Entities.Results; @@ -139,9 +140,9 @@ public class PostActionAsyncTask extends AsyncTask<Void, Void, Void> { else uri = remoteStatus.getUrl(); } - Results search = api.search(uri); - if (search != null) { - List<fr.gouv.etalab.mastodon.client.Entities.Status> remoteStatuses = search.getStatuses(); + APIResponse search = api.search(uri); + if (search != null && search.getResults() != null) { + List<fr.gouv.etalab.mastodon.client.Entities.Status> remoteStatuses = search.getResults().getStatuses(); if (remoteStatuses != null && remoteStatuses.size() > 0) { fr.gouv.etalab.mastodon.client.Entities.Status statusTmp = remoteStatuses.get(0); this.targetedId = statusTmp.getId(); @@ -150,9 +151,9 @@ public class PostActionAsyncTask extends AsyncTask<Void, Void, Void> { } } else if (remoteAccount != null) { String searchString = remoteAccount.getAcct().contains("@") ? "@" + remoteAccount.getAcct() : "@" + remoteAccount.getAcct() + "@" + Helper.getLiveInstance(contextReference.get()); - Results search = api.search(searchString); - if (search != null) { - List<Account> accounts = search.getAccounts(); + APIResponse search = api.search(searchString); + if (search != null && search.getResults() != null) { + List<Account> accounts = search.getResults().getAccounts(); if (accounts != null && accounts.size() > 0) { Account accountTmp = accounts.get(0); this.targetedId = accountTmp.getId(); diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/RetrieveAccountsAsyncTask.java b/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/RetrieveAccountsAsyncTask.java index 690e2da46..b59ea270f 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/RetrieveAccountsAsyncTask.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/RetrieveAccountsAsyncTask.java @@ -48,7 +48,8 @@ public class RetrieveAccountsAsyncTask extends AsyncTask<Void, Void, Void> { FOLLOWERS, CHANNELS, REBLOGGED, - FAVOURITED + FAVOURITED, + SEARCH } public RetrieveAccountsAsyncTask(Context context, String instance, String name, OnRetrieveAccountsInterface onRetrieveAccountsInterface){ @@ -92,6 +93,10 @@ public class RetrieveAccountsAsyncTask extends AsyncTask<Void, Void, Void> { apiResponse = gnuapi.getRebloggedBy(targetedId, max_id); } break; + case SEARCH: + api = new API(this.contextReference.get()); + apiResponse = api.search2(targetedId, API.searchType.ACCOUNTS, max_id); + break; case FAVOURITED: if( MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.GNU && MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA){ assert api != null; diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/RetrieveFeedsAsyncTask.java b/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/RetrieveFeedsAsyncTask.java index 633d96c61..d3a117234 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/RetrieveFeedsAsyncTask.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/RetrieveFeedsAsyncTask.java @@ -76,6 +76,7 @@ public class RetrieveFeedsAsyncTask extends AsyncTask<Void, Void, Void> { REMOTE_INSTANCE, ART, NOTIFICATION, + SEARCH, PSUBSCRIPTIONS, POVERVIEW, @@ -260,6 +261,9 @@ public class RetrieveFeedsAsyncTask extends AsyncTask<Void, Void, Void> { case ONESTATUS: apiResponse = api.getStatusbyId(targetedID); break; + case SEARCH: + apiResponse = api.search2(tag, API.searchType.STATUSES, max_id); + break; case TAG: if( MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.GNU && MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA) { List<TagTimeline> tagTimelines = new SearchDAO(contextReference.get(), db).getTimelineInfo(tag); diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/RetrieveRemoteDataAsyncTask.java b/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/RetrieveRemoteDataAsyncTask.java index fcaf9a6ee..a6331385b 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/RetrieveRemoteDataAsyncTask.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/RetrieveRemoteDataAsyncTask.java @@ -18,6 +18,7 @@ import android.content.Context; import android.os.AsyncTask; import java.lang.ref.WeakReference; import fr.gouv.etalab.mastodon.client.API; +import fr.gouv.etalab.mastodon.client.APIResponse; import fr.gouv.etalab.mastodon.client.Entities.Results; import fr.gouv.etalab.mastodon.helper.Helper; import fr.gouv.etalab.mastodon.interfaces.OnRetrieveRemoteAccountInterface; @@ -53,7 +54,9 @@ public class RetrieveRemoteDataAsyncTask extends AsyncTask<Void, Void, Void> { @Override protected Void doInBackground(Void... params) { API api = new API(this.contextReference.get()); - results = api.search(this.url); + APIResponse apiResponse = api.search(this.url); + if( apiResponse.getResults() != null) + results = apiResponse.getResults(); return null; } diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/RetrieveSearchAsyncTask.java b/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/RetrieveSearchAsyncTask.java index e5b8a69f4..18fc85b56 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/RetrieveSearchAsyncTask.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/RetrieveSearchAsyncTask.java @@ -23,7 +23,7 @@ import java.util.List; import fr.gouv.etalab.mastodon.activities.MainActivity; import fr.gouv.etalab.mastodon.client.API; -import fr.gouv.etalab.mastodon.client.Entities.Error; +import fr.gouv.etalab.mastodon.client.APIResponse; import fr.gouv.etalab.mastodon.client.Entities.Results; import fr.gouv.etalab.mastodon.client.GNUAPI; import fr.gouv.etalab.mastodon.helper.Helper; @@ -40,11 +40,12 @@ import fr.gouv.etalab.mastodon.sqlite.TagsCacheDAO; public class RetrieveSearchAsyncTask extends AsyncTask<Void, Void, Void> { private String query; - private Results results; + private APIResponse apiResponse; private OnRetrieveSearchInterface listener; - private Error error; private WeakReference<Context> contextReference; private boolean tagsOnly = false; + private API.searchType type; + private String max_id; public RetrieveSearchAsyncTask(Context context, String query, OnRetrieveSearchInterface onRetrieveSearchInterface){ this.contextReference = new WeakReference<>(context); @@ -59,40 +60,52 @@ public class RetrieveSearchAsyncTask extends AsyncTask<Void, Void, Void> { this.tagsOnly = tagsOnly; } + public RetrieveSearchAsyncTask(Context context, String query, API.searchType searchType, String max_id, OnRetrieveSearchInterface onRetrieveSearchInterface){ + this.contextReference = new WeakReference<>(context); + this.query = query; + this.listener = onRetrieveSearchInterface; + this.type = searchType; + this.max_id = max_id; + } + @Override protected Void doInBackground(Void... params) { - if(MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA) { - API api = new API(this.contextReference.get()); - if (!tagsOnly) - results = api.search(query); - else { - //search tags only - results = api.search(query); - SQLiteDatabase db = Sqlite.getInstance(contextReference.get(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open(); - List<String> cachedTags = new TagsCacheDAO(contextReference.get(), db).getBy(query); - if (results != null && results.getHashtags() != null) { - //If cache contains matching tags - if (cachedTags != null) { - for (String apiTag : results.getHashtags()) { - //Cache doesn't contain the tags coming from the api (case insensitive) - if (!Helper.containsCaseInsensitive(apiTag, cachedTags)) { - cachedTags.add(apiTag); //It's added + if (this.type == null) { + if (MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA) { + API api = new API(this.contextReference.get()); + if (!tagsOnly) + apiResponse = api.search(query); + else { + //search tags only + apiResponse = api.search(query); + SQLiteDatabase db = Sqlite.getInstance(contextReference.get(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open(); + List<String> cachedTags = new TagsCacheDAO(contextReference.get(), db).getBy(query); + if (apiResponse != null && apiResponse.getResults() != null && apiResponse.getResults().getHashtags() != null) { + //If cache contains matching tags + if (cachedTags != null) { + for (String apiTag : apiResponse.getResults().getHashtags()) { + //Cache doesn't contain the tags coming from the api (case insensitive) + if (!Helper.containsCaseInsensitive(apiTag, cachedTags)) { + cachedTags.add(apiTag); //It's added + } } + apiResponse.getResults().setHashtags(cachedTags); + } + } else if (cachedTags != null) { + if (apiResponse != null && apiResponse.getResults() == null) { + apiResponse.setResults(new Results()); + apiResponse.getResults().setHashtags(cachedTags); } - results.setHashtags(cachedTags); } - } else if (cachedTags != null) { - if (results == null) - results = new Results(); - results.setHashtags(cachedTags); } + } else { + GNUAPI gnuapi = new GNUAPI(this.contextReference.get()); + apiResponse = gnuapi.search(query); } - error = api.getError(); - }else { - GNUAPI gnuapi = new GNUAPI(this.contextReference.get()); - results = gnuapi.search(query); - error = gnuapi.getError(); + }else{ + API api = new API(this.contextReference.get()); + apiResponse = api.search2(query, type, max_id); } return null; @@ -100,7 +113,7 @@ public class RetrieveSearchAsyncTask extends AsyncTask<Void, Void, Void> { @Override protected void onPostExecute(Void result) { - listener.onRetrieveSearch(results, error); + listener.onRetrieveSearch(apiResponse); } } diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/UpdateAccountInfoAsyncTask.java b/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/UpdateAccountInfoAsyncTask.java index 9a3745c09..b4e57ea0b 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/UpdateAccountInfoAsyncTask.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/UpdateAccountInfoAsyncTask.java @@ -24,13 +24,11 @@ import android.os.AsyncTask; import java.io.UnsupportedEncodingException; import java.lang.ref.WeakReference; import java.net.URLDecoder; -import java.util.HashMap; import fr.gouv.etalab.mastodon.activities.MainActivity; import fr.gouv.etalab.mastodon.client.API; import fr.gouv.etalab.mastodon.client.Entities.Account; import fr.gouv.etalab.mastodon.client.GNUAPI; -import fr.gouv.etalab.mastodon.client.HttpsConnection; import fr.gouv.etalab.mastodon.client.PeertubeAPI; import fr.gouv.etalab.mastodon.helper.Helper; import fr.gouv.etalab.mastodon.sqlite.AccountDAO; @@ -73,33 +71,18 @@ public class UpdateAccountInfoAsyncTask extends AsyncTask<Void, Void, Void> { account = new API(this.contextReference.get(), instance, null).verifyCredentials(); account.setSocial(account.getSocial()); }else if( social == SOCIAL.PEERTUBE) { - try { - account = new PeertubeAPI(this.contextReference.get(), instance, null).verifyCredentials(); - account.setSocial("PEERTUBE"); - }catch (HttpsConnection.HttpsConnectionException exception){ - if(exception.getStatusCode() == 401){ - HashMap<String, String> values = new PeertubeAPI(this.contextReference.get(), instance, null).refreshToken(client_id, client_secret, refresh_token); - if( values.get("access_token") != null) - this.token = values.get("access_token"); - if( values.get("refresh_token") != null) - this.refresh_token = values.get("refresh_token"); - } - } + account = new PeertubeAPI(this.contextReference.get(), instance, null).verifyCredentials(); + account.setSocial("PEERTUBE"); }else{ account = new GNUAPI(this.contextReference.get(), instance, null).verifyCredentials(); account.setSocial(account.getSocial()); } - if( account == null) - return null; try { //At the state the instance can be encoded instance = URLDecoder.decode(instance, "utf-8"); - } catch (UnsupportedEncodingException ignored) {ignored.printStackTrace();} + } catch (UnsupportedEncodingException ignored) {} SharedPreferences sharedpreferences = this.contextReference.get().getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); - if( token == null) { - token = sharedpreferences.getString(Helper.PREF_KEY_OAUTH_TOKEN, null); - } account.setToken(token); account.setClient_id(client_id); account.setClient_secret(client_secret); diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/UpdateAccountInfoByIDAsyncTask.java b/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/UpdateAccountInfoByIDAsyncTask.java index 4a3cddcdb..351be5752 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/UpdateAccountInfoByIDAsyncTask.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/UpdateAccountInfoByIDAsyncTask.java @@ -62,28 +62,8 @@ public class UpdateAccountInfoByIDAsyncTask extends AsyncTask<Void, Void, Void> if( social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA) account = new API(this.contextReference.get()).getAccount(userId); else if( social == UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE) { - - try { - account = new PeertubeAPI(this.contextReference.get()).verifyCredentials(); - account.setSocial("PEERTUBE"); - }catch (HttpsConnection.HttpsConnectionException exception){ - if(exception.getStatusCode() == 401){ - SQLiteDatabase db = Sqlite.getInstance(this.contextReference.get(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open(); - String instance = sharedpreferences.getString(Helper.PREF_INSTANCE, Helper.getLiveInstance(contextReference.get())); - account = new AccountDAO(contextReference.get(), db).getUniqAccount(userId, instance); - HashMap<String, String> values = new PeertubeAPI(this.contextReference.get()).refreshToken(account.getClient_id(), account.getClient_secret(), account.getRefresh_token()); - if( values != null) { - String newtoken = values.get("access_token"); - String refresh_token = values.get("refresh_token"); - if (newtoken != null) - account.setToken(newtoken); - if (refresh_token != null) - account.setRefresh_token(refresh_token); - new AccountDAO(this.contextReference.get(), db).updateAccount(account); - } - } - } - + account = new PeertubeAPI(this.contextReference.get()).verifyCredentials(); + account.setSocial("PEERTUBE"); }else if ( social == UpdateAccountInfoAsyncTask.SOCIAL.GNU || social == UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA){ account = new GNUAPI(this.contextReference.get()).verifyCredentials(); } |