Fix arrow icon direction, expanded list divider change background.

This commit is contained in:
Dima-1 2020-05-12 15:48:30 +03:00
parent e4685ac04f
commit a2bdce610b
4 changed files with 129 additions and 34 deletions

View file

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<shape android:shape="rectangle">
<solid android:color="?attr/activity_background_color" />
</shape>
</item>
<item android:state_enabled="false">
<shape android:shape="rectangle">
<solid android:color="?attr/activity_background_color" />
</shape>
</item>
<item>
<shape android:shape="rectangle">
<solid android:color="?attr/activity_background_color" />
</shape>
</item>
</selector>

View file

@ -9,7 +9,8 @@
<LinearLayout
android:id="@+id/group_divider"
android:layout_width="match_parent"
android:layout_height="wrap_content">
android:layout_height="wrap_content"
android:background="@drawable/list_divider_background_stateless">
<include layout="@layout/list_item_divider"/>

View file

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:osmand="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
@ -97,15 +98,15 @@
android:contentDescription="@string/show_view_angle"
android:src="@drawable/ic_direction_arrow" />
<TextView
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/distance"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/gpx_small_icon_margin"
android:layout_marginLeft="@dimen/gpx_small_icon_margin"
android:ellipsize="end"
android:maxLines="1"
android:textColor="?android:textColorSecondary"
osmand:typeface="@string/font_roboto_medium"
android:textSize="@dimen/default_desc_text_size"
tools:text="100500 km" />
@ -126,6 +127,8 @@
android:layout_gravity="center_vertical"
android:layout_marginStart="@dimen/gpx_small_icon_margin"
android:layout_marginLeft="@dimen/gpx_small_icon_margin"
android:ellipsize="end"
android:maxLines="1"
android:textColor="?android:textColorSecondary"
android:textSize="@dimen/default_desc_text_size" />
</LinearLayout>

View file

