Handles errors with messages (can be disabled in settings)

This commit is contained in:
tom79 2017-05-30 19:31:44 +02:00
parent 8b41d694b0
commit 18da5dde02
41 changed files with 308 additions and 168 deletions

View File

@ -15,6 +15,7 @@
package fr.gouv.etalab.mastodon.activities;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.os.Bundle;
@ -26,11 +27,13 @@ import android.view.View;
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.asynctasks.RetrieveFeedsAsyncTask;
import fr.gouv.etalab.mastodon.client.Entities.Error;
import fr.gouv.etalab.mastodon.client.Entities.Status;
import fr.gouv.etalab.mastodon.drawers.StatusListAdapter;
import fr.gouv.etalab.mastodon.helper.Helper;
@ -136,8 +139,17 @@ public class HashTagActivity extends AppCompatActivity implements OnRetrieveFeed
}
@Override
public void onRetrieveFeeds(List<Status> statuses) {
public void onRetrieveFeeds(List<Status> statuses, Error error) {
mainLoader.setVisibility(View.GONE);
nextElementLoader.setVisibility(View.GONE);
if( error != 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();
return;
}
if( firstLoad && (statuses == null || statuses.size() == 0))
textviewNoAction.setVisibility(View.VISIBLE);
else
@ -146,9 +158,6 @@ public class HashTagActivity extends AppCompatActivity implements OnRetrieveFeed
max_id =statuses.get(statuses.size()-1).getId();
else
max_id = null;
mainLoader.setVisibility(View.GONE);
nextElementLoader.setVisibility(View.GONE);
if( statuses != null) {
for(Status tmpStatus: statuses){
this.statuses.add(tmpStatus);

View File

@ -14,6 +14,8 @@
* see <http://www.gnu.org/licenses>. */
package fr.gouv.etalab.mastodon.activities;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
@ -26,9 +28,11 @@ import java.util.List;
import fr.gouv.etalab.mastodon.asynctasks.RetrieveSearchAsyncTask;
import fr.gouv.etalab.mastodon.client.Entities.Account;
import fr.gouv.etalab.mastodon.client.Entities.Error;
import fr.gouv.etalab.mastodon.client.Entities.Results;
import fr.gouv.etalab.mastodon.client.Entities.Status;
import fr.gouv.etalab.mastodon.drawers.SearchListAdapter;
import fr.gouv.etalab.mastodon.helper.Helper;
import fr.gouv.etalab.mastodon.interfaces.OnRetrieveSearchInterface;
import mastodon.etalab.gouv.fr.mastodon.R;
@ -86,9 +90,15 @@ public class SearchResultActivity extends AppCompatActivity implements OnRetriev
@Override
public void onRetrieveSearch(Results results) {
public void onRetrieveSearch(Results results, Error error) {
loader.setVisibility(View.GONE);
if( error != 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();
return;
}
if( results == null){
RelativeLayout no_result = (RelativeLayout) findViewById(R.id.no_result);
no_result.setVisibility(View.VISIBLE);

View File

@ -54,6 +54,7 @@ import fr.gouv.etalab.mastodon.asynctasks.RetrieveFeedsAsyncTask;
import fr.gouv.etalab.mastodon.asynctasks.RetrieveRelationshipAsyncTask;
import fr.gouv.etalab.mastodon.client.API;
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.drawers.StatusListAdapter;
import fr.gouv.etalab.mastodon.fragments.DisplayAccountsFragment;
@ -241,7 +242,14 @@ public class ShowAccountActivity extends AppCompatActivity implements OnPostActi
@Override
public void onPostAction(int statusCode,API.StatusAction statusAction, String targetedId) {
public void onPostAction(int statusCode,API.StatusAction statusAction, String targetedId, Error error) {
if( error != 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();
return;
}
Helper.manageMessageStatusCode(getApplicationContext(), statusCode, statusAction);
new RetrieveRelationshipAsyncTask(getApplicationContext(), accountId,ShowAccountActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
@ -258,7 +266,14 @@ public class ShowAccountActivity extends AppCompatActivity implements OnPostActi
}
@Override
public void onRetrieveAccount(Account account) {
public void onRetrieveAccount(Account account, Error error) {
if( error != 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();
return;
}
ImageView account_pp = (ImageView) findViewById(R.id.account_pp);
TextView account_dn = (TextView) findViewById(R.id.account_dn);
TextView account_un = (TextView) findViewById(R.id.account_un);
@ -301,7 +316,15 @@ public class ShowAccountActivity extends AppCompatActivity implements OnPostActi
}
@Override
public void onRetrieveRelationship(Relationship relationship) {
public void onRetrieveRelationship(Relationship relationship, Error error) {
if( error != 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();
return;
}
if( relationship.isBlocking()){
account_follow.setText(R.string.action_unblock);
doAction = action.UNBLOCK;

View File

@ -23,6 +23,7 @@ import android.view.MenuItem;
import android.view.View;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.Toast;
import java.util.ArrayList;
import java.util.List;
@ -30,6 +31,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.Entities.Context;
import fr.gouv.etalab.mastodon.client.Entities.Error;
import fr.gouv.etalab.mastodon.client.Entities.Status;
import fr.gouv.etalab.mastodon.drawers.StatusListAdapter;
import fr.gouv.etalab.mastodon.helper.Helper;
@ -78,7 +80,14 @@ public class ShowConversationActivity extends AppCompatActivity implements OnRet
}
@Override
public void onRetrieveFeeds(List<Status> statuses) {
public void onRetrieveFeeds(List<Status> statuses, Error error) {
if( error != 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();
return;
}
if( statuses != null && statuses.size() > 0 ){
initialStatus = statuses.get(0);
new RetrieveContextAsyncTask(getApplicationContext(), initialStatus.getId(), ShowConversationActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
@ -86,7 +95,14 @@ public class ShowConversationActivity extends AppCompatActivity implements OnRet
}
@Override
public void onRetrieveFeeds(Context context) {
public void onRetrieveFeeds(Context context, Error error) {
if( error != 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();
return;
}
boolean isOnWifi = Helper.isOnWIFI(getApplicationContext());
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, android.content.Context.MODE_PRIVATE);
int behaviorWithAttachments = sharedpreferences.getInt(Helper.SET_ATTACHMENT_ACTION, Helper.ATTACHMENT_ALWAYS);

View File

@ -64,6 +64,7 @@ import fr.gouv.etalab.mastodon.asynctasks.UploadActionAsyncTask;
import fr.gouv.etalab.mastodon.client.API;
import fr.gouv.etalab.mastodon.client.Entities.Account;
import fr.gouv.etalab.mastodon.client.Entities.Attachment;
import fr.gouv.etalab.mastodon.client.Entities.Error;
import fr.gouv.etalab.mastodon.client.Entities.Status;
import fr.gouv.etalab.mastodon.drawers.AccountsSearchAdapter;
import fr.gouv.etalab.mastodon.helper.Helper;
@ -350,9 +351,16 @@ public class TootActivity extends AppCompatActivity implements OnRetrieveSearcAc
LocalBroadcastManager.getInstance(this).unregisterReceiver(search_validate);
}
@Override
public void onRetrieveAttachment(final Attachment attachment) {
public void onRetrieveAttachment(final Attachment attachment, Error error) {
loading_picture.setVisibility(View.GONE);
toot_picture_container.setVisibility(View.VISIBLE);
if( error != 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();
return;
}
if( attachment != null ){
String url = attachment.getPreview_url();
if( url == null || url.trim().equals(""))
@ -452,7 +460,14 @@ public class TootActivity extends AppCompatActivity implements OnRetrieveSearcAc
}
@Override
public void onPostAction(int statusCode, API.StatusAction statusAction, String userId) {
public void onPostAction(int statusCode, API.StatusAction statusAction, String userId, Error error) {
if( error != 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();
return;
}
if( statusCode == 200){
//Clear the toot
toot_content.setText("");
@ -476,7 +491,14 @@ public class TootActivity extends AppCompatActivity implements OnRetrieveSearcAc
}
@Override
public void onRetrieveFeeds(List<Status> statuses) {
public void onRetrieveFeeds(List<Status> statuses, Error error) {
if( error != 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();
return;
}
if( statuses != null && statuses.size() > 0 ){
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
boolean show_reply = sharedpreferences.getBoolean(Helper.SET_SHOW_REPLY, false);
@ -517,7 +539,14 @@ public class TootActivity extends AppCompatActivity implements OnRetrieveSearcAc
@Override
public void onRetrieveSearchAccounts(List<Account> accounts) {
public void onRetrieveSearchAccounts(List<Account> accounts, Error error) {
if( error != 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();
return;
}
if( accounts != null && accounts.size() > 0){
AccountsSearchAdapter accountsListAdapter = new AccountsSearchAdapter(TootActivity.this, accounts);
toot_lv_accounts.setAdapter(accountsListAdapter);

View File

@ -39,6 +39,7 @@ public class PostActionAsyncTask extends AsyncTask<Void, Void, Void> {
private String comment;
private Account account;
private fr.gouv.etalab.mastodon.client.Entities.Status status;
private API api;
public PostActionAsyncTask(Context context, API.StatusAction statusAction, String statusId, OnPostActionInterface onPostActionInterface){
this.context = context;
@ -59,18 +60,19 @@ public class PostActionAsyncTask extends AsyncTask<Void, Void, Void> {
@Override
protected Void doInBackground(Void... params) {
api = new API(context);
if(statusAction == API.StatusAction.REPORT)
statusCode = new API(context).reportAction(status, comment);
statusCode = api.reportAction(status, comment);
else if(statusAction == API.StatusAction.CREATESTATUS)
statusCode = new API(context).statusAction(status);
statusCode = api.statusAction(status);
else
statusCode = new API(context).postAction(statusAction, statusId);
statusCode = api.postAction(statusAction, statusId);
return null;
}
@Override
protected void onPostExecute(Void result) {
listener.onPostAction(statusCode, statusAction, statusId);
listener.onPostAction(statusCode, statusAction, statusId, api.getError());
}
}

View File

@ -33,7 +33,7 @@ public class RetrieveAccountAsyncTask extends AsyncTask<Void, Void, Void> {
private String targetedId;
private Account account;
private OnRetrieveAccountInterface listener;
private API api;
public RetrieveAccountAsyncTask(Context context, String targetedId, OnRetrieveAccountInterface onRetrieveAccountInterface){
this.context = context;
@ -43,14 +43,14 @@ public class RetrieveAccountAsyncTask extends AsyncTask<Void, Void, Void> {
@Override
protected Void doInBackground(Void... params) {
account = new API(context).getAccount(targetedId);
api = new API(context);
account = api.getAccount(targetedId);
return null;
}
@Override
protected void onPostExecute(Void result) {
listener.onRetrieveAccount(account);
listener.onRetrieveAccount(account, api.getError());
}
}

View File

@ -37,6 +37,7 @@ public class RetrieveAccountsAsyncTask extends AsyncTask<Void, Void, Void> {
private String max_id;
private OnRetrieveAccountsInterface listener;
private String targetedId;
private API api;
public enum Type{
BLOCKED,
@ -63,18 +64,19 @@ public class RetrieveAccountsAsyncTask extends AsyncTask<Void, Void, Void> {
@Override
protected Void doInBackground(Void... params) {
api = new API(context);
switch (action){
case BLOCKED:
accounts = new API(context).getBlocks(max_id);
accounts = api.getBlocks(max_id);
break;
case MUTED:
accounts = new API(context).getMuted(max_id);
accounts = api.getMuted(max_id);
break;
case FOLLOWING:
accounts = new API(context).getFollowing(targetedId, max_id);
accounts = api.getFollowing(targetedId, max_id);
break;
case FOLLOWERS:
accounts = new API(context).getFollowers(targetedId, max_id);
accounts = api.getFollowers(targetedId, max_id);
break;
}
return null;
@ -82,7 +84,7 @@ public class RetrieveAccountsAsyncTask extends AsyncTask<Void, Void, Void> {
@Override
protected void onPostExecute(Void result) {
listener.onRetrieveAccounts(accounts);
listener.onRetrieveAccounts(accounts, api.getError());
}
}

View File

@ -32,6 +32,7 @@ public class RetrieveContextAsyncTask extends AsyncTask<Void, Void, Void> {
private String statusId;
private fr.gouv.etalab.mastodon.client.Entities.Context statusContext;
private OnRetrieveContextInterface listener;
private API api;
public RetrieveContextAsyncTask(Context context, String statusId, OnRetrieveContextInterface onRetrieveContextInterface){
this.context = context;
@ -41,13 +42,14 @@ public class RetrieveContextAsyncTask extends AsyncTask<Void, Void, Void> {
@Override
protected Void doInBackground(Void... params) {
statusContext = new API(context).getStatusContext(statusId);
api = new API(context);
statusContext = api.getStatusContext(statusId);
return null;
}
@Override
protected void onPostExecute(Void result) {
listener.onRetrieveFeeds(statusContext);
listener.onRetrieveFeeds(statusContext, api.getError());
}
}

View File

@ -1,56 +0,0 @@
/* Copyright 2017 Thomas Schneider
*
* This file is a part of Mastodon Etalab for mastodon.etalab.gouv.fr
*
* This program is free software; you can redistribute it and/or modify it under the terms of the
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
* License, or (at your option) any later version.
*
* Mastodon Etalab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details.
*
* You should have received a copy of the GNU General Public License along with Thomas Schneider; if not,
* see <http://www.gnu.org/licenses>. */
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.interfaces.OnRetrieveFeedsAccountInterface;
/**
* Created by Thomas on 01/05/2017.
* Retrieves toots for an account
*/
public class RetrieveFeedsAccountAsyncTask extends AsyncTask<Void, Void, Void> {
private Context context;
private String accountId;
private List<fr.gouv.etalab.mastodon.client.Entities.Status> statuses;
private OnRetrieveFeedsAccountInterface listener;
public RetrieveFeedsAccountAsyncTask(Context context, String accountId, OnRetrieveFeedsAccountInterface onRetrieveFeedsAccountInterface){
this.context = context;
this.listener = onRetrieveFeedsAccountInterface;
this.accountId = accountId;
}
@Override
protected Void doInBackground(Void... params) {
statuses = new API(context).getStatus(accountId);
return null;
}
@Override
protected void onPostExecute(Void result) {
listener.onRetrieveFeedsAccount(statuses);
}
}

View File

@ -40,6 +40,7 @@ public class RetrieveFeedsAsyncTask extends AsyncTask<Void, Void, Void> {
private String targetedID;
private fr.gouv.etalab.mastodon.client.Entities.Status status;
private String tag;
private API api;
public enum Type{
HOME,
@ -78,27 +79,28 @@ public class RetrieveFeedsAsyncTask extends AsyncTask<Void, Void, Void> {
@Override
protected Void doInBackground(Void... params) {
api = new API(context);
switch (action){
case HOME:
statuses = new API(context).getHomeTimeline(max_id);
statuses = api.getHomeTimeline(max_id);
break;
case LOCAL:
statuses = new API(context).getPublicTimeline(true, max_id);
statuses = api.getPublicTimeline(true, max_id);
break;
case PUBLIC:
statuses = new API(context).getPublicTimeline(false, max_id);
statuses = api.getPublicTimeline(false, max_id);
break;
case FAVOURITES:
statuses = new API(context).getFavourites(max_id);
statuses = api.getFavourites(max_id);
break;
case USER:
statuses = new API(context).getStatus(targetedID, max_id);
statuses = api.getStatus(targetedID, max_id);
break;
case ONESTATUS:
statuses = new API(context).getStatusbyId(targetedID);
statuses = api.getStatusbyId(targetedID);
break;
case TAG:
statuses = new API(context).getPublicTimelineTag(tag, false, max_id);
statuses = api.getPublicTimelineTag(tag, false, max_id);
break;
case HASHTAG:
break;
@ -108,7 +110,7 @@ public class RetrieveFeedsAsyncTask extends AsyncTask<Void, Void, Void> {
@Override
protected void onPostExecute(Void result) {
listener.onRetrieveFeeds(statuses);
listener.onRetrieveFeeds(statuses, api.getError());
}
}

View File

@ -36,6 +36,7 @@ public class RetrieveHomeTimelineServiceAsyncTask extends AsyncTask<Void, Void,
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;
@ -49,13 +50,14 @@ public class RetrieveHomeTimelineServiceAsyncTask extends AsyncTask<Void, Void,
@Override
protected Void doInBackground(Void... params) {
statuses = new API(context, instance, token).getHomeTimelineSinceId(since_id);
api = new API(context, instance, token);
statuses = api.getHomeTimelineSinceId(since_id);
return null;
}
@Override
protected void onPostExecute(Void result) {
listener.onRetrieveHomeTimelineService(statuses, acct, userId);
listener.onRetrieveHomeTimelineService(statuses, acct, userId, api.getError());
}
}

View File

@ -39,7 +39,7 @@ public class RetrieveNotificationsAsyncTask extends AsyncTask<Void, Void, Void>
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){
@ -54,16 +54,18 @@ public class RetrieveNotificationsAsyncTask extends AsyncTask<Void, Void, Void>
@Override
protected Void doInBackground(Void... params) {
api = new API(context, instance, token);
if( acct == null)
notifications = new API(context, instance, token).getNotifications(max_id);
notifications = api.getNotifications(max_id);
else
notifications = new API(context, instance, token).getNotificationsSince(max_id);
notifications = api.getNotificationsSince(max_id);
return null;
}
@Override
protected void onPostExecute(Void result) {
listener.onRetrieveNotifications(notifications, acct, userId);
listener.onRetrieveNotifications(notifications, acct, userId, api.getError());
}
}

View File

@ -32,7 +32,7 @@ public class RetrieveRelationshipAsyncTask extends AsyncTask<Void, Void, Void> {
private String accountId;
private Relationship relationship;
private OnRetrieveRelationshipInterface listener;
private API api;
public RetrieveRelationshipAsyncTask(Context context, String accountId, OnRetrieveRelationshipInterface onRetrieveRelationshipInterface){
this.context = context;
@ -43,13 +43,14 @@ public class RetrieveRelationshipAsyncTask extends AsyncTask<Void, Void, Void> {
@Override
protected Void doInBackground(Void... params) {
relationship = new API(context).getRelationship(accountId);
api = new API(context);
relationship = api.getRelationship(accountId);
return null;
}
@Override
protected void onPostExecute(Void result) {
listener.onRetrieveRelationship(relationship);
listener.onRetrieveRelationship(relationship, api.getError());
}
}

View File

@ -35,7 +35,7 @@ public class RetrieveSearchAccountsAsyncTask extends AsyncTask<Void, Void, Void>
private String query;
private List<Account> accounts;
private OnRetrieveSearcAccountshInterface listener;
private API api;
public RetrieveSearchAccountsAsyncTask(Context context, String query, OnRetrieveSearcAccountshInterface onRetrieveSearcAccountshInterface){
this.context = context;
@ -46,14 +46,14 @@ public class RetrieveSearchAccountsAsyncTask extends AsyncTask<Void, Void, Void>
@Override
protected Void doInBackground(Void... params) {
accounts = new API(context).searchAccounts(query);
api = new API(context);
accounts = api.searchAccounts(query);
return null;
}
@Override
protected void onPostExecute(Void result) {
listener.onRetrieveSearchAccounts(accounts);
listener.onRetrieveSearchAccounts(accounts, api.getError());
}
}

View File

@ -33,7 +33,7 @@ public class RetrieveSearchAsyncTask extends AsyncTask<Void, Void, Void> {
private String query;
private Results results;
private OnRetrieveSearchInterface listener;
private API api;
public RetrieveSearchAsyncTask(Context context, String query, OnRetrieveSearchInterface onRetrieveSearchInterface){
this.context = context;
@ -44,14 +44,14 @@ public class RetrieveSearchAsyncTask extends AsyncTask<Void, Void, Void> {
@Override
protected Void doInBackground(Void... params) {
results = new API(context).search(query);
api = new API(context);
results = api.search(query);
return null;
}
@Override
protected void onPostExecute(Void result) {
listener.onRetrieveSearch(results);
listener.onRetrieveSearch(results, api.getError());
}
}

View File

@ -36,6 +36,7 @@ public class UploadActionAsyncTask extends AsyncTask<Void, Void, Void> {
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){
this.context = context;
@ -45,14 +46,14 @@ public class UploadActionAsyncTask extends AsyncTask<Void, Void, Void> {
@Override
protected Void doInBackground(Void... params) {
attachment = new API(context).uploadMedia(inputStream);
api = new API(context);
attachment = api.uploadMedia(inputStream);
return null;
}
@Override
protected void onPostExecute(Void result) {
listener.onRetrieveAttachment(attachment);
listener.onRetrieveAttachment(attachment, api.getError());
}
}

View File

@ -16,7 +16,6 @@ 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;
@ -38,14 +37,9 @@ import java.util.ArrayList;
import java.util.List;
import cz.msebera.android.httpclient.Header;
import fr.gouv.etalab.mastodon.client.Entities.Results;
import fr.gouv.etalab.mastodon.client.Entities.*;
import fr.gouv.etalab.mastodon.client.Entities.Error;
import fr.gouv.etalab.mastodon.helper.Helper;
import fr.gouv.etalab.mastodon.client.Entities.Account;
import fr.gouv.etalab.mastodon.client.Entities.Application;
import fr.gouv.etalab.mastodon.client.Entities.Attachment;
import fr.gouv.etalab.mastodon.client.Entities.Notification;
import fr.gouv.etalab.mastodon.client.Entities.Relationship;
import fr.gouv.etalab.mastodon.client.Entities.Status;
import mastodon.etalab.gouv.fr.mastodon.R;
import static fr.gouv.etalab.mastodon.helper.Helper.USER_AGENT;
@ -76,6 +70,7 @@ public class API {
private int actionCode;
private String instance;
private String prefKeyOauthTokenT;
private Error errorApi = null;
public enum StatusAction{
FAVOURITE,
@ -127,7 +122,6 @@ public class API {
* @return Account
*/
public Account verifyCredentials() {
account = new Account();
get("/accounts/verify_credentials", null, new JsonHttpResponseHandler() {
@Override
@ -144,7 +138,7 @@ public class API {
}
@Override
public void onFailure(int statusCode, Header[] headers, Throwable error, JSONObject response){
setError(statusCode, error);
}
});
return account;
@ -173,7 +167,7 @@ public class API {
}
@Override
public void onFailure(int statusCode, Header[] headers, Throwable error, JSONObject response){
setError(statusCode, error);
}
});
return account;
@ -205,7 +199,7 @@ public class API {
}
@Override
public void onFailure(int statusCode, Header[] headers, Throwable error, JSONObject response){
setError(statusCode, error);
}
});
return relationship;
@ -272,6 +266,7 @@ public class API {
}
@Override
public void onFailure(int statusCode, Header[] headers, Throwable error, JSONObject response){
setError(statusCode, error);
}
});
return statuses;
@ -298,7 +293,7 @@ public class API {
}
@Override
public void onFailure(int statusCode, Header[] headers, Throwable error, JSONObject response){
setError(statusCode, error);
}
});
return statuses;
@ -319,7 +314,7 @@ public class API {
}
@Override
public void onFailure(int statusCode, Header[] headers, Throwable error, JSONObject response){
setError(statusCode, error);
}
});
return statusContext;
@ -375,7 +370,7 @@ public class API {
}
@Override
public void onFailure(int statusCode, Header[] headers, Throwable error, JSONObject response){
setError(statusCode, error);
}
});
return statuses;
@ -425,7 +420,7 @@ public class API {
}
@Override
public void onFailure(int statusCode, Header[] headers, Throwable error, JSONObject response){
setError(statusCode, error);
}
});
return statuses;
@ -477,7 +472,7 @@ public class API {
}
@Override
public void onFailure(int statusCode, Header[] headers, Throwable error, JSONObject response){
setError(statusCode, error);
}
});
return statuses;
@ -554,7 +549,7 @@ public class API {
}
@Override
public void onFailure(int statusCode, Header[] headers, Throwable error, JSONObject response){
setError(statusCode, error);
}
});
return accounts;
@ -600,7 +595,7 @@ public class API {
}
@Override
public void onFailure(int statusCode, Header[] headers, Throwable error, JSONObject response){
setError(statusCode, error);
}
});
return statuses;
@ -721,6 +716,7 @@ public class API {
@Override
public void onFailure(int statusCode, Header[] headers, Throwable error, JSONObject response) {
actionCode = statusCode;
setError(statusCode, error);
}
});
}else{
@ -739,6 +735,7 @@ public class API {
@Override
public void onFailure(int statusCode, Header[] headers, Throwable error, JSONObject response) {
actionCode = statusCode;
setError(statusCode, error);
}
});
}
@ -795,7 +792,7 @@ public class API {
}
@Override
public void onFailure(int statusCode, Header[] headers, Throwable error, JSONObject response){
error.printStackTrace();
setError(statusCode, error);
}
});
return notifications;
@ -822,6 +819,7 @@ public class API {
}
@Override
public void onFailure(int statusCode, Header[] headers, Throwable error, JSONObject response){
setError(statusCode, error);
}
});
return attachment;
@ -846,7 +844,7 @@ public class API {
}
@Override
public void onFailure(int statusCode, Header[] headers, Throwable error, JSONObject response){
setError(statusCode, error);
}
});
return results;
@ -879,7 +877,7 @@ public class API {
}
@Override
public void onFailure(int statusCode, Header[] headers, Throwable error, JSONObject response){
setError(statusCode, error);
}
});
return accounts;
@ -1224,8 +1222,8 @@ public class API {
* @param error Throwable error
*/
private void setError(int statusCode, Throwable error){
fr.gouv.etalab.mastodon.client.Entities.Error errorResponse = new fr.gouv.etalab.mastodon.client.Entities.Error();
errorResponse.setError(statusCode + " - " + error.getMessage());
errorApi = new Error();
errorApi.setError(statusCode + " - " + error.getMessage());
}
@ -1270,6 +1268,10 @@ public class API {
}
}
public Error getError(){
return errorApi;
}
private String getAbsoluteUrl(String action) {
return "https://" + this.instance + "/api/v1" + action;

View File

@ -16,11 +16,12 @@ package fr.gouv.etalab.mastodon.client.Entities;
/**
* Created by Thomas on 23/04/2017.
* Manage errors
*/
public class Error {
private String error;
private String error = null;
public String getError() {
return error;

View File

@ -18,6 +18,7 @@ import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
@ -31,6 +32,8 @@ import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.display.SimpleBitmapDisplayer;
@ -41,6 +44,7 @@ import java.util.List;
import fr.gouv.etalab.mastodon.asynctasks.RetrieveAccountsAsyncTask;
import fr.gouv.etalab.mastodon.client.API;
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.OnPostActionInterface;
import mastodon.etalab.gouv.fr.mastodon.R;
@ -180,7 +184,14 @@ public class AccountsListAdapter extends BaseAdapter implements OnPostActionInte
}
@Override
public void onPostAction(int statusCode, API.StatusAction statusAction, String targetedId) {
public void onPostAction(int statusCode, API.StatusAction statusAction, String targetedId, Error error) {
if( error != 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(context, error.getError(),Toast.LENGTH_LONG).show();
return;
}
Helper.manageMessageStatusCode(context, statusCode, statusAction);
//When unmuting or unblocking an account, it is removed from the list
List<Account> accountsToRemove = new ArrayList<>();

View File

@ -44,6 +44,7 @@ import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.VideoView;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
@ -58,6 +59,7 @@ import java.util.List;
import fr.gouv.etalab.mastodon.activities.MainActivity;
import fr.gouv.etalab.mastodon.activities.ShowConversationActivity;
import fr.gouv.etalab.mastodon.activities.TootActivity;
import fr.gouv.etalab.mastodon.client.Entities.Error;
import fr.gouv.etalab.mastodon.helper.Helper;
import mastodon.etalab.gouv.fr.mastodon.R;
import fr.gouv.etalab.mastodon.activities.ShowAccountActivity;
@ -522,7 +524,15 @@ public class StatusListAdapter extends BaseAdapter implements OnPostActionInterf
}
@Override
public void onPostAction(int statusCode,API.StatusAction statusAction, String targetedId) {
public void onPostAction(int statusCode, API.StatusAction statusAction, String targetedId, Error error) {
if( error != 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(context, error.getError(),Toast.LENGTH_LONG).show();
return;
}
Helper.manageMessageStatusCode(context, statusCode, statusAction);
//When muting or blocking an account, its status are removed from the list
List<Status> statusesToRemove = new ArrayList<>();

View File

@ -30,11 +30,13 @@ import android.widget.AbsListView;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
import java.util.ArrayList;
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.helper.Helper;
import mastodon.etalab.gouv.fr.mastodon.R;
import fr.gouv.etalab.mastodon.asynctasks.RetrieveAccountsAsyncTask;
@ -139,7 +141,12 @@ public class DisplayAccountsFragment extends Fragment implements OnRetrieveAccou
@Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
if (view.getId() == lv_accounts.getId() && totalItemCount > visibleItemCount) {
if( firstVisibleItem == 0) {
Intent intent = new Intent(Helper.HEADER_ACCOUNT);
intent.putExtra("hide", false);
LocalBroadcastManager.getInstance(context).sendBroadcast(intent);
}else if (view.getId() == lv_accounts.getId() && totalItemCount > visibleItemCount) {
final int currentFirstVisibleItem = lv_accounts.getFirstVisiblePosition();
if (currentFirstVisibleItem > lastFirstVisibleItem) {
@ -213,8 +220,17 @@ public class DisplayAccountsFragment extends Fragment implements OnRetrieveAccou
@Override
public void onRetrieveAccounts(List<Account> accounts) {
public void onRetrieveAccounts(List<Account> accounts, Error error) {
mainLoader.setVisibility(View.GONE);
nextElementLoader.setVisibility(View.GONE);
if( error != 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();
return;
}
if( firstLoad && (accounts == null || accounts.size() == 0))
textviewNoAction.setVisibility(View.VISIBLE);
else
@ -223,8 +239,6 @@ public class DisplayAccountsFragment extends Fragment implements OnRetrieveAccou
max_id =accounts.get(accounts.size()-1).getId();
else
max_id = null;
mainLoader.setVisibility(View.GONE);
nextElementLoader.setVisibility(View.GONE);
if( accounts != null) {
for(Account tmpAccount: accounts){

View File

@ -26,11 +26,13 @@ import android.view.ViewGroup;
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.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;
@ -145,8 +147,17 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve
@Override
public void onRetrieveNotifications(List<Notification> notifications, String acct, String userId) {
public void onRetrieveNotifications(List<Notification> notifications, String acct, String userId, Error error) {
mainLoader.setVisibility(View.GONE);
nextElementLoader.setVisibility(View.GONE);
if( error != 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();
return;
}
if( firstLoad && (notifications == null || notifications.size() == 0))
textviewNoAction.setVisibility(View.VISIBLE);
else
@ -155,8 +166,7 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve
max_id =notifications.get(notifications.size()-1).getId();
else
max_id = null;
mainLoader.setVisibility(View.GONE);
nextElementLoader.setVisibility(View.GONE);
if( notifications != null) {
for(Notification tmpNotification: notifications){

View File

@ -29,6 +29,7 @@ import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.Toast;
import java.util.ArrayList;
@ -36,6 +37,7 @@ 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.drawers.StatusListAdapter;
import fr.gouv.etalab.mastodon.helper.Helper;
import fr.gouv.etalab.mastodon.sqlite.AccountDAO;
@ -145,7 +147,11 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
@Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
if (view.getId() == lv_status.getId() && totalItemCount > visibleItemCount) {
if( firstVisibleItem == 0) {
Intent intent = new Intent(Helper.HEADER_ACCOUNT);
intent.putExtra("hide", false);
LocalBroadcastManager.getInstance(context).sendBroadcast(intent);
}else if (view.getId() == lv_status.getId() && totalItemCount > visibleItemCount) {
final int currentFirstVisibleItem = lv_status.getFirstVisiblePosition();
if (currentFirstVisibleItem > lastFirstVisibleItem) {
@ -226,7 +232,17 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
@Override
public void onRetrieveFeeds(List<Status> statuses) {
public void onRetrieveFeeds(List<Status> statuses, Error error) {
mainLoader.setVisibility(View.GONE);
nextElementLoader.setVisibility(View.GONE);
if( error != 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();
return;
}
if( firstLoad && (statuses == null || statuses.size() == 0))
textviewNoAction.setVisibility(View.VISIBLE);
else
@ -235,8 +251,6 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
max_id =statuses.get(statuses.size()-1).getId();
else
max_id = null;
mainLoader.setVisibility(View.GONE);
nextElementLoader.setVisibility(View.GONE);
if( statuses != null) {
for(Status tmpStatus: statuses){

View File

@ -52,6 +52,7 @@ public class SettingsNotificationsFragment extends Fragment {
boolean notif_validation = sharedpreferences.getBoolean(Helper.SET_NOTIF_VALIDATION, true);
boolean notif_wifi = sharedpreferences.getBoolean(Helper.SET_WIFI_ONLY, false);
boolean notif_silent = sharedpreferences.getBoolean(Helper.SET_NOTIF_SILENT, false);
boolean show_error_messages = sharedpreferences.getBoolean(Helper.SET_SHOW_ERROR_MESSAGES, true);
boolean notif_hometimeline = sharedpreferences.getBoolean(Helper.SET_NOTIF_HOMETIMELINE, true);
final CheckBox set_notif_follow = (CheckBox) rootView.findViewById(R.id.set_notif_follow);
@ -61,6 +62,7 @@ public class SettingsNotificationsFragment extends Fragment {
final CheckBox set_notif_follow_share = (CheckBox) rootView.findViewById(R.id.set_notif_follow_share);
final CheckBox set_share_validation = (CheckBox) rootView.findViewById(R.id.set_share_validation);
final CheckBox set_notif_hometimeline = (CheckBox) rootView.findViewById(R.id.set_notif_hometimeline);
final CheckBox set_show_error_messages = (CheckBox) rootView.findViewById(R.id.set_show_error_messages);
final SwitchCompat switchCompatWIFI = (SwitchCompat) rootView.findViewById(R.id.set_wifi_only);
final SwitchCompat switchCompatSilent = (SwitchCompat) rootView.findViewById(R.id.set_silence);
@ -71,6 +73,7 @@ public class SettingsNotificationsFragment extends Fragment {
set_notif_follow_share.setChecked(notif_share);
set_share_validation.setChecked(notif_validation);
set_notif_hometimeline.setChecked(notif_hometimeline);
set_show_error_messages.setChecked(show_error_messages);
switchCompatWIFI.setChecked(notif_wifi);
switchCompatSilent.setChecked(notif_silent);
@ -130,6 +133,14 @@ public class SettingsNotificationsFragment extends Fragment {
editor.apply();
}
});
set_show_error_messages.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putBoolean(Helper.SET_SHOW_ERROR_MESSAGES, set_show_error_messages.isChecked());
editor.apply();
}
});
switchCompatWIFI.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override

View File

@ -143,6 +143,7 @@ public class Helper {
public static final String SET_NOTIF_HOMETIMELINE = "set_notif_hometimeline";
public static final String SET_NOTIF_SILENT = "set_notif_silent";
public static final String SET_SHOW_REPLY = "set_show_reply";
public static final String SET_SHOW_ERROR_MESSAGES = "set_show_error_messages";
//End points
public static final String EP_AUTHORIZE = "/oauth/authorize";

View File

@ -16,11 +16,12 @@ package fr.gouv.etalab.mastodon.interfaces;
import fr.gouv.etalab.mastodon.client.API;
import fr.gouv.etalab.mastodon.client.Entities.Error;
/**
* Created by Thomas on 29/04/2017.
* Interface when post actions has been done with a status
*/
public interface OnPostActionInterface {
void onPostAction(int statusCode, API.StatusAction statusAction, String userId);
void onPostAction(int statusCode, API.StatusAction statusAction, String userId, Error error);
}

View File

@ -15,11 +15,12 @@
package fr.gouv.etalab.mastodon.interfaces;
import fr.gouv.etalab.mastodon.client.Entities.Account;
import fr.gouv.etalab.mastodon.client.Entities.Error;
/**
* Created by Thomas on 01/05/2017.
* Interface when one account have been retrieved
*/
public interface OnRetrieveAccountInterface {
void onRetrieveAccount(Account account);
void onRetrieveAccount(Account account, Error error);
}

View File

@ -18,11 +18,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;
/**
* Created by Thomas on 27/04/2017.
* Interface when accounts have been retrieved
*/
public interface OnRetrieveAccountsInterface {
void onRetrieveAccounts(List<Account> accounts);
void onRetrieveAccounts(List<Account> accounts, Error error);
}

View File

@ -15,11 +15,12 @@
package fr.gouv.etalab.mastodon.interfaces;
import fr.gouv.etalab.mastodon.client.Entities.Attachment;
import fr.gouv.etalab.mastodon.client.Entities.Error;
/**
* Created by Thomas on 01/05/2017.
* Interface when an attachment has been retrieved
*/
public interface OnRetrieveAttachmentInterface {
void onRetrieveAttachment(Attachment attachment);
void onRetrieveAttachment(Attachment attachment, Error error);
}

View File

@ -16,11 +16,12 @@ package fr.gouv.etalab.mastodon.interfaces;
import fr.gouv.etalab.mastodon.client.Entities.Context;
import fr.gouv.etalab.mastodon.client.Entities.Error;
/**
* Created by Thomas on 04/05/2017.
* Interface when a context for a status has been retrieved
*/
public interface OnRetrieveContextInterface {
void onRetrieveFeeds(Context context);
void onRetrieveFeeds(Context context, Error error);
}

View File

@ -17,6 +17,7 @@ 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;
/**
@ -24,5 +25,5 @@ import fr.gouv.etalab.mastodon.client.Entities.Status;
* Interface when status have been retrieved
*/
public interface OnRetrieveFeedsInterface {
void onRetrieveFeeds(List<Status> statuses);
void onRetrieveFeeds(List<Status> statuses, Error error);
}

View File

@ -16,6 +16,8 @@ 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;
/**
@ -23,5 +25,5 @@ import fr.gouv.etalab.mastodon.client.Entities.Status;
* Interface when home timeline toots have been retrieved
*/
public interface OnRetrieveHomeTimelineServiceInterface {
void onRetrieveHomeTimelineService(List<Status> statuses, String acct, String userId);
void onRetrieveHomeTimelineService(List<Status> statuses, String acct, String userId, Error error);
}

View File

@ -17,6 +17,7 @@ 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;
/**
@ -24,5 +25,5 @@ import fr.gouv.etalab.mastodon.client.Entities.Notification;
* Interface when notifications have been retrieved
*/
public interface OnRetrieveNotificationsInterface {
void onRetrieveNotifications(List<Notification> notifications, String acct, String userId);
void onRetrieveNotifications(List<Notification> notifications, String acct, String userId, Error error);
}

View File

@ -15,6 +15,7 @@
package fr.gouv.etalab.mastodon.interfaces;
import fr.gouv.etalab.mastodon.client.Entities.Error;
import fr.gouv.etalab.mastodon.client.Entities.Relationship;
/**
@ -22,5 +23,5 @@ import fr.gouv.etalab.mastodon.client.Entities.Relationship;
* Interface when relationship has been retrieved for an account
*/
public interface OnRetrieveRelationshipInterface {
void onRetrieveRelationship(Relationship relationship);
void onRetrieveRelationship(Relationship relationship, Error error);
}

View File

@ -17,6 +17,7 @@ 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;
/**
@ -24,5 +25,5 @@ import fr.gouv.etalab.mastodon.client.Entities.Account;
* Interface for search accounts
*/
public interface OnRetrieveSearcAccountshInterface {
void onRetrieveSearchAccounts(List<Account> accounts);
void onRetrieveSearchAccounts(List<Account> accounts, Error error);
}

View File

@ -14,6 +14,7 @@
* see <http://www.gnu.org/licenses>. */
package fr.gouv.etalab.mastodon.interfaces;
import fr.gouv.etalab.mastodon.client.Entities.Error;
import fr.gouv.etalab.mastodon.client.Entities.Results;
/**
@ -21,5 +22,5 @@ import fr.gouv.etalab.mastodon.client.Entities.Results;
* Interface for search
*/
public interface OnRetrieveSearchInterface {
void onRetrieveSearch(Results results);
void onRetrieveSearch(Results results, Error error);
}

View File

@ -22,6 +22,7 @@ import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.AsyncTask;
import android.support.annotation.NonNull;
import android.widget.Toast;
import com.evernote.android.job.Job;
import com.evernote.android.job.JobManager;
@ -38,6 +39,7 @@ 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.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;
@ -116,8 +118,8 @@ public class HomeTimelineSyncJob extends Job implements OnRetrieveHomeTimelineSe
@Override
public void onRetrieveHomeTimelineService(List<Status> statuses, String acct, String userId) {
if( statuses == null || statuses.size() == 0)
public void onRetrieveHomeTimelineService(List<Status> statuses, String acct, String userId, Error error) {
if( error != null || statuses == null || statuses.size() == 0)
return;
Bitmap icon_notification = null;
final SharedPreferences sharedpreferences = getContext().getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);

View File

@ -39,6 +39,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.PatchBaseImageDownloader;
import fr.gouv.etalab.mastodon.helper.Helper;
import mastodon.etalab.gouv.fr.mastodon.R;
@ -127,8 +128,8 @@ public class NotificationsSyncJob extends Job implements OnRetrieveNotifications
@Override
public void onRetrieveNotifications(List<Notification> notifications, String acct, String userId) {
if( notifications == null || notifications.size() == 0)
public void onRetrieveNotifications(List<Notification> notifications, String acct, String userId, Error error) {
if( error != null || notifications == null || notifications.size() == 0)
return;
Bitmap icon_notification = null;
final SharedPreferences sharedpreferences = getContext().getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);

View File

@ -99,6 +99,12 @@
android:text="@string/set_share_validation"
android:layout_height="wrap_content" />
<CheckBox
android:id="@+id/set_show_error_messages"
android:layout_width="wrap_content"
android:text="@string/set_show_error_messages"
android:layout_height="wrap_content" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"

View File

@ -208,7 +208,7 @@
<string name="set_title_news">Actualités</string>
<string name="set_notification_news">Notifier lors de nouveaux pouets sur la page d\'accueil</string>
<string name="set_show_error_messages">Afficher les messages d\'erreur</string>
<string name="action_follow">Suivre</string>
<string name="action_unfollow">Se désabonner</string>
<string name="action_block">Bloquer</string>