Use static

This commit is contained in:
tom79 2019-08-18 18:20:48 +02:00
parent 8e731de073
commit e4b6414549
7 changed files with 41 additions and 17 deletions

View File

@ -179,6 +179,11 @@ public abstract class BaseMainActivity extends BaseActivity
public static HashMap<String, Integer> poll_limits = new HashMap<>();
private Instance instanceClass;
public static List<String> mutedAccount = new ArrayList<>();
public static String regex_home, regex_local, regex_public;
public static boolean show_boosts, show_replies, show_art_nsfw;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -216,6 +221,14 @@ public abstract class BaseMainActivity extends BaseActivity
countNewStatus = 0;
countNewNotifications = 0;
regex_home = sharedpreferences.getString(Helper.SET_FILTER_REGEX_HOME, null);
regex_local = sharedpreferences.getString(Helper.SET_FILTER_REGEX_LOCAL, null);
regex_public = sharedpreferences.getString(Helper.SET_FILTER_REGEX_PUBLIC, null);
show_art_nsfw = sharedpreferences.getBoolean(Helper.SET_ART_WITH_NSFW, false);
show_boosts = sharedpreferences.getBoolean(Helper.SET_SHOW_BOOSTS, true);
show_replies = sharedpreferences.getBoolean(Helper.SET_SHOW_REPLIES, true);
if (!isTaskRoot()
&& getIntent().hasCategory(Intent.CATEGORY_LAUNCHER)
&& getIntent().getAction() != null

View File

@ -595,6 +595,7 @@ public class ManageTimelines {
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putBoolean(Helper.SET_ART_WITH_NSFW, show_nsfw[0]);
editor.apply();
MainActivity.show_art_nsfw = show_nsfw[0];
}
return false;
}
@ -674,12 +675,14 @@ public class ManageTimelines {
editor.putBoolean(Helper.SET_SHOW_BOOSTS, show_boosts[0]);
itemShowBoosts.setChecked(show_boosts[0]);
editor.apply();
MainActivity.show_boosts = show_boosts[0];
break;
case R.id.action_show_replies:
show_replies[0] = !show_replies[0];
editor.putBoolean(Helper.SET_SHOW_REPLIES, show_replies[0]);
itemShowReplies.setChecked(show_replies[0]);
editor.apply();
MainActivity.show_replies = show_replies[0];
break;
case R.id.action_filter:
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(context, style);
@ -715,12 +718,18 @@ public class ManageTimelines {
@Override
public void onClick(DialogInterface dialog, int id) {
itemFilter.setTitle(editText.getText().toString().trim());
if(displayStatusFragment != null && displayStatusFragment.getUserVisibleHint() && tl.getType() == Type.HOME)
if(displayStatusFragment != null && displayStatusFragment.getUserVisibleHint() && tl.getType() == Type.HOME) {
editor.putString(Helper.SET_FILTER_REGEX_HOME, editText.getText().toString().trim());
if(displayStatusFragment != null && displayStatusFragment.getUserVisibleHint() && tl.getType() == Type.LOCAL)
MainActivity.regex_home = editText.getText().toString().trim();
}
if(displayStatusFragment != null && displayStatusFragment.getUserVisibleHint() && tl.getType() == Type.LOCAL) {
editor.putString(Helper.SET_FILTER_REGEX_LOCAL, editText.getText().toString().trim());
if(displayStatusFragment != null && displayStatusFragment.getUserVisibleHint() && tl.getType() == Type.PUBLIC)
MainActivity.regex_local = editText.getText().toString().trim();
}
if(displayStatusFragment != null && displayStatusFragment.getUserVisibleHint() && tl.getType() == Type.PUBLIC) {
editor.putString(Helper.SET_FILTER_REGEX_PUBLIC, editText.getText().toString().trim());
MainActivity.regex_public = editText.getText().toString().trim();
}
editor.apply();
}
});

View File