@ -16,6 +16,7 @@ import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.ExpandableListView;
@ -33,6 +34,7 @@ import androidx.core.content.ContextCompat;
import androidx.core.view.MenuItemCompat;
import net.osmand.AndroidUtils;
import net.osmand.Location;
import net.osmand.data.FavouritePoint;
import net.osmand.data.LatLon;
import net.osmand.data.PointDescription;
@ -40,7 +42,7 @@ import net.osmand.plus.FavouritesDbHelper;
import net.osmand.plus.FavouritesDbHelper.FavoriteGroup;
import net.osmand.plus.FavouritesDbHelper.FavoritesListener;
import net.osmand.plus.MapMarkersHelper;
import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmAndLocationProvider;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
@ -71,8 +73,9 @@ import static net.osmand.plus.myplaces.FavoritesActivity.FAV_TAB;
import static net.osmand.plus.myplaces.FavoritesActivity.TAB_ID;
public class FavoritesTreeFragment extends OsmandExpandableListFragment implements
FavoritesFragmentStateHolder {
public class FavoritesTreeFragment extends OsmandExpandableListFragment implements FavoritesFragmentStateHolder,
OsmAndLocationProvider.OsmAndCompassListener, OsmAndLocationProvider.OsmAndLocationListener {
public static final int SEARCH_ID = -1;
// public static final int EXPORT_ID = 0;
// public static final int IMPORT_ID = 1;
@ -84,7 +87,7 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment implemen
public static final int IMPORT_FAVOURITES_ID = 7;
public static final String GROUP_EXPANDED_POSTFIX = "_group_expanded";
private FavouritesAdapter favouritesAdapter = new FavouritesAdapter();
private FavouritesAdapter favouritesAdapter;
private FavouritesDbHelper helper;
private OsmandApplication app;
@ -92,22 +95,26 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment implemen
private LinkedHashMap<String, Set<FavouritePoint>> favoritesSelected = new LinkedHashMap<>();
private Set<FavoriteGroup> groupsToDelete = new LinkedHashSet<>();
private ActionMode actionMode;
Drawable arrowImage;
Drawable arrowImageDisabled;
private Drawable arrowImageDisabled;
private HashMap<String, OsmandSettings.OsmandPreference<Boolean>> preferenceCache = new HashMap<>();
private View footerView;
private Location lastLocation;
private float lastHeading;
private int selectedGroupPos = -1;
private int selectedChildPos = -1;
private FavoritesListener favoritesListener;
String groupNameToShow = null;
private String groupNameToShow = null;
private boolean compassUpdateAllowed = true;
private boolean locationUpdateStarted;
@Override
public void onAttach(Context context) {
super.onAttach(context);
this.app = (OsmandApplication) getActivity().getApplication();
favouritesAdapter = new FavouritesAdapter();
helper = getMyApplication().getFavorites();
if (helper.isFavoritesLoaded()) {
@ -126,18 +133,11 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment implemen
}
setAdapter(favouritesAdapter);
boolean light = getMyApplication().getSettings().isLightContent();
arrowImage = ContextCompat.getDrawable(context, R.drawable.ic_direction_arrow);
arrowImage.mutate();
if (light) {
arrowImage.setColorFilter(ContextCompat.getColor(context, R.color.color_distance), PorterDuff.Mode.MULTIPLY);
} else {
arrowImage.setColorFilter(ContextCompat.getColor(context, R.color.color_distance), PorterDuff.Mode.MULTIPLY);
}
arrowImageDisabled = ContextCompat.getDrawable(context, R.drawable.ic_direction_arrow);
arrowImageDisabled.mutate();
arrowImageDisabled.setColorFilter(ContextCompat.getColor(
context, light ? R.color.icon_color_default_light : R.color.icon_color_default_dark), PorterDuff.Mode.MULTIPLY);
if (arrowImageDisabled != null) {
arrowImageDisabled.setColorFilter(ContextCompat.getColor(context, R.color.icon_color_default_light), PorterDuff.Mode.MULTIPLY);
}
}
private void deleteFavorites() {
@ -249,8 +249,35 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment implemen
listView.setBackgroundColor(getResources().getColor(
getMyApplication().getSettings().isLightContent() ? R.color.activity_background_color_light
: R.color.activity_background_color_dark));
getExpandableListView().setOnScrollListener(new AbsListView.OnScrollListener() {
@Override
public void onScrollStateChanged(AbsListView view, int newState) {
compassUpdateAllowed = newState == AbsListView.OnScrollListener.SCROLL_STATE_IDLE;
}
@Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
}
});
}
@Override
public void updateLocation(Location location) {
if (!MapUtils.areLatLonEqual(lastLocation, location)) {
lastLocation = location;
updateLocationUi();
}
}
@Override
public void updateCompassValue(float heading) {
if (Math.abs(MapUtils.degreesDiff(lastHeading, heading)) > 5) {
lastHeading = heading;
updateLocationUi();
}
}
@Override
public void onResume() {
super.onResume();
@ -259,11 +286,51 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment implemen
if (groupNameToShow == null) {
restoreState(getArguments());
}
startLocationUpdate();
}
private void startLocationUpdate() {
OsmandApplication app = getMyApplication();
if (app != null && !locationUpdateStarted) {
locationUpdateStarted = true;
app.getLocationProvider().resumeAllUpdates();
app.getLocationProvider().removeCompassListener(app.getLocationProvider().getNavigationInfo());
app.getLocationProvider().addCompassListener(this);
app.getLocationProvider().addLocationListener(this);
updateLocationUi();
}
}
private void stopLocationUpdate() {
OsmandApplication app = getMyApplication();
if (app != null && locationUpdateStarted) {
locationUpdateStarted = false;
app.getLocationProvider().removeLocationListener(this);
app.getLocationProvider().removeCompassListener(this);
app.getLocationProvider().addCompassListener(app.getLocationProvider().getNavigationInfo());
app.getLocationProvider().pauseAllUpdates();
}
}
private void updateLocationUi() {
if (!compassUpdateAllowed) {
return;
}
if (app != null && favouritesAdapter != null) {
app.runInUIThread(new Runnable() {
@Override
public void run() {
favouritesAdapter.notifyDataSetChanged();
}
});
}
}
@Override
public void onPause() {
super.onPause();
stopLocationUpdate();
if (actionMode != null) {
actionMode.finish();
}
@ -271,6 +338,7 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment implemen
helper.removeListener(favoritesListener);
favoritesListener = null;
}
}
private int getSelectedFavoritesCount() {
@ -748,6 +816,11 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment implemen
List<FavoriteGroup> groups = new ArrayList<FavoriteGroup>();
Filter myFilter;
private Set<?> filter;
private UiUtilities.UpdateLocationViewCache cache;
FavouritesAdapter() {
cache = app.getUIUtilities().getUpdateLocationViewCache();
}
void synchronizeGroups() {
favoriteGroups.clear();
@ -928,6 +1001,7 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment implemen
TextView name = (TextView) row.findViewById(R.id.favourite_label);
TextView distanceText = (TextView) row.findViewById(R.id.distance);
TextView addressText = (TextView) row.findViewById(R.id.group_name);
ImageView icon = (ImageView) row.findViewById(R.id.favourite_icon);
final FavouritePoint model = getChild(groupPosition, childPosition);
@ -951,13 +1025,11 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment implemen
LatLon lastKnownMapLocation = getMyApplication().getSettings().getLastKnownMapLocation();
int dist = (int) (MapUtils.getDistance(model.getLatitude(), model.getLongitude(),
lastKnownMapLocation.getLatitude(), lastKnownMapLocation.getLongitude()));
String distance = OsmAndFormatter.getFormattedDistance(dist, getMyApplication()) + " ";
name.setText(model.getDisplayName(app), TextView.BufferType.SPANNABLE);
name.setTypeface(Typeface.DEFAULT, visible ? Typeface.NORMAL : Typeface.ITALIC);
name.setTextColor(getResources().getColor(visible ? enabledColor : disabledColor));
distanceText.setText(distance);
if (model.isAddressSpecified()) {
distanceText.setText(String.format(getString(R.string.ltr_or_rtl_combine_via_comma), distance.trim(), model.getAddress()));
addressText.setText(model.getAddress());
}
int color = visible
? app.getFavorites().getColorWithCategory(model, getResources().getColor(R.color.color_favorite))
@ -971,18 +1043,17 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment implemen
}
FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(iconSize, iconSize, CENTER);
icon.setLayoutParams(lp);
if (visible) {
distanceText.setTextColor(getResources().getColor(R.color.color_distance));
} else {
distanceText.setTextColor(getResources().getColor(disabledColor));
}
row.findViewById(R.id.group_image).setVisibility(View.GONE);
ImageView direction = (ImageView) row.findViewById(R.id.direction);
app.getUIUtilities().updateLocationView(cache, direction, distanceText, model.getLatitude(), model.getLongitude());
if (model.isAddressSpecified()) {
String addComma = app.getString(R.string.ltr_or_rtl_combine_via_comma);
distanceText.setText(String.format(addComma, distanceText.getText(), ""));
}
direction.setVisibility(View.VISIBLE);
if (visible) {
direction.setImageDrawable(arrowImage);
} else {
if (!visible) {
distanceText.setTextColor(getResources().getColor(disabledColor));
direction.setImageDrawable(arrowImageDisabled);
}