Merge branch 'develop' of https://bitbucket.org/tom79/mastodon_etalab into develop
This commit is contained in:
commit
abd1dbb14f
|
@ -0,0 +1,54 @@
|
|||
/* Copyright 2017 Thomas Schneider
|
||||
*
|
||||
* This file is a part of Mastalab
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* Mastalab 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 Mastalab; 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.client.APIResponse;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Account;
|
||||
import fr.gouv.etalab.mastodon.interfaces.OnRetrieveManyRelationshipsInterface;
|
||||
|
||||
/**
|
||||
* Created by Thomas on 16/09/2017.
|
||||
* Retrieves many relationship between the authenticated user and other accounts
|
||||
*/
|
||||
|
||||
public class RetrieveManyRelationshipsAsyncTask extends AsyncTask<Void, Void, Void> {
|
||||
|
||||
private Context context;
|
||||
private List<Account> accounts;
|
||||
private OnRetrieveManyRelationshipsInterface listener;
|
||||
private APIResponse apiResponse;
|
||||
|
||||
public RetrieveManyRelationshipsAsyncTask(Context context, List<Account> accounts, OnRetrieveManyRelationshipsInterface onRetrieveManyRelationshipsInterface){
|
||||
this.context = context;
|
||||
this.listener = onRetrieveManyRelationshipsInterface;
|
||||
this.accounts = accounts;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Void doInBackground(Void... params) {
|
||||
apiResponse = new API(context).getRelationship(accounts);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Void result) {
|
||||
listener.onRetrieveRelationship(apiResponse);
|
||||
}
|
||||
|
||||
}
|
|
@ -69,6 +69,7 @@ public class API {
|
|||
private Attachment attachment;
|
||||
private List<Account> accounts;
|
||||
private List<Status> statuses;
|
||||
private List<Relationship> relationships;
|
||||
private List<Notification> notifications;
|
||||
private int tootPerPage, accountPerPage, notificationPerPage;
|
||||
private int actionCode;
|
||||
|
@ -270,6 +271,43 @@ public class API {
|
|||
return relationship;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a relationship between the authenticated account and an account
|
||||
* @param accounts ArrayList<Account> accounts fetched
|
||||
* @return Relationship entity
|
||||
*/
|
||||
public APIResponse getRelationship(List<Account> accounts) {
|
||||
|
||||
relationship = new Relationship();
|
||||
RequestParams params = new RequestParams();
|
||||
if( accounts != null && accounts.size() > 0 ) {
|
||||
for(Account account: accounts) {
|
||||
params.add("id[]", account.getId());
|
||||
}
|
||||
}
|
||||
get("/accounts/relationships", params, new JsonHttpResponseHandler() {
|
||||
@Override
|
||||
public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
|
||||
Relationship relationship = parseRelationshipResponse(response);
|
||||
relationships.add(relationship);
|
||||
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));
|
||||
relationships = parseRelationshipResponse(response);
|
||||
}
|
||||
@Override
|
||||
public void onFailure(int statusCode, Header[] headers, Throwable error, JSONObject response){
|
||||
setError(statusCode, error);
|
||||
}
|
||||
});
|
||||
apiResponse.setRelationships(relationships);
|
||||
return apiResponse;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves status for the account *synchronously*
|
||||
*
|
||||
|
@ -1399,29 +1437,47 @@ public class API {
|
|||
|
||||
|
||||
/**
|
||||
* Parse json response for list of accounts which could contain the developer name
|
||||
* @param jsonArray JSONArray
|
||||
* @return List<Account>
|
||||
* Parse json response an unique relationship
|
||||
* @param resobj JSONObject
|
||||
* @return Relationship
|
||||
*/
|
||||
private List<Account> parseDeveloperResponse(JSONArray jsonArray){
|
||||
private Relationship parseRelationshipResponse(JSONObject resobj){
|
||||
|
||||
List<Account> accounts = new ArrayList<>();
|
||||
Relationship relationship = new Relationship();
|
||||
try {
|
||||
int i = 0;
|
||||
Account account = null;
|
||||
while (i < jsonArray.length() ) {
|
||||
JSONObject resobj = jsonArray.getJSONObject(i);
|
||||
account = parseAccountResponse(context, resobj);
|
||||
if( account.getAcct().contains(Helper.DEVELOPER_INSTANCE))
|
||||
accounts.add(account);
|
||||
i++;
|
||||
}
|
||||
if( accounts.size() == 0)
|
||||
accounts.add(account);
|
||||
relationship.setId(resobj.get("id").toString());
|
||||
relationship.setFollowing(Boolean.valueOf(resobj.get("following").toString()));
|
||||
relationship.setFollowed_by(Boolean.valueOf(resobj.get("followed_by").toString()));
|
||||
relationship.setBlocking(Boolean.valueOf(resobj.get("blocking").toString()));
|
||||
relationship.setMuting(Boolean.valueOf(resobj.get("muting").toString()));
|
||||
relationship.setRequested(Boolean.valueOf(resobj.get("requested").toString()));
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return accounts;
|
||||
return relationship;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Parse json response for list of relationship
|
||||
* @param jsonArray JSONArray
|
||||
* @return List<Relationship>
|
||||
*/
|
||||
private List<Relationship> parseRelationshipResponse(JSONArray jsonArray){
|
||||
|
||||
List<Relationship> relationships = new ArrayList<>();
|
||||
try {
|
||||
int i = 0;
|
||||
while (i < jsonArray.length() ) {
|
||||
JSONObject resobj = jsonArray.getJSONObject(i);
|
||||
Relationship relationship = parseRelationshipResponse(resobj);
|
||||
relationships.add(relationship);
|
||||
i++;
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return relationships;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1469,26 +1525,7 @@ public class API {
|
|||
return attachment;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse json response an unique relationship
|
||||
* @param resobj JSONObject
|
||||
* @return Relationship
|
||||
*/
|
||||
private Relationship parseRelationshipResponse(JSONObject resobj){
|
||||
|
||||
Relationship relationship = new Relationship();
|
||||
try {
|
||||
relationship.setId(resobj.get("id").toString());
|
||||
relationship.setFollowing(Boolean.valueOf(resobj.get("following").toString()));
|
||||
relationship.setFollowed_by(Boolean.valueOf(resobj.get("followed_by").toString()));
|
||||
relationship.setBlocking(Boolean.valueOf(resobj.get("blocking").toString()));
|
||||
relationship.setMuting(Boolean.valueOf(resobj.get("muting").toString()));
|
||||
relationship.setRequested(Boolean.valueOf(resobj.get("requested").toString()));
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return relationship;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse json response an unique notification
|
||||
|
|
|
@ -29,6 +29,7 @@ public class APIResponse {
|
|||
private List<Status> statuses = null;
|
||||
private List<Context> contexts = null;
|
||||
private List<Notification> notifications = null;
|
||||
private List<Relationship> relationships = null;
|
||||
private fr.gouv.etalab.mastodon.client.Entities.Error error = null;
|
||||
private String since_id, max_id;
|
||||
private Instance instance;
|
||||
|
@ -96,4 +97,12 @@ public class APIResponse {
|
|||
public void setInstance(Instance instance) {
|
||||
this.instance = instance;
|
||||
}
|
||||
|
||||
public List<Relationship> getRelationships() {
|
||||
return relationships;
|
||||
}
|
||||
|
||||
public void setRelationships(List<Relationship> relationships) {
|
||||
this.relationships = relationships;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,6 +48,34 @@ public class Account implements Parcelable {
|
|||
private String instance;
|
||||
private boolean isFollowing;
|
||||
private boolean isRemote;
|
||||
private followAction followType = followAction.NOTHING;
|
||||
private boolean isMakingAction = false;
|
||||
|
||||
public followAction getFollowType() {
|
||||
return followType;
|
||||
}
|
||||
|
||||
public void setFollowType(followAction followType) {
|
||||
this.followType = followType;
|
||||
}
|
||||
|
||||
public boolean isMakingAction() {
|
||||
return isMakingAction;
|
||||
}
|
||||
|
||||
public void setMakingAction(boolean makingAction) {
|
||||
isMakingAction = makingAction;
|
||||
}
|
||||
|
||||
public enum followAction{
|
||||
FOLLOW,
|
||||
NOT_FOLLOW,
|
||||
BLOCK,
|
||||
MUTE,
|
||||
REQUEST_SENT,
|
||||
NOTHING
|
||||
}
|
||||
|
||||
|
||||
protected Account(Parcel in) {
|
||||
id = in.readString();
|
||||
|
|
|
@ -14,9 +14,7 @@ package fr.gouv.etalab.mastodon.drawers;
|
|||
* You should have received a copy of the GNU General Public License along with Mastalab; if not,
|
||||
* see <http://www.gnu.org/licenses>. */
|
||||
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.AsyncTask;
|
||||
|
@ -33,17 +31,14 @@ import android.widget.ImageView;
|
|||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.nostra13.universalimageloader.cache.disc.impl.UnlimitedDiskCache;
|
||||
import com.nostra13.universalimageloader.core.DisplayImageOptions;
|
||||
import com.nostra13.universalimageloader.core.ImageLoader;
|
||||
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
|
||||
import com.nostra13.universalimageloader.core.display.SimpleBitmapDisplayer;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
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;
|
||||
|
@ -78,7 +73,15 @@ public class AccountsListAdapter extends BaseAdapter implements OnPostActionInte
|
|||
this.targetedId = targetedId;
|
||||
}
|
||||
|
||||
public enum action{
|
||||
FOLLOW,
|
||||
UNFOLLOW,
|
||||
UNBLOCK,
|
||||
NOTHING,
|
||||
UNMUTE
|
||||
}
|
||||
|
||||
private API.StatusAction doAction;
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
|
@ -126,9 +129,8 @@ public class AccountsListAdapter extends BaseAdapter implements OnPostActionInte
|
|||
holder.account_sc = (TextView) convertView.findViewById(R.id.account_sc);
|
||||
holder.account_fgc = (TextView) convertView.findViewById(R.id.account_fgc);
|
||||
holder.account_frc = (TextView) convertView.findViewById(R.id.account_frc);
|
||||
holder.account_action_block = (FloatingActionButton) convertView.findViewById(R.id.account_action_block);
|
||||
holder.account_action_mute = (FloatingActionButton) convertView.findViewById(R.id.account_action_mute);
|
||||
|
||||
holder.account_follow = (FloatingActionButton) convertView.findViewById(R.id.account_follow);
|
||||
holder.account_follow_request = (TextView) convertView.findViewById(R.id.account_follow_request);
|
||||
holder.account_container = (LinearLayout) convertView.findViewById(R.id.account_container);
|
||||
convertView.setTag(holder);
|
||||
} else {
|
||||
|
@ -136,24 +138,40 @@ public class AccountsListAdapter extends BaseAdapter implements OnPostActionInte
|
|||
}
|
||||
|
||||
if( action == RetrieveAccountsAsyncTask.Type.BLOCKED)
|
||||
holder.account_action_block.setVisibility(View.VISIBLE);
|
||||
account.setFollowType(Account.followAction.BLOCK);
|
||||
else if( action == RetrieveAccountsAsyncTask.Type.MUTED)
|
||||
holder.account_action_mute.setVisibility(View.VISIBLE);
|
||||
account.setFollowType(Account.followAction.MUTE);
|
||||
|
||||
if (account.getFollowType() == Account.followAction.NOTHING){
|
||||
holder.account_follow.setVisibility(View.GONE);
|
||||
holder.account_follow_request.setVisibility(View.GONE);
|
||||
doAction = null;
|
||||
}else if( account.getFollowType() == Account.followAction.REQUEST_SENT){
|
||||
holder.account_follow.setVisibility(View.GONE);
|
||||
holder.account_follow_request.setVisibility(View.VISIBLE);
|
||||
doAction = null;
|
||||
}else if( account.getFollowType() == Account.followAction.FOLLOW){
|
||||
holder.account_follow.setImageResource(R.drawable.ic_user_times);
|
||||
doAction = API.StatusAction.UNFOLLOW;
|
||||
holder.account_follow.setVisibility(View.VISIBLE);
|
||||
holder.account_follow_request.setVisibility(View.GONE);
|
||||
}else if( account.getFollowType() == Account.followAction.NOT_FOLLOW){
|
||||
holder.account_follow.setImageResource(R.drawable.ic_user_plus);
|
||||
doAction = API.StatusAction.FOLLOW;
|
||||
holder.account_follow.setVisibility(View.VISIBLE);
|
||||
holder.account_follow_request.setVisibility(View.GONE);
|
||||
}else if( account.getFollowType() == Account.followAction.BLOCK){
|
||||
holder.account_follow.setImageResource(R.drawable.ic_unlock_alt);
|
||||
doAction = API.StatusAction.UNBLOCK;
|
||||
holder.account_follow.setVisibility(View.VISIBLE);
|
||||
holder.account_follow_request.setVisibility(View.GONE);
|
||||
}else if( account.getFollowType() == Account.followAction.MUTE){
|
||||
holder.account_follow.setImageResource(R.drawable.ic_mute_white);
|
||||
doAction = API.StatusAction.UNMUTE;
|
||||
holder.account_follow.setVisibility(View.VISIBLE);
|
||||
holder.account_follow_request.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
holder.account_action_mute.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
moreOptionDialog(account);
|
||||
}
|
||||
});
|
||||
|
||||
holder.account_action_block.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
moreOptionDialog(account);
|
||||
}
|
||||
});
|
||||
|
||||
holder.account_container.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
|
@ -184,6 +202,22 @@ public class AccountsListAdapter extends BaseAdapter implements OnPostActionInte
|
|||
imageLoader.displayImage(account.getAvatar(), holder.account_pp, options);
|
||||
|
||||
|
||||
|
||||
if( account.isMakingAction()){
|
||||
holder.account_follow.setEnabled(false);
|
||||
}else {
|
||||
holder.account_follow.setEnabled(true);
|
||||
}
|
||||
//Follow button
|
||||
holder.account_follow.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if( doAction != null) {
|
||||
account.setMakingAction(true);
|
||||
new PostActionAsyncTask(context, doAction, account.getId(), AccountsListAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
}
|
||||
}
|
||||
});
|
||||
holder.account_pp.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
@ -233,44 +267,9 @@ public class AccountsListAdapter extends BaseAdapter implements OnPostActionInte
|
|||
TextView account_sc;
|
||||
TextView account_fgc;
|
||||
TextView account_frc;
|
||||
FloatingActionButton account_follow;
|
||||
TextView account_follow_request;
|
||||
LinearLayout account_container;
|
||||
FloatingActionButton account_action_block;
|
||||
FloatingActionButton account_action_mute;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* More option for acccounts (unmute / unblock)
|
||||
* @param account Account current account
|
||||
*/
|
||||
private void moreOptionDialog(final Account account){
|
||||
|
||||
String[] stringArrayConf = context.getResources().getStringArray(R.array.more_action_confirm_account);
|
||||
final API.StatusAction doAction;
|
||||
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
AlertDialog.Builder dialog = new AlertDialog.Builder(context);
|
||||
|
||||
if( action == RetrieveAccountsAsyncTask.Type.BLOCKED) {
|
||||
dialog.setMessage(stringArrayConf[1]);
|
||||
doAction = API.StatusAction.UNBLOCK;
|
||||
}else {
|
||||
dialog.setMessage(stringArrayConf[0]);
|
||||
doAction = API.StatusAction.UNMUTE;
|
||||
}
|
||||
dialog.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog,int which) {
|
||||
dialog.dismiss();
|
||||
}
|
||||
});
|
||||
dialog.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog,int which) {
|
||||
new PostActionAsyncTask(context, doAction, account.getId(), AccountsListAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
dialog.dismiss();
|
||||
}
|
||||
});
|
||||
dialog.show();
|
||||
}
|
||||
|
||||
}
|
|
@ -34,9 +34,13 @@ import android.widget.Toast;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import fr.gouv.etalab.mastodon.asynctasks.RetrieveManyRelationshipsAsyncTask;
|
||||
import fr.gouv.etalab.mastodon.client.APIResponse;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Account;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Relationship;
|
||||
import fr.gouv.etalab.mastodon.helper.Helper;
|
||||
import fr.gouv.etalab.mastodon.interfaces.OnRetrieveManyRelationshipsInterface;
|
||||
import mastodon.etalab.gouv.fr.mastodon.R;
|
||||
import fr.gouv.etalab.mastodon.asynctasks.RetrieveAccountsAsyncTask;
|
||||
import fr.gouv.etalab.mastodon.drawers.AccountsListAdapter;
|
||||
|
@ -47,7 +51,7 @@ import fr.gouv.etalab.mastodon.interfaces.OnRetrieveAccountsInterface;
|
|||
* Created by Thomas on 27/04/2017.
|
||||
* Fragment to display content related to accounts
|
||||
*/
|
||||
public class DisplayAccountsFragment extends Fragment implements OnRetrieveAccountsInterface {
|
||||
public class DisplayAccountsFragment extends Fragment implements OnRetrieveAccountsInterface, OnRetrieveManyRelationshipsInterface {
|
||||
|
||||
private boolean flag_loading;
|
||||
private Context context;
|
||||
|
@ -59,7 +63,6 @@ public class DisplayAccountsFragment extends Fragment implements OnRetrieveAccou
|
|||
private RelativeLayout mainLoader, nextElementLoader, textviewNoAction;
|
||||
private boolean firstLoad;
|
||||
private SwipeRefreshLayout swipeRefreshLayout;
|
||||
private int accountPerPage;
|
||||
private String targetedId;
|
||||
private boolean swiped;
|
||||
private ListView lv_accounts;
|
||||
|
@ -97,7 +100,6 @@ public class DisplayAccountsFragment extends Fragment implements OnRetrieveAccou
|
|||
|
||||
swipeRefreshLayout = (SwipeRefreshLayout) rootView.findViewById(R.id.swipeContainer);
|
||||
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
accountPerPage = sharedpreferences.getInt(Helper.SET_ACCOUNTS_PER_PAGE, 40);
|
||||
lv_accounts = (ListView) rootView.findViewById(R.id.lv_accounts);
|
||||
|
||||
mainLoader = (RelativeLayout) rootView.findViewById(R.id.loader);
|
||||
|
@ -166,7 +168,6 @@ public class DisplayAccountsFragment extends Fragment implements OnRetrieveAccou
|
|||
asyncTask = new RetrieveAccountsAsyncTask(context, type, targetedId, max_id, DisplayAccountsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
}
|
||||
});
|
||||
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
|
||||
swipeRefreshLayout.setColorSchemeResources(R.color.mastodonC4,
|
||||
R.color.mastodonC2,
|
||||
R.color.mastodonC3);
|
||||
|
@ -246,5 +247,46 @@ public class DisplayAccountsFragment extends Fragment implements OnRetrieveAccou
|
|||
}
|
||||
swipeRefreshLayout.setRefreshing(false);
|
||||
firstLoad = false;
|
||||
|
||||
if( type != RetrieveAccountsAsyncTask.Type.BLOCKED && type != RetrieveAccountsAsyncTask.Type.MUTED)
|
||||
new RetrieveManyRelationshipsAsyncTask(context, accounts,DisplayAccountsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRetrieveRelationship(APIResponse apiResponse) {
|
||||
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(context, apiResponse.getError().getError(),Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||
List<Relationship> relationships = apiResponse.getRelationships();
|
||||
if( relationships != null && relationships.size() > 0 ){
|
||||
for(Relationship relationship: relationships){
|
||||
for(Account account: accounts){
|
||||
if( account.getId().equals(userId)){
|
||||
account.setFollowType(Account.followAction.NOTHING);
|
||||
continue;
|
||||
}
|
||||
if( account.getId().equals(relationship.getId())){
|
||||
if( relationship.isFollowing())
|
||||
account.setFollowType(Account.followAction.FOLLOW);
|
||||
else
|
||||
account.setFollowType(Account.followAction.NOT_FOLLOW);
|
||||
if(relationship.isBlocking())
|
||||
account.setFollowType(Account.followAction.BLOCK);
|
||||
else if(relationship.isMuting())
|
||||
account.setFollowType(Account.followAction.MUTE);
|
||||
else if(relationship.isRequested())
|
||||
account.setFollowType(Account.followAction.REQUEST_SENT);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
accountsListAdapter.notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
/* Copyright 2017 Thomas Schneider
|
||||
*
|
||||
* This file is a part of Mastalab
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* Mastalab 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 Mastalab; if not,
|
||||
* see <http://www.gnu.org/licenses>. */
|
||||
package fr.gouv.etalab.mastodon.interfaces;
|
||||
|
||||
|
||||
import fr.gouv.etalab.mastodon.client.APIResponse;
|
||||
|
||||
/**
|
||||
* Created by Thomas on 16/09/2017.
|
||||
* Interface when relationships have been retrieved for several accounts
|
||||
*/
|
||||
public interface OnRetrieveManyRelationshipsInterface {
|
||||
void onRetrieveRelationship(APIResponse apiResponse);
|
||||
}
|
|
@ -154,27 +154,27 @@
|
|||
android:autoLink="web"
|
||||
android:visibility="gone"/>
|
||||
</LinearLayout>
|
||||
<android.support.design.widget.FloatingActionButton
|
||||
android:layout_marginTop="20dp"
|
||||
<TextView
|
||||
android:id="@+id/account_follow_request"
|
||||
android:textColor="?attr/colorAccent"
|
||||
android:text="@string/request_sent"
|
||||
android:visibility="gone"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:maxLines="1"
|
||||
android:layout_gravity="center"
|
||||
android:gravity="center"
|
||||
/>
|
||||
<android.support.design.widget.FloatingActionButton
|
||||
android:id="@+id/account_follow"
|
||||
android:visibility="gone"
|
||||
android:id="@+id/account_action_block"
|
||||
app:fabSize="mini"
|
||||
android:layout_width="40dp"
|
||||
android:layout_height="40dp"
|
||||
android:scaleType="center"
|
||||
android:layout_margin="5dp"
|
||||
android:scaleType="fitXY"
|
||||
android:layout_gravity="center"
|
||||
android:gravity="center"
|
||||
android:src="@drawable/ic_block_white" />
|
||||
<android.support.design.widget.FloatingActionButton
|
||||
android:layout_marginTop="20dp"
|
||||
android:visibility="gone"
|
||||
android:id="@+id/account_action_mute"
|
||||
app:fabSize="mini"
|
||||
android:layout_width="40dp"
|
||||
android:layout_height="40dp"
|
||||
android:scaleType="center"
|
||||
android:layout_gravity="center"
|
||||
android:gravity="center"
|
||||
android:src="@drawable/ic_mute_white" />
|
||||
/>
|
||||
</LinearLayout>
|
||||
</android.support.v7.widget.CardView>
|
|
@ -132,27 +132,27 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
</LinearLayout>
|
||||
<android.support.design.widget.FloatingActionButton
|
||||
android:layout_marginTop="20dp"
|
||||
<TextView
|
||||
android:id="@+id/account_follow_request"
|
||||
android:textColor="?attr/colorAccent"
|
||||
android:text="@string/request_sent"
|
||||
android:visibility="gone"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:maxLines="1"
|
||||
android:layout_gravity="center"
|
||||
android:gravity="center"
|
||||
/>
|
||||
<android.support.design.widget.FloatingActionButton
|
||||
android:id="@+id/account_follow"
|
||||
android:visibility="gone"
|
||||
android:id="@+id/account_action_block"
|
||||
app:fabSize="mini"
|
||||
android:layout_width="40dp"
|
||||
android:layout_height="40dp"
|
||||
android:scaleType="center"
|
||||
android:layout_margin="5dp"
|
||||
android:scaleType="fitXY"
|
||||
android:layout_gravity="center"
|
||||
android:gravity="center"
|
||||
android:src="@drawable/ic_block_white" />
|
||||
<android.support.design.widget.FloatingActionButton
|
||||
android:layout_marginTop="20dp"
|
||||
android:visibility="gone"
|
||||
android:id="@+id/account_action_mute"
|
||||
app:fabSize="mini"
|
||||
android:layout_width="40dp"
|
||||
android:layout_height="40dp"
|
||||
android:scaleType="center"
|
||||
android:layout_gravity="center"
|
||||
android:gravity="center"
|
||||
android:src="@drawable/ic_mute_white" />
|
||||
/>
|
||||
</LinearLayout>
|
||||
</android.support.v7.widget.CardView>
|
Loading…
Reference in New Issue