@ -151,7 +151,7 @@ public class ArtListAdapter extends RecyclerView.Adapter implements OnPostAction
@Override
public int getItemViewType(int position) {
if( !Helper.filterToots(context, statuses.get(position), null))
if( !Helper.filterToots(statuses.get(position), null))
return HIDDEN_STATUS;
else
return DISPLAYED_STATUS;

View File

@ -176,7 +176,7 @@ public class PixelfedListAdapter extends RecyclerView.Adapter implements OnPostA
@Override
public int getItemViewType(int position) {
if( !Helper.filterToots(context, statuses.get(position), null))
if( !Helper.filterToots(statuses.get(position), null))
return HIDDEN_STATUS;
else
return DISPLAYED_STATUS;

View File

@ -845,7 +845,7 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
@Override
public int getItemViewType(int position) {
if( type != RetrieveFeedsAsyncTask.Type.REMOTE_INSTANCE && type != RetrieveFeedsAsyncTask.Type.NEWS && !Helper.filterToots(context, statuses.get(position), type))
if( type != RetrieveFeedsAsyncTask.Type.REMOTE_INSTANCE && type != RetrieveFeedsAsyncTask.Type.NEWS && !Helper.filterToots(statuses.get(position), type))
return HIDDEN_STATUS;
if( statuses.get(position).isFocused() && type == RetrieveFeedsAsyncTask.Type.CONTEXT && statuses.get(position).getViewType() != CONSOLE_STATUS)
return FOCUSED_STATUS;

View File

@ -678,7 +678,6 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
boolean liveNotifications = sharedpreferences.getBoolean(Helper.SET_LIVE_NOTIFICATIONS, true);
if (type == RetrieveFeedsAsyncTask.Type.HOME){
if( getUserVisibleHint() ){
statusListAdapter.updateMuted(mutedAccount);
if( statuses != null && statuses.size() > 0 && asyncTask.getStatus() != AsyncTask.Status.RUNNING) {
retrieveMissingToots(statuses.get(0).getId());
}

View File

@ -222,6 +222,9 @@ import okhttp3.TlsVersion;
import static android.content.Context.DOWNLOAD_SERVICE;
import static app.fedilab.android.activities.BaseMainActivity.mutedAccount;
import static app.fedilab.android.activities.BaseMainActivity.regex_home;
import static app.fedilab.android.activities.BaseMainActivity.regex_local;
import static app.fedilab.android.activities.BaseMainActivity.regex_public;
import static com.koushikdutta.async.util.StreamUtility.copyStream;
import static app.fedilab.android.activities.BaseMainActivity.filters;
@ -3554,20 +3557,20 @@ public class Helper {
return emojiCount/2;
}
public static boolean filterToots(Context context, Status status, RetrieveFeedsAsyncTask.Type type){
public static boolean filterToots(Status status, RetrieveFeedsAsyncTask.Type type){
String filter;
if( status == null)
return true;
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
if( type != null) {
if (type == RetrieveFeedsAsyncTask.Type.HOME)
filter = sharedpreferences.getString(Helper.SET_FILTER_REGEX_HOME, null);
filter = regex_home;
else if (type == RetrieveFeedsAsyncTask.Type.LOCAL)
filter = sharedpreferences.getString(Helper.SET_FILTER_REGEX_LOCAL, null);
filter = regex_local;
else
filter = sharedpreferences.getString(Helper.SET_FILTER_REGEX_PUBLIC, null);
filter = regex_public;
}else {
filter = sharedpreferences.getString(Helper.SET_FILTER_REGEX_PUBLIC, null);
filter = regex_public;
}
String content = status.getContent();
@ -3575,8 +3578,8 @@ public class Helper {
content += " "+ status.getSpoiler_text();
if( status.getAccount() == null)
return false;
boolean show_nsfw = sharedpreferences.getBoolean(Helper.SET_ART_WITH_NSFW, false);
if( type == RetrieveFeedsAsyncTask.Type.ART && !show_nsfw && status.isSensitive())
if( type == RetrieveFeedsAsyncTask.Type.ART && !MainActivity.show_art_nsfw && status.isSensitive())
return false;
if(MainActivity.filters != null){
@ -3612,9 +3615,9 @@ public class Helper {
}catch (Exception ignored){ }
}
if (type == RetrieveFeedsAsyncTask.Type.HOME) {
if (status.getReblog() != null && !sharedpreferences.getBoolean(Helper.SET_SHOW_BOOSTS, true))
if (status.getReblog() != null && !MainActivity.show_boosts)
return false;
else if (status.getIn_reply_to_id() != null && !status.getIn_reply_to_id().equals("null") && !sharedpreferences.getBoolean(Helper.SET_SHOW_REPLIES, true)) {
else if (status.getIn_reply_to_id() != null && !status.getIn_reply_to_id().equals("null") && !MainActivity.show_replies) {
return false;
}
} else {