use cards instead of fragment
This commit is contained in:
parent
a6d117f5a1
commit
f5cacff2cd
4 changed files with 81 additions and 140 deletions
|
@ -144,7 +144,7 @@
|
|||
android:layout_height="@dimen/content_padding_small" />
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/fragmentContainer"
|
||||
android:id="@+id/cards_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
|
|
|
@ -26,7 +26,6 @@ import androidx.core.content.ContextCompat;
|
|||
import androidx.core.widget.TextViewCompat;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import androidx.fragment.app.FragmentTransaction;
|
||||
import androidx.recyclerview.widget.ItemTouchHelper;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
|
@ -72,6 +71,7 @@ import net.osmand.plus.measurementtool.command.MovePointCommand;
|
|||
import net.osmand.plus.measurementtool.command.RemovePointCommand;
|
||||
import net.osmand.plus.measurementtool.command.ReorderPointCommand;
|
||||
import net.osmand.plus.measurementtool.command.ReversePointsCommand;
|
||||
import net.osmand.plus.routepreparationmenu.cards.BaseCard;
|
||||
import net.osmand.plus.settings.backend.ApplicationMode;
|
||||
import net.osmand.plus.settings.backend.OsmandSettings;
|
||||
import net.osmand.plus.views.layers.MapControlsLayer;
|
||||
|
@ -116,6 +116,8 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
|
|||
private TextView distanceToCenterTv;
|
||||
private String pointsSt;
|
||||
private View additionalInfoContainer;
|
||||
private ViewGroup additionalInfoCardsContainer;
|
||||
private BaseCard visibleAdditionalInfoCard;
|
||||
private LinearLayout customRadioButton;
|
||||
private View mainView;
|
||||
private ImageView upDownBtn;
|
||||
|
@ -157,18 +159,8 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
|
|||
}
|
||||
|
||||
private enum AdditionalInfoType {
|
||||
POINTS(MtPointsFragment.class.getName()),
|
||||
GRAPH(MtGraphFragment.class.getName());
|
||||
|
||||
AdditionalInfoType(String fragmentName) {
|
||||
this.fragmentName = fragmentName;
|
||||
}
|
||||
|
||||
final String fragmentName;
|
||||
|
||||
public String getFragmentName() {
|
||||
return fragmentName;
|
||||
}
|
||||
POINTS,
|
||||
GRAPH
|
||||
}
|
||||
|
||||
private void setEditingCtx(MeasurementEditingContext editingCtx) {
|
||||
|
@ -264,6 +256,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
|
|||
mainView = view.findViewById(R.id.main_view);
|
||||
AndroidUtils.setBackground(mapActivity, mainView, nightMode, R.drawable.bg_bottom_menu_light, R.drawable.bg_bottom_menu_dark);
|
||||
additionalInfoContainer = mainView.findViewById(R.id.additional_info_container);
|
||||
additionalInfoCardsContainer = mainView.findViewById(R.id.cards_container);
|
||||
if (portrait) {
|
||||
customRadioButton = mainView.findViewById(R.id.custom_radio_buttons);
|
||||
|
||||
|
@ -521,7 +514,6 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
|
|||
private void changeAdditionalInfoType(@NonNull AdditionalInfoType type) {
|
||||
if (!additionalInfoExpanded || !isCurrentAdditionalInfoType(type)) {
|
||||
currentAdditionalInfoType = type;
|
||||
additionalInfoExpanded = true;
|
||||
updateUpDownBtn();
|
||||
OsmandApplication app = getMyApplication();
|
||||
if (AdditionalInfoType.POINTS.equals(type)) {
|
||||
|
@ -531,14 +523,13 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
|
|||
} else {
|
||||
return;
|
||||
}
|
||||
setAdditionalInfoFragment(type.getFragmentName());
|
||||
setAdditionalInfoCard(type);
|
||||
}
|
||||
}
|
||||
|
||||
private void updateAdditionalInfoView() {
|
||||
Fragment fragment = getActiveAdditionalInfoFragment();
|
||||
if (fragment instanceof OnUpdateAdditionalInfoListener) {
|
||||
((OnUpdateAdditionalInfoListener) fragment).onUpdateAdditionalInfo();
|
||||
if (visibleAdditionalInfoCard instanceof OnUpdateAdditionalInfoListener) {
|
||||
((OnUpdateAdditionalInfoListener) visibleAdditionalInfoCard).onUpdateAdditionalInfo();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1472,29 +1463,28 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
|
|||
if (portrait) {
|
||||
additionalInfoExpanded = false;
|
||||
updateUpDownBtn();
|
||||
MapActivity mapActivity = getMapActivity();
|
||||
if (mapActivity != null) {
|
||||
Fragment activeFragment = getActiveAdditionalInfoFragment();
|
||||
if (activeFragment != null) {
|
||||
FragmentManager manager = getChildFragmentManager();
|
||||
manager.beginTransaction().remove(activeFragment).commitAllowingStateLoss();
|
||||
}
|
||||
additionalInfoContainer.setVisibility(View.GONE);
|
||||
setDefaultMapPosition();
|
||||
}
|
||||
additionalInfoContainer.setVisibility(View.GONE);
|
||||
setDefaultMapPosition();
|
||||
}
|
||||
}
|
||||
|
||||
private void setAdditionalInfoFragment(String fragmentName) {
|
||||
Context ctx = getContext();
|
||||
if (ctx == null) return;
|
||||
private void setAdditionalInfoCard(AdditionalInfoType type) {
|
||||
MapActivity ma = getMapActivity();
|
||||
if (ma == null) return;
|
||||
|
||||
Fragment fragment = Fragment.instantiate(ctx, fragmentName);
|
||||
FragmentManager fm = getChildFragmentManager();
|
||||
FragmentTransaction fragmentTransaction = fm.beginTransaction();
|
||||
fragmentTransaction.replace(R.id.fragmentContainer, fragment, fragmentName);
|
||||
fragmentTransaction.commit();
|
||||
fm.executePendingTransactions();
|
||||
BaseCard additionalInfoCard = null;
|
||||
if (type.equals(AdditionalInfoType.POINTS)) {
|
||||
additionalInfoCard = new MtPointsFragment(ma, this);
|
||||
} else if (type.equals(AdditionalInfoType.GRAPH)) {
|
||||
additionalInfoCard = new MtGraphFragment(ma, this);
|
||||
}
|
||||
|
||||
if (additionalInfoCard != null) {
|
||||
visibleAdditionalInfoCard = additionalInfoCard;
|
||||
additionalInfoCardsContainer.removeAllViews();
|
||||
additionalInfoCardsContainer.addView(additionalInfoCard.build(ma));
|
||||
additionalInfoExpanded = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void collapseAdditionalInfoIfNoPointsEnough() {
|
||||
|
@ -1512,24 +1502,6 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
|
|||
}
|
||||
}
|
||||
|
||||
private Fragment getActiveAdditionalInfoFragment() {
|
||||
MapActivity mapActivity = getMapActivity();
|
||||
if (mapActivity != null) {
|
||||
for (AdditionalInfoType type : AdditionalInfoType.values()) {
|
||||
try {
|
||||
FragmentManager fm = getChildFragmentManager();
|
||||
Fragment fragment = fm.findFragmentByTag(type.getFragmentName());
|
||||
if (fragment != null) {
|
||||
return fragment;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void setDefaultMapPosition() {
|
||||
setMapPosition(OsmandSettings.CENTER_CONSTANT);
|
||||
}
|
||||
|
|
|
@ -1,15 +1,10 @@
|
|||
package net.osmand.plus.measurementtool;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
|
@ -21,12 +16,12 @@ import com.github.mikephil.charting.interfaces.datasets.ILineDataSet;
|
|||
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.UiUtilities;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.activities.SettingsBaseActivity;
|
||||
import net.osmand.plus.helpers.GpxUiHelper;
|
||||
import net.osmand.plus.mapcontextmenu.other.HorizontalSelectionAdapter;
|
||||
import net.osmand.plus.render.MapRenderRepositories;
|
||||
import net.osmand.plus.routepreparationmenu.cards.BaseCard;
|
||||
import net.osmand.render.RenderingRuleSearchRequest;
|
||||
import net.osmand.render.RenderingRulesStorage;
|
||||
import net.osmand.router.RouteSegmentResult;
|
||||
|
@ -43,7 +38,7 @@ import java.util.Collections;
|
|||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
public class MtGraphFragment extends Fragment
|
||||
public class MtGraphFragment extends BaseCard
|
||||
implements MeasurementToolFragment.OnUpdateAdditionalInfoListener {
|
||||
|
||||
private static String GRAPH_DATA_GPX_FILE_NAME = "graph_data_tmp";
|
||||
|
@ -55,10 +50,15 @@ public class MtGraphFragment extends Fragment
|
|||
private HorizontalBarChart customGraphChart;
|
||||
private RecyclerView rvGraphTypesMenu;
|
||||
|
||||
private boolean nightMode;
|
||||
private MeasurementEditingContext editingCtx;
|
||||
private GraphType currentGraphType;
|
||||
private List<GraphType> graphTypes = new ArrayList<>();
|
||||
private MeasurementToolFragment mtf;
|
||||
|
||||
public MtGraphFragment(@NonNull MapActivity mapActivity, MeasurementToolFragment mtf) {
|
||||
super(mapActivity);
|
||||
this.mtf = mtf;
|
||||
}
|
||||
|
||||
private enum CommonGraphType {
|
||||
OVERVIEW(R.string.shared_string_overview, false),
|
||||
|
@ -75,39 +75,6 @@ public class MtGraphFragment extends Fragment
|
|||
final boolean canBeCalculated;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater,
|
||||
@Nullable ViewGroup container,
|
||||
@Nullable Bundle savedInstanceState) {
|
||||
|
||||
final MapActivity mapActivity = (MapActivity) getActivity();
|
||||
final MeasurementToolFragment mtf = (MeasurementToolFragment) getParentFragment();
|
||||
if (mapActivity == null || mtf == null) return null;
|
||||
|
||||
editingCtx = mtf.getEditingCtx();
|
||||
OsmandApplication app = mapActivity.getMyApplication();
|
||||
|
||||
nightMode = app.getDaynightHelper().isNightModeForMapControls();
|
||||
View view = UiUtilities.getInflater(app, nightMode).inflate(
|
||||
R.layout.fragment_measurement_tool_graph, container, false);
|
||||
commonGraphContainer = view.findViewById(R.id.common_graphs_container);
|
||||
customGraphContainer = view.findViewById(R.id.custom_graphs_container);
|
||||
messageContainer = view.findViewById(R.id.message_container);
|
||||
commonGraphChart = (LineChart) view.findViewById(R.id.line_chart);
|
||||
customGraphChart = (HorizontalBarChart) view.findViewById(R.id.horizontal_chart);
|
||||
updateGraphData();
|
||||
|
||||
rvGraphTypesMenu = view.findViewById(R.id.graph_types_recycler_view);
|
||||
rvGraphTypesMenu.setLayoutManager(
|
||||
new LinearLayoutManager(mapActivity, RecyclerView.HORIZONTAL, false));
|
||||
|
||||
refreshGraphTypesSelectionMenu();
|
||||
setupVisibleGraphType(graphTypes.get(0));
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
private void refreshGraphTypesSelectionMenu() {
|
||||
rvGraphTypesMenu.removeAllViews();
|
||||
OsmandApplication app = getMyApplication();
|
||||
|
@ -149,7 +116,8 @@ public class MtGraphFragment extends Fragment
|
|||
}
|
||||
|
||||
private void setupVisibleGraphType(GraphType preferredType) {
|
||||
currentGraphType = preferredType.hasData() ? preferredType : getFirstAvailableGraphType();
|
||||
currentGraphType = currentGraphType != null && preferredType.hasData()
|
||||
? preferredType : getFirstAvailableGraphType();
|
||||
updateDataView();
|
||||
}
|
||||
|
||||
|
@ -192,7 +160,7 @@ public class MtGraphFragment extends Fragment
|
|||
messageContainer.setVisibility(View.VISIBLE);
|
||||
TextView tvMessage = messageContainer.findViewById(R.id.message_text);
|
||||
ImageView icon = messageContainer.findViewById(R.id.message_icon);
|
||||
String message = getString(R.string.message_need_calculate_route_before_show_graph, currentGraphType.getTitle());
|
||||
String message = app.getString(R.string.message_need_calculate_route_before_show_graph, currentGraphType.getTitle());
|
||||
tvMessage.setText(message);
|
||||
icon.setImageResource(R.drawable.ic_action_altitude_average);
|
||||
}
|
||||
|
@ -224,7 +192,7 @@ public class MtGraphFragment extends Fragment
|
|||
if (!Algorithms.isEmpty(dataSets)) {
|
||||
data = new LineData(dataSets);
|
||||
}
|
||||
String title = getString(commonType.titleId);
|
||||
String title = app.getString(commonType.titleId);
|
||||
graphTypes.add(new GraphType(title, false, commonType.canBeCalculated, data));
|
||||
}
|
||||
|
||||
|
@ -328,12 +296,31 @@ public class MtGraphFragment extends Fragment
|
|||
defaultRender, currentSearchRequest, defaultSearchRequest);
|
||||
}
|
||||
|
||||
private OsmandApplication getMyApplication() {
|
||||
return getMapActivity().getMyApplication();
|
||||
@Override
|
||||
public int getCardLayoutId() {
|
||||
return R.layout.fragment_measurement_tool_graph;
|
||||
}
|
||||
|
||||
private MapActivity getMapActivity() {
|
||||
return (MapActivity) getActivity();
|
||||
@Override
|
||||
protected void updateContent() {
|
||||
if (mapActivity == null || mtf == null) return;
|
||||
|
||||
editingCtx = mtf.getEditingCtx();
|
||||
OsmandApplication app = mapActivity.getMyApplication();
|
||||
|
||||
commonGraphContainer = view.findViewById(R.id.common_graphs_container);
|
||||
customGraphContainer = view.findViewById(R.id.custom_graphs_container);
|
||||
messageContainer = view.findViewById(R.id.message_container);
|
||||
commonGraphChart = (LineChart) view.findViewById(R.id.line_chart);
|
||||
customGraphChart = (HorizontalBarChart) view.findViewById(R.id.horizontal_chart);
|
||||
updateGraphData();
|
||||
|
||||
rvGraphTypesMenu = view.findViewById(R.id.graph_types_recycler_view);
|
||||
rvGraphTypesMenu.setLayoutManager(
|
||||
new LinearLayoutManager(mapActivity, RecyclerView.HORIZONTAL, false));
|
||||
|
||||
refreshGraphTypesSelectionMenu();
|
||||
setupVisibleGraphType(currentGraphType);
|
||||
}
|
||||
|
||||
private static class GraphType {
|
||||
|
|
|
@ -1,46 +1,41 @@
|
|||
package net.osmand.plus.measurementtool;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.recyclerview.widget.ItemTouchHelper;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.UiUtilities;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.measurementtool.adapter.MeasurementToolAdapter;
|
||||
import net.osmand.plus.routepreparationmenu.cards.BaseCard;
|
||||
import net.osmand.plus.views.controls.ReorderItemTouchHelperCallback;
|
||||
|
||||
public class MtPointsFragment extends Fragment
|
||||
public class MtPointsFragment extends BaseCard
|
||||
implements MeasurementToolFragment.OnUpdateAdditionalInfoListener {
|
||||
|
||||
private boolean nightMode;
|
||||
private MeasurementToolAdapter adapter;
|
||||
private MeasurementEditingContext editingCtx;
|
||||
private RecyclerView pointsRv;
|
||||
private MeasurementToolFragment mtf;
|
||||
|
||||
public MtPointsFragment(@NonNull MapActivity mapActivity, MeasurementToolFragment mtf) {
|
||||
super(mapActivity);
|
||||
this.mtf = mtf;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater,
|
||||
@Nullable ViewGroup container,
|
||||
@Nullable Bundle savedInstanceState) {
|
||||
public void onUpdateAdditionalInfo() {
|
||||
adapter.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
final MapActivity mapActivity = (MapActivity) getActivity();
|
||||
final MeasurementToolFragment mtf = (MeasurementToolFragment) getParentFragment();
|
||||
if (mapActivity == null || mtf == null) {
|
||||
return null;
|
||||
}
|
||||
nightMode = mapActivity.getMyApplication().getDaynightHelper().isNightModeForMapControls();
|
||||
View view = UiUtilities.getInflater(getContext(), nightMode)
|
||||
.inflate(R.layout.fragment_measurement_tool_points_list, container, false);
|
||||
@Override
|
||||
public int getCardLayoutId() {
|
||||
return R.layout.fragment_measurement_tool_points_list;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void updateContent() {
|
||||
editingCtx = mtf.getEditingCtx();
|
||||
final GpxData gpxData = editingCtx.getGpxData();
|
||||
adapter = new MeasurementToolAdapter(mapActivity, editingCtx.getPoints(),
|
||||
|
@ -49,20 +44,7 @@ public class MtPointsFragment extends Fragment
|
|||
ItemTouchHelper touchHelper = new ItemTouchHelper(new ReorderItemTouchHelperCallback(adapter));
|
||||
touchHelper.attachToRecyclerView(pointsRv);
|
||||
adapter.setAdapterListener(mtf.createMeasurementAdapterListener(touchHelper));
|
||||
pointsRv.setLayoutManager(new LinearLayoutManager(getContext()));
|
||||
pointsRv.setLayoutManager(new LinearLayoutManager(app));
|
||||
pointsRv.setAdapter(adapter);
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
super.onDestroyView();
|
||||
adapter.setAdapterListener(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpdateAdditionalInfo() {
|
||||
adapter.notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue