Adds follow requests for locked accounts

This commit is contained in:
tom79 2017-06-07 11:12:40 +02:00
parent 3b6ecfe0a2
commit f2a20c3ed3
19 changed files with 571 additions and 33 deletions

View File

@ -50,6 +50,7 @@ import fr.gouv.etalab.mastodon.asynctasks.UpdateAccountInfoByIDAsyncTask;
import fr.gouv.etalab.mastodon.client.Entities.Account;
import fr.gouv.etalab.mastodon.client.PatchBaseImageDownloader;
import fr.gouv.etalab.mastodon.fragments.DisplayAccountsFragment;
import fr.gouv.etalab.mastodon.fragments.DisplayFollowRequestSentFragment;
import fr.gouv.etalab.mastodon.fragments.DisplayNotificationsFragment;
import fr.gouv.etalab.mastodon.helper.Helper;
import fr.gouv.etalab.mastodon.interfaces.OnUpdateAccountInfoInterface;
@ -147,7 +148,6 @@ public class MainActivity extends AppCompatActivity
menuAccounts(MainActivity.this);
}
});
boolean matchingIntent = mamageNewIntent(getIntent());
if (savedInstanceState == null && !matchingIntent) {
navigationView.setCheckedItem(R.id.nav_home);
@ -468,6 +468,12 @@ public class MainActivity extends AppCompatActivity
fragmentTag = "NOTIFICATIONS";
fragmentManager.beginTransaction()
.replace(R.id.main_app_container, notificationsFragment, fragmentTag).addToBackStack(fragmentTag).commit();
}else if( id == R.id.nav_follow_request){
toot.setVisibility(View.GONE);
DisplayFollowRequestSentFragment followRequestSentFragment = new DisplayFollowRequestSentFragment();
fragmentTag = "FOLLOW_REQUEST_SENT";
fragmentManager.beginTransaction()
.replace(R.id.main_app_container, followRequestSentFragment, fragmentTag).addToBackStack(fragmentTag).commit();
}

View File

