在左侧菜单中,我添加了文本首页,但是无法在其内容中添加标签。我该如何解决这个问题?我不想一一展示标签。我想在主页上添加默认帖子,然后在侧面显示标签。我已经检查了示例,但找不到类似的用法。类似的示例仅在各个标签中列出。
public class MainFragment extends BrowseFragment implements OnItemViewSelectedListener, OnItemViewClickedListener {
@Inject
SaatAPI saatAPI;
private GlideBackgroundManager mBackgroundManager;
SparseArray<MovieRow> mRows;
List<SaatDataLabel> labels;
public static MainFragment newInstance() {
Bundle args = new Bundle();
MainFragment fragment = new MainFragment();
fragment.setArguments(args);
return fragment;
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
App.instance().appComponent().inject(this);
mBackgroundManager = new GlideBackgroundManager(getActivity());
setBrandColor(ContextCompat.getColor(getActivity(), R.color.primary_transparent));
setHeadersState(HEADERS_ENABLED);
setHeadersTransitionOnBackEnabled(true);
setSearchAffordanceColor(getResources().getColor(android.R.color.black));
initMainScreen();
}
//todo make a better solution for later.
private void initMainScreen() {
saatAPI.getVodLabels()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(response -> {
labels = response.getData();
createDataRows(labels);
createRows();
fetchMovies(mRows);
}, e -> {
Timber.e(e, "Error fetching now playing movies: %s", e.getMessage());
});
}
private void createDataRows(List<SaatDataLabel> labels) {
mRows = new SparseArray<>();
MoviePresenter moviePresenter = new MoviePresenter();
for (SaatDataLabel label : labels) {
mRows.put(labels.indexOf(label), new MovieRow()
.setId(labels.indexOf(label))
.setAdapter(new ArrayObjectAdapter(moviePresenter))
.setTitle(label.getName())
);
}
}
private void createRows() {
setOnSearchClickedListener(view -> {
Intent intent = new Intent(getActivity(), SearchActivity.class);
startActivity(intent);
});
ArrayObjectAdapter rowsAdapter = new ArrayObjectAdapter(new ListRowPresenter());
for (int i = 0; i < mRows.size(); i++) {
MovieRow row = mRows.get(i);
HeaderItem headerItem = new HeaderItem(row.getId(), row.getTitle());
ListRow listRow = new ListRow(headerItem, row.getAdapter());
rowsAdapter.add(listRow);
}
setAdapter(rowsAdapter);
setOnItemViewSelectedListener(this);
setOnItemViewClickedListener(this);
}
private void fetchMovies(SparseArray<MovieRow> rows) {
for (int i = 0; i < rows.size(); i++) {
MovieRow row = rows.get(i);
saatAPI.getNowPlayingMovies(row.getTitle(), row.getPage())
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(response -> {
bindMovieResponse(response, rows.indexOfValue(row));
startEntranceTransition();
}, e -> {
Timber.e(e, "Error fetching now playing movies: %s", e.getMessage());
});
}
}
private void bindMovieResponse(SaatResponse<List<SaatDataVod>> response, int id) {
Log.e("bindMovieResponse", response.toString());
MovieRow row = mRows.get(id);
row.setPage(row.getPage() + 1);
for (SaatDataVod saatData : response.getData()) {
if (saatData.getCatalogPoster() != null) { // Avoid showing movie without posters
row.getAdapter().add(saatData);
}
}
}
}