Manage filters
This commit is contained in:
parent
0ae9bee19d
commit
e3f59fb337
|
@ -0,0 +1,79 @@
|
|||
/* 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.lang.ref.WeakReference;
|
||||
|
||||
import fr.gouv.etalab.mastodon.client.API;
|
||||
import fr.gouv.etalab.mastodon.client.APIResponse;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Filters;
|
||||
import fr.gouv.etalab.mastodon.interfaces.OnFilterActionInterface;
|
||||
|
||||
|
||||
/**
|
||||
* Created by Thomas on 05/09/2018.
|
||||
* Async works to manage Filters
|
||||
*/
|
||||
|
||||
public class ManageFiltersAsyncTask extends AsyncTask<Void, Void, Void> {
|
||||
|
||||
public enum action{
|
||||
GET_FILTER,
|
||||
GET_ALL_FILTER,
|
||||
CREATE_FILTER,
|
||||
DELETE_FILTER,
|
||||
UPDATE_FILTER,
|
||||
}
|
||||
|
||||
private OnFilterActionInterface listener;
|
||||
private APIResponse apiResponse;
|
||||
private int statusCode;
|
||||
private action apiAction;
|
||||
private WeakReference<Context> contextReference;
|
||||
private Filters filter;
|
||||
|
||||
public ManageFiltersAsyncTask(Context context, action apiAction, Filters filter, OnFilterActionInterface onFilterActionInterface){
|
||||
contextReference = new WeakReference<>(context);
|
||||
this.listener = onFilterActionInterface;
|
||||
this.filter = filter;
|
||||
this.apiAction = apiAction;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected Void doInBackground(Void... params) {
|
||||
if (apiAction == action.GET_ALL_FILTER) {
|
||||
apiResponse = new API(contextReference.get()).getFilters();
|
||||
}else if(apiAction == action.GET_FILTER){
|
||||
apiResponse = new API(contextReference.get()).getFilters(filter.getId());
|
||||
}else if(apiAction == action.CREATE_FILTER){
|
||||
apiResponse = new API(contextReference.get()).addFilters(filter);
|
||||
}else if( apiAction == action.UPDATE_FILTER){
|
||||
apiResponse = new API(contextReference.get()).updateFilters(filter);
|
||||
}else if(apiAction == action.DELETE_FILTER){
|
||||
statusCode = new API(contextReference.get()).deleteFilters(filter);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Void result) {
|
||||
listener.onActionDone(this.apiAction, apiResponse, statusCode);
|
||||
}
|
||||
|
||||
}
|
|
@ -1495,10 +1495,12 @@ public class API {
|
|||
* @param filter Filter
|
||||
* @return APIResponse
|
||||
*/
|
||||
public APIResponse deleteFilters(Filters filter){
|
||||
public int deleteFilters(Filters filter){
|
||||
|
||||
try {
|
||||
HttpsConnection httpsConnection = new HttpsConnection(context);
|
||||
new HttpsConnection(context).delete(getAbsoluteUrl(String.format("/filters/%s", filter.getId())), 60, null, prefKeyOauthTokenT);
|
||||
actionCode = httpsConnection.getActionCode();
|
||||
} catch (HttpsConnection.HttpsConnectionException e) {
|
||||
setError(e.getStatusCode(), e);
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
|
@ -1508,7 +1510,7 @@ public class API {
|
|||
} catch (KeyManagementException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return apiResponse;
|
||||
return actionCode;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -2228,6 +2230,7 @@ public class API {
|
|||
filter.setContext(finalContext);
|
||||
}
|
||||
}
|
||||
|
||||
}catch (Exception ignored){}
|
||||
return filter;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,208 @@
|
|||
package fr.gouv.etalab.mastodon.drawers;
|
||||
/* Copyright 2018 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.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.AsyncTask;
|
||||
import android.support.design.widget.FloatingActionButton;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.WindowManager;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.EditText;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import fr.gouv.etalab.mastodon.R;
|
||||
import fr.gouv.etalab.mastodon.activities.BaseMainActivity;
|
||||
import fr.gouv.etalab.mastodon.asynctasks.ManageFiltersAsyncTask;
|
||||
import fr.gouv.etalab.mastodon.client.APIResponse;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Filters;
|
||||
import fr.gouv.etalab.mastodon.interfaces.OnFilterActionInterface;
|
||||
|
||||
|
||||
/**
|
||||
* Created by Thomas on 05/09/2018.
|
||||
* Adapter for filters
|
||||
*/
|
||||
public class FilterAdapter extends BaseAdapter implements OnFilterActionInterface {
|
||||
|
||||
private List<fr.gouv.etalab.mastodon.client.Entities.Filters> filters;
|
||||
private LayoutInflater layoutInflater;
|
||||
private Context context;
|
||||
private FilterAdapter filterAdapter;
|
||||
private RelativeLayout textviewNoAction;
|
||||
|
||||
public FilterAdapter(Context context, List<fr.gouv.etalab.mastodon.client.Entities.Filters> filters, RelativeLayout textviewNoAction){
|
||||
this.filters = filters;
|
||||
layoutInflater = LayoutInflater.from(context);
|
||||
this.context = context;
|
||||
this.filterAdapter = this;
|
||||
this.textviewNoAction = textviewNoAction;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return filters.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getItem(int position) {
|
||||
return filters.get(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
return position;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public View getView(final int position, View convertView, ViewGroup parent) {
|
||||
|
||||
final fr.gouv.etalab.mastodon.client.Entities.Filters filter = filters.get(position);
|
||||
final ViewHolder holder;
|
||||
if (convertView == null) {
|
||||
convertView = layoutInflater.inflate(R.layout.drawer_filters, parent, false);
|
||||
holder = new ViewHolder();
|
||||
holder.filter_word = convertView.findViewById(R.id.filter_word);
|
||||
holder.filter_context = convertView.findViewById(R.id.filter_context);
|
||||
convertView.setTag(holder);
|
||||
} else {
|
||||
holder = (ViewHolder) convertView.getTag();
|
||||
}
|
||||
|
||||
|
||||
|
||||
holder.edit_filter.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(context);
|
||||
LayoutInflater inflater = ((BaseMainActivity)context).getLayoutInflater();
|
||||
@SuppressLint("InflateParams") View dialogView = inflater.inflate(R.layout.add_filter, null);
|
||||
dialogBuilder.setView(dialogView);
|
||||
|
||||
EditText add_phrase = dialogView.findViewById(R.id.add_phrase);
|
||||
CheckBox context_home = dialogView.findViewById(R.id.context_home);
|
||||
CheckBox context_public = dialogView.findViewById(R.id.context_public);
|
||||
CheckBox context_notification = dialogView.findViewById(R.id.context_notification);
|
||||
CheckBox context_conversation = dialogView.findViewById(R.id.context_conversation);
|
||||
CheckBox context_whole_word = dialogView.findViewById(R.id.context_whole_word);
|
||||
CheckBox context_drop = dialogView.findViewById(R.id.context_drop);
|
||||
|
||||
dialogBuilder.setPositiveButton(R.string.validate, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
|
||||
if( add_phrase.getText() != null && add_phrase.getText().toString().trim().length() > 0 ) {
|
||||
Filters filter = new Filters();
|
||||
ArrayList<String> contextFilter = new ArrayList<>();
|
||||
if( context_home.isChecked())
|
||||
contextFilter.add("home");
|
||||
if( context_public.isChecked())
|
||||
contextFilter.add("public");
|
||||
if( context_notification.isChecked())
|
||||
contextFilter.add("notifications");
|
||||
if( context_conversation.isChecked())
|
||||
contextFilter.add("thread");
|
||||
filter.setContext(contextFilter);
|
||||
filter.setPhrase(add_phrase.getText().toString());
|
||||
filter.setWhole_word(context_whole_word.isChecked());
|
||||
filter.setIrreversible(context_drop.isChecked());
|
||||
new ManageFiltersAsyncTask(context, ManageFiltersAsyncTask.action.UPDATE_FILTER, filter, FilterAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
}
|
||||
dialog.dismiss();
|
||||
}
|
||||
});
|
||||
dialogBuilder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
dialog.dismiss();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
AlertDialog alertDialog = dialogBuilder.create();
|
||||
alertDialog.setTitle(context.getString(R.string.action_update_filter));
|
||||
alertDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
|
||||
@Override
|
||||
public void onDismiss(DialogInterface dialogInterface) {
|
||||
//Hide keyboard
|
||||
InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
assert imm != null;
|
||||
imm.hideSoftInputFromWindow(add_phrase.getWindowToken(), 0);
|
||||
}
|
||||
});
|
||||
if( alertDialog.getWindow() != null )
|
||||
alertDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
|
||||
alertDialog.show();
|
||||
}
|
||||
});
|
||||
|
||||
holder.delete_filter.setOnLongClickListener(new View.OnLongClickListener() {
|
||||
@Override
|
||||
public boolean onLongClick(View view) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
||||
builder.setTitle(context.getString(R.string.action_filter_delete) );
|
||||
builder.setMessage(context.getString(R.string.action_lists_confirm_delete) );
|
||||
builder.setIcon(android.R.drawable.ic_dialog_alert)
|
||||
.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
filters.remove(filter);
|
||||
filterAdapter.notifyDataSetChanged();
|
||||
new ManageFiltersAsyncTask(context, ManageFiltersAsyncTask.action.DELETE_FILTER,filter, FilterAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
if( filters.size() == 0 && textviewNoAction != null && textviewNoAction.getVisibility() == View.GONE)
|
||||
textviewNoAction.setVisibility(View.VISIBLE);
|
||||
dialog.dismiss();
|
||||
}
|
||||
})
|
||||
.setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
dialog.dismiss();
|
||||
}
|
||||
})
|
||||
.show();
|
||||
return false;
|
||||
}
|
||||
});
|
||||
return convertView;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActionDone(ManageFiltersAsyncTask.action actionType, APIResponse apiResponse, int statusCode) {
|
||||
|
||||
}
|
||||
|
||||
private class ViewHolder {
|
||||
TextView filter_word;
|
||||
TextView filter_context;
|
||||
FloatingActionButton edit_filter;
|
||||
FloatingActionButton delete_filter;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,213 @@
|
|||
package fr.gouv.etalab.mastodon.fragments;
|
||||
/* Copyright 2018 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.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
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.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.WindowManager;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.EditText;
|
||||
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.R;
|
||||
import fr.gouv.etalab.mastodon.activities.MainActivity;
|
||||
import fr.gouv.etalab.mastodon.asynctasks.ManageFiltersAsyncTask;
|
||||
import fr.gouv.etalab.mastodon.client.APIResponse;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Filters;
|
||||
import fr.gouv.etalab.mastodon.drawers.FilterAdapter;
|
||||
import fr.gouv.etalab.mastodon.helper.Helper;
|
||||
import fr.gouv.etalab.mastodon.interfaces.OnFilterActionInterface;
|
||||
|
||||
|
||||
/**
|
||||
* Created by Thomas on 05/09/2018.
|
||||
* Fragment to display Filters
|
||||
*/
|
||||
public class DisplayFiltersFragment extends Fragment implements OnFilterActionInterface {
|
||||
|
||||
|
||||
private Context context;
|
||||
private AsyncTask<Void, Void, Void> asyncTask;
|
||||
private List<fr.gouv.etalab.mastodon.client.Entities.Filters> filters;
|
||||
private TextView no_action_text;
|
||||
private RelativeLayout mainLoader;
|
||||
private FloatingActionButton add_new;
|
||||
private FilterAdapter filterAdapter;
|
||||
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
|
||||
//View for fragment is the same that fragment accounts
|
||||
View rootView = inflater.inflate(R.layout.fragment_filters, container, false);
|
||||
|
||||
context = getContext();
|
||||
filters = new ArrayList<>();
|
||||
|
||||
|
||||
ListView lv_filters = rootView.findViewById(R.id.lv_filters);
|
||||
RelativeLayout textviewNoAction = rootView.findViewById(R.id.no_action);
|
||||
no_action_text = rootView.findViewById(R.id.no_action_text);
|
||||
mainLoader = rootView.findViewById(R.id.loader);
|
||||
RelativeLayout nextElementLoader = rootView.findViewById(R.id.loading_next_items);
|
||||
mainLoader.setVisibility(View.VISIBLE);
|
||||
nextElementLoader.setVisibility(View.GONE);
|
||||
filterAdapter = new FilterAdapter(context, filters, textviewNoAction);
|
||||
lv_filters.setAdapter(filterAdapter);
|
||||
no_action_text.setVisibility(View.GONE);
|
||||
asyncTask = new ManageFiltersAsyncTask(context, ManageFiltersAsyncTask.action.GET_ALL_FILTER, null, DisplayFiltersFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
try {
|
||||
add_new = ((MainActivity) context).findViewById(R.id.add_new);
|
||||
}catch (Exception ignored){}
|
||||
if( add_new != null)
|
||||
add_new.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(context);
|
||||
LayoutInflater inflater = getLayoutInflater();
|
||||
@SuppressLint("InflateParams") View dialogView = inflater.inflate(R.layout.add_filter, null);
|
||||
dialogBuilder.setView(dialogView);
|
||||
|
||||
EditText add_phrase = dialogView.findViewById(R.id.add_phrase);
|
||||
CheckBox context_home = dialogView.findViewById(R.id.context_home);
|
||||
CheckBox context_public = dialogView.findViewById(R.id.context_public);
|
||||
CheckBox context_notification = dialogView.findViewById(R.id.context_notification);
|
||||
CheckBox context_conversation = dialogView.findViewById(R.id.context_conversation);
|
||||
CheckBox context_whole_word = dialogView.findViewById(R.id.context_whole_word);
|
||||
CheckBox context_drop = dialogView.findViewById(R.id.context_drop);
|
||||
|
||||
dialogBuilder.setPositiveButton(R.string.validate, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
|
||||
if( add_phrase.getText() != null && add_phrase.getText().toString().trim().length() > 0 ) {
|
||||
Filters filter = new Filters();
|
||||
ArrayList<String> contextFilter = new ArrayList<>();
|
||||
if( context_home.isChecked())
|
||||
contextFilter.add("home");
|
||||
if( context_public.isChecked())
|
||||
contextFilter.add("public");
|
||||
if( context_notification.isChecked())
|
||||
contextFilter.add("notifications");
|
||||
if( context_conversation.isChecked())
|
||||
contextFilter.add("thread");
|
||||
filter.setContext(contextFilter);
|
||||
filter.setPhrase(add_phrase.getText().toString());
|
||||
filter.setWhole_word(context_whole_word.isChecked());
|
||||
filter.setIrreversible(context_drop.isChecked());
|
||||
new ManageFiltersAsyncTask(context, ManageFiltersAsyncTask.action.CREATE_FILTER, filter, DisplayFiltersFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
}
|
||||
dialog.dismiss();
|
||||
add_new.setEnabled(false);
|
||||
}
|
||||
});
|
||||
dialogBuilder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
dialog.dismiss();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
AlertDialog alertDialog = dialogBuilder.create();
|
||||
alertDialog.setTitle(getString(R.string.action_filter_create));
|
||||
alertDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
|
||||
@Override
|
||||
public void onDismiss(DialogInterface dialogInterface) {
|
||||
//Hide keyboard
|
||||
InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
assert imm != null;
|
||||
imm.hideSoftInputFromWindow(add_phrase.getWindowToken(), 0);
|
||||
}
|
||||
});
|
||||
if( alertDialog.getWindow() != null )
|
||||
alertDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
|
||||
alertDialog.show();
|
||||
}
|
||||
});
|
||||
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 onDestroy() {
|
||||
super.onDestroy();
|
||||
if(asyncTask != null && asyncTask.getStatus() == AsyncTask.Status.RUNNING)
|
||||
asyncTask.cancel(true);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void onActionDone(ManageFiltersAsyncTask.action actionType, APIResponse apiResponse, int statusCode) {
|
||||
mainLoader.setVisibility(View.GONE);
|
||||
add_new.setEnabled(true);
|
||||
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 == ManageFiltersAsyncTask.action.GET_ALL_FILTER) {
|
||||
if (apiResponse.getFilters() != null && apiResponse.getFilters().size() > 0) {
|
||||
this.filters.addAll(apiResponse.getFilters());
|
||||
filterAdapter.notifyDataSetChanged();
|
||||
|
||||
} else {
|
||||
no_action_text.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}else if( actionType == ManageFiltersAsyncTask.action.CREATE_FILTER){
|
||||
if (apiResponse.getFilters() != null && apiResponse.getFilters().size() > 0) {
|
||||
|
||||
this.filters.add(0, apiResponse.getFilters().get(0));
|
||||
filterAdapter.notifyDataSetChanged();
|
||||
}else{
|
||||
Toast.makeText(context, apiResponse.getError().getError(),Toast.LENGTH_LONG).show();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
/* Copyright 2018 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.asynctasks.ManageFiltersAsyncTask;
|
||||
import fr.gouv.etalab.mastodon.client.APIResponse;
|
||||
|
||||
/**
|
||||
* Created by Thomas on 05/09/2018.
|
||||
* Interface when actions have been done with lists
|
||||
*/
|
||||
public interface OnFilterActionInterface {
|
||||
void onActionDone(ManageFiltersAsyncTask.action actionType, APIResponse apiResponse, int statusCode);
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 122 B |
Binary file not shown.
After Width: | Height: | Size: 199 B |
Binary file not shown.
After Width: | Height: | Size: 108 B |
Binary file not shown.
After Width: | Height: | Size: 112 B |
Binary file not shown.
After Width: | Height: | Size: 139 B |
Binary file not shown.
After Width: | Height: | Size: 112 B |
|
@ -0,0 +1,147 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Copyright 2018 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"
|
||||
android:orientation="vertical" android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:text="@string/filter_keyword"
|
||||
android:layout_height="wrap_content" />
|
||||
<TextView
|
||||
android:textSize="12sp"
|
||||
android:text="@string/filter_keyword_explanations"
|
||||
android:layout_width="match_parent"
|
||||
android:textColor="?colorAccent"
|
||||
android:layout_height="wrap_content" />
|
||||
<EditText
|
||||
android:id="@+id/add_phrase"
|
||||
android:inputType="text"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:maxLines="1"
|
||||
/>
|
||||
|
||||
<TextView
|
||||
android:textSize="12sp"
|
||||
android:text="@string/filter_context"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
<TextView
|
||||
android:textSize="12sp"
|
||||
android:text="@string/filter_context_explanations"
|
||||
android:layout_width="match_parent"
|
||||
android:textColor="?colorAccent"
|
||||
android:layout_height="wrap_content" />
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
<CheckBox
|
||||
android:id="@+id/context_home"
|
||||
android:layout_width="0dp"
|
||||
android:text="@string/context_home"
|
||||
android:layout_weight="1"
|
||||
android:layout_height="wrap_content" />
|
||||
<CheckBox
|
||||
android:id="@+id/context_public"
|
||||
android:layout_width="0dp"
|
||||
android:layout_weight="1"
|
||||
android:text="@string/context_public"
|
||||
android:layout_height="wrap_content" />
|
||||
</LinearLayout>
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
<CheckBox
|
||||
android:id="@+id/context_notification"
|
||||
android:layout_width="0dp"
|
||||
android:text="@string/context_notification"
|
||||
android:layout_weight="1"
|
||||
android:layout_height="wrap_content" />
|
||||
<CheckBox
|
||||
android:id="@+id/context_conversation"
|
||||
android:layout_width="0dp"
|
||||
android:text="@string/context_conversation"
|
||||
android:layout_weight="1"
|
||||
android:layout_height="wrap_content" />
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
<CheckBox
|
||||
android:id="@+id/context_drop"
|
||||
android:layout_width="match_parent"
|
||||
android:text="@string/context_drop"
|
||||
android:layout_height="wrap_content" />
|
||||
<TextView
|
||||
android:textSize="12sp"
|
||||
android:text="@string/context_drop_explanations"
|
||||
android:layout_width="match_parent"
|
||||
android:textColor="?colorAccent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="20dp"
|
||||
android:layout_marginLeft="20dp"
|
||||
android:layout_marginEnd="20dp"
|
||||
android:layout_marginRight="20dp"/>
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/context_whole_word"
|
||||
android:layout_width="match_parent"
|
||||
android:checked="true"
|
||||
android:text="@string/context_whole_word"
|
||||
android:layout_height="wrap_content" />
|
||||
<TextView
|
||||
android:textSize="12sp"
|
||||
android:text="@string/context_whole_word_explanations"
|
||||
android:layout_width="match_parent"
|
||||
android:textColor="?colorAccent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="20dp"
|
||||
android:layout_marginLeft="20dp"
|
||||
android:layout_marginEnd="20dp"
|
||||
android:layout_marginRight="20dp"/>
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
<TextView
|
||||
android:textSize="12sp"
|
||||
android:text="@string/filter_expire"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
<Spinner
|
||||
android:layout_marginStart="30dp"
|
||||
android:id="@+id/filter_expire"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="30dp" />
|
||||
</LinearLayout>
|
||||
<Button
|
||||
android:layout_marginTop="5dp"
|
||||
android:id="@+id/save_filter"
|
||||
android:layout_gravity="center"
|
||||
android:gravity="center"
|
||||
style="@style/Base.Widget.AppCompat.Button.Colored"
|
||||
android:maxWidth="150dp"
|
||||
android:text="@string/add_new_filter"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
</LinearLayout>
|
|
@ -0,0 +1,60 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Copyright 2018 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"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/filter_container"
|
||||
android:orientation="horizontal">
|
||||
<TextView
|
||||
android:layout_marginStart="5dp"
|
||||
android:layout_marginLeft="5dp"
|
||||
android:id="@+id/filter_word"
|
||||
android:layout_width="0dp"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_weight="1"
|
||||
android:layout_height="wrap_content"/>
|
||||
<TextView
|
||||
android:layout_marginStart="5dp"
|
||||
android:layout_marginLeft="5dp"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:id="@+id/filter_context"
|
||||
android:layout_width="0dp"
|
||||
android:layout_weight="2"
|
||||
android:layout_height="wrap_content"/>
|
||||
|
||||
<android.support.design.widget.FloatingActionButton
|
||||
android:layout_width="30dp"
|
||||
android:layout_margin="5dp"
|
||||
android:id="@+id/edit_filter"
|
||||
app:fabSize="mini"
|
||||
app:backgroundTint="?colorAccent"
|
||||
app:srcCompat="@drawable/ic_edit"
|
||||
tools:ignore="VectorDrawableCompat"
|
||||
android:layout_height="30dp" />
|
||||
<android.support.design.widget.FloatingActionButton
|
||||
android:layout_width="30dp"
|
||||
app:fabSize="mini"
|
||||
android:layout_margin="5dp"
|
||||
android:id="@+id/delete_filter"
|
||||
app:backgroundTint="?colorAccent"
|
||||
app:srcCompat="@drawable/ic_delete"
|
||||
tools:ignore="VectorDrawableCompat"
|
||||
android:layout_height="30dp"/>
|
||||
</LinearLayout>
|
|
@ -0,0 +1,77 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Copyright 2018 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>.
|
||||
-->
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
|
||||
android:paddingLeft="@dimen/fab_margin"
|
||||
android:paddingRight="@dimen/fab_margin"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
<!-- Listview filter -->
|
||||
<ListView
|
||||
android:id="@+id/lv_filters"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:scrollbars="none"
|
||||
android:divider="@null"
|
||||
/>
|
||||
<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_filters_empty_content"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
</RelativeLayout>
|
||||
<!-- Main Loader -->
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/loader"
|
||||
android:visibility="gone"
|
||||
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>
|
||||
<!-- Loader for next items -->
|
||||
<RelativeLayout
|
||||
android:id="@+id/loading_next_items"
|
||||
android:visibility="gone"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_gravity="bottom|center_horizontal"
|
||||
android:gravity="bottom|center_horizontal"
|
||||
android:layout_height="20dp">
|
||||
<ProgressBar
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:indeterminate="true" />
|
||||
</RelativeLayout>
|
||||
</RelativeLayout>
|
||||
|
|
@ -31,6 +31,10 @@
|
|||
android:id="@+id/nav_bookmarks"
|
||||
android:icon="@drawable/ic_bookmark"
|
||||
android:title="@string/bookmarks" />
|
||||
<item
|
||||
android:id="@+id/nav_filters"
|
||||
android:icon="@drawable/ic_filter"
|
||||
android:title="@string/filters" />
|
||||
<item
|
||||
android:id="@+id/nav_follow_request"
|
||||
android:icon="@drawable/ic_group_add"
|
||||
|
|
|
@ -570,6 +570,25 @@
|
|||
<string name="toast_show_boost">Boosts are now shown!</string>
|
||||
<string name="toast_hide_boost">Boosts are now hidden!</string>
|
||||
<string name="direct_message">Direct message</string>
|
||||
<string name="filters">Filters</string>
|
||||
<string name="action_filters_empty_content">No filters to display. You can create one by clicking on the \"+\" button.</string>
|
||||
<string name="filter_keyword">Keyword or phrase</string>
|
||||
<string name="context_home">Home timeline</string>
|
||||
<string name="context_public">Public timelines</string>
|
||||
<string name="context_notification">Notifications</string>
|
||||
<string name="context_conversation">Conversations</string>
|
||||
<string name="filter_keyword_explanations">Will be matched regardless of casing in text or content warning of a toot</string>
|
||||
<string name="context_drop">Drop instead of hide</string>
|
||||
<string name="context_drop_explanations">Filtered toots will disappear irreversibly, even if filter is later removed</string>
|
||||
<string name="context_whole_word_explanations">When the keyword or phrase is alphanumeric only, it will only be applied if it matches the whole word</string>
|
||||
<string name="context_whole_word">Whole word</string>
|
||||
<string name="filter_context">Filter contexts</string>
|
||||
<string name="filter_context_explanations">One or multiple contexts where the filter should apply</string>
|
||||
<string name="filter_expire">Expire after</string>
|
||||
<string name="add_new_filter">Add New Filter</string>
|
||||
<string name="action_filter_delete">Delete filter?</string>
|
||||
<string name="action_update_filter">Update filter</string>
|
||||
<string name="action_filter_create">Create filter</string>
|
||||
|
||||
|
||||
<string-array translatable="false" name="proxy_type_choice">
|
||||
|
|
Loading…
Reference in New Issue