Merge pull request #9839 from osmandapp/hide_gpx_folders

Hide track folder names
This commit is contained in:
vshcherb 2020-09-18 10:39:02 +02:00 committed by GitHub
commit da239a69ff
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 36 additions and 13 deletions

View file

@ -34,14 +34,17 @@ public class GpxTrackAdapter extends RecyclerView.Adapter<GpxTrackAdapter.TrackV
private LayoutInflater themedInflater;
private UiUtilities iconsCache;
private List<GPXInfo> gpxInfoList;
private boolean showCurrentGpx;
private OnItemClickListener onItemClickListener;
public GpxTrackAdapter(Context ctx, List<GPXInfo> gpxInfoList, boolean showCurrentGpx) {
private boolean showFolderName;
private boolean showCurrentGpx;
public GpxTrackAdapter(Context ctx, List<GPXInfo> gpxInfoList, boolean showCurrentGpx, boolean showFolderName) {
app = (OsmandApplication) ctx.getApplicationContext();
themedInflater = UiUtilities.getInflater(ctx, app.getDaynightHelper().isNightModeForMapControls());
iconsCache = app.getUIUtilities();
this.gpxInfoList = gpxInfoList;
this.showFolderName = showFolderName;
this.showCurrentGpx = showCurrentGpx;
}
@ -57,6 +60,10 @@ public class GpxTrackAdapter extends RecyclerView.Adapter<GpxTrackAdapter.TrackV
this.showCurrentGpx = showCurrentGpx;
}
public void setShowFolderName(boolean showFolderName) {
this.showFolderName = showFolderName;
}
@NonNull
@Override
public GpxTrackAdapter.TrackViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
@ -82,6 +89,9 @@ public class GpxTrackAdapter extends RecyclerView.Adapter<GpxTrackAdapter.TrackV
GPXInfo info = gpxInfoList.get(adapterPosition);
GpxDataItem dataItem = getDataItem(info);
String itemTitle = GpxUiHelper.getGpxTitle(info.getFileName());
if (!showFolderName) {
itemTitle = Algorithms.getFileWithoutDirs(itemTitle);
}
updateGpxInfoView(holder, itemTitle, info, dataItem, currentlyRecordingTrack, app);
holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override

View file

