This commit is contained in:
Nazar-Kutz 2020-05-12 10:15:32 +03:00
parent 4526ae6426
commit 9f4d9e74d2
8 changed files with 72 additions and 11 deletions

View file

@ -38,6 +38,18 @@
android:textColor="?android:textColorPrimary"
tools:text="Today"/>
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/clear_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="@dimen/default_desc_text_size"
android:text="@string/shared_string_clear"
osmand:typeface="@string/font_roboto_medium"
android:layout_marginLeft="@dimen/bottom_sheet_content_margin"
android:layout_marginRight="@dimen/bottom_sheet_content_margin"
android:visibility="gone"
android:textColor="?attr/active_color_basic" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/disable_group_switch"
android:layout_width="wrap_content"

View file

@ -51,6 +51,7 @@ import android.widget.TextView;
import androidx.annotation.AttrRes;
import androidx.annotation.ColorInt;
import androidx.annotation.ColorRes;
import androidx.annotation.DrawableRes;
import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;
import androidx.core.content.FileProvider;
@ -706,6 +707,11 @@ public class AndroidUtils {
return new BitmapDrawable(ctx.getResources(), flipBitmapHorizontally(bitmap));
}
public static Bitmap bitmapFromDrawableRes(@NonNull Context ctx, @DrawableRes int drawableResId) {
Drawable drawable = ContextCompat.getDrawable(ctx, drawableResId);
return drawableToBitmap(drawable);
}
public static Bitmap drawableToBitmap(Drawable drawable) {
if (drawable instanceof BitmapDrawable) {
BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;

View file

@ -322,7 +322,7 @@ public class MapMarkersDbHelper {
marker.creationDate = currentTime;
String descr = PointDescription.serializeToString(marker.getOriginalPointDescription());
int active = marker.history ? 0 : 1;
long visited = saveExisting ? currentTime : 0;
long visited = saveExisting ? currentTime : marker.visitedDate;
PointDescription pointDescription = marker.getOriginalPointDescription();
if (pointDescription != null && !pointDescription.isSearchingAddress(context)) {

View file

@ -1,7 +1,6 @@
package net.osmand.plus.mapmarkers;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.PorterDuff;
@ -24,6 +23,7 @@ import androidx.recyclerview.widget.RecyclerView;
import com.google.android.material.snackbar.Snackbar;
import net.osmand.AndroidUtils;
import net.osmand.GPXUtilities.WptPt;
import net.osmand.Location;
import net.osmand.data.Amenity;
@ -106,8 +106,8 @@ public class MapMarkersGroupsFragment extends Fragment implements OsmAndCompassL
ItemTouchHelper.SimpleCallback simpleItemTouchCallback = new ItemTouchHelper.SimpleCallback(0, ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT) {
private float marginSides = getResources().getDimension(R.dimen.list_content_padding);
private Bitmap deleteBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ic_action_delete_dark);
private Bitmap historyBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ic_action_history);
private Bitmap deleteBitmap = AndroidUtils.bitmapFromDrawableRes(mapActivity, R.drawable.ic_action_delete_dark);
private Bitmap historyBitmap = AndroidUtils.bitmapFromDrawableRes(mapActivity, R.drawable.ic_action_history);
private boolean iconHidden;
@Override

View file

@ -1,7 +1,6 @@
package net.osmand.plus.mapmarkers;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.PorterDuff;
@ -23,6 +22,7 @@ import androidx.recyclerview.widget.RecyclerView;
import com.google.android.material.snackbar.Snackbar;
import net.osmand.AndroidUtils;
import net.osmand.plus.MapMarkersHelper;
import net.osmand.plus.MapMarkersHelper.MapMarker;
import net.osmand.plus.OsmandApplication;
@ -84,8 +84,8 @@ public class MapMarkersHistoryFragment extends Fragment implements MapMarkersHel
ItemTouchHelper.SimpleCallback simpleItemTouchCallback = new ItemTouchHelper.SimpleCallback(0, ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT) {
private float marginSides = getResources().getDimension(R.dimen.list_content_padding);
private Bitmap deleteBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ic_action_delete_dark);
private Bitmap resetBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ic_action_reset_to_default_dark);
private Bitmap deleteBitmap = AndroidUtils.bitmapFromDrawableRes(app, R.drawable.ic_action_delete_dark);
private Bitmap resetBitmap = AndroidUtils.bitmapFromDrawableRes(app, R.drawable.ic_action_reset_to_default_dark);
private boolean iconHidden;
@Override

View file

@ -15,6 +15,7 @@ public class MapMarkerHeaderViewHolder extends RecyclerView.ViewHolder {
final View iconSpace;
final TextView title;
final TextView content;
final TextView clearButton;
final TextView button;
final SwitchCompat disableGroupSwitch;
final View bottomShadow;
@ -28,6 +29,7 @@ public class MapMarkerHeaderViewHolder extends RecyclerView.ViewHolder {
disableGroupSwitch = (SwitchCompat) itemView.findViewById(R.id.disable_group_switch);
bottomShadow = itemView.findViewById(R.id.bottom_shadow);
content = itemView.findViewById(R.id.content);
clearButton = itemView.findViewById(R.id.clear_button);
button = itemView.findViewById(R.id.text_button);
articleDescription = itemView.findViewById(R.id.article_description);
}

View file

@ -19,8 +19,10 @@ import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
public class MapMarkersHistoryAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
@ -34,6 +36,7 @@ public class MapMarkersHistoryAdapter extends RecyclerView.Adapter<RecyclerView.
private OsmandApplication app;
private List<Object> items = new ArrayList<>();
private Map<Integer, List<MapMarker>> markerGroups = new HashMap<>();
private MapMarkersHistoryAdapterListener listener;
private Snackbar snackbar;
private boolean night;
@ -46,6 +49,7 @@ public class MapMarkersHistoryAdapter extends RecyclerView.Adapter<RecyclerView.
public void createHeaders() {
items = new ArrayList<>();
markerGroups = new HashMap<>();
List<MapMarker> markersHistory = app.getMapMarkersHelper().getMapMarkersHistory();
int previousHeader = -1;
int monthsDisplayed = 0;
@ -84,10 +88,22 @@ public class MapMarkersHistoryAdapter extends RecyclerView.Adapter<RecyclerView.
items.add(markerYear);
previousHeader = markerYear;
}
addMarkerToGroup(previousHeader, marker);
items.add(marker);
}
}
private void addMarkerToGroup(Integer groupHeader, MapMarker marker) {
List<MapMarker> group = markerGroups.get(groupHeader);
if (group != null) {
group.add(marker);
} else {
group = new ArrayList<>();
group.add(marker);
markerGroups.put(groupHeader, group);
}
}
public void setAdapterListener(MapMarkersHistoryAdapterListener listener) {
this.listener = listener;
}
@ -112,7 +128,7 @@ public class MapMarkersHistoryAdapter extends RecyclerView.Adapter<RecyclerView.
}
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
public void onBindViewHolder(final RecyclerView.ViewHolder holder, int position) {
UiUtilities iconsCache = app.getUIUtilities();
if (holder instanceof MapMarkerItemViewHolder) {
final MapMarkerItemViewHolder itemViewHolder = (MapMarkerItemViewHolder) holder;
@ -188,7 +204,32 @@ public class MapMarkersHistoryAdapter extends RecyclerView.Adapter<RecyclerView.
}
dateViewHolder.disableGroupSwitch.setVisibility(View.GONE);
dateViewHolder.title.setText(dateString);
dateViewHolder.clearButton.setVisibility(View.VISIBLE);
dateViewHolder.articleDescription.setVisibility(View.GONE);
dateViewHolder.clearButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final List<MapMarker> group = markerGroups.get(dateHeader);
if (group == null) {
return;
}
for (MapMarker marker : group) {
app.getMapMarkersHelper().removeMarker((MapMarker) marker);
}
snackbar = Snackbar.make(holder.itemView, app.getString(R.string.n_items_removed), Snackbar.LENGTH_LONG)
.setAction(R.string.shared_string_undo, new View.OnClickListener() {
@Override
public void onClick(View view) {
for (MapMarker marker : group) {
app.getMapMarkersHelper().addMarker(marker);
}
}
});
UiUtilities.setupSnackbar(snackbar, night);
snackbar.show();
}
});
}
}

View file

@ -1,7 +1,6 @@
package net.osmand.plus.mapmarkers.adapters;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.PorterDuff;
@ -13,6 +12,7 @@ import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.ItemTouchHelper;
import androidx.recyclerview.widget.RecyclerView;
import net.osmand.AndroidUtils;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
@ -47,8 +47,8 @@ public class MapMarkersItemTouchHelperCallback extends ItemTouchHelper.Callback
this.mapActivity = mapActivity;
this.adapter = adapter;
marginSides = mapActivity.getResources().getDimension(R.dimen.list_content_padding);
deleteBitmap = BitmapFactory.decodeResource(mapActivity.getResources(), R.drawable.ic_action_delete_dark);
historyBitmap = BitmapFactory.decodeResource(mapActivity.getResources(), R.drawable.ic_action_history);
deleteBitmap = AndroidUtils.bitmapFromDrawableRes(mapActivity, R.drawable.ic_action_delete_dark);
historyBitmap = AndroidUtils.bitmapFromDrawableRes(mapActivity, R.drawable.ic_action_history);
night = !mapActivity.getMyApplication().getSettings().isLightContent();
backgroundPaint.setColor(ContextCompat.getColor(mapActivity, night ? R.color.divider_color_dark : R.color.divider_color_light));