@ -16,11 +16,8 @@ package fr.gouv.etalab.mastodon.asynctasks;
import android.content.Context;
import android.os.AsyncTask;
import android.util.Log;
import fr.gouv.etalab.mastodon.client.API;
import fr.gouv.etalab.mastodon.client.Entities.Account;
import fr.gouv.etalab.mastodon.helper.Helper;
import fr.gouv.etalab.mastodon.interfaces.OnPostActionInterface;
@ -34,25 +31,24 @@ public class PostActionAsyncTask extends AsyncTask<Void, Void, Void> {
private Context context;
private OnPostActionInterface listener;
private int statusCode;
private API.StatusAction statusAction;
private String statusId;
private API.StatusAction apiAction;
private String targetedId;
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){
public PostActionAsyncTask(Context context, API.StatusAction apiAction, String targetedId, OnPostActionInterface onPostActionInterface){
this.context = context;
this.listener = onPostActionInterface;
this.statusAction = statusAction;
this.statusId = statusId;
this.apiAction = apiAction;
this.targetedId = targetedId;
}
public PostActionAsyncTask(Context context, API.StatusAction statusAction, String statusId, fr.gouv.etalab.mastodon.client.Entities.Status status, String comment, OnPostActionInterface onPostActionInterface){
public PostActionAsyncTask(Context context, API.StatusAction apiAction, String targetedId, fr.gouv.etalab.mastodon.client.Entities.Status status, String comment, OnPostActionInterface onPostActionInterface){
this.context = context;
this.listener = onPostActionInterface;
this.statusAction = statusAction;
this.statusId = statusId;
this.apiAction = apiAction;
this.targetedId = targetedId;
this.comment = comment;
this.status = status;
}
@ -61,18 +57,18 @@ public class PostActionAsyncTask extends AsyncTask<Void, Void, Void> {
protected Void doInBackground(Void... params) {
api = new API(context);
if(statusAction == API.StatusAction.REPORT)
if(apiAction == API.StatusAction.REPORT)
statusCode = api.reportAction(status, comment);
else if(statusAction == API.StatusAction.CREATESTATUS)
else if(apiAction == API.StatusAction.CREATESTATUS)
statusCode = api.statusAction(status);
else
statusCode = api.postAction(statusAction, statusId);
statusCode = api.postAction(apiAction, targetedId);
return null;
}
@Override
protected void onPostExecute(Void result) {
listener.onPostAction(statusCode, statusAction, statusId, api.getError());
listener.onPostAction(statusCode, apiAction, targetedId, api.getError());
}
}

View File

@ -0,0 +1,56 @@
/* 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 fr.gouv.etalab.mastodon.client.API;
import fr.gouv.etalab.mastodon.client.APIResponse;
import fr.gouv.etalab.mastodon.interfaces.OnRetrieveAccountsInterface;
/**
* Created by Thomas on 07/06/2017.
* Retrieves follow requests sent for the authenticated account
*/
public class RetrieveFollowRequestSentAsyncTask extends AsyncTask<Void, Void, Void> {
private Context context;
private APIResponse apiResponse;
private String max_id;
private OnRetrieveAccountsInterface listener;
public RetrieveFollowRequestSentAsyncTask(Context context, String max_id, OnRetrieveAccountsInterface onRetrieveAccountsInterface){
this.context = context;
this.max_id = max_id;
this.listener = onRetrieveAccountsInterface;
}
@Override
protected Void doInBackground(Void... params) {
apiResponse = new API(context).getFollowRequest(max_id);
return null;
}
@Override
protected void onPostExecute(Void result) {
listener.onRetrieveAccounts(apiResponse);
}
}

View File

@ -90,6 +90,8 @@ public class API {
UNFOLLOW,
CREATESTATUS,
UNSTATUS,
AUTHORIZE,
REJECT,
REPORT
}
@ -294,7 +296,7 @@ public class API {
* @param max_id String id max
* @param since_id String since the id
* @param limit int limit - max value 40
* @return List<Status>
* @return APIResponse
*/
private APIResponse getStatus(String accountId, boolean onlyMedia,
boolean exclude_replies, String max_id, String since_id, int limit) {
@ -413,7 +415,7 @@ public class API {
* @param max_id String id max
* @param since_id String since the id
* @param limit int limit - max value 40
* @return List<Status>
* @return APIResponse
*/
private APIResponse getHomeTimeline(String max_id, String since_id, int limit) {
@ -466,7 +468,7 @@ public class API {
* @param max_id String id max
* @param since_id String since the id
* @param limit int limit - max value 40
* @return List<Status>
* @return APIResponse
*/
private APIResponse getPublicTimeline(boolean local, String max_id, String since_id, int limit){
@ -522,7 +524,7 @@ public class API {
* @param max_id String id max
* @param since_id String since the id
* @param limit int limit - max value 40
* @return List<Status>
* @return APIResponse
*/
private APIResponse getPublicTimelineTag(String tag, boolean local, String max_id, String since_id, int limit){
@ -607,7 +609,7 @@ public class API {
* @param max_id String id max
* @param since_id String since the id
* @param limit int limit - max value 40
* @return List<Status>
* @return APIResponse
*/
private APIResponse getAccounts(String action, String max_id, String since_id, int limit){
@ -645,6 +647,57 @@ public class API {
}
/**
* Retrieves follow requests for the authenticated account *synchronously*
* @param max_id String id max
* @return APIResponse
*/
public APIResponse getFollowRequest(String max_id){
return getFollowRequest(max_id, null, accountPerPage);
}
/**
* Retrieves follow requests for the authenticated account *synchronously*
* @param max_id String id max
* @param since_id String since the id
* @param limit int limit - max value 40
* @return APIResponse
*/
private APIResponse getFollowRequest(String max_id, String since_id, int limit){
RequestParams params = new RequestParams();
if( max_id != null )
params.put("max_id", max_id);
if( since_id != null )
params.put("since_id", since_id);
if( 0 > limit || limit > 40)
limit = 40;
params.put("limit",String.valueOf(limit));
accounts = new ArrayList<>();
get("/follow_requests", params, new JsonHttpResponseHandler() {
@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
public void onFailure(int statusCode, Header[] headers, Throwable error, JSONObject response){
setError(statusCode, error);
}
});
apiResponse.setAccounts(accounts);
return apiResponse;
}
/**
* Retrieves favourited status for the authenticated account *synchronously*
* @param max_id String id max
@ -658,7 +711,7 @@ public class API {
* @param max_id String id max
* @param since_id String since the id
* @param limit int limit - max value 40
* @return List<Status>
* @return APIResponse
*/
private APIResponse getFavourites(String max_id, String since_id, int limit){
@ -706,6 +759,7 @@ public class API {
return postAction(statusAction, targetedId, null, null);
}
/**
* Makes the post action
* @param status Status object related to the status
@ -766,6 +820,12 @@ public class API {
case UNSTATUS:
action = String.format("/statuses/%s", targetedId);
break;
case AUTHORIZE:
action = String.format("/follow_requests/%s/authorize", targetedId);
break;
case REJECT:
action = String.format("/follow_requests/%s/reject", targetedId);
break;
case REPORT:
action = "/reports";
params = new RequestParams();
@ -774,7 +834,6 @@ public class API {
params.put("status_ids[]", status.getId());
break;
case CREATESTATUS:
params = new RequestParams();
action = "/statuses";
params.put("status", status.getContent());
@ -860,7 +919,7 @@ public class API {
* @param max_id String id max
* @param since_id String since the id
* @param limit int limit - max value 40
* @return List<Notification>
* @return APIResponse
*/
private APIResponse getNotifications(String max_id, String since_id, int limit){
@ -897,6 +956,11 @@ public class API {
return apiResponse;
}
/**
* Upload media
* @param inputStream InputStream
* @return Attachment
*/
public Attachment uploadMedia(InputStream inputStream){
RequestParams params = new RequestParams();

View File

@ -0,0 +1,155 @@
package fr.gouv.etalab.mastodon.drawers;
/* 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>. */
import android.content.Context;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
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;
import java.util.ArrayList;
import java.util.List;
import fr.gouv.etalab.mastodon.asynctasks.PostActionAsyncTask;
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;
/**
* Created by Thomas on 07/05/2017.
* Adapter for accounts asking a follow request
*/
public class AccountsFollowRequestAdapter extends BaseAdapter implements OnPostActionInterface {
private List<Account> accounts;
private LayoutInflater layoutInflater;
private ImageLoader imageLoader;
private DisplayImageOptions options;
private Context context;
private AccountsFollowRequestAdapter accountsFollowRequestAdapter;
public AccountsFollowRequestAdapter(Context context, List<Account> accounts){
this.accounts = accounts;
layoutInflater = LayoutInflater.from(context);
imageLoader = ImageLoader.getInstance();
this.context = context;
options = new DisplayImageOptions.Builder().displayer(new SimpleBitmapDisplayer()).cacheInMemory(false)
.cacheOnDisk(true).resetViewBeforeLoading(true).build();
accountsFollowRequestAdapter = this;
}
@Override
public int getCount() {
return accounts.size();
}
@Override
public Object getItem(int position) {
return accounts.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
final Account account = accounts.get(position);
final ViewHolder holder;
if (convertView == null) {
convertView = layoutInflater.inflate(R.layout.drawer_account_follow_request, parent, false);
holder = new ViewHolder();
holder.account_pp = (ImageView) convertView.findViewById(R.id.account_pp);
holder.account_un = (TextView) convertView.findViewById(R.id.account_un);
holder.btn_authorize = (Button) convertView.findViewById(R.id.btn_authorize);
holder.btn_reject = (Button) convertView.findViewById(R.id.btn_reject);
holder.account_container = (LinearLayout) convertView.findViewById(R.id.account_container);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.account_un.setText(String.format("@%s", account.getUsername()));
//Profile picture
imageLoader.displayImage(account.getAvatar(), holder.account_pp, options);
holder.btn_authorize.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
new PostActionAsyncTask(context, API.StatusAction.AUTHORIZE, account.getId(), AccountsFollowRequestAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
});
holder.btn_reject.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
new PostActionAsyncTask(context, API.StatusAction.REJECT, account.getId(), AccountsFollowRequestAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
});
return convertView;
}
@Override
public void onPostAction(int statusCode, API.StatusAction statusAction, String userId, 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 authorizing or rejecting an account, this account is removed from the list
List<Account> accountToRemove = new ArrayList<>();
if( statusAction == API.StatusAction.AUTHORIZE || statusAction == API.StatusAction.REJECT){
for(Account account: accounts){
if( account.getId().equals(userId))
accountToRemove.add(account);
}
accounts.removeAll(accountToRemove);
accountsFollowRequestAdapter.notifyDataSetChanged();
}
}
private class ViewHolder {
ImageView account_pp;
Button btn_authorize;
Button btn_reject;
TextView account_un;
LinearLayout account_container;
}
}

View File

@ -0,0 +1,178 @@
package fr.gouv.etalab.mastodon.fragments;
/* 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>. */
import android.content.Context;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.widget.SwipeRefreshLayout;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
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.asynctasks.RetrieveFollowRequestSentAsyncTask;
import fr.gouv.etalab.mastodon.client.APIResponse;
import fr.gouv.etalab.mastodon.client.Entities.Account;
import fr.gouv.etalab.mastodon.drawers.AccountsFollowRequestAdapter;
import fr.gouv.etalab.mastodon.helper.Helper;
import fr.gouv.etalab.mastodon.interfaces.OnRetrieveAccountsInterface;
import mastodon.etalab.gouv.fr.mastodon.R;
/**
* Created by Thomas on 07/06/2017.
* Fragment to display follow requests for the authenticated account
*/
public class DisplayFollowRequestSentFragment extends Fragment implements OnRetrieveAccountsInterface {
private boolean flag_loading;
private Context context;
private AsyncTask<Void, Void, Void> asyncTask;
private AccountsFollowRequestAdapter accountsFollowRequestAdapter;
private String max_id;
private List<Account> accounts;
private RelativeLayout mainLoader, nextElementLoader, textviewNoAction;
private boolean firstLoad;
private SwipeRefreshLayout swipeRefreshLayout;
private int accountPerPage;
private TextView no_action_text;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
//View for fragment is the same that fragment accounts
View rootView = inflater.inflate(R.layout.fragment_accounts, container, false);
context = getContext();
accounts = new ArrayList<>();
max_id = null;
firstLoad = true;
flag_loading = true;
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);
final ListView lv_accounts = (ListView) rootView.findViewById(R.id.lv_accounts);
no_action_text = (TextView) rootView.findViewById(R.id.no_action_text);
mainLoader = (RelativeLayout) rootView.findViewById(R.id.loader);
nextElementLoader = (RelativeLayout) rootView.findViewById(R.id.loading_next_accounts);
textviewNoAction = (RelativeLayout) rootView.findViewById(R.id.no_action);
mainLoader.setVisibility(View.VISIBLE);
nextElementLoader.setVisibility(View.GONE);
accountsFollowRequestAdapter = new AccountsFollowRequestAdapter(context, this.accounts);
lv_accounts.setAdapter(accountsFollowRequestAdapter);
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;
asyncTask = new RetrieveFollowRequestSentAsyncTask(context, max_id, DisplayFollowRequestSentFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
nextElementLoader.setVisibility(View.VISIBLE);
}
} else {
nextElementLoader.setVisibility(View.GONE);
}
}
});
swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
max_id = null;
accounts = new ArrayList<>();
firstLoad = true;
flag_loading = true;
asyncTask = new RetrieveFollowRequestSentAsyncTask(context, max_id, DisplayFollowRequestSentFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
});
swipeRefreshLayout.setColorSchemeResources(R.color.colorAccent,
R.color.colorPrimary,
R.color.colorPrimaryDark);
asyncTask = new RetrieveFollowRequestSentAsyncTask(context, max_id, DisplayFollowRequestSentFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
return rootView;
}
@Override
public void onCreate(Bundle saveInstance)
{
super.onCreate(saveInstance);
}
@Override
public void onAttach(Context context) {
super.onAttach(context);
this.context = context;
}
public void onStop() {
super.onStop();
if(asyncTask != null && asyncTask.getStatus() == AsyncTask.Status.RUNNING)
asyncTask.cancel(true);
}
@Override
public void onRetrieveAccounts(APIResponse apiResponse) {
mainLoader.setVisibility(View.GONE);
nextElementLoader.setVisibility(View.GONE);
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(), apiResponse.getError().getError(),Toast.LENGTH_LONG).show();
return;
}
List<Account> accounts = apiResponse.getAccounts();
if( firstLoad && (accounts == null || accounts.size() == 0)) {
no_action_text.setText(context.getString(R.string.no_follow_request));
textviewNoAction.setVisibility(View.VISIBLE);
}else
textviewNoAction.setVisibility(View.GONE);
max_id = apiResponse.getMax_id();
if( accounts != null) {
for(Account tmpAccount: accounts){
this.accounts.add(tmpAccount);
}
accountsFollowRequestAdapter.notifyDataSetChanged();
}
swipeRefreshLayout.setRefreshing(false);
firstLoad = false;
flag_loading = accounts != null && accounts.size() < accountPerPage;
}
}

View File

@ -272,7 +272,7 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
flag_loading = statuses != null && statuses.size() < tootsPerPage;
//Store last toot id for home timeline to avoid to notify for those that have been already seen
if(statuses != null && statuses.size() > 0 && type == RetrieveFeedsAsyncTask.Type.HOME ){
final SharedPreferences sharedpreferences = getContext().getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
//acct is null when used in Fragment, data need to be retrieved via shared preferences and db
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
SQLiteDatabase db = Sqlite.getInstance(context, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();

View File

@ -532,10 +532,6 @@ public class Helper {
Toast.makeText(activity, activity.getString(R.string.toast_account_changed, "@" + account.getAcct() + "@" + account.getInstance()), Toast.LENGTH_LONG).show();
changeUser(activity, userId);
arrow.setImageResource(R.drawable.ic_arrow_drop_down);
navigationView.getMenu().clear();
navigationView.inflateMenu(R.menu.activity_main_drawer);
navigationView.setCheckedItem(R.id.nav_home);
navigationView.getMenu().performIdentifierAction(R.id.nav_home, 0);
return true;
}
return false;
@ -595,9 +591,19 @@ public class Helper {
*/
public static void changeUser(Activity activity, String userID) {
final NavigationView navigationView = (NavigationView) activity.findViewById(R.id.nav_view);
navigationView.getMenu().clear();
navigationView.inflateMenu(R.menu.activity_main_drawer);
navigationView.setCheckedItem(R.id.nav_home);
navigationView.getMenu().performIdentifierAction(R.id.nav_home, 0);
SQLiteDatabase db = Sqlite.getInstance(activity, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
Account account = new AccountDAO(activity,db).getAccountByID(userID);
//Locked account can see follow request
if (account.isLocked()) {
navigationView.getMenu().findItem(R.id.nav_follow_request).setVisible(true);
} else {
navigationView.getMenu().findItem(R.id.nav_follow_request).setVisible(false);
}
SharedPreferences sharedpreferences = activity.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putString(Helper.PREF_KEY_OAUTH_TOKEN, account.getToken());
@ -607,7 +613,6 @@ public class Helper {
DisplayImageOptions options = new DisplayImageOptions.Builder().displayer(new SimpleBitmapDisplayer()).cacheInMemory(false)
.cacheOnDisk(true).resetViewBeforeLoading(true).build();
imageLoader = ImageLoader.getInstance();
NavigationView navigationView = (NavigationView) activity.findViewById(R.id.nav_view);
View headerLayout = navigationView.getHeaderView(0);
updateHeaderAccountInfo(activity, account, headerLayout, imageLoader, options);
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 328 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 295 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 187 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 311 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 441 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 593 B

View File

@ -0,0 +1,68 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
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>.
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:id="@+id/account_container"
android:orientation="horizontal">
<ImageView
android:layout_gravity="center"
android:id="@+id/account_pp"
android:layout_width="30dp"
android:layout_height="30dp"
tools:ignore="ContentDescription" />
<TextView
android:id="@+id/account_un"
android:layout_marginStart="10dp"
android:layout_marginLeft="10dp"
android:maxLines="1"
android:layout_gravity="center_vertical"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content" />
<LinearLayout
android:layout_width="wrap_content"
android:gravity="end"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="@+id/btn_authorize"
android:text="@string/authorize"
android:layout_marginStart="5dp"
android:layout_marginLeft="5dp"
android:layout_gravity="end"
android:gravity="center"
style="@style/Base.Widget.AppCompat.Button.Colored"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button
android:id="@+id/btn_reject"
android:layout_marginStart="5dp"
android:layout_marginLeft="5dp"
android:text="@string/reject"
android:layout_gravity="end"
android:gravity="center"
style="@style/Base.Widget.AppCompat.Button.Small"
android:textColor="@color/red_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>

View File

@ -41,6 +41,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/no_action_text"
android:padding="10dp"
android:gravity="center"
android:textSize="25sp"

View File

@ -22,6 +22,10 @@
android:id="@+id/nav_notification"
android:icon="@drawable/ic_notifications"
android:title="@string/notifications" />
<item
android:id="@+id/nav_follow_request"
android:icon="@drawable/ic_group_add"
android:title="@string/follow_request" />
</group>
</menu>
</item>

View File

@ -21,4 +21,5 @@
<color name="background_image">#282c37</color>
<color name="red_1">#F44336</color>
</resources>

View File

@ -48,6 +48,7 @@
<string name="muted_menu">Utilisateurs muets</string>
<string name="blocked_menu">Utilisateurs bloqués</string>
<string name="notifications">Notifications</string>
<string name="follow_request">Demandes d\'abonnements</string>
<string name="optimization">Optimisation</string>
<string name="profile">Profil</string>
<string name="make_a_choice">Que souhaitez-vous faire ?</string>
@ -157,9 +158,12 @@
<!-- Accounts -->
<string name="no_accounts">Aucun compte à afficher</string>
<string name="no_follow_request">Aucune demande d\'abonnement</string>
<string name="status_cnt">Pouets \n %d</string>
<string name="following_cnt">Abonnements \n %d</string>
<string name="followers_cnt">Abonnés \n %d</string>
<string name="authorize">Autoriser</string>
<string name="reject">Rejeter</string>
<!-- Notifications -->
<string name="no_notifications">Aucune notification à afficher</string>
@ -270,6 +274,6 @@
- <b>Android Asynchronous Http Client</b> : Pour la gestion des requêtes\n
- <b>Universal Image Loader</b> : Pour la gestion des médias\n
- <b>Android-Job</b> : Pour la gestion des services
- <b>Emoji-java</b> : Pour l'affichage des emoji
- <b>Emoji-java</b> : Pour l\'affichage des emoji
</string>
</resources>