Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add route legend card #21619

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions OsmAnd/res/layout/fragment_mtb_routes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,16 @@

</LinearLayout>

<include layout="@layout/list_item_divider" />

<LinearLayout
android:id="@+id/legend_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

</LinearLayout>

<include
android:id="@+id/bottom_divider"
layout="@layout/card_bottom_divider" />
Expand Down
45 changes: 45 additions & 0 deletions OsmAnd/res/layout/route_legend_card.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/route_legend_card"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<LinearLayout
android:id="@+id/properties_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/list_background_color"
android:orientation="vertical">

<net.osmand.plus.widgets.TextViewEx
android:id="@+id/card_title"
style="@style/TitleStyle.Medium"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="@dimen/content_padding"
android:layout_marginVertical="@dimen/content_padding_small"
android:textColor="?android:textColorPrimary"
tools:text="Legend" />

<LinearLayout
android:id="@+id/classification_properties"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

</LinearLayout>

</LinearLayout>

<LinearLayout
android:id="@+id/main_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/list_background_color"
android:orientation="vertical">

</LinearLayout>

</LinearLayout>
78 changes: 78 additions & 0 deletions OsmAnd/res/layout/route_legend_item.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:descendantFocusability="blocksDescendants"
android:gravity="center"
android:orientation="horizontal">

<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/icon"
android:layout_width="@dimen/standard_icon_size"
android:layout_height="@dimen/standard_icon_size"
android:layout_marginStart="@dimen/content_padding"
android:layout_marginEnd="@dimen/favorites_icon_right_margin"
android:src="@drawable/ic_action_route_direction_here" />

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="@dimen/setting_profile_item_height"
android:orientation="horizontal">

<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">

<TextView
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="2"
android:textColor="?android:textColorPrimary"
android:textSize="@dimen/default_list_text_size"
tools:text="Title" />

<TextView
android:id="@+id/description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="1"
android:textColor="?android:textColorSecondary"
android:textSize="@dimen/default_desc_text_size"
tools:text="Description" />

</LinearLayout>

<androidx.appcompat.widget.SwitchCompat
android:id="@+id/compound_button"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center_vertical|end"
android:background="@null"
android:focusableInTouchMode="true"
android:padding="@dimen/content_padding" />

</LinearLayout>

<View
android:id="@+id/divider_bottom"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="?attr/list_divider" />

</LinearLayout>

</LinearLayout>
20 changes: 19 additions & 1 deletion OsmAnd/src/net/osmand/plus/configmap/MtbRoutesFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.base.BaseOsmAndFragment;
import net.osmand.plus.configmap.RouteLegendCard.DataClass;
import net.osmand.plus.configmap.routes.MtbClassification;
import net.osmand.plus.configmap.routes.RouteLayersHelper;
import net.osmand.plus.helpers.AndroidUiHelper;
Expand All @@ -25,6 +26,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.stream.IntStream;

public class MtbRoutesFragment extends BaseOsmAndFragment {

Expand Down Expand Up @@ -55,6 +57,7 @@ public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
setupClassifications(view);
updateClassificationPreferences();

setupLegendCard(view);
return view;
}

Expand Down Expand Up @@ -85,6 +88,22 @@ private void setupClassifications(@NonNull View view) {
}
}

@NonNull
private List<DataClass> getDataClasses() {
return IntStream.rangeClosed(1, 9)
.mapToObj(i -> new DataClass("Legend item " + i, "Description"))
.toList();
}

private void setupLegendCard(@NonNull View view) {
List<DataClass> items = getDataClasses();

RouteLegendCard card = new RouteLegendCard(requireActivity(), items, app.getString(R.string.shared_string_legend));
ViewGroup group = view.findViewById(R.id.legend_container);
View cardView = card.build();
group.addView(cardView);
}

private View createRadioButton(@NonNull MtbClassification classification, @NonNull LayoutInflater inflater, @Nullable ViewGroup container, boolean hasDivider) {
View view = inflater.inflate(R.layout.item_with_radiobutton_and_descr, container, false);
view.setTag(classification);
Expand Down Expand Up @@ -142,5 +161,4 @@ public static void showInstance(@NonNull FragmentManager manager) {
.commitAllowingStateLoss();
}
}

}
99 changes: 99 additions & 0 deletions OsmAnd/src/net/osmand/plus/configmap/RouteLegendCard.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
package net.osmand.plus.configmap;

import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CompoundButton;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.fragment.app.FragmentActivity;

import net.osmand.plus.R;
import net.osmand.plus.helpers.AndroidUiHelper;
import net.osmand.plus.routepreparationmenu.cards.BaseCard;
import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.utils.AndroidUtils;
import net.osmand.plus.utils.UiUtilities;

import java.util.List;

public class RouteLegendCard extends BaseCard {
private final LayoutInflater themedInflater;

private final List<DataClass> items;
private final String cardTitle;

public RouteLegendCard(@NonNull FragmentActivity activity, @NonNull List<DataClass> items, @NonNull String cardTitle) {
super(activity, true);
this.items = items;
this.cardTitle = cardTitle;
themedInflater = UiUtilities.getInflater(activity, nightMode);
}

@Override
public int getCardLayoutId() {
return R.layout.route_legend_card;
}

@Override
protected void updateContent() {
setupCardTitle();
setupLegendItems();
}

private void setupLegendItems() {
ViewGroup mainContainer = view.findViewById(R.id.main_container);
mainContainer.removeAllViews();
for (int i = 0; i < items.size(); i++) {
mainContainer.addView(createView(i));
}
}

@NonNull
private View createView(int position) {
DataClass dataClass = items.get(position);
View itemView = themedInflater.inflate(R.layout.route_legend_item, null, false);
CompoundButton compoundButton = itemView.findViewById(R.id.compound_button);
TextView title = itemView.findViewById(R.id.title);
TextView description = itemView.findViewById(R.id.description);
View divider = itemView.findViewById(R.id.divider_bottom);

title.setText(dataClass.title());
description.setText(dataClass.description());

compoundButton.setChecked(isClassEnabled(dataClass));

AndroidUiHelper.updateVisibility(divider, position != items.size() - 1);
itemView.setOnClickListener(view -> {
compoundButton.performClick();
onClassSelected(dataClass, compoundButton.isChecked());
});

compoundButton.setFocusable(false);
compoundButton.setClickable(false);

OsmandSettings settings = app.getSettings();
Drawable background = UiUtilities.getColoredSelectableDrawable(app, settings.getApplicationMode().getProfileColor(nightMode), 0.3f);
AndroidUtils.setBackground(itemView, background);

return itemView;
}

private void setupCardTitle() {
TextView title = view.findViewById(R.id.card_title);
title.setText(cardTitle);
}

public boolean isClassEnabled(@NonNull DataClass dataClass) {
return false;
}

public void onClassSelected(@NonNull DataClass dataClass, boolean checked) {

}

public record DataClass(String title, String description) {
}
}
Loading