fixed night theme bug and added recyclerview scrollbar

This commit is contained in:
Chumva 2018-03-16 15:40:00 +02:00
parent 54746337e9
commit 829e986e79
5 changed files with 32 additions and 13 deletions

View file

@ -15,8 +15,8 @@
android:layout_width="@dimen/standard_icon_size"
android:layout_height="@dimen/standard_icon_size"
android:layout_gravity="center_vertical"
android:layout_marginEnd="@dimen/bottom_sheet_icon_margin"
android:layout_marginRight="@dimen/bottom_sheet_icon_margin"
android:layout_marginEnd="@dimen/route_info_icon_padding_right"
android:layout_marginRight="@dimen/route_info_icon_padding_right"
android:src="@drawable/map_favorite" />
<LinearLayout

View file

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/favourites_recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/bg_color"
android:clipToPadding="false"
android:orientation="vertical"
android:scrollbars="vertical" />

View file

@ -59,12 +59,12 @@ public class FavouritesAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
favouritesViewHolder.description.setText(favouritePoint.getCategory());
}
Location myloc = app.getLocationProvider().getLastKnownLocation();
favouritesViewHolder.favouriteImage.setImageDrawable(FavoriteImageDrawable.getOrCreate(context, favouritePoint.getColor(), false));
if (myloc == null) {
return;
}
float dist = (float) MapUtils.getDistance(favouritePoint.getLatitude(), favouritePoint.getLongitude(), myloc.getLatitude(), myloc.getLongitude());
favouritesViewHolder.distance.setText(OsmAndFormatter.getFormattedDistance(dist, app));
favouritesViewHolder.favouriteImage.setImageDrawable(FavoriteImageDrawable.getOrCreate(context, favouritePoint.getColor(), false));
favouritesViewHolder.arrowImage.setImageDrawable(iconsCache.getIcon(R.drawable.ic_direction_arrow));
DashLocationFragment.updateLocationView(useCenter, location, heading, favouritesViewHolder.arrowImage,
favouritesViewHolder.distance, favouritePoint.getLatitude(), favouritePoint.getLongitude(),

View file

@ -5,6 +5,7 @@ import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.ContextThemeWrapper;
import android.view.View;
import net.osmand.Location;
@ -36,6 +37,7 @@ public class FavouritesBottomSheetMenuFragment extends MenuBottomSheetDialogFrag
private static final String SORTED_BY_TYPE = "sortedByType";
private Location location;
private LatLon latLon;
private Float heading;
private List<FavouritePoint> favouritePoints;
private FavouritesAdapter adapter;
@ -55,20 +57,30 @@ public class FavouritesBottomSheetMenuFragment extends MenuBottomSheetDialogFrag
target = args.getBoolean(TARGET);
intermediate = args.getBoolean(INTERMEDIATE);
}
favouritePoints = getMyApplication().getFavorites().getVisibleFavouritePoints();
recyclerView = new RecyclerView(getContext());
final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme;
recyclerView = (RecyclerView) View.inflate(new ContextThemeWrapper(getContext(), themeRes),
R.layout.favourites_recycleview, null);
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
location = getMyApplication().getLocationProvider().getLastKnownLocation();
if (location != null) {
latLon = new LatLon(location.getLatitude(), location.getLongitude());
}
adapter = new FavouritesAdapter(getContext(), favouritePoints);
if (savedInstanceState != null && savedInstanceState.getBoolean(IS_SORTED)) {
sortByDist = savedInstanceState.getBoolean(SORTED_BY_TYPE);
sortFavourites();
}
title = (BottomSheetItemWithTitleAndButton) new BottomSheetItemWithTitleAndButton.Builder()
.setButtonIcons(null, getIconForButton())
.setButtonTitle(getTextForButton())
.setonButtonClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
sortFavourites();
title.setButtonIcons(null, getIconForButton());
title.setButtonText(getTextForButton());
sortFavourites();
}
})
.setTitle(getString(R.string.favourites))
@ -76,7 +88,6 @@ public class FavouritesBottomSheetMenuFragment extends MenuBottomSheetDialogFrag
.create();
items.add(title);
adapter = new FavouritesAdapter(getContext(), favouritePoints);
adapter.setItemClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@ -95,14 +106,9 @@ public class FavouritesBottomSheetMenuFragment extends MenuBottomSheetDialogFrag
compassUpdateAllowed = newState == RecyclerView.SCROLL_STATE_IDLE;
}
});
items.add(new BaseBottomSheetItem.Builder()
.setCustomView(recyclerView)
.create());
if (savedInstanceState != null && savedInstanceState.getBoolean(IS_SORTED)) {
sortByDist = savedInstanceState.getBoolean(SORTED_BY_TYPE);
sortFavourites();
}
}
private Drawable getIconForButton() {
@ -251,11 +257,12 @@ public class FavouritesBottomSheetMenuFragment extends MenuBottomSheetDialogFrag
}
private void sortFavourites() {
if (location == null) {
if (location != null) {
latLon = new LatLon(location.getLatitude(), location.getLongitude());
} else if (sortByDist) {
return;
}
final Collator inst = Collator.getInstance();
final LatLon latLon = new LatLon(location.getLatitude(), location.getLongitude());
Collections.sort(favouritePoints, new Comparator<FavouritePoint>() {
@Override
public int compare(FavouritePoint lhs, FavouritePoint rhs) {
@ -272,5 +279,6 @@ public class FavouritesBottomSheetMenuFragment extends MenuBottomSheetDialogFrag
sortByDist = !sortByDist;
isSorted = true;
adapter.notifyDataSetChanged();
recyclerView.getLayoutManager().scrollToPosition(0);
}
}

View file

@ -387,6 +387,8 @@ public class MapRouteInfoMenu implements IRouteInformationListener {
final TargetPointsHelper targets = getTargets();
final Spinner fromSpinner = setupFromSpinner(parentView);
fromSpinner.setClickable(false);
// fromSpinner.setSelected(false);
// fromSpinner.setSelection(0, true);
final View fromLayout = parentView.findViewById(R.id.FromLayout);
fromSpinner.setOnTouchListener(new View.OnTouchListener() {
@Override