Finale release

This commit is contained in:
stom79 2017-12-15 20:01:58 +01:00
parent 7aebf73e3a
commit 8dfb8c4a0d
7 changed files with 100 additions and 43 deletions

View File

@ -20,7 +20,10 @@ import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
@ -50,14 +53,13 @@ import fr.gouv.etalab.mastodon.interfaces.OnListActionInterface;
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;
public EditText search_account;
private LinearLayout main_account_container;
private RelativeLayout loader;
private RecyclerView lv_accounts_current, lv_accounts_search;
private String title, listId;
private java.util.List<Account> accounts;
private AccountsInAListAdapter accountsInAListAdapter, accountsSearchInAListAdapter;
private AccountsInAListAdapter accountsInAListAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -77,32 +79,71 @@ public class ManageAccountsInListActivity extends BaseActivity implements OnList
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);
TextView 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);
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, listId, this.accounts);
lv_accounts_search.setAdapter(accountsSearchInAListAdapter);
LinearLayoutManager mLayoutManager1 = new LinearLayoutManager(ManageAccountsInListActivity.this);
lv_accounts_search.setLayoutManager(mLayoutManager1);
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);
search_account.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
if (count > 0) {
search_account.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.ic_close, 0);
}else{
search_account.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.ic_search, 0);
}
}
@Override
public void afterTextChanged(Editable s) {
if( s != null && s.length() > 0){
new ManageListsAsyncTask(ManageAccountsInListActivity.this, s.toString(), ManageAccountsInListActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}else{
lv_accounts_search.setVisibility(View.GONE);
lv_accounts_current.setVisibility(View.VISIBLE);
}
}
});
search_account.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
final int DRAWABLE_RIGHT = 2;
if (event.getAction() == MotionEvent.ACTION_UP) {
if (search_account.length() > 0 && event.getRawX() >= (search_account.getRight() - search_account.getCompoundDrawables()[DRAWABLE_RIGHT].getBounds().width())) {
search_account.setText("");
}
}
return false;
}
});
}
public void addAccount(Account account){
search_account.setText("");
accounts.add(0,account);
accountsInAListAdapter.notifyItemInserted(0);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
@ -119,6 +160,7 @@ public class ManageAccountsInListActivity extends BaseActivity implements OnList
@Override
public void onActionDone(ManageListsAsyncTask.action actionType, APIResponse apiResponse, int statusCode) {
loader.setVisibility(View.GONE);
main_account_container.setVisibility(View.VISIBLE);
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);
@ -126,14 +168,24 @@ public class ManageAccountsInListActivity extends BaseActivity implements OnList
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();
main_account_container.setVisibility(View.VISIBLE);
} else {
no_action.setVisibility(View.VISIBLE);
lv_accounts_search.setVisibility(View.GONE);
lv_accounts_current.setVisibility(View.VISIBLE);
}
}else if( actionType == ManageListsAsyncTask.action.SEARCH_USER){
if (apiResponse.getAccounts() != null && apiResponse.getAccounts().size() > 0) {
java.util.List<Account> accountsSearch = new ArrayList<>();
accountsSearch.addAll(apiResponse.getAccounts());
AccountsInAListAdapter accountsSearchInAListAdapter = new AccountsInAListAdapter(ManageAccountsInListActivity.this, AccountsInAListAdapter.type.SEARCH, listId, accountsSearch);
lv_accounts_search.setAdapter(accountsSearchInAListAdapter);
LinearLayoutManager mLayoutManager1 = new LinearLayoutManager(ManageAccountsInListActivity.this);
lv_accounts_search.setLayoutManager(mLayoutManager1);
lv_accounts_search.setVisibility(View.VISIBLE);
lv_accounts_current.setVisibility(View.GONE);
}
}
}

View File

