Improves API response with header
This commit is contained in:
parent
9d66499883
commit
6b9ccc110c
|
@ -29,8 +29,8 @@ import android.widget.TextView;
|
|||
import java.util.List;
|
||||
|
||||
import fr.gouv.etalab.mastodon.asynctasks.RetrieveDeveloperAccountsAsyncTask;
|
||||
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.OnRetrieveSearcAccountshInterface;
|
||||
import mastodon.etalab.gouv.fr.mastodon.R;
|
||||
|
@ -103,8 +103,9 @@ public class AboutActivity extends AppCompatActivity implements OnRetrieveSearcA
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onRetrieveSearchAccounts(final List<Account> accounts, Error error) {
|
||||
public void onRetrieveSearchAccounts(APIResponse apiResponse) {
|
||||
about_developer.setEnabled(true);
|
||||
final List<Account> accounts = apiResponse.getAccounts();
|
||||
if( accounts != null && accounts.size() > 0 && accounts.get(0) != null) {
|
||||
about_developer.setOnClickListener(null);
|
||||
about_developer.setOnClickListener(new View.OnClickListener() {
|
||||
|
|
|
@ -21,7 +21,6 @@ import android.os.AsyncTask;
|
|||
import android.os.Bundle;
|
||||
import android.support.v4.widget.SwipeRefreshLayout;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.util.Log;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.AbsListView;
|
||||
|
@ -33,7 +32,7 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
|
||||
import fr.gouv.etalab.mastodon.asynctasks.RetrieveFeedsAsyncTask;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Error;
|
||||
import fr.gouv.etalab.mastodon.client.APIResponse;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Status;
|
||||
import fr.gouv.etalab.mastodon.drawers.StatusListAdapter;
|
||||
import fr.gouv.etalab.mastodon.helper.Helper;
|
||||
|
@ -139,17 +138,18 @@ public class HashTagActivity extends AppCompatActivity implements OnRetrieveFeed
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onRetrieveFeeds(List<Status> statuses, Error error) {
|
||||
public void onRetrieveFeeds(APIResponse apiResponse) {
|
||||
|
||||
mainLoader.setVisibility(View.GONE);
|
||||
nextElementLoader.setVisibility(View.GONE);
|
||||
if( error != null){
|
||||
if( apiResponse.getError() != null){
|
||||
final SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
boolean show_error_messages = sharedpreferences.getBoolean(Helper.SET_SHOW_ERROR_MESSAGES, true);
|
||||
if( show_error_messages)
|
||||
Toast.makeText(getApplicationContext(), error.getError(),Toast.LENGTH_LONG).show();
|
||||
Toast.makeText(getApplicationContext(), apiResponse.getError().getError(),Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
List<Status> statuses = apiResponse.getStatuses();
|
||||
if( firstLoad && (statuses == null || statuses.size() == 0))
|
||||
textviewNoAction.setVisibility(View.VISIBLE);
|
||||
else
|
||||
|
|
|
@ -14,22 +14,18 @@
|
|||
* see <http://www.gnu.org/licenses>. */
|
||||
package fr.gouv.etalab.mastodon.activities;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.graphics.Paint;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.support.design.widget.NavigationView;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.util.Log;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
|
|
|
@ -30,6 +30,7 @@ import java.util.List;
|
|||
|
||||
import fr.gouv.etalab.mastodon.asynctasks.RetrieveContextAsyncTask;
|
||||
import fr.gouv.etalab.mastodon.asynctasks.RetrieveFeedsAsyncTask;
|
||||
import fr.gouv.etalab.mastodon.client.APIResponse;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Context;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Error;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Status;
|
||||
|
@ -80,14 +81,15 @@ public class ShowConversationActivity extends AppCompatActivity implements OnRet
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onRetrieveFeeds(List<Status> statuses, Error error) {
|
||||
if( error != null){
|
||||
public void onRetrieveFeeds(APIResponse apiResponse) {
|
||||
if( apiResponse.getError() != null){
|
||||
final SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, android.content.Context.MODE_PRIVATE);
|
||||
boolean show_error_messages = sharedpreferences.getBoolean(Helper.SET_SHOW_ERROR_MESSAGES, true);
|
||||
if( show_error_messages)
|
||||
Toast.makeText(getApplicationContext(), error.getError(),Toast.LENGTH_LONG).show();
|
||||
Toast.makeText(getApplicationContext(), apiResponse.getError().getError(),Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
List<Status> statuses = apiResponse.getStatuses();
|
||||
if( statuses != null && statuses.size() > 0 ){
|
||||
initialStatus = statuses.get(0);
|
||||
new RetrieveContextAsyncTask(getApplicationContext(), initialStatus.getId(), ShowConversationActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
|
|
|
@ -61,6 +61,7 @@ import fr.gouv.etalab.mastodon.asynctasks.PostActionAsyncTask;
|
|||
import fr.gouv.etalab.mastodon.asynctasks.RetrieveSearchAccountsAsyncTask;
|
||||
import fr.gouv.etalab.mastodon.asynctasks.UploadActionAsyncTask;
|
||||
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.Attachment;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Error;
|
||||
|
@ -539,14 +540,15 @@ public class TootActivity extends AppCompatActivity implements OnRetrieveSearcAc
|
|||
|
||||
|
||||
@Override
|
||||
public void onRetrieveSearchAccounts(List<Account> accounts, Error error) {
|
||||
if( error != null){
|
||||
public void onRetrieveSearchAccounts(APIResponse apiResponse) {
|
||||
if( apiResponse.getError() != null){
|
||||
final SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
boolean show_error_messages = sharedpreferences.getBoolean(Helper.SET_SHOW_ERROR_MESSAGES, true);
|
||||
if( show_error_messages)
|
||||
Toast.makeText(getApplicationContext(), error.getError(),Toast.LENGTH_LONG).show();
|
||||
Toast.makeText(getApplicationContext(), apiResponse.getError().getError(),Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
List<Account> accounts = apiResponse.getAccounts();
|
||||
if( accounts != null && accounts.size() > 0){
|
||||
AccountsSearchAdapter accountsListAdapter = new AccountsSearchAdapter(TootActivity.this, accounts);
|
||||
toot_lv_accounts.setAdapter(accountsListAdapter);
|
||||
|
|
|
@ -16,11 +16,8 @@ package fr.gouv.etalab.mastodon.asynctasks;
|
|||
|
||||
import android.content.Context;
|
||||
import android.os.AsyncTask;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import fr.gouv.etalab.mastodon.client.API;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Account;
|
||||
import fr.gouv.etalab.mastodon.client.APIResponse;
|
||||
import fr.gouv.etalab.mastodon.interfaces.OnRetrieveAccountsInterface;
|
||||
|
||||
|
||||
|
@ -33,11 +30,10 @@ public class RetrieveAccountsAsyncTask extends AsyncTask<Void, Void, Void> {
|
|||
|
||||
private Context context;
|
||||
private Type action;
|
||||
private List<Account> accounts;
|
||||
private APIResponse apiResponse;
|
||||
private String max_id;
|
||||
private OnRetrieveAccountsInterface listener;
|
||||
private String targetedId;
|
||||
private API api;
|
||||
|
||||
public enum Type{
|
||||
BLOCKED,
|
||||
|
@ -64,19 +60,19 @@ public class RetrieveAccountsAsyncTask extends AsyncTask<Void, Void, Void> {
|
|||
@Override
|
||||
protected Void doInBackground(Void... params) {
|
||||
|
||||
api = new API(context);
|
||||
API api = new API(context);
|
||||
switch (action){
|
||||
case BLOCKED:
|
||||
accounts = api.getBlocks(max_id);
|
||||
apiResponse = api.getBlocks(max_id);
|
||||
break;
|
||||
case MUTED:
|
||||
accounts = api.getMuted(max_id);
|
||||
apiResponse = api.getMuted(max_id);
|
||||
break;
|
||||
case FOLLOWING:
|
||||
accounts = api.getFollowing(targetedId, max_id);
|
||||
apiResponse = api.getFollowing(targetedId, max_id);
|
||||
break;
|
||||
case FOLLOWERS:
|
||||
accounts = api.getFollowers(targetedId, max_id);
|
||||
apiResponse = api.getFollowers(targetedId, max_id);
|
||||
break;
|
||||
}
|
||||
return null;
|
||||
|
@ -84,7 +80,7 @@ public class RetrieveAccountsAsyncTask extends AsyncTask<Void, Void, Void> {
|
|||
|
||||
@Override
|
||||
protected void onPostExecute(Void result) {
|
||||
listener.onRetrieveAccounts(accounts, api.getError());
|
||||
listener.onRetrieveAccounts(apiResponse);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -16,9 +16,8 @@ package fr.gouv.etalab.mastodon.asynctasks;
|
|||
|
||||
import android.content.Context;
|
||||
import android.os.AsyncTask;
|
||||
import java.util.List;
|
||||
import fr.gouv.etalab.mastodon.client.API;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Account;
|
||||
import fr.gouv.etalab.mastodon.client.APIResponse;
|
||||
import fr.gouv.etalab.mastodon.interfaces.OnRetrieveSearcAccountshInterface;
|
||||
|
||||
|
||||
|
@ -30,7 +29,7 @@ import fr.gouv.etalab.mastodon.interfaces.OnRetrieveSearcAccountshInterface;
|
|||
public class RetrieveDeveloperAccountsAsyncTask extends AsyncTask<Void, Void, Void> {
|
||||
|
||||
private Context context;
|
||||
private List<Account> accounts;
|
||||
private APIResponse apiResponse;
|
||||
private OnRetrieveSearcAccountshInterface listener;
|
||||
private API api;
|
||||
|
||||
|
@ -42,12 +41,12 @@ public class RetrieveDeveloperAccountsAsyncTask extends AsyncTask<Void, Void, Vo
|
|||
@Override
|
||||
protected Void doInBackground(Void... params) {
|
||||
api = new API(context);
|
||||
accounts = api.searchDeveloper();
|
||||
apiResponse = api.searchDeveloper();
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
protected void onPostExecute(Void result) {
|
||||
listener.onRetrieveSearchAccounts(accounts, api.getError());
|
||||
listener.onRetrieveSearchAccounts(apiResponse);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -16,12 +16,8 @@ package fr.gouv.etalab.mastodon.asynctasks;
|
|||
|
||||
import android.content.Context;
|
||||
import android.os.AsyncTask;
|
||||
import android.util.Log;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import fr.gouv.etalab.mastodon.client.API;
|
||||
import fr.gouv.etalab.mastodon.helper.Helper;
|
||||
import fr.gouv.etalab.mastodon.client.APIResponse;
|
||||
import fr.gouv.etalab.mastodon.interfaces.OnRetrieveFeedsInterface;
|
||||
|
||||
|
||||
|
@ -34,13 +30,11 @@ public class RetrieveFeedsAsyncTask extends AsyncTask<Void, Void, Void> {
|
|||
|
||||
private Context context;
|
||||
private Type action;
|
||||
private List<fr.gouv.etalab.mastodon.client.Entities.Status> statuses;
|
||||
private APIResponse apiResponse;
|
||||
private String max_id;
|
||||
private OnRetrieveFeedsInterface listener;
|
||||
private String targetedID;
|
||||
private fr.gouv.etalab.mastodon.client.Entities.Status status;
|
||||
private String tag;
|
||||
private API api;
|
||||
|
||||
public enum Type{
|
||||
HOME,
|
||||
|
@ -79,28 +73,28 @@ public class RetrieveFeedsAsyncTask extends AsyncTask<Void, Void, Void> {
|
|||
@Override
|
||||
protected Void doInBackground(Void... params) {
|
||||
|
||||
api = new API(context);
|
||||
API api = new API(context);
|
||||
switch (action){
|
||||
case HOME:
|
||||
statuses = api.getHomeTimeline(max_id);
|
||||
apiResponse = api.getHomeTimeline(max_id);
|
||||
break;
|
||||
case LOCAL:
|
||||
statuses = api.getPublicTimeline(true, max_id);
|
||||
apiResponse = api.getPublicTimeline(true, max_id);
|
||||
break;
|
||||
case PUBLIC:
|
||||
statuses = api.getPublicTimeline(false, max_id);
|
||||
apiResponse = api.getPublicTimeline(false, max_id);
|
||||
break;
|
||||
case FAVOURITES:
|
||||
statuses = api.getFavourites(max_id);
|
||||
apiResponse = api.getFavourites(max_id);
|
||||
break;
|
||||
case USER:
|
||||
statuses = api.getStatus(targetedID, max_id);
|
||||
apiResponse = api.getStatus(targetedID, max_id);
|
||||
break;
|
||||
case ONESTATUS:
|
||||
statuses = api.getStatusbyId(targetedID);
|
||||
apiResponse = api.getStatusbyId(targetedID);
|
||||
break;
|
||||
case TAG:
|
||||
statuses = api.getPublicTimelineTag(tag, false, max_id);
|
||||
apiResponse = api.getPublicTimelineTag(tag, false, max_id);
|
||||
break;
|
||||
case HASHTAG:
|
||||
break;
|
||||
|
@ -110,7 +104,7 @@ public class RetrieveFeedsAsyncTask extends AsyncTask<Void, Void, Void> {
|
|||
|
||||
@Override
|
||||
protected void onPostExecute(Void result) {
|
||||
listener.onRetrieveFeeds(statuses, api.getError());
|
||||
listener.onRetrieveFeeds(apiResponse);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -16,10 +16,8 @@ package fr.gouv.etalab.mastodon.asynctasks;
|
|||
|
||||
import android.content.Context;
|
||||
import android.os.AsyncTask;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import fr.gouv.etalab.mastodon.client.API;
|
||||
import fr.gouv.etalab.mastodon.client.APIResponse;
|
||||
import fr.gouv.etalab.mastodon.interfaces.OnRetrieveHomeTimelineServiceInterface;
|
||||
|
||||
/**
|
||||
|
@ -30,13 +28,12 @@ import fr.gouv.etalab.mastodon.interfaces.OnRetrieveHomeTimelineServiceInterface
|
|||
public class RetrieveHomeTimelineServiceAsyncTask extends AsyncTask<Void, Void, Void> {
|
||||
|
||||
private Context context;
|
||||
private List<fr.gouv.etalab.mastodon.client.Entities.Status> statuses;
|
||||
private APIResponse apiResponse;
|
||||
private String since_id;
|
||||
private String acct, userId;
|
||||
private OnRetrieveHomeTimelineServiceInterface listener;
|
||||
private String instance;
|
||||
private String token;
|
||||
private API api;
|
||||
|
||||
public RetrieveHomeTimelineServiceAsyncTask(Context context, String instance, String token, String since_id, String acct, String userId, OnRetrieveHomeTimelineServiceInterface onRetrieveHomeTimelineServiceInterface){
|
||||
this.context = context;
|
||||
|
@ -50,14 +47,14 @@ public class RetrieveHomeTimelineServiceAsyncTask extends AsyncTask<Void, Void,
|
|||
|
||||
@Override
|
||||
protected Void doInBackground(Void... params) {
|
||||
api = new API(context, instance, token);
|
||||
statuses = api.getHomeTimelineSinceId(since_id);
|
||||
API api = new API(context, instance, token);
|
||||
apiResponse = api.getHomeTimelineSinceId(since_id);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Void result) {
|
||||
listener.onRetrieveHomeTimelineService(statuses, acct, userId, api.getError());
|
||||
listener.onRetrieveHomeTimelineService(apiResponse, acct, userId);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -16,13 +16,9 @@ package fr.gouv.etalab.mastodon.asynctasks;
|
|||
|
||||
import android.content.Context;
|
||||
import android.os.AsyncTask;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import fr.gouv.etalab.mastodon.client.API;
|
||||
import fr.gouv.etalab.mastodon.helper.Helper;
|
||||
import fr.gouv.etalab.mastodon.client.APIResponse;
|
||||
import fr.gouv.etalab.mastodon.interfaces.OnRetrieveNotificationsInterface;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Notification;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -33,13 +29,12 @@ import fr.gouv.etalab.mastodon.client.Entities.Notification;
|
|||
public class RetrieveNotificationsAsyncTask extends AsyncTask<Void, Void, Void> {
|
||||
|
||||
private Context context;
|
||||
private List<Notification> notifications;
|
||||
private APIResponse apiResponse;
|
||||
private String max_id;
|
||||
private String acct, userId;
|
||||
private OnRetrieveNotificationsInterface listener;
|
||||
private String instance;
|
||||
private String token;
|
||||
private API api;
|
||||
|
||||
|
||||
public RetrieveNotificationsAsyncTask(Context context, String instance, String token, String max_id, String acct, String userId, OnRetrieveNotificationsInterface onRetrieveNotificationsInterface){
|
||||
|
@ -55,17 +50,17 @@ public class RetrieveNotificationsAsyncTask extends AsyncTask<Void, Void, Void>
|
|||
@Override
|
||||
protected Void doInBackground(Void... params) {
|
||||
|
||||
api = new API(context, instance, token);
|
||||
API api = new API(context, instance, token);
|
||||
if( acct == null)
|
||||
notifications = api.getNotifications(max_id);
|
||||
apiResponse = api.getNotifications(max_id);
|
||||
else
|
||||
notifications = api.getNotificationsSince(max_id);
|
||||
apiResponse = api.getNotificationsSince(max_id);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Void result) {
|
||||
listener.onRetrieveNotifications(notifications, acct, userId, api.getError());
|
||||
listener.onRetrieveNotifications(apiResponse, acct, userId);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -16,11 +16,8 @@ package fr.gouv.etalab.mastodon.asynctasks;
|
|||
|
||||
import android.content.Context;
|
||||
import android.os.AsyncTask;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import fr.gouv.etalab.mastodon.client.API;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Account;
|
||||
import fr.gouv.etalab.mastodon.client.APIResponse;
|
||||
import fr.gouv.etalab.mastodon.interfaces.OnRetrieveSearcAccountshInterface;
|
||||
|
||||
|
||||
|
@ -33,9 +30,8 @@ public class RetrieveSearchAccountsAsyncTask extends AsyncTask<Void, Void, Void>
|
|||
|
||||
private Context context;
|
||||
private String query;
|
||||
private List<Account> accounts;
|
||||
private APIResponse apiResponse;
|
||||
private OnRetrieveSearcAccountshInterface listener;
|
||||
private API api;
|
||||
|
||||
public RetrieveSearchAccountsAsyncTask(Context context, String query, OnRetrieveSearcAccountshInterface onRetrieveSearcAccountshInterface){
|
||||
this.context = context;
|
||||
|
@ -46,14 +42,14 @@ public class RetrieveSearchAccountsAsyncTask extends AsyncTask<Void, Void, Void>
|
|||
|
||||
@Override
|
||||
protected Void doInBackground(Void... params) {
|
||||
api = new API(context);
|
||||
accounts = api.searchAccounts(query);
|
||||
API api = new API(context);
|
||||
apiResponse = api.searchAccounts(query);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Void result) {
|
||||
listener.onRetrieveSearchAccounts(accounts, api.getError());
|
||||
listener.onRetrieveSearchAccounts(apiResponse);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -20,8 +20,6 @@ import android.content.Intent;
|
|||
import android.content.SharedPreferences;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.os.AsyncTask;
|
||||
import android.util.Log;
|
||||
|
||||
import fr.gouv.etalab.mastodon.activities.MainActivity;
|
||||
import fr.gouv.etalab.mastodon.client.API;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Account;
|
||||
|
|
|
@ -35,7 +35,6 @@ public class UploadActionAsyncTask extends AsyncTask<Void, Void, Void> {
|
|||
private OnRetrieveAttachmentInterface listener;
|
||||
private Attachment attachment;
|
||||
private InputStream inputStream;
|
||||
private fr.gouv.etalab.mastodon.client.Entities.Status status;
|
||||
private API api;
|
||||
|
||||
public UploadActionAsyncTask(Context context, InputStream inputStream, OnRetrieveAttachmentInterface onRetrieveAttachmentInterface){
|
||||
|
|
|
@ -16,6 +16,7 @@ package fr.gouv.etalab.mastodon.client;
|
|||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.loopj.android.http.AsyncHttpResponseHandler;
|
||||
|
@ -35,6 +36,8 @@ import java.security.NoSuchAlgorithmException;
|
|||
import java.security.UnrecoverableKeyException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import cz.msebera.android.httpclient.Header;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.*;
|
||||
|
@ -70,7 +73,8 @@ public class API {
|
|||
private int actionCode;
|
||||
private String instance;
|
||||
private String prefKeyOauthTokenT;
|
||||
private Error errorApi = null;
|
||||
private APIResponse apiResponse;
|
||||
private Error APIError;
|
||||
|
||||
public enum StatusAction{
|
||||
FAVOURITE,
|
||||
|
@ -96,6 +100,8 @@ public class API {
|
|||
notificationPerPage = sharedpreferences.getInt(Helper.SET_NOTIFICATIONS_PER_PAGE, 40);
|
||||
this.instance = Helper.getLiveInstance(context);
|
||||
this.prefKeyOauthTokenT = sharedpreferences.getString(Helper.PREF_KEY_OAUTH_TOKEN, null);
|
||||
apiResponse = new APIResponse();
|
||||
APIError = null;
|
||||
}
|
||||
|
||||
public API(Context context, String instance, String token) {
|
||||
|
@ -113,7 +119,8 @@ public class API {
|
|||
this.prefKeyOauthTokenT = token;
|
||||
else
|
||||
this.prefKeyOauthTokenT = sharedpreferences.getString(Helper.PREF_KEY_OAUTH_TOKEN, null);
|
||||
|
||||
apiResponse = new APIResponse();
|
||||
APIError = null;
|
||||
}
|
||||
|
||||
|
||||
|
@ -211,7 +218,7 @@ public class API {
|
|||
* @param accountId String Id of the account
|
||||
* @return List<Status>
|
||||
*/
|
||||
public List<Status> getStatus(String accountId) {
|
||||
public APIResponse getStatus(String accountId) {
|
||||
return getStatus(accountId, false, false, null, null, tootPerPage);
|
||||
}
|
||||
|
||||
|
@ -222,7 +229,7 @@ public class API {
|
|||
* @param max_id String id max
|
||||
* @return List<Status>
|
||||
*/
|
||||
public List<Status> getStatus(String accountId, String max_id) {
|
||||
public APIResponse getStatus(String accountId, String max_id) {
|
||||
return getStatus(accountId, false, false, max_id, null, tootPerPage);
|
||||
}
|
||||
|
||||
|
@ -237,7 +244,7 @@ public class API {
|
|||
* @param limit int limit - max value 40
|
||||
* @return List<Status>
|
||||
*/
|
||||
private List<Status> getStatus(String accountId, boolean onlyMedia,
|
||||
private APIResponse getStatus(String accountId, boolean onlyMedia,
|
||||
boolean exclude_replies, String max_id, String since_id, int limit) {
|
||||
|
||||
RequestParams params = new RequestParams();
|
||||
|
@ -258,9 +265,13 @@ public class API {
|
|||
public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
|
||||
Status status = parseStatuses(response);
|
||||
statuses.add(status);
|
||||
apiResponse.setSince_id(findSinceId(headers));
|
||||
apiResponse.setMax_id(findMaxId(headers));
|
||||
}
|
||||
@Override
|
||||
public void onSuccess(int statusCode, Header[] headers, JSONArray response) {
|
||||
apiResponse.setSince_id(findSinceId(headers));
|
||||
apiResponse.setMax_id(findMaxId(headers));
|
||||
statuses = parseStatuses(response);
|
||||
|
||||
}
|
||||
|
@ -269,7 +280,8 @@ public class API {
|
|||
setError(statusCode, error);
|
||||
}
|
||||
});
|
||||
return statuses;
|
||||
apiResponse.setStatuses(statuses);
|
||||
return apiResponse;
|
||||
}
|
||||
|
||||
|
||||
|
@ -279,16 +291,20 @@ public class API {
|
|||
* @param statusId String Id of the status
|
||||
* @return List<Status>
|
||||
*/
|
||||
public List<Status> getStatusbyId(String statusId) {
|
||||
public APIResponse getStatusbyId(String statusId) {
|
||||
statuses = new ArrayList<>();
|
||||
get(String.format("/statuses/%s", statusId), null, new JsonHttpResponseHandler() {
|
||||
@Override
|
||||
public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
|
||||
apiResponse.setSince_id(findSinceId(headers));
|
||||
apiResponse.setMax_id(findMaxId(headers));
|
||||
Status status = parseStatuses(response);
|
||||
statuses.add(status);
|
||||
}
|
||||
@Override
|
||||
public void onSuccess(int statusCode, Header[] headers, JSONArray response) {
|
||||
apiResponse.setSince_id(findSinceId(headers));
|
||||
apiResponse.setMax_id(findMaxId(headers));
|
||||
statuses = parseStatuses(response);
|
||||
}
|
||||
@Override
|
||||
|
@ -296,7 +312,8 @@ public class API {
|
|||
setError(statusCode, error);
|
||||
}
|
||||
});
|
||||
return statuses;
|
||||
apiResponse.setStatuses(statuses);
|
||||
return apiResponse;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -327,7 +344,7 @@ public class API {
|
|||
* @param max_id String id max
|
||||
* @return List<Status>
|
||||
*/
|
||||
public List<Status> getHomeTimeline( String max_id) {
|
||||
public APIResponse getHomeTimeline( String max_id) {
|
||||
return getHomeTimeline(max_id, null, tootPerPage);
|
||||
}
|
||||
|
||||
|
@ -335,7 +352,7 @@ public class API {
|
|||
* Retrieves home timeline for the account since an Id value *synchronously*
|
||||
* @return List<Status>
|
||||
*/
|
||||
public List<Status> getHomeTimelineSinceId(String since_id) {
|
||||
public APIResponse getHomeTimelineSinceId(String since_id) {
|
||||
return getHomeTimeline(null, since_id, tootPerPage);
|
||||
}
|
||||
|
||||
|
@ -346,7 +363,7 @@ public class API {
|
|||
* @param limit int limit - max value 40
|
||||
* @return List<Status>
|
||||
*/
|
||||
private List<Status> getHomeTimeline(String max_id, String since_id, int limit) {
|
||||
private APIResponse getHomeTimeline(String max_id, String since_id, int limit) {
|
||||
|
||||
RequestParams params = new RequestParams();
|
||||
if (max_id != null)
|
||||
|
@ -363,17 +380,22 @@ public class API {
|
|||
public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
|
||||
Status status = parseStatuses(response);
|
||||
statuses.add(status);
|
||||
apiResponse.setSince_id(findSinceId(headers));
|
||||
apiResponse.setMax_id(findMaxId(headers));
|
||||
}
|
||||
@Override
|
||||
public void onSuccess(int statusCode, Header[] headers, JSONArray response) {
|
||||
statuses = parseStatuses(response);
|
||||
apiResponse.setSince_id(findSinceId(headers));
|
||||
apiResponse.setMax_id(findMaxId(headers));
|
||||
}
|
||||
@Override
|
||||
public void onFailure(int statusCode, Header[] headers, Throwable error, JSONObject response){
|
||||
setError(statusCode, error);
|
||||
}
|
||||
});
|
||||
return statuses;
|
||||
apiResponse.setStatuses(statuses);
|
||||
return apiResponse;
|
||||
}
|
||||
|
||||
|
||||
|
@ -383,7 +405,7 @@ public class API {
|
|||
* @param max_id String id max
|
||||
* @return List<Status>
|
||||
*/
|
||||
public List<Status> getPublicTimeline(boolean local, String max_id){
|
||||
public APIResponse getPublicTimeline(boolean local, String max_id){
|
||||
return getPublicTimeline(local, max_id, null, tootPerPage);
|
||||
}
|
||||
/**
|
||||
|
@ -394,7 +416,7 @@ public class API {
|
|||
* @param limit int limit - max value 40
|
||||
* @return List<Status>
|
||||
*/
|
||||
private List<Status> getPublicTimeline(boolean local, String max_id, String since_id, int limit){
|
||||
private APIResponse getPublicTimeline(boolean local, String max_id, String since_id, int limit){
|
||||
|
||||
RequestParams params = new RequestParams();
|
||||
if( local)
|
||||
|
@ -413,17 +435,22 @@ public class API {
|
|||
public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
|
||||
Status status = parseStatuses(response);
|
||||
statuses.add(status);
|
||||
apiResponse.setSince_id(findSinceId(headers));
|
||||
apiResponse.setMax_id(findMaxId(headers));
|
||||
}
|
||||
@Override
|
||||
public void onSuccess(int statusCode, Header[] headers, JSONArray response) {
|
||||
statuses = parseStatuses(response);
|
||||
apiResponse.setSince_id(findSinceId(headers));
|
||||
apiResponse.setMax_id(findMaxId(headers));
|
||||
}
|
||||
@Override
|
||||
public void onFailure(int statusCode, Header[] headers, Throwable error, JSONObject response){
|
||||
setError(statusCode, error);
|
||||
}
|
||||
});
|
||||
return statuses;
|
||||
apiResponse.setStatuses(statuses);
|
||||
return apiResponse;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -433,7 +460,7 @@ public class API {
|
|||
* @param max_id String id max
|
||||
* @return List<Status>
|
||||
*/
|
||||
public List<Status> getPublicTimelineTag(String tag, boolean local, String max_id){
|
||||
public APIResponse getPublicTimelineTag(String tag, boolean local, String max_id){
|
||||
return getPublicTimelineTag(tag, local, max_id, null, tootPerPage);
|
||||
}
|
||||
/**
|
||||
|
@ -445,7 +472,7 @@ public class API {
|
|||
* @param limit int limit - max value 40
|
||||
* @return List<Status>
|
||||
*/
|
||||
private List<Status> getPublicTimelineTag(String tag, boolean local, String max_id, String since_id, int limit){
|
||||
private APIResponse getPublicTimelineTag(String tag, boolean local, String max_id, String since_id, int limit){
|
||||
|
||||
RequestParams params = new RequestParams();
|
||||
if( local)
|
||||
|
@ -465,17 +492,22 @@ public class API {
|
|||
public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
|
||||
Status status = parseStatuses(response);
|
||||
statuses.add(status);
|
||||
apiResponse.setSince_id(findSinceId(headers));
|
||||
apiResponse.setMax_id(findMaxId(headers));
|
||||
}
|
||||
@Override
|
||||
public void onSuccess(int statusCode, Header[] headers, JSONArray response) {
|
||||
statuses = parseStatuses(response);
|
||||
apiResponse.setSince_id(findSinceId(headers));
|
||||
apiResponse.setMax_id(findMaxId(headers));
|
||||
}
|
||||
@Override
|
||||
public void onFailure(int statusCode, Header[] headers, Throwable error, JSONObject response){
|
||||
setError(statusCode, error);
|
||||
}
|
||||
});
|
||||
return statuses;
|
||||
apiResponse.setStatuses(statuses);
|
||||
return apiResponse;
|
||||
}
|
||||
|
||||
|
||||
|
@ -484,7 +516,7 @@ public class API {
|
|||
* @param max_id String id max
|
||||
* @return List<Status>
|
||||
*/
|
||||
public List<Account> getMuted(String max_id){
|
||||
public APIResponse getMuted(String max_id){
|
||||
return getAccounts("/mutes", max_id, null, accountPerPage);
|
||||
}
|
||||
|
||||
|
@ -493,7 +525,7 @@ public class API {
|
|||
* @param max_id String id max
|
||||
* @return List<Status>
|
||||
*/
|
||||
public List<Account> getBlocks(String max_id){
|
||||
public APIResponse getBlocks(String max_id){
|
||||
return getAccounts("/blocks", max_id, null, accountPerPage);
|
||||
}
|
||||
|
||||
|
@ -504,7 +536,7 @@ public class API {
|
|||
* @param max_id String id max
|
||||
* @return List<Status>
|
||||
*/
|
||||
public List<Account> getFollowing(String targetedId, String max_id){
|
||||
public APIResponse getFollowing(String targetedId, String max_id){
|
||||
return getAccounts(String.format("/accounts/%s/following",targetedId),max_id, null, accountPerPage);
|
||||
}
|
||||
|
||||
|
@ -514,7 +546,7 @@ public class API {
|
|||
* @param max_id String id max
|
||||
* @return List<Status>
|
||||
*/
|
||||
public List<Account> getFollowers(String targetedId, String max_id){
|
||||
public APIResponse getFollowers(String targetedId, String max_id){
|
||||
return getAccounts(String.format("/accounts/%s/followers",targetedId),max_id, null, accountPerPage);
|
||||
}
|
||||
|
||||
|
@ -525,7 +557,7 @@ public class API {
|
|||
* @param limit int limit - max value 40
|
||||
* @return List<Status>
|
||||
*/
|
||||
private List<Account> getAccounts(String action, String max_id, String since_id, int limit){
|
||||
private APIResponse getAccounts(String action, String max_id, String since_id, int limit){
|
||||
|
||||
RequestParams params = new RequestParams();
|
||||
if( max_id != null )
|
||||
|
@ -540,11 +572,15 @@ public class API {
|
|||
|
||||
@Override
|
||||
public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
|
||||
apiResponse.setSince_id(findSinceId(headers));
|
||||
apiResponse.setMax_id(findMaxId(headers));
|
||||
Account account = parseAccountResponse(response);
|
||||
accounts.add(account);
|
||||
}
|
||||
@Override
|
||||
public void onSuccess(int statusCode, Header[] headers, JSONArray response) {
|
||||
apiResponse.setSince_id(findSinceId(headers));
|
||||
apiResponse.setMax_id(findMaxId(headers));
|
||||
accounts = parseAccountResponse(response);
|
||||
}
|
||||
@Override
|
||||
|
@ -552,7 +588,8 @@ public class API {
|
|||
setError(statusCode, error);
|
||||
}
|
||||
});
|
||||
return accounts;
|
||||
apiResponse.setAccounts(accounts);
|
||||
return apiResponse;
|
||||
}
|
||||
|
||||
|
||||
|
@ -561,7 +598,7 @@ public class API {
|
|||
* @param max_id String id max
|
||||
* @return List<Status>
|
||||
*/
|
||||
public List<Status> getFavourites(String max_id){
|
||||
public APIResponse getFavourites(String max_id){
|
||||
return getFavourites(max_id, null, tootPerPage);
|
||||
}
|
||||
/**
|
||||
|
@ -571,7 +608,7 @@ public class API {
|
|||
* @param limit int limit - max value 40
|
||||
* @return List<Status>
|
||||
*/
|
||||
private List<Status> getFavourites(String max_id, String since_id, int limit){
|
||||
private APIResponse getFavourites(String max_id, String since_id, int limit){
|
||||
|
||||
RequestParams params = new RequestParams();
|
||||
if( max_id != null )
|
||||
|
@ -588,17 +625,22 @@ public class API {
|
|||
public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
|
||||
Status status = parseStatuses(response);
|
||||
statuses.add(status);
|
||||
apiResponse.setSince_id(findSinceId(headers));
|
||||
apiResponse.setMax_id(findMaxId(headers));
|
||||
}
|
||||
@Override
|
||||
public void onSuccess(int statusCode, Header[] headers, JSONArray response) {
|
||||
statuses = parseStatuses(response);
|
||||
apiResponse.setSince_id(findSinceId(headers));
|
||||
apiResponse.setMax_id(findMaxId(headers));
|
||||
}
|
||||
@Override
|
||||
public void onFailure(int statusCode, Header[] headers, Throwable error, JSONObject response){
|
||||
setError(statusCode, error);
|
||||
}
|
||||
});
|
||||
return statuses;
|
||||
apiResponse.setStatuses(statuses);
|
||||
return apiResponse;
|
||||
}
|
||||
|
||||
|
||||
|
@ -749,7 +791,7 @@ public class API {
|
|||
* @param since_id String since max
|
||||
* @return List<Notification>
|
||||
*/
|
||||
public List<Notification> getNotificationsSince(String since_id){
|
||||
public APIResponse getNotificationsSince(String since_id){
|
||||
return getNotifications(null, since_id, notificationPerPage);
|
||||
}
|
||||
|
||||
|
@ -758,7 +800,7 @@ public class API {
|
|||
* @param max_id String id max
|
||||
* @return List<Notification>
|
||||
*/
|
||||
public List<Notification> getNotifications(String max_id){
|
||||
public APIResponse getNotifications(String max_id){
|
||||
return getNotifications(max_id, null, notificationPerPage);
|
||||
}
|
||||
/**
|
||||
|
@ -768,7 +810,7 @@ public class API {
|
|||
* @param limit int limit - max value 40
|
||||
* @return List<Notification>
|
||||
*/
|
||||
private List<Notification> getNotifications(String max_id, String since_id, int limit){
|
||||
private APIResponse getNotifications(String max_id, String since_id, int limit){
|
||||
|
||||
RequestParams params = new RequestParams();
|
||||
if( max_id != null )
|
||||
|
@ -785,17 +827,22 @@ public class API {
|
|||
public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
|
||||
Notification notification = parseNotificationResponse(response);
|
||||
notifications.add(notification);
|
||||
apiResponse.setSince_id(findSinceId(headers));
|
||||
apiResponse.setMax_id(findMaxId(headers));
|
||||
}
|
||||
@Override
|
||||
public void onSuccess(int statusCode, Header[] headers, JSONArray response) {
|
||||
notifications = parseNotificationResponse(response);
|
||||
apiResponse.setSince_id(findSinceId(headers));
|
||||
apiResponse.setMax_id(findMaxId(headers));
|
||||
}
|
||||
@Override
|
||||
public void onFailure(int statusCode, Header[] headers, Throwable error, JSONObject response){
|
||||
setError(statusCode, error);
|
||||
}
|
||||
});
|
||||
return notifications;
|
||||
apiResponse.setNotifications(notifications);
|
||||
return apiResponse;
|
||||
}
|
||||
|
||||
public Attachment uploadMedia(InputStream inputStream){
|
||||
|
@ -855,7 +902,7 @@ public class API {
|
|||
*
|
||||
* @return List<Account>
|
||||
*/
|
||||
public List<Account> searchDeveloper() {
|
||||
public APIResponse searchDeveloper() {
|
||||
RequestParams params = new RequestParams();
|
||||
params.add("q", "tschneider");
|
||||
get("/accounts/search", params, new JsonHttpResponseHandler() {
|
||||
|
@ -864,17 +911,22 @@ public class API {
|
|||
accounts = new ArrayList<>();
|
||||
account = parseAccountResponse(response);
|
||||
accounts.add(account);
|
||||
apiResponse.setSince_id(findSinceId(headers));
|
||||
apiResponse.setMax_id(findMaxId(headers));
|
||||
}
|
||||
@Override
|
||||
public void onSuccess(int statusCode, Header[] headers, JSONArray response) {
|
||||
accounts = parseDeveloperResponse(response);
|
||||
apiResponse.setSince_id(findSinceId(headers));
|
||||
apiResponse.setMax_id(findMaxId(headers));
|
||||
}
|
||||
@Override
|
||||
public void onFailure(int statusCode, Header[] headers, Throwable error, JSONObject response){
|
||||
setError(statusCode, error);
|
||||
}
|
||||
});
|
||||
return accounts;
|
||||
apiResponse.setAccounts(accounts);
|
||||
return apiResponse;
|
||||
}
|
||||
/**
|
||||
* Retrieves Accounts when searching (ie: via @...) *synchronously*
|
||||
|
@ -882,7 +934,7 @@ public class API {
|
|||
* @param query String search
|
||||
* @return List<Account>
|
||||
*/
|
||||
public List<Account> searchAccounts(String query) {
|
||||
public APIResponse searchAccounts(String query) {
|
||||
|
||||
RequestParams params = new RequestParams();
|
||||
params.add("q", query);
|
||||
|
@ -895,18 +947,23 @@ public class API {
|
|||
accounts = new ArrayList<>();
|
||||
account = parseAccountResponse(response);
|
||||
accounts.add(account);
|
||||
apiResponse.setSince_id(findSinceId(headers));
|
||||
apiResponse.setMax_id(findMaxId(headers));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSuccess(int statusCode, Header[] headers, JSONArray response) {
|
||||
accounts = parseAccountResponse(response);
|
||||
apiResponse.setSince_id(findSinceId(headers));
|
||||
apiResponse.setMax_id(findMaxId(headers));
|
||||
}
|
||||
@Override
|
||||
public void onFailure(int statusCode, Header[] headers, Throwable error, JSONObject response){
|
||||
setError(statusCode, error);
|
||||
}
|
||||
});
|
||||
return accounts;
|
||||
apiResponse.setAccounts(accounts);
|
||||
return apiResponse;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1231,8 +1288,9 @@ public class API {
|
|||
* @param error Throwable error
|
||||
*/
|
||||
private void setError(int statusCode, Throwable error){
|
||||
errorApi = new Error();
|
||||
errorApi.setError(statusCode + " - " + error.getMessage());
|
||||
APIError = new Error();
|
||||
APIError.setError(statusCode + " - " + error.getMessage());
|
||||
apiResponse.setError(APIError);
|
||||
}
|
||||
|
||||
|
||||
|
@ -1284,7 +1342,7 @@ public class API {
|
|||
}
|
||||
|
||||
public Error getError(){
|
||||
return errorApi;
|
||||
return APIError;
|
||||
}
|
||||
|
||||
|
||||
|
@ -1292,5 +1350,44 @@ public class API {
|
|||
return "https://" + this.instance + "/api/v1" + action;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find max_id in header
|
||||
* @param headers Header[]
|
||||
* @return String max_id if presents
|
||||
*/
|
||||
private String findMaxId(Header[] headers){
|
||||
if( headers == null)
|
||||
return null;
|
||||
for(Header header: headers){
|
||||
if( header.toString().startsWith("Link: ")){
|
||||
Pattern pattern = Pattern.compile("max_id=([0-9]{1,}).*");
|
||||
Matcher matcher = pattern.matcher(header.toString());
|
||||
if (matcher.find()) {
|
||||
return matcher.group(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find since_id in header
|
||||
* @param headers Header[]
|
||||
* @return String since_id if presents
|
||||
*/
|
||||
private String findSinceId(Header[] headers){
|
||||
if( headers == null)
|
||||
return null;
|
||||
for(Header header: headers){
|
||||
if( header.toString().startsWith("Link: ")){
|
||||
Pattern pattern = Pattern.compile("since_id=([0-9]{1,}).*");
|
||||
Matcher matcher = pattern.matcher(header.toString());
|
||||
if (matcher.find()) {
|
||||
return matcher.group(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,79 @@
|
|||
package fr.gouv.etalab.mastodon.client;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import fr.gouv.etalab.mastodon.client.Entities.*;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Error;
|
||||
|
||||
/**
|
||||
* Created by Thomas on 03/06/2017.
|
||||
* Hydrate response from the API
|
||||
*/
|
||||
|
||||
public class APIResponse {
|
||||
|
||||
private List<Account> accounts = null;
|
||||
private List<Status> statuses = null;
|
||||
private List<Context> contexts = null;
|
||||
private List<Notification> notifications = null;
|
||||
private fr.gouv.etalab.mastodon.client.Entities.Error error = null;
|
||||
private String since_id, max_id;
|
||||
|
||||
public List<Account> getAccounts() {
|
||||
return accounts;
|
||||
}
|
||||
|
||||
public void setAccounts(List<Account> accounts) {
|
||||
this.accounts = accounts;
|
||||
}
|
||||
|
||||
public List<Status> getStatuses() {
|
||||
return statuses;
|
||||
}
|
||||
|
||||
public void setStatuses(List<Status> statuses) {
|
||||
this.statuses = statuses;
|
||||
}
|
||||
|
||||
public List<Context> getContexts() {
|
||||
return contexts;
|
||||
}
|
||||
|
||||
public void setContexts(List<Context> contexts) {
|
||||
this.contexts = contexts;
|
||||
}
|
||||
|
||||
public List<Notification> getNotifications() {
|
||||
return notifications;
|
||||
}
|
||||
|
||||
public void setNotifications(List<Notification> notifications) {
|
||||
this.notifications = notifications;
|
||||
}
|
||||
|
||||
public Error getError() {
|
||||
return error;
|
||||
}
|
||||
|
||||
public void setError(Error error) {
|
||||
this.error = error;
|
||||
}
|
||||
|
||||
public String getMax_id() {
|
||||
return max_id;
|
||||
}
|
||||
|
||||
public void setMax_id(String max_id) {
|
||||
this.max_id = max_id;
|
||||
}
|
||||
|
||||
public String getSince_id() {
|
||||
return since_id;
|
||||
}
|
||||
|
||||
public void setSince_id(String since_id) {
|
||||
this.since_id = since_id;
|
||||
}
|
||||
}
|
|
@ -35,6 +35,8 @@ import android.widget.Toast;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
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;
|
||||
|
@ -107,28 +109,7 @@ public class DisplayAccountsFragment extends Fragment implements OnRetrieveAccou
|
|||
lv_accounts.setAdapter(accountsListAdapter);
|
||||
|
||||
if( !comesFromSearch) {
|
||||
lv_accounts.setOnScrollListener(new AbsListView.OnScrollListener() {
|
||||
@Override
|
||||
public void onScrollStateChanged(AbsListView view, int scrollState) {
|
||||
|
||||
}
|
||||
|
||||
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
|
||||
|
||||
if (firstVisibleItem + visibleItemCount == totalItemCount) {
|
||||
if (!flag_loading) {
|
||||
flag_loading = true;
|
||||
if (type != RetrieveAccountsAsyncTask.Type.FOLLOWERS && type != RetrieveAccountsAsyncTask.Type.FOLLOWING)
|
||||
asyncTask = new RetrieveAccountsAsyncTask(context, type, max_id, DisplayAccountsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
else
|
||||
asyncTask = new RetrieveAccountsAsyncTask(context, type, targetedId, max_id, DisplayAccountsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
nextElementLoader.setVisibility(View.VISIBLE);
|
||||
}
|
||||
} else {
|
||||
nextElementLoader.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
//Hide account header when scrolling for ShowAccountActivity
|
||||
if (hideHeader) {
|
||||
|
@ -160,6 +141,41 @@ public class DisplayAccountsFragment extends Fragment implements OnRetrieveAccou
|
|||
}
|
||||
lastFirstVisibleItem = currentFirstVisibleItem;
|
||||
}
|
||||
if (firstVisibleItem + visibleItemCount == totalItemCount) {
|
||||
if (!flag_loading) {
|
||||
flag_loading = true;
|
||||
if (type != RetrieveAccountsAsyncTask.Type.FOLLOWERS && type != RetrieveAccountsAsyncTask.Type.FOLLOWING)
|
||||
asyncTask = new RetrieveAccountsAsyncTask(context, type, max_id, DisplayAccountsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
else
|
||||
asyncTask = new RetrieveAccountsAsyncTask(context, type, targetedId, max_id, DisplayAccountsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
nextElementLoader.setVisibility(View.VISIBLE);
|
||||
}
|
||||
} else {
|
||||
nextElementLoader.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
});
|
||||
}else{
|
||||
lv_accounts.setOnScrollListener(new AbsListView.OnScrollListener() {
|
||||
@Override
|
||||
public void onScrollStateChanged(AbsListView view, int scrollState) {
|
||||
|
||||
}
|
||||
|
||||
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
|
||||
|
||||
if (firstVisibleItem + visibleItemCount == totalItemCount) {
|
||||
if (!flag_loading) {
|
||||
flag_loading = true;
|
||||
if (type != RetrieveAccountsAsyncTask.Type.FOLLOWERS && type != RetrieveAccountsAsyncTask.Type.FOLLOWING)
|
||||
asyncTask = new RetrieveAccountsAsyncTask(context, type, max_id, DisplayAccountsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
else
|
||||
asyncTask = new RetrieveAccountsAsyncTask(context, type, targetedId, max_id, DisplayAccountsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
nextElementLoader.setVisibility(View.VISIBLE);
|
||||
}
|
||||
} else {
|
||||
nextElementLoader.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -220,26 +236,23 @@ public class DisplayAccountsFragment extends Fragment implements OnRetrieveAccou
|
|||
|
||||
|
||||
@Override
|
||||
public void onRetrieveAccounts(List<Account> accounts, Error error) {
|
||||
public void onRetrieveAccounts(APIResponse apiResponse) {
|
||||
|
||||
mainLoader.setVisibility(View.GONE);
|
||||
nextElementLoader.setVisibility(View.GONE);
|
||||
if( error != null){
|
||||
if( apiResponse.getError() != null){
|
||||
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
boolean show_error_messages = sharedpreferences.getBoolean(Helper.SET_SHOW_ERROR_MESSAGES, true);
|
||||
if( show_error_messages)
|
||||
Toast.makeText(getContext(), error.getError(),Toast.LENGTH_LONG).show();
|
||||
Toast.makeText(getContext(), apiResponse.getError().getError(),Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
List<Account> accounts = apiResponse.getAccounts();
|
||||
if( firstLoad && (accounts == null || accounts.size() == 0))
|
||||
textviewNoAction.setVisibility(View.VISIBLE);
|
||||
else
|
||||
textviewNoAction.setVisibility(View.GONE);
|
||||
if( accounts != null && accounts.size() > 1)
|
||||
max_id =accounts.get(accounts.size()-1).getId();
|
||||
else
|
||||
max_id = null;
|
||||
|
||||
max_id = apiResponse.getMax_id();
|
||||
if( accounts != null) {
|
||||
for(Account tmpAccount: accounts){
|
||||
this.accounts.add(tmpAccount);
|
||||
|
|
|
@ -20,7 +20,6 @@ import android.os.AsyncTask;
|
|||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.widget.SwipeRefreshLayout;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
@ -32,8 +31,8 @@ import android.widget.Toast;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
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.drawers.NotificationsListAdapter;
|
||||
import fr.gouv.etalab.mastodon.helper.Helper;
|
||||
import fr.gouv.etalab.mastodon.sqlite.AccountDAO;
|
||||
|
@ -148,26 +147,23 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve
|
|||
|
||||
|
||||
@Override
|
||||
public void onRetrieveNotifications(List<Notification> notifications, String acct, String userId, Error error) {
|
||||
public void onRetrieveNotifications(APIResponse apiResponse, String acct, String userId) {
|
||||
|
||||
mainLoader.setVisibility(View.GONE);
|
||||
nextElementLoader.setVisibility(View.GONE);
|
||||
if( error != null){
|
||||
if( apiResponse.getError() != null){
|
||||
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
boolean show_error_messages = sharedpreferences.getBoolean(Helper.SET_SHOW_ERROR_MESSAGES, true);
|
||||
if( show_error_messages)
|
||||
Toast.makeText(getContext(), error.getError(),Toast.LENGTH_LONG).show();
|
||||
Toast.makeText(getContext(), apiResponse.getError().getError(),Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
List<Notification> notifications = apiResponse.getNotifications();
|
||||
if( firstLoad && (notifications == null || notifications.size() == 0))
|
||||
textviewNoAction.setVisibility(View.VISIBLE);
|
||||
else
|
||||
textviewNoAction.setVisibility(View.GONE);
|
||||
if( notifications != null && notifications.size() > 1)
|
||||
max_id =notifications.get(notifications.size()-1).getId();
|
||||
else
|
||||
max_id = null;
|
||||
|
||||
max_id = apiResponse.getMax_id();
|
||||
|
||||
if( notifications != null) {
|
||||
for(Notification tmpNotification: notifications){
|
||||
|
|
|
@ -30,14 +30,10 @@ import android.widget.AbsListView;
|
|||
import android.widget.ListView;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.Toast;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
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.drawers.StatusListAdapter;
|
||||
import fr.gouv.etalab.mastodon.helper.Helper;
|
||||
import fr.gouv.etalab.mastodon.sqlite.AccountDAO;
|
||||
|
@ -112,29 +108,6 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
|
|||
lv_status.setAdapter(statusListAdapter);
|
||||
|
||||
if( !comesFromSearch){
|
||||
lv_status.setOnScrollListener(new AbsListView.OnScrollListener() {
|
||||
@Override
|
||||
public void onScrollStateChanged(AbsListView view, int scrollState) {
|
||||
|
||||
}
|
||||
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
|
||||
if(firstVisibleItem + visibleItemCount == totalItemCount ) {
|
||||
if(!flag_loading ) {
|
||||
flag_loading = true;
|
||||
if( type == RetrieveFeedsAsyncTask.Type.USER)
|
||||
asyncTask = new RetrieveFeedsAsyncTask(context, type, targetedId, max_id, DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
else if( type == RetrieveFeedsAsyncTask.Type.TAG)
|
||||
asyncTask = new RetrieveFeedsAsyncTask(context, type, tag, targetedId, max_id, DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
else
|
||||
asyncTask = new RetrieveFeedsAsyncTask(context, type, max_id, DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
|
||||
nextElementLoader.setVisibility(View.VISIBLE);
|
||||
}
|
||||
} else {
|
||||
nextElementLoader.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
//Hide account header when scrolling for ShowAccountActivity
|
||||
if( hideHeader ) {
|
||||
|
@ -165,6 +138,45 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
|
|||
}
|
||||
lastFirstVisibleItem = currentFirstVisibleItem;
|
||||
}
|
||||
if(firstVisibleItem + visibleItemCount == totalItemCount ) {
|
||||
if(!flag_loading ) {
|
||||
flag_loading = true;
|
||||
if( type == RetrieveFeedsAsyncTask.Type.USER)
|
||||
asyncTask = new RetrieveFeedsAsyncTask(context, type, targetedId, max_id, DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
else if( type == RetrieveFeedsAsyncTask.Type.TAG)
|
||||
asyncTask = new RetrieveFeedsAsyncTask(context, type, tag, targetedId, max_id, DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
else
|
||||
asyncTask = new RetrieveFeedsAsyncTask(context, type, max_id, DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
|
||||
nextElementLoader.setVisibility(View.VISIBLE);
|
||||
}
|
||||
} else {
|
||||
nextElementLoader.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
});
|
||||
}else{
|
||||
lv_status.setOnScrollListener(new AbsListView.OnScrollListener() {
|
||||
@Override
|
||||
public void onScrollStateChanged(AbsListView view, int scrollState) {
|
||||
|
||||
}
|
||||
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
|
||||
if(firstVisibleItem + visibleItemCount == totalItemCount ) {
|
||||
if(!flag_loading ) {
|
||||
flag_loading = true;
|
||||
if( type == RetrieveFeedsAsyncTask.Type.USER)
|
||||
asyncTask = new RetrieveFeedsAsyncTask(context, type, targetedId, max_id, DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
else if( type == RetrieveFeedsAsyncTask.Type.TAG)
|
||||
asyncTask = new RetrieveFeedsAsyncTask(context, type, tag, targetedId, max_id, DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
else
|
||||
asyncTask = new RetrieveFeedsAsyncTask(context, type, max_id, DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
|
||||
nextElementLoader.setVisibility(View.VISIBLE);
|
||||
}
|
||||
} else {
|
||||
nextElementLoader.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -232,26 +244,23 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
|
|||
|
||||
|
||||
@Override
|
||||
public void onRetrieveFeeds(List<Status> statuses, Error error) {
|
||||
public void onRetrieveFeeds(APIResponse apiResponse) {
|
||||
|
||||
mainLoader.setVisibility(View.GONE);
|
||||
nextElementLoader.setVisibility(View.GONE);
|
||||
if( error != null){
|
||||
if( apiResponse.getError() != null){
|
||||
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
boolean show_error_messages = sharedpreferences.getBoolean(Helper.SET_SHOW_ERROR_MESSAGES, true);
|
||||
if( show_error_messages)
|
||||
Toast.makeText(getContext(), error.getError(),Toast.LENGTH_LONG).show();
|
||||
Toast.makeText(getContext(), apiResponse.getError().getError(),Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
List<Status> statuses = apiResponse.getStatuses();
|
||||
if( firstLoad && (statuses == null || statuses.size() == 0))
|
||||
textviewNoAction.setVisibility(View.VISIBLE);
|
||||
else
|
||||
textviewNoAction.setVisibility(View.GONE);
|
||||
if( statuses != null && statuses.size() > 1)
|
||||
max_id =statuses.get(statuses.size()-1).getId();
|
||||
else
|
||||
max_id = null;
|
||||
|
||||
max_id = apiResponse.getMax_id();
|
||||
if( statuses != null) {
|
||||
for(Status tmpStatus: statuses){
|
||||
this.statuses.add(tmpStatus);
|
||||
|
|
|
@ -15,15 +15,12 @@
|
|||
package fr.gouv.etalab.mastodon.interfaces;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Account;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Error;
|
||||
import fr.gouv.etalab.mastodon.client.APIResponse;
|
||||
|
||||
/**
|
||||
* Created by Thomas on 27/04/2017.
|
||||
* Interface when accounts have been retrieved
|
||||
*/
|
||||
public interface OnRetrieveAccountsInterface {
|
||||
void onRetrieveAccounts(List<Account> accounts, Error error);
|
||||
void onRetrieveAccounts(APIResponse apiResponse);
|
||||
}
|
||||
|
|
|
@ -14,16 +14,12 @@
|
|||
* see <http://www.gnu.org/licenses>. */
|
||||
package fr.gouv.etalab.mastodon.interfaces;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Error;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Status;
|
||||
import fr.gouv.etalab.mastodon.client.APIResponse;
|
||||
|
||||
/**
|
||||
* Created by Thomas on 24/04/2017.
|
||||
* Interface when status have been retrieved
|
||||
*/
|
||||
public interface OnRetrieveFeedsInterface {
|
||||
void onRetrieveFeeds(List<Status> statuses, Error error);
|
||||
void onRetrieveFeeds(APIResponse apiResponse);
|
||||
}
|
||||
|
|
|
@ -15,15 +15,12 @@
|
|||
package fr.gouv.etalab.mastodon.interfaces;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Error;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Status;
|
||||
import fr.gouv.etalab.mastodon.client.APIResponse;
|
||||
|
||||
/**
|
||||
* Created by Thomas on 20/05/2017.
|
||||
* Interface when home timeline toots have been retrieved
|
||||
*/
|
||||
public interface OnRetrieveHomeTimelineServiceInterface {
|
||||
void onRetrieveHomeTimelineService(List<Status> statuses, String acct, String userId, Error error);
|
||||
void onRetrieveHomeTimelineService(APIResponse apiResponse, String acct, String userId);
|
||||
}
|
||||
|
|
|
@ -14,16 +14,12 @@
|
|||
* see <http://www.gnu.org/licenses>. */
|
||||
package fr.gouv.etalab.mastodon.interfaces;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Error;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Notification;
|
||||
import fr.gouv.etalab.mastodon.client.APIResponse;
|
||||
|
||||
/**
|
||||
* Created by Thomas on 28/04/2017.
|
||||
* Interface when notifications have been retrieved
|
||||
*/
|
||||
public interface OnRetrieveNotificationsInterface {
|
||||
void onRetrieveNotifications(List<Notification> notifications, String acct, String userId, Error error);
|
||||
void onRetrieveNotifications(APIResponse apiResponse, String acct, String userId);
|
||||
}
|
||||
|
|
|
@ -14,10 +14,7 @@
|
|||
* see <http://www.gnu.org/licenses>. */
|
||||
package fr.gouv.etalab.mastodon.interfaces;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Account;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Error;
|
||||
import fr.gouv.etalab.mastodon.client.APIResponse;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -25,5 +22,5 @@ import fr.gouv.etalab.mastodon.client.Entities.Error;
|
|||
* Interface for search accounts
|
||||
*/
|
||||
public interface OnRetrieveSearcAccountshInterface {
|
||||
void onRetrieveSearchAccounts(List<Account> accounts, Error error);
|
||||
void onRetrieveSearchAccounts(APIResponse apiResponse);
|
||||
}
|
||||
|
|
|
@ -37,8 +37,8 @@ import java.util.concurrent.TimeUnit;
|
|||
|
||||
import fr.gouv.etalab.mastodon.activities.MainActivity;
|
||||
import fr.gouv.etalab.mastodon.asynctasks.RetrieveHomeTimelineServiceAsyncTask;
|
||||
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.Status;
|
||||
import fr.gouv.etalab.mastodon.client.PatchBaseImageDownloader;
|
||||
import fr.gouv.etalab.mastodon.helper.Helper;
|
||||
|
@ -125,8 +125,9 @@ public class HomeTimelineSyncJob extends Job implements OnRetrieveHomeTimelineSe
|
|||
|
||||
|
||||
@Override
|
||||
public void onRetrieveHomeTimelineService(List<Status> statuses, String acct, String userId, Error error) {
|
||||
if( error != null || statuses == null || statuses.size() == 0)
|
||||
public void onRetrieveHomeTimelineService(APIResponse apiResponse, String acct, String userId) {
|
||||
List<Status> statuses = apiResponse.getStatuses();
|
||||
if( apiResponse.getError() != null || statuses == null || statuses.size() == 0)
|
||||
return;
|
||||
Bitmap icon_notification = null;
|
||||
final SharedPreferences sharedpreferences = getContext().getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
|
@ -135,6 +136,7 @@ public class HomeTimelineSyncJob extends Job implements OnRetrieveHomeTimelineSe
|
|||
//No previous notifications in cache, so no notification will be sent
|
||||
String message;
|
||||
String title = null;
|
||||
|
||||
for(Status status: statuses){
|
||||
//The notification associated to max_id is discarded as it is supposed to have already been sent
|
||||
//Also, if the toot comes from the owner, we will avoid to warn him/her...
|
||||
|
@ -173,7 +175,7 @@ public class HomeTimelineSyncJob extends Job implements OnRetrieveHomeTimelineSe
|
|||
if( max_id != null)
|
||||
notify_user(getContext(), intent, notificationId, icon_notification,title,message);
|
||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||
editor.putString(Helper.LAST_HOMETIMELINE_MAX_ID + userId, statuses.get(0).getId());
|
||||
editor.putString(Helper.LAST_HOMETIMELINE_MAX_ID + userId, apiResponse.getMax_id());
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@ import java.util.Set;
|
|||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import fr.gouv.etalab.mastodon.activities.MainActivity;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Error;
|
||||
import fr.gouv.etalab.mastodon.client.APIResponse;
|
||||
import fr.gouv.etalab.mastodon.client.PatchBaseImageDownloader;
|
||||
import fr.gouv.etalab.mastodon.helper.Helper;
|
||||
import mastodon.etalab.gouv.fr.mastodon.R;
|
||||
|
@ -130,8 +130,10 @@ public class NotificationsSyncJob extends Job implements OnRetrieveNotifications
|
|||
|
||||
|
||||
@Override
|
||||
public void onRetrieveNotifications(List<Notification> notifications, String acct, String userId, Error error) {
|
||||
if( error != null || notifications == null || notifications.size() == 0)
|
||||
public void onRetrieveNotifications(APIResponse apiResponse, String acct, String userId) {
|
||||
|
||||
List<Notification> notifications = apiResponse.getNotifications();
|
||||
if( apiResponse.getError() != null || notifications == null || notifications.size() == 0)
|
||||
return;
|
||||
Bitmap icon_notification = null;
|
||||
final SharedPreferences sharedpreferences = getContext().getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
|
@ -228,7 +230,7 @@ public class NotificationsSyncJob extends Job implements OnRetrieveNotifications
|
|||
}
|
||||
|
||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||
editor.putString(Helper.LAST_NOTIFICATION_MAX_ID + userId, notifications.get(0).getId());
|
||||
editor.putString(Helper.LAST_NOTIFICATION_MAX_ID + userId, apiResponse.getMax_id());
|
||||
editor.apply();
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue