Improve filters
This commit is contained in:
parent
c1848ffdc4
commit
e97f05d1d4
|
@ -1536,12 +1536,7 @@ public abstract class BaseMainActivity extends BaseActivity
|
||||||
popup.setOnDismissListener(new PopupMenu.OnDismissListener() {
|
popup.setOnDismissListener(new PopupMenu.OnDismissListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onDismiss(PopupMenu menu) {
|
public void onDismiss(PopupMenu menu) {
|
||||||
if(homeFragment != null && homeFragment.getUserVisibleHint())
|
refreshFilters();
|
||||||
homeFragment.refreshFilter();
|
|
||||||
if(localFragment != null && localFragment.getUserVisibleHint())
|
|
||||||
localFragment.refreshFilter();
|
|
||||||
if(federatedFragment != null && federatedFragment.getUserVisibleHint())
|
|
||||||
federatedFragment.refreshFilter();
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
|
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
|
||||||
|
@ -1629,6 +1624,14 @@ public abstract class BaseMainActivity extends BaseActivity
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void refreshFilters(){
|
||||||
|
if(homeFragment != null && homeFragment.getUserVisibleHint())
|
||||||
|
homeFragment.refreshFilter();
|
||||||
|
if(localFragment != null && localFragment.getUserVisibleHint())
|
||||||
|
localFragment.refreshFilter();
|
||||||
|
if(federatedFragment != null && federatedFragment.getUserVisibleHint())
|
||||||
|
federatedFragment.refreshFilter();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onNewIntent(Intent intent) {
|
protected void onNewIntent(Intent intent) {
|
||||||
|
|
|
@ -40,6 +40,7 @@ import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import fr.gouv.etalab.mastodon.R;
|
import fr.gouv.etalab.mastodon.R;
|
||||||
import fr.gouv.etalab.mastodon.activities.BaseMainActivity;
|
import fr.gouv.etalab.mastodon.activities.BaseMainActivity;
|
||||||
|
import fr.gouv.etalab.mastodon.activities.MainActivity;
|
||||||
import fr.gouv.etalab.mastodon.asynctasks.ManageFiltersAsyncTask;
|
import fr.gouv.etalab.mastodon.asynctasks.ManageFiltersAsyncTask;
|
||||||
import fr.gouv.etalab.mastodon.client.APIResponse;
|
import fr.gouv.etalab.mastodon.client.APIResponse;
|
||||||
import fr.gouv.etalab.mastodon.client.Entities.Filters;
|
import fr.gouv.etalab.mastodon.client.Entities.Filters;
|
||||||
|
@ -208,6 +209,7 @@ public class FilterAdapter extends BaseAdapter implements OnFilterActionInterfac
|
||||||
filterSent.setIrreversible(context_drop.isChecked());
|
filterSent.setIrreversible(context_drop.isChecked());
|
||||||
new ManageFiltersAsyncTask(context, ManageFiltersAsyncTask.action.UPDATE_FILTER, filterSent, FilterAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
new ManageFiltersAsyncTask(context, ManageFiltersAsyncTask.action.UPDATE_FILTER, filterSent, FilterAdapter.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||||
}
|
}
|
||||||
|
((MainActivity)context).refreshFilters();
|
||||||
dialog.dismiss();
|
dialog.dismiss();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -141,6 +141,7 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
|
||||||
private StatusListAdapter statusListAdapter;
|
private StatusListAdapter statusListAdapter;
|
||||||
private RetrieveFeedsAsyncTask.Type type;
|
private RetrieveFeedsAsyncTask.Type type;
|
||||||
private String targetedId;
|
private String targetedId;
|
||||||
|
private final int HIDDEN_STATUS = 0;
|
||||||
private final int DISPLAYED_STATUS = 1;
|
private final int DISPLAYED_STATUS = 1;
|
||||||
private final int FOCUSED_STATUS = 2;
|
private final int FOCUSED_STATUS = 2;
|
||||||
private final int COMPACT_STATUS = 3;
|
private final int COMPACT_STATUS = 3;
|
||||||
|
@ -389,6 +390,8 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
|
||||||
boolean isCompactMode = sharedpreferences.getBoolean(Helper.SET_COMPACT_MODE, true);
|
boolean isCompactMode = sharedpreferences.getBoolean(Helper.SET_COMPACT_MODE, true);
|
||||||
if( type == RetrieveFeedsAsyncTask.Type.CONTEXT && position == conversationPosition)
|
if( type == RetrieveFeedsAsyncTask.Type.CONTEXT && position == conversationPosition)
|
||||||
return FOCUSED_STATUS;
|
return FOCUSED_STATUS;
|
||||||
|
else if( !Helper.filterToots(context, statuses.get(position), timedMute, type))
|
||||||
|
return HIDDEN_STATUS;
|
||||||
else
|
else
|
||||||
return isCompactMode?COMPACT_STATUS:DISPLAYED_STATUS;
|
return isCompactMode?COMPACT_STATUS:DISPLAYED_STATUS;
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,7 +75,6 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
|
||||||
private PeertubeAdapter peertubeAdapater;
|
private PeertubeAdapter peertubeAdapater;
|
||||||
private String max_id;
|
private String max_id;
|
||||||
private List<Status> statuses;
|
private List<Status> statuses;
|
||||||
private List<Status> notFilteredStatuses;
|
|
||||||
private List<Peertube> peertubes;
|
private List<Peertube> peertubes;
|
||||||
private RetrieveFeedsAsyncTask.Type type;
|
private RetrieveFeedsAsyncTask.Type type;
|
||||||
private RelativeLayout mainLoader, nextElementLoader, textviewNoAction;
|
private RelativeLayout mainLoader, nextElementLoader, textviewNoAction;
|
||||||
|
@ -103,7 +102,6 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
|
||||||
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||||
View rootView = inflater.inflate(R.layout.fragment_status, container, false);
|
View rootView = inflater.inflate(R.layout.fragment_status, container, false);
|
||||||
statuses = new ArrayList<>();
|
statuses = new ArrayList<>();
|
||||||
notFilteredStatuses = new ArrayList<>();
|
|
||||||
peertubes = new ArrayList<>();
|
peertubes = new ArrayList<>();
|
||||||
context = getContext();
|
context = getContext();
|
||||||
Bundle bundle = this.getArguments();
|
Bundle bundle = this.getArguments();
|
||||||
|
@ -398,8 +396,7 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
|
||||||
apiResponse.setStatuses(statusesConversations);
|
apiResponse.setStatuses(statusesConversations);
|
||||||
}
|
}
|
||||||
int previousPosition = this.statuses.size();
|
int previousPosition = this.statuses.size();
|
||||||
List<Status> statuses = Helper.filterToots(context, apiResponse.getStatuses(), mutedAccount, type);
|
List<Status> statuses = apiResponse.getStatuses();
|
||||||
List<Status> notFilteredStatuses = apiResponse.getStatuses();
|
|
||||||
if( type == RetrieveFeedsAsyncTask.Type.HOME) {
|
if( type == RetrieveFeedsAsyncTask.Type.HOME) {
|
||||||
if (max_id == null || (apiResponse.getMax_id() != null && Long.parseLong(max_id) > Long.parseLong(apiResponse.getMax_id())))
|
if (max_id == null || (apiResponse.getMax_id() != null && Long.parseLong(max_id) > Long.parseLong(apiResponse.getMax_id())))
|
||||||
max_id = apiResponse.getMax_id();
|
max_id = apiResponse.getMax_id();
|
||||||
|
@ -426,7 +423,6 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
|
||||||
//Toots are older than the bookmark -> no special treatment with them
|
//Toots are older than the bookmark -> no special treatment with them
|
||||||
if( bookmark == null || Long.parseLong(statuses.get(0).getId())+1 < Long.parseLong(bookmark)){
|
if( bookmark == null || Long.parseLong(statuses.get(0).getId())+1 < Long.parseLong(bookmark)){
|
||||||
this.statuses.addAll(statuses);
|
this.statuses.addAll(statuses);
|
||||||
this.notFilteredStatuses.addAll(notFilteredStatuses);
|
|
||||||
statusListAdapter.notifyItemRangeInserted(previousPosition, statuses.size());
|
statusListAdapter.notifyItemRangeInserted(previousPosition, statuses.size());
|
||||||
}else { //Toots are younger than the bookmark
|
}else { //Toots are younger than the bookmark
|
||||||
String currentMaxId = sharedpreferences.getString(Helper.LAST_HOMETIMELINE_MAX_ID + userId + instance, null);
|
String currentMaxId = sharedpreferences.getString(Helper.LAST_HOMETIMELINE_MAX_ID + userId + instance, null);
|
||||||
|
@ -435,9 +431,6 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
|
||||||
while (position < this.statuses.size() && Long.parseLong(statuses.get(0).getId()) < Long.parseLong(this.statuses.get(position).getId())) {
|
while (position < this.statuses.size() && Long.parseLong(statuses.get(0).getId()) < Long.parseLong(this.statuses.get(position).getId())) {
|
||||||
position++;
|
position++;
|
||||||
}
|
}
|
||||||
while (positionNotFiltered < this.notFilteredStatuses.size() && Long.parseLong(statuses.get(0).getId()) < Long.parseLong(this.notFilteredStatuses.get(positionNotFiltered).getId())) {
|
|
||||||
positionNotFiltered++;
|
|
||||||
}
|
|
||||||
ArrayList<Status> tmpStatuses = new ArrayList<>();
|
ArrayList<Status> tmpStatuses = new ArrayList<>();
|
||||||
for (Status tmpStatus : statuses) {
|
for (Status tmpStatus : statuses) {
|
||||||
//Mark status at new ones when their id is greater than the bookmark id / Also increments counter
|
//Mark status at new ones when their id is greater than the bookmark id / Also increments counter
|
||||||
|
@ -457,7 +450,6 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.statuses.addAll(position, tmpStatuses);
|
this.statuses.addAll(position, tmpStatuses);
|
||||||
this.notFilteredStatuses.addAll(positionNotFiltered, tmpStatuses);
|
|
||||||
statusListAdapter.notifyItemRangeInserted(position, tmpStatuses.size());
|
statusListAdapter.notifyItemRangeInserted(position, tmpStatuses.size());
|
||||||
if( tmpStatuses.size() < 3) //If new toots are only two
|
if( tmpStatuses.size() < 3) //If new toots are only two
|
||||||
lv_status.scrollToPosition(0);
|
lv_status.scrollToPosition(0);
|
||||||
|
@ -468,7 +460,6 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
|
||||||
|
|
||||||
}else {
|
}else {
|
||||||
this.statuses.addAll(statuses);
|
this.statuses.addAll(statuses);
|
||||||
this.notFilteredStatuses.addAll(statuses);
|
|
||||||
statusListAdapter.notifyItemRangeInserted(previousPosition, statuses.size());
|
statusListAdapter.notifyItemRangeInserted(previousPosition, statuses.size());
|
||||||
}
|
}
|
||||||
if( type == RetrieveFeedsAsyncTask.Type.HOME ) {
|
if( type == RetrieveFeedsAsyncTask.Type.HOME ) {
|
||||||
|
@ -500,10 +491,9 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
|
||||||
return;
|
return;
|
||||||
if( status.getId() != null && statuses != null && statuses.size() > 0 && statuses.get(0)!= null
|
if( status.getId() != null && statuses != null && statuses.size() > 0 && statuses.get(0)!= null
|
||||||
&& Long.parseLong(status.getId()) > Long.parseLong(statuses.get(0).getId())) {
|
&& Long.parseLong(status.getId()) > Long.parseLong(statuses.get(0).getId())) {
|
||||||
List<Status> tempToot = new ArrayList();
|
List<Status> tempTootResult = new ArrayList();
|
||||||
tempToot.add(status);
|
tempTootResult.add(status);
|
||||||
List<Status> tempTootResult = Helper.filterToots(context, tempToot, mutedAccount, type);
|
if( tempTootResult.size() > 0)
|
||||||
if( tempTootResult != null && tempTootResult.size() > 0)
|
|
||||||
status = tempTootResult.get(0);
|
status = tempTootResult.get(0);
|
||||||
if (type == RetrieveFeedsAsyncTask.Type.HOME) {
|
if (type == RetrieveFeedsAsyncTask.Type.HOME) {
|
||||||
|
|
||||||
|
@ -512,7 +502,6 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
|
||||||
//Update the id of the last toot retrieved
|
//Update the id of the last toot retrieved
|
||||||
MainActivity.lastHomeId = status.getId();
|
MainActivity.lastHomeId = status.getId();
|
||||||
statuses.add(0, status);
|
statuses.add(0, status);
|
||||||
notFilteredStatuses.add(0, status);
|
|
||||||
if (!status.getAccount().getId().equals(userId))
|
if (!status.getAccount().getId().equals(userId))
|
||||||
MainActivity.countNewStatus++;
|
MainActivity.countNewStatus++;
|
||||||
statusListAdapter.notifyItemInserted(0);
|
statusListAdapter.notifyItemInserted(0);
|
||||||
|
@ -525,7 +514,6 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
|
||||||
|
|
||||||
status.setNew(false);
|
status.setNew(false);
|
||||||
statuses.add(0, status);
|
statuses.add(0, status);
|
||||||
notFilteredStatuses.add(0, status);
|
|
||||||
int firstVisibleItem = mLayoutManager.findFirstVisibleItemPosition();
|
int firstVisibleItem = mLayoutManager.findFirstVisibleItemPosition();
|
||||||
if (firstVisibleItem > 0)
|
if (firstVisibleItem > 0)
|
||||||
statusListAdapter.notifyItemInserted(0);
|
statusListAdapter.notifyItemInserted(0);
|
||||||
|
@ -538,14 +526,6 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Refresh status in list
|
|
||||||
*/
|
|
||||||
public void refreshFilter(){
|
|
||||||
statuses.clear();
|
|
||||||
statuses.addAll(Helper.filterToots(context, notFilteredStatuses, mutedAccount, type));
|
|
||||||
statusListAdapter.notifyDataSetChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onResume(){
|
public void onResume(){
|
||||||
|
@ -689,13 +669,19 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Refresh status in list
|
||||||
|
*/
|
||||||
|
public void refreshFilter(){
|
||||||
|
statusListAdapter.notifyDataSetChanged();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onRetrieveMissingFeeds(List<Status> statusesMissing) {
|
public void onRetrieveMissingFeeds(List<Status> statuses) {
|
||||||
if(swipeRefreshLayout == null)
|
if(swipeRefreshLayout == null)
|
||||||
return;
|
return;
|
||||||
swipeRefreshLayout.setRefreshing(false);
|
swipeRefreshLayout.setRefreshing(false);
|
||||||
|
|
||||||
List<Status> statuses = Helper.filterToots(context, statusesMissing, mutedAccount, type);
|
|
||||||
if( isSwipped && this.statuses != null && this.statuses.size() > 0) {
|
if( isSwipped && this.statuses != null && this.statuses.size() > 0) {
|
||||||
for (Status status : this.statuses) {
|
for (Status status : this.statuses) {
|
||||||
status.setNew(false);
|
status.setNew(false);
|
||||||
|
@ -713,7 +699,6 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
|
||||||
statuses.get(i).setNew(true);
|
statuses.get(i).setNew(true);
|
||||||
inserted++;
|
inserted++;
|
||||||
this.statuses.add(0, statuses.get(i));
|
this.statuses.add(0, statuses.get(i));
|
||||||
notFilteredStatuses.add(0, statuses.get(i));
|
|
||||||
if (type == RetrieveFeedsAsyncTask.Type.HOME && !statuses.get(i).getAccount().getId().equals(userId))
|
if (type == RetrieveFeedsAsyncTask.Type.HOME && !statuses.get(i).getAccount().getId().equals(userId))
|
||||||
MainActivity.countNewStatus++;
|
MainActivity.countNewStatus++;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2584,10 +2584,8 @@ public class Helper {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static List<Status> filterToots(Context context, List<Status> statuses, List<String> timedMute, RetrieveFeedsAsyncTask.Type type){
|
|
||||||
if( statuses == null || statuses.size() == 0 )
|
public static boolean filterToots(Context context, Status status, List<String> timedMute, RetrieveFeedsAsyncTask.Type type){
|
||||||
return statuses;
|
|
||||||
ArrayList<Status> filteredStatus = new ArrayList<>();
|
|
||||||
String filter;
|
String filter;
|
||||||
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||||
if( type == RetrieveFeedsAsyncTask.Type.HOME)
|
if( type == RetrieveFeedsAsyncTask.Type.HOME)
|
||||||
|
@ -2596,7 +2594,7 @@ public class Helper {
|
||||||
filter = sharedpreferences.getString(Helper.SET_FILTER_REGEX_LOCAL, null);
|
filter = sharedpreferences.getString(Helper.SET_FILTER_REGEX_LOCAL, null);
|
||||||
else
|
else
|
||||||
filter = sharedpreferences.getString(Helper.SET_FILTER_REGEX_PUBLIC, null);
|
filter = sharedpreferences.getString(Helper.SET_FILTER_REGEX_PUBLIC, null);
|
||||||
for(Status status: statuses){
|
|
||||||
String content = status.getContent();
|
String content = status.getContent();
|
||||||
if( status.getSpoiler_text() != null)
|
if( status.getSpoiler_text() != null)
|
||||||
content += status.getSpoiler_text();
|
content += status.getSpoiler_text();
|
||||||
|
@ -2655,12 +2653,9 @@ public class Helper {
|
||||||
addToot = false;
|
addToot = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(addToot)
|
|
||||||
filteredStatus.add(status);
|
|
||||||
}
|
|
||||||
return filteredStatus;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
return addToot;
|
||||||
|
}
|
||||||
|
|
||||||
public static void colorizeIconMenu(Menu menu, int toolbarIconsColor) {
|
public static void colorizeIconMenu(Menu menu, int toolbarIconsColor) {
|
||||||
final PorterDuffColorFilter colorFilter
|
final PorterDuffColorFilter colorFilter
|
||||||
|
|
Loading…
Reference in New Issue