@ -39,7 +39,8 @@ public class ManageListsAsyncTask extends AsyncTask<Void, Void, Void> {
DELETE_LIST,
UPDATE_LIST,
ADD_USERS,
DELETE_USERS
DELETE_USERS,
SEARCH_USER
}
private OnListActionInterface listener;
@ -53,6 +54,7 @@ public class ManageListsAsyncTask extends AsyncTask<Void, Void, Void> {
private WeakReference<Context> contextReference;
private String max_id, since_id;
private int limit;
private String search;
public ManageListsAsyncTask(Context context, action apiAction, String[] accountsId, String targetedId, String listId, String title, OnListActionInterface onListActionInterface){
contextReference = new WeakReference<>(context);
@ -74,6 +76,13 @@ public class ManageListsAsyncTask extends AsyncTask<Void, Void, Void> {
this.apiAction = action.GET_LIST_TIMELINE;
}
public ManageListsAsyncTask(Context context, String search, OnListActionInterface onListActionInterface){
contextReference = new WeakReference<>(context);
this.listener = onListActionInterface;
this.search = search;
this.apiAction = action.SEARCH_USER;
}
@Override
protected Void doInBackground(Void... params) {
if (apiAction == action.GET_LIST) {
@ -92,6 +101,8 @@ public class ManageListsAsyncTask extends AsyncTask<Void, Void, Void> {
apiResponse = new API(contextReference.get()).addAccountToList(this.listId, this.accountsId);
}else if(apiAction == action.DELETE_USERS){
statusCode = new API(contextReference.get()).deleteAccountFromList(this.listId, this.accountsId);
}else if( apiAction == action.SEARCH_USER){
apiResponse = new API(contextReference.get()).searchAccounts(this.search, 20, true);
}
return null;
}

View File

@ -16,8 +16,6 @@ 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;
import org.json.JSONObject;
@ -1113,8 +1111,10 @@ public class API {
apiResponse.setMax_id(httpsConnection.getMax_id());
} catch (HttpsConnection.HttpsConnectionException e) {
setError(e.getStatusCode(), e);
e.printStackTrace();
}catch (Exception e) {
setDefaultError();
e.printStackTrace();
}
apiResponse.setAccounts(accounts);
return apiResponse;

View File

@ -16,7 +16,6 @@ package fr.gouv.etalab.mastodon.drawers;
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;
@ -29,20 +28,16 @@ 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.ManageAccountsInListActivity;
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;
/**
@ -114,6 +109,8 @@ public class AccountsInAListAdapter extends RecyclerView.Adapter implements OnLi
accounts.remove(account);
accountsInAListAdapter.notifyDataSetChanged();
}else if(actionType == type.SEARCH){
new ManageListsAsyncTask(context, ManageListsAsyncTask.action.ADD_USERS, new String[]{account.getId()}, null, listId, null, AccountsInAListAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
((ManageAccountsInListActivity)context).addAccount(account);
}
}

View File

@ -23,7 +23,6 @@ import android.support.annotation.NonNull;
import android.support.design.widget.FloatingActionButton;
import android.support.v4.app.Fragment;
import android.support.v7.app.AlertDialog;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

View File

@ -142,6 +142,7 @@ import fr.gouv.etalab.mastodon.client.Entities.Account;
import fr.gouv.etalab.mastodon.client.Entities.Mention;
import fr.gouv.etalab.mastodon.client.Entities.Results;
import fr.gouv.etalab.mastodon.client.Entities.Status;
import fr.gouv.etalab.mastodon.client.Entities.Version;
import fr.gouv.etalab.mastodon.sqlite.AccountDAO;
import fr.gouv.etalab.mastodon.sqlite.Sqlite;
@ -1626,6 +1627,19 @@ public class Helper {
if( navigationView.getMenu().findItem(R.id.nav_follow_request) != null)
navigationView.getMenu().findItem(R.id.nav_follow_request).setVisible(false);
}
}
//Check instance release for lists
String instance = Helper.getLiveInstance(activity);
String instanceVersion = sharedpreferences.getString(Helper.INSTANCE_VERSION + userID + instance, null);
if (instanceVersion != null) {
Version currentVersion = new Version(instanceVersion);
Version minVersion = new Version("2.1");
if (currentVersion.compareTo(minVersion) == 1 || currentVersion.equals(minVersion)) {
navigationView.getMenu().findItem(R.id.nav_list).setVisible(true);
} else {
navigationView.getMenu().findItem(R.id.nav_list).setVisible(false);
}
}
tableLayout.setVisibility(View.VISIBLE);
}

View File

@ -29,6 +29,7 @@
android:id="@+id/search_account"
android:drawableRight="@drawable/ic_search"
android:drawableEnd="@drawable/ic_search"
android:maxLines="1"
android:layout_marginTop="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
@ -49,23 +50,6 @@
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"