@ -52,7 +52,7 @@ public class SelectGpxTrackBottomSheet extends MenuBottomSheetDialogFragment {
final RecyclerView recyclerView = mainView.findViewById(R.id.gpx_track_list);
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
adapter = new GpxTrackAdapter(requireContext(), gpxInfoList, showCurrentGpx);
adapter = new GpxTrackAdapter(requireContext(), gpxInfoList, showCurrentGpx, true);
adapter.setAdapterListener(new GpxTrackAdapter.OnItemClickListener() {
@Override
public void onItemClick(int position) {

View file

@ -64,6 +64,7 @@ public class SelectFileBottomSheet extends BottomSheetBehaviourDialogFragment {
private Map<String, List<GPXInfo>> gpxInfoMap;
private Mode fragmentMode;
private String selectedFolder;
private String allFilesFolder;
public void setFragmentMode(Mode fragmentMode) {
this.fragmentMode = fragmentMode;
@ -91,7 +92,7 @@ public class SelectFileBottomSheet extends BottomSheetBehaviourDialogFragment {
final File gpxDir = app.getAppPath(IndexConstants.GPX_INDEX_DIR);
collectDirs(gpxDir, dirs);
List<String> dirItems = new ArrayList<>();
String allFilesFolder = context.getString(R.string.shared_string_all);
allFilesFolder = context.getString(R.string.shared_string_all);
if (savedInstanceState == null) {
selectedFolder = allFilesFolder;
}
@ -116,7 +117,7 @@ public class SelectFileBottomSheet extends BottomSheetBehaviourDialogFragment {
gpxList.add(gpxInfo);
}
adapter = new GpxTrackAdapter(requireContext(), allGpxList, isShowCurrentGpx());
adapter = new GpxTrackAdapter(requireContext(), allGpxList, isShowCurrentGpx(), showFoldersName());
adapter.setAdapterListener(new OnItemClickListener() {
@Override
public void onItemClick(int position) {
@ -157,11 +158,16 @@ public class SelectFileBottomSheet extends BottomSheetBehaviourDialogFragment {
private void updateFileList(String folderName, HorizontalSelectionAdapter folderAdapter) {
List<GPXInfo> gpxInfoList = gpxInfoMap.get(folderName);
adapter.setShowFolderName(showFoldersName());
adapter.setGpxInfoList(gpxInfoList != null ? gpxInfoList : new ArrayList<GPXInfo>());
adapter.notifyDataSetChanged();
folderAdapter.notifyDataSetChanged();
}
private boolean showFoldersName() {
return allFilesFolder.equals(selectedFolder);
}
private boolean isShowCurrentGpx() {
return fragmentMode == Mode.ADD_TO_TRACK;
}

View file

@ -128,7 +128,7 @@ public class StartPlanRouteBottomSheet extends BottomSheetBehaviourDialogFragmen
}
});
final List<GPXInfo> gpxTopList = gpxList.subList(0, Math.min(5, gpxList.size()));
adapter = new GpxTrackAdapter(requireContext(), gpxTopList, false);
adapter = new GpxTrackAdapter(requireContext(), gpxTopList, false, true);
adapter.setAdapterListener(new GpxTrackAdapter.OnItemClickListener() {
@Override
public void onItemClick(int position) {

View file

@ -23,6 +23,8 @@ public class TracksToFollowCard extends BaseCard {
private List<GPXInfo> gpxInfoList;
private String selectedCategory;
private String defaultCategory;
private String visibleCategory;
private GpxTrackAdapter tracksAdapter;
@ -30,6 +32,8 @@ public class TracksToFollowCard extends BaseCard {
super(mapActivity);
this.gpxInfoList = gpxInfoList;
this.selectedCategory = selectedCategory;
defaultCategory = app.getString(R.string.shared_string_all);
visibleCategory = app.getString(R.string.shared_string_visible);
gpxInfoCategories = getGpxInfoCategories();
}
@ -62,7 +66,7 @@ public class TracksToFollowCard extends BaseCard {
filesRecyclerView.setLayoutManager(new LinearLayoutManager(view.getContext()));
filesRecyclerView.setNestedScrollingEnabled(false);
tracksAdapter = new GpxTrackAdapter(view.getContext(), gpxInfoList, false);
tracksAdapter = new GpxTrackAdapter(view.getContext(), gpxInfoList, false, showFoldersName());
tracksAdapter.setAdapterListener(new GpxTrackAdapter.OnItemClickListener() {
@Override
public void onItemClick(int position) {
@ -88,6 +92,7 @@ public class TracksToFollowCard extends BaseCard {
public void onItemSelected(String item) {
selectedCategory = item;
List<GPXInfo> items = gpxInfoCategories.get(item);
tracksAdapter.setShowFolderName(showFoldersName());
tracksAdapter.setGpxInfoList(items != null ? items : new ArrayList<GPXInfo>());
tracksAdapter.notifyDataSetChanged();
@ -101,17 +106,19 @@ public class TracksToFollowCard extends BaseCard {
selectionAdapter.notifyDataSetChanged();
}
private boolean showFoldersName() {
return defaultCategory.equals(selectedCategory) || visibleCategory.equals(selectedCategory);
}
private Map<String, List<GPXInfo>> getGpxInfoCategories() {
String all = app.getString(R.string.shared_string_all);
String visible = app.getString(R.string.shared_string_visible);
Map<String, List<GPXInfo>> gpxInfoCategories = new LinkedHashMap<>();
gpxInfoCategories.put(visible, new ArrayList<GPXInfo>());
gpxInfoCategories.put(all, new ArrayList<GPXInfo>());
gpxInfoCategories.put(visibleCategory, new ArrayList<GPXInfo>());
gpxInfoCategories.put(defaultCategory, new ArrayList<GPXInfo>());
for (GPXInfo info : gpxInfoList) {
if (info.isSelected()) {
addGpxInfoCategory(gpxInfoCategories, info, visible);
addGpxInfoCategory(gpxInfoCategories, info, visibleCategory);
}
if (!Algorithms.isEmpty(info.getFileName())) {
File file = new File(info.getFileName());
@ -120,7 +127,7 @@ public class TracksToFollowCard extends BaseCard {
addGpxInfoCategory(gpxInfoCategories, info, dirName);
}
}
addGpxInfoCategory(gpxInfoCategories, info, all);
addGpxInfoCategory(gpxInfoCategories, info, defaultCategory);
}
return gpxInfoCategories;