Use GpxTrackAdapter for tracks card

This commit is contained in:
Vitaliy 2020-08-07 13:30:10 +03:00
parent 4c9b9f6f5c
commit 960848ecf5
8 changed files with 74 additions and 86 deletions

View file

@ -16,7 +16,7 @@
android:focusable="false" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/group_name_recycler_view"
android:id="@+id/track_categories"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clipToPadding="false"
@ -29,12 +29,11 @@
tools:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
tools:listitem="@layout/point_editor_icon_category_item" />
<LinearLayout
android:id="@+id/items"
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/track_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/card_and_list_background_basic"
android:orientation="vertical"
android:paddingBottom="@dimen/route_info_button_go_margin" />
android:layout_height="match_parent"
tools:itemCount="5"
tools:listitem="@layout/gpx_track_select_item" />
</LinearLayout>

View file

@ -66,7 +66,7 @@
android:foreground="@drawable/bg_contextmenu_shadow"
android:foregroundGravity="top|fill_horizontal">
<net.osmand.plus.LockableScrollView
<androidx.core.widget.NestedScrollView
android:id="@+id/route_menu_bottom_scroll"
android:layout_width="match_parent"
android:layout_height="match_parent"
@ -82,7 +82,7 @@
</LinearLayout>
</net.osmand.plus.LockableScrollView>
</androidx.core.widget.NestedScrollView>
</FrameLayout>

View file

