mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2024-11-10 20:57:25 +01:00
Fix not able to add subreddits in CustomizePostFilterActivity in anonymous mode.
This commit is contained in:
parent
e0106e23e5
commit
659cfa511d
@ -53,7 +53,8 @@ public class CustomizePostFilterActivity extends BaseActivity {
|
|||||||
private static final String POST_FILTER_STATE = "PFS";
|
private static final String POST_FILTER_STATE = "PFS";
|
||||||
private static final String ORIGINAL_NAME_STATE = "ONS";
|
private static final String ORIGINAL_NAME_STATE = "ONS";
|
||||||
private static final int ADD_SUBREDDITS_REQUEST_CODE = 1;
|
private static final int ADD_SUBREDDITS_REQUEST_CODE = 1;
|
||||||
private static final int ADD_USERS_REQUEST_CODE = 2;
|
private static final int ADD_SUBREDDITS_ANONYMOUS_REQUEST_CODE = 2;
|
||||||
|
private static final int ADD_USERS_REQUEST_CODE = 3;
|
||||||
|
|
||||||
@BindView(R.id.coordinator_layout_customize_post_filter_activity)
|
@BindView(R.id.coordinator_layout_customize_post_filter_activity)
|
||||||
CoordinatorLayout coordinatorLayout;
|
CoordinatorLayout coordinatorLayout;
|
||||||
@ -173,6 +174,9 @@ public class CustomizePostFilterActivity extends BaseActivity {
|
|||||||
@Named("default")
|
@Named("default")
|
||||||
SharedPreferences mSharedPreferences;
|
SharedPreferences mSharedPreferences;
|
||||||
@Inject
|
@Inject
|
||||||
|
@Named("current_account")
|
||||||
|
SharedPreferences currentAccountSharedPreferences;
|
||||||
|
@Inject
|
||||||
CustomThemeWrapper mCustomThemeWrapper;
|
CustomThemeWrapper mCustomThemeWrapper;
|
||||||
@Inject
|
@Inject
|
||||||
Executor mExecutor;
|
Executor mExecutor;
|
||||||
@ -239,9 +243,17 @@ public class CustomizePostFilterActivity extends BaseActivity {
|
|||||||
onlySpoilerSwitch.performClick();
|
onlySpoilerSwitch.performClick();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
String accessToken = currentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null);
|
||||||
addSubredditsImageView.setOnClickListener(view -> {
|
addSubredditsImageView.setOnClickListener(view -> {
|
||||||
Intent intent = new Intent(this, SubredditMultiselectionActivity.class);
|
if (accessToken == null) {
|
||||||
startActivityForResult(intent, ADD_SUBREDDITS_REQUEST_CODE);
|
Intent intent = new Intent(this, SearchActivity.class);
|
||||||
|
intent.putExtra(SearchActivity.EXTRA_SEARCH_ONLY_SUBREDDITS, true);
|
||||||
|
intent.putExtra(SearchActivity.EXTRA_IS_MULTI_SELECTION, true);
|
||||||
|
startActivityForResult(intent, ADD_SUBREDDITS_ANONYMOUS_REQUEST_CODE);
|
||||||
|
} else {
|
||||||
|
Intent intent = new Intent(this, SubredditMultiselectionActivity.class);
|
||||||
|
startActivityForResult(intent, ADD_SUBREDDITS_REQUEST_CODE);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
addUsersImageView.setOnClickListener(view -> {
|
addUsersImageView.setOnClickListener(view -> {
|
||||||
@ -425,19 +437,10 @@ public class CustomizePostFilterActivity extends BaseActivity {
|
|||||||
if (resultCode == RESULT_OK && data != null) {
|
if (resultCode == RESULT_OK && data != null) {
|
||||||
if (requestCode == ADD_SUBREDDITS_REQUEST_CODE) {
|
if (requestCode == ADD_SUBREDDITS_REQUEST_CODE) {
|
||||||
ArrayList<String> subredditNames = data.getStringArrayListExtra(SubredditMultiselectionActivity.EXTRA_RETURN_SELECTED_SUBREDDITS);
|
ArrayList<String> subredditNames = data.getStringArrayListExtra(SubredditMultiselectionActivity.EXTRA_RETURN_SELECTED_SUBREDDITS);
|
||||||
String currentSubreddits = excludesSubredditsTextInputEditText.getText().toString().trim();
|
updateExcludeSubredditNames(subredditNames);
|
||||||
if (subredditNames != null && !currentSubreddits.isEmpty() && currentSubreddits.charAt(currentSubreddits.length() - 1) != ',') {
|
} else if (requestCode == ADD_SUBREDDITS_ANONYMOUS_REQUEST_CODE) {
|
||||||
String newString = currentSubreddits + ",";
|
ArrayList<String> subredditNames = data.getStringArrayListExtra(SearchActivity.RETURN_EXTRA_SELECTED_SUBREDDIT_NAMES);
|
||||||
excludesSubredditsTextInputEditText.setText(newString);
|
updateExcludeSubredditNames(subredditNames);
|
||||||
}
|
|
||||||
if (subredditNames != null) {
|
|
||||||
StringBuilder stringBuilder = new StringBuilder();
|
|
||||||
for (String s : subredditNames) {
|
|
||||||
stringBuilder.append(s).append(",");
|
|
||||||
}
|
|
||||||
stringBuilder.deleteCharAt(stringBuilder.length() - 1);
|
|
||||||
excludesSubredditsTextInputEditText.append(stringBuilder.toString());
|
|
||||||
}
|
|
||||||
} else if (requestCode == ADD_USERS_REQUEST_CODE) {
|
} else if (requestCode == ADD_USERS_REQUEST_CODE) {
|
||||||
ArrayList<String> usernames = data.getStringArrayListExtra(SearchActivity.RETURN_EXTRA_SELECTED_USERNAMES);
|
ArrayList<String> usernames = data.getStringArrayListExtra(SearchActivity.RETURN_EXTRA_SELECTED_USERNAMES);
|
||||||
String currentUsers = excludesUsersTextInputEditText.getText().toString().trim();
|
String currentUsers = excludesUsersTextInputEditText.getText().toString().trim();
|
||||||
@ -457,6 +460,22 @@ public class CustomizePostFilterActivity extends BaseActivity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void updateExcludeSubredditNames(ArrayList<String> subredditNames) {
|
||||||
|
String currentSubreddits = excludesSubredditsTextInputEditText.getText().toString().trim();
|
||||||
|
if (subredditNames != null && !currentSubreddits.isEmpty() && currentSubreddits.charAt(currentSubreddits.length() - 1) != ',') {
|
||||||
|
String newString = currentSubreddits + ",";
|
||||||
|
excludesSubredditsTextInputEditText.setText(newString);
|
||||||
|
}
|
||||||
|
if (subredditNames != null) {
|
||||||
|
StringBuilder stringBuilder = new StringBuilder();
|
||||||
|
for (String s : subredditNames) {
|
||||||
|
stringBuilder.append(s).append(",");
|
||||||
|
}
|
||||||
|
stringBuilder.deleteCharAt(stringBuilder.length() - 1);
|
||||||
|
excludesSubredditsTextInputEditText.append(stringBuilder.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void constructPostFilter() {
|
private void constructPostFilter() {
|
||||||
postFilter.name = nameTextInputEditText.getText().toString();
|
postFilter.name = nameTextInputEditText.getText().toString();
|
||||||
postFilter.maxVote = maxVoteTextInputEditText.getText() == null || maxVoteTextInputEditText.getText().toString().equals("") ? -1 : Integer.parseInt(maxVoteTextInputEditText.getText().toString());
|
postFilter.maxVote = maxVoteTextInputEditText.getText() == null || maxVoteTextInputEditText.getText().toString().equals("") ? -1 : Integer.parseInt(maxVoteTextInputEditText.getText().toString());
|
||||||
|
Loading…
Reference in New Issue
Block a user