Delete accounts from list

This commit is contained in:
stom79 2017-12-15 18:53:17 +01:00
parent 8f68d890ce
commit 7aebf73e3a
9 changed files with 41 additions and 27 deletions

View File

@ -17,6 +17,7 @@ package fr.gouv.etalab.mastodon.activities;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.os.Bundle;
@ -174,8 +175,11 @@ public class ListActivity extends BaseActivity implements OnListActionInterface
finish();
return true;
case R.id.action_add_user:
Intent intent = new Intent(ListActivity.this, ManageAccountsInListActivity.class);
intent.putExtra("title", title);
intent.putExtra("id", listId);
startActivity(intent);
return true;
case R.id.action_edit_list:
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(ListActivity.this);
LayoutInflater inflater = getLayoutInflater();

View File

@ -31,6 +31,8 @@ import android.widget.TextView;
import android.widget.Toast;
import java.util.ArrayList;
import fr.gouv.etalab.mastodon.R;
import fr.gouv.etalab.mastodon.asynctasks.ManageListsAsyncTask;
import fr.gouv.etalab.mastodon.client.APIResponse;
@ -83,14 +85,16 @@ public class ManageAccountsInListActivity extends BaseActivity implements OnList
lv_accounts_search = findViewById(R.id.lv_accounts_search);
lv_accounts_current = findViewById(R.id.lv_accounts_current);
no_action = findViewById(R.id.no_action);
accountsInAListAdapter = new AccountsInAListAdapter(ManageAccountsInListActivity.this, AccountsInAListAdapter.type.CURRENT, this.accounts);
this.accounts = new ArrayList<>();
accountsInAListAdapter = new AccountsInAListAdapter(ManageAccountsInListActivity.this, AccountsInAListAdapter.type.CURRENT, listId, this.accounts);
lv_accounts_current.setAdapter(accountsInAListAdapter);
LinearLayoutManager mLayoutManager = new LinearLayoutManager(ManageAccountsInListActivity.this);
lv_accounts_current.setLayoutManager(mLayoutManager);
accountsSearchInAListAdapter = new AccountsInAListAdapter(ManageAccountsInListActivity.this, AccountsInAListAdapter.type.SEARCH, this.accounts);
accountsSearchInAListAdapter = new AccountsInAListAdapter(ManageAccountsInListActivity.this, AccountsInAListAdapter.type.SEARCH, listId, this.accounts);
lv_accounts_search.setAdapter(accountsSearchInAListAdapter);
lv_accounts_search.setLayoutManager(mLayoutManager);
LinearLayoutManager mLayoutManager1 = new LinearLayoutManager(ManageAccountsInListActivity.this);
lv_accounts_search.setLayoutManager(mLayoutManager1);
list_title.setText(title);
@ -127,7 +131,7 @@ public class ManageAccountsInListActivity extends BaseActivity implements OnList
if (apiResponse.getAccounts() != null && apiResponse.getAccounts().size() > 0) {
this.accounts.addAll(apiResponse.getAccounts());
accountsInAListAdapter.notifyDataSetChanged();
main_account_container.setVisibility(View.VISIBLE);
} else {
no_action.setVisibility(View.VISIBLE);
}

View File

@ -81,7 +81,7 @@ public class ManageListsAsyncTask extends AsyncTask<Void, Void, Void> {
}else if(apiAction == action.GET_LIST_TIMELINE){
apiResponse = new API(contextReference.get()).getListTimeline(this.listId, this.max_id, this.since_id, this.limit);
}else if(apiAction == action.GET_LIST_ACCOUNT){
apiResponse = new API(contextReference.get()).getLists(this.targetedId);
apiResponse = new API(contextReference.get()).getAccountsInList(this.listId,0);
}else if( apiAction == action.CREATE_LIST){
apiResponse = new API(contextReference.get()).createList(this.title);
}else if(apiAction == action.DELETE_LIST){

View File

@ -16,6 +16,7 @@ package fr.gouv.etalab.mastodon.client;
import android.content.Context;
import android.content.SharedPreferences;
import android.util.Log;
import org.json.JSONArray;
import org.json.JSONException;
@ -1250,7 +1251,7 @@ public class API {
}catch (Exception e) {
setDefaultError();
}
apiResponse.setLists(lists);
apiResponse.setAccounts(accounts);
return apiResponse;
}
@ -1294,7 +1295,7 @@ public class API {
for(String val: account_ids)
parameters.append("account_ids[]=").append(val).append("&");
if( parameters.length() > 0) {
parameters = new StringBuilder(parameters.substring(0, parameters.length() - 1).substring(16));
parameters = new StringBuilder(parameters.substring(0, parameters.length() - 1).substring(14));
params.put("account_ids[]", parameters.toString());
}
List<fr.gouv.etalab.mastodon.client.Entities.List> lists = new ArrayList<>();
@ -1323,15 +1324,17 @@ public class API {
for(String val: account_ids)
parameters.append("account_ids[]=").append(val).append("&");
if( parameters.length() > 0) {
parameters = new StringBuilder(parameters.substring(0, parameters.length() - 1).substring(16));
parameters = new StringBuilder(parameters.substring(0, parameters.length() - 1).substring(14));
params.put("account_ids[]", parameters.toString());
}
httpsConnection.delete(getAbsoluteUrl(String.format("/lists/%s/accounts", id)), 60, params, prefKeyOauthTokenT);
actionCode = httpsConnection.getActionCode();
} catch (HttpsConnection.HttpsConnectionException e) {
setError(e.getStatusCode(), e);
e.printStackTrace();
}catch (Exception e) {
setDefaultError();
e.printStackTrace();
}
return actionCode;
}