@ -66,9 +66,9 @@ public abstract class ContextMenuFragment extends BaseOsmAndFragment {
private View view;
private OnLayoutChangeListener containerLayoutListener;
private View topShadow;
private View bottomScrollView;
private LinearLayout cardsContainer;
private FrameLayout bottomContainer;
private LockableScrollView bottomScrollView;
private boolean portrait;
private boolean nightMode;
@ -241,7 +241,7 @@ public abstract class ContextMenuFragment extends BaseOsmAndFragment {
return bottomContainer;
}
public LockableScrollView getBottomScrollView() {
public View getBottomScrollView() {
return bottomScrollView;
}
@ -278,14 +278,17 @@ public abstract class ContextMenuFragment extends BaseOsmAndFragment {
mainView = view.findViewById(getMainViewId());
topShadow = view.findViewById(getTopShadowViewId());
cardsContainer = (LinearLayout) view.findViewById(getCardsContainerViewId());
bottomContainer = (FrameLayout) view.findViewById(getBottomContainerViewId());
bottomScrollView = (LockableScrollView) view.findViewById(getBottomScrollViewId());
cardsContainer = view.findViewById(getCardsContainerViewId());
bottomContainer = view.findViewById(getBottomContainerViewId());
bottomScrollView = view.findViewById(getBottomScrollViewId());
if (bottomScrollView instanceof LockableScrollView) {
((LockableScrollView) bottomScrollView).setScrollingEnabled(false);
}
ViewConfiguration vc = ViewConfiguration.get(context);
final int touchSlop = vc.getScaledTouchSlop();
bottomScrollView.setScrollingEnabled(false);
if (getTopViewId() != 0) {
View topView = view.findViewById(getTopViewId());
AndroidUtils.setBackground(app, topView, nightMode, R.color.card_and_list_background_light, R.color.card_and_list_background_dark);

View file

@ -8,14 +8,15 @@ import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import net.osmand.plus.LockableScrollView;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.MapActivityLayers;
import net.osmand.plus.base.ContextMenuFragment.ContextMenuFragmentListener;
import net.osmand.plus.helpers.AndroidUiHelper;
import net.osmand.plus.views.OsmandMapTileView;
import net.osmand.plus.views.layers.MapControlsLayer;
import net.osmand.plus.views.layers.MapInfoLayer;
import net.osmand.plus.views.OsmandMapTileView;
import net.osmand.plus.views.mapwidgets.widgets.RulerWidget;
import java.util.Arrays;
@ -57,7 +58,11 @@ public abstract class ContextMenuScrollFragment extends ContextMenuFragment impl
View view = super.onCreateView(inflater, container, savedInstanceState);
if (view != null) {
setListener(this);
getBottomScrollView().setScrollingEnabled(true);
View bottomScrollView = getBottomScrollView();
if (bottomScrollView instanceof LockableScrollView) {
((LockableScrollView) bottomScrollView).setScrollingEnabled(true);
}
mapBottomHudButtons = view.findViewById(R.id.map_controls_container);
if (mapBottomHudButtons != null) {

View file

@ -14,7 +14,6 @@ import androidx.recyclerview.widget.RecyclerView;
import net.osmand.AndroidUtils;
import net.osmand.GPXUtilities;
import net.osmand.IndexConstants;
import net.osmand.plus.GPXDatabase;
import net.osmand.plus.GPXDatabase.GpxDataItem;
import net.osmand.plus.GpxDbHelper;
import net.osmand.plus.OsmAndFormatter;
@ -46,6 +45,10 @@ public class GpxTrackAdapter extends RecyclerView.Adapter<GpxTrackAdapter.TrackV
this.showCurrentGpx = showCurrentGpx;
}
public List<GPXInfo> getGpxInfoList() {
return gpxInfoList;
}
public void setGpxInfoList(List<GPXInfo> gpxInfoList) {
this.gpxInfoList = gpxInfoList;
}

View file

@ -15,7 +15,6 @@ import android.view.ViewTreeObserver;
import android.widget.FrameLayout;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import androidx.annotation.NonNull;
@ -38,7 +37,7 @@ import net.osmand.plus.helpers.ImportHelper;
import net.osmand.plus.routepreparationmenu.cards.BaseCard;
import net.osmand.plus.routepreparationmenu.cards.BaseCard.CardListener;
import net.osmand.plus.routepreparationmenu.cards.ImportTrackCard;
import net.osmand.plus.routepreparationmenu.cards.SelectTrackToFollowCard;
import net.osmand.plus.routepreparationmenu.cards.TracksToFollowCard;
import net.osmand.plus.routing.RouteProvider.GPXRouteParamsBuilder;
import org.apache.commons.logging.Log;
@ -84,6 +83,11 @@ public class FollowTrackFragment extends ContextMenuScrollFragment implements Ca
return 0.5f;
}
@Override
public int getInitialMenuState() {
return MenuState.HALF_SCREEN;
}
@Override
public int getSupportedMenuStatesPortrait() {
return MenuState.HEADER_ONLY | MenuState.HALF_SCREEN | MenuState.FULL_SCREEN;
@ -161,7 +165,7 @@ public class FollowTrackFragment extends ContextMenuScrollFragment implements Ca
List<String> selectedTrackNames = GpxUiHelper.getSelectedTrackNames(app);
List<GPXInfo> list = GpxUiHelper.getSortedGPXFilesInfo(dir, selectedTrackNames, false);
if (list.size() > 0) {
SelectTrackToFollowCard tracksCard = new SelectTrackToFollowCard(mapActivity, list);
TracksToFollowCard tracksCard = new TracksToFollowCard(mapActivity, list);
tracksCard.setListener(this);
cardsContainer.addView(tracksCard.build(mapActivity));
}
@ -261,15 +265,15 @@ public class FollowTrackFragment extends ContextMenuScrollFragment implements Ca
public void onCardButtonPressed(@NonNull BaseCard card, int buttonIndex) {
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
if (card instanceof SelectTrackToFollowCard) {
if (card instanceof TracksToFollowCard) {
if (buttonIndex >= 0) {
loadAndFollowTrack((SelectTrackToFollowCard) card, buttonIndex);
loadAndFollowTrack((TracksToFollowCard) card, buttonIndex);
}
}
}
}
private void loadAndFollowTrack(SelectTrackToFollowCard card, int index) {
private void loadAndFollowTrack(TracksToFollowCard card, int index) {
MapActivity mapActivity = getMapActivity();
if (mapActivity != null && index < card.getGpxInfoList().size()) {
GPXInfo gpxInfo = card.getGpxInfoList().get(index);
@ -365,7 +369,7 @@ public class FollowTrackFragment extends ContextMenuScrollFragment implements Ca
int shadowIconId = isNightMode() ? R.drawable.bg_contextmenu_shadow : R.drawable.bg_contextmenu_shadow;
final Drawable shadowIcon = app.getUIUtilities().getIcon(shadowIconId);
final ScrollView scrollView = getBottomScrollView();
final View scrollView = getBottomScrollView();
final FrameLayout bottomContainer = getBottomContainer();
scrollView.getViewTreeObserver().addOnScrollChangedListener(new ViewTreeObserver.OnScrollChangedListener() {

View file

@ -1,20 +1,12 @@
package net.osmand.plus.routepreparationmenu.cards;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import net.osmand.AndroidUtils;
import net.osmand.IndexConstants;
import net.osmand.plus.GPXDatabase.GpxDataItem;
import net.osmand.plus.R;
import net.osmand.plus.UiUtilities;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.helpers.GpxUiHelper;
import net.osmand.plus.helpers.GpxTrackAdapter;
import net.osmand.plus.helpers.GpxUiHelper.GPXInfo;
import net.osmand.plus.mapcontextmenu.other.HorizontalSelectionAdapter;
import net.osmand.util.Algorithms;
@ -25,23 +17,29 @@ import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
public class SelectTrackToFollowCard extends BaseCard {
public class TracksToFollowCard extends BaseCard {
private Map<String, List<GPXInfo>> data;
private Map<String, List<GPXInfo>> gpxInfoCategories;
private List<GPXInfo> gpxInfoList;
private String selectedCategory;
public SelectTrackToFollowCard(MapActivity mapActivity, List<GPXInfo> gpxInfoList) {
private GpxTrackAdapter tracksAdapter;
public TracksToFollowCard(MapActivity mapActivity, List<GPXInfo> gpxInfoList) {
super(mapActivity);
this.gpxInfoList = gpxInfoList;
data = getGpxInfoCategories();
gpxInfoCategories = getGpxInfoCategories();
}
public List<GPXInfo> getGpxInfoList() {
return gpxInfoList;
}
public String getSelectedCategory() {
return selectedCategory;
}
@Override
public int getCardLayoutId() {
return R.layout.follow_track_card;
@ -54,72 +52,49 @@ public class SelectTrackToFollowCard extends BaseCard {
}
private void setupTracksItems() {
LinearLayout tracks = view.findViewById(R.id.items);
tracks.removeAllViews();
RecyclerView filesRecyclerView = view.findViewById(R.id.track_list);
filesRecyclerView.setLayoutManager(new LinearLayoutManager(view.getContext()));
filesRecyclerView.setNestedScrollingEnabled(false);
final List<GPXInfo> infoItems = data.get(selectedCategory);
if (!Algorithms.isEmpty(infoItems)) {
int minCardHeight = app.getResources().getDimensionPixelSize(R.dimen.route_info_card_row_min_height);
int contentPadding = app.getResources().getDimensionPixelSize(R.dimen.content_padding);
LayoutInflater inflater = UiUtilities.getInflater(mapActivity, nightMode);
for (int i = 0; i < infoItems.size(); i++) {
final GPXInfo item = infoItems.get(i);
View trackView = inflater.inflate(R.layout.gpx_track_item, tracks, false);
String fileName = Algorithms.getFileWithoutDirs(item.getFileName());
String title = GpxUiHelper.getGpxTitle(fileName);
GpxDataItem dataItem = getDataItem(item);
GpxUiHelper.updateGpxInfoView(trackView, title, item, dataItem, false, app);
ImageView icon = trackView.findViewById(R.id.icon);
icon.setImageDrawable(getContentIcon(R.drawable.ic_action_polygom_dark));
icon.setVisibility(View.VISIBLE);
LinearLayout container = trackView.findViewById(R.id.container);
container.setMinimumHeight(minCardHeight);
AndroidUtils.setPadding(container, contentPadding, 0, 0, 0);
trackView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
CardListener listener = getListener();
if (listener != null) {
listener.onCardButtonPressed(SelectTrackToFollowCard.this, gpxInfoList.indexOf(item));
}
tracksAdapter = new GpxTrackAdapter(view.getContext(), gpxInfoList, false);
tracksAdapter.setAdapterListener(new GpxTrackAdapter.OnItemClickListener() {
@Override
public void onItemClick(int position) {
if (position != RecyclerView.NO_POSITION) {
GPXInfo gpxInfo = tracksAdapter.getGpxInfoList().get(position);
CardListener listener = getListener();
if (listener != null) {
int index = gpxInfoList.indexOf(gpxInfo);
listener.onCardButtonPressed(TracksToFollowCard.this, index);
}
});
tracks.addView(trackView);
}
}
}
}
private GpxDataItem getDataItem(GPXInfo info) {
return app.getGpxDbHelper().getItem(new File(app.getAppPath(IndexConstants.GPX_INDEX_DIR), info.getFileName()));
});
filesRecyclerView.setAdapter(tracksAdapter);
}
private void setupCategoriesRow() {
final HorizontalSelectionAdapter selectionAdapter = new HorizontalSelectionAdapter(app, nightMode);
selectionAdapter.setItems(new ArrayList<>(data.keySet()));
selectionAdapter.setItems(new ArrayList<>(gpxInfoCategories.keySet()));
selectionAdapter.setSelectedItem(selectedCategory);
selectionAdapter.setListener(new HorizontalSelectionAdapter.HorizontalSelectionAdapterListener() {
@Override
public void onItemSelected(String item) {
setSelectedCategory(item);
selectedCategory = item;
List<GPXInfo> items = gpxInfoCategories.get(item);
tracksAdapter.setGpxInfoList(items != null ? items : new ArrayList<GPXInfo>());
tracksAdapter.notifyDataSetChanged();
selectionAdapter.notifyDataSetChanged();
}
});
RecyclerView iconCategoriesRecyclerView = view.findViewById(R.id.group_name_recycler_view);
RecyclerView iconCategoriesRecyclerView = view.findViewById(R.id.track_categories);
iconCategoriesRecyclerView.setAdapter(selectionAdapter);
iconCategoriesRecyclerView.setLayoutManager(new LinearLayoutManager(app, RecyclerView.HORIZONTAL, false));
selectionAdapter.notifyDataSetChanged();
}
private void setSelectedCategory(String category) {
selectedCategory = category;
setupTracksItems();
}
private Map<String, List<GPXInfo>> getGpxInfoCategories() {
String all = app.getString(R.string.shared_string_all);
String visible = app.getString(R.string.shared_string_visible);

View file

@ -13,7 +13,6 @@ import android.view.ViewTreeObserver;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import androidx.annotation.ColorInt;
import androidx.annotation.NonNull;
@ -444,7 +443,7 @@ public class TrackAppearanceFragment extends ContextMenuScrollFragment implement
int shadowIconId = isNightMode() ? R.drawable.bg_contextmenu_shadow : R.drawable.bg_contextmenu_shadow;
final Drawable shadowIcon = app.getUIUtilities().getIcon(shadowIconId);
final ScrollView scrollView = getBottomScrollView();
final View scrollView = getBottomScrollView();
final FrameLayout bottomContainer = getBottomContainer();
scrollView.getViewTreeObserver().addOnScrollChangedListener(new ViewTreeObserver.OnScrollChangedListener() {