Refactor ExploreTabFragment
This commit is contained in:
parent
825a81042c
commit
8d9206eeae
1 changed files with 26 additions and 7 deletions
|
@ -22,33 +22,52 @@ import java.util.List;
|
||||||
|
|
||||||
public class ExploreTabFragment extends BaseOsmAndFragment {
|
public class ExploreTabFragment extends BaseOsmAndFragment {
|
||||||
|
|
||||||
|
private ExploreRvAdapter adapter = new ExploreRvAdapter();
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||||
final View mainView = inflater.inflate(R.layout.fragment_explore_tab, container, false);
|
final View mainView = inflater.inflate(R.layout.fragment_explore_tab, container, false);
|
||||||
ExploreRvAdapter adapter = new ExploreRvAdapter();
|
|
||||||
|
adapter.setItems(generateItems());
|
||||||
|
|
||||||
final RecyclerView rv = (RecyclerView) mainView.findViewById(R.id.recycler_view);
|
final RecyclerView rv = (RecyclerView) mainView.findViewById(R.id.recycler_view);
|
||||||
rv.setLayoutManager(new LinearLayoutManager(getContext()));
|
rv.setLayoutManager(new LinearLayoutManager(getContext()));
|
||||||
adapter.setItems(getItems());
|
|
||||||
rv.setAdapter(adapter);
|
rv.setAdapter(adapter);
|
||||||
|
|
||||||
return mainView;
|
return mainView;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<Object> getItems() {
|
/**
|
||||||
|
* Cards order:
|
||||||
|
* - Download/Update
|
||||||
|
* - Open Beta
|
||||||
|
* - Edit Wiki
|
||||||
|
* - Popular Destinations
|
||||||
|
* - Maps you need
|
||||||
|
*
|
||||||
|
* @return list of generated items.
|
||||||
|
*/
|
||||||
|
private List<Object> generateItems() {
|
||||||
|
final List<Object> items = new ArrayList<>();
|
||||||
final OsmandApplication app = getMyApplication();
|
final OsmandApplication app = getMyApplication();
|
||||||
boolean nightMode = !getSettings().isLightContent();
|
final boolean nightMode = !getSettings().isLightContent();
|
||||||
List<Object> items = new ArrayList<>();
|
|
||||||
List<TravelArticle> savedArticles = app.getTravelDbHelper().searchPopular();
|
|
||||||
items.add(new OpenBetaTravelCard(app, nightMode, getFragmentManager()));
|
items.add(new OpenBetaTravelCard(app, nightMode, getFragmentManager()));
|
||||||
items.add(new StartEditingTravelCard(app, nightMode));
|
items.add(new StartEditingTravelCard(app, nightMode));
|
||||||
|
addPopularDestinations(items, nightMode);
|
||||||
|
|
||||||
|
return items;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addPopularDestinations(@NonNull List<Object> items, boolean nightMode) {
|
||||||
|
OsmandApplication app = getMyApplication();
|
||||||
|
List<TravelArticle> savedArticles = app.getTravelDbHelper().searchPopular();
|
||||||
if (!savedArticles.isEmpty()) {
|
if (!savedArticles.isEmpty()) {
|
||||||
items.add(getString(R.string.popular_destinations));
|
items.add(getString(R.string.popular_destinations));
|
||||||
for (TravelArticle article : savedArticles) {
|
for (TravelArticle article : savedArticles) {
|
||||||
items.add(new ArticleTravelCard(app, nightMode, article, getFragmentManager()));
|
items.add(new ArticleTravelCard(app, nightMode, article, getFragmentManager()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return items;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue