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
|
||||
android:id="@+id/points_list_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="220dp"
|
||||
android:layout_height="180dp"
|
||||
android:background="@color/ctx_menu_info_view_bg_dark"
|
||||
android:visibility="gone">
|
||||
|
||||
<include layout="@layout/card_bottom_divider"/>
|
||||
|
||||
<android.support.v7.widget.RecyclerView
|
||||
android:id="@+id/measure_points_recycler_view"
|
||||
<ListView
|
||||
android:id="@+id/measure_points_list_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"/>
|
||||
|
||||
|
|
|
@ -1,9 +1,13 @@
|
|||
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.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
@ -17,33 +21,39 @@ import net.osmand.util.MapUtils;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
class MeasurementToolAdapter extends RecyclerView.Adapter<MeasurementToolAdapter.Holder> {
|
||||
class MeasurementToolAdapter extends ArrayAdapter<WptPt> {
|
||||
|
||||
private MapActivity mapActivity;
|
||||
private List<WptPt> points;
|
||||
private RemovePointListener listener;
|
||||
|
||||
MeasurementToolAdapter(MapActivity mapActivity, List<WptPt> points) {
|
||||
this.mapActivity = mapActivity;
|
||||
MeasurementToolAdapter(@NonNull Context context, @LayoutRes int resource, List<WptPt> points) {
|
||||
super(context, resource, points);
|
||||
this.mapActivity = (MapActivity) context;
|
||||
this.points = points;
|
||||
}
|
||||
|
||||
public void setListener(RemovePointListener listener) {
|
||||
void setRemovePointListener(RemovePointListener listener) {
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Holder onCreateViewHolder(ViewGroup viewGroup, int i) {
|
||||
View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.measure_points_list_item, viewGroup, false);
|
||||
final boolean nightMode = mapActivity.getMyApplication().getDaynightHelper().isNightModeForMapControls();
|
||||
if (!nightMode) {
|
||||
view.findViewById(R.id.points_divider).setBackgroundResource(R.drawable.divider);
|
||||
}
|
||||
return new Holder(view);
|
||||
}
|
||||
public View getView(final int pos, @Nullable View view, @NonNull ViewGroup parent) {
|
||||
ViewHolder holder;
|
||||
|
||||
if (view == null) {
|
||||
view = LayoutInflater.from(parent.getContext()).inflate(R.layout.measure_points_list_item, parent, false);
|
||||
final boolean nightMode = mapActivity.getMyApplication().getDaynightHelper().isNightModeForMapControls();
|
||||
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();
|
||||
holder.icon.setImageDrawable(iconsCache.getThemedIcon(R.drawable.ic_action_measure_point));
|
||||
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() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
points.remove(holder.getAdapterPosition());
|
||||
points.remove(pos);
|
||||
listener.onPointRemove();
|
||||
}
|
||||
});
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return points.size();
|
||||
}
|
||||
|
||||
static class Holder extends RecyclerView.ViewHolder {
|
||||
private static class ViewHolder {
|
||||
|
||||
final ImageView icon;
|
||||
final TextView title;
|
||||
final TextView descr;
|
||||
final ImageButton deleteBtn;
|
||||
|
||||
Holder(View view) {
|
||||
super(view);
|
||||
ViewHolder(View view) {
|
||||
icon = (ImageView) view.findViewById(R.id.measure_point_icon);
|
||||
title = (TextView) view.findViewById(R.id.measure_point_title);
|
||||
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.content.ContextCompat;
|
||||
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.text.Editable;
|
||||
import android.text.TextWatcher;
|
||||
|
@ -24,6 +22,7 @@ import android.view.ViewGroup;
|
|||
import android.widget.EditText;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
|
@ -197,8 +196,8 @@ public class MeasurementToolFragment extends Fragment {
|
|||
mapActivity.showTopToolbar(toolBarController);
|
||||
}
|
||||
|
||||
adapter = new MeasurementToolAdapter(getMapActivity(), measurementLayer.getMeasurementPoints());
|
||||
adapter.setListener(new MeasurementToolAdapter.RemovePointListener() {
|
||||
adapter = new MeasurementToolAdapter(getMapActivity(), R.layout.measure_points_list_item, measurementLayer.getMeasurementPoints());
|
||||
adapter.setRemovePointListener(new MeasurementToolAdapter.RemovePointListener() {
|
||||
@Override
|
||||
public void onPointRemove() {
|
||||
adapter.notifyDataSetChanged();
|
||||
|
@ -212,9 +211,9 @@ public class MeasurementToolFragment extends Fragment {
|
|||
}
|
||||
}
|
||||
});
|
||||
RecyclerView rv = mainView.findViewById(R.id.measure_points_recycler_view);
|
||||
rv.setLayoutManager(new LinearLayoutManager(getContext()));
|
||||
rv.setAdapter(adapter);
|
||||
ListView lv = mainView.findViewById(R.id.measure_points_list_view);
|
||||
lv.setDivider(null);
|
||||
lv.setAdapter(adapter);
|
||||
|
||||
return view;
|
||||
}
|
||||
|
@ -364,7 +363,7 @@ public class MeasurementToolFragment extends Fragment {
|
|||
public void onDestroyView() {
|
||||
super.onDestroyView();
|
||||
exitMeasurementMode();
|
||||
adapter.setListener(null);
|
||||
adapter.setRemovePointListener(null);
|
||||
}
|
||||
|
||||
private MapActivity getMapActivity() {
|
||||
|
|
Loading…
Reference in a new issue