Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix EnhancedBrowseFragment duplicating items on resume #2266

Merged
merged 1 commit into from
Nov 16, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,12 @@ public class EnhancedBrowseFragment extends Fragment implements RowLoader, View.
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
favSongsRowItem = new BaseRowItem(FakeBaseItem.INSTANCE.getFAV_SONGS());

mRowsAdapter = new MutableObjectAdapter<Row>(new PositionableListRowPresenter());
backgroundService.getValue().attach(requireActivity());

setupViews();
setupQueries(this);
}

@Nullable
Expand All @@ -133,22 +139,11 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
.findFragmentById(R.id.rowsFragment);
}

mRowsAdapter = new MutableObjectAdapter<Row>(new PositionableListRowPresenter());
mRowsFragment.setAdapter(mRowsAdapter);

return binding.getRoot();
}

@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);

backgroundService.getValue().attach(requireActivity());

setupViews();
setupQueries(this);
}

@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
Expand Down Expand Up @@ -211,7 +206,8 @@ public void onResume() {
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
if (!getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED)) return;
if (!getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED))
return;

for (int i = 0; i < mRowsAdapter.size(); i++) {
if (mRowsAdapter.get(i) instanceof ListRow) {
Expand Down Expand Up @@ -293,7 +289,7 @@ public void loadRows(List<BrowseRowDef> rows) {

addAdditionalRows(mRowsAdapter);

mRowsFragment.setAdapter(mRowsAdapter);
if (mRowsFragment != null) mRowsFragment.setAdapter(mRowsAdapter);
}

protected void addAdditionalRows(MutableObjectAdapter<Row> rowAdapter) {
Expand Down Expand Up @@ -409,7 +405,7 @@ public void onItemClicked(Presenter.ViewHolder itemViewHolder, Object item, RowP

case SERIES:
case LiveTvOption.LIVE_TV_SERIES_OPTION_ID:
navigationRepository.getValue().navigate(Destinations.INSTANCE.libraryBrowser(FakeBaseItem.INSTANCE.getSERIES_TIMERS()));
navigationRepository.getValue().navigate(Destinations.INSTANCE.libraryBrowser(FakeBaseItem.INSTANCE.getSERIES_TIMERS()));
break;

case SCHEDULE:
Expand Down Expand Up @@ -470,7 +466,8 @@ public void onItemSelected(Presenter.ViewHolder itemViewHolder, Object item,
mTitle.setText(rowItem.getName(requireContext()));

String summary = rowItem.getSummary(requireContext());
if (summary != null) mSummary.setText(markdownRenderer.getValue().toMarkdownSpanned(summary));
if (summary != null)
mSummary.setText(markdownRenderer.getValue().toMarkdownSpanned(summary));
else mSummary.setText(null);

InfoLayoutHelper.addInfoRow(requireContext(), rowItem, mInfoRow, true, true);
Expand Down