View File

@ -557,7 +557,6 @@ public class HttpsConnection {
httpsURLConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
httpsURLConnection.setRequestProperty("Content-Length", String.valueOf(postDataBytes.length));
httpsURLConnection.setDoOutput(true);
getSinceMaxId();
httpsURLConnection.getOutputStream().write(postDataBytes);
Reader in = new BufferedReader(new InputStreamReader(httpsURLConnection.getInputStream(), "UTF-8"));
@ -603,11 +602,11 @@ public class HttpsConnection {
httpsURLConnection.setConnectTimeout(timeout * 1000);
httpsURLConnection.setRequestProperty("Content-Length", String.valueOf(postDataBytes.length));
getSinceMaxId();
httpsURLConnection.getOutputStream().write(postDataBytes);
if (httpsURLConnection.getResponseCode() >= 200 && httpsURLConnection.getResponseCode() < 400) {
getSinceMaxId();
httpsURLConnection.disconnect();
return httpsURLConnection.getResponseCode();
}else {

View File

@ -56,7 +56,7 @@ public class AccountsInAListAdapter extends RecyclerView.Adapter implements OnLi
private Context context;
private AccountsInAListAdapter accountsInAListAdapter;
private type actionType;
private String listId;
public enum type{
@ -64,12 +64,13 @@ public class AccountsInAListAdapter extends RecyclerView.Adapter implements OnLi
SEARCH
}
public AccountsInAListAdapter(Context context, type actionType, List<Account> accounts){
public AccountsInAListAdapter(Context context, type actionType, String listId, List<Account> accounts){
this.context = context;
this.accounts = accounts;
layoutInflater = LayoutInflater.from(context);
this.accountsInAListAdapter = this;
this.actionType = actionType;
this.listId = listId;
}
@Override
@ -109,7 +110,7 @@ public class AccountsInAListAdapter extends RecyclerView.Adapter implements OnLi
@Override
public void onClick(View view) {
if( actionType == type.CURRENT){
new ManageListsAsyncTask(context, ManageListsAsyncTask.action.DELETE_USERS, new String[]{account.getId()}, null, null, null, AccountsInAListAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
new ManageListsAsyncTask(context, ManageListsAsyncTask.action.DELETE_USERS, new String[]{account.getId()}, null, listId, null, AccountsInAListAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
accounts.remove(account);
accountsInAListAdapter.notifyDataSetChanged();
}else if(actionType == type.SEARCH){
@ -133,13 +134,9 @@ public class AccountsInAListAdapter extends RecyclerView.Adapter implements OnLi
@Override
public void onActionDone(ManageListsAsyncTask.action actionType, APIResponse apiResponse, int statusCode) {
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;
}
if( actionType == ManageListsAsyncTask.action.DELETE_USERS && statusCode != 200){
Toast.makeText(context, context.getString(R.string.toast_error), Toast.LENGTH_SHORT).show();
}
}
@Override

View File

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FFFFFFFF"
android:pathData="M12,5.9c1.16,0 2.1,0.94 2.1,2.1s-0.94,2.1 -2.1,2.1S9.9,9.16 9.9,8s0.94,-2.1 2.1,-2.1m0,9c2.97,0 6.1,1.46 6.1,2.1v1.1L5.9,18.1L5.9,17c0,-0.64 3.13,-2.1 6.1,-2.1M12,4C9.79,4 8,5.79 8,8s1.79,4 4,4 4,-1.79 4,-4 -1.79,-4 -4,-4zM12,13c-2.67,0 -8,1.34 -8,4v3h16v-3c0,-2.66 -5.33,-4 -8,-4z"/>
</vector>

View File

@ -57,10 +57,9 @@
</LinearLayout>
<android.support.design.widget.FloatingActionButton
android:id="@+id/account_action"
android:visibility="gone"
app:fabSize="mini"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_margin="5dp"
android:scaleType="fitXY"
android:layout_gravity="center"

View File

@ -4,8 +4,7 @@
<item
android:id="@+id/action_add_user"
android:title="@string/action_lists_add_to"
android:icon="@drawable/ic_user_plus"
android:visible="false"
android:icon="@drawable/ic_person_outline"
app:showAsAction="always" />
<item
android:id="@+id/action_edit_list"