Fix crash when adding a community to multi-communties

This commit fixes the issue where the app previously crashed when adding a community to a multi-community from search.
This commit is contained in:
Bazsalanszky 2024-07-09 10:37:49 +02:00
parent e96a89d430
commit 1cdd490789
3 changed files with 8 additions and 6 deletions

View File

@ -470,7 +470,7 @@ public class SearchActivity extends BaseActivity {
} else if (requestCode == SUBREDDIT_SEARCH_REQUEST_CODE) {
Intent returnIntent = new Intent();
if (getIntent().getBooleanExtra(EXTRA_IS_MULTI_SELECTION, false)) {
returnIntent.putStringArrayListExtra(RETURN_EXTRA_SELECTED_SUBREDDIT_NAMES, data.getStringArrayListExtra(SearchSubredditsResultActivity.RETURN_EXTRA_SELECTED_SUBREDDIT_NAMES));
returnIntent.putParcelableArrayListExtra(RETURN_EXTRA_SELECTED_SUBREDDIT_NAMES, data.getParcelableArrayListExtra(SearchSubredditsResultActivity.RETURN_EXTRA_SELECTED_SUBREDDIT_NAMES));
} else {
SubscribedSubredditData communityData = data.getParcelableExtra(SearchSubredditsResultActivity.EXTRA_RETURN_SUBREDDIT_NAME);
String iconUrl = data.getStringExtra(SearchSubredditsResultActivity.EXTRA_RETURN_SUBREDDIT_ICON_URL);

View File

@ -35,6 +35,7 @@ import eu.toldi.infinityforlemmy.customviews.slidr.Slidr;
import eu.toldi.infinityforlemmy.events.SwitchAccountEvent;
import eu.toldi.infinityforlemmy.fragments.SubredditListingFragment;
import eu.toldi.infinityforlemmy.subreddit.SubredditData;
import eu.toldi.infinityforlemmy.subreddit.SubredditWithSelection;
import eu.toldi.infinityforlemmy.subscribedsubreddit.SubscribedSubredditData;
import eu.toldi.infinityforlemmy.utils.SharedPreferencesUtils;
@ -171,9 +172,9 @@ public class SearchSubredditsResultActivity extends BaseActivity implements Acti
return true;
} else if (item.getItemId() == R.id.action_save_search_subreddits_result_activity) {
if (mFragment != null) {
ArrayList<String> selectedSubredditNames = ((SubredditListingFragment) mFragment).getSelectedSubredditNames();
ArrayList<SubredditWithSelection> selectedSubredditNames = ((SubredditListingFragment) mFragment).getSelectedSubredditNames();
Intent returnIntent = new Intent();
returnIntent.putStringArrayListExtra(RETURN_EXTRA_SELECTED_SUBREDDIT_NAMES, selectedSubredditNames);
returnIntent.putParcelableArrayListExtra(RETURN_EXTRA_SELECTED_SUBREDDIT_NAMES, selectedSubredditNames);
setResult(Activity.RESULT_OK, returnIntent);
finish();
}

View File

@ -48,6 +48,7 @@ import eu.toldi.infinityforlemmy.customtheme.CustomThemeWrapper;
import eu.toldi.infinityforlemmy.customviews.LinearLayoutManagerBugFixed;
import eu.toldi.infinityforlemmy.subreddit.SubredditData;
import eu.toldi.infinityforlemmy.subreddit.SubredditListingViewModel;
import eu.toldi.infinityforlemmy.subreddit.SubredditWithSelection;
import eu.toldi.infinityforlemmy.utils.LemmyUtils;
import eu.toldi.infinityforlemmy.utils.SharedPreferencesUtils;
@ -263,17 +264,17 @@ public class SubredditListingFragment extends Fragment implements FragmentCommun
return sortType;
}
public ArrayList<String> getSelectedSubredditNames() {
public ArrayList<SubredditWithSelection> getSelectedSubredditNames() {
if (mSubredditListingViewModel != null) {
List<SubredditData> allSubreddits = mSubredditListingViewModel.getSubreddits().getValue();
if (allSubreddits == null) {
return null;
}
ArrayList<String> selectedSubreddits = new ArrayList<>();
ArrayList<SubredditWithSelection> selectedSubreddits = new ArrayList<>();
for (SubredditData s : allSubreddits) {
if (s.isSelected()) {
selectedSubreddits.add(s.getName());
selectedSubreddits.add(new SubredditWithSelection(s.getName(), s.getIconUrl(), LemmyUtils.actorID2FullName(s.getActorId())));
}
}
return selectedSubreddits;