Accounts search
This commit is contained in:
parent
5ef9ccc698
commit
13ad601da5
Binary file not shown.
|
@ -178,5 +178,8 @@
|
|||
<activity android:name=".activities.InstanceHealthActivity"
|
||||
android:theme="@style/Base.V7.Theme.AppCompat.Dialog"
|
||||
android:excludeFromRecents="true"/>
|
||||
<activity android:name=".activities.ManageAccountsInListActivity"
|
||||
android:theme="@style/Base.V7.Theme.AppCompat.Dialog"
|
||||
android:excludeFromRecents="true"/>
|
||||
</application>
|
||||
</manifest>
|
|
@ -0,0 +1,136 @@
|
|||
/* 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.activities;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.Window;
|
||||
import android.widget.EditText;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
|
||||
import fr.gouv.etalab.mastodon.R;
|
||||
import fr.gouv.etalab.mastodon.asynctasks.ManageListsAsyncTask;
|
||||
import fr.gouv.etalab.mastodon.client.APIResponse;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Account;
|
||||
import fr.gouv.etalab.mastodon.drawers.AccountsInAListAdapter;
|
||||
import fr.gouv.etalab.mastodon.helper.Helper;
|
||||
import fr.gouv.etalab.mastodon.interfaces.OnListActionInterface;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Created by Thomas on 15/12/2017.
|
||||
* Manage accounts in Lists
|
||||
*/
|
||||
|
||||
public class ManageAccountsInListActivity extends BaseActivity implements OnListActionInterface {
|
||||
|
||||
private TextView list_title;
|
||||
private EditText search_account;
|
||||
private LinearLayout container, main_account_container;
|
||||
private RelativeLayout loader, no_action;
|
||||
private RecyclerView lv_accounts_current, lv_accounts_search;
|
||||
private String title, listId;
|
||||
private java.util.List<Account> accounts;
|
||||
private AccountsInAListAdapter accountsInAListAdapter, accountsSearchInAListAdapter;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
setTheme(R.style.AppThemeDark_NoActionBar);
|
||||
setContentView(R.layout.activity_manage_accounts_list);
|
||||
getWindow().setLayout(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
||||
if( getSupportActionBar() != null)
|
||||
getSupportActionBar().hide();
|
||||
|
||||
Bundle b = getIntent().getExtras();
|
||||
if(b != null){
|
||||
title = b.getString("title");
|
||||
listId = b.getString("id");
|
||||
}else{
|
||||
Toast.makeText(this,R.string.toast_error,Toast.LENGTH_LONG).show();
|
||||
}
|
||||
|
||||
container = findViewById(R.id.container);
|
||||
main_account_container = findViewById(R.id.main_account_container);
|
||||
loader = findViewById(R.id.loader);
|
||||
list_title = findViewById(R.id.list_title);
|
||||
search_account = findViewById(R.id.search_account);
|
||||
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);
|
||||
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);
|
||||
lv_accounts_search.setAdapter(accountsSearchInAListAdapter);
|
||||
lv_accounts_search.setLayoutManager(mLayoutManager);
|
||||
|
||||
|
||||
list_title.setText(title);
|
||||
loader.setVisibility(View.VISIBLE);
|
||||
new ManageListsAsyncTask(ManageAccountsInListActivity.this, ManageListsAsyncTask.action.GET_LIST_ACCOUNT, null, null, listId, null, ManageAccountsInListActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case android.R.id.home:
|
||||
finish();
|
||||
return true;
|
||||
default:
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void onActionDone(ManageListsAsyncTask.action actionType, APIResponse apiResponse, int statusCode) {
|
||||
loader.setVisibility(View.GONE);
|
||||
if( apiResponse.getError() != null){
|
||||
final SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
boolean show_error_messages = sharedpreferences.getBoolean(Helper.SET_SHOW_ERROR_MESSAGES, true);
|
||||
if( show_error_messages)
|
||||
Toast.makeText(ManageAccountsInListActivity.this, apiResponse.getError().getError(),Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
|
||||
if( actionType == ManageListsAsyncTask.action.GET_LIST_ACCOUNT){
|
||||
if (apiResponse.getAccounts() != null && apiResponse.getAccounts().size() > 0) {
|
||||
this.accounts.addAll(apiResponse.getAccounts());
|
||||
accountsInAListAdapter.notifyDataSetChanged();
|
||||
|
||||
} else {
|
||||
no_action.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,174 @@
|
|||
package fr.gouv.etalab.mastodon.drawers;
|
||||
/* 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>. */
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.support.design.widget.FloatingActionButton;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import fr.gouv.etalab.mastodon.R;
|
||||
import fr.gouv.etalab.mastodon.activities.ShowAccountActivity;
|
||||
import fr.gouv.etalab.mastodon.asynctasks.ManageListsAsyncTask;
|
||||
import fr.gouv.etalab.mastodon.client.API;
|
||||
import fr.gouv.etalab.mastodon.client.APIResponse;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Account;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Error;
|
||||
import fr.gouv.etalab.mastodon.fragments.DisplayListsFragment;
|
||||
import fr.gouv.etalab.mastodon.helper.Helper;
|
||||
import fr.gouv.etalab.mastodon.interfaces.OnListActionInterface;
|
||||
import fr.gouv.etalab.mastodon.interfaces.OnPostActionInterface;
|
||||
|
||||
|
||||
/**
|
||||
* Created by Thomas on 15/12/2017.
|
||||
* Adapter for accounts in lists
|
||||
*/
|
||||
public class AccountsInAListAdapter extends RecyclerView.Adapter implements OnListActionInterface {
|
||||
|
||||
private List<Account> accounts;
|
||||
private LayoutInflater layoutInflater;
|
||||
private Context context;
|
||||
private AccountsInAListAdapter accountsInAListAdapter;
|
||||
private type actionType;
|
||||
|
||||
|
||||
|
||||
public enum type{
|
||||
CURRENT,
|
||||
SEARCH
|
||||
}
|
||||
|
||||
public AccountsInAListAdapter(Context context, type actionType, List<Account> accounts){
|
||||
this.context = context;
|
||||
this.accounts = accounts;
|
||||
layoutInflater = LayoutInflater.from(context);
|
||||
this.accountsInAListAdapter = this;
|
||||
this.actionType = actionType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
return new ViewHolder(layoutInflater.inflate(R.layout.drawer_account_list, parent, false));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int position) {
|
||||
final AccountsInAListAdapter.ViewHolder holder = (AccountsInAListAdapter.ViewHolder) viewHolder;
|
||||
final Account account = accounts.get(position);
|
||||
|
||||
|
||||
|
||||
holder.account_un.setText(Helper.shortnameToUnicode(account.getDisplay_name(), true));
|
||||
holder.account_ac.setText(account.getAcct());
|
||||
if( account.getDisplay_name().equals(account.getAcct()))
|
||||
holder.account_ac.setVisibility(View.GONE);
|
||||
else
|
||||
holder.account_ac.setVisibility(View.VISIBLE);
|
||||
//Profile picture
|
||||
Helper.loadGiF(context, account.getAvatar(), holder.account_pp);
|
||||
|
||||
//Follow button
|
||||
holder.account_action.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
||||
}
|
||||
});
|
||||
if( actionType == type.CURRENT){
|
||||
holder.account_action.setImageResource(R.drawable.ic_close);
|
||||
}else if(actionType == type.SEARCH){
|
||||
holder.account_action.setImageResource(R.drawable.ic_add);
|
||||
}
|
||||
holder.account_action.setOnClickListener(new View.OnClickListener() {
|
||||
@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);
|
||||
accounts.remove(account);
|
||||
accountsInAListAdapter.notifyDataSetChanged();
|
||||
}else if(actionType == type.SEARCH){
|
||||
|
||||
}
|
||||
}
|
||||
});
|
||||
holder.account_container.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Intent intent = new Intent(context, ShowAccountActivity.class);
|
||||
Bundle b = new Bundle();
|
||||
b.putString("accountId", account.getId());
|
||||
intent.putExtras(b);
|
||||
context.startActivity(intent);
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@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;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
return position;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return accounts.size();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private class ViewHolder extends RecyclerView.ViewHolder{
|
||||
ImageView account_pp;
|
||||
TextView account_ac;
|
||||
TextView account_un;
|
||||
FloatingActionButton account_action;
|
||||
LinearLayout account_container;
|
||||
ViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
account_container = itemView.findViewById(R.id.account_container);
|
||||
account_pp = itemView.findViewById(R.id.account_pp);
|
||||
account_ac = itemView.findViewById(R.id.account_ac);
|
||||
account_un = itemView.findViewById(R.id.account_un);
|
||||
account_action = itemView.findViewById(R.id.account_action);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -4,6 +4,6 @@
|
|||
android:viewportWidth="24.0"
|
||||
android:viewportHeight="24.0">
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:fillColor="#FFFFFFFF"
|
||||
android:pathData="M19,13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z"/>
|
||||
</vector>
|
||||
|
|
|
@ -0,0 +1,80 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:fitsSystemWindows="true"
|
||||
tools:context="fr.gouv.etalab.mastodon.activities.InstanceHealthActivity"
|
||||
android:layout_margin="@dimen/fab_margin"
|
||||
android:id="@+id/container"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="300dp">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/main_account_container"
|
||||
android:visibility="gone"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
<TextView
|
||||
android:id="@+id/list_title"
|
||||
android:textSize="20sp"
|
||||
android:textColor="@color/titleb"
|
||||
android:layout_gravity="center"
|
||||
android:gravity="center"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/search_account"
|
||||
android:drawableRight="@drawable/ic_search"
|
||||
android:drawableEnd="@drawable/ic_search"
|
||||
android:layout_marginTop="10dp"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:inputType="text" />
|
||||
<android.support.v7.widget.RecyclerView
|
||||
android:id="@+id/lv_accounts_current"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:scrollbars="none"
|
||||
android:divider="@null"
|
||||
/>
|
||||
<android.support.v7.widget.RecyclerView
|
||||
android:visibility="gone"
|
||||
android:id="@+id/lv_accounts_search"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:scrollbars="none"
|
||||
android:divider="@null"
|
||||
/>
|
||||
</LinearLayout>
|
||||
<RelativeLayout
|
||||
android:id="@+id/no_action"
|
||||
android:visibility="gone"
|
||||
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"
|
||||
android:layout_gravity="center"
|
||||
android:textStyle="italic|bold"
|
||||
android:typeface="serif"
|
||||
android:text="@string/action_lists_empty_content"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
</RelativeLayout>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/loader"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center"
|
||||
>
|
||||
<ProgressBar
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:indeterminate="true" />
|
||||
</RelativeLayout>
|
||||
</LinearLayout>
|
|
@ -0,0 +1,69 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
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>.
|
||||
-->
|
||||
<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"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:padding="2dp"
|
||||
android:id="@+id/account_container"
|
||||
android:orientation="horizontal">
|
||||
<ImageView
|
||||
android:layout_margin="5dp"
|
||||
android:layout_gravity="center"
|
||||
android:id="@+id/account_pp"
|
||||
android:layout_width="30dp"
|
||||
android:layout_height="30dp"
|
||||
tools:ignore="ContentDescription" />
|
||||
<LinearLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_weight="1"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
<TextView
|
||||
android:layout_marginStart="10dp"
|
||||
android:layout_marginLeft="10dp"
|
||||
android:maxLines="1"
|
||||
android:textSize="14sp"
|
||||
android:textStyle="bold"
|
||||
android:id="@+id/account_un"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
<TextView
|
||||
android:id="@+id/account_ac"
|
||||
android:layout_marginStart="10dp"
|
||||
android:layout_marginLeft="10dp"
|
||||
android:maxLines="1"
|
||||
android:textSize="14sp"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
</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_margin="5dp"
|
||||
android:scaleType="fitXY"
|
||||
android:layout_gravity="center"
|
||||
android:gravity="center"
|
||||
/>
|
||||
</LinearLayout>
|
Loading…
Reference in New Issue