Clean up sorting in tracks to follow
This commit is contained in:
parent
8e4a619229
commit
e9925fbddd
3 changed files with 54 additions and 91 deletions
|
@ -60,14 +60,11 @@
|
|||
android:layout_width="@dimen/wikipedia_options_button_width"
|
||||
android:layout_height="@dimen/dialog_button_height"
|
||||
android:layout_gravity="center"
|
||||
osmand:srcCompat="@drawable/ic_sort_waypoint_dark"
|
||||
android:tint="?attr/color_dialog_buttons"
|
||||
android:background="?attr/bg_dash_line"
|
||||
android:visibility="gone"
|
||||
tools:visibility="visible"
|
||||
android:layout_marginEnd="@dimen/content_padding"
|
||||
android:layout_marginRight="@dimen/content_padding" />
|
||||
|
||||
android:layout_marginRight="@dimen/content_padding"
|
||||
android:background="?attr/bg_dash_line"
|
||||
android:tint="?attr/color_dialog_buttons"
|
||||
osmand:srcCompat="@drawable/ic_sort_waypoint_dark" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
@ -95,14 +92,6 @@
|
|||
android:orientation="vertical"
|
||||
android:paddingBottom="@dimen/dialog_button_ex_height">
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/gpx_track_list"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1"
|
||||
tools:itemCount="1"
|
||||
tools:listitem="@layout/gpx_track_select_item" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</androidx.core.widget.NestedScrollView>
|
||||
|
|
|
@ -1,11 +1,8 @@
|
|||
package net.osmand.plus.routepreparationmenu;
|
||||
|
||||
import android.animation.Animator;
|
||||
import android.animation.AnimatorListenerAdapter;
|
||||
import android.app.Activity;
|
||||
import android.content.ActivityNotFoundException;
|
||||
import android.content.Intent;
|
||||
import android.graphics.drawable.AnimationDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
|
@ -19,21 +16,16 @@ import android.view.ViewGroup.MarginLayoutParams;
|
|||
import android.view.ViewTreeObserver.OnScrollChangedListener;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import net.osmand.AndroidUtils;
|
||||
import net.osmand.CallbackWithObject;
|
||||
import net.osmand.Collator;
|
||||
import net.osmand.GPXUtilities.GPXFile;
|
||||
import net.osmand.GPXUtilities.WptPt;
|
||||
import net.osmand.IndexConstants;
|
||||
import net.osmand.OsmAndCollator;
|
||||
import net.osmand.PlatformUtil;
|
||||
import net.osmand.ValueHolder;
|
||||
import net.osmand.data.QuadRect;
|
||||
|
@ -41,7 +33,7 @@ import net.osmand.data.RotatedTileBox;
|
|||
import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.SimplePopUpMenuItemAdapter;
|
||||
import net.osmand.plus.SimplePopUpMenuItemAdapter.SimplePopUpMenuItem;
|
||||
import net.osmand.plus.UiUtilities;
|
||||
import net.osmand.plus.UiUtilities.DialogButtonType;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
|
@ -78,8 +70,6 @@ import org.apache.commons.logging.Log;
|
|||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
|
@ -98,12 +88,14 @@ public class FollowTrackFragment extends ContextMenuScrollFragment implements Ca
|
|||
private GPXFile gpxFile;
|
||||
|
||||
private View buttonsShadow;
|
||||
private ImageButton sortButton;
|
||||
|
||||
private TracksToFollowCard tracksCard;
|
||||
private TracksSortByMode sortByMode = TracksSortByMode.BY_DATE;
|
||||
|
||||
private boolean editingTrack;
|
||||
private boolean selectingTrack;
|
||||
private int menuTitleHeight;
|
||||
TracksSortByMode sortByMode = TracksSortByMode.BY_DATE;
|
||||
|
||||
@Override
|
||||
public int getMainLayoutId() {
|
||||
|
@ -162,42 +154,6 @@ public class FollowTrackFragment extends ContextMenuScrollFragment implements Ca
|
|||
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
View view = super.onCreateView(inflater, container, savedInstanceState);
|
||||
if (view != null) {
|
||||
final ImageButton sortButton = view.findViewById(R.id.sort_button);
|
||||
Drawable background = app.getUIUtilities().getIcon(R.drawable.bg_dash_line_dark,
|
||||
isNightMode()
|
||||
? R.color.inactive_buttons_and_links_bg_dark
|
||||
: R.color.inactive_buttons_and_links_bg_light);
|
||||
sortButton.setImageResource(sortByMode.getIconId());
|
||||
AndroidUtils.setBackground(sortButton, background);
|
||||
sortButton.setVisibility(View.VISIBLE);
|
||||
final RecyclerView filesRecyclerView = view.findViewById(R.id.gpx_track_list);
|
||||
filesRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
|
||||
sortButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
final List<SimplePopUpMenuItemAdapter.SimplePopUpMenuItem> items = new ArrayList<>();
|
||||
for (final TracksSortByMode mode : TracksSortByMode.values()) {
|
||||
items.add(new SimplePopUpMenuItemAdapter.SimplePopUpMenuItem(
|
||||
getString(mode.getNameId()),
|
||||
app.getUIUtilities().getThemedIcon(mode.getIconId()),
|
||||
new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
sortByMode = mode;
|
||||
sortButton.setImageResource(mode.getIconId());
|
||||
if (tracksCard != null) {
|
||||
List<GPXInfo> list = tracksCard.getGpxInfoList();
|
||||
tracksCard.setSortByMode(mode);
|
||||
tracksCard.setGpxInfoList(list);
|
||||
|
||||
}
|
||||
}
|
||||
}, sortByMode == mode
|
||||
));
|
||||
}
|
||||
UiUtilities.showPopUpMenu(v, items);
|
||||
}
|
||||
});
|
||||
ImageButton closeButton = view.findViewById(R.id.close_button);
|
||||
buttonsShadow = view.findViewById(R.id.buttons_shadow);
|
||||
closeButton.setImageDrawable(getContentIcon(AndroidUtils.getNavigationIconResId(app)));
|
||||
|
@ -213,6 +169,7 @@ public class FollowTrackFragment extends ContextMenuScrollFragment implements Ca
|
|||
}
|
||||
setupCards();
|
||||
setupButtons(view);
|
||||
setupSortButton(view);
|
||||
setupScrollShadow();
|
||||
if (!isPortrait()) {
|
||||
int widthNoShadow = getLandscapeNoShadowWidth();
|
||||
|
@ -249,9 +206,6 @@ public class FollowTrackFragment extends ContextMenuScrollFragment implements Ca
|
|||
cardsContainer.removeAllViews();
|
||||
|
||||
if (gpxFile == null || selectingTrack) {
|
||||
ImportTrackCard importTrackCard = new ImportTrackCard(mapActivity);
|
||||
importTrackCard.setListener(this);
|
||||
|
||||
setupTracksCard();
|
||||
} else {
|
||||
String fileName = null;
|
||||
|
@ -318,8 +272,6 @@ public class FollowTrackFragment extends ContextMenuScrollFragment implements Ca
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void setupNavigateOptionsCard(GPXRouteParamsBuilder rparams) {
|
||||
MapActivity mapActivity = getMapActivity();
|
||||
if (mapActivity != null) {
|
||||
|
@ -649,6 +601,34 @@ public class FollowTrackFragment extends ContextMenuScrollFragment implements Ca
|
|||
}
|
||||
}
|
||||
|
||||
private void setupSortButton(View view) {
|
||||
final ImageButton sortButton = view.findViewById(R.id.sort_button);
|
||||
int colorId = isNightMode() ? R.color.inactive_buttons_and_links_bg_dark : R.color.inactive_buttons_and_links_bg_light;
|
||||
Drawable background = app.getUIUtilities().getIcon(R.drawable.bg_dash_line_dark, colorId);
|
||||
sortButton.setImageResource(sortByMode.getIconId());
|
||||
AndroidUtils.setBackground(sortButton, background);
|
||||
sortButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
List<SimplePopUpMenuItem> items = new ArrayList<>();
|
||||
for (final TracksSortByMode mode : TracksSortByMode.values()) {
|
||||
items.add(new SimplePopUpMenuItem(getString(mode.getNameId()),
|
||||
app.getUIUtilities().getThemedIcon(mode.getIconId()),
|
||||
new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
sortByMode = mode;
|
||||
tracksCard.setSortByMode(mode);
|
||||
sortButton.setImageResource(mode.getIconId());
|
||||
}
|
||||
}, sortByMode == mode
|
||||
));
|
||||
}
|
||||
UiUtilities.showPopUpMenu(v, items);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void setupButtons(View view) {
|
||||
View buttonsContainer = view.findViewById(R.id.buttons_container);
|
||||
buttonsContainer.setBackgroundColor(AndroidUtils.getColorFromAttr(view.getContext(), R.attr.bg_color));
|
||||
|
|
|
@ -24,19 +24,15 @@ import java.util.Map;
|
|||
|
||||
public class TracksToFollowCard extends BaseCard {
|
||||
|
||||
private List<GPXInfo> gpxInfoList;
|
||||
private Map<String, List<GPXInfo>> gpxInfoCategories;
|
||||
|
||||
private List<GPXInfo> gpxInfoList;
|
||||
private String selectedCategory;
|
||||
private GpxTrackAdapter tracksAdapter;
|
||||
private TracksSortByMode sortByMode = TracksSortByMode.BY_DATE;
|
||||
|
||||
private String defaultCategory;
|
||||
private String visibleCategory;
|
||||
TracksSortByMode sortByMode = TracksSortByMode.BY_DATE;
|
||||
|
||||
public void setSortByMode(TracksSortByMode sortByMode) {
|
||||
this.sortByMode = sortByMode;
|
||||
}
|
||||
|
||||
private GpxTrackAdapter tracksAdapter;
|
||||
private String selectedCategory;
|
||||
|
||||
public TracksToFollowCard(MapActivity mapActivity, List<GPXInfo> gpxInfoList, String selectedCategory) {
|
||||
super(mapActivity);
|
||||
|
@ -44,24 +40,19 @@ public class TracksToFollowCard extends BaseCard {
|
|||
this.selectedCategory = selectedCategory;
|
||||
defaultCategory = app.getString(R.string.shared_string_all);
|
||||
visibleCategory = app.getString(R.string.shared_string_visible);
|
||||
sortGPXInfoItems(gpxInfoList);
|
||||
gpxInfoCategories = getGpxInfoCategories();
|
||||
}
|
||||
|
||||
public void setGpxInfoList(List<GPXInfo> gpxInfoList) {
|
||||
this.gpxInfoList = gpxInfoList;
|
||||
sortGPXInfoItems(gpxInfoList);
|
||||
public void setSortByMode(TracksSortByMode sortByMode) {
|
||||
this.sortByMode = sortByMode;
|
||||
gpxInfoCategories = getGpxInfoCategories();
|
||||
List<GPXInfo> items = gpxInfoCategories.get(selectedCategory);
|
||||
tracksAdapter.setGpxInfoList(items != null ? items : new ArrayList<GPXInfo>());
|
||||
tracksAdapter.notifyDataSetChanged();
|
||||
updateTracksAdapter();
|
||||
}
|
||||
|
||||
public List<GPXInfo> getGpxInfoList() {
|
||||
return gpxInfoList;
|
||||
}
|
||||
|
||||
|
||||
public String getSelectedCategory() {
|
||||
return selectedCategory;
|
||||
}
|
||||
|
@ -107,11 +98,8 @@ public class TracksToFollowCard extends BaseCard {
|
|||
@Override
|
||||
public void onItemSelected(HorizontalSelectionAdapter.HorizontalSelectionItem item) {
|
||||
selectedCategory = item.getTitle();
|
||||
List<GPXInfo> items = gpxInfoCategories.get(selectedCategory);
|
||||
tracksAdapter.setShowFolderName(showFoldersName());
|
||||
tracksAdapter.setGpxInfoList(items != null ? items : new ArrayList<GPXInfo>());
|
||||
tracksAdapter.notifyDataSetChanged();
|
||||
|
||||
updateTracksAdapter();
|
||||
selectionAdapter.notifyDataSetChanged();
|
||||
}
|
||||
});
|
||||
|
@ -122,6 +110,12 @@ public class TracksToFollowCard extends BaseCard {
|
|||
selectionAdapter.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
private void updateTracksAdapter() {
|
||||
List<GPXInfo> items = gpxInfoCategories.get(selectedCategory);
|
||||
tracksAdapter.setGpxInfoList(items != null ? items : new ArrayList<GPXInfo>());
|
||||
tracksAdapter.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
private boolean showFoldersName() {
|
||||
return defaultCategory.equals(selectedCategory) || visibleCategory.equals(selectedCategory);
|
||||
}
|
||||
|
@ -132,6 +126,7 @@ public class TracksToFollowCard extends BaseCard {
|
|||
gpxInfoCategories.put(visibleCategory, new ArrayList<GPXInfo>());
|
||||
gpxInfoCategories.put(defaultCategory, new ArrayList<GPXInfo>());
|
||||
|
||||
sortGPXInfoItems(gpxInfoList);
|
||||
for (GPXInfo info : gpxInfoList) {
|
||||
if (info.isSelected()) {
|
||||
addGpxInfoCategory(gpxInfoCategories, info, visibleCategory);
|
||||
|
@ -178,5 +173,4 @@ public class TracksToFollowCard extends BaseCard {
|
|||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue