Updated recents views
This commit is contained in:
parent
2fb513c558
commit
34611f7a57
4 changed files with 105 additions and 44 deletions
|
@ -107,6 +107,9 @@ public class PointDescription {
|
|||
return POINT_TYPE_FAVORITE.equals(type);
|
||||
}
|
||||
|
||||
public boolean isAvNote() {
|
||||
return POINT_TYPE_NOTE.equals(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
package net.osmand.plus.activities;
|
||||
|
||||
|
@ -11,6 +11,7 @@ import android.graphics.drawable.Drawable;
|
|||
import android.support.v4.app.ListFragment;
|
||||
import android.support.v7.widget.PopupMenu;
|
||||
import android.view.*;
|
||||
|
||||
import net.osmand.data.FavouritePoint;
|
||||
import net.osmand.data.LatLon;
|
||||
import net.osmand.plus.OsmAndFormatter;
|
||||
|
@ -22,6 +23,7 @@ import net.osmand.plus.activities.search.SearchActivity.SearchActivityChild;
|
|||
import net.osmand.plus.base.FavoriteImageDrawable;
|
||||
import net.osmand.plus.dialogs.DirectionsDialogs;
|
||||
import net.osmand.util.MapUtils;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.widget.ArrayAdapter;
|
||||
|
@ -31,20 +33,20 @@ import android.widget.ListView;
|
|||
import android.widget.TextView;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class FavoritesListFragment extends ListFragment implements SearchActivityChild {
|
||||
|
||||
public static final String SELECT_FAVORITE_POINT_INTENT_KEY = "SELECT_FAVORITE_POINT_INTENT_KEY";
|
||||
public static final String SELECT_FAVORITE_POINT_INTENT_KEY = "SELECT_FAVORITE_POINT_INTENT_KEY";
|
||||
public static final int SELECT_FAVORITE_POINT_RESULT_OK = 1;
|
||||
|
||||
|
||||
private FavouritesAdapter favouritesAdapter;
|
||||
|
||||
private boolean selectFavoriteMode;
|
||||
private OsmandSettings settings;
|
||||
private LatLon location;
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void onAttach(Activity activity) {
|
||||
super.onAttach(activity);
|
||||
|
@ -58,7 +60,7 @@ public class FavoritesListFragment extends ListFragment implements SearchActivit
|
|||
private OsmandApplication getApplication() {
|
||||
return (OsmandApplication) getActivity().getApplication();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
|
@ -73,14 +75,14 @@ public class FavoritesListFragment extends ListFragment implements SearchActivit
|
|||
}
|
||||
}
|
||||
}
|
||||
if (!isSelectFavoriteMode()) {
|
||||
if (location == null && getActivity() instanceof SearchActivity) {
|
||||
location = ((SearchActivity) getActivity()).getSearchPoint();
|
||||
}
|
||||
if (location == null) {
|
||||
location = settings.getLastKnownMapLocation();
|
||||
}
|
||||
|
||||
if (location == null && getActivity() instanceof SearchActivity) {
|
||||
location = ((SearchActivity) getActivity()).getSearchPoint();
|
||||
}
|
||||
if (location == null) {
|
||||
location = settings.getLastKnownMapLocation();
|
||||
}
|
||||
|
||||
locationUpdate(location);
|
||||
|
||||
}
|
||||
|
@ -92,22 +94,22 @@ public class FavoritesListFragment extends ListFragment implements SearchActivit
|
|||
favouritesAdapter.updateLocation(l);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isSelectFavoriteMode(){
|
||||
|
||||
public boolean isSelectFavoriteMode() {
|
||||
return selectFavoriteMode;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(Menu onCreate, MenuInflater inflater) {
|
||||
if(getActivity() instanceof SearchActivity) {
|
||||
if (getActivity() instanceof SearchActivity) {
|
||||
((SearchActivity) getActivity()).getClearToolbar(false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onListItemClick(ListView l, View v, int position, long id) {
|
||||
|
||||
|
||||
if (!isSelectFavoriteMode()) {
|
||||
FavouritePoint point = favouritesAdapter.getItem(position);
|
||||
LatLon location = new LatLon(point.getLatitude(), point.getLongitude());
|
||||
|
@ -128,11 +130,11 @@ public class FavoritesListFragment extends ListFragment implements SearchActivit
|
|||
private LatLon location;
|
||||
private OsmandApplication app;
|
||||
Drawable arrowImage;
|
||||
|
||||
|
||||
public LatLon getLocation() {
|
||||
return location;
|
||||
}
|
||||
|
||||
|
||||
public void updateLocation(LatLon l) {
|
||||
location = l;
|
||||
sort(new Comparator<FavouritePoint>() {
|
||||
|
@ -151,7 +153,7 @@ public class FavoritesListFragment extends ListFragment implements SearchActivit
|
|||
return getName(object1).compareTo(getName(object2));
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
public FavouritesAdapter(Activity activity, List<FavouritePoint> list) {
|
||||
|
@ -167,11 +169,11 @@ public class FavoritesListFragment extends ListFragment implements SearchActivit
|
|||
arrowImage.setColorFilter(activity.getResources().getColor(R.color.color_distance), PorterDuff.Mode.MULTIPLY);
|
||||
}
|
||||
}
|
||||
|
||||
public String getName(FavouritePoint model){
|
||||
|
||||
public String getName(FavouritePoint model) {
|
||||
return model.getName();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
View row = convertView;
|
||||
|
@ -186,23 +188,23 @@ public class FavoritesListFragment extends ListFragment implements SearchActivit
|
|||
ImageView direction = (ImageView) row.findViewById(R.id.direction);
|
||||
direction.setImageDrawable(arrowImage);
|
||||
direction.setVisibility(View.VISIBLE);
|
||||
final FavouritePoint model = getItem(position);
|
||||
if (!model.getCategory().isEmpty()){
|
||||
final FavouritePoint favorite = getItem(position);
|
||||
if (!favorite.getCategory().isEmpty()) {
|
||||
row.findViewById(R.id.group_image).setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
row.findViewById(R.id.group_image).setVisibility(View.GONE);
|
||||
}
|
||||
((TextView) row.findViewById(R.id.group_name)).setText(model.getCategory());
|
||||
((TextView) row.findViewById(R.id.group_name)).setText(favorite.getCategory());
|
||||
|
||||
icon.setImageDrawable(FavoriteImageDrawable.getOrCreate(activity, model.getColor()));
|
||||
icon.setImageDrawable(FavoriteImageDrawable.getOrCreate(activity, favorite.getColor()));
|
||||
String distance = "";
|
||||
if (location != null) {
|
||||
int dist = (int) (MapUtils.getDistance(model.getLatitude(), model.getLongitude(), location.getLatitude(), location
|
||||
int dist = (int) (MapUtils.getDistance(favorite.getLatitude(), favorite.getLongitude(), location.getLatitude(), location
|
||||
.getLongitude()));
|
||||
distance = OsmAndFormatter.getFormattedDistance(dist, app) + " " ;
|
||||
distance = OsmAndFormatter.getFormattedDistance(dist, app) + " ";
|
||||
}
|
||||
distanceText.setText(distance);
|
||||
name.setText(getName(model));
|
||||
name.setText(getName(favorite));
|
||||
final CheckBox ch = (CheckBox) row.findViewById(R.id.check_item);
|
||||
row.findViewById(R.id.favourite_icon).setVisibility(View.VISIBLE);
|
||||
ch.setVisibility(View.GONE);
|
||||
|
@ -212,6 +214,6 @@ public class FavoritesListFragment extends ListFragment implements SearchActivit
|
|||
}
|
||||
|
||||
public OsmandApplication getMyApplication() {
|
||||
return (OsmandApplication)getActivity().getApplication();
|
||||
return (OsmandApplication) getActivity().getApplication();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,6 +43,12 @@ public class SearchHistoryFragment extends ListFragment implements SearchActivit
|
|||
public static final String SEARCH_LAT = SearchActivity.SEARCH_LAT;
|
||||
public static final String SEARCH_LON = SearchActivity.SEARCH_LON;
|
||||
private HistoryAdapter historyAdapter;
|
||||
private Drawable addressIcon;
|
||||
private Drawable favoriteIcon;
|
||||
private Drawable locationIcon;
|
||||
private Drawable poiIcon;
|
||||
private Drawable wptIcon;
|
||||
private Drawable noteIcon;
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
|
@ -57,15 +63,39 @@ public class SearchHistoryFragment extends ListFragment implements SearchActivit
|
|||
clearButton.setVisibility(View.GONE);
|
||||
}
|
||||
});
|
||||
loadIcons();
|
||||
return view;
|
||||
}
|
||||
|
||||
private void loadIcons() {
|
||||
addressIcon = getResources().getDrawable(R.drawable.ic_type_coordinates);
|
||||
favoriteIcon = getResources().getDrawable(R.drawable.ic_action_fav_dark);
|
||||
locationIcon = getResources().getDrawable(R.drawable.ic_action_marker_dark);
|
||||
poiIcon = getResources().getDrawable(R.drawable.ic_action_gabout_dark);
|
||||
wptIcon = getResources().getDrawable(R.drawable.ic_action_flage_dark);
|
||||
noteIcon = getResources().getDrawable(R.drawable.ic_action_note_dark);
|
||||
if (getMyApplication().getSettings().isLightContent()) {
|
||||
addressIcon = addressIcon.mutate();
|
||||
addressIcon.setColorFilter(getResources().getColor(R.color.icon_color_light), PorterDuff.Mode.MULTIPLY);
|
||||
favoriteIcon = favoriteIcon.mutate();
|
||||
favoriteIcon.setColorFilter(getResources().getColor(R.color.icon_color_light), PorterDuff.Mode.MULTIPLY);
|
||||
locationIcon = locationIcon.mutate();
|
||||
locationIcon.setColorFilter(getResources().getColor(R.color.icon_color_light), PorterDuff.Mode.MULTIPLY);
|
||||
poiIcon = poiIcon.mutate();
|
||||
poiIcon.setColorFilter(getResources().getColor(R.color.icon_color_light), PorterDuff.Mode.MULTIPLY);
|
||||
wptIcon = wptIcon.mutate();
|
||||
wptIcon.setColorFilter(getResources().getColor(R.color.icon_color_light), PorterDuff.Mode.MULTIPLY);
|
||||
noteIcon = noteIcon.mutate();
|
||||
noteIcon.setColorFilter(getResources().getColor(R.color.icon_color_light), PorterDuff.Mode.MULTIPLY);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
helper = SearchHistoryHelper.getInstance((OsmandApplication) getActivity().getApplicationContext());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onActivityCreated(Bundle savedInstanceState) {
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
|
@ -73,8 +103,8 @@ public class SearchHistoryFragment extends ListFragment implements SearchActivit
|
|||
setListAdapter(historyAdapter);
|
||||
setHasOptionsMenu(true);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
|
@ -97,18 +127,18 @@ public class SearchHistoryFragment extends ListFragment implements SearchActivit
|
|||
location = ((OsmandApplication) activity.getApplication()).getSettings().getLastKnownMapLocation();
|
||||
}
|
||||
historyAdapter.clear();
|
||||
for(HistoryEntry entry : helper.getHistoryEntries()){
|
||||
for (HistoryEntry entry : helper.getHistoryEntries()) {
|
||||
historyAdapter.add(entry);
|
||||
}
|
||||
locationUpdate(location);
|
||||
clearButton.setVisibility(historyAdapter.isEmpty() ? View.GONE : View.VISIBLE);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void locationUpdate(LatLon l) {
|
||||
//location = l;
|
||||
if(historyAdapter != null) {
|
||||
if (historyAdapter != null) {
|
||||
historyAdapter.updateLocation(l);
|
||||
}
|
||||
}
|
||||
|
@ -175,18 +205,36 @@ public class SearchHistoryFragment extends ListFragment implements SearchActivit
|
|||
ImageView arrow = (ImageView) row.findViewById(R.id.direction);
|
||||
arrow.setImageDrawable(arrowImage);
|
||||
ImageButton options = (ImageButton) row.findViewById(R.id.options);
|
||||
final HistoryEntry model = getItem(position);
|
||||
final HistoryEntry historyEntry = getItem(position);
|
||||
if (location != null) {
|
||||
int dist = (int) (MapUtils.getDistance(location, model.getLat(), model.getLon()));
|
||||
int dist = (int) (MapUtils.getDistance(location, historyEntry.getLat(), historyEntry.getLon()));
|
||||
distance = OsmAndFormatter.getFormattedDistance(dist, (OsmandApplication) getActivity().getApplication()) + " ";
|
||||
}
|
||||
distanceText.setText(distance);
|
||||
nameText.setText(model.getName().getName(), BufferType.SPANNABLE);
|
||||
nameText.setText(historyEntry.getName().getName(), BufferType.SPANNABLE);
|
||||
ImageView icon =((ImageView) row.findViewById(R.id.icon));
|
||||
|
||||
if (historyEntry.getName().isAddress()) {
|
||||
icon.setImageDrawable(addressIcon);
|
||||
} else if (historyEntry.getName().isFavorite()) {
|
||||
icon.setImageDrawable(favoriteIcon);
|
||||
} else if (historyEntry.getName().isLocation()) {
|
||||
icon.setImageDrawable(locationIcon);
|
||||
} else if (historyEntry.getName().isPoi()) {
|
||||
icon.setImageDrawable(poiIcon);
|
||||
} else if (historyEntry.getName().isWpt()) {
|
||||
icon.setImageDrawable(wptIcon);
|
||||
} else if (historyEntry.getName().isAvNote()) {
|
||||
icon.setImageDrawable(noteIcon);
|
||||
} else {
|
||||
icon.setImageDrawable(addressIcon);
|
||||
}
|
||||
|
||||
|
||||
options.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
selectModel(model, v);
|
||||
selectModel(historyEntry, v);
|
||||
}
|
||||
|
||||
});
|
||||
|
@ -197,8 +245,8 @@ public class SearchHistoryFragment extends ListFragment implements SearchActivit
|
|||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(Menu onCreate, MenuInflater inflater) {
|
||||
if(getActivity() instanceof SearchActivity) {
|
||||
((SearchActivity) getActivity()).getClearToolbar(false);
|
||||
if (getActivity() instanceof SearchActivity) {
|
||||
((SearchActivity) getActivity()).getClearToolbar(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -21,7 +21,9 @@ import net.osmand.util.MapUtils;
|
|||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.Typeface;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.view.LayoutInflater;
|
||||
|
@ -42,6 +44,7 @@ public class DashRecentsFragment extends DashLocationFragment {
|
|||
|
||||
private List<ImageView> arrows = new ArrayList<ImageView>();
|
||||
List<HistoryEntry> points = new ArrayList<HistoryEntry>();
|
||||
Drawable icon;
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
|
@ -65,6 +68,11 @@ public class DashRecentsFragment extends DashLocationFragment {
|
|||
activity.startActivity(search);
|
||||
}
|
||||
});
|
||||
icon = getResources().getDrawable(R.drawable.ic_type_coordinates);
|
||||
if (getMyApplication().getSettings().isLightContent()) {
|
||||
icon = icon.mutate();
|
||||
icon.setColorFilter(getResources().getColor(R.color.icon_color_light), PorterDuff.Mode.MULTIPLY);
|
||||
}
|
||||
return view;
|
||||
}
|
||||
|
||||
|
@ -121,7 +129,7 @@ public class DashRecentsFragment extends DashLocationFragment {
|
|||
|
||||
|
||||
((ImageView) view.findViewById(R.id.icon)).
|
||||
setImageDrawable(FavoriteImageDrawable.getOrCreate(getActivity(), Color.BLUE));
|
||||
setImageDrawable(icon);
|
||||
|
||||
if(loc != null){
|
||||
direction.setVisibility(View.VISIBLE);
|
||||
|
|
Loading…
Reference in a new issue