Fix NSFW for art
This commit is contained in:
parent
cf1dc7518c
commit
4ad6f7a14f
|
@ -183,7 +183,7 @@ public abstract class BaseMainActivity extends BaseActivity
|
||||||
private RelativeLayout main_app_container;
|
private RelativeLayout main_app_container;
|
||||||
private Stack<Integer> stackBack = new Stack<>();
|
private Stack<Integer> stackBack = new Stack<>();
|
||||||
public static List<Filters> filters = new ArrayList<>();
|
public static List<Filters> filters = new ArrayList<>();
|
||||||
private DisplayStatusFragment homeFragment, federatedFragment, localFragment;
|
private DisplayStatusFragment homeFragment, federatedFragment, localFragment, artFragment;
|
||||||
private DisplayNotificationsFragment notificationsFragment;
|
private DisplayNotificationsFragment notificationsFragment;
|
||||||
private static final int ERROR_DIALOG_REQUEST_CODE = 97;
|
private static final int ERROR_DIALOG_REQUEST_CODE = 97;
|
||||||
private static BroadcastReceiver receive_data, receive_federated_data, receive_local_data;
|
private static BroadcastReceiver receive_data, receive_federated_data, receive_local_data;
|
||||||
|
@ -192,7 +192,7 @@ public abstract class BaseMainActivity extends BaseActivity
|
||||||
public static int countNewNotifications = 0;
|
public static int countNewNotifications = 0;
|
||||||
private String userIdService;
|
private String userIdService;
|
||||||
public static String lastHomeId = null, lastNotificationId = null;
|
public static String lastHomeId = null, lastNotificationId = null;
|
||||||
boolean notif_follow, notif_add, notif_mention, notif_share, show_boosts, show_replies;
|
boolean notif_follow, notif_add, notif_mention, notif_share, show_boosts, show_replies , show_nsfw;
|
||||||
String show_filtered;
|
String show_filtered;
|
||||||
private AppBarLayout appBar;
|
private AppBarLayout appBar;
|
||||||
private String bookmark;
|
private String bookmark;
|
||||||
|
@ -853,6 +853,13 @@ public abstract class BaseMainActivity extends BaseActivity
|
||||||
return manageFilters(tabStrip, sharedpreferences);
|
return manageFilters(tabStrip, sharedpreferences);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
if( tabPosition.containsKey("art"))
|
||||||
|
tabStrip.getChildAt(tabPosition.get("art")).setOnLongClickListener(new View.OnLongClickListener() {
|
||||||
|
@Override
|
||||||
|
public boolean onLongClick(View v) {
|
||||||
|
return manageFilters(tabStrip, sharedpreferences);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
viewPager.setOffscreenPageLimit(countPage);
|
viewPager.setOffscreenPageLimit(countPage);
|
||||||
main_app_container = findViewById(R.id.main_app_container);
|
main_app_container = findViewById(R.id.main_app_container);
|
||||||
|
@ -1566,9 +1573,10 @@ public abstract class BaseMainActivity extends BaseActivity
|
||||||
//Only shown if the tab has focus
|
//Only shown if the tab has focus
|
||||||
if(
|
if(
|
||||||
(homeFragment != null && homeFragment.getUserVisibleHint()) ||
|
(homeFragment != null && homeFragment.getUserVisibleHint()) ||
|
||||||
(federatedFragment != null && federatedFragment.getUserVisibleHint()) ||
|
(federatedFragment != null && federatedFragment.getUserVisibleHint()) ||
|
||||||
(localFragment != null && localFragment.getUserVisibleHint())
|
(localFragment != null && localFragment.getUserVisibleHint()) ||
|
||||||
){
|
(artFragment != null && artFragment.getUserVisibleHint())
|
||||||
|
){
|
||||||
PopupMenu popup = null;
|
PopupMenu popup = null;
|
||||||
if(homeFragment != null && homeFragment.getUserVisibleHint())
|
if(homeFragment != null && homeFragment.getUserVisibleHint())
|
||||||
popup = new PopupMenu(BaseMainActivity.this, tabStrip.getChildAt(0));
|
popup = new PopupMenu(BaseMainActivity.this, tabStrip.getChildAt(0));
|
||||||
|
@ -1576,6 +1584,55 @@ public abstract class BaseMainActivity extends BaseActivity
|
||||||
popup = new PopupMenu(BaseMainActivity.this, tabStrip.getChildAt(tabPosition.get("local")));
|
popup = new PopupMenu(BaseMainActivity.this, tabStrip.getChildAt(tabPosition.get("local")));
|
||||||
else if(federatedFragment != null && federatedFragment.getUserVisibleHint()){
|
else if(federatedFragment != null && federatedFragment.getUserVisibleHint()){
|
||||||
popup = new PopupMenu(BaseMainActivity.this, tabStrip.getChildAt(tabPosition.get("global")));
|
popup = new PopupMenu(BaseMainActivity.this, tabStrip.getChildAt(tabPosition.get("global")));
|
||||||
|
}else if(artFragment != null && artFragment.getUserVisibleHint()){
|
||||||
|
popup = new PopupMenu(BaseMainActivity.this, tabStrip.getChildAt(tabPosition.get("art")));
|
||||||
|
popup.getMenuInflater()
|
||||||
|
.inflate(R.menu.option_tag_timeline, popup.getMenu());
|
||||||
|
Menu menu = popup.getMenu();
|
||||||
|
|
||||||
|
show_nsfw = sharedpreferences.getBoolean(Helper.SET_ART_WITH_NSFW, false);
|
||||||
|
final MenuItem itemShowNSFW = menu.findItem(R.id.action_show_nsfw);
|
||||||
|
final MenuItem itemMedia = menu.findItem(R.id.action_show_media_only);
|
||||||
|
final MenuItem itemDelete = menu.findItem(R.id.action_delete);
|
||||||
|
itemMedia.setVisible(false);
|
||||||
|
itemDelete.setVisible(false);
|
||||||
|
itemShowNSFW.setChecked(show_nsfw);
|
||||||
|
popup.setOnDismissListener(new PopupMenu.OnDismissListener() {
|
||||||
|
@Override
|
||||||
|
public void onDismiss(PopupMenu menu) {
|
||||||
|
refreshFilters();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
|
||||||
|
public boolean onMenuItemClick(MenuItem item) {
|
||||||
|
item.setShowAsAction(MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
|
||||||
|
item.setActionView(new View(getApplicationContext()));
|
||||||
|
item.setOnActionExpandListener(new MenuItem.OnActionExpandListener() {
|
||||||
|
@Override
|
||||||
|
public boolean onMenuItemActionExpand(MenuItem item) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onMenuItemActionCollapse(MenuItem item) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
switch (item.getItemId()) {
|
||||||
|
|
||||||
|
case R.id.action_show_nsfw:
|
||||||
|
show_nsfw = !show_nsfw;
|
||||||
|
itemShowNSFW.setChecked(show_nsfw);
|
||||||
|
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||||
|
editor.putBoolean(Helper.SET_ART_WITH_NSFW, show_nsfw);
|
||||||
|
editor.apply();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
popup.show();
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
if( popup == null)
|
if( popup == null)
|
||||||
return true;
|
return true;
|
||||||
|
@ -1709,6 +1766,8 @@ public abstract class BaseMainActivity extends BaseActivity
|
||||||
localFragment.refreshFilter();
|
localFragment.refreshFilter();
|
||||||
if(federatedFragment != null)
|
if(federatedFragment != null)
|
||||||
federatedFragment.refreshFilter();
|
federatedFragment.refreshFilter();
|
||||||
|
if(artFragment != null)
|
||||||
|
artFragment.refreshFilter();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -2394,19 +2453,16 @@ public abstract class BaseMainActivity extends BaseActivity
|
||||||
homeFragment = (DisplayStatusFragment) createdFragment;
|
homeFragment = (DisplayStatusFragment) createdFragment;
|
||||||
}else if( position == 1){
|
}else if( position == 1){
|
||||||
notificationsFragment = (DisplayNotificationsFragment) createdFragment;
|
notificationsFragment = (DisplayNotificationsFragment) createdFragment;
|
||||||
}else if( position ==2 && countPage > 2){
|
}else{
|
||||||
if( !display_direct && display_local)
|
if( display_local && position == tabPosition.get("local"))
|
||||||
localFragment = (DisplayStatusFragment) createdFragment;
|
localFragment = (DisplayStatusFragment) createdFragment;
|
||||||
else if (!display_local)
|
else if( display_global && position == tabPosition.get("global"))
|
||||||
federatedFragment = (DisplayStatusFragment) createdFragment;
|
|
||||||
}else if (position == 3 && countPage > 3){
|
|
||||||
if( display_local)
|
|
||||||
localFragment = (DisplayStatusFragment) createdFragment;
|
|
||||||
else if (display_global)
|
|
||||||
federatedFragment = (DisplayStatusFragment) createdFragment;
|
|
||||||
}else if( position == 4 && countPage > 4)
|
|
||||||
if( display_global)
|
|
||||||
federatedFragment = (DisplayStatusFragment) createdFragment;
|
federatedFragment = (DisplayStatusFragment) createdFragment;
|
||||||
|
else if( display_art && position == tabPosition.get("art"))
|
||||||
|
artFragment = (DisplayStatusFragment) createdFragment;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
return createdFragment;
|
return createdFragment;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -462,7 +462,7 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
|
||||||
public void onBindViewHolder(@NonNull final RecyclerView.ViewHolder viewHolder, int i) {
|
public void onBindViewHolder(@NonNull final RecyclerView.ViewHolder viewHolder, int i) {
|
||||||
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||||
final String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
final String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||||
if( type == RetrieveFeedsAsyncTask.Type.ART || (tagTimeline != null && tagTimeline.isART())) {
|
if( (type == RetrieveFeedsAsyncTask.Type.ART || (tagTimeline != null && tagTimeline.isART())) && viewHolder.getItemViewType() != HIDDEN_STATUS ) {
|
||||||
final ViewHolderArt holder = (ViewHolderArt) viewHolder;
|
final ViewHolderArt holder = (ViewHolderArt) viewHolder;
|
||||||
final Status status = statuses.get(viewHolder.getAdapterPosition());
|
final Status status = statuses.get(viewHolder.getAdapterPosition());
|
||||||
|
|
||||||
|
|
|
@ -491,6 +491,7 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
|
||||||
statusListAdapter.notifyItemRangeInserted(previousPosition, statuses.size());
|
statusListAdapter.notifyItemRangeInserted(previousPosition, statuses.size());
|
||||||
}else { //If it's an Art timeline not allowing NSFW
|
}else { //If it's an Art timeline not allowing NSFW
|
||||||
ArrayList<Status> safeStatuses = new ArrayList<>();
|
ArrayList<Status> safeStatuses = new ArrayList<>();
|
||||||
|
|
||||||
for(Status status: statuses){
|
for(Status status: statuses){
|
||||||
if( !status.isSensitive())
|
if( !status.isSensitive())
|
||||||
safeStatuses.add(status);
|
safeStatuses.add(status);
|
||||||
|
@ -498,6 +499,8 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
|
||||||
this.statuses.addAll(safeStatuses);
|
this.statuses.addAll(safeStatuses);
|
||||||
statusListAdapter.notifyItemRangeInserted(previousPosition, safeStatuses.size());
|
statusListAdapter.notifyItemRangeInserted(previousPosition, safeStatuses.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
if( type == RetrieveFeedsAsyncTask.Type.HOME ) {
|
if( type == RetrieveFeedsAsyncTask.Type.HOME ) {
|
||||||
//Update the id of the last toot retrieved
|
//Update the id of the last toot retrieved
|
||||||
|
|
|
@ -340,6 +340,7 @@ public class Helper {
|
||||||
public static final String SET_AUTOMATICALLY_SPLIT_TOOTS = "set_automatically_split_toots";
|
public static final String SET_AUTOMATICALLY_SPLIT_TOOTS = "set_automatically_split_toots";
|
||||||
public static final String SET_AUTOMATICALLY_SPLIT_TOOTS_SIZE = "set_automatically_split_toots_size";
|
public static final String SET_AUTOMATICALLY_SPLIT_TOOTS_SIZE = "set_automatically_split_toots_size";
|
||||||
public static final String SET_TRUNCATE_TOOTS_SIZE = "set_truncate_toots_size";
|
public static final String SET_TRUNCATE_TOOTS_SIZE = "set_truncate_toots_size";
|
||||||
|
public static final String SET_ART_WITH_NSFW = "set_art_with_nsfw";
|
||||||
//End points
|
//End points
|
||||||
public static final String EP_AUTHORIZE = "/oauth/authorize";
|
public static final String EP_AUTHORIZE = "/oauth/authorize";
|
||||||
|
|
||||||
|
@ -2707,65 +2708,68 @@ public class Helper {
|
||||||
else
|
else
|
||||||
filter = sharedpreferences.getString(Helper.SET_FILTER_REGEX_PUBLIC, null);
|
filter = sharedpreferences.getString(Helper.SET_FILTER_REGEX_PUBLIC, null);
|
||||||
|
|
||||||
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();
|
||||||
boolean addToot = true; //Flag to tell if the current toot will be added.
|
boolean addToot = true; //Flag to tell if the current toot will be added.
|
||||||
if( status.getAccount() == null)
|
if( status.getAccount() == null)
|
||||||
addToot = false;
|
addToot = false;
|
||||||
if(addToot && MainActivity.filters != null){
|
boolean show_nsfw = sharedpreferences.getBoolean(Helper.SET_ART_WITH_NSFW, false);
|
||||||
for(Filters mfilter: filters){
|
if( type == RetrieveFeedsAsyncTask.Type.ART && !show_nsfw && status.isSensitive()) {
|
||||||
ArrayList<String> filterContext = mfilter.getContext();
|
addToot = false;
|
||||||
if(
|
}
|
||||||
(type == RetrieveFeedsAsyncTask.Type.HOME && filterContext.contains("home")) ||
|
if(addToot && MainActivity.filters != null){
|
||||||
(type == RetrieveFeedsAsyncTask.Type.LOCAL && filterContext.contains("public")) ||
|
for(Filters mfilter: filters){
|
||||||
(type == RetrieveFeedsAsyncTask.Type.PUBLIC && filterContext.contains("public"))
|
ArrayList<String> filterContext = mfilter.getContext();
|
||||||
|
if(
|
||||||
|
(type == RetrieveFeedsAsyncTask.Type.HOME && filterContext.contains("home")) ||
|
||||||
|
(type == RetrieveFeedsAsyncTask.Type.LOCAL && filterContext.contains("public")) ||
|
||||||
|
(type == RetrieveFeedsAsyncTask.Type.PUBLIC && filterContext.contains("public"))
|
||||||
|
|
||||||
) {
|
) {
|
||||||
if (mfilter.isWhole_word() && content.contains(mfilter.getPhrase())) {
|
if (mfilter.isWhole_word() && content.contains(mfilter.getPhrase())) {
|
||||||
addToot = false;
|
addToot = false;
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
Pattern filterPattern = Pattern.compile("(" + mfilter.getPhrase() + ")", Pattern.CASE_INSENSITIVE);
|
Pattern filterPattern = Pattern.compile("(" + mfilter.getPhrase() + ")", Pattern.CASE_INSENSITIVE);
|
||||||
Matcher matcher = filterPattern.matcher(content);
|
Matcher matcher = filterPattern.matcher(content);
|
||||||
if (matcher.find())
|
if (matcher.find())
|
||||||
addToot = false;
|
addToot = false;
|
||||||
} catch (Exception ignored) { }
|
} catch (Exception ignored) { }
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if( addToot && filter != null && filter.length() > 0){
|
}
|
||||||
try {
|
if( addToot && filter != null && filter.length() > 0){
|
||||||
Pattern filterPattern = Pattern.compile("(" + filter + ")", Pattern.CASE_INSENSITIVE);
|
try {
|
||||||
Matcher matcher = filterPattern.matcher(content);
|
Pattern filterPattern = Pattern.compile("(" + filter + ")", Pattern.CASE_INSENSITIVE);
|
||||||
if (matcher.find())
|
Matcher matcher = filterPattern.matcher(content);
|
||||||
addToot = false;
|
if (matcher.find())
|
||||||
}catch (Exception ignored){ }
|
addToot = false;
|
||||||
}
|
}catch (Exception ignored){ }
|
||||||
if(addToot) {
|
}
|
||||||
if (type == RetrieveFeedsAsyncTask.Type.HOME) {
|
if(addToot) {
|
||||||
if (status.getReblog() != null && !sharedpreferences.getBoolean(Helper.SET_SHOW_BOOSTS, true))
|
if (type == RetrieveFeedsAsyncTask.Type.HOME) {
|
||||||
addToot = false;
|
if (status.getReblog() != null && !sharedpreferences.getBoolean(Helper.SET_SHOW_BOOSTS, true))
|
||||||
else if (status.getIn_reply_to_id() != null && !status.getIn_reply_to_id().equals("null") && !sharedpreferences.getBoolean(Helper.SET_SHOW_REPLIES, true)) {
|
addToot = false;
|
||||||
addToot = false;
|
else if (status.getIn_reply_to_id() != null && !status.getIn_reply_to_id().equals("null") && !sharedpreferences.getBoolean(Helper.SET_SHOW_REPLIES, true)) {
|
||||||
}
|
addToot = false;
|
||||||
} else {
|
|
||||||
if (context instanceof ShowAccountActivity) {
|
|
||||||
if (status.getReblog() != null && !((ShowAccountActivity) context).showBoosts())
|
|
||||||
addToot = false;
|
|
||||||
else if (status.getIn_reply_to_id() != null && !status.getIn_reply_to_id().equals("null") && !((ShowAccountActivity) context).showReplies())
|
|
||||||
addToot = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
if( addToot){
|
if (context instanceof ShowAccountActivity) {
|
||||||
if (timedMute != null && timedMute.size() > 0) {
|
if (status.getReblog() != null && !((ShowAccountActivity) context).showBoosts())
|
||||||
if (timedMute.contains(status.getAccount().getId()))
|
addToot = false;
|
||||||
|
else if (status.getIn_reply_to_id() != null && !status.getIn_reply_to_id().equals("null") && !((ShowAccountActivity) context).showReplies())
|
||||||
addToot = false;
|
addToot = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if( addToot){
|
||||||
|
if (timedMute != null && timedMute.size() > 0) {
|
||||||
|
if (timedMute.contains(status.getAccount().getId()))
|
||||||
|
addToot = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
return addToot;
|
return addToot;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue