Replace RecyclerView with ListView
This commit is contained in:
parent
3066ba2ee0
commit
2ef81d2048
3 changed files with 40 additions and 35 deletions
|
@ -84,14 +84,14 @@
|
||||||
<FrameLayout
|
<FrameLayout
|
||||||
android:id="@+id/points_list_container"
|
android:id="@+id/points_list_container"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="220dp"
|
android:layout_height="180dp"
|
||||||
android:background="@color/ctx_menu_info_view_bg_dark"
|
android:background="@color/ctx_menu_info_view_bg_dark"
|
||||||
android:visibility="gone">
|
android:visibility="gone">
|
||||||
|
|
||||||
<include layout="@layout/card_bottom_divider"/>
|
<include layout="@layout/card_bottom_divider"/>
|
||||||
|
|
||||||
<android.support.v7.widget.RecyclerView
|
<ListView
|
||||||
android:id="@+id/measure_points_recycler_view"
|
android:id="@+id/measure_points_list_view"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"/>
|
android:layout_height="match_parent"/>
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,13 @@
|
||||||
package net.osmand.plus.measurementtool;
|
package net.osmand.plus.measurementtool;
|
||||||
|
|
||||||
import android.support.v7.widget.RecyclerView;
|
import android.content.Context;
|
||||||
|
import android.support.annotation.LayoutRes;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.ArrayAdapter;
|
||||||
import android.widget.ImageButton;
|
import android.widget.ImageButton;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
@ -17,33 +21,39 @@ import net.osmand.util.MapUtils;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
class MeasurementToolAdapter extends RecyclerView.Adapter<MeasurementToolAdapter.Holder> {
|
class MeasurementToolAdapter extends ArrayAdapter<WptPt> {
|
||||||
|
|
||||||
private MapActivity mapActivity;
|
private MapActivity mapActivity;
|
||||||
private List<WptPt> points;
|
private List<WptPt> points;
|
||||||
private RemovePointListener listener;
|
private RemovePointListener listener;
|
||||||
|
|
||||||
MeasurementToolAdapter(MapActivity mapActivity, List<WptPt> points) {
|
MeasurementToolAdapter(@NonNull Context context, @LayoutRes int resource, List<WptPt> points) {
|
||||||
this.mapActivity = mapActivity;
|
super(context, resource, points);
|
||||||
|
this.mapActivity = (MapActivity) context;
|
||||||
this.points = points;
|
this.points = points;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setListener(RemovePointListener listener) {
|
void setRemovePointListener(RemovePointListener listener) {
|
||||||
this.listener = listener;
|
this.listener = listener;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public Holder onCreateViewHolder(ViewGroup viewGroup, int i) {
|
public View getView(final int pos, @Nullable View view, @NonNull ViewGroup parent) {
|
||||||
View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.measure_points_list_item, viewGroup, false);
|
ViewHolder holder;
|
||||||
final boolean nightMode = mapActivity.getMyApplication().getDaynightHelper().isNightModeForMapControls();
|
|
||||||
if (!nightMode) {
|
if (view == null) {
|
||||||
view.findViewById(R.id.points_divider).setBackgroundResource(R.drawable.divider);
|
view = LayoutInflater.from(parent.getContext()).inflate(R.layout.measure_points_list_item, parent, false);
|
||||||
}
|
final boolean nightMode = mapActivity.getMyApplication().getDaynightHelper().isNightModeForMapControls();
|
||||||
return new Holder(view);
|
if (!nightMode) {
|
||||||
}
|
view.findViewById(R.id.points_divider).setBackgroundResource(R.drawable.divider);
|
||||||
|
}
|
||||||
|
holder = new ViewHolder(view);
|
||||||
|
view.setTag(holder);
|
||||||
|
} else {
|
||||||
|
holder = (ViewHolder) view.getTag();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onBindViewHolder(final Holder holder, int pos) {
|
|
||||||
IconsCache iconsCache = mapActivity.getMyApplication().getIconsCache();
|
IconsCache iconsCache = mapActivity.getMyApplication().getIconsCache();
|
||||||
holder.icon.setImageDrawable(iconsCache.getThemedIcon(R.drawable.ic_action_measure_point));
|
holder.icon.setImageDrawable(iconsCache.getThemedIcon(R.drawable.ic_action_measure_point));
|
||||||
holder.title.setText(mapActivity.getString(R.string.plugin_distance_point) + " - " + (pos + 1));
|
holder.title.setText(mapActivity.getString(R.string.plugin_distance_point) + " - " + (pos + 1));
|
||||||
|
@ -61,26 +71,22 @@ class MeasurementToolAdapter extends RecyclerView.Adapter<MeasurementToolAdapter
|
||||||
holder.deleteBtn.setOnClickListener(new View.OnClickListener() {
|
holder.deleteBtn.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
points.remove(holder.getAdapterPosition());
|
points.remove(pos);
|
||||||
listener.onPointRemove();
|
listener.onPointRemove();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private static class ViewHolder {
|
||||||
public int getItemCount() {
|
|
||||||
return points.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
static class Holder extends RecyclerView.ViewHolder {
|
|
||||||
|
|
||||||
final ImageView icon;
|
final ImageView icon;
|
||||||
final TextView title;
|
final TextView title;
|
||||||
final TextView descr;
|
final TextView descr;
|
||||||
final ImageButton deleteBtn;
|
final ImageButton deleteBtn;
|
||||||
|
|
||||||
Holder(View view) {
|
ViewHolder(View view) {
|
||||||
super(view);
|
|
||||||
icon = (ImageView) view.findViewById(R.id.measure_point_icon);
|
icon = (ImageView) view.findViewById(R.id.measure_point_icon);
|
||||||
title = (TextView) view.findViewById(R.id.measure_point_title);
|
title = (TextView) view.findViewById(R.id.measure_point_title);
|
||||||
descr = (TextView) view.findViewById(R.id.measure_point_descr);
|
descr = (TextView) view.findViewById(R.id.measure_point_descr);
|
||||||
|
|
|
@ -10,8 +10,6 @@ import android.support.v4.app.Fragment;
|
||||||
import android.support.v4.app.FragmentManager;
|
import android.support.v4.app.FragmentManager;
|
||||||
import android.support.v4.content.ContextCompat;
|
import android.support.v4.content.ContextCompat;
|
||||||
import android.support.v7.app.AlertDialog;
|
import android.support.v7.app.AlertDialog;
|
||||||
import android.support.v7.widget.LinearLayoutManager;
|
|
||||||
import android.support.v7.widget.RecyclerView;
|
|
||||||
import android.support.v7.widget.SwitchCompat;
|
import android.support.v7.widget.SwitchCompat;
|
||||||
import android.text.Editable;
|
import android.text.Editable;
|
||||||
import android.text.TextWatcher;
|
import android.text.TextWatcher;
|
||||||
|
@ -24,6 +22,7 @@ import android.view.ViewGroup;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
import android.widget.ImageButton;
|
import android.widget.ImageButton;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
|
import android.widget.ListView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
@ -197,8 +196,8 @@ public class MeasurementToolFragment extends Fragment {
|
||||||
mapActivity.showTopToolbar(toolBarController);
|
mapActivity.showTopToolbar(toolBarController);
|
||||||
}
|
}
|
||||||
|
|
||||||
adapter = new MeasurementToolAdapter(getMapActivity(), measurementLayer.getMeasurementPoints());
|
adapter = new MeasurementToolAdapter(getMapActivity(), R.layout.measure_points_list_item, measurementLayer.getMeasurementPoints());
|
||||||
adapter.setListener(new MeasurementToolAdapter.RemovePointListener() {
|
adapter.setRemovePointListener(new MeasurementToolAdapter.RemovePointListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onPointRemove() {
|
public void onPointRemove() {
|
||||||
adapter.notifyDataSetChanged();
|
adapter.notifyDataSetChanged();
|
||||||
|
@ -212,9 +211,9 @@ public class MeasurementToolFragment extends Fragment {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
RecyclerView rv = mainView.findViewById(R.id.measure_points_recycler_view);
|
ListView lv = mainView.findViewById(R.id.measure_points_list_view);
|
||||||
rv.setLayoutManager(new LinearLayoutManager(getContext()));
|
lv.setDivider(null);
|
||||||
rv.setAdapter(adapter);
|
lv.setAdapter(adapter);
|
||||||
|
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
@ -364,7 +363,7 @@ public class MeasurementToolFragment extends Fragment {
|
||||||
public void onDestroyView() {
|
public void onDestroyView() {
|
||||||
super.onDestroyView();
|
super.onDestroyView();
|
||||||
exitMeasurementMode();
|
exitMeasurementMode();
|
||||||
adapter.setListener(null);
|
adapter.setRemovePointListener(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private MapActivity getMapActivity() {
|
private MapActivity getMapActivity() {
|
||||||
|
|
Loading…
Reference